Changeset View
Changeset View
Standalone View
Standalone View
sys/netlink/route/route.h
- This file was added.
/* | |||||
* Route-related (RTM_<NEW|DEL|GET>ROUTE) message header and attributes. | |||||
*/ | |||||
#ifndef _NETLINK_ROUTE_ROUTE_H_ | |||||
#define _NETLINK_ROUTE_ROUTE_H_ | |||||
/* Base header for all of the relevant messages */ | |||||
struct rtmsg { | |||||
unsigned char rtm_family; /* address family */ | |||||
unsigned char rtm_dst_len; /* Prefix length */ | |||||
unsigned char rtm_src_len; /* Source prefix length (not used) */ | |||||
unsigned char rtm_tos; /* Type of service (not used) */ | |||||
unsigned char rtm_table; /* rtable id */ | |||||
unsigned char rtm_protocol; /* Routing protocol id (RTPROT_) */ | |||||
unsigned char rtm_scope; /* Route distance (RT_SCOPE_) */ | |||||
unsigned char rtm_type; /* Route type (RTN_) */ | |||||
unsigned rtm_flags; /* Route flags (RTM_F_) */ | |||||
}; | |||||
/* | |||||
* RFC 3549, 3.1.1, route type (rtm_type field). | |||||
*/ | |||||
enum { | |||||
RTN_UNSPEC, | |||||
RTN_UNICAST, /* Unicast route */ | |||||
RTN_LOCAL, /* Accept locally (not supported) */ | |||||
RTN_BROADCAST, /* Accept locally as broadcast, send as broadcast */ | |||||
RTN_ANYCAST, /* Accept locally as broadcast, but send as unicast */ | |||||
RTN_MULTICAST, /* Multicast route */ | |||||
RTN_BLACKHOLE, /* Drop traffic towards destination */ | |||||
RTN_UNREACHABLE,/* Destination is unreachable */ | |||||
RTN_PROHIBIT, /* Administratively prohibited */ | |||||
RTN_THROW, /* Not in this table (not supported) */ | |||||
RTN_NAT, /* Translate this address (not supported) */ | |||||
RTN_XRESOLVE, /* Use external resolver (not supported) */ | |||||
__RTN_MAX, | |||||
}; | |||||
#define RTN_MAX (__RTN_MAX - 1) | |||||
/* | |||||
* RFC 3549, 3.1.1, protocol (Identifies what/who added the route). | |||||
* Values larger than RTPROT_STATIC(4) are not interpreted by the | |||||
* kernel, they are just for user information. | |||||
*/ | |||||
#define RTPROT_UNSPEC 0 | |||||
#define RTPROT_REDIRECT 1 /* Route installed by ICMP redirect */ | |||||
#define RTPROT_KERNEL 2 /* Route installed by kernel */ | |||||
#define RTPROT_BOOT 3 /* Route installed during boot */ | |||||
#define RTPROT_STATIC 4 /* Route installed by administrator */ | |||||
#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_KEEPALIVED 18 /* Keepalived daemon */ | |||||
#define RTPROT_BABEL 42 /* Babel daemon */ | |||||
#define RTPROT_OPENR 99 /* Open Routing (Open/R) Routes */ | |||||
#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 */ | |||||
/* | |||||
* RFC 3549 3.1.1 Route scope (valid distance to destination). | |||||
* | |||||
* The values between RT_SCOPE_UNIVERSE(0) and RT_SCOPE_SITE(200) | |||||
* are available to the user. | |||||
*/ | |||||
enum rt_scope_t { | |||||
RT_SCOPE_UNIVERSE = 0, | |||||
/* User defined values */ | |||||
RT_SCOPE_SITE = 200, | |||||
RT_SCOPE_LINK = 253, | |||||
RT_SCOPE_HOST = 254, | |||||
RT_SCOPE_NOWHERE = 255 | |||||
}; | |||||
/* | |||||
* RFC 3549 3.1.1 Route flags. | |||||
*/ | |||||
#define RTM_F_NOTIFY 0x100 /* Notify user of route change */ | |||||
#define RTM_F_CLONED 0x200 /* This route is cloned (not used) */ | |||||
#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */ | |||||
#define RTM_F_PREFIX 0x800 /* Prefix addresses */ | |||||
#define RTM_F_LOOKUP_TABLE 0x1000 /* set tableid 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 */ | |||||
#define RTM_F_OFFLOAD_FAILED 0x20000000 /* route offload failed */ | |||||
/* Compatibility handling helpers */ | |||||
#ifndef _KERNEL | |||||
#define NL_RTM_HDRLEN ((int)sizeof(struct rtmsg)) | |||||
#define RTM_RTA(_rtm) ((struct rtattr *)(NL_ITEM_DATA(_rtm) + NL_RTM_HDRLEN)) | |||||
#define RTM_PAYLOAD(_hdr) NLMSG_PAYLOAD((_hdr), NL_RTM_HDRLEN) | |||||
#endif | |||||
/* | |||||
* Routing table identifiers. | |||||
* FreeBSD route table numbering starts from 0, where 0 is a valid default routing table. | |||||
* Indicating "all tables" via rtsock can be done by not including RTA_TABLE attribute | |||||
* and keeping rtm_table=0 (compatibility) or setting RTA_TABLE value to RT_TABLE_UNSPEC. | |||||
*/ | |||||
#define RT_TABLE_MAIN 0 /* RT_DEFAULT_FIB */ | |||||
#define RT_TABLE_UNSPEC 0xFFFFFFFF /* RT_ALL_FIBS */ | |||||
enum rtattr_type_t { | |||||
NL_RTA_UNSPEC, | |||||
NL_RTA_DST, | |||||
NL_RTA_SRC, | |||||
NL_RTA_IIF, | |||||
NL_RTA_OIF, | |||||
NL_RTA_GATEWAY, | |||||
NL_RTA_PRIORITY, | |||||
NL_RTA_PREFSRC, | |||||
NL_RTA_METRICS, | |||||
NL_RTA_MULTIPATH, | |||||
NL_RTA_PROTOINFO, /* not used / deprecated */ | |||||
NL_RTA_FLOW, | |||||
NL_RTA_CACHEINFO, /* not used */ | |||||
NL_RTA_SESSION, /* not used / deprecated */ | |||||
NL_RTA_MP_ALGO, /* not used / deprecated */ | |||||
NL_RTA_TABLE, | |||||
NL_RTA_MARK, /* not used */ | |||||
NL_RTA_MFC_STATS, | |||||
NL_RTA_VIA, | |||||
NL_RTA_NEWDST, | |||||
NL_RTA_PREF, | |||||
NL_RTA_ENCAP_TYPE, | |||||
NL_RTA_ENCAP, | |||||
NL_RTA_EXPIRES, | |||||
NL_RTA_PAD, | |||||
NL_RTA_UID, | |||||
NL_RTA_TTL_PROPAGATE, | |||||
imp: If we start at 0, is there another #define that this ould be useful to define as since this is… | |||||
Done Inline ActionsSorry, I'm not sure I get this. Could you please rephrase it? melifaro: Sorry, I'm not sure I get this. Could you please rephrase it?
Quite a lot of (currently Linux)… | |||||
NL_RTA_IP_PROTO, | |||||
NL_RTA_SPORT, | |||||
NL_RTA_DPORT, | |||||
NL_RTA_NH_ID, | |||||
__RTA_MAX | |||||
}; | |||||
#define NL_RTA_MAX (__RTA_MAX - 1) | |||||
#ifndef _KERNEL | |||||
/* | |||||
* RTA_* space has clashes with rtsock namespace. | |||||
* Use NL_RTA_ prefix in the kernel and map to | |||||
* RTA_ for userland. | |||||
*/ | |||||
#define RTA_UNSPEC NL_RTA_UNSPEC | |||||
#define RTA_DST NL_RTA_DST | |||||
#define RTA_SRC NL_RTA_SRC | |||||
#define RTA_IIF NL_RTA_IIF | |||||
#define RTA_OIF NL_RTA_OIF | |||||
#define RTA_GATEWAY NL_RTA_GATEWAY | |||||
#define RTA_PRIORITY NL_RTA_PRIORITY | |||||
#define RTA_PREFSRC NL_RTA_PREFSRC | |||||
#define RTA_METRICS NL_RTA_METRICS | |||||
#define RTA_MULTIPATH NL_RTA_MULTIPATH | |||||
#define RTA_PROTOINFO NL_RTA_PROTOINFO | |||||
#define RTA_FLOW NL_RTA_FLOW | |||||
#define RTA_CACHEINFO NL_RTA_CACHEINFO | |||||
#define RTA_SESSION NL_RTA_SESSION | |||||
#define RTA_MP_ALGO NL_RTA_MP_ALGO | |||||
#define RTA_TABLE NL_RTA_TABLE | |||||
#define RTA_MARK NL_RTA_MARK | |||||
#define RTA_MFC_STATS NL_RTA_MFC_STATS | |||||
#define RTA_VIA NL_RTA_VIA | |||||
#define RTA_NEWDST NL_RTA_NEWDST | |||||
#define RTA_PREF NL_RTA_PREF | |||||
#define RTA_ENCAP_TYPE NL_RTA_ENCAP_TYPE | |||||
#define RTA_ENCAP NL_RTA_ENCAP | |||||
#define RTA_EXPIRES NL_RTA_EXPIRES | |||||
#define RTA_PAD NL_RTA_PAD | |||||
#define RTA_UID NL_RTA_UID | |||||
#define RTA_TTL_PROPAGATE NL_RTA_TTL_PROPAGATE | |||||
#define RTA_IP_PROTO NL_RTA_IP_PROTO | |||||
#define RTA_SPORT NL_RTA_SPORT | |||||
#define RTA_DPORT NL_RTA_DPORT | |||||
#define RTA_NH_ID NL_RTA_NH_ID | |||||
#define RTA_MAX NL_RTA_MAX | |||||
#endif | |||||
/* route attribute header */ | |||||
struct rtattr { | |||||
unsigned short rta_len; | |||||
unsigned short rta_type; | |||||
}; | |||||
#define NL_RTA_ALIGN_SIZE NL_ITEM_ALIGN_SIZE | |||||
#define NL_RTA_ALIGN NL_ITEM_ALIGN | |||||
#define NL_RTA_HDRLEN ((int)sizeof(struct rtattr)) | |||||
#define NL_RTA_DATA_LEN(_rta) ((int)((_rta)->rta_len - NL_RTA_HDRLEN)) | |||||
#define NL_RTA_DATA(_rta) NL_ITEM_DATA(_rta, NL_RTA_HDRLEN) | |||||
#define NL_RTA_DATA_CONST(_rta) NL_ITEM_DATA_CONST(_rta, NL_RTA_HDRLEN) | |||||
/* Compatibility attribute handling helpers */ | |||||
#ifndef _KERNEL | |||||
#define RTA_ALIGNTO NL_RTA_ALIGN_SIZE | |||||
#define RTA_ALIGN(_len) NL_RTA_ALIGN(_len) | |||||
#define _RTA_LEN(_rta) ((int)(_rta)->rta_len) | |||||
#define _RTA_ALIGNED_LEN(_rta) RTA_ALIGN(_RTA_LEN(_rta)) | |||||
#define RTA_OK(_rta, _len) NL_ITEM_OK(_rta, _len, NL_RTA_HDRLEN, _RTA_LEN) | |||||
#define RTA_NEXT(_rta, _len) NL_ITEM_ITER(_rta, _len, _RTA_ALIGNED_LEN) | |||||
#define RTA_LENGTH(_len) (NL_RTA_HDRLEN + (_len)) | |||||
#define RTA_SPACE(_len) RTA_ALIGN(RTA_LENGTH(_len)) | |||||
#define RTA_DATA(_rta) NL_RTA_DATA(_rta) | |||||
#define RTA_PAYLOAD(_rta) ((int)(_RTA_LEN(_rta) - NL_RTA_HDRLEN) | |||||
#endif | |||||
/* RTA attribute headers */ | |||||
/* RTA_VIA */ | |||||
struct rtvia { | |||||
sa_family_t rtvia_family; | |||||
uint8_t rtvia_addr[0]; | |||||
}; | |||||
/* | |||||
* RTA_METRICS is a nested attribute, consistes of array of 'struct rtattr' | |||||
* with the types defined below. Most of the values are uint32_t. | |||||
*/ | |||||
enum { | |||||
NL_RTAX_UNSPEC, | |||||
#define NL_RTAX_UNSPEC NL_RTAX_UNSPEC | |||||
NL_RTAX_LOCK, | |||||
#define NL_RTAX_LOCK NL_RTAX_LOCK | |||||
NL_RTAX_MTU, | |||||
#define NL_RTAX_MTU NL_RTAX_MTU | |||||
NL_RTAX_WINDOW, | |||||
#define NL_RTAX_WINDOW NL_RTAX_WINDOW | |||||
NL_RTAX_RTT, | |||||
#define NL_RTAX_RTT NL_RTAX_RTT | |||||
NL_RTAX_RTTVAR, | |||||
#define NL_RTAX_RTTVAR NL_RTAX_RTTVAR | |||||
NL_RTAX_SSTHRESH, | |||||
#define NL_RTAX_SSTHRESH NL_RTAX_SSTHRESH | |||||
NL_RTAX_CWND, | |||||
#define NL_RTAX_CWND NL_RTAX_CWND | |||||
NL_RTAX_ADVMSS, | |||||
#define NL_RTAX_ADVMSS NL_RTAX_ADVMSS | |||||
NL_RTAX_REORDERING, | |||||
#define NL_RTAX_REORDERING NL_RTAX_REORDERING | |||||
NL_RTAX_HOPLIMIT, | |||||
#define NL_RTAX_HOPLIMIT NL_RTAX_HOPLIMIT | |||||
NL_RTAX_INITCWND, | |||||
#define NL_RTAX_INITCWND NL_RTAX_INITCWND | |||||
NL_RTAX_FEATURES, | |||||
#define NL_RTAX_FEATURES NL_RTAX_FEATURES | |||||
NL_RTAX_RTO_MIN, | |||||
#define NL_RTAX_RTO_MIN NL_RTAX_RTO_MIN | |||||
NL_RTAX_INITRWND, | |||||
#define NL_RTAX_INITRWND NL_RTAX_INITRWND | |||||
NL_RTAX_QUICKACK, | |||||
#define NL_RTAX_QUICKACK NL_RTAX_QUICKACK | |||||
NL_RTAX_CC_ALGO, | |||||
#define NL_RTAX_CC_ALGO NL_RTAX_CC_ALGO | |||||
NL_RTAX_FASTOPEN_NO_COOKIE, | |||||
#define NL_RTAX_FASTOPEN_NO_COOKIE NL_RTAX_FASTOPEN_NO_COOKIE | |||||
__NL_RTAX_MAX | |||||
}; | |||||
#define NL_RTAX_MAX (__NL_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) | |||||
#ifndef _KERNEL | |||||
/* | |||||
* RTAX_* space clashes with rtsock namespace. | |||||
* Use NL_RTAX_ prefix in the kernel and map to | |||||
* RTAX_ for userland. | |||||
*/ | |||||
#define RTAX_UNSPEC NL_RTAX_UNSPEC | |||||
#define RTAX_LOCK NL_RTAX_LOCK | |||||
#define RTAX_MTU NL_RTAX_MTU | |||||
#define RTAX_WINDOW NL_RTAX_WINDOW | |||||
#define RTAX_RTT NL_RTAX_RTT | |||||
#define RTAX_RTTVAR NL_RTAX_RTTVAR | |||||
#define RTAX_SSTHRESH NL_RTAX_SSTHRESH | |||||
#define RTAX_CWND NL_RTAX_CWND | |||||
#define RTAX_ADVMSS NL_RTAX_ADVMSS | |||||
#define RTAX_REORDERING NL_RTAX_REORDERING | |||||
#define RTAX_HOPLIMIT NL_RTAX_HOPLIMIT | |||||
#define RTAX_INITCWND NL_RTAX_INITCWND | |||||
#define RTAX_FEATURES NL_RTAX_FEATURES | |||||
#define RTAX_RTO_MIN NL_RTAX_RTO_MIN | |||||
#define RTAX_INITRWND NL_RTAX_INITRWND | |||||
#define RTAX_QUICKACK NL_RTAX_QUICKACK | |||||
#define RTAX_CC_ALGO NL_RTAX_CC_ALGO | |||||
#define RTAX_FASTOPEN_NO_COOKIE NL_RTAX_FASTOPEN_NO_COOKIE | |||||
#endif | |||||
/* RTA_MULTIPATH consists of an array of rtnexthop structures. */ | |||||
struct rtnexthop { | |||||
unsigned short rtnh_len; | |||||
unsigned char rtnh_flags; | |||||
unsigned char rtnh_hops; | |||||
int rtnh_ifindex; | |||||
}; | |||||
/* rtnh_flags */ | |||||
#define RTNH_F_DEAD 0x01 /* Nexthop is dead (used by multipath) */ | |||||
#define RTNH_F_PERVASIVE 0x02 /* Do recursive gateway lookup */ | |||||
#define RTNH_F_ONLINK 0x04 /* Gateway is forced on link */ | |||||
#define RTNH_F_OFFLOAD 0x08 /* Nexthop is offloaded */ | |||||
#define RTNH_F_LINKDOWN 0x10 /* carrier-down on nexthop */ | |||||
#define RTNH_F_UNRESOLVED 0x20 /* The entry is unresolved (ipmr) */ | |||||
#define RTNH_F_TRAP 0x40 /* Nexthop is trapping packets */ | |||||
#define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | \ | |||||
RTNH_F_OFFLOAD | RTNH_F_TRAP) | |||||
/* Macros to handle hexthops */ | |||||
#define RTNH_ALIGNTO NL_ITEM_ALIGN_SIZE | |||||
#define RTNH_ALIGN(_len) NL_ITEM_ALIGN(_len) | |||||
#define RTNH_HDRLEN ((int)sizeof(struct rtnexthop)) | |||||
#define _RTNH_LEN(_nh) ((int)(_nh)->rtnh_len) | |||||
#define _RTNH_ALIGNED_LEN(_nh) RTNH_ALIGN(_RTNH_LEN(_nh)) | |||||
#define RTNH_OK(_nh, _len) NL_ITEM_OK(_nh, _len, RTNH_HDRLEN, _RTNH_LEN) | |||||
//#define RTNH_NEXT(_nh) (struct rtnexthop *)NL_ITEM_DATA(_nh, RTNH_HDRLEN) | |||||
//#define RTNH_NEXT(_nh) NL_ITEM_NEXT(_nh, _RTNH_ALIGNED_LEN(_nh)) | |||||
#define RTNH_LENGTH(_len) (RTNH_HDRLEN + (_len)) | |||||
#define RTNH_SPACE(_len) RTNH_ALIGN(RTNH_LENGTH(_len)) | |||||
#define RTNH_DATA(_nh) ((struct rtattr *)NL_ITEM_DATA(_nh, RTNH_HDRLEN)) | |||||
struct rtgenmsg { | |||||
unsigned char rtgen_family; | |||||
}; | |||||
#endif |
If we start at 0, is there another #define that this ould be useful to define as since this is just a compat item?