/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef __LINUX_RTNETLINK_H
#define __LINUX_RTNETLINK_H
#include <linux/netlink.h>
#include <linux/if_link.h>
#include <linux/if_addr.h>
#include <linux/neighbour.h>
/* rtnetlink families. Values up to 127 are reserved for real address
* families, values above 128 may be used arbitrarily.
#define RTNL_FAMILY_IPMR 128
#define RTNL_FAMILY_IP6MR 129
#define RTNL_FAMILY_MAX 129
* Routing/neighbour discovery messages.
#define RTM_BASE RTM_BASE
#define RTM_NEWLINK RTM_NEWLINK
#define RTM_DELLINK RTM_DELLINK
#define RTM_GETLINK RTM_GETLINK
#define RTM_SETLINK RTM_SETLINK
#define RTM_NEWADDR RTM_NEWADDR
#define RTM_DELADDR RTM_DELADDR
#define RTM_GETADDR RTM_GETADDR
#define RTM_NEWROUTE RTM_NEWROUTE
#define RTM_DELROUTE RTM_DELROUTE
#define RTM_GETROUTE RTM_GETROUTE
#define RTM_NEWNEIGH RTM_NEWNEIGH
#define RTM_DELNEIGH RTM_DELNEIGH
#define RTM_GETNEIGH RTM_GETNEIGH
#define RTM_NEWRULE RTM_NEWRULE
#define RTM_DELRULE RTM_DELRULE
#define RTM_GETRULE RTM_GETRULE
#define RTM_NEWQDISC RTM_NEWQDISC
#define RTM_DELQDISC RTM_DELQDISC
#define RTM_GETQDISC RTM_GETQDISC
#define RTM_NEWTCLASS RTM_NEWTCLASS
#define RTM_DELTCLASS RTM_DELTCLASS
#define RTM_GETTCLASS RTM_GETTCLASS
#define RTM_NEWTFILTER RTM_NEWTFILTER
#define RTM_DELTFILTER RTM_DELTFILTER
#define RTM_GETTFILTER RTM_GETTFILTER
#define RTM_NEWACTION RTM_NEWACTION
#define RTM_DELACTION RTM_DELACTION
#define RTM_GETACTION RTM_GETACTION
#define RTM_NEWPREFIX RTM_NEWPREFIX
#define RTM_GETMULTICAST RTM_GETMULTICAST
#define RTM_GETANYCAST RTM_GETANYCAST
#define RTM_NEWNEIGHTBL RTM_NEWNEIGHTBL
#define RTM_GETNEIGHTBL RTM_GETNEIGHTBL
#define RTM_SETNEIGHTBL RTM_SETNEIGHTBL
#define RTM_NEWNDUSEROPT RTM_NEWNDUSEROPT
#define RTM_NEWADDRLABEL RTM_NEWADDRLABEL
#define RTM_DELADDRLABEL RTM_DELADDRLABEL
#define RTM_GETADDRLABEL RTM_GETADDRLABEL
#define RTM_GETDCB RTM_GETDCB
#define RTM_SETDCB RTM_SETDCB
#define RTM_NEWNETCONF RTM_NEWNETCONF
#define RTM_DELNETCONF RTM_DELNETCONF
#define RTM_GETNETCONF RTM_GETNETCONF
#define RTM_NEWMDB RTM_NEWMDB
#define RTM_DELMDB RTM_DELMDB
#define RTM_GETMDB RTM_GETMDB
#define RTM_NEWNSID RTM_NEWNSID
#define RTM_DELNSID RTM_DELNSID
#define RTM_GETNSID RTM_GETNSID
#define RTM_NEWSTATS RTM_NEWSTATS
#define RTM_GETSTATS RTM_GETSTATS
#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
#define RTM_NEWCHAIN RTM_NEWCHAIN
#define RTM_DELCHAIN RTM_DELCHAIN
#define RTM_GETCHAIN RTM_GETCHAIN
#define RTM_NEWNEXTHOP RTM_NEWNEXTHOP
#define RTM_DELNEXTHOP RTM_DELNEXTHOP
#define RTM_GETNEXTHOP RTM_GETNEXTHOP
#define RTM_NEWLINKPROP RTM_NEWLINKPROP
#define RTM_DELLINKPROP RTM_DELLINKPROP
#define RTM_GETLINKPROP RTM_GETLINKPROP
#define RTM_NEWNVLAN RTM_NEWVLAN
#define RTM_DELVLAN RTM_DELVLAN
#define RTM_GETVLAN RTM_GETVLAN
#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
#define RTM_NR_MSGTYPES (RTM_MAX + 1 - RTM_BASE)
#define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
#define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
Generic structure for encapsulation of optional route information.
It is reminiscent of sockaddr, but with sa_family replaced
/* Macros to handle rtattributes */
#define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
#define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
(rta)->rta_len >= sizeof(struct rtattr) && \
#define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
(struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
#define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
#define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
#define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
#define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
/******************************************************************************
* Definitions used in routing table administration.
unsigned char rtm_family;
unsigned char rtm_dst_len;
unsigned char rtm_src_len;
unsigned char rtm_table; /* Routing table id */
unsigned char rtm_protocol; /* Routing protocol; see below */
unsigned char rtm_scope; /* See below */
unsigned char rtm_type; /* See below */
RTN_UNICAST, /* Gateway or direct route */
RTN_LOCAL, /* Accept locally */
RTN_BROADCAST, /* Accept locally as broadcast,
RTN_ANYCAST, /* Accept locally as broadcast,
RTN_MULTICAST, /* Multicast route */
RTN_BLACKHOLE, /* Drop */
RTN_UNREACHABLE, /* Destination is unreachable */
RTN_PROHIBIT, /* Administratively prohibited */
RTN_THROW, /* Not in this table */
RTN_NAT, /* Translate this address */
RTN_XRESOLVE, /* Use external resolver */
#define RTN_MAX (__RTN_MAX - 1)
#define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
not used by current IPv4 */
#define RTPROT_KERNEL 2 /* Route installed by kernel */
#define RTPROT_BOOT 3 /* Route installed during boot */
#define RTPROT_STATIC 4 /* Route installed by administrator */
/* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
they are just passed from user and back as is.
It will be used by hypothetical multiple routing daemons.
Note that protocol values should be standardized in order to
#define RTPROT_GATED 8 /* Apparently, GateD */
#define RTPROT_RA 9 /* RDISC/ND router advertisements */
#define RTPROT_MRT 10 /* Merit MRT */
#define RTPROT_ZEBRA 11 /* Zebra */
#define RTPROT_BIRD 12 /* BIRD */
#define RTPROT_DNROUTED 13 /* DECnet routing daemon */
#define RTPROT_XORP 14 /* XORP */
#define RTPROT_NTK 15 /* Netsukuku */
#define RTPROT_DHCP 16 /* DHCP client */
#define RTPROT_MROUTED 17 /* Multicast daemon */
#define RTPROT_BABEL 42 /* Babel daemon */
#define RTPROT_BGP 186 /* BGP Routes */
#define RTPROT_ISIS 187 /* ISIS Routes */
#define RTPROT_OSPF 188 /* OSPF Routes */
#define RTPROT_RIP 189 /* RIP Routes */
#define RTPROT_EIGRP 192 /* EIGRP Routes */
Really it is not scope, but sort of distance to the destination.
NOWHERE are reserved for not existing destinations, HOST is our
local addresses, LINK are destinations, located on directly attached
link and UNIVERSE is everywhere in the Universe.
Intermediate values are also possible f.e. interior routes
could be assigned a value between UNIVERSE and LINK.
/* User defined values */
#define RTM_F_NOTIFY 0x100 /* Notify user of route change */
#define RTM_F_CLONED 0x200 /* This route is cloned */
#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
#define RTM_F_PREFIX 0x800 /* Prefix addresses */
#define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
#define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */
#define RTM_F_OFFLOAD 0x4000 /* route is offloaded */
#define RTM_F_TRAP 0x8000 /* route is trapping packets */
/* Reserved table identifiers */
/* User defined values */
/* Routing message attributes */
RTA_PROTOINFO, /* no longer used */
RTA_SESSION, /* no longer used */
RTA_MP_ALGO, /* no longer used */
#define RTA_MAX (__RTA_MAX - 1)
#define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
#define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
/* RTM_MULTIPATH --- array of struct rtnexthop.
* "struct rtnexthop" describes all necessary nexthop information,
* i.e. parameters of path to a destination via this nexthop.
* At the moment it is impossible to set different prefsrc, mtu, window
* and rtt for different paths from multipath.
unsigned char rtnh_flags;
#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
#define RTNH_F_ONLINK 4 /* Gateway is forced on link */
#define RTNH_F_OFFLOAD 8 /* offloaded route */
#define RTNH_F_LINKDOWN 16 /* carrier-down on nexthop */
#define RTNH_F_UNRESOLVED 32 /* The entry is unresolved (ipmr) */
#define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | RTNH_F_OFFLOAD)
/* Macros to handle hexthops */
#define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
#define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
((int)(rtnh)->rtnh_len) <= (len))
#define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
#define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
#define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
#define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
__kernel_sa_family_t rtvia_family;
#define RTNETLINK_HAVE_PEERINFO 1
/* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
#define RTAX_UNSPEC RTAX_UNSPEC
#define RTAX_LOCK RTAX_LOCK
#define RTAX_MTU RTAX_MTU
#define RTAX_WINDOW RTAX_WINDOW
#define RTAX_RTT RTAX_RTT
#define RTAX_RTTVAR RTAX_RTTVAR
#define RTAX_SSTHRESH RTAX_SSTHRESH
#define RTAX_CWND RTAX_CWND
#define RTAX_ADVMSS RTAX_ADVMSS
#define RTAX_REORDERING RTAX_REORDERING
#define RTAX_HOPLIMIT RTAX_HOPLIMIT
#define RTAX_INITCWND RTAX_INITCWND
#define RTAX_FEATURES RTAX_FEATURES
#define RTAX_RTO_MIN RTAX_RTO_MIN
#define RTAX_INITRWND RTAX_INITRWND
#define RTAX_QUICKACK RTAX_QUICKACK
#define RTAX_CC_ALGO RTAX_CC_ALGO
#define RTAX_FASTOPEN_NO_COOKIE RTAX_FASTOPEN_NO_COOKIE
#define RTAX_MAX (__RTAX_MAX - 1)
#define RTAX_FEATURE_ECN (1 << 0)
#define RTAX_FEATURE_SACK (1 << 1)
#define RTAX_FEATURE_TIMESTAMP (1 << 2)
#define RTAX_FEATURE_ALLFRAG (1 << 3)
#define RTAX_FEATURE_MASK (RTAX_FEATURE_ECN | RTAX_FEATURE_SACK | \
RTAX_FEATURE_TIMESTAMP | RTAX_FEATURE_ALLFRAG)