From f992e2a98c357c1adc500f8ba712678282f1f8e7 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 19 May 2015 18:03:58 -0700 Subject: [PATCH] Install aggregate routes we create in the RIB --- bgpd/bgp_route.c | 12 ++++++++---- bgpd/bgp_zebra.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index cca1d750c2..de140d46d5 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2337,14 +2337,16 @@ bgp_process_main (struct work_queue *wq, void *data) { if (new_select && new_select->type == ZEBRA_ROUTE_BGP - && new_select->sub_type == BGP_ROUTE_NORMAL) + && (new_select->sub_type == BGP_ROUTE_NORMAL || + new_select->sub_type == BGP_ROUTE_AGGREGATE)) bgp_zebra_announce (p, new_select, bgp, afi, safi); else { /* Withdraw the route from the kernel. */ if (old_select && old_select->type == ZEBRA_ROUTE_BGP - && old_select->sub_type == BGP_ROUTE_NORMAL) + && (old_select->sub_type == BGP_ROUTE_NORMAL || + old_select->sub_type == BGP_ROUTE_AGGREGATE)) bgp_zebra_withdraw (p, old_select, safi); } } @@ -3838,7 +3840,8 @@ bgp_cleanup_routes (void) for (ri = rn->info; ri; ri = ri->next) if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->type == ZEBRA_ROUTE_BGP - && ri->sub_type == BGP_ROUTE_NORMAL) + && (ri->sub_type == BGP_ROUTE_NORMAL || + ri->sub_type == BGP_ROUTE_AGGREGATE)) bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); table = bgp->rib[AFI_IP6][SAFI_UNICAST]; @@ -3847,7 +3850,8 @@ bgp_cleanup_routes (void) for (ri = rn->info; ri; ri = ri->next) if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->type == ZEBRA_ROUTE_BGP - && ri->sub_type == BGP_ROUTE_NORMAL) + && (ri->sub_type == BGP_ROUTE_NORMAL || + ri->sub_type == BGP_ROUTE_AGGREGATE)) bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); } } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 8a97bd5f64..ed41c39bee 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -965,7 +965,13 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, else tag = 0; - if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) + /* When we create an aggregate route we must also install a Null0 route in + * the RIB */ + if (info->sub_type == BGP_ROUTE_AGGREGATE) + SET_FLAG (flags, ZEBRA_FLAG_BLACKHOLE); + + if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED || + info->sub_type == BGP_ROUTE_AGGREGATE) { SET_FLAG (flags, ZEBRA_FLAG_IBGP); SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); @@ -1064,7 +1070,17 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, api.message = 0; api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - api.nexthop_num = valid_nh_count; + + /* Note that this currently only applies to Null0 routes for aggregates. + * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv4_route to encode a special + * BLACKHOLE nexthop. We want to set api.nexthop_num to zero since we + * do not want to also encode the 0.0.0.0 nexthop for the aggregate route. + */ + if (CHECK_FLAG(flags, ZEBRA_FLAG_BLACKHOLE)) + api.nexthop_num = 0; + else + api.nexthop_num = valid_nh_count; + api.nexthop = (struct in_addr **)STREAM_DATA (bgp_nexthop_buf); api.ifindex_num = 0; SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); @@ -1233,7 +1249,17 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, api.message = 0; api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - api.nexthop_num = valid_nh_count; + + /* Note that this currently only applies to Null0 routes for aggregates. + * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv6_route to encode a special + * BLACKHOLE nexthop. We want to set api.nexthop_num to zero since we + * do not want to also encode the :: nexthop for the aggregate route. + */ + if (CHECK_FLAG(flags, ZEBRA_FLAG_BLACKHOLE)) + api.nexthop_num = 0; + else + api.nexthop_num = valid_nh_count; + api.nexthop = (struct in6_addr **)STREAM_DATA (bgp_nexthop_buf); SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); api.ifindex_num = valid_nh_count; -- 2.39.5