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 | |
| 28 | #include "shill/kernel_bound_nlmessage.h" |
| 29 | |
| 30 | #include <base/basictypes.h> |
| 31 | #include <base/bind.h> |
| 32 | |
| 33 | struct nl_msg; |
| 34 | |
| 35 | namespace shill { |
| 36 | struct NetlinkSocket; |
| 37 | |
| 38 | // TODO(wdg): eventually, KernelBoundNlMessage and UserBoundNlMessage should |
| 39 | // be combined into a monolithic NlMessage. |
| 40 | // |
| 41 | // Provides a wrapper around a netlink message destined for kernel-space. |
| 42 | class KernelBoundNlMessage { |
| 43 | public: |
| 44 | KernelBoundNlMessage() : message_(NULL) {} |
| 45 | virtual ~KernelBoundNlMessage(); |
| 46 | |
| 47 | // Non-trivial initialization. |
| 48 | bool Init(); |
| 49 | |
| 50 | // Message ID is equivalent to the message's sequence number. |
| 51 | uint32_t GetId() const; |
| 52 | |
| 53 | // Add a netlink header to the message. |
| 54 | bool AddNetlinkHeader(uint32_t port, uint32_t seq, int family_id, int hdrlen, |
| 55 | int flags, uint8_t cmd, uint8_t version); |
| 56 | |
| 57 | // Add a netlink attribute to the message. |
| 58 | int AddAttribute(int attrtype, int attrlen, const void *data); |
| 59 | |
| 60 | // Sends |this| over the netlink socket. |
| 61 | virtual bool Send(NetlinkSocket *socket); |
| 62 | |
| 63 | private: |
| 64 | static const uint32_t kIllegalMessage; |
| 65 | |
| 66 | struct nl_msg *message_; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(KernelBoundNlMessage); |
| 69 | }; |
| 70 | |
| 71 | } // namespace shill |
| 72 | |
| 73 | #endif // SHILL_KERNEL_BOUND_NLMESSAGE_H_ |