rtnetlink.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. #ifndef __LINUX_RTNETLINK_H
  2. #define __LINUX_RTNETLINK_H
  3. #include <linux/netlink.h>
  4. /****
  5. * Routing/neighbour discovery messages.
  6. ****/
  7. /* Types of messages */
  8. enum {
  9. RTM_BASE = 16,
  10. #define RTM_BASE RTM_BASE
  11. RTM_NEWLINK = 16,
  12. #define RTM_NEWLINK RTM_NEWLINK
  13. RTM_DELLINK,
  14. #define RTM_DELLINK RTM_DELLINK
  15. RTM_GETLINK,
  16. #define RTM_GETLINK RTM_GETLINK
  17. RTM_SETLINK,
  18. #define RTM_SETLINK RTM_SETLINK
  19. RTM_NEWADDR = 20,
  20. #define RTM_NEWADDR RTM_NEWADDR
  21. RTM_DELADDR,
  22. #define RTM_DELADDR RTM_DELADDR
  23. RTM_GETADDR,
  24. #define RTM_GETADDR RTM_GETADDR
  25. RTM_NEWROUTE = 24,
  26. #define RTM_NEWROUTE RTM_NEWROUTE
  27. RTM_DELROUTE,
  28. #define RTM_DELROUTE RTM_DELROUTE
  29. RTM_GETROUTE,
  30. #define RTM_GETROUTE RTM_GETROUTE
  31. RTM_NEWNEIGH = 28,
  32. #define RTM_NEWNEIGH RTM_NEWNEIGH
  33. RTM_DELNEIGH,
  34. #define RTM_DELNEIGH RTM_DELNEIGH
  35. RTM_GETNEIGH,
  36. #define RTM_GETNEIGH RTM_GETNEIGH
  37. RTM_NEWRULE = 32,
  38. #define RTM_NEWRULE RTM_NEWRULE
  39. RTM_DELRULE,
  40. #define RTM_DELRULE RTM_DELRULE
  41. RTM_GETRULE,
  42. #define RTM_GETRULE RTM_GETRULE
  43. RTM_NEWQDISC = 36,
  44. #define RTM_NEWQDISC RTM_NEWQDISC
  45. RTM_DELQDISC,
  46. #define RTM_DELQDISC RTM_DELQDISC
  47. RTM_GETQDISC,
  48. #define RTM_GETQDISC RTM_GETQDISC
  49. RTM_NEWTCLASS = 40,
  50. #define RTM_NEWTCLASS RTM_NEWTCLASS
  51. RTM_DELTCLASS,
  52. #define RTM_DELTCLASS RTM_DELTCLASS
  53. RTM_GETTCLASS,
  54. #define RTM_GETTCLASS RTM_GETTCLASS
  55. RTM_NEWTFILTER = 44,
  56. #define RTM_NEWTFILTER RTM_NEWTFILTER
  57. RTM_DELTFILTER,
  58. #define RTM_DELTFILTER RTM_DELTFILTER
  59. RTM_GETTFILTER,
  60. #define RTM_GETTFILTER RTM_GETTFILTER
  61. RTM_NEWACTION = 48,
  62. #define RTM_NEWACTION RTM_NEWACTION
  63. RTM_DELACTION,
  64. #define RTM_DELACTION RTM_DELACTION
  65. RTM_GETACTION,
  66. #define RTM_GETACTION RTM_GETACTION
  67. RTM_NEWPREFIX = 52,
  68. #define RTM_NEWPREFIX RTM_NEWPREFIX
  69. RTM_GETPREFIX = 54,
  70. #define RTM_GETPREFIX RTM_GETPREFIX
  71. RTM_GETMULTICAST = 58,
  72. #define RTM_GETMULTICAST RTM_GETMULTICAST
  73. RTM_GETANYCAST = 62,
  74. #define RTM_GETANYCAST RTM_GETANYCAST
  75. RTM_NEWNEIGHTBL = 64,
  76. #define RTM_NEWNEIGHTBL RTM_NEWNEIGHTBL
  77. RTM_GETNEIGHTBL = 66,
  78. #define RTM_GETNEIGHTBL RTM_GETNEIGHTBL
  79. RTM_SETNEIGHTBL,
  80. #define RTM_SETNEIGHTBL RTM_SETNEIGHTBL
  81. __RTM_MAX,
  82. #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
  83. };
  84. #define RTM_NR_MSGTYPES (RTM_MAX + 1 - RTM_BASE)
  85. #define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
  86. #define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
  87. /*
  88. Generic structure for encapsulation of optional route information.
  89. It is reminiscent of sockaddr, but with sa_family replaced
  90. with attribute type.
  91. */
  92. struct rtattr
  93. {
  94. unsigned short rta_len;
  95. unsigned short rta_type;
  96. };
  97. /* Macros to handle rtattributes */
  98. #define RTA_ALIGNTO 4
  99. #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
  100. #define RTA_OK(rta,len) ((len) >= (int)sizeof(struct rtattr) && \
  101. (rta)->rta_len >= sizeof(struct rtattr) && \
  102. (rta)->rta_len <= (len))
  103. #define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
  104. (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
  105. #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
  106. #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
  107. #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
  108. #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
  109. /******************************************************************************
  110. * Definitions used in routing table administration.
  111. ****/
  112. struct rtmsg
  113. {
  114. unsigned char rtm_family;
  115. unsigned char rtm_dst_len;
  116. unsigned char rtm_src_len;
  117. unsigned char rtm_tos;
  118. unsigned char rtm_table; /* Routing table id */
  119. unsigned char rtm_protocol; /* Routing protocol; see below */
  120. unsigned char rtm_scope; /* See below */
  121. unsigned char rtm_type; /* See below */
  122. unsigned rtm_flags;
  123. };
  124. /* rtm_type */
  125. enum
  126. {
  127. RTN_UNSPEC,
  128. RTN_UNICAST, /* Gateway or direct route */
  129. RTN_LOCAL, /* Accept locally */
  130. RTN_BROADCAST, /* Accept locally as broadcast,
  131. send as broadcast */
  132. RTN_ANYCAST, /* Accept locally as broadcast,
  133. but send as unicast */
  134. RTN_MULTICAST, /* Multicast route */
  135. RTN_BLACKHOLE, /* Drop */
  136. RTN_UNREACHABLE, /* Destination is unreachable */
  137. RTN_PROHIBIT, /* Administratively prohibited */
  138. RTN_THROW, /* Not in this table */
  139. RTN_NAT, /* Translate this address */
  140. RTN_XRESOLVE, /* Use external resolver */
  141. __RTN_MAX
  142. };
  143. #define RTN_MAX (__RTN_MAX - 1)
  144. /* rtm_protocol */
  145. #define RTPROT_UNSPEC 0
  146. #define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
  147. not used by current IPv4 */
  148. #define RTPROT_KERNEL 2 /* Route installed by kernel */
  149. #define RTPROT_BOOT 3 /* Route installed during boot */
  150. #define RTPROT_STATIC 4 /* Route installed by administrator */
  151. /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
  152. they are just passed from user and back as is.
  153. It will be used by hypothetical multiple routing daemons.
  154. Note that protocol values should be standardized in order to
  155. avoid conflicts.
  156. */
  157. #define RTPROT_GATED 8 /* Apparently, GateD */
  158. #define RTPROT_RA 9 /* RDISC/ND router advertisements */
  159. #define RTPROT_MRT 10 /* Merit MRT */
  160. #define RTPROT_ZEBRA 11 /* Zebra */
  161. #define RTPROT_BIRD 12 /* BIRD */
  162. #define RTPROT_DNROUTED 13 /* DECnet routing daemon */
  163. #define RTPROT_XORP 14 /* XORP */
  164. #define RTPROT_NTK 15 /* Netsukuku */
  165. /* rtm_scope
  166. Really it is not scope, but sort of distance to the destination.
  167. NOWHERE are reserved for not existing destinations, HOST is our
  168. local addresses, LINK are destinations, located on directly attached
  169. link and UNIVERSE is everywhere in the Universe.
  170. Intermediate values are also possible f.e. interior routes
  171. could be assigned a value between UNIVERSE and LINK.
  172. */
  173. enum rt_scope_t
  174. {
  175. RT_SCOPE_UNIVERSE=0,
  176. /* User defined values */
  177. RT_SCOPE_SITE=200,
  178. RT_SCOPE_LINK=253,
  179. RT_SCOPE_HOST=254,
  180. RT_SCOPE_NOWHERE=255
  181. };
  182. /* rtm_flags */
  183. #define RTM_F_NOTIFY 0x100 /* Notify user of route change */
  184. #define RTM_F_CLONED 0x200 /* This route is cloned */
  185. #define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
  186. #define RTM_F_PREFIX 0x800 /* Prefix addresses */
  187. /* Reserved table identifiers */
  188. enum rt_class_t
  189. {
  190. RT_TABLE_UNSPEC=0,
  191. /* User defined values */
  192. RT_TABLE_DEFAULT=253,
  193. RT_TABLE_MAIN=254,
  194. RT_TABLE_LOCAL=255,
  195. __RT_TABLE_MAX
  196. };
  197. #define RT_TABLE_MAX (__RT_TABLE_MAX - 1)
  198. /* Routing message attributes */
  199. enum rtattr_type_t
  200. {
  201. RTA_UNSPEC,
  202. RTA_DST,
  203. RTA_SRC,
  204. RTA_IIF,
  205. RTA_OIF,
  206. RTA_GATEWAY,
  207. RTA_PRIORITY,
  208. RTA_PREFSRC,
  209. RTA_METRICS,
  210. RTA_MULTIPATH,
  211. RTA_PROTOINFO,
  212. RTA_FLOW,
  213. RTA_CACHEINFO,
  214. RTA_SESSION,
  215. RTA_MP_ALGO,
  216. __RTA_MAX
  217. };
  218. #define RTA_MAX (__RTA_MAX - 1)
  219. #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
  220. #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
  221. /* RTM_MULTIPATH --- array of struct rtnexthop.
  222. *
  223. * "struct rtnexthop" describes all necessary nexthop information,
  224. * i.e. parameters of path to a destination via this nexthop.
  225. *
  226. * At the moment it is impossible to set different prefsrc, mtu, window
  227. * and rtt for different paths from multipath.
  228. */
  229. struct rtnexthop
  230. {
  231. unsigned short rtnh_len;
  232. unsigned char rtnh_flags;
  233. unsigned char rtnh_hops;
  234. int rtnh_ifindex;
  235. };
  236. /* rtnh_flags */
  237. #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
  238. #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
  239. #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
  240. /* Macros to handle hexthops */
  241. #define RTNH_ALIGNTO 4
  242. #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
  243. #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
  244. ((int)(rtnh)->rtnh_len) <= (len))
  245. #define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
  246. #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
  247. #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
  248. #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
  249. /* RTM_CACHEINFO */
  250. struct rta_cacheinfo
  251. {
  252. __u32 rta_clntref;
  253. __u32 rta_lastuse;
  254. __s32 rta_expires;
  255. __u32 rta_error;
  256. __u32 rta_used;
  257. #define RTNETLINK_HAVE_PEERINFO 1
  258. __u32 rta_id;
  259. __u32 rta_ts;
  260. __u32 rta_tsage;
  261. };
  262. /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
  263. enum
  264. {
  265. RTAX_UNSPEC,
  266. #define RTAX_UNSPEC RTAX_UNSPEC
  267. RTAX_LOCK,
  268. #define RTAX_LOCK RTAX_LOCK
  269. RTAX_MTU,
  270. #define RTAX_MTU RTAX_MTU
  271. RTAX_WINDOW,
  272. #define RTAX_WINDOW RTAX_WINDOW
  273. RTAX_RTT,
  274. #define RTAX_RTT RTAX_RTT
  275. RTAX_RTTVAR,
  276. #define RTAX_RTTVAR RTAX_RTTVAR
  277. RTAX_SSTHRESH,
  278. #define RTAX_SSTHRESH RTAX_SSTHRESH
  279. RTAX_CWND,
  280. #define RTAX_CWND RTAX_CWND
  281. RTAX_ADVMSS,
  282. #define RTAX_ADVMSS RTAX_ADVMSS
  283. RTAX_REORDERING,
  284. #define RTAX_REORDERING RTAX_REORDERING
  285. RTAX_HOPLIMIT,
  286. #define RTAX_HOPLIMIT RTAX_HOPLIMIT
  287. RTAX_INITCWND,
  288. #define RTAX_INITCWND RTAX_INITCWND
  289. RTAX_FEATURES,
  290. #define RTAX_FEATURES RTAX_FEATURES
  291. __RTAX_MAX
  292. };
  293. #define RTAX_MAX (__RTAX_MAX - 1)
  294. #define RTAX_FEATURE_ECN 0x00000001
  295. #define RTAX_FEATURE_SACK 0x00000002
  296. #define RTAX_FEATURE_TIMESTAMP 0x00000004
  297. #define RTAX_FEATURE_ALLFRAG 0x00000008
  298. struct rta_session
  299. {
  300. __u8 proto;
  301. __u8 pad1;
  302. __u16 pad2;
  303. union {
  304. struct {
  305. __u16 sport;
  306. __u16 dport;
  307. } ports;
  308. struct {
  309. __u8 type;
  310. __u8 code;
  311. __u16 ident;
  312. } icmpt;
  313. __u32 spi;
  314. } u;
  315. };
  316. /**************************************************************
  317. * Neighbour discovery.
  318. ****/
  319. struct ndmsg
  320. {
  321. unsigned char ndm_family;
  322. unsigned char ndm_pad1;
  323. unsigned short ndm_pad2;
  324. int ndm_ifindex; /* Link index */
  325. __u16 ndm_state;
  326. __u8 ndm_flags;
  327. __u8 ndm_type;
  328. };
  329. enum
  330. {
  331. NDA_UNSPEC,
  332. NDA_DST,
  333. NDA_LLADDR,
  334. NDA_CACHEINFO,
  335. NDA_PROBES,
  336. __NDA_MAX
  337. };
  338. #define NDA_MAX (__NDA_MAX - 1)
  339. #define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
  340. #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
  341. /*
  342. * Neighbor Cache Entry Flags
  343. */
  344. #define NTF_PROXY 0x08 /* == ATF_PUBL */
  345. #define NTF_ROUTER 0x80
  346. /*
  347. * Neighbor Cache Entry States.
  348. */
  349. #define NUD_INCOMPLETE 0x01
  350. #define NUD_REACHABLE 0x02
  351. #define NUD_STALE 0x04
  352. #define NUD_DELAY 0x08
  353. #define NUD_PROBE 0x10
  354. #define NUD_FAILED 0x20
  355. /* Dummy states */
  356. #define NUD_NOARP 0x40
  357. #define NUD_PERMANENT 0x80
  358. #define NUD_NONE 0x00
  359. struct nda_cacheinfo
  360. {
  361. __u32 ndm_confirmed;
  362. __u32 ndm_used;
  363. __u32 ndm_updated;
  364. __u32 ndm_refcnt;
  365. };
  366. /*****************************************************************
  367. * Neighbour tables specific messages.
  368. *
  369. * To retrieve the neighbour tables send RTM_GETNEIGHTBL with the
  370. * NLM_F_DUMP flag set. Every neighbour table configuration is
  371. * spread over multiple messages to avoid running into message
  372. * size limits on systems with many interfaces. The first message
  373. * in the sequence transports all not device specific data such as
  374. * statistics, configuration, and the default parameter set.
  375. * This message is followed by 0..n messages carrying device
  376. * specific parameter sets.
  377. * Although the ordering should be sufficient, NDTA_NAME can be
  378. * used to identify sequences. The initial message can be identified
  379. * by checking for NDTA_CONFIG. The device specific messages do
  380. * not contain this TLV but have NDTPA_IFINDEX set to the
  381. * corresponding interface index.
  382. *
  383. * To change neighbour table attributes, send RTM_SETNEIGHTBL
  384. * with NDTA_NAME set. Changeable attribute include NDTA_THRESH[1-3],
  385. * NDTA_GC_INTERVAL, and all TLVs in NDTA_PARMS unless marked
  386. * otherwise. Device specific parameter sets can be changed by
  387. * setting NDTPA_IFINDEX to the interface index of the corresponding
  388. * device.
  389. ****/
  390. struct ndt_stats
  391. {
  392. __u64 ndts_allocs;
  393. __u64 ndts_destroys;
  394. __u64 ndts_hash_grows;
  395. __u64 ndts_res_failed;
  396. __u64 ndts_lookups;
  397. __u64 ndts_hits;
  398. __u64 ndts_rcv_probes_mcast;
  399. __u64 ndts_rcv_probes_ucast;
  400. __u64 ndts_periodic_gc_runs;
  401. __u64 ndts_forced_gc_runs;
  402. };
  403. enum {
  404. NDTPA_UNSPEC,
  405. NDTPA_IFINDEX, /* u32, unchangeable */
  406. NDTPA_REFCNT, /* u32, read-only */
  407. NDTPA_REACHABLE_TIME, /* u64, read-only, msecs */
  408. NDTPA_BASE_REACHABLE_TIME, /* u64, msecs */
  409. NDTPA_RETRANS_TIME, /* u64, msecs */
  410. NDTPA_GC_STALETIME, /* u64, msecs */
  411. NDTPA_DELAY_PROBE_TIME, /* u64, msecs */
  412. NDTPA_QUEUE_LEN, /* u32 */
  413. NDTPA_APP_PROBES, /* u32 */
  414. NDTPA_UCAST_PROBES, /* u32 */
  415. NDTPA_MCAST_PROBES, /* u32 */
  416. NDTPA_ANYCAST_DELAY, /* u64, msecs */
  417. NDTPA_PROXY_DELAY, /* u64, msecs */
  418. NDTPA_PROXY_QLEN, /* u32 */
  419. NDTPA_LOCKTIME, /* u64, msecs */
  420. __NDTPA_MAX
  421. };
  422. #define NDTPA_MAX (__NDTPA_MAX - 1)
  423. struct ndtmsg
  424. {
  425. __u8 ndtm_family;
  426. __u8 ndtm_pad1;
  427. __u16 ndtm_pad2;
  428. };
  429. struct ndt_config
  430. {
  431. __u16 ndtc_key_len;
  432. __u16 ndtc_entry_size;
  433. __u32 ndtc_entries;
  434. __u32 ndtc_last_flush; /* delta to now in msecs */
  435. __u32 ndtc_last_rand; /* delta to now in msecs */
  436. __u32 ndtc_hash_rnd;
  437. __u32 ndtc_hash_mask;
  438. __u32 ndtc_hash_chain_gc;
  439. __u32 ndtc_proxy_qlen;
  440. };
  441. enum {
  442. NDTA_UNSPEC,
  443. NDTA_NAME, /* char *, unchangeable */
  444. NDTA_THRESH1, /* u32 */
  445. NDTA_THRESH2, /* u32 */
  446. NDTA_THRESH3, /* u32 */
  447. NDTA_CONFIG, /* struct ndt_config, read-only */
  448. NDTA_PARMS, /* nested TLV NDTPA_* */
  449. NDTA_STATS, /* struct ndt_stats, read-only */
  450. NDTA_GC_INTERVAL, /* u64, msecs */
  451. __NDTA_MAX
  452. };
  453. #define NDTA_MAX (__NDTA_MAX - 1)
  454. #define NDTA_RTA(r) ((struct rtattr*)(((char*)(r)) + \
  455. NLMSG_ALIGN(sizeof(struct ndtmsg))))
  456. #define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
  457. /****
  458. * General form of address family dependent message.
  459. ****/
  460. struct rtgenmsg
  461. {
  462. unsigned char rtgen_family;
  463. };
  464. /*****************************************************************
  465. * Link layer specific messages.
  466. ****/
  467. /* struct ifinfomsg
  468. * passes link level specific information, not dependent
  469. * on network protocol.
  470. */
  471. struct ifinfomsg
  472. {
  473. unsigned char ifi_family;
  474. unsigned char __ifi_pad;
  475. unsigned short ifi_type; /* ARPHRD_* */
  476. int ifi_index; /* Link index */
  477. unsigned ifi_flags; /* IFF_* flags */
  478. unsigned ifi_change; /* IFF_* change mask */
  479. };
  480. /********************************************************************
  481. * prefix information
  482. ****/
  483. struct prefixmsg
  484. {
  485. unsigned char prefix_family;
  486. unsigned char prefix_pad1;
  487. unsigned short prefix_pad2;
  488. int prefix_ifindex;
  489. unsigned char prefix_type;
  490. unsigned char prefix_len;
  491. unsigned char prefix_flags;
  492. unsigned char prefix_pad3;
  493. };
  494. enum
  495. {
  496. PREFIX_UNSPEC,
  497. PREFIX_ADDRESS,
  498. PREFIX_CACHEINFO,
  499. __PREFIX_MAX
  500. };
  501. #define PREFIX_MAX (__PREFIX_MAX - 1)
  502. struct prefix_cacheinfo
  503. {
  504. __u32 preferred_time;
  505. __u32 valid_time;
  506. };
  507. /* The struct should be in sync with struct net_device_stats */
  508. struct rtnl_link_stats
  509. {
  510. __u32 rx_packets; /* total packets received */
  511. __u32 tx_packets; /* total packets transmitted */
  512. __u32 rx_bytes; /* total bytes received */
  513. __u32 tx_bytes; /* total bytes transmitted */
  514. __u32 rx_errors; /* bad packets received */
  515. __u32 tx_errors; /* packet transmit problems */
  516. __u32 rx_dropped; /* no space in linux buffers */
  517. __u32 tx_dropped; /* no space available in linux */
  518. __u32 multicast; /* multicast packets received */
  519. __u32 collisions;
  520. /* detailed rx_errors: */
  521. __u32 rx_length_errors;
  522. __u32 rx_over_errors; /* receiver ring buff overflow */
  523. __u32 rx_crc_errors; /* recved pkt with crc error */
  524. __u32 rx_frame_errors; /* recv'd frame alignment error */
  525. __u32 rx_fifo_errors; /* recv'r fifo overrun */
  526. __u32 rx_missed_errors; /* receiver missed packet */
  527. /* detailed tx_errors */
  528. __u32 tx_aborted_errors;
  529. __u32 tx_carrier_errors;
  530. __u32 tx_fifo_errors;
  531. __u32 tx_heartbeat_errors;
  532. __u32 tx_window_errors;
  533. /* for cslip etc */
  534. __u32 rx_compressed;
  535. __u32 tx_compressed;
  536. };
  537. /* The struct should be in sync with struct ifmap */
  538. struct rtnl_link_ifmap
  539. {
  540. __u64 mem_start;
  541. __u64 mem_end;
  542. __u64 base_addr;
  543. __u16 irq;
  544. __u8 dma;
  545. __u8 port;
  546. };
  547. enum
  548. {
  549. IFLA_UNSPEC,
  550. IFLA_ADDRESS,
  551. IFLA_BROADCAST,
  552. IFLA_IFNAME,
  553. IFLA_MTU,
  554. IFLA_LINK,
  555. IFLA_QDISC,
  556. IFLA_STATS,
  557. IFLA_COST,
  558. #define IFLA_COST IFLA_COST
  559. IFLA_PRIORITY,
  560. #define IFLA_PRIORITY IFLA_PRIORITY
  561. IFLA_MASTER,
  562. #define IFLA_MASTER IFLA_MASTER
  563. IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */
  564. #define IFLA_WIRELESS IFLA_WIRELESS
  565. IFLA_PROTINFO, /* Protocol specific information for a link */
  566. #define IFLA_PROTINFO IFLA_PROTINFO
  567. IFLA_TXQLEN,
  568. #define IFLA_TXQLEN IFLA_TXQLEN
  569. IFLA_MAP,
  570. #define IFLA_MAP IFLA_MAP
  571. IFLA_WEIGHT,
  572. #define IFLA_WEIGHT IFLA_WEIGHT
  573. IFLA_OPERSTATE,
  574. IFLA_LINKMODE,
  575. __IFLA_MAX
  576. };
  577. #define IFLA_MAX (__IFLA_MAX - 1)
  578. #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
  579. #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
  580. /* ifi_flags.
  581. IFF_* flags.
  582. The only change is:
  583. IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
  584. more not changeable by user. They describe link media
  585. characteristics and set by device driver.
  586. Comments:
  587. - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
  588. - If neither of these three flags are set;
  589. the interface is NBMA.
  590. - IFF_MULTICAST does not mean anything special:
  591. multicasts can be used on all not-NBMA links.
  592. IFF_MULTICAST means that this media uses special encapsulation
  593. for multicast frames. Apparently, all IFF_POINTOPOINT and
  594. IFF_BROADCAST devices are able to use multicasts too.
  595. */
  596. /* IFLA_LINK.
  597. For usual devices it is equal ifi_index.
  598. If it is a "virtual interface" (f.e. tunnel), ifi_link
  599. can point to real physical interface (f.e. for bandwidth calculations),
  600. or maybe 0, what means, that real media is unknown (usual
  601. for IPIP tunnels, when route to endpoint is allowed to change)
  602. */
  603. /* Subtype attributes for IFLA_PROTINFO */
  604. enum
  605. {
  606. IFLA_INET6_UNSPEC,
  607. IFLA_INET6_FLAGS, /* link flags */
  608. IFLA_INET6_CONF, /* sysctl parameters */
  609. IFLA_INET6_STATS, /* statistics */
  610. IFLA_INET6_MCAST, /* MC things. What of them? */
  611. IFLA_INET6_CACHEINFO, /* time values and max reasm size */
  612. __IFLA_INET6_MAX
  613. };
  614. #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
  615. struct ifla_cacheinfo
  616. {
  617. __u32 max_reasm_len;
  618. __u32 tstamp; /* ipv6InterfaceTable updated timestamp */
  619. __u32 reachable_time;
  620. __u32 retrans_time;
  621. };
  622. /*****************************************************************
  623. * Traffic control messages.
  624. ****/
  625. struct tcmsg
  626. {
  627. unsigned char tcm_family;
  628. unsigned char tcm__pad1;
  629. unsigned short tcm__pad2;
  630. int tcm_ifindex;
  631. __u32 tcm_handle;
  632. __u32 tcm_parent;
  633. __u32 tcm_info;
  634. };
  635. enum
  636. {
  637. TCA_UNSPEC,
  638. TCA_KIND,
  639. TCA_OPTIONS,
  640. TCA_STATS,
  641. TCA_XSTATS,
  642. TCA_RATE,
  643. TCA_FCNT,
  644. TCA_STATS2,
  645. __TCA_MAX
  646. };
  647. #define TCA_MAX (__TCA_MAX - 1)
  648. #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
  649. #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
  650. #ifndef __KERNEL__
  651. /* RTnetlink multicast groups - backwards compatibility for userspace */
  652. #define RTMGRP_LINK 1
  653. #define RTMGRP_NOTIFY 2
  654. #define RTMGRP_NEIGH 4
  655. #define RTMGRP_TC 8
  656. #define RTMGRP_IPV4_IFADDR 0x10
  657. #define RTMGRP_IPV4_MROUTE 0x20
  658. #define RTMGRP_IPV4_ROUTE 0x40
  659. #define RTMGRP_IPV4_RULE 0x80
  660. #define RTMGRP_IPV6_IFADDR 0x100
  661. #define RTMGRP_IPV6_MROUTE 0x200
  662. #define RTMGRP_IPV6_ROUTE 0x400
  663. #define RTMGRP_IPV6_IFINFO 0x800
  664. #define RTMGRP_DECnet_IFADDR 0x1000
  665. #define RTMGRP_DECnet_ROUTE 0x4000
  666. #define RTMGRP_IPV6_PREFIX 0x20000
  667. #endif
  668. /* RTnetlink multicast groups */
  669. enum rtnetlink_groups {
  670. RTNLGRP_NONE,
  671. #define RTNLGRP_NONE RTNLGRP_NONE
  672. RTNLGRP_LINK,
  673. #define RTNLGRP_LINK RTNLGRP_LINK
  674. RTNLGRP_NOTIFY,
  675. #define RTNLGRP_NOTIFY RTNLGRP_NOTIFY
  676. RTNLGRP_NEIGH,
  677. #define RTNLGRP_NEIGH RTNLGRP_NEIGH
  678. RTNLGRP_TC,
  679. #define RTNLGRP_TC RTNLGRP_TC
  680. RTNLGRP_IPV4_IFADDR,
  681. #define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR
  682. RTNLGRP_IPV4_MROUTE,
  683. #define RTNLGRP_IPV4_MROUTE RTNLGRP_IPV4_MROUTE
  684. RTNLGRP_IPV4_ROUTE,
  685. #define RTNLGRP_IPV4_ROUTE RTNLGRP_IPV4_ROUTE
  686. RTNLGRP_IPV4_RULE,
  687. #define RTNLGRP_IPV4_RULE RTNLGRP_IPV4_RULE
  688. RTNLGRP_IPV6_IFADDR,
  689. #define RTNLGRP_IPV6_IFADDR RTNLGRP_IPV6_IFADDR
  690. RTNLGRP_IPV6_MROUTE,
  691. #define RTNLGRP_IPV6_MROUTE RTNLGRP_IPV6_MROUTE
  692. RTNLGRP_IPV6_ROUTE,
  693. #define RTNLGRP_IPV6_ROUTE RTNLGRP_IPV6_ROUTE
  694. RTNLGRP_IPV6_IFINFO,
  695. #define RTNLGRP_IPV6_IFINFO RTNLGRP_IPV6_IFINFO
  696. RTNLGRP_DECnet_IFADDR,
  697. #define RTNLGRP_DECnet_IFADDR RTNLGRP_DECnet_IFADDR
  698. RTNLGRP_NOP2,
  699. RTNLGRP_DECnet_ROUTE,
  700. #define RTNLGRP_DECnet_ROUTE RTNLGRP_DECnet_ROUTE
  701. RTNLGRP_NOP3,
  702. RTNLGRP_NOP4,
  703. RTNLGRP_IPV6_PREFIX,
  704. #define RTNLGRP_IPV6_PREFIX RTNLGRP_IPV6_PREFIX
  705. RTNLGRP_IPV6_RULE,
  706. #define RTNLGRP_IPV6_RULE RTNLGRP_IPV6_RULE
  707. __RTNLGRP_MAX
  708. };
  709. #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
  710. /* TC action piece */
  711. struct tcamsg
  712. {
  713. unsigned char tca_family;
  714. unsigned char tca__pad1;
  715. unsigned short tca__pad2;
  716. };
  717. #define TA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
  718. #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
  719. #define TCA_ACT_TAB 1 /* attr type must be >=1 */
  720. #define TCAA_MAX 1
  721. /* End of information exported to user level */
  722. #ifdef __KERNEL__
  723. #include <linux/mutex.h>
  724. extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
  725. static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
  726. {
  727. int len = strlen(str) + 1;
  728. return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
  729. }
  730. extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
  731. #define rtattr_parse_nested(tb, max, rta) \
  732. rtattr_parse((tb), (max), RTA_DATA((rta)), RTA_PAYLOAD((rta)))
  733. extern struct sock *rtnl;
  734. struct rtnetlink_link
  735. {
  736. int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
  737. int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
  738. };
  739. extern struct rtnetlink_link * rtnetlink_links[NPROTO];
  740. extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
  741. extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
  742. extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
  743. #define RTA_PUT(skb, attrtype, attrlen, data) \
  744. ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
  745. goto rtattr_failure; \
  746. __rta_fill(skb, attrtype, attrlen, data); })
  747. #define RTA_APPEND(skb, attrlen, data) \
  748. ({ if (unlikely(skb_tailroom(skb) < (int)(attrlen))) \
  749. goto rtattr_failure; \
  750. memcpy(skb_put(skb, attrlen), data, attrlen); })
  751. #define RTA_PUT_NOHDR(skb, attrlen, data) \
  752. ({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \
  753. memset(skb->tail - (RTA_ALIGN(attrlen) - attrlen), 0, \
  754. RTA_ALIGN(attrlen) - attrlen); })
  755. #define RTA_PUT_U8(skb, attrtype, value) \
  756. ({ u8 _tmp = (value); \
  757. RTA_PUT(skb, attrtype, sizeof(u8), &_tmp); })
  758. #define RTA_PUT_U16(skb, attrtype, value) \
  759. ({ u16 _tmp = (value); \
  760. RTA_PUT(skb, attrtype, sizeof(u16), &_tmp); })
  761. #define RTA_PUT_U32(skb, attrtype, value) \
  762. ({ u32 _tmp = (value); \
  763. RTA_PUT(skb, attrtype, sizeof(u32), &_tmp); })
  764. #define RTA_PUT_U64(skb, attrtype, value) \
  765. ({ u64 _tmp = (value); \
  766. RTA_PUT(skb, attrtype, sizeof(u64), &_tmp); })
  767. #define RTA_PUT_SECS(skb, attrtype, value) \
  768. RTA_PUT_U64(skb, attrtype, (value) / HZ)
  769. #define RTA_PUT_MSECS(skb, attrtype, value) \
  770. RTA_PUT_U64(skb, attrtype, jiffies_to_msecs(value))
  771. #define RTA_PUT_STRING(skb, attrtype, value) \
  772. RTA_PUT(skb, attrtype, strlen(value) + 1, value)
  773. #define RTA_PUT_FLAG(skb, attrtype) \
  774. RTA_PUT(skb, attrtype, 0, NULL);
  775. #define RTA_NEST(skb, type) \
  776. ({ struct rtattr *__start = (struct rtattr *) (skb)->tail; \
  777. RTA_PUT(skb, type, 0, NULL); \
  778. __start; })
  779. #define RTA_NEST_END(skb, start) \
  780. ({ (start)->rta_len = ((skb)->tail - (unsigned char *) (start)); \
  781. (skb)->len; })
  782. #define RTA_NEST_CANCEL(skb, start) \
  783. ({ if (start) \
  784. skb_trim(skb, (unsigned char *) (start) - (skb)->data); \
  785. -1; })
  786. #define RTA_GET_U8(rta) \
  787. ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u8)) \
  788. goto rtattr_failure; \
  789. *(u8 *) RTA_DATA(rta); })
  790. #define RTA_GET_U16(rta) \
  791. ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u16)) \
  792. goto rtattr_failure; \
  793. *(u16 *) RTA_DATA(rta); })
  794. #define RTA_GET_U32(rta) \
  795. ({ if (!rta || RTA_PAYLOAD(rta) < sizeof(u32)) \
  796. goto rtattr_failure; \
  797. *(u32 *) RTA_DATA(rta); })
  798. #define RTA_GET_U64(rta) \
  799. ({ u64 _tmp; \
  800. if (!rta || RTA_PAYLOAD(rta) < sizeof(u64)) \
  801. goto rtattr_failure; \
  802. memcpy(&_tmp, RTA_DATA(rta), sizeof(_tmp)); \
  803. _tmp; })
  804. #define RTA_GET_FLAG(rta) (!!(rta))
  805. #define RTA_GET_SECS(rta) ((unsigned long) RTA_GET_U64(rta) * HZ)
  806. #define RTA_GET_MSECS(rta) (msecs_to_jiffies((unsigned long) RTA_GET_U64(rta)))
  807. static inline struct rtattr *
  808. __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)
  809. {
  810. struct rtattr *rta;
  811. int size = RTA_LENGTH(attrlen);
  812. rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
  813. rta->rta_type = attrtype;
  814. rta->rta_len = size;
  815. memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
  816. return rta;
  817. }
  818. #define __RTA_PUT(skb, attrtype, attrlen) \
  819. ({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \
  820. goto rtattr_failure; \
  821. __rta_reserve(skb, attrtype, attrlen); })
  822. extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
  823. /* RTNL is used as a global lock for all changes to network configuration */
  824. extern void rtnl_lock(void);
  825. extern void rtnl_unlock(void);
  826. extern int rtnl_trylock(void);
  827. extern void rtnetlink_init(void);
  828. extern void __rtnl_unlock(void);
  829. #define ASSERT_RTNL() do { \
  830. if (unlikely(rtnl_trylock())) { \
  831. rtnl_unlock(); \
  832. printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
  833. __FILE__, __LINE__); \
  834. dump_stack(); \
  835. } \
  836. } while(0)
  837. #define BUG_TRAP(x) do { \
  838. if (unlikely(!(x))) { \
  839. printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \
  840. #x, __FILE__ , __LINE__); \
  841. } \
  842. } while(0)
  843. #endif /* __KERNEL__ */
  844. #endif /* __LINUX_RTNETLINK_H */