version 1.1.1.1, 2012/02/21 17:26:11
|
version 1.1.1.2, 2012/10/09 09:22:29
|
Line 55 static const struct
|
Line 55 static const struct
|
{ |
{ |
int key; |
int key; |
int distance; |
int distance; |
} route_info[] = | } route_info[ZEBRA_ROUTE_MAX] = |
{ |
{ |
{ZEBRA_ROUTE_SYSTEM, 0}, | [ZEBRA_ROUTE_SYSTEM] = {ZEBRA_ROUTE_SYSTEM, 0}, |
{ZEBRA_ROUTE_KERNEL, 0}, | [ZEBRA_ROUTE_KERNEL] = {ZEBRA_ROUTE_KERNEL, 0}, |
{ZEBRA_ROUTE_CONNECT, 0}, | [ZEBRA_ROUTE_CONNECT] = {ZEBRA_ROUTE_CONNECT, 0}, |
{ZEBRA_ROUTE_STATIC, 1}, | [ZEBRA_ROUTE_STATIC] = {ZEBRA_ROUTE_STATIC, 1}, |
{ZEBRA_ROUTE_RIP, 120}, | [ZEBRA_ROUTE_RIP] = {ZEBRA_ROUTE_RIP, 120}, |
{ZEBRA_ROUTE_RIPNG, 120}, | [ZEBRA_ROUTE_RIPNG] = {ZEBRA_ROUTE_RIPNG, 120}, |
{ZEBRA_ROUTE_OSPF, 110}, | [ZEBRA_ROUTE_OSPF] = {ZEBRA_ROUTE_OSPF, 110}, |
{ZEBRA_ROUTE_OSPF6, 110}, | [ZEBRA_ROUTE_OSPF6] = {ZEBRA_ROUTE_OSPF6, 110}, |
{ZEBRA_ROUTE_ISIS, 115}, | [ZEBRA_ROUTE_ISIS] = {ZEBRA_ROUTE_ISIS, 115}, |
{ZEBRA_ROUTE_BGP, 20 /* IBGP is 200. */} | [ZEBRA_ROUTE_BGP] = {ZEBRA_ROUTE_BGP, 20 /* IBGP is 200. */}, |
| [ZEBRA_ROUTE_BABEL] = {ZEBRA_ROUTE_BABEL, 95}, |
| /* no entry/default: 150 */ |
}; |
}; |
|
|
/* Vector for routing table. */ |
/* Vector for routing table. */ |
Line 89 vrf_alloc (const char *name)
|
Line 91 vrf_alloc (const char *name)
|
vrf->table[AFI_IP6][SAFI_UNICAST] = route_table_init (); |
vrf->table[AFI_IP6][SAFI_UNICAST] = route_table_init (); |
vrf->stable[AFI_IP][SAFI_UNICAST] = route_table_init (); |
vrf->stable[AFI_IP][SAFI_UNICAST] = route_table_init (); |
vrf->stable[AFI_IP6][SAFI_UNICAST] = route_table_init (); |
vrf->stable[AFI_IP6][SAFI_UNICAST] = route_table_init (); |
|
vrf->table[AFI_IP][SAFI_MULTICAST] = route_table_init (); |
|
vrf->table[AFI_IP6][SAFI_MULTICAST] = route_table_init (); |
|
vrf->stable[AFI_IP][SAFI_MULTICAST] = route_table_init (); |
|
vrf->stable[AFI_IP6][SAFI_MULTICAST] = route_table_init (); |
|
|
|
|
return vrf; |
return vrf; |
} |
} |
|
|
Line 225 nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv
|
Line 232 nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv
|
return nexthop; |
return nexthop; |
} |
} |
|
|
static struct nexthop * | struct nexthop * |
nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, |
nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, |
struct in_addr *src, unsigned int ifindex) |
struct in_addr *src, unsigned int ifindex) |
{ |
{ |
Line 1229 static const u_char meta_queue_map[ZEBRA_ROUTE_MAX] =
|
Line 1236 static const u_char meta_queue_map[ZEBRA_ROUTE_MAX] =
|
[ZEBRA_ROUTE_ISIS] = 2, |
[ZEBRA_ROUTE_ISIS] = 2, |
[ZEBRA_ROUTE_BGP] = 3, |
[ZEBRA_ROUTE_BGP] = 3, |
[ZEBRA_ROUTE_HSLS] = 4, |
[ZEBRA_ROUTE_HSLS] = 4, |
|
[ZEBRA_ROUTE_BABEL] = 2, |
}; |
}; |
|
|
/* Look into the RN and queue it into one or more priority queues, |
/* Look into the RN and queue it into one or more priority queues, |
Line 1271 rib_meta_queue_add (struct meta_queue *mq, struct rout
|
Line 1279 rib_meta_queue_add (struct meta_queue *mq, struct rout
|
static void |
static void |
rib_queue_add (struct zebra_t *zebra, struct route_node *rn) |
rib_queue_add (struct zebra_t *zebra, struct route_node *rn) |
{ |
{ |
|
char buf[INET_ADDRSTRLEN]; |
|
assert (zebra && rn); |
|
|
if (IS_ZEBRA_DEBUG_RIB_Q) |
if (IS_ZEBRA_DEBUG_RIB_Q) |
|
inet_ntop (AF_INET, &rn->p.u.prefix, buf, INET_ADDRSTRLEN); |
|
|
|
/* Pointless to queue a route_node with no RIB entries to add or remove */ |
|
if (!rn->info) |
{ |
{ |
char buf[INET6_ADDRSTRLEN]; | zlog_debug ("%s: called for route_node (%p, %d) with no ribs", |
| __func__, rn, rn->lock); |
| zlog_backtrace(LOG_DEBUG); |
| return; |
| } |
|
|
zlog_info ("%s: %s/%d: work queue added", __func__, | if (IS_ZEBRA_DEBUG_RIB_Q) |
inet_ntop (rn->p.family, &rn->p.u.prefix, buf, INET6_ADDRSTRLEN), | zlog_info ("%s: %s/%d: work queue added", __func__, buf, rn->p.prefixlen); |
rn->p.prefixlen); | |
| assert (zebra); |
| |
| if (zebra->ribq == NULL) |
| { |
| zlog_err ("%s: work_queue does not exist!", __func__); |
| return; |
} |
} |
|
|
/* |
/* |
Line 1293 rib_queue_add (struct zebra_t *zebra, struct route_nod
|
Line 1317 rib_queue_add (struct zebra_t *zebra, struct route_nod
|
work_queue_add (zebra->ribq, zebra->mq); |
work_queue_add (zebra->ribq, zebra->mq); |
|
|
rib_meta_queue_add (zebra->mq, rn); |
rib_meta_queue_add (zebra->mq, rn); |
|
|
|
if (IS_ZEBRA_DEBUG_RIB_Q) |
|
zlog_debug ("%s: %s/%d: rn %p queued", __func__, buf, rn->p.prefixlen, rn); |
|
|
|
return; |
} |
} |
|
|
/* Create new meta queue. |
/* Create new meta queue. |
Line 1320 meta_queue_new (void)
|
Line 1349 meta_queue_new (void)
|
static void |
static void |
rib_queue_init (struct zebra_t *zebra) |
rib_queue_init (struct zebra_t *zebra) |
{ |
{ |
|
assert (zebra); |
|
|
if (! (zebra->ribq = work_queue_new (zebra->master, |
if (! (zebra->ribq = work_queue_new (zebra->master, |
"route_node processing"))) |
"route_node processing"))) |
{ |
{ |
Line 1335 rib_queue_init (struct zebra_t *zebra)
|
Line 1366 rib_queue_init (struct zebra_t *zebra)
|
zebra->ribq->spec.hold = rib_process_hold_time; |
zebra->ribq->spec.hold = rib_process_hold_time; |
|
|
if (!(zebra->mq = meta_queue_new ())) |
if (!(zebra->mq = meta_queue_new ())) |
|
{ |
zlog_err ("%s: could not initialise meta queue!", __func__); |
zlog_err ("%s: could not initialise meta queue!", __func__); |
|
return; |
|
} |
|
return; |
} |
} |
|
|
/* RIB updates are processed via a queue of pointers to route_nodes. |
/* RIB updates are processed via a queue of pointers to route_nodes. |
Line 1492 int
|
Line 1527 int
|
rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
struct in_addr *gate, struct in_addr *src, |
struct in_addr *gate, struct in_addr *src, |
unsigned int ifindex, u_int32_t vrf_id, |
unsigned int ifindex, u_int32_t vrf_id, |
u_int32_t metric, u_char distance) | u_int32_t metric, u_char distance, safi_t safi) |
{ |
{ |
struct rib *rib; |
struct rib *rib; |
struct rib *same = NULL; |
struct rib *same = NULL; |
Line 1501 rib_add_ipv4 (int type, int flags, struct prefix_ipv4
|
Line 1536 rib_add_ipv4 (int type, int flags, struct prefix_ipv4
|
struct nexthop *nexthop; |
struct nexthop *nexthop; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP, SAFI_UNICAST, 0); | table = vrf_table (AFI_IP, safi, 0); |
if (! table) |
if (! table) |
return 0; |
return 0; |
|
|
Line 1511 rib_add_ipv4 (int type, int flags, struct prefix_ipv4
|
Line 1546 rib_add_ipv4 (int type, int flags, struct prefix_ipv4
|
/* Set default distance by route type. */ |
/* Set default distance by route type. */ |
if (distance == 0) |
if (distance == 0) |
{ |
{ |
distance = route_info[type].distance; | if ((unsigned)type >= sizeof(route_info) / sizeof(route_info[0])) |
| distance = 150; |
| else |
| distance = route_info[type].distance; |
|
|
/* iBGP distance is 200. */ |
/* iBGP distance is 200. */ |
if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP)) |
if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP)) |
Line 1747 void rib_lookup_and_pushup (struct prefix_ipv4 * p)
|
Line 1785 void rib_lookup_and_pushup (struct prefix_ipv4 * p)
|
} |
} |
|
|
int |
int |
rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib) | rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) |
{ |
{ |
struct route_table *table; |
struct route_table *table; |
struct route_node *rn; |
struct route_node *rn; |
Line 1755 rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct
|
Line 1793 rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct
|
struct nexthop *nexthop; |
struct nexthop *nexthop; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP, SAFI_UNICAST, 0); | table = vrf_table (AFI_IP, safi, 0); |
if (! table) |
if (! table) |
return 0; |
return 0; |
|
|
/* Make it sure prefixlen is applied to the prefix. */ |
/* Make it sure prefixlen is applied to the prefix. */ |
apply_mask_ipv4 (p); |
apply_mask_ipv4 (p); |
|
|
Line 1820 rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct
|
Line 1859 rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct
|
/* XXX factor with rib_delete_ipv6 */ |
/* XXX factor with rib_delete_ipv6 */ |
int |
int |
rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, |
struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id) | struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi) |
{ |
{ |
struct route_table *table; |
struct route_table *table; |
struct route_node *rn; |
struct route_node *rn; |
Line 1832 rib_delete_ipv4 (int type, int flags, struct prefix_ip
|
Line 1871 rib_delete_ipv4 (int type, int flags, struct prefix_ip
|
char buf2[INET_ADDRSTRLEN]; |
char buf2[INET_ADDRSTRLEN]; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP, SAFI_UNICAST, 0); | table = vrf_table (AFI_IP, safi, 0); |
if (! table) |
if (! table) |
return 0; |
return 0; |
|
|
Line 1879 rib_delete_ipv4 (int type, int flags, struct prefix_ip
|
Line 1918 rib_delete_ipv4 (int type, int flags, struct prefix_ip
|
if (rib->type != type) |
if (rib->type != type) |
continue; |
continue; |
if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) && |
if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) && |
nexthop->type == NEXTHOP_TYPE_IFINDEX && nexthop->ifindex == ifindex) | nexthop->type == NEXTHOP_TYPE_IFINDEX) |
{ |
{ |
|
if (nexthop->ifindex != ifindex) |
|
continue; |
if (rib->refcnt) |
if (rib->refcnt) |
{ |
{ |
rib->refcnt--; |
rib->refcnt--; |
Line 2281 rib_bogus_ipv6 (int type, struct prefix_ipv6 *p,
|
Line 2322 rib_bogus_ipv6 (int type, struct prefix_ipv6 *p,
|
int |
int |
rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, |
u_int32_t metric, u_char distance) | u_int32_t metric, u_char distance, safi_t safi) |
{ |
{ |
struct rib *rib; |
struct rib *rib; |
struct rib *same = NULL; |
struct rib *same = NULL; |
Line 2290 rib_add_ipv6 (int type, int flags, struct prefix_ipv6
|
Line 2331 rib_add_ipv6 (int type, int flags, struct prefix_ipv6
|
struct nexthop *nexthop; |
struct nexthop *nexthop; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); | table = vrf_table (AFI_IP6, safi, 0); |
if (! table) |
if (! table) |
return 0; |
return 0; |
|
|
Line 2375 rib_add_ipv6 (int type, int flags, struct prefix_ipv6
|
Line 2416 rib_add_ipv6 (int type, int flags, struct prefix_ipv6
|
/* XXX factor with rib_delete_ipv6 */ |
/* XXX factor with rib_delete_ipv6 */ |
int |
int |
rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, |
struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id) | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi) |
{ |
{ |
struct route_table *table; |
struct route_table *table; |
struct route_node *rn; |
struct route_node *rn; |
Line 2390 rib_delete_ipv6 (int type, int flags, struct prefix_ip
|
Line 2431 rib_delete_ipv6 (int type, int flags, struct prefix_ip
|
apply_mask_ipv6 (p); |
apply_mask_ipv6 (p); |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); | table = vrf_table (AFI_IP6, safi, 0); |
if (! table) |
if (! table) |
return 0; |
return 0; |
|
|
Line 2427 rib_delete_ipv6 (int type, int flags, struct prefix_ip
|
Line 2468 rib_delete_ipv6 (int type, int flags, struct prefix_ip
|
if (rib->type != type) |
if (rib->type != type) |
continue; |
continue; |
if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) && |
if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) && |
nexthop->type == NEXTHOP_TYPE_IFINDEX && nexthop->ifindex == ifindex) | nexthop->type == NEXTHOP_TYPE_IFINDEX) |
{ |
{ |
|
if (nexthop->ifindex != ifindex) |
|
continue; |
if (rib->refcnt) |
if (rib->refcnt) |
{ |
{ |
rib->refcnt--; |
rib->refcnt--; |
Line 2877 rib_sweep_route (void)
|
Line 2920 rib_sweep_route (void)
|
rib_sweep_table (vrf_table (AFI_IP, SAFI_UNICAST, 0)); |
rib_sweep_table (vrf_table (AFI_IP, SAFI_UNICAST, 0)); |
rib_sweep_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0)); |
rib_sweep_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0)); |
} |
} |
| |
| /* Remove specific by protocol routes from 'table'. */ |
| static unsigned long |
| rib_score_proto_table (u_char proto, struct route_table *table) |
| { |
| struct route_node *rn; |
| struct rib *rib; |
| struct rib *next; |
| unsigned long n = 0; |
| |
| if (table) |
| for (rn = route_top (table); rn; rn = route_next (rn)) |
| for (rib = rn->info; rib; rib = next) |
| { |
| next = rib->next; |
| if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) |
| continue; |
| if (rib->type == proto) |
| { |
| rib_delnode (rn, rib); |
| n++; |
| } |
| } |
| |
| return n; |
| } |
| |
| /* Remove specific by protocol routes. */ |
| unsigned long |
| rib_score_proto (u_char proto) |
| { |
| return rib_score_proto_table (proto, vrf_table (AFI_IP, SAFI_UNICAST, 0)) |
| +rib_score_proto_table (proto, vrf_table (AFI_IP6, SAFI_UNICAST, 0)); |
| } |
| |
/* Close RIB and clean up kernel routes. */ |
/* Close RIB and clean up kernel routes. */ |
static void |
static void |
rib_close_table (struct route_table *table) |
rib_close_table (struct route_table *table) |