]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rtnetlink.3
epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, fallocate.2, futex.2, getcpu...
[thirdparty/man-pages.git] / man3 / rtnetlink.3
1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2 .\"
3 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
8 .\" %%%LICENSE_END
9 .\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
10 .TH RTNETLINK 3 2012-03-24 "GNU" "Linux Programmer's Manual"
11 .SH NAME
12 rtnetlink \- macros to manipulate rtnetlink messages
13 .SH SYNOPSIS
14 .B #include <asm/types.h>
15 .br
16 .B #include <linux/netlink.h>
17 .br
18 .B #include <linux/rtnetlink.h>
19 .br
20 .B #include <sys/socket.h>
21
22 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
23 ", NETLINK_ROUTE);"
24 .sp
25 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
26 .sp
27 .BI "void *RTA_DATA(struct rtattr *" rta );
28 .sp
29 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
30 .sp
31 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
32 ", unsigned int " rtabuflen );
33 .sp
34 .BI "unsigned int RTA_LENGTH(unsigned int " length );
35 .sp
36 .BI "unsigned int RTA_SPACE(unsigned int "length );
37 .SH DESCRIPTION
38 All
39 .BR rtnetlink (7)
40 messages consist of a
41 .BR netlink (7)
42 message header and appended attributes.
43 The attributes should be only
44 manipulated using the macros provided here.
45 .PP
46 .BI RTA_OK( rta ", " attrlen )
47 returns true if
48 .I rta
49 points to a valid routing attribute;
50 .I attrlen
51 is the running length of the attribute buffer.
52 When not true then you must assume there are no more attributes in the
53 message, even if
54 .I attrlen
55 is nonzero.
56 .PP
57 .BI RTA_DATA( rta )
58 returns a pointer to the start of this attribute's data.
59 .PP
60 .BI RTA_PAYLOAD( rta )
61 returns the length of this attribute's data.
62 .PP
63 .BI RTA_NEXT( rta ", " attrlen )
64 gets the next attribute after
65 .IR rta .
66 Calling this macro will update
67 .IR attrlen .
68 You should use
69 .B RTA_OK
70 to check the validity of the returned pointer.
71 .PP
72 .BI RTA_LENGTH( len )
73 returns the length which is required for
74 .I len
75 bytes of data plus the header.
76 .PP
77 .BI RTA_SPACE( len )
78 returns the amount of space which will be needed in a message with
79 .I len
80 bytes of data.
81 .SH CONFORMING TO
82 These macros are nonstandard Linux extensions.
83 .SH BUGS
84 This manual page is incomplete.
85 .SH EXAMPLE
86 .\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
87
88 Creating a rtnetlink message to set the MTU of a device:
89 .nf
90 #include <linux/rtnetlink.h>
91
92 ...
93
94 struct {
95 struct nlmsghdr nh;
96 struct ifinfomsg if;
97 char attrbuf[512];
98 } req;
99
100 struct rtattr *rta;
101 unsigned int mtu = 1000;
102
103 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
104
105 memset(&req, 0, sizeof(req));
106 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
107 req.nh.nlmsg_flags = NLM_F_REQUEST;
108 req.nh.nlmsg_type = RTM_NEWLINK;
109 req.if.ifi_family = AF_UNSPEC;
110 req.if.ifi_index = INTERFACE_INDEX;
111 req.if.ifi_change = 0xffffffff; /* ??? */
112 rta = (struct rtattr *)(((char *) &req) +
113 NLMSG_ALIGN(req.nh.nlmsg_len));
114 rta\->rta_type = IFLA_MTU;
115 rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
116 req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
117 RTA_LENGTH(sizeof(mtu));
118 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
119 send(rtnetlink_sk, &req, req.nh.nlmsg_len);
120 .fi
121 .SH SEE ALSO
122 .BR netlink (3),
123 .BR netlink (7),
124 .BR rtnetlink (7)