Skip to content

Commit

Permalink
bgpd: fix invalid ipv4-vpn nexthop for IPv6 peer
Browse files Browse the repository at this point in the history
Given that two routers are connected each other and they have IPv6
addresses and they establish BGP peer with extended-nexthop capability
and one router tries to advertise locally-generated IPv4-VPN routes to
other router.

In this situation, bgpd on the router that tries to advertise IPv4-VPN
routes will be crashed with "invalid MP nexthop length (AFI IP6)".

This issue is happened because MP_REACH_NLRI path attribute is not
generated correctly when ipv4-vpn routes are advertised to IPv6 peer.
When IPv4 routes are leaked from VRF RIB, the nexthop of these routes
are also IPv4 address (0.0.0.0/0 or specific addresses). However,
bgp_packet_mpattr_start only covers the case of IPv6 nexthop (for IPv6
peer).

ipv4-unicast routes were not affected by this issue because the case of
IPv4 nexthop is covered in `else` block.

Signed-off-by: Ryoga Saito <[email protected]>
(cherry picked from commit 63e7ddb)
  • Loading branch information
Ryoga Saito authored and mergify[bot] committed Nov 17, 2022
1 parent daa2126 commit 8dff1be
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3736,13 +3736,6 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
} break;
case SAFI_MPLS_VPN: {
if (attr->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL) {
stream_putc(s, 24);
stream_putl(s, 0); /* RD = 0, per RFC */
stream_putl(s, 0);
stream_put(s, &attr->mp_nexthop_global,
IPV6_MAX_BYTELEN);
} else if (attr->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
stream_putc(s, 48);
stream_putl(s, 0); /* RD = 0, per RFC */
Expand All @@ -3753,6 +3746,12 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
stream_putl(s, 0);
stream_put(s, &attr->mp_nexthop_local,
IPV6_MAX_BYTELEN);
} else {
stream_putc(s, 24);
stream_putl(s, 0); /* RD = 0, per RFC */
stream_putl(s, 0);
stream_put(s, &attr->mp_nexthop_global,
IPV6_MAX_BYTELEN);
}
} break;
case SAFI_ENCAP:
Expand Down

0 comments on commit 8dff1be

Please sign in to comment.