Skip to content

Commit a9e767b

Browse files
authored
Merge pull request FRRouting#19808 from opensourcerouting/fix/draft-ietf-idr-next-next-hop-nodes
bgpd: Put local BGP ID when sending NNHN TLV for NH characteristic
2 parents a44a6d8 + fdddac1 commit a9e767b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

bgpd/bgp_attr.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3767,7 +3767,7 @@ static int bgp_attr_nhc(struct bgp_attr_parser_args *args)
37673767
zlog_debug("%pBP rcvd BGP NHC TLV code %d, length %d, value %p", peer,
37683768
tlv->code, tlv->length, tlv->value);
37693769

3770-
/* draft-wang-idr-next-next-hop-nodes */
3770+
/* draft-ietf-idr-next-next-hop-nodes-00 */
37713771
if (tlv->code == BGP_ATTR_NHC_TLV_NNHN) {
37723772
if (tlv->length % IPV4_MAX_BYTELEN != 0) {
37733773
zlog_err("%pBP rcvd BGP NHC (NNHN TLV) length %d not a multiple of %d",
@@ -4640,6 +4640,7 @@ static void bgp_packet_nhc(struct stream *s, struct peer *peer, afi_t afi, safi_
46404640
prefix = bgp_dest_get_prefix(bpi->net);
46414641

46424642
total = bgp_path_info_mpath_count(bpi) * IPV4_MAX_BYTELEN;
4643+
total += IPV4_MAX_BYTELEN; /* Next-hop BGP ID */
46434644

46444645
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
46454646
stream_putc(s, BGP_ATTR_NHC);
@@ -4671,12 +4672,22 @@ static void bgp_packet_nhc(struct stream *s, struct peer *peer, afi_t afi, safi_
46714672
/* Put TLVs */
46724673

46734674
/* Begin NNHN TLV */
4675+
/*
4676+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4677+
* | Characteristic Code = 2 |Characteristic Length(variable)|
4678+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4679+
* | Next-hop BGP ID |
4680+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4681+
* | Next-next-hop BGP IDs (variable) |
4682+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4683+
*/
46744684
if (bgp_path_info_mpath_count(bpi) > 1) {
46754685
if (bgp_debug_update(peer, NULL, NULL, 1))
46764686
zlog_debug("%pBP: Sending NHC TLV (%d) for %pFX", peer,
46774687
BGP_ATTR_NHC_TLV_NNHN, prefix);
46784688
stream_putw(s, BGP_ATTR_NHC_TLV_NNHN);
46794689
stream_putw(s, total);
4690+
stream_put_ipv4(s, bpi->peer->local_id.s_addr);
46804691
stream_put_ipv4(s, bpi->peer->remote_id.s_addr);
46814692

46824693
for (exists = bgp_path_info_mpath_first(bpi); exists;

bgpd/bgp_nhc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ uint64_t bgp_nhc_nnhn_count(struct bgp_nhc *nhc)
8989
if (tlv->code == BGP_ATTR_NHC_TLV_NNHN) {
9090
/* BGP Identifier is always 4-bytes (yet...) */
9191
count = tlv->length / IPV4_MAX_BYTELEN;
92-
break;
92+
if (count <= 1)
93+
return 0;
94+
95+
/* -1 is to exclude the next-hop BGP ID.
96+
* We care only about Next-next hops here.
97+
*/
98+
return count - 1;
9399
}
94100
}
95101

96-
return count;
102+
return 0;
97103
}

bgpd/bgp_nhc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct bgp_nhc {
4545
#define BGP_NHC_MIN_IPV6_LEN 24
4646

4747
/* TLV values: */
48-
/* draft-wang-idr-next-next-hop-nodes */
48+
/* draft-ietf-idr-next-next-hop-nodes-00 */
4949
#define BGP_ATTR_NHC_TLV_NNHN 2
5050
/* draft-ietf-idr-entropy-label */
5151
#define BGP_ATTR_NHC_TLV_BGPID 3

bgpd/bgp_route.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12663,7 +12663,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
1266312663
else
1266412664
json_nhc_nnhn = json_object_new_array();
1266512665

12666-
for (i = 0; i < tlv->length; i += IPV4_MAX_BYTELEN) {
12666+
/* First is Next-hop BGP ID, skip it. */
12667+
for (i = IPV4_MAX_BYTELEN; i < tlv->length;
12668+
i += IPV4_MAX_BYTELEN) {
1266712669
if (!json_paths) {
1266812670
vty_out(vty, " %pI4\n",
1266912671
(struct in_addr *)&tlv->value[i]);

0 commit comments

Comments
 (0)