Codex

RTNETLINK

Section: Linux Programmer's Manual (7)

Updated: 2013-03-05

Index?action=index Return to Main Contents


NAME

rtnetlink - Linux IPv4 routing socket

SYNOPSIS

#include <asm/types.h>

#include <linux/if_link.h>

#include <linux/netlink.h>

#include <linux/rtnetlink.h>

#include <sys/socket.h>

rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE);

DESCRIPTION

Rtnetlink allows the kernel's routing tables to be read and altered. It is used within the kernel to communicate between various subsystems, though this usage is not documented here, and for communication with user-space programs. Network routes, IP addresses, link parameters, neighbor setups, queueing disciplines, traffic classes and packet classifiers may all be controlled through NETLINK_ROUTE sockets. It is based on netlink messages; see netlink?(7) for more information.

Routing attributes

Some rtnetlink messages have optional attributes after the initial header:

These attributes should be manipulated using only the RTA_* macros or libnetlink, see rtnetlink?(3).

Messages

Rtnetlink consists of these message types (in addition to standard netlink messages):

RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
Create, remove or get information about a specific network interface. These messages contain an ifinfomsg structure followed by a series of rtattr structures.

ifi_flags contains the device flags, see netdevice?(7); ifi_index is the unique interface index (since Linux 3.7, it is possible to feed a nonzero value with the RTM_NEWLINK message, thus creating a link with the given ifindex); ifi_change is reserved for future use and should be always set to 0xFFFFFFFF.

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="3|Routing attributes

</TD> </TR> <TR VALIGN="top| <TD>rta_type</TD> <TD>value type</TD> <TD>description

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="3|


</TD> </TR> <TR VALIGN="top| <TD>IFLA_UNSPEC</TD> <TD>-</TD> <TD>unspecified.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_ADDRESS</TD> <TD>hardware address</TD> <TD>interface L2 address

</TD> </TR> <TR VALIGN="top| <TD>IFLA_BROADCAST</TD> <TD>hardware address</TD> <TD>L2 broadcast address.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_IFNAME</TD> <TD>asciiz string</TD> <TD>Device name.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_MTU</TD> <TD>unsigned int</TD> <TD>MTU of the device.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_LINK</TD> <TD>int</TD> <TD>Link type.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_QDISC</TD> <TD>asciiz string</TD> <TD>Queueing discipline.

</TD> </TR> <TR VALIGN="top| <TD>IFLA_STATS</TD> <TD>see below</TD> <TD>Interface Statistics.

</TD> </TR> </TABLE>

The value type for IFLA_STATS is struct rtnl_link_stats (struct net_device_stats in Linux 2.4 and earlier).

:

RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
Add, remove or receive information about an IP address associated with an interface. In Linux 2.2, an interface can carry multiple IP addresses, this replaces the alias device concept in 2.0. In Linux 2.2, these messages support IPv4 and IPv6 addresses. They contain an ifaddrmsg structure, optionally followed by rtattr routing attributes.

ifa_family is the address family type (currently AF_INET or AF_INET6), ifa_prefixlen is the length of the address mask of the address if defined for the family (like for IPv4), ifa_scope is the address scope, ifa_index is the interface index of the interface the address is associated with. ifa_flags is a flag word of IFA_F_SECONDARY for secondary address (old alias interface), IFA_F_PERMANENT for a permanent address set by the user and other undocumented flags.

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="3|Attributes

</TD> </TR> <TR VALIGN="top| <TD>rta_type</TD> <TD>value type</TD> <TD>description

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="3|


</TD> </TR> <TR VALIGN="top| <TD>IFA_UNSPEC</TD> <TD>-</TD> <TD>unspecified.

</TD> </TR> <TR VALIGN="top| <TD>IFA_ADDRESS</TD> <TD>raw protocol address</TD> <TD>interface address

</TD> </TR> <TR VALIGN="top| <TD>IFA_LOCAL</TD> <TD>raw protocol address</TD> <TD>local address

