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 | // This code is derived from the 'iw' source code. The copyright and license |
| 6 | // of that code is as follows: |
| 7 | // |
| 8 | // Copyright (c) 2007, 2008 Johannes Berg |
| 9 | // Copyright (c) 2007 Andy Lutomirski |
| 10 | // Copyright (c) 2007 Mike Kershaw |
| 11 | // Copyright (c) 2008-2009 Luis R. Rodriguez |
| 12 | // |
| 13 | // Permission to use, copy, modify, and/or distribute this software for any |
| 14 | // purpose with or without fee is hereby granted, provided that the above |
| 15 | // copyright notice and this permission notice appear in all copies. |
| 16 | // |
| 17 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 18 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 19 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 20 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 22 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 23 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 | |
| 25 | #ifndef SHILL_KERNEL_BOUND_NLMESSAGE_H_ |
| 26 | #define SHILL_KERNEL_BOUND_NLMESSAGE_H_ |
| 27 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 28 | #include <base/basictypes.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 29 | |
| 30 | struct nl_msg; |
| 31 | |
| 32 | namespace shill { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 33 | |
| 34 | // TODO(wdg): eventually, KernelBoundNlMessage and UserBoundNlMessage should |
| 35 | // be combined into a monolithic NlMessage. |
| 36 | // |
| 37 | // Provides a wrapper around a netlink message destined for kernel-space. |
| 38 | class KernelBoundNlMessage { |
| 39 | public: |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 40 | // |command| is a type of command understood by the kernel, for instance: |
| 41 | // CTRL_CMD_GETFAMILY. |
| 42 | explicit KernelBoundNlMessage(uint8 command) |
| 43 | : command_(command), |
| 44 | message_(NULL) {}; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 45 | virtual ~KernelBoundNlMessage(); |
| 46 | |
| 47 | // Non-trivial initialization. |
| 48 | bool Init(); |
| 49 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 50 | // Add a netlink attribute to the message. |
| 51 | int AddAttribute(int attrtype, int attrlen, const void *data); |
| 52 | |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 53 | uint8 command() const { return command_; } |
| 54 | // TODO(wiley) It would be better if messages were bags of attributes which |
| 55 | // the socket collapses into binary blobs at send time. |
| 56 | struct nl_msg *message() const { return message_; } |
| 57 | // Returns 0 when unsent, > 0 otherwise. |
| 58 | uint32 sequence_number() const; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 61 | uint8 command_; |
| 62 | // TODO(wiley) Rename to |raw_message_| (message.message() looks silly). |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 63 | struct nl_msg *message_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(KernelBoundNlMessage); |
| 66 | }; |
| 67 | |
| 68 | } // namespace shill |
| 69 | |
| 70 | #endif // SHILL_KERNEL_BOUND_NLMESSAGE_H_ |