summaryrefslogtreecommitdiffstats
path: root/man/man3/rtnetlink.3
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-24 04:52:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-24 04:52:22 +0000
commit3d08cd331c1adcf0d917392f7e527b3f00511748 (patch)
tree312f0d1e1632f48862f044b8bb87e602dcffb5f9 /man/man3/rtnetlink.3
parentAdding debian version 6.7-2. (diff)
downloadmanpages-3d08cd331c1adcf0d917392f7e527b3f00511748.tar.xz
manpages-3d08cd331c1adcf0d917392f7e527b3f00511748.zip
Merging upstream version 6.8.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'man/man3/rtnetlink.3')
-rw-r--r--man/man3/rtnetlink.3122
1 files changed, 122 insertions, 0 deletions
diff --git a/man/man3/rtnetlink.3 b/man/man3/rtnetlink.3
new file mode 100644
index 0000000..7eaef31
--- /dev/null
+++ b/man/man3/rtnetlink.3
@@ -0,0 +1,122 @@
+.\" SPDX-License-Identifier: Linux-man-pages-1-para
+.\"
+.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
+.\"
+.\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
+.\"
+.TH rtnetlink 3 2024-05-02 "Linux man-pages (unreleased)"
+.SH NAME
+rtnetlink \- macros to manipulate rtnetlink messages
+.SH LIBRARY
+Standard C library
+.RI ( libc ", " \-lc )
+.SH SYNOPSIS
+.nf
+.B #include <asm/types.h>
+.B #include <linux/netlink.h>
+.B #include <linux/rtnetlink.h>
+.B #include <sys/socket.h>
+.P
+.BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
+", NETLINK_ROUTE);"
+.P
+.BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
+.P
+.BI "void *RTA_DATA(struct rtattr *" rta );
+.BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
+.P
+.BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
+", unsigned int " rtabuflen );
+.P
+.BI "unsigned int RTA_LENGTH(unsigned int " length );
+.BI "unsigned int RTA_SPACE(unsigned int "length );
+.fi
+.SH DESCRIPTION
+All
+.BR rtnetlink (7)
+messages consist of a
+.BR netlink (7)
+message header and appended attributes.
+The attributes should be manipulated only using the macros provided here.
+.P
+.BI RTA_OK( rta ", " attrlen )
+returns true if
+.I rta
+points to a valid routing attribute;
+.I attrlen
+is the running length of the attribute buffer.
+When not true then you must assume there are no more attributes in the
+message, even if
+.I attrlen
+is nonzero.
+.P
+.BI RTA_DATA( rta )
+returns a pointer to the start of this attribute's data.
+.P
+.BI RTA_PAYLOAD( rta )
+returns the length of this attribute's data.
+.P
+.BI RTA_NEXT( rta ", " attrlen )
+gets the next attribute after
+.IR rta .
+Calling this macro will update
+.IR attrlen .
+You should use
+.B RTA_OK
+to check the validity of the returned pointer.
+.P
+.BI RTA_LENGTH( len )
+returns the length which is required for
+.I len
+bytes of data plus the header.
+.P
+.BI RTA_SPACE( len )
+returns the amount of space which will be needed in a message with
+.I len
+bytes of data.
+.SH STANDARDS
+Linux.
+.SH BUGS
+This manual page is incomplete.
+.SH EXAMPLES
+.\" FIXME . ? would be better to use libnetlink in the EXAMPLE code here
+Creating a rtnetlink message to set the MTU of a device:
+.P
+.in +4n
+.EX
+#include <linux/rtnetlink.h>
+\&
+\&...
+\&
+struct {
+ struct nlmsghdr nh;
+ struct ifinfomsg if;
+ char attrbuf[512];
+} req;
+\&
+struct rtattr *rta;
+unsigned int mtu = 1000;
+\&
+int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
+\&
+memset(&req, 0, sizeof(req));
+req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
+req.nh.nlmsg_flags = NLM_F_REQUEST;
+req.nh.nlmsg_type = RTM_NEWLINK;
+req.if.ifi_family = AF_UNSPEC;
+req.if.ifi_index = INTERFACE_INDEX;
+req.if.ifi_change = 0xffffffff; /* ??? */
+rta = (struct rtattr *)(((char *) &req) +
+ NLMSG_ALIGN(req.nh.nlmsg_len));
+rta\->rta_type = IFLA_MTU;
+rta\->rta_len = RTA_LENGTH(sizeof(mtu));
+req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
+ RTA_LENGTH(sizeof(mtu));
+memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
+send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);
+.EE
+.in
+.SH SEE ALSO
+.BR netlink (3),
+.BR netlink (7),
+.BR rtnetlink (7)