Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: fix updating ipv6 global nexthop #17152

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 35 additions & 46 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,56 +324,45 @@ static int bgp_interface_address_add(ZAPI_CALLBACK_ARGS)
if (!bgp)
return 0;

if (if_is_operative(ifc->ifp)) {
bgp_connected_add(bgp, ifc);
if (!if_is_operative(ifc->ifp))
return 0;

/* If we have learnt of any neighbors on this interface,
* check to kick off any BGP interface-based neighbors,
* but only if this is a link-local address.
*/
if (IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6)
&& !list_isempty(ifc->ifp->nbr_connected))
bgp_start_interface_nbrs(bgp, ifc->ifp);
else {
addr = ifc->address;
bgp_connected_add(bgp, ifc);

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (addr->family == AF_INET)
continue;
/* If we have learnt of any neighbors on this interface,
* check to kick off any BGP interface-based neighbors,
* but only if this is a link-local address.
*/
if (IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6) &&
!list_isempty(ifc->ifp->nbr_connected))
bgp_start_interface_nbrs(bgp, ifc->ifp);
else if (ifc->address->family == AF_INET6 &&
!IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6)) {
addr = ifc->address;

/*
* If the Peer's interface name matches the
* interface name for which BGP received the
* update and if the received interface address
* is a globalV6 and if the peer is currently
* using a v4-mapped-v6 addr or a link local
* address, then copy the Rxed global v6 addr
* into peer's v6_global and send updates out
* with new nexthop addr.
*/
if ((peer->conf_if &&
(strcmp(peer->conf_if, ifc->ifp->name) ==
0)) &&
!IN6_IS_ADDR_LINKLOCAL(&addr->u.prefix6) &&
((IS_MAPPED_IPV6(
&peer->nexthop.v6_global)) ||
IN6_IS_ADDR_LINKLOCAL(
&peer->nexthop.v6_global))) {

if (bgp_debug_zebra(ifc->address)) {
zlog_debug(
"Update peer %pBP's current intf addr %pI6 and send updates",
peer,
&peer->nexthop
.v6_global);
}
memcpy(&peer->nexthop.v6_global,
&addr->u.prefix6,
IPV6_MAX_BYTELEN);
FOREACH_AFI_SAFI (afi, safi)
bgp_announce_route(peer, afi,
safi, true);
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
/*
* If the Peer's interface name matches the
* interface name for which BGP received the
* update and if the received interface address
* is a globalV6 and if the peer is currently
* using a v4-mapped-v6 addr or a link local
* address, then copy the Rxed global v6 addr
* into peer's v6_global and send updates out
* with new nexthop addr.
*/
if ((peer->nexthop.ifp == ifc->ifp ||
(peer->conf_if && strcmp(peer->conf_if, ifc->ifp->name) == 0)) &&
(IS_MAPPED_IPV6(&peer->nexthop.v6_global) ||
IN6_IS_ADDR_LINKLOCAL(&peer->nexthop.v6_global) ||
IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_global))) {
if (bgp_debug_zebra(ifc->address)) {
zlog_debug("Update peer %pBP's current intf global addr from %pI6 to %pI6 and send updates",
peer, &peer->nexthop.v6_global, &addr->u.prefix6);
}
memcpy(&peer->nexthop.v6_global, &addr->u.prefix6, IPV6_MAX_BYTELEN);
FOREACH_AFI_SAFI (afi, safi)
bgp_announce_route(peer, afi, safi, true);
}
}
}
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/h1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ipv6 route ::/0 fd00:100::2
ip route 0.0.0.0/0 192.168.1.2
interface eth-r1
ip address 192.168.1.1/24
ipv6 address fd00:100::1/64
!
6 changes: 6 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/h2/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ipv6 route ::/0 fd00:700::2
ip route 0.0.0.0/0 192.168.7.2
interface eth-r7
ip address 192.168.7.1/24
ipv6 address fd00:700::1/64
!
6 changes: 6 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/h3/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ipv6 route ::/0 fd00:800::2
ip route 0.0.0.0/0 192.168.8.2
interface eth-r8
ip address 192.168.8.1/24
ipv6 address fd00:800::1/64
!
70 changes: 70 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/r1/bgp_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"routes": {
"192.168.1.0/24": [
{
"valid": true,
"bestpath": true,
"path": "",
"nexthops": [
{
"ip": "0.0.0.0",
"afi": "ipv4",
"used": true
}
]
}
],
"192.168.7.0/24": [
{
"valid": true,
"multipath": true,
"path": "65000 65700",
"nexthops": [
{
"ip": "172.16.1.3",
"afi": "ipv4",
"used": true
}
]
},
{
"valid": true,
"bestpath": true,
"path": "65000 65700",
"nexthops": [
{
"ip": "172.16.0.2",
"afi": "ipv4",
"used": true
}
]
}
],
"192.168.8.0/24": [
{
"valid": true,
"multipath": true,
"path": "65000 65800",
"nexthops": [
{
"ip": "172.16.1.3",
"afi": "ipv4",
"used": true
}
]
},
{
"valid": true,
"bestpath": true,
"path": "65000 65800",
"nexthops": [
{
"ip": "172.16.0.2",
"afi": "ipv4",
"used": true
}
]
}
]
}
}
90 changes: 90 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/r1/bgp_ipv6_step1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"routes": {
"fd00:100::/64": [
{
"valid": true,
"bestpath": true,
"path": "",
"nexthops": [
{
"ip": "::",
"afi": "ipv6",
"used": true
}
]
}
],
"fd00:700::/64": [
{
"valid": true,
"multipath": true,
"path": "65000 65700",
"nexthops": [
{
"ip": "fd00:0:2::3",
"afi": "ipv6",
"scope": "global"
},
{
"afi": "ipv6",
"scope": "link-local",
"used": true
}
]
},
{
"valid": true,
"bestpath": true,
"path": "65000 65700",
"nexthops": [
{
"ip": "fd00:0:1::2",
"afi": "ipv6",
"scope": "global"
},
{
"afi": "ipv6",
"scope": "link-local",
"used": true
}
]
}
],
"fd00:800::/64": [
{
"valid": true,
"multipath": true,
"path": "65000 65800",
"nexthops": [
{
"ip": "fd00:0:2::3",
"afi": "ipv6",
"scope": "global"
},
{
"afi": "ipv6",
"scope": "link-local",
"used": true
}
]
},
{
"valid": true,
"bestpath": true,
"path": "65000 65800",
"nexthops": [
{
"ip": "fd00:0:1::2",
"afi": "ipv6",
"scope": "global"
},
{
"afi": "ipv6",
"scope": "link-local",
"used": true
}
]
}
]
}
}
23 changes: 23 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
router bgp 65100
no bgp ebgp-requires-policy
neighbor 172.16.0.2 remote-as external
neighbor 172.16.1.3 remote-as external
! neighbor 172.16.0.2 capability extended-nexthop
!
address-family ipv4 unicast
redistribute connected route-map RMAP4
!
address-family ipv6 unicast
redistribute connected route-map RMAP6
neighbor 172.16.0.2 activate
neighbor 172.16.1.3 activate
!

