diff options
Diffstat (limited to 'bgpd/bgp_zebra.c')
| -rw-r--r-- | bgpd/bgp_zebra.c | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 66c18c8e57..47723f1dc4 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1227,7 +1227,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info struct bgp_info local_info; struct bgp_info *info_cp = &local_info; route_tag_t tag; - u_int32_t label; + mpls_label_t label; /* Don't try to install if we're not connected to Zebra or Zebra doesn't * know of this instance. @@ -1278,6 +1278,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info struct in_addr *nexthop; char buf[2][INET_ADDRSTRLEN]; int valid_nh_count = 0; + int has_valid_label = 0; /* resize nexthop buffer size if necessary */ if ((oldsize = stream_get_size (bgp_nexthop_buf)) < @@ -1297,7 +1298,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info /* For labeled unicast, each nexthop has a label too. Resize label * buffer, if required. */ - if (safi == SAFI_LABELED_UNICAST) + if (safi == SAFI_UNICAST) { if ((oldsize = stream_get_size (bgp_label_buf)) < (sizeof (unsigned int) * nhcount)) @@ -1342,10 +1343,11 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info { stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); valid_nh_count++; - if (safi == SAFI_LABELED_UNICAST) + if (info->extra && bgp_is_valid_label(&info->extra->label)) { - label = label_pton(info->extra->tag); - stream_put (bgp_label_buf, &label, sizeof (u_int32_t)); + has_valid_label = 1; + label = label_pton(&info->extra->label); + stream_put (bgp_label_buf, &label, sizeof (mpls_label_t)); } } @@ -1372,10 +1374,11 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info continue; stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); - if (safi == SAFI_LABELED_UNICAST) + if (mpinfo->extra && bgp_is_valid_label(&mpinfo->extra->label)) { - label = label_pton(mpinfo->extra->tag); - stream_put (bgp_label_buf, &label, sizeof (u_int32_t)); + has_valid_label = 1; + label = label_pton(&mpinfo->extra->label); + stream_put (bgp_label_buf, &label, sizeof (mpls_label_t)); } valid_nh_count++; } @@ -1385,9 +1388,10 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info api.type = ZEBRA_ROUTE_BGP; api.instance = 0; api.message = 0; - api.safi = (safi == SAFI_LABELED_UNICAST) ? SAFI_UNICAST : safi; + api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - if (safi == SAFI_LABELED_UNICAST) + + if (has_valid_label) SET_FLAG (api.message, ZAPI_MESSAGE_LABEL); /* Note that this currently only applies to Null0 routes for aggregates. @@ -1401,7 +1405,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info api.nexthop_num = valid_nh_count; api.nexthop = (struct in_addr **)STREAM_DATA (bgp_nexthop_buf); - if (safi == SAFI_LABELED_UNICAST) + if (has_valid_label) { api.label_num = valid_nh_count; api.label = (unsigned int *)STREAM_DATA (bgp_label_buf); @@ -1441,7 +1445,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info for (i = 0; i < api.nexthop_num; i++) { label_buf[0] = '\0'; - if (safi == SAFI_LABELED_UNICAST) + if (has_valid_label) sprintf(label_buf, "label %u", api.label[i]); zlog_debug(" nhop [%d]: %s %s", i+1, @@ -1463,6 +1467,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info struct zapi_ipv6 api; int valid_nh_count = 0; char buf[2][INET6_ADDRSTRLEN]; + int has_valid_label = 0; /* resize nexthop buffer size if necessary */ if ((oldsize = stream_get_size (bgp_nexthop_buf)) < @@ -1495,7 +1500,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info /* For labeled unicast, each nexthop has a label too. Resize label * buffer, if required. */ - if (safi == SAFI_LABELED_UNICAST) + if (safi == SAFI_UNICAST) { if ((oldsize = stream_get_size (bgp_label_buf)) < (sizeof (unsigned int) * nhcount)) @@ -1556,10 +1561,12 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info } stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in6_addr *)); stream_put (bgp_ifindices_buf, &ifindex, sizeof (unsigned int)); - if (safi == SAFI_LABELED_UNICAST) + + if (info->extra && bgp_is_valid_label(&info->extra->label)) { - label = label_pton(info->extra->tag); - stream_put (bgp_label_buf, &label, sizeof (u_int32_t)); + has_valid_label = 1; + label = label_pton(&info->extra->label); + stream_put (bgp_label_buf, &label, sizeof (mpls_label_t)); } valid_nh_count++; } @@ -1603,10 +1610,12 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in6_addr *)); stream_put (bgp_ifindices_buf, &ifindex, sizeof (unsigned int)); - if (safi == SAFI_LABELED_UNICAST) + + if (mpinfo->extra && bgp_is_valid_label(&mpinfo->extra->label)) { - label = label_pton(mpinfo->extra->tag); - stream_put (bgp_label_buf, &label, sizeof (u_int32_t)); + has_valid_label = 1; + label = label_pton(&mpinfo->extra->label); + stream_put (bgp_label_buf, &label, sizeof (mpls_label_t)); } valid_nh_count++; } @@ -1617,9 +1626,10 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info api.type = ZEBRA_ROUTE_BGP; api.instance = 0; api.message = 0; - api.safi = (safi == SAFI_LABELED_UNICAST) ? SAFI_UNICAST : safi; + api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - if (safi == SAFI_LABELED_UNICAST) + + if (has_valid_label) SET_FLAG (api.message, ZAPI_MESSAGE_LABEL); /* Note that this currently only applies to Null0 routes for aggregates. @@ -1636,7 +1646,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); api.ifindex_num = valid_nh_count; api.ifindex = (ifindex_t *)STREAM_DATA (bgp_ifindices_buf); - if (safi == SAFI_LABELED_UNICAST) + if (has_valid_label) { api.label_num = valid_nh_count; api.label = (unsigned int *)STREAM_DATA (bgp_label_buf); @@ -1676,7 +1686,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info for (i = 0; i < api.nexthop_num; i++) { label_buf[0] = '\0'; - if (safi == SAFI_LABELED_UNICAST) + if (has_valid_label) sprintf(label_buf, "label %u", api.label[i]); zlog_debug(" nhop [%d]: %s if %s %s", i+1, @@ -1707,7 +1717,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info for (i = 0; i < api.nexthop_num; i++) { label_buf[0] = '\0'; - if (safi == SAFI_LABELED_UNICAST) + if (has_valid_label) sprintf(label_buf, "label %u", api.label[i]); zlog_debug(" nhop [%d]: %s if %s %s", i+1, @@ -1793,10 +1803,8 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) api.type = ZEBRA_ROUTE_BGP; api.instance = 0; api.message = 0; - api.safi = (safi == SAFI_LABELED_UNICAST) ? SAFI_UNICAST : safi; + api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - if (safi == SAFI_LABELED_UNICAST) - SET_FLAG (api.message, ZAPI_MESSAGE_LABEL); api.nexthop_num = 0; api.nexthop = NULL; api.label_num = 0; @@ -1836,10 +1844,8 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) api.type = ZEBRA_ROUTE_BGP; api.instance = 0; api.message = 0; - api.safi = (safi == SAFI_LABELED_UNICAST) ? SAFI_UNICAST : safi; + api.safi = safi; SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); - if (safi == SAFI_LABELED_UNICAST) - SET_FLAG (api.message, ZAPI_MESSAGE_LABEL); api.nexthop_num = 0; api.nexthop = NULL; api.ifindex_num = 0; |
