Data Structures | |
struct | nlmsghdr |
Netlink message header. More... | |
struct | nlmsgerr |
Netlink error message. More... | |
Modules | |
Attributes | |
Netlink Attributes Construction/Parsing Interface. | |
Defines | |
#define | NL_AUTO_PID 0 |
Will cause the netlink pid to be set to the pid assigned to the netlink handle (socket) just before sending the message off. | |
#define | NL_AUTO_SEQ 0 |
May be used to refer to a sequence number which should be automatically set just before sending the message off. |
NLM_F_MULTI
Netlink header flag set, except for the last header which has the Netlink header type NLMSG_DONE
.0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Flags | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Process ID (PID) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
<------- NLMSG_ALIGN(hlen) ------> <---- NLMSG_ALIGN(len) ---> +----------------------------+- - -+- - - - - - - - - - -+- - -+ | Header | Pad | Payload | Pad | | struct nlmsghdr | | | | +----------------------------+- - -+- - - - - - - - - - -+- - -+
<--- nlmsg_total_size(payload) ---> <-- nlmsg_msg_size(payload) -> +----------+- - -+-------------+- - -+-------- - - | nlmsghdr | Pad | Payload | Pad | nlmsghdr +----------+- - -+-------------+- - -+-------- - - nlmsg_data(nlh)---^ ^ nlmsg_next(nlh)-----------------------+
<---------------------- nlmsg_len(nlh) ---------------------> <------ hdrlen ------> <- nlmsg_attrlen(nlh, hdrlen) -> +----------------------+- - -+--------------------------------+ | Family Header | Pad | Attributes | +----------------------+- - -+--------------------------------+ nlmsg_attrdata(nlh, hdrlen)---^
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Netlink message header | | type = NLMSG_ERROR | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error code | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | OLD Netlink message header | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Various methods exist to create/allocate a new netlink // message. // // nlmsg_alloc() will allocate an empty netlink message with // a maximum payload size which defaults to the page size of // the system. This default size can be modified using the // function nlmsg_set_default_size(). struct nl_msg *msg = nlmsg_alloc(); // Very often, the message type and message flags are known // at allocation time while the other fields are auto generated: struct nl_msg *msg = nlmsg_alloc_simple(MY_TYPE, MY_FLAGS); // Alternatively an existing netlink message header can be used // to inherit the header values: struct nlmsghdr hdr = { .nlmsg_type = MY_TYPE, .nlmsg_flags = MY_FLAGS, }; struct nl_msg *msg = nlmsg_inherit(&hdr); // Last but not least, netlink messages received from netlink sockets // can be converted into nl_msg objects using nlmsg_convert(). This // will create a message with a maximum payload size which equals the // length of the existing netlink message, therefore no more data can // be appened without calling nlmsg_expand() first. struct nl_msg *msg = nlmsg_convert(nlh_from_nl_sock); // Payload may be added to the message via nlmsg_append(). The fourth // parameter specifies the number of alignment bytes the data should // be padding with at the end. Common values are 0 to disable it or // NLMSG_ALIGNTO to ensure proper netlink message padding. nlmsg_append(msg, &mydata, sizeof(mydata), 0); // Sometimes it may be necessary to reserve room for data but defer // the actual copying to a later point, nlmsg_reserve() can be used // for this purpose: void *data = nlmsg_reserve(msg, sizeof(mydata), NLMSG_ALIGNTO); // Attributes may be added using the attributes interface. // After successful use of the message, the memory must be freed // using nlmsg_free() nlmsg_free(msg);
int n; unsigned char *buf; struct nlmsghdr *hdr; n = nl_recv(handle, NULL, &buf); hdr = (struct nlmsghdr *) buf; while (nlmsg_ok(hdr, n)) { // Process message here... hdr = nlmsg_next(hdr, &n); }
#define NL_AUTO_PID 0 |
#define NL_AUTO_SEQ 0 |
#define nlmsg_for_each_attr | ( | pos, | |||
nlh, | |||||
hdrlen, | |||||
rem | ) |
Value:
nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \ nlmsg_attrlen(nlh, hdrlen), rem)
pos | loop counter, set to current attribute | |
nlh | netlink message header | |
hdrlen | length of family header | |
rem | initialized to len, holds bytes currently remaining in stream |
#define nlmsg_for_each_msg | ( | pos, | |||
head, | |||||
len, | |||||
rem | ) |
Value:
for (pos = head, rem = len; \ nlmsg_ok(pos, rem); \ pos = nlmsg_next(pos, &(rem)))
pos | loop counter, set to current message | |
head | head of message stream | |
len | length of message stream | |
rem | initialized to len, holds bytes currently remaining in stream |
#define NLM_F_ATOMIC 0x400 |
This may require special privileges because it has the potential to interrupt service in the FE for a longer time.
Definition at line 106 of file netlink-kernel.h.
#define NLMSG_ERROR 0x2 |
This can be looked at as a NACK and typically it is from FEC to CPC.
Definition at line 159 of file netlink-kernel.h.
int nlmsg_msg_size | ( | int | payload | ) |
payload | length of message payload |
Definition at line 184 of file msg.c.
Referenced by nl_msg_dump(), nlmsg_padlen(), and nlmsg_total_size().
int nlmsg_total_size | ( | int | payload | ) |
payload | length of message payload |
Definition at line 193 of file msg.c.
References nlmsg_msg_size().
Referenced by nlmsg_padlen(), and nlmsg_set_default_size().
int nlmsg_padlen | ( | int | payload | ) |
payload | length of message payload |
Definition at line 202 of file msg.c.
References nlmsg_msg_size(), and nlmsg_total_size().
void* nlmsg_data | ( | const struct nlmsghdr * | nlh | ) |
nlh | netlink messsage header |
Definition at line 218 of file msg.c.
Referenced by genlmsg_put(), nfnlmsg_family(), nfnlmsg_res_id(), nl_msg_dump(), nla_put(), nla_put_nested(), nla_reserve(), and nlmsg_attrdata().
int nlmsg_len | ( | const struct nlmsghdr * | nlh | ) |
nlh | netlink message header |
Definition at line 232 of file msg.c.
References nlmsghdr::nlmsg_len.
Referenced by nl_msg_dump(), nla_put_nested(), nlmsg_attrlen(), and nlmsg_reserve().
struct nlattr* nlmsg_attrdata | ( | const struct nlmsghdr * | nlh, | |
int | hdrlen | |||
) | [read] |
nlh | netlink message header | |
hdrlen | length of family specific header |
Definition at line 249 of file msg.c.
References nlmsg_data().
Referenced by nl_msg_dump(), nlmsg_find_attr(), nlmsg_parse(), and nlmsg_validate().
int nlmsg_attrlen | ( | const struct nlmsghdr * | nlh, | |
int | hdrlen | |||
) |
nlh | netlink message header | |
hdrlen | length of family specific header |
Definition at line 260 of file msg.c.
References nlmsg_len().
Referenced by nl_msg_dump(), nlmsg_find_attr(), nlmsg_parse(), and nlmsg_validate().
int nlmsg_ok | ( | const struct nlmsghdr * | nlh, | |
int | remaining | |||
) |
nlh | netlink message header | |
remaining | number of bytes remaining in message stream |
Definition at line 285 of file msg.c.
References nlmsghdr::nlmsg_len.
nlh | netlink message header | |
remaining | number of bytes remaining in message stream |
Definition at line 300 of file msg.c.
References nlmsghdr::nlmsg_len.
int nlmsg_parse | ( | struct nlmsghdr * | nlh, | |
int | hdrlen, | |||
struct nlattr * | tb[], | |||
int | maxtype, | |||
struct nla_policy * | policy | |||
) |
nlh | netlink message header | |
hdrlen | length of family specific header | |
tb | destination array with maxtype+1 elements | |
maxtype | maximum attribute type to be expected | |
policy | validation policy |
Definition at line 319 of file msg.c.
References nla_parse(), nlmsg_attrdata(), and nlmsg_attrlen().
struct nlattr* nlmsg_find_attr | ( | struct nlmsghdr * | nlh, | |
int | hdrlen, | |||
int | attrtype | |||
) | [read] |
nlh | netlink message header | |
hdrlen | length of familiy specific header | |
attrtype | type of attribute to look for |
Definition at line 337 of file msg.c.
References nla_find(), nlmsg_attrdata(), and nlmsg_attrlen().
int nlmsg_validate | ( | struct nlmsghdr * | nlh, | |
int | hdrlen, | |||
int | maxtype, | |||
struct nla_policy * | policy | |||
) |
nlh | netlinket message header | |
hdrlen | length of familiy specific header | |
maxtype | maximum attribute type to be expected | |
policy | validation policy |
Definition at line 350 of file msg.c.
References nla_validate(), nlmsg_attrdata(), and nlmsg_attrlen().
struct nl_msg* nlmsg_alloc | ( | void | ) | [read] |
Allocates a new netlink message without any further payload. The maximum payload size defaults to PAGESIZE or as otherwise specified with nlmsg_set_default_size().
Definition at line 401 of file msg.c.
Referenced by nlmsg_inherit(), and rtnl_neightbl_build_change_request().
struct nl_msg* nlmsg_inherit | ( | struct nlmsghdr * | hdr | ) | [read] |
hdr | Netlink message header template |
Definition at line 424 of file msg.c.
References nlmsg_alloc(), nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_pid, nlmsghdr::nlmsg_seq, and nlmsghdr::nlmsg_type.
Referenced by nl_msg_dump(), and nlmsg_alloc_simple().
struct nl_msg* nlmsg_alloc_simple | ( | int | nlmsgtype, | |
int | flags | |||
) | [read] |
nlmsgtype | Netlink message type | |
flags | Message flags. |
Definition at line 448 of file msg.c.
References nlmsg_inherit(), and nlmsghdr::nlmsg_type.
Referenced by flnl_lookup_build_request(), nfnlmsg_alloc_simple(), nl_send_simple(), rtnl_link_build_change_request(), rtnl_neightbl_build_change_request(), and rtnl_qdisc_build_delete_request().
void nlmsg_set_default_size | ( | size_t | max | ) |
max | Size of payload in bytes. |
Definition at line 467 of file msg.c.
References nlmsg_total_size().
struct nl_msg* nlmsg_convert | ( | struct nlmsghdr * | hdr | ) | [read] |
hdr | Netlink message received from netlink socket. |
Definition at line 484 of file msg.c.
References nlmsg_free(), and nlmsghdr::nlmsg_len.
void* nlmsg_reserve | ( | struct nl_msg * | n, | |
size_t | len, | |||
int | pad | |||
) |
n | netlink message | |
len | length of additional data to reserve room for | |
pad | number of bytes to align data to |
Definition at line 512 of file msg.c.
References nlmsg_len().
Referenced by nlmsg_append(), and nlmsg_put().
int nlmsg_append | ( | struct nl_msg * | n, | |
void * | data, | |||
size_t | len, | |||
int | pad | |||
) |
n | netlink message | |
data | data to add | |
len | length of data | |
pad | Number of bytes to align data to. |
Definition at line 549 of file msg.c.
References nlmsg_reserve().
Referenced by flnl_lookup_build_request(), nl_send_simple(), rtnl_link_build_change_request(), rtnl_neightbl_build_change_request(), and rtnl_qdisc_build_delete_request().
int nlmsg_expand | ( | struct nl_msg * | n, | |
size_t | newlen | |||
) |
n | Netlink message. | |
newlen | New maximum payload size. |
struct nlmsghdr* nlmsg_put | ( | struct nl_msg * | n, | |
uint32_t | pid, | |||
uint32_t | seq, | |||
int | type, | |||
int | payload, | |||
int | flags | |||
) | [read] |
n | netlink message | |
pid | netlink process id or NL_AUTO_PID | |
seq | sequence number of message or NL_AUTO_SEQ | |
type | message type | |
payload | length of message payload | |
flags | message flags |
Definition at line 610 of file msg.c.
References nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_pid, nlmsg_reserve(), nlmsghdr::nlmsg_seq, and nlmsghdr::nlmsg_type.
Referenced by genlmsg_put(), and nfnlmsg_put().
struct nlmsghdr* nlmsg_hdr | ( | struct nl_msg * | n | ) | [read] |
n | netlink message |
Definition at line 643 of file msg.c.
Referenced by nl_cache_parse_and_add(), nl_msg_dump(), nl_send_auto_complete(), and nl_sendmsg().
void nlmsg_free | ( | struct nl_msg * | n | ) |
n | netlink message |
Definition at line 656 of file msg.c.
Referenced by flnl_lookup(), flnl_lookup_build_request(), nfnlmsg_alloc_simple(), nl_msg_dump(), nl_send_simple(), nlmsg_convert(), rtnl_addr_add(), rtnl_addr_delete(), rtnl_class_add(), rtnl_cls_add(), rtnl_cls_change(), rtnl_cls_delete(), rtnl_link_build_change_request(), rtnl_link_change(), rtnl_neigh_add(), rtnl_neigh_change(), rtnl_neigh_delete(), rtnl_neightbl_build_change_request(), rtnl_neightbl_change(), rtnl_qdisc_add(), rtnl_qdisc_change(), rtnl_qdisc_delete(), rtnl_rule_add(), and rtnl_rule_delete().
void nl_msg_dump | ( | struct nl_msg * | msg, | |
FILE * | ofd | |||
) |
msg | Message to print | |
ofd | File descriptor. |
Definition at line 947 of file msg.c.
References nl_cache_ops::co_hdrsize, nlmsgerr::error, nlmsgerr::msg, nl_cache_ops_associate(), nlmsg_attrdata(), nlmsg_attrlen(), nlmsg_data(), nlmsg_free(), nlmsg_hdr(), nlmsg_inherit(), nlmsg_len(), nlmsghdr::nlmsg_len, nlmsg_msg_size(), and nlmsghdr::nlmsg_type.