1RTNETLINK(3)               Linux Programmer's Manual              RTNETLINK(3)
2
3
4

NAME

6       rtnetlink - macros to manipulate rtnetlink messages
7

SYNOPSIS

9       #include <asm/types.h>
10       #include <linux/netlink.h>
11       #include <linux/rtnetlink.h>
12       #include <sys/socket.h>
13
14       rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE);
15
16       int RTA_OK(struct rtattr *rta, int rtabuflen);
17
18       void *RTA_DATA(struct rtattr *rta);
19
20       unsigned int RTA_PAYLOAD(struct rtattr *rta);
21
22       struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
23
24       unsigned int RTA_LENGTH(unsigned int length);
25
26       unsigned int RTA_SPACE(unsigned int length);
27

DESCRIPTION

29       All  rtnetlink(7)  messages  consist of a netlink(7) message header and
30       appended attributes.  The attributes should be manipulated  only  using
31       the macros provided here.
32
33       RTA_OK(rta,  attrlen)  returns  true  if  rta points to a valid routing
34       attribute; attrlen is the running length of the attribute buffer.  When
35       not  true then you must assume there are no more attributes in the mes‐
36       sage, even if attrlen is nonzero.
37
38       RTA_DATA(rta) returns a pointer to the start of this attribute's data.
39
40       RTA_PAYLOAD(rta) returns the length of this attribute's data.
41
42       RTA_NEXT(rta, attrlen) gets the next attribute after rta.  Calling this
43       macro will update attrlen.  You should use RTA_OK to check the validity
44       of the returned pointer.
45
46       RTA_LENGTH(len) returns the length which is required for len  bytes  of
47       data plus the header.
48
49       RTA_SPACE(len)  returns  the  amount of space which will be needed in a
50       message with len bytes of data.
51

CONFORMING TO

53       These macros are nonstandard Linux extensions.
54

BUGS

56       This manual page is incomplete.
57

EXAMPLE

59       Creating a rtnetlink message to set the MTU of a device:
60           #include <linux/rtnetlink.h>
61
62           ...
63
64           struct {
65               struct nlmsghdr  nh;
66               struct ifinfomsg if;
67               char             attrbuf[512];
68           } req;
69
70           struct rtattr *rta;
71           unsigned int mtu = 1000;
72
73           int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
74
75           memset(&req, 0, sizeof(req));
76           req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
77           req.nh.nlmsg_flags = NLM_F_REQUEST;
78           req.nh.nlmsg_type = RTM_NEWLINK;
79           req.if.ifi_family = AF_UNSPEC;
80           req.if.ifi_index = INTERFACE_INDEX;
81           req.if.ifi_change = 0xffffffff; /* ??? */
82           rta = (struct rtattr *)(((char *) &req) +
83                                    NLMSG_ALIGN(req.nh.nlmsg_len));
84           rta->rta_type = IFLA_MTU;
85           rta->rta_len = RTA_LENGTH(sizeof(unsigned int));
86           req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
87                                         RTA_LENGTH(sizeof(mtu));
88           memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
89           send(rtnetlink_sk, &req, req.nh.nlmsg_len);
90

SEE ALSO

92       netlink(3), netlink(7), rtnetlink(7)
93

COLOPHON

95       This page is part of release 3.53 of the Linux  man-pages  project.   A
96       description  of  the project, and information about reporting bugs, can
97       be found at http://www.kernel.org/doc/man-pages/.
98
99
100
101GNU                               2012-03-24                      RTNETLINK(3)
Impressum