</TD> </TR> <TR VALIGN="top| <TD>IFA_LABEL</TD> <TD>asciiz string</TD> <TD>name of the interface

</TD> </TR> <TR VALIGN="top| <TD>IFA_BROADCAST</TD> <TD>raw protocol address</TD> <TD>broadcast address.

</TD> </TR> <TR VALIGN="top| <TD>IFA_ANYCAST</TD> <TD>raw protocol address</TD> <TD>anycast address

</TD> </TR> <TR VALIGN="top| <TD>IFA_CACHEINFO</TD> <TD>struct ifa_cacheinfo</TD> <TD>Address information.

</TD> </TR> </TABLE> :

RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
Create, remove or receive information about a network route. These messages contain an rtmsg structure with an optional sequence of rtattr structures following. For RTM_GETROUTE, setting rtm_dst_len and rtm_src_len to 0 means you get all entries for the specified routing table. For the other fields, except rtm_table and rtm_protocol, 0 is the wildcard.

<TABLE> <TR VALIGN="top| <TD>rtm_type</TD> <TD>Route type

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="2|


</TD> </TR> <TR VALIGN="top| <TD>RTN_UNSPEC</TD> <TD>unknown route

</TD> </TR> <TR VALIGN="top| <TD>RTN_UNICAST</TD> <TD>a gateway or direct route

</TD> </TR> <TR VALIGN="top| <TD>RTN_LOCAL</TD> <TD>a local interface route

</TD> </TR> <TR VALIGN="top| <TD>RTN_BROADCAST</TD> <TD>a local broadcast route (sent as a broadcast)

</TD> </TR> <TR VALIGN="top| <TD>RTN_ANYCAST</TD> <TD>a local broadcast route (sent as a unicast)

</TD> </TR> <TR VALIGN="top| <TD>RTN_MULTICAST</TD> <TD>a multicast route

</TD> </TR> <TR VALIGN="top| <TD>RTN_BLACKHOLE</TD> <TD>a packet dropping route

</TD> </TR> <TR VALIGN="top| <TD>RTN_UNREACHABLE</TD> <TD>an unreachable destination

</TD> </TR> <TR VALIGN="top| <TD>RTN_PROHIBIT</TD> <TD>a packet rejection route

</TD> </TR> <TR VALIGN="top| <TD>RTN_THROW</TD> <TD>continue routing lookup in another table

</TD> </TR> <TR VALIGN="top| <TD>RTN_NAT</TD> <TD>a network address translation rule

</TD> </TR> <TR VALIGN="top| <TD>RTN_XRESOLVE</TD> <TD>refer to an external resolver (not implemented)

</TD> </TR> </TABLE> <TABLE> <TR VALIGN="top| <TD>rtm_protocol</TD> <TD>Route origin.

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="2|


</TD> </TR> <TR VALIGN="top| <TD>RTPROT_UNSPEC</TD> <TD>unknown

</TD> </TR> <TR VALIGN="top| <TD>RTPROT_REDIRECT</TD> <TD>by an ICMP redirect (currently unused)

</TD> </TR> <TR VALIGN="top| <TD>RTPROT_KERNEL</TD> <TD>by the kernel

</TD> </TR> <TR VALIGN="top| <TD>RTPROT_BOOT</TD> <TD>during boot

</TD> </TR> <TR VALIGN="top| <TD>RTPROT_STATIC</TD> <TD>by the administrator

</TD> </TR> </TABLE>

Values larger than RTPROT_STATIC are not interpreted by the kernel, they are just for user information. They may be used to tag the source of a routing information or to distinguish between multiple routing daemons. See <linux/rtnetlink.h> for the routing daemon identifiers which are already assigned.

rtm_scope is the distance to the destination:

<TABLE> <TR VALIGN="top| <TD>RT_SCOPE_UNIVERSE</TD> <TD>global route

</TD> </TR> <TR VALIGN="top| <TD>RT_SCOPE_SITE</TD> <TD>interior route in the local autonomous system

