diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 11:49:42 +0200 | 
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-08-09 12:03:17 +0200 | 
| commit | ac4d0be5874fafd14212d6007fff7495edc9b152 (patch) | |
| tree | 5e2f0d3189de928c849f9983406389ade3b098cb /zebra/zebra_static.c | |
| parent | 76a86854181c27819e5cf71b12ae1fa5ccd9e02a (diff) | |
*: reindentreindent-3.0-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'zebra/zebra_static.c')
| -rw-r--r-- | zebra/zebra_static.c | 1026 | 
1 files changed, 508 insertions, 518 deletions
diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c index 169f1827e0..384e3671ba 100644 --- a/zebra/zebra_static.c +++ b/zebra/zebra_static.c @@ -38,551 +38,541 @@  #include "zebra/zebra_memory.h"  /* Install static route into rib. */ -void -static_install_route (afi_t afi, safi_t safi, struct prefix *p, -                      struct prefix_ipv6 *src_p, struct static_route *si) +void static_install_route(afi_t afi, safi_t safi, struct prefix *p, +			  struct prefix_ipv6 *src_p, struct static_route *si)  { -  struct rib *rib; -  struct route_node *rn; -  struct route_table *table; -  struct prefix nh_p; -  struct nexthop *nexthop = NULL; - -  /* Lookup table.  */ -  table = zebra_vrf_table (afi, safi, si->vrf_id); -  if (! table) -    return; - -  memset (&nh_p, 0, sizeof (nh_p)); - -  /* Lookup existing route */ -  rn = srcdest_rnode_get (table, p, src_p); -  RNODE_FOREACH_RIB (rn, rib) -    { -       if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) -         continue; - -       if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance) -         break; -    } - -  if (rib) -    { -      /* if tag value changed , update old value in RIB */ -      if (rib->tag != si->tag) -        rib->tag = si->tag; - -      /* Same distance static route is there.  Update it with new -         nexthop. */ -      route_unlock_node (rn); -      switch (si->type) -        { -	case STATIC_IPV4_GATEWAY: -	  nexthop = rib_nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); -	  nh_p.family = AF_INET; -	  nh_p.prefixlen = IPV4_MAX_BITLEN; -	  nh_p.u.prefix4 = si->addr.ipv4; -	  zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); -	  break; -	case STATIC_IFNAME: -	  nexthop = rib_nexthop_ifindex_add (rib, si->ifindex); -	  break; -	case STATIC_BLACKHOLE: -	  nexthop = rib_nexthop_blackhole_add (rib); -	  break; -	case STATIC_IPV6_GATEWAY: -	  nexthop = rib_nexthop_ipv6_add (rib, &si->addr.ipv6); -	  nh_p.family = AF_INET6; -	  nh_p.prefixlen = IPV6_MAX_BITLEN; -	  nh_p.u.prefix6 = si->addr.ipv6; -	  zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); -	  break; -	case STATIC_IPV6_GATEWAY_IFNAME: -	  nexthop = rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, -						  si->ifindex); -	  break; -        } -      /* Update label(s), if present. */ -      if (si->snh_label.num_labels) -	nexthop_add_labels (nexthop, ZEBRA_LSP_STATIC, si->snh_label.num_labels, -			    &si->snh_label.label[0]); - -      if (IS_ZEBRA_DEBUG_RIB) -        { -          char buf[INET6_ADDRSTRLEN]; -          if (IS_ZEBRA_DEBUG_RIB) -            { -              inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); -              zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", -                          si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); -            } -        } -      /* Schedule route for processing or invoke NHT, as appropriate. */ -      if (si->type == STATIC_IPV4_GATEWAY || -          si->type == STATIC_IPV6_GATEWAY) -        zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); -      else -        rib_queue_add (rn); -    } -  else -    { -      /* This is new static route. */ -      rib = XCALLOC (MTYPE_RIB, sizeof (struct rib)); - -      rib->type = ZEBRA_ROUTE_STATIC; -      rib->instance = 0; -      rib->distance = si->distance; -      rib->metric = 0; -      rib->mtu = 0; -      rib->vrf_id = si->vrf_id; -      rib->table =  si->vrf_id ? (zebra_vrf_lookup_by_id(si->vrf_id))->table_id : zebrad.rtm_table_default; -      rib->nexthop_num = 0; -      rib->tag = si->tag; - -      switch (si->type) -        { -	case STATIC_IPV4_GATEWAY: -	  nexthop = rib_nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); -	  nh_p.family = AF_INET; -	  nh_p.prefixlen = IPV4_MAX_BITLEN; -	  nh_p.u.prefix4 = si->addr.ipv4; -	  zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); -	  break; -	case STATIC_IFNAME: -	  nexthop = rib_nexthop_ifindex_add (rib, si->ifindex); -	  break; -	case STATIC_BLACKHOLE: -	  nexthop = rib_nexthop_blackhole_add (rib); -	  break; -	case STATIC_IPV6_GATEWAY: -	  nexthop = rib_nexthop_ipv6_add (rib, &si->addr.ipv6); -	  nh_p.family = AF_INET6; -	  nh_p.prefixlen = IPV6_MAX_BITLEN; -	  nh_p.u.prefix6 = si->addr.ipv6; -	  zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); -	  break; -	case STATIC_IPV6_GATEWAY_IFNAME: -	  nexthop = rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, -						  si->ifindex); -	  break; -        } -      /* Update label(s), if present. */ -      if (si->snh_label.num_labels) -	nexthop_add_labels (nexthop, ZEBRA_LSP_STATIC, si->snh_label.num_labels, -			    &si->snh_label.label[0]); - -      /* Save the flags of this static routes (reject, blackhole) */ -      rib->flags = si->flags; - -      if (IS_ZEBRA_DEBUG_RIB) -        { -          char buf[INET6_ADDRSTRLEN]; -          if (IS_ZEBRA_DEBUG_RIB) -            { -              inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); -              zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d)", -                          si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); -            } -        } -      /* Link this rib to the tree. Schedule for processing or invoke NHT, -       * as appropriate. -       */ -      if (si->type == STATIC_IPV4_GATEWAY || -          si->type == STATIC_IPV6_GATEWAY) -        { -          rib_addnode (rn, rib, 0); -          zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); -        } -      else -        rib_addnode (rn, rib, 1); -    } +	struct rib *rib; +	struct route_node *rn; +	struct route_table *table; +	struct prefix nh_p; +	struct nexthop *nexthop = NULL; + +	/* Lookup table.  */ +	table = zebra_vrf_table(afi, safi, si->vrf_id); +	if (!table) +		return; + +	memset(&nh_p, 0, sizeof(nh_p)); + +	/* Lookup existing route */ +	rn = srcdest_rnode_get(table, p, src_p); +	RNODE_FOREACH_RIB(rn, rib) +	{ +		if (CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED)) +			continue; + +		if (rib->type == ZEBRA_ROUTE_STATIC +		    && rib->distance == si->distance) +			break; +	} + +	if (rib) { +		/* if tag value changed , update old value in RIB */ +		if (rib->tag != si->tag) +			rib->tag = si->tag; + +		/* Same distance static route is there.  Update it with new +		   nexthop. */ +		route_unlock_node(rn); +		switch (si->type) { +		case STATIC_IPV4_GATEWAY: +			nexthop = +				rib_nexthop_ipv4_add(rib, &si->addr.ipv4, NULL); +			nh_p.family = AF_INET; +			nh_p.prefixlen = IPV4_MAX_BITLEN; +			nh_p.u.prefix4 = si->addr.ipv4; +			zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); +			break; +		case STATIC_IFNAME: +			nexthop = rib_nexthop_ifindex_add(rib, si->ifindex); +			break; +		case STATIC_BLACKHOLE: +			nexthop = rib_nexthop_blackhole_add(rib); +			break; +		case STATIC_IPV6_GATEWAY: +			nexthop = rib_nexthop_ipv6_add(rib, &si->addr.ipv6); +			nh_p.family = AF_INET6; +			nh_p.prefixlen = IPV6_MAX_BITLEN; +			nh_p.u.prefix6 = si->addr.ipv6; +			zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); +			break; +		case STATIC_IPV6_GATEWAY_IFNAME: +			nexthop = rib_nexthop_ipv6_ifindex_add( +				rib, &si->addr.ipv6, si->ifindex); +			break; +		} +		/* Update label(s), if present. */ +		if (si->snh_label.num_labels) +			nexthop_add_labels(nexthop, ZEBRA_LSP_STATIC, +					   si->snh_label.num_labels, +					   &si->snh_label.label[0]); + +		if (IS_ZEBRA_DEBUG_RIB) { +			char buf[INET6_ADDRSTRLEN]; +			if (IS_ZEBRA_DEBUG_RIB) { +				inet_ntop(p->family, &p->u.prefix, buf, +					  INET6_ADDRSTRLEN); +				zlog_debug( +					"%u:%s/%d: Modifying route rn %p, rib %p (type %d)", +					si->vrf_id, buf, p->prefixlen, rn, rib, +					rib->type); +			} +		} +		/* Schedule route for processing or invoke NHT, as appropriate. +		 */ +		if (si->type == STATIC_IPV4_GATEWAY +		    || si->type == STATIC_IPV6_GATEWAY) +			zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, +					   RNH_NEXTHOP_TYPE, &nh_p); +		else +			rib_queue_add(rn); +	} else { +		/* This is new static route. */ +		rib = XCALLOC(MTYPE_RIB, sizeof(struct rib)); + +		rib->type = ZEBRA_ROUTE_STATIC; +		rib->instance = 0; +		rib->distance = si->distance; +		rib->metric = 0; +		rib->mtu = 0; +		rib->vrf_id = si->vrf_id; +		rib->table = +			si->vrf_id +				? (zebra_vrf_lookup_by_id(si->vrf_id))->table_id +				: zebrad.rtm_table_default; +		rib->nexthop_num = 0; +		rib->tag = si->tag; + +		switch (si->type) { +		case STATIC_IPV4_GATEWAY: +			nexthop = +				rib_nexthop_ipv4_add(rib, &si->addr.ipv4, NULL); +			nh_p.family = AF_INET; +			nh_p.prefixlen = IPV4_MAX_BITLEN; +			nh_p.u.prefix4 = si->addr.ipv4; +			zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); +			break; +		case STATIC_IFNAME: +			nexthop = rib_nexthop_ifindex_add(rib, si->ifindex); +			break; +		case STATIC_BLACKHOLE: +			nexthop = rib_nexthop_blackhole_add(rib); +			break; +		case STATIC_IPV6_GATEWAY: +			nexthop = rib_nexthop_ipv6_add(rib, &si->addr.ipv6); +			nh_p.family = AF_INET6; +			nh_p.prefixlen = IPV6_MAX_BITLEN; +			nh_p.u.prefix6 = si->addr.ipv6; +			zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); +			break; +		case STATIC_IPV6_GATEWAY_IFNAME: +			nexthop = rib_nexthop_ipv6_ifindex_add( +				rib, &si->addr.ipv6, si->ifindex); +			break; +		} +		/* Update label(s), if present. */ +		if (si->snh_label.num_labels) +			nexthop_add_labels(nexthop, ZEBRA_LSP_STATIC, +					   si->snh_label.num_labels, +					   &si->snh_label.label[0]); + +		/* Save the flags of this static routes (reject, blackhole) */ +		rib->flags = si->flags; + +		if (IS_ZEBRA_DEBUG_RIB) { +			char buf[INET6_ADDRSTRLEN]; +			if (IS_ZEBRA_DEBUG_RIB) { +				inet_ntop(p->family, &p->u.prefix, buf, +					  INET6_ADDRSTRLEN); +				zlog_debug( +					"%u:%s/%d: Inserting route rn %p, rib %p (type %d)", +					si->vrf_id, buf, p->prefixlen, rn, rib, +					rib->type); +			} +		} +		/* Link this rib to the tree. Schedule for processing or invoke +		 * NHT, +		 * as appropriate. +		 */ +		if (si->type == STATIC_IPV4_GATEWAY +		    || si->type == STATIC_IPV6_GATEWAY) { +			rib_addnode(rn, rib, 0); +			zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, +					   RNH_NEXTHOP_TYPE, &nh_p); +		} else +			rib_addnode(rn, rib, 1); +	}  }  /* this works correctly with IFNAME<>IFINDEX because a static route on a   * non-active interface will have IFINDEX_INTERNAL and thus compare false   */ -static int -static_nexthop_same (struct nexthop *nexthop, struct static_route *si) +static int static_nexthop_same(struct nexthop *nexthop, struct static_route *si)  { -  if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE -      && si->type == STATIC_BLACKHOLE) -    return 1; - -  if (nexthop->type == NEXTHOP_TYPE_IPV4 -      && si->type == STATIC_IPV4_GATEWAY -      && IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->addr.ipv4)) -    return 1; -  else if (nexthop->type == NEXTHOP_TYPE_IFINDEX -      && si->type == STATIC_IFNAME -      && nexthop->ifindex == si->ifindex) -    return 1; -  else if (nexthop->type == NEXTHOP_TYPE_IPV6 -      && si->type == STATIC_IPV6_GATEWAY -      && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6)) -    return 1; -  else if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX -      && si->type == STATIC_IPV6_GATEWAY_IFNAME -      && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6) -      && nexthop->ifindex == si->ifindex) -    return 1; - -  return 0; +	if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE +	    && si->type == STATIC_BLACKHOLE) +		return 1; + +	if (nexthop->type == NEXTHOP_TYPE_IPV4 +	    && si->type == STATIC_IPV4_GATEWAY +	    && IPV4_ADDR_SAME(&nexthop->gate.ipv4, &si->addr.ipv4)) +		return 1; +	else if (nexthop->type == NEXTHOP_TYPE_IFINDEX +		 && si->type == STATIC_IFNAME +		 && nexthop->ifindex == si->ifindex) +		return 1; +	else if (nexthop->type == NEXTHOP_TYPE_IPV6 +		 && si->type == STATIC_IPV6_GATEWAY +		 && IPV6_ADDR_SAME(&nexthop->gate.ipv6, &si->addr.ipv6)) +		return 1; +	else if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX +		 && si->type == STATIC_IPV6_GATEWAY_IFNAME +		 && IPV6_ADDR_SAME(&nexthop->gate.ipv6, &si->addr.ipv6) +		 && nexthop->ifindex == si->ifindex) +		return 1; + +	return 0;  }  /* Uninstall static route from RIB. */ -void -static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, -                        struct prefix_ipv6 *src_p, struct static_route *si) +void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p, +			    struct prefix_ipv6 *src_p, struct static_route *si)  { -  struct route_node *rn; -  struct rib *rib; -  struct nexthop *nexthop; -  struct route_table *table; -  struct prefix nh_p; - -  /* Lookup table.  */ -  table = zebra_vrf_table (afi, safi, si->vrf_id); -  if (! table) -    return; - -  /* Lookup existing route with type and distance. */ -  rn = srcdest_rnode_lookup (table, p, src_p); -  if (! rn) -    return; - -  RNODE_FOREACH_RIB (rn, rib) -    { -      if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) -        continue; - -      if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance && -          rib->tag == si->tag) -        break; -    } - -  if (! rib) -    { -      route_unlock_node (rn); -      return; -    } - -  /* Lookup nexthop. */ -  for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) -    if (static_nexthop_same (nexthop, si)) -      break; - -  /* Can't find nexthop. */ -  if (! nexthop) -    { -      route_unlock_node (rn); -      return; -    } - -  /* Check nexthop. */ -  if (rib->nexthop_num == 1) -    rib_delnode (rn, rib); -  else -    { -      /* Mark this nexthop as inactive and reinstall the route. Then, delete -       * the nexthop. There is no need to re-evaluate the route for this -       * scenario. -       */ -      if (IS_ZEBRA_DEBUG_RIB) -        { -          char buf[INET6_ADDRSTRLEN]; -          if (IS_ZEBRA_DEBUG_RIB) -            { -              inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); -              zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", -                          si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); -            } -        } -      UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); -      if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) -        { -          /* If there are other active nexthops, do an update. */ -          if (rib->nexthop_active_num > 1) -            { -              /* Update route in kernel if it's in fib */ -              if (CHECK_FLAG(rib->status, RIB_ENTRY_SELECTED_FIB)) -                rib_install_kernel (rn, rib, rib); -              /* Update redistribution if it's selected */ -              if (CHECK_FLAG(rib->flags, ZEBRA_FLAG_SELECTED)) -                redistribute_update (p, (struct prefix*)src_p, rib, NULL); -            } -          else -            { -              /* Remove from redistribute if selected route becomes inactive */ -              if (CHECK_FLAG(rib->flags, ZEBRA_FLAG_SELECTED)) -                redistribute_delete (p, (struct prefix*)src_p, rib); -              /* Remove from kernel if fib route becomes inactive */ -              if (CHECK_FLAG(rib->status, RIB_ENTRY_SELECTED_FIB)) -              rib_uninstall_kernel (rn, rib); -            } -        } - -      if (afi == AFI_IP) +	struct route_node *rn; +	struct rib *rib; +	struct nexthop *nexthop; +	struct route_table *table; +	struct prefix nh_p; + +	/* Lookup table.  */ +	table = zebra_vrf_table(afi, safi, si->vrf_id); +	if (!table) +		return; + +	/* Lookup existing route with type and distance. */ +	rn = srcdest_rnode_lookup(table, p, src_p); +	if (!rn) +		return; + +	RNODE_FOREACH_RIB(rn, rib)  	{ -	  /* Delete the nexthop and dereg from NHT */ -	  nh_p.family = AF_INET; -	  nh_p.prefixlen = IPV4_MAX_BITLEN; -	  nh_p.u.prefix4 = nexthop->gate.ipv4; +		if (CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED)) +			continue; + +		if (rib->type == ZEBRA_ROUTE_STATIC +		    && rib->distance == si->distance && rib->tag == si->tag) +			break;  	} -      else -	{ -	  nh_p.family = AF_INET6; -	  nh_p.prefixlen = IPV6_MAX_BITLEN; -	  nh_p.u.prefix6 = nexthop->gate.ipv6; + +	if (!rib) { +		route_unlock_node(rn); +		return; +	} + +	/* Lookup nexthop. */ +	for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) +		if (static_nexthop_same(nexthop, si)) +			break; + +	/* Can't find nexthop. */ +	if (!nexthop) { +		route_unlock_node(rn); +		return; +	} + +	/* Check nexthop. */ +	if (rib->nexthop_num == 1) +		rib_delnode(rn, rib); +	else { +		/* Mark this nexthop as inactive and reinstall the route. Then, +		 * delete +		 * the nexthop. There is no need to re-evaluate the route for +		 * this +		 * scenario. +		 */ +		if (IS_ZEBRA_DEBUG_RIB) { +			char buf[INET6_ADDRSTRLEN]; +			if (IS_ZEBRA_DEBUG_RIB) { +				inet_ntop(p->family, &p->u.prefix, buf, +					  INET6_ADDRSTRLEN); +				zlog_debug( +					"%u:%s/%d: Modifying route rn %p, rib %p (type %d)", +					si->vrf_id, buf, p->prefixlen, rn, rib, +					rib->type); +			} +		} +		UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); +		if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { +			/* If there are other active nexthops, do an update. */ +			if (rib->nexthop_active_num > 1) { +				/* Update route in kernel if it's in fib */ +				if (CHECK_FLAG(rib->status, +					       RIB_ENTRY_SELECTED_FIB)) +					rib_install_kernel(rn, rib, rib); +				/* Update redistribution if it's selected */ +				if (CHECK_FLAG(rib->flags, ZEBRA_FLAG_SELECTED)) +					redistribute_update( +						p, (struct prefix *)src_p, rib, +						NULL); +			} else { +				/* Remove from redistribute if selected route +				 * becomes inactive */ +				if (CHECK_FLAG(rib->flags, ZEBRA_FLAG_SELECTED)) +					redistribute_delete( +						p, (struct prefix *)src_p, rib); +				/* Remove from kernel if fib route becomes +				 * inactive */ +				if (CHECK_FLAG(rib->status, +					       RIB_ENTRY_SELECTED_FIB)) +					rib_uninstall_kernel(rn, rib); +			} +		} + +		if (afi == AFI_IP) { +			/* Delete the nexthop and dereg from NHT */ +			nh_p.family = AF_INET; +			nh_p.prefixlen = IPV4_MAX_BITLEN; +			nh_p.u.prefix4 = nexthop->gate.ipv4; +		} else { +			nh_p.family = AF_INET6; +			nh_p.prefixlen = IPV6_MAX_BITLEN; +			nh_p.u.prefix6 = nexthop->gate.ipv6; +		} +		rib_nexthop_delete(rib, nexthop); +		zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn); +		nexthop_free(nexthop);  	} -      rib_nexthop_delete (rib, nexthop); -      zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn); -      nexthop_free (nexthop); -    } -  /* Unlock node. */ -  route_unlock_node (rn); +	/* Unlock node. */ +	route_unlock_node(rn);  } -int -static_add_route (afi_t afi, safi_t safi, u_char type, struct prefix *p, -		  struct prefix_ipv6 *src_p, union g_addr *gate, -		  const char *ifname, u_char flags, route_tag_t tag, -		  u_char distance, struct zebra_vrf *zvrf, -		  struct static_nh_label *snh_label) +int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, +		     struct prefix_ipv6 *src_p, union g_addr *gate, +		     const char *ifname, u_char flags, route_tag_t tag, +		     u_char distance, struct zebra_vrf *zvrf, +		     struct static_nh_label *snh_label)  { -  struct route_node *rn; -  struct static_route *si; -  struct static_route *pp; -  struct static_route *cp; -  struct static_route *update = NULL; -  struct route_table *stable = zvrf->stable[afi][safi]; - -  if (! stable) -    return -1; - -  if (!gate && -      (type == STATIC_IPV4_GATEWAY || -       type == STATIC_IPV6_GATEWAY || -       type == STATIC_IPV6_GATEWAY_IFNAME)) -    return -1; - -  if (!ifname && -      (type == STATIC_IFNAME || -       type == STATIC_IPV6_GATEWAY_IFNAME)) -    return -1; - -  /* Lookup static route prefix. */ -  rn = srcdest_rnode_get (stable, p, src_p); - -  /* Do nothing if there is a same static route.  */ -  for (si = rn->info; si; si = si->next) -    { -      if (type == si->type -	  && (! gate || -	      ((afi == AFI_IP && IPV4_ADDR_SAME (gate, &si->addr.ipv4)) || -	       (afi == AFI_IP6 && IPV6_ADDR_SAME (gate, &si->addr.ipv6)))) -	  && (!strcmp (ifname ? ifname : "", si->ifname))) -	{ -	  if ((distance == si->distance) && (tag == si->tag) && -	      !memcmp (&si->snh_label, snh_label, sizeof (struct static_nh_label)) && -	      si->flags == flags) -	    { -	      route_unlock_node (rn); -	      return 0; -	    } -	  else -	    update = si; +	struct route_node *rn; +	struct static_route *si; +	struct static_route *pp; +	struct static_route *cp; +	struct static_route *update = NULL; +	struct route_table *stable = zvrf->stable[afi][safi]; + +	if (!stable) +		return -1; + +	if (!gate && (type == STATIC_IPV4_GATEWAY || type == STATIC_IPV6_GATEWAY +		      || type == STATIC_IPV6_GATEWAY_IFNAME)) +		return -1; + +	if (!ifname +	    && (type == STATIC_IFNAME || type == STATIC_IPV6_GATEWAY_IFNAME)) +		return -1; + +	/* Lookup static route prefix. */ +	rn = srcdest_rnode_get(stable, p, src_p); + +	/* Do nothing if there is a same static route.  */ +	for (si = rn->info; si; si = si->next) { +		if (type == si->type +		    && (!gate || ((afi == AFI_IP +				   && IPV4_ADDR_SAME(gate, &si->addr.ipv4)) +				  || (afi == AFI_IP6 +				      && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) +		    && (!strcmp(ifname ? ifname : "", si->ifname))) { +			if ((distance == si->distance) && (tag == si->tag) +			    && !memcmp(&si->snh_label, snh_label, +				       sizeof(struct static_nh_label)) +			    && si->flags == flags) { +				route_unlock_node(rn); +				return 0; +			} else +				update = si; +		}  	} -    } - -  /* Distance or tag or label changed, delete existing first. */ -  if (update) -    static_delete_route (afi, safi, type, p, src_p, gate, ifname, update->tag, -			 update->distance, zvrf, &update->snh_label); - -  /* Make new static route structure. */ -  si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route)); - -  si->type = type; -  si->distance = distance; -  si->flags = flags; -  si->tag = tag; -  si->vrf_id = zvrf_id (zvrf); -  if (ifname) -    strlcpy(si->ifname, ifname, sizeof(si->ifname)); -  si->ifindex = IFINDEX_INTERNAL; - -  switch (type) -    { -    case STATIC_IPV4_GATEWAY: -      si->addr.ipv4 = gate->ipv4; -      break; -    case STATIC_IPV6_GATEWAY: -      si->addr.ipv6 = gate->ipv6; -      break; -    case STATIC_IPV6_GATEWAY_IFNAME: -      si->addr.ipv6 = gate->ipv6; -      break; -    case STATIC_IFNAME: -      break; -    } - -  /* Save labels, if any. */ -  memcpy (&si->snh_label, snh_label, sizeof (struct static_nh_label)); - -  /* Add new static route information to the tree with sort by -     distance value and gateway address. */ -  for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) -    { -      if (si->distance < cp->distance) -	break; -      if (si->distance > cp->distance) -	continue; -      if (si->type == STATIC_IPV4_GATEWAY && cp->type == STATIC_IPV4_GATEWAY) -	{ -	  if (ntohl (si->addr.ipv4.s_addr) < ntohl (cp->addr.ipv4.s_addr)) -	    break; -	  if (ntohl (si->addr.ipv4.s_addr) > ntohl (cp->addr.ipv4.s_addr)) -	    continue; + +	/* Distance or tag or label changed, delete existing first. */ +	if (update) +		static_delete_route(afi, safi, type, p, src_p, gate, ifname, +				    update->tag, update->distance, zvrf, +				    &update->snh_label); + +	/* Make new static route structure. */ +	si = XCALLOC(MTYPE_STATIC_ROUTE, sizeof(struct static_route)); + +	si->type = type; +	si->distance = distance; +	si->flags = flags; +	si->tag = tag; +	si->vrf_id = zvrf_id(zvrf); +	if (ifname) +		strlcpy(si->ifname, ifname, sizeof(si->ifname)); +	si->ifindex = IFINDEX_INTERNAL; + +	switch (type) { +	case STATIC_IPV4_GATEWAY: +		si->addr.ipv4 = gate->ipv4; +		break; +	case STATIC_IPV6_GATEWAY: +		si->addr.ipv6 = gate->ipv6; +		break; +	case STATIC_IPV6_GATEWAY_IFNAME: +		si->addr.ipv6 = gate->ipv6; +		break; +	case STATIC_IFNAME: +		break;  	} -    } - -  /* Make linked list. */ -  if (pp) -    pp->next = si; -  else -    rn->info = si; -  if (cp) -    cp->prev = si; -  si->prev = pp; -  si->next = cp; - -  /* check whether interface exists in system & install if it does */ -  if (!ifname) -    static_install_route(afi, safi, p, src_p, si); -  else -    { -      struct interface *ifp; - -      ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); -      if (ifp && ifp->ifindex != IFINDEX_INTERNAL) -        { -          si->ifindex = ifp->ifindex; -          static_install_route (afi, safi, p, src_p, si); -        } -    } - -  return 1; + +	/* Save labels, if any. */ +	memcpy(&si->snh_label, snh_label, sizeof(struct static_nh_label)); + +	/* Add new static route information to the tree with sort by +	   distance value and gateway address. */ +	for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) { +		if (si->distance < cp->distance) +			break; +		if (si->distance > cp->distance) +			continue; +		if (si->type == STATIC_IPV4_GATEWAY +		    && cp->type == STATIC_IPV4_GATEWAY) { +			if (ntohl(si->addr.ipv4.s_addr) +			    < ntohl(cp->addr.ipv4.s_addr)) +				break; +			if (ntohl(si->addr.ipv4.s_addr) +			    > ntohl(cp->addr.ipv4.s_addr)) +				continue; +		} +	} + +	/* Make linked list. */ +	if (pp) +		pp->next = si; +	else +		rn->info = si; +	if (cp) +		cp->prev = si; +	si->prev = pp; +	si->next = cp; + +	/* check whether interface exists in system & install if it does */ +	if (!ifname) +		static_install_route(afi, safi, p, src_p, si); +	else { +		struct interface *ifp; + +		ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); +		if (ifp && ifp->ifindex != IFINDEX_INTERNAL) { +			si->ifindex = ifp->ifindex; +			static_install_route(afi, safi, p, src_p, si); +		} +	} + +	return 1;  } -int -static_delete_route (afi_t afi, safi_t safi, u_char type, struct prefix *p, -		     struct prefix_ipv6 *src_p, -		     union g_addr *gate, const char *ifname, -		     route_tag_t tag, u_char distance, struct zebra_vrf *zvrf, -		     struct static_nh_label *snh_label) +int static_delete_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, +			struct prefix_ipv6 *src_p, union g_addr *gate, +			const char *ifname, route_tag_t tag, u_char distance, +			struct zebra_vrf *zvrf, +			struct static_nh_label *snh_label)  { -  struct route_node *rn; -  struct static_route *si; -  struct route_table *stable; - -  /* Lookup table.  */ -  stable = zebra_vrf_static_table (afi, safi, zvrf); -  if (! stable) -    return -1; - -  /* Lookup static route prefix. */ -  rn = srcdest_rnode_lookup (stable, p, src_p); -  if (! rn) -    return 0; - -  /* Find same static route is the tree */ -  for (si = rn->info; si; si = si->next) -    if (type == si->type -	&& (! gate || ( -		       (afi == AFI_IP && IPV4_ADDR_SAME (gate, &si->addr.ipv4)) || -		       (afi == AFI_IP6 && IPV6_ADDR_SAME (gate, &si->addr.ipv6)))) -	&& (!strcmp(ifname ? ifname : "", si->ifname)) -	&& (! tag || (tag == si->tag)) -	&& (! snh_label->num_labels || -	    !memcmp (&si->snh_label, snh_label, sizeof (struct static_nh_label)))) -      break; - -  /* Can't find static route. */ -  if (! si) -    { -      route_unlock_node (rn); -      return 0; -    } - -  /* Uninstall from rib. */ -  if (!si->ifname[0] || si->ifindex != IFINDEX_INTERNAL) -    static_uninstall_route (afi, safi, p, src_p, si); - -  /* Unlink static route from linked list. */ -  if (si->prev) -    si->prev->next = si->next; -  else -    rn->info = si->next; -  if (si->next) -    si->next->prev = si->prev; -  route_unlock_node (rn); - -  /* Free static route configuration. */ -  XFREE (MTYPE_STATIC_ROUTE, si); - -  route_unlock_node (rn); - -  return 1; +	struct route_node *rn; +	struct static_route *si; +	struct route_table *stable; + +	/* Lookup table.  */ +	stable = zebra_vrf_static_table(afi, safi, zvrf); +	if (!stable) +		return -1; + +	/* Lookup static route prefix. */ +	rn = srcdest_rnode_lookup(stable, p, src_p); +	if (!rn) +		return 0; + +	/* Find same static route is the tree */ +	for (si = rn->info; si; si = si->next) +		if (type == si->type +		    && (!gate || ((afi == AFI_IP +				   && IPV4_ADDR_SAME(gate, &si->addr.ipv4)) +				  || (afi == AFI_IP6 +				      && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) +		    && (!strcmp(ifname ? ifname : "", si->ifname)) +		    && (!tag || (tag == si->tag)) +		    && (!snh_label->num_labels +			|| !memcmp(&si->snh_label, snh_label, +				   sizeof(struct static_nh_label)))) +			break; + +	/* Can't find static route. */ +	if (!si) { +		route_unlock_node(rn); +		return 0; +	} + +	/* Uninstall from rib. */ +	if (!si->ifname[0] || si->ifindex != IFINDEX_INTERNAL) +		static_uninstall_route(afi, safi, p, src_p, si); + +	/* Unlink static route from linked list. */ +	if (si->prev) +		si->prev->next = si->next; +	else +		rn->info = si->next; +	if (si->next) +		si->next->prev = si->prev; +	route_unlock_node(rn); + +	/* Free static route configuration. */ +	XFREE(MTYPE_STATIC_ROUTE, si); + +	route_unlock_node(rn); + +	return 1;  } -static void -static_ifindex_update_af(struct interface *ifp, bool up, -                         afi_t afi, safi_t safi) +static void static_ifindex_update_af(struct interface *ifp, bool up, afi_t afi, +				     safi_t safi)  { -  struct route_table *stable; -  struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); -  struct route_node *rn; -  struct static_route *si; -  struct prefix *p, *src_pp; -  struct prefix_ipv6 *src_p; - -  stable = zebra_vrf_static_table(afi, safi, zvrf); -  if (!stable) -    return; - -  for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) -    { -      srcdest_rnode_prefixes(rn, &p, &src_pp); -      src_p = (struct prefix_ipv6 *)src_pp; - -      for (si = rn->info; si; si = si->next) -        { -          if (!si->ifname[0]) -            continue; -          if (up) -            { -              if (strcmp(si->ifname, ifp->name)) -                continue; -              si->ifindex = ifp->ifindex; -              static_install_route(afi, safi, p, src_p, si); -            } -          else -            { -              if (si->ifindex != ifp->ifindex) -                continue; -              static_uninstall_route(afi, safi, p, src_p, si); -              si->ifindex = IFINDEX_INTERNAL; -          } -        } -    } +	struct route_table *stable; +	struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); +	struct route_node *rn; +	struct static_route *si; +	struct prefix *p, *src_pp; +	struct prefix_ipv6 *src_p; + +	stable = zebra_vrf_static_table(afi, safi, zvrf); +	if (!stable) +		return; + +	for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) { +		srcdest_rnode_prefixes(rn, &p, &src_pp); +		src_p = (struct prefix_ipv6 *)src_pp; + +		for (si = rn->info; si; si = si->next) { +			if (!si->ifname[0]) +				continue; +			if (up) { +				if (strcmp(si->ifname, ifp->name)) +					continue; +				si->ifindex = ifp->ifindex; +				static_install_route(afi, safi, p, src_p, si); +			} else { +				if (si->ifindex != ifp->ifindex) +					continue; +				static_uninstall_route(afi, safi, p, src_p, si); +				si->ifindex = IFINDEX_INTERNAL; +			} +		} +	}  }  /* called from if_{add,delete}_update, i.e. when ifindex becomes [in]valid */ -void -static_ifindex_update(struct interface *ifp, bool up) +void static_ifindex_update(struct interface *ifp, bool up)  { -  static_ifindex_update_af(ifp, up, AFI_IP, SAFI_UNICAST); -  static_ifindex_update_af(ifp, up, AFI_IP, SAFI_MULTICAST); -  static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_UNICAST); -  static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_MULTICAST); +	static_ifindex_update_af(ifp, up, AFI_IP, SAFI_UNICAST); +	static_ifindex_update_af(ifp, up, AFI_IP, SAFI_MULTICAST); +	static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_UNICAST); +	static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_MULTICAST);  }  | 
