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       unsigned int RTA_PAYLOAD(struct rtattr *rta);
20
21       struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
22
23       unsigned int RTA_LENGTH(unsigned int length);
24       unsigned int RTA_SPACE(unsigned int length);
25

DESCRIPTION

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

CONFORMING TO

51       These macros are nonstandard Linux extensions.
52

BUGS

54       This manual page is incomplete.
55

EXAMPLES

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

SEE ALSO

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

COLOPHON

94       This page is part of release 5.12 of the Linux  man-pages  project.   A
95       description  of  the project, information about reporting bugs, and the
96       latest    version    of    this    page,    can     be     found     at
97       https://www.kernel.org/doc/man-pages/.
98
99
100
101GNU                               2021-03-22                      RTNETLINK(3)
Impressum