man-pages/man3/rtnetlink.3

119 lines
3.3 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
.\" Permission is granted to distribute possibly modified copies
.\" of this page provided the header is included verbatim,
.\" and in case of nontrivial modification author and date
.\" of the modification is added to the header.
.\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
2007-05-18 09:55:10 +00:00
.TH RTNETLINK 3 1999-05-14 "GNU" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
2007-06-13 22:01:33 +00:00
rtnetlink \- macros to manipulate rtnetlink messages
2004-11-03 13:51:07 +00:00
.SH SYNOPSIS
.B #include <asm/types.h>
.br
.B #include <linux/netlink.h>
.br
.B #include <linux/rtnetlink.h>
.br
.B #include <sys/socket.h>
2007-04-03 15:32:52 +00:00
.BI "rtnetlink_socket = socket(PF_NETLINK, int " socket_type \
", NETLINK_ROUTE);"
.sp
.BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
2007-04-03 15:32:52 +00:00
.sp
.BI "void *RTA_DATA(struct rtattr *" rta );
2007-04-03 15:32:52 +00:00
.sp
.BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
2007-04-03 15:32:52 +00:00
.sp
.BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
", unsigned int " rtabuflen );
2007-04-03 15:32:52 +00:00
.sp
.BI "unsigned int RTA_LENGTH(unsigned int " length );
2007-04-03 15:32:52 +00:00
.sp
.BI "unsigned int RTA_SPACE(unsigned int "length );
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
All
2004-11-03 13:51:07 +00:00
.BR rtnetlink (7)
messages consist of a
2004-11-03 13:51:07 +00:00
.BR netlink (7)
message header and appended attributes.
The attributes should be only
2004-11-03 13:51:07 +00:00
manipulated using the macros provided here.
.PP
.BI RTA_OK( rta ", " attrlen )
returns true if
.I rta
points to a valid routing attribute;
.I attrlen
2007-12-19 06:29:23 +00:00
is the running length of the attribute buffer.
2004-11-03 13:51:07 +00:00
When not true then you must assume there are no more attributes in the
message, even if
.I attrlen
2008-03-19 13:16:39 +00:00
is non-zero.
2007-06-13 22:01:33 +00:00
.PP
2004-11-03 13:51:07 +00:00
.BI RTA_DATA( rta )
returns a pointer to the start of this attribute's data.
2007-06-13 22:01:33 +00:00
.PP
2004-11-03 13:51:07 +00:00
.BI RTA_PAYLOAD( rta )
returns the length of this attribute's data.
2007-06-13 22:01:33 +00:00
.PP
2004-11-03 13:51:07 +00:00
.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.
2007-06-13 22:01:33 +00:00
.PP
2004-11-03 13:51:07 +00:00
.BI RTA_LENGTH( len )
returns the length which is required for
.I len
bytes of data plus the header.
2007-06-13 22:01:33 +00:00
.PP
2004-11-03 13:51:07 +00:00
.BI RTA_SPACE( len )
returns the amount of space which will be needed in a message with
2004-11-03 13:51:07 +00:00
.I len
bytes of data.
2007-07-18 20:25:14 +00:00
.SH CONFORMING TO
These macros are non-standard Linux extensions.
.SH BUGS
2007-06-13 22:01:33 +00:00
This manual page is incomplete.
2004-11-03 13:51:07 +00:00
.SH EXAMPLE
2007-06-13 21:48:16 +00:00
.\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
2004-11-03 13:51:07 +00:00
Creating a rtnetlink message to set the MTU of a device:
2004-11-03 13:51:07 +00:00
.nf
2007-06-13 22:01:33 +00:00
2007-04-03 15:32:52 +00:00
struct {
struct nlmsghdr nh;
struct ifinfomsg if;
char attrbuf[512];
} req;
2004-11-03 13:51:07 +00:00
2007-04-03 15:32:52 +00:00
struct rtattr *rta;
unsigned int mtu = 1000;
2004-11-03 13:51:07 +00:00
int rtnetlink_sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
2007-04-03 15:32:52 +00:00
memset(&req, 0, sizeof(req));
req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.nh.nlmsg_flags = NLM_F_REQUEST;
2007-04-03 15:32:52 +00:00
req.nh.nlmsg_type = RTML_NEWLINK;
req.if.ifi_family = AF_UNSPEC;
req.if.ifi_index = INTERFACE_INDEX;
2007-04-03 15:32:52 +00:00
req.if.ifi_change = 0xffffffff; /* ???*/
rta = (struct rtattr *)(((char *) &req) +
2007-06-20 21:39:45 +00:00
NLMSG_ALIGN(n\->nlmsg_len));
rta\->rta_type = IFLA_MTU;
rta\->rta_len = sizeof(unsigned int);
req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) +
RTA_LENGTH(sizeof(mtu));
2007-04-05 12:36:57 +00:00
memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
send(rtnetlink_sk, &req, req.n.nlmsg_len);
2007-04-03 15:32:52 +00:00
.fi
2004-11-03 13:51:07 +00:00
.SH "SEE ALSO"
.BR netlink (3),
.BR netlink (7),
.BR rtnetlink (7)