rtnetlink(7) Miscellaneous Information Manual rtnetlink(7) rtnetlink - Linux routing socket #include #include #include #include rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE); Rtnetlink . ( ), . , IP-, (link parameters), (neighbor setups), (queueing disciplines), NETLINK_ROUTE. netlink; netlink(7). rtnetlink : struct rtattr { unsigned short rta_len; /* */ unsigned short rta_type; /* */ /* */ }; RTA_* libnetlink, rtnetlink(3). Rtnetlink ( netlink): RTM_NEWLINK RTM_DELLINK RTM_GETLINK , . ifinfomsg, rtattr. struct ifinfomsg { unsigned char ifi_family; /* AF_UNSPEC */ unsigned short ifi_type; /* */ int ifi_index; /* */ unsigned int ifi_flags; /* */ unsigned int ifi_change; /* */ }; ifi_flags , netdevice(7); ifi_index -- ( Linux 3.7 RTM_NEWLINK; (link) ifindex); ifi_change 0xFFFFFFFF. rta_type -------------------------------------------------------------------------------------------------------------------------------------------- IFLA_UNSPEC - IFLA_ADDRESS L2 IFLA_BROADCAST L2 IFLA_IFNAME asciiz IFLA_MTU unsigned int MTU IFLA_LINK int IFLA_QDISC asciiz IFLA_STATS IFLA_PERM_ADDRESS hardware address provided by device (since Linux 5.5) IFLA_STATS -- struct rtnl_link_stats ( Linux 2.4 -- struct net_device_stats). 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 Linux 2.0. In Linux 2.2, these messages support IPv4 and IPv6 addresses. They contain an ifaddrmsg structure, optionally followed by rtattr routing attributes. struct ifaddrmsg { unsigned char ifa_family; /* */ unsigned char ifa_prefixlen; /* */ unsigned char ifa_flags; /* */ unsigned char ifa_scope; /* */ unsigned int ifa_index; /* */ }; ifa_family (AF_INET AF_INET6), ifa_prefixlen -- , ( IPv4), ifa_scope -- , ifa_index -- , . ifa_flags -- : IFA_F_SECONDARY -- ( ), IFA_F_PERMANENT -- , . rta_type ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- IFA_UNSPEC - IFA_ADDRESS IFA_LOCAL IFA_LABEL asciiz IFA_BROADCAST IFA_ANYCAST anycast IFA_CACHEINFO struct ifa_cacheinfo RTM_NEWROUTE RTM_DELROUTE RTM_GETROUTE , . rtmsg rtattr. RTM_GETROUTE, rtm_dst_len rtm_src_len 0, . , rtm_table rtm_protocol, 0 (wildcard). struct rtmsg { unsigned char rtm_family; /* Address family of route */ unsigned char rtm_dst_len; /* Length of destination */ unsigned char rtm_src_len; /* Length of source */ unsigned char rtm_tos; /* TOS filter */ unsigned char rtm_table; /* Routing table ID; see RTA_TABLE below */ unsigned char rtm_protocol; /* Routing protocol; see below */ unsigned char rtm_scope; /* See below */ unsigned char rtm_type; /* See below */ unsigned int rtm_flags; }; rtm_type --------------------------------------------------------------------------------------------------------------------------------------------- RTN_UNSPEC RTN_UNICAST RTN_LOCAL RTN_BROADCAST ( ) RTN_ANYCAST ( ) RTN_MULTICAST RTN_BLACKHOLE RTN_UNREACHABLE RTN_PROHIBIT RTN_THROW RTN_NAT RTN_XRESOLVE ( ) ----------------------------------------------------------------------------------- RTPROT_UNSPEC RTPROT_REDIRECT - ICMP ( ) RTPROT_KERNEL RTPROT_BOOT RTPROT_STATIC RTPROT_STATIC , . . . rtm_scope -- : RT_SCOPE_UNIVERSE RT_SCOPE_SITE RT_SCOPE_LINK RT_SCOPE_HOST RT_SCOPE_NOWHERE RT_SCOPE_UNIVERSE RT_SCOPE_SITE . rtm_flags : RTM_F_NOTIFY -- rtnetlink RTM_F_CLONED RTM_F_EQUALIZE ( ) rtm_table : RT_TABLE_UNSPEC RT_TABLE_DEFAULT RT_TABLE_MAIN RT_TABLE_LOCAL RT_TABLE_UNSPEC RT_TABLE_DEFAULT. rta_type ------------------------------------------------------------------------------------------------------------------------------------------- RTA_UNSPEC - RTA_DST RTA_SRC RTA_IIF int RTA_OIF int RTA_GATEWAY RTA_PRIORITY int RTA_PREFSRC Preferred source address RTA_METRICS int RTA_MULTIPATH Multipath nexthop data br (see below). RTA_PROTOINFO No longer used RTA_FLOW int Route realm RTA_CACHEINFO struct rta_cacheinfo (see linux/rtnetlink.h) RTA_SESSION No longer used RTA_MP_ALGO No longer used RTA_TABLE int Routing table ID; if set, rtm_table is ignored RTA_MARK int RTA_MFC_STATS struct rta_mfc_stats (see linux/rtnetlink.h) RTA_VIA struct rtvia Gateway in different AF (see below) RTA_NEWDST Change packet destination address RTA_PREF char RFC4191 IPv6 router preference (see below) RTA_ENCAP_TYPE short Encapsulation type for lwtunnels (see below) RTA_ENCAP Defined by RTA_ENCAP_TYPE RTA_EXPIRES int Expire time for IPv6 routes (in seconds) RTA_MULTIPATH contains several packed instances of struct rtnexthop together with nested RTAs (RTA_GATEWAY): struct rtnexthop { unsigned short rtnh_len; /* Length of struct + length of RTAs */ unsigned char rtnh_flags; /* Flags (see linux/rtnetlink.h) */ unsigned char rtnh_hops; /* Nexthop priority */ int rtnh_ifindex; /* Interface index for this nexthop */ } There exist a bunch of RTNH_* macros similar to RTA_* and NLHDR_* macros useful to handle these structures. struct rtvia { unsigned short rtvia_family; unsigned char rtvia_addr[0]; }; rtvia_addr is the address, rtvia_family is its family type. RTA_PREF may contain values ICMPV6_ROUTER_PREF_LOW, ICMPV6_ROUTER_PREF_MEDIUM, and ICMPV6_ROUTER_PREF_HIGH defined incw . RTA_ENCAP_TYPE may contain values LWTUNNEL_ENCAP_MPLS, LWTUNNEL_ENCAP_IP, LWTUNNEL_ENCAP_ILA, or LWTUNNEL_ENCAP_IP6 defined in . ! RTM_NEWNEIGH RTM_DELNEIGH RTM_GETNEIGH , (, ARP). ndmsg: struct ndmsg { unsigned char ndm_family; int ndm_ifindex; /* Interface index */ __u16 ndm_state; /* State */ __u8 ndm_flags; /* Flags */ __u8 ndm_type; }; struct nda_cacheinfo { __u32 ndm_confirmed; __u32 ndm_used; __u32 ndm_updated; __u32 ndm_refcnt; }; ndm_state : NUD_INCOMPLETE NUD_REACHABLE NUD_STALE NUD_DELAY NUD_PROBE NUD_FAILED NUD_NOARP NUD_PERMANENT ndm_flags: NTF_PROXY arp NTF_ROUTER IPv6 rtattr rta_type: NDA_UNSPEC NDA_DST NDA_LLADDR NDA_CACHEINFO rta_type NDA_CACHEINFO, struct nda_cacheinfo. RTM_NEWRULE RTM_DELRULE RTM_GETRULE , . struct rtmsg. RTM_NEWQDISC RTM_DELQDISC RTM_GETQDISC , . struct tcmsg, . struct tcmsg { unsigned char tcm_family; int tcm_ifindex; /* */ __u32 tcm_handle; /* qdisc */ __u32 tcm_parent; /* qdisc */ __u32 tcm_info; }; rta_type ---------------------------------------------------------------------------------------------------------------------------------------------------------------- TCA_UNSPEC - TCA_KIND asciiz - TCA_OPTIONS qdisc TCA_STATS struct tc_stats qdisc TCA_XSTATS qdisc - . TCA_RATE struct tc_estimator , qdisc. . RTM_NEWTCLASS RTM_DELTCLASS RTM_GETTCLASS , . struct tcmsg, . RTM_NEWTFILTER RTM_DELTFILTER RTM_GETTFILTER , . struct tcmsg, . rtnetlink Linux 2.2. . . cmsg(3), rtnetlink(3), ip(7), netlink(7) aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . rtnetlink(7)