</TD> </TR> <TR VALIGN="top| <TD>RT_SCOPE_LINK</TD> <TD>route on this link

</TD> </TR> <TR VALIGN="top| <TD>RT_SCOPE_HOST</TD> <TD>route on the local host

</TD> </TR> <TR VALIGN="top| <TD>RT_SCOPE_NOWHERE</TD> <TD>destination doesn't exist

</TD> </TR> </TABLE>

The values between RT_SCOPE_UNIVERSE and RT_SCOPE_SITE are available to the user.

The rtm_flags have the following meanings:

<TABLE> <TR VALIGN="top| <TD>RTM_F_NOTIFY</TD> <TD>if the route changes, notify the user via rtnetlink

</TD> </TR> <TR VALIGN="top| <TD>RTM_F_CLONED</TD> <TD>route is cloned from another route

</TD> </TR> <TR VALIGN="top| <TD>RTM_F_EQUALIZE</TD> <TD>a multipath equalizer (not yet implemented)

</TD> </TR> </TABLE>

rtm_table specifies the routing table

<TABLE> <TR VALIGN="top| <TD>RT_TABLE_UNSPEC</TD> <TD>an unspecified routing table

</TD> </TR> <TR VALIGN="top| <TD>RT_TABLE_DEFAULT</TD> <TD>the default table

</TD> </TR> <TR VALIGN="top| <TD>RT_TABLE_MAIN</TD> <TD>the main table

</TD> </TR> <TR VALIGN="top| <TD>RT_TABLE_LOCAL</TD> <TD>the local table

</TD> </TR> </TABLE>

The user may assign arbitrary values between RT_TABLE_UNSPEC and RT_TABLE_DEFAULT.

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="3|Attributes

</TD> </TR> <TR VALIGN="top| <TD>rta_type</TD> <TD>value type</TD> <TD>description

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="3|


</TD> </TR> <TR VALIGN="top| <TD>RTA_UNSPEC</TD> <TD>-</TD> <TD>ignored.

</TD> </TR> <TR VALIGN="top| <TD>RTA_DST</TD> <TD>protocol address</TD> <TD>Route destination address.

</TD> </TR> <TR VALIGN="top| <TD>RTA_SRC</TD> <TD>protocol address</TD> <TD>Route source address.

</TD> </TR> <TR VALIGN="top| <TD>RTA_IIF</TD> <TD>int</TD> <TD>Input interface index.

</TD> </TR> <TR VALIGN="top| <TD>RTA_OIF</TD> <TD>int</TD> <TD>Output interface index.

</TD> </TR> <TR VALIGN="top| <TD>RTA_GATEWAY</TD> <TD>protocol address</TD> <TD>The gateway of the route

</TD> </TR> <TR VALIGN="top| <TD>RTA_PRIORITY</TD> <TD>int</TD> <TD>Priority of route.

</TD> </TR> <TR VALIGN="top| <TD>RTA_PREFSRC</TD> <TD></TD> <TD>

</TD> </TR> <TR VALIGN="top| <TD>RTA_METRICS</TD> <TD>int</TD> <TD>Route metric

</TD> </TR> <TR VALIGN="top| <TD>RTA_MULTIPATH</TD> <TD></TD> <TD>

</TD> </TR> <TR VALIGN="top| <TD>RTA_PROTOINFO</TD> <TD></TD> <TD>

</TD> </TR> <TR VALIGN="top| <TD>RTA_FLOW</TD> <TD></TD> <TD>

</TD> </TR> <TR VALIGN="top| <TD>RTA_CACHEINFO</TD> <TD></TD> <TD>

</TD> </TR> </TABLE>

Fill these values in!

:

RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
Add, remove or receive information about a neighbor table entry (e.g., an ARP entry). The message contains an ndmsg structure.

ndm_state is a bit mask of the following states:

<TABLE> <TR VALIGN="top| <TD>NUD_INCOMPLETE</TD> <TD>a currently resolving cache entry

</TD> </TR> <TR VALIGN="top| <TD>NUD_REACHABLE</TD> <TD>a confirmed working cache entry