ip prefix-list RANGE4 seq 10 permit 192.168.0.0/16 le 24
ipv6 prefix-list RANGE6 seq 10 permit fd00:100::0/64

route-map RMAP4 permit 10
match ip address prefix-list RANGE4
!
route-map RMAP6 permit 10
match ipv6 address prefix-list RANGE6
16 changes: 16 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
!
interface eth-h1
ip address 192.168.1.2/24
ipv6 address fd00:100::2/64
!
interface eth-r2
ip address 172.16.0.1/24
ipv6 address fd00:0:1::1/64
!
interface eth-r3
ip address 172.16.1.1/24
ipv6 address fd00:0:2::1/64
!
interface lo
ip address 192.0.2.1/32
ipv6 address 2001:db8::1/128
46 changes: 46 additions & 0 deletions tests/topotests/bgp_nexthop_mp_ipv4_6/r2/bgp_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"routes": {
"192.168.1.0/24": [
{
"valid": true,
"bestpath": true,
"path": "65100",
"nexthops": [
{
"ip": "172.16.0.1",
"afi": "ipv4",
"used": true
}
]
}
],
"192.168.7.0/24": [
{
"valid": true,
"bestpath": true,
"path": "65700",
"nexthops": [
{
"ip": "172.17.0.7",
"afi": "ipv4",
"used": true
}
]
}
],
"192.168.8.0/24": [
{
"valid": true,
"bestpath": true,
"path": "65800",
"nexthops": [
{
"ip": "172.17.0.8",
"afi": "ipv4",
"used": true
}
]
}
]
}
}
Loading
Loading