Annotation of embedaddon/quagga/zebra/rib.h, revision 1.1.1.3
1.1 misho 1: /*
2: * Routing Information Base header
3: * Copyright (C) 1997 Kunihiro Ishiguro
4: *
5: * This file is part of GNU Zebra.
6: *
7: * GNU Zebra is free software; you can redistribute it and/or modify it
8: * under the terms of the GNU General Public License as published by the
9: * Free Software Foundation; either version 2, or (at your option) any
10: * later version.
11: *
12: * GNU Zebra is distributed in the hope that it will be useful, but
13: * WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with GNU Zebra; see the file COPYING. If not, write to the Free
19: * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: */
22:
23: #ifndef _ZEBRA_RIB_H
24: #define _ZEBRA_RIB_H
25:
26: #include "prefix.h"
1.1.1.3 ! misho 27: #include "table.h"
! 28: #include "queue.h"
1.1 misho 29:
30: #define DISTANCE_INFINITY 255
31:
32: /* Routing information base. */
33:
34: union g_addr {
35: struct in_addr ipv4;
36: #ifdef HAVE_IPV6
37: struct in6_addr ipv6;
38: #endif /* HAVE_IPV6 */
39: };
40:
41: struct rib
42: {
43: /* Link list. */
44: struct rib *next;
45: struct rib *prev;
46:
47: /* Nexthop structure */
48: struct nexthop *nexthop;
49:
50: /* Refrence count. */
51: unsigned long refcnt;
52:
53: /* Uptime. */
54: time_t uptime;
55:
56: /* Type fo this route. */
57: int type;
58:
59: /* Which routing table */
60: int table;
61:
62: /* Metric */
63: u_int32_t metric;
64:
65: /* Distance. */
66: u_char distance;
67:
68: /* Flags of this route.
69: * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
70: * to clients via Zserv
71: */
72: u_char flags;
73:
74: /* RIB internal status */
75: u_char status;
76: #define RIB_ENTRY_REMOVED (1 << 0)
77:
78: /* Nexthop information. */
79: u_char nexthop_num;
80: u_char nexthop_active_num;
81: u_char nexthop_fib_num;
82: };
83:
84: /* meta-queue structure:
85: * sub-queue 0: connected, kernel
86: * sub-queue 1: static
87: * sub-queue 2: RIP, RIPng, OSPF, OSPF6, IS-IS
88: * sub-queue 3: iBGP, eBGP
89: * sub-queue 4: any other origin (if any)
90: */
91: #define MQ_SIZE 5
92: struct meta_queue
93: {
94: struct list *subq[MQ_SIZE];
95: u_int32_t size; /* sum of lengths of all subqueues */
96: };
97:
1.1.1.3 ! misho 98: /*
! 99: * Structure that represents a single destination (prefix).
! 100: */
! 101: typedef struct rib_dest_t_
! 102: {
! 103:
! 104: /*
! 105: * Back pointer to the route node for this destination. This helps
! 106: * us get to the prefix that this structure is for.
! 107: */
! 108: struct route_node *rnode;
! 109:
! 110: /*
! 111: * Doubly-linked list of routes for this prefix.
! 112: */
! 113: struct rib *routes;
! 114:
! 115: /*
! 116: * Flags, see below.
! 117: */
! 118: u_int32_t flags;
! 119:
! 120: /*
! 121: * Linkage to put dest on the FPM processing queue.
! 122: */
! 123: TAILQ_ENTRY(rib_dest_t_) fpm_q_entries;
! 124:
! 125: } rib_dest_t;
! 126:
! 127: #define RIB_ROUTE_QUEUED(x) (1 << (x))
! 128:
! 129: /*
! 130: * The maximum qindex that can be used.
! 131: */
! 132: #define ZEBRA_MAX_QINDEX (MQ_SIZE - 1)
! 133:
! 134: /*
! 135: * This flag indicates that a given prefix has been 'advertised' to
! 136: * the FPM to be installed in the forwarding plane.
! 137: */
! 138: #define RIB_DEST_SENT_TO_FPM (1 << (ZEBRA_MAX_QINDEX + 1))
! 139:
! 140: /*
! 141: * This flag is set when we need to send an update to the FPM about a
! 142: * dest.
! 143: */
! 144: #define RIB_DEST_UPDATE_FPM (1 << (ZEBRA_MAX_QINDEX + 2))
! 145:
! 146: /*
! 147: * Macro to iterate over each route for a destination (prefix).
! 148: */
! 149: #define RIB_DEST_FOREACH_ROUTE(dest, rib) \
! 150: for ((rib) = (dest) ? (dest)->routes : NULL; (rib); (rib) = (rib)->next)
! 151:
! 152: /*
! 153: * Same as above, but allows the current node to be unlinked.
! 154: */
! 155: #define RIB_DEST_FOREACH_ROUTE_SAFE(dest, rib, next) \
! 156: for ((rib) = (dest) ? (dest)->routes : NULL; \
! 157: (rib) && ((next) = (rib)->next, 1); \
! 158: (rib) = (next))
! 159:
! 160: #define RNODE_FOREACH_RIB(rn, rib) \
! 161: RIB_DEST_FOREACH_ROUTE (rib_dest_from_rnode (rn), rib)
! 162:
! 163: #define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \
! 164: RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next)
! 165:
1.1 misho 166: /* Static route information. */
167: struct static_ipv4
168: {
169: /* For linked list. */
170: struct static_ipv4 *prev;
171: struct static_ipv4 *next;
172:
173: /* Administrative distance. */
174: u_char distance;
175:
176: /* Flag for this static route's type. */
177: u_char type;
178: #define STATIC_IPV4_GATEWAY 1
179: #define STATIC_IPV4_IFNAME 2
180: #define STATIC_IPV4_BLACKHOLE 3
181:
182: /* Nexthop value. */
183: union
184: {
185: struct in_addr ipv4;
186: char *ifname;
187: } gate;
188:
189: /* bit flags */
190: u_char flags;
191: /*
192: see ZEBRA_FLAG_REJECT
193: ZEBRA_FLAG_BLACKHOLE
194: */
195: };
196:
197: #ifdef HAVE_IPV6
198: /* Static route information. */
199: struct static_ipv6
200: {
201: /* For linked list. */
202: struct static_ipv6 *prev;
203: struct static_ipv6 *next;
204:
205: /* Administrative distance. */
206: u_char distance;
207:
208: /* Flag for this static route's type. */
209: u_char type;
210: #define STATIC_IPV6_GATEWAY 1
211: #define STATIC_IPV6_GATEWAY_IFNAME 2
212: #define STATIC_IPV6_IFNAME 3
213:
214: /* Nexthop value. */
215: struct in6_addr ipv6;
216: char *ifname;
217:
218: /* bit flags */
219: u_char flags;
220: /*
221: see ZEBRA_FLAG_REJECT
222: ZEBRA_FLAG_BLACKHOLE
223: */
224: };
225: #endif /* HAVE_IPV6 */
226:
227: enum nexthop_types_t
228: {
229: NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
230: NEXTHOP_TYPE_IFNAME, /* Interface route. */
231: NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
232: NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
233: NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
234: NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
235: NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
236: NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
237: NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
238: };
239:
240: /* Nexthop structure. */
241: struct nexthop
242: {
243: struct nexthop *next;
244: struct nexthop *prev;
245:
246: /* Interface index. */
247: char *ifname;
248: unsigned int ifindex;
249:
250: enum nexthop_types_t type;
251:
252: u_char flags;
253: #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
254: #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
255: #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
256:
257: /* Nexthop address or interface name. */
258: union g_addr gate;
259:
260: /* Recursive lookup nexthop. */
261: u_char rtype;
262: unsigned int rifindex;
263: union g_addr rgate;
264: union g_addr src;
265: };
266:
267: /* Routing table instance. */
268: struct vrf
269: {
270: /* Identifier. This is same as routing table vector index. */
271: u_int32_t id;
272:
273: /* Routing table name. */
274: char *name;
275:
276: /* Description. */
277: char *desc;
278:
279: /* FIB identifier. */
280: u_char fib_id;
281:
282: /* Routing table. */
283: struct route_table *table[AFI_MAX][SAFI_MAX];
284:
285: /* Static route configuration. */
286: struct route_table *stable[AFI_MAX][SAFI_MAX];
287: };
288:
1.1.1.3 ! misho 289: /*
! 290: * rib_table_info_t
! 291: *
! 292: * Structure that is hung off of a route_table that holds information about
! 293: * the table.
! 294: */
! 295: typedef struct rib_table_info_t_
! 296: {
! 297:
! 298: /*
! 299: * Back pointer to vrf.
! 300: */
! 301: struct vrf *vrf;
! 302: afi_t afi;
! 303: safi_t safi;
! 304:
! 305: } rib_table_info_t;
! 306:
! 307: typedef enum
! 308: {
! 309: RIB_TABLES_ITER_S_INIT,
! 310: RIB_TABLES_ITER_S_ITERATING,
! 311: RIB_TABLES_ITER_S_DONE
! 312: } rib_tables_iter_state_t;
! 313:
! 314: /*
! 315: * Structure that holds state for iterating over all tables in the
! 316: * Routing Information Base.
! 317: */
! 318: typedef struct rib_tables_iter_t_
! 319: {
! 320: uint32_t vrf_id;
! 321: int afi_safi_ix;
! 322:
! 323: rib_tables_iter_state_t state;
! 324: } rib_tables_iter_t;
! 325:
! 326: extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
1.1 misho 327: extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
328: extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
329: extern struct nexthop *nexthop_blackhole_add (struct rib *);
330: extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *,
331: struct in_addr *);
1.1.1.2 misho 332: extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
333: struct in_addr *,
334: struct in_addr *,
335: unsigned int);
1.1 misho 336: extern void rib_lookup_and_dump (struct prefix_ipv4 *);
337: extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
338: extern void rib_dump (const char *, const struct prefix_ipv4 *, const struct rib *);
339: extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
340: #define ZEBRA_RIB_LOOKUP_ERROR -1
341: #define ZEBRA_RIB_FOUND_EXACT 0
342: #define ZEBRA_RIB_FOUND_NOGATE 1
343: #define ZEBRA_RIB_FOUND_CONNECTED 2
344: #define ZEBRA_RIB_NOTFOUND 3
345:
346: #ifdef HAVE_IPV6
347: extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
348: #endif /* HAVE_IPV6 */
349:
350: extern struct vrf *vrf_lookup (u_int32_t);
351: extern struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id);
352: extern struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id);
353:
354: /* NOTE:
355: * All rib_add_ipv[46]* functions will not just add prefix into RIB, but
356: * also implicitly withdraw equal prefix of same type. */
357: extern int rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
358: struct in_addr *gate, struct in_addr *src,
359: unsigned int ifindex, u_int32_t vrf_id,
1.1.1.2 misho 360: u_int32_t, u_char, safi_t);
1.1 misho 361:
1.1.1.2 misho 362: extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
1.1 misho 363:
364: extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
365: struct in_addr *gate, unsigned int ifindex,
1.1.1.2 misho 366: u_int32_t, safi_t safi);
1.1 misho 367:
368: extern struct rib *rib_match_ipv4 (struct in_addr);
369:
370: extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
371:
372: extern void rib_update (void);
373: extern void rib_weed_tables (void);
374: extern void rib_sweep_route (void);
375: extern void rib_close (void);
376: extern void rib_init (void);
1.1.1.2 misho 377: extern unsigned long rib_score_proto (u_char proto);
1.1 misho 378:
379: extern int
380: static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
381: u_char flags, u_char distance, u_int32_t vrf_id);
382:
383: extern int
384: static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
385: u_char distance, u_int32_t vrf_id);
386:
387: #ifdef HAVE_IPV6
388: extern int
389: rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
390: struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
1.1.1.2 misho 391: u_int32_t metric, u_char distance, safi_t safi);
1.1 misho 392:
393: extern int
394: rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
1.1.1.2 misho 395: struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi);
1.1 misho 396:
397: extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
398:
399: extern struct rib *rib_match_ipv6 (struct in6_addr *);
400:
401: extern struct route_table *rib_table_ipv6;
402:
403: extern int
404: static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
405: const char *ifname, u_char flags, u_char distance,
406: u_int32_t vrf_id);
407:
408: extern int
409: static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
410: const char *ifname, u_char distance, u_int32_t vrf_id);
411:
412: #endif /* HAVE_IPV6 */
413:
1.1.1.3 ! misho 414: extern int rib_gc_dest (struct route_node *rn);
! 415: extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
! 416:
! 417: /*
! 418: * Inline functions.
! 419: */
! 420:
! 421: /*
! 422: * rib_table_info
! 423: */
! 424: static inline rib_table_info_t *
! 425: rib_table_info (struct route_table *table)
! 426: {
! 427: return (rib_table_info_t *) table->info;
! 428: }
! 429:
! 430: /*
! 431: * rib_dest_from_rnode
! 432: */
! 433: static inline rib_dest_t *
! 434: rib_dest_from_rnode (struct route_node *rn)
! 435: {
! 436: return (rib_dest_t *) rn->info;
! 437: }
! 438:
! 439: /*
! 440: * rnode_to_ribs
! 441: *
! 442: * Returns a pointer to the list of routes corresponding to the given
! 443: * route_node.
! 444: */
! 445: static inline struct rib *
! 446: rnode_to_ribs (struct route_node *rn)
! 447: {
! 448: rib_dest_t *dest;
! 449:
! 450: dest = rib_dest_from_rnode (rn);
! 451: if (!dest)
! 452: return NULL;
! 453:
! 454: return dest->routes;
! 455: }
! 456:
! 457: /*
! 458: * rib_dest_prefix
! 459: */
! 460: static inline struct prefix *
! 461: rib_dest_prefix (rib_dest_t *dest)
! 462: {
! 463: return &dest->rnode->p;
! 464: }
! 465:
! 466: /*
! 467: * rib_dest_af
! 468: *
! 469: * Returns the address family that the destination is for.
! 470: */
! 471: static inline u_char
! 472: rib_dest_af (rib_dest_t *dest)
! 473: {
! 474: return dest->rnode->p.family;
! 475: }
! 476:
! 477: /*
! 478: * rib_dest_table
! 479: */
! 480: static inline struct route_table *
! 481: rib_dest_table (rib_dest_t *dest)
! 482: {
! 483: return dest->rnode->table;
! 484: }
! 485:
! 486: /*
! 487: * rib_dest_vrf
! 488: */
! 489: static inline struct vrf *
! 490: rib_dest_vrf (rib_dest_t *dest)
! 491: {
! 492: return rib_table_info (rib_dest_table (dest))->vrf;
! 493: }
! 494:
! 495: /*
! 496: * rib_tables_iter_init
! 497: */
! 498: static inline void
! 499: rib_tables_iter_init (rib_tables_iter_t *iter)
! 500:
! 501: {
! 502: memset (iter, 0, sizeof (*iter));
! 503: iter->state = RIB_TABLES_ITER_S_INIT;
! 504: }
! 505:
! 506: /*
! 507: * rib_tables_iter_started
! 508: *
! 509: * Returns TRUE if this iterator has started iterating over the set of
! 510: * tables.
! 511: */
! 512: static inline int
! 513: rib_tables_iter_started (rib_tables_iter_t *iter)
! 514: {
! 515: return iter->state != RIB_TABLES_ITER_S_INIT;
! 516: }
! 517:
! 518: /*
! 519: * rib_tables_iter_cleanup
! 520: */
! 521: static inline void
! 522: rib_tables_iter_cleanup (rib_tables_iter_t *iter)
! 523: {
! 524: iter->state = RIB_TABLES_ITER_S_DONE;
! 525: }
! 526:
1.1 misho 527: #endif /*_ZEBRA_RIB_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>