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