Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // 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 Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 7 | #include <netlink/msg.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 8 | |
| 9 | #include "shill/logging.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 10 | |
| 11 | namespace shill { |
| 12 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 13 | KernelBoundNlMessage::~KernelBoundNlMessage() { |
| 14 | if (message_) { |
| 15 | nlmsg_free(message_); |
| 16 | message_ = NULL; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | bool 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 Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 31 | int 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 Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 44 | uint32 KernelBoundNlMessage::sequence_number() const { |
| 45 | if (message_ && nlmsg_hdr(message_)) { |
| 46 | return nlmsg_hdr(message_)->nlmsg_seq; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 47 | } |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 48 | return 0; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace shill. |