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

SEE ALSO

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

COLOPHON

96       This page is part of release 5.02 of the Linux  man-pages  project.   A
97       description  of  the project, information about reporting bugs, and the
98       latest    version    of    this    page,    can     be     found     at
99       https://www.kernel.org/doc/man-pages/.
100
101
102
103GNU                               2014-09-06                      RTNETLINK(3)
Impressum