blob: e1b8e7c4632b47f1412939c2d12b870c4665322f [file] [log] [blame]
Wade Guthrie0d438532012-05-18 14:18:50 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/kernel_bound_nlmessage.h"
6
Wade Guthrie0d438532012-05-18 14:18:50 -07007#include <netlink/msg.h>
Wade Guthrie0d438532012-05-18 14:18:50 -07008
9#include "shill/logging.h"
Wade Guthrie0d438532012-05-18 14:18:50 -070010
11namespace shill {
12
Wade Guthrie0d438532012-05-18 14:18:50 -070013KernelBoundNlMessage::~KernelBoundNlMessage() {
14 if (message_) {
15 nlmsg_free(message_);
16 message_ = NULL;
17 }
18}
19
20bool KernelBoundNlMessage::Init() {
21 message_ = nlmsg_alloc();
22
23 if (!message_) {
24 LOG(ERROR) << "Couldn't allocate |message_|";
25 return false;
26 }
27
28 return true;
29}
30
Wade Guthrie0d438532012-05-18 14:18:50 -070031int KernelBoundNlMessage::AddAttribute(int attrtype, int attrlen,
32 const void *data) {
33 if (!data) {
34 LOG(ERROR) << "NULL |data| parameter";
35 return -1;
36 }
37 if (!message_) {
38 LOG(ERROR) << "NULL |message_|.";
39 return -1;
40 }
41 return nla_put(message_, attrtype, attrlen, data);
42}
43
Christopher Wiley393b93f2012-11-08 17:30:58 -080044uint32 KernelBoundNlMessage::sequence_number() const {
45 if (message_ && nlmsg_hdr(message_)) {
46 return nlmsg_hdr(message_)->nlmsg_seq;
Wade Guthrie0d438532012-05-18 14:18:50 -070047 }
Christopher Wiley393b93f2012-11-08 17:30:58 -080048 return 0;
Wade Guthrie0d438532012-05-18 14:18:50 -070049}
50
51} // namespace shill.