Merge pull request #1156 from donaldsharp/cleaner

Some minor cleanups around zebra code
This commit is contained in:
Renato Westphal 2017-09-12 12:42:55 -03:00 committed by GitHub
commit cc2e32a333
5 changed files with 54 additions and 39 deletions

View File

@ -84,11 +84,13 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id)
if (!rn) if (!rn)
continue; continue;
RNODE_FOREACH_RE(rn, newre) RNODE_FOREACH_RE(rn, newre) {
if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED) if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)
&& newre->distance != DISTANCE_INFINITY) && newre->distance != DISTANCE_INFINITY)
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD, zsend_redistribute_route(
client, &rn->p, NULL, newre); ZEBRA_REDISTRIBUTE_ROUTE_ADD,
client, &rn->p, NULL, newre);
}
route_unlock_node(rn); route_unlock_node(rn);
} }

View File

@ -2392,15 +2392,20 @@ void mpls_ldp_ftn_uninstall_all(struct zebra_vrf *zvrf, int afi)
for (rn = route_top(table); rn; rn = route_next(rn)) { for (rn = route_top(table); rn; rn = route_next(rn)) {
update = 0; update = 0;
RNODE_FOREACH_RE(rn, re) RNODE_FOREACH_RE(rn, re) {
for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) for (nexthop = re->nexthop;
if (nexthop->nh_label_type == ZEBRA_LSP_LDP) { nexthop;
nexthop = nexthop->next) {
if (nexthop->nh_label_type != ZEBRA_LSP_LDP)
continue;
nexthop_del_labels(nexthop); nexthop_del_labels(nexthop);
SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); SET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
SET_FLAG(re->status, SET_FLAG(re->status,
ROUTE_ENTRY_LABELS_CHANGED); ROUTE_ENTRY_LABELS_CHANGED);
update = 1; update = 1;
} }
}
if (update) if (update)
rib_queue_add(rn); rib_queue_add(rn);

View File

@ -1118,7 +1118,6 @@ static int rib_can_delete_dest(rib_dest_t *dest)
int rib_gc_dest(struct route_node *rn) int rib_gc_dest(struct route_node *rn)
{ {
rib_dest_t *dest; rib_dest_t *dest;
struct zebra_vrf *zvrf;
dest = rib_dest_from_rnode(rn); dest = rib_dest_from_rnode(rn);
if (!dest) if (!dest)
@ -1127,9 +1126,12 @@ int rib_gc_dest(struct route_node *rn)
if (!rib_can_delete_dest(dest)) if (!rib_can_delete_dest(dest))
return 0; return 0;
zvrf = rib_dest_vrf(dest); if (IS_ZEBRA_DEBUG_RIB) {
if (IS_ZEBRA_DEBUG_RIB) struct zebra_vrf *zvrf;
zvrf = rib_dest_vrf(dest);
rnode_debug(rn, zvrf_id(zvrf), "removing dest from table"); rnode_debug(rn, zvrf_id(zvrf), "removing dest from table");
}
dest->rnode = NULL; dest->rnode = NULL;
XFREE(MTYPE_RIB_DEST, dest); XFREE(MTYPE_RIB_DEST, dest);
@ -2551,27 +2553,29 @@ static void rib_update_table(struct route_table *table,
*/ */
RNODE_FOREACH_RE_SAFE(rn, re, next) RNODE_FOREACH_RE_SAFE(rn, re, next)
{ {
if (re->type == ZEBRA_ROUTE_OSPF struct nexthop *nh;
|| re->type == ZEBRA_ROUTE_OSPF6
|| re->type == ZEBRA_ROUTE_BGP)
continue; /* protocol will handle. */
else if (re->type == ZEBRA_ROUTE_STATIC) {
struct nexthop *nh;
for (nh = re->nexthop; nh;
nh = nh->next)
if (!(nh->type
== NEXTHOP_TYPE_IPV4
|| nh->type
== NEXTHOP_TYPE_IPV6))
break;
/* If we only have nexthops to a if (re->type != ZEBRA_ROUTE_SYSTEM &&
* gateway, NHT will re->type != ZEBRA_ROUTE_KERNEL &&
* take care. re->type != ZEBRA_ROUTE_CONNECT &&
*/ re->type != ZEBRA_ROUTE_STATIC)
if (nh) continue;
rib_queue_add(rn);
} else if (re->type != ZEBRA_ROUTE_STATIC) {
rib_queue_add(rn);
continue;
}
for (nh = re->nexthop; nh; nh = nh->next)
if (!(nh->type == NEXTHOP_TYPE_IPV4
|| nh->type == NEXTHOP_TYPE_IPV6))
break;
/* If we only have nexthops to a
* gateway, NHT will
* take care.
*/
if (nh)
rib_queue_add(rn); rib_queue_add(rn);
} }
break; break;

View File

@ -155,8 +155,9 @@ static u_char *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len,
/* Return number of routing entries. */ /* Return number of routing entries. */
result = 0; result = 0;
for (rn = route_top(table); rn; rn = route_next(rn)) for (rn = route_top(table); rn; rn = route_next(rn))
RNODE_FOREACH_RE(rn, re) RNODE_FOREACH_RE(rn, re) {
result++; result++;
}
return (u_char *)&result; return (u_char *)&result;
} }
@ -182,8 +183,9 @@ static u_char *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len,
/* Return number of routing entries. */ /* Return number of routing entries. */
result = 0; result = 0;
for (rn = route_top(table); rn; rn = route_next(rn)) for (rn = route_top(table); rn; rn = route_next(rn))
RNODE_FOREACH_RE(rn, re) RNODE_FOREACH_RE(rn, re) {
result++; result++;
}
return (u_char *)&result; return (u_char *)&result;
} }
@ -388,8 +390,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[],
/* Check destination first */ /* Check destination first */
if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) > 0) if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) > 0)
RNODE_FOREACH_RE(np2, re2) RNODE_FOREACH_RE(np2, re2) {
check_replace(np2, re2, np, re); check_replace(np2, re2, np, re);
}
if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest)
== 0) { /* have to look at each re individually */ == 0) { /* have to look at each re individually */

View File

@ -290,8 +290,9 @@ static void zebra_rtable_node_cleanup(struct route_table *table,
{ {
struct route_entry *re, *next; struct route_entry *re, *next;
RNODE_FOREACH_RE_SAFE(node, re, next) RNODE_FOREACH_RE_SAFE(node, re, next) {
rib_unlink(node, re); rib_unlink(node, re);
}
if (node->info) if (node->info)
XFREE(MTYPE_RIB_DEST, node->info); XFREE(MTYPE_RIB_DEST, node->info);