</TD> </TR> <TR VALIGN="top| <TD>NUD_STALE</TD> <TD>an expired cache entry

</TD> </TR> <TR VALIGN="top| <TD>NUD_DELAY</TD> <TD>an entry waiting for a timer

</TD> </TR> <TR VALIGN="top| <TD>NUD_PROBE</TD> <TD>a cache entry that is currently reprobed

</TD> </TR> <TR VALIGN="top| <TD>NUD_FAILED</TD> <TD>an invalid cache entry

</TD> </TR> <TR VALIGN="top| <TD>NUD_NOARP</TD> <TD>a device with no destination cache

</TD> </TR> <TR VALIGN="top| <TD>NUD_PERMANENT</TD> <TD>a static entry

</TD> </TR> </TABLE>

Valid ndm_flags are:

<TABLE> <TR VALIGN="top| <TD>NTF_PROXY</TD> <TD>a proxy arp entry

</TD> </TR> <TR VALIGN="top| <TD>NTF_ROUTER</TD> <TD>an IPv6 router

</TD> </TR> </TABLE>

The rtattr struct has the following meanings for the rta_type field:

<TABLE> <TR VALIGN="top| <TD>NDA_UNSPEC</TD> <TD>unknown type

</TD> </TR> <TR VALIGN="top| <TD>NDA_DST</TD> <TD>a neighbor cache n/w layer destination address

</TD> </TR> <TR VALIGN="top| <TD>NDA_LLADDR</TD> <TD>a neighbor cache link layer address

</TD> </TR> <TR VALIGN="top| <TD>NDA_CACHEINFO</TD> <TD>cache statistics.

</TD> </TR> </TABLE>

If the rta_type field is NDA_CACHEINFO, then a struct nda_cacheinfo header follows

:

RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
Add, delete or retrieve a routing rule. Carries a struct rtmsg:
RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
Add, remove or get a queueing discipline. The message contains a struct tcmsg and may be followed by a series of attributes.

<TABLE> <TR VALIGN="top| <TD ALIGN="center" COLSPAN="3|Attributes

</TD> </TR> <TR VALIGN="top| <TD>rta_type  </TD> <TD>value type  </TD> <TD>Description

</TD> </TR> <TR VALIGN="top| <TD COLSPAN="3|


</TD> </TR> <TR VALIGN="top| <TD>TCA_UNSPEC  </TD> <TD>-  </TD> <TD>unspecified

</TD> </TR> <TR VALIGN="top| <TD>TCA_KIND  </TD> <TD>asciiz string  </TD> <TD>Name of queueing discipline

</TD> </TR> <TR VALIGN="top| <TD>TCA_OPTIONS  </TD> <TD>byte sequence  </TD> <TD>Qdisc-specific options follow

</TD> </TR> <TR VALIGN="top| <TD>TCA_STATS  </TD> <TD>struct tc_stats  </TD> <TD>Qdisc statistics.

</TD> </TR> <TR VALIGN="top| <TD>TCA_XSTATS  </TD> <TD>qdisc-specific  </TD> <TD>Module-specific statistics.

</TD> </TR> <TR VALIGN="top| <TD>TCA_RATE  </TD> <TD>struct tc_estimator  </TD> <TD>Rate limit.

</TD> </TR> </TABLE>

In addition, various other qdisc-module-specific attributes are allowed. For more information see the appropriate include files.

:

RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
Add, remove or get a traffic class. These messages contain a struct tcmsg as described above.:
RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
Add, remove or receive information about a traffic filter. These messages contain a struct tcmsg as described above.:

VERSIONS

rtnetlink is a new feature of Linux 2.2.

BUGS

This manual page is incomplete.

SEE ALSO

cmsg?(3), rtnetlink?(3), ip?(7), netlink?(7)

COLOPHON

This page is part of release 3.74 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.


Index

NAME

SYNOPSIS

DESCRIPTION

Routing attributes

Messages

VERSIONS

BUGS

SEE ALSO

COLOPHON