blob: 6a559860b624f6840d084f03446595ea562509f6 [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// 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 Guthrie0d438532012-05-18 14:18:50 -070028#include <base/basictypes.h>
Wade Guthrie0d438532012-05-18 14:18:50 -070029
30struct nl_msg;
31
32namespace shill {
Wade Guthrie0d438532012-05-18 14:18:50 -070033
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.
38class KernelBoundNlMessage {
39 public:
Christopher Wiley393b93f2012-11-08 17:30:58 -080040 // |command| is a type of command understood by the kernel, for instance:
41 // CTRL_CMD_GETFAMILY.
42 explicit KernelBoundNlMessage(uint8 command)
43 : command_(command),
Wade Guthrie8343f7f2012-12-04 13:52:32 -080044 message_(NULL) {}
Wade Guthrie0d438532012-05-18 14:18:50 -070045 virtual ~KernelBoundNlMessage();
46
47 // Non-trivial initialization.
48 bool Init();
49
Wade Guthrie0d438532012-05-18 14:18:50 -070050 // Add a netlink attribute to the message.
51 int AddAttribute(int attrtype, int attrlen, const void *data);
52
Christopher Wiley393b93f2012-11-08 17:30:58 -080053 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 Guthrie0d438532012-05-18 14:18:50 -070059
60 private:
Christopher Wiley393b93f2012-11-08 17:30:58 -080061 uint8 command_;
62 // TODO(wiley) Rename to |raw_message_| (message.message() looks silly).
Wade Guthrie0d438532012-05-18 14:18:50 -070063 struct nl_msg *message_;
64
65 DISALLOW_COPY_AND_ASSIGN(KernelBoundNlMessage);
66};
67
68} // namespace shill
69
70#endif // SHILL_KERNEL_BOUND_NLMESSAGE_H_