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

Bgp bfd and its ilk #17473

Merged
merged 3 commits into from
Nov 21, 2024
Merged
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
6 changes: 5 additions & 1 deletion bgpd/bgp_bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void bgp_peer_config_apply(struct peer *p, struct peer_group *pg)

void bgp_peer_bfd_update_source(struct peer *p)
{
struct bfd_session_params *session = p->bfd_config->session;
struct bfd_session_params *session;
const union sockunion *source = NULL;
bool changed = false;
int family;
Expand All @@ -162,6 +162,10 @@ void bgp_peer_bfd_update_source(struct peer *p)
struct interface *ifp;
union sockunion addr;

if (!p->bfd_config)
return;

session = p->bfd_config->session;
/* Nothing to do for groups. */
if (CHECK_FLAG(p->sflags, PEER_STATUS_GROUP))
return;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ static void bgp_connect_in_progress_update_connection(struct peer *peer)
static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
{
struct peer *peer = connection->peer;
int status;
enum connect_result status;

bgp_peer_conf_if_to_su_update(connection);

Expand Down
10 changes: 5 additions & 5 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ static int bgp_update_source(struct peer_connection *connection)
}

/* BGP try to connect to the peer. */
int bgp_connect(struct peer_connection *connection)
enum connect_result bgp_connect(struct peer_connection *connection)
{
struct peer *peer = connection->peer;

Expand All @@ -773,7 +773,7 @@ int bgp_connect(struct peer_connection *connection)
if (peer->conf_if && BGP_CONNECTION_SU_UNSPEC(connection)) {
if (bgp_debug_neighbor_events(peer))
zlog_debug("Peer address not learnt: Returning from connect");
return 0;
return connect_error;
}
frr_with_privs(&bgpd_privs) {
/* Make socket for the peer. */
Expand All @@ -787,7 +787,7 @@ int bgp_connect(struct peer_connection *connection)
zlog_debug("%s: Failure to create socket for connection to %s, error received: %s(%d)",
__func__, peer->host, safe_strerror(errno),
errno);
return -1;
return connect_error;
}

set_nonblocking(connection->fd);
Expand All @@ -808,7 +808,7 @@ int bgp_connect(struct peer_connection *connection)
__func__, peer->host, safe_strerror(errno),
errno);

return -1;
return connect_error;
}

sockopt_reuseaddr(connection->fd);
Expand Down Expand Up @@ -844,7 +844,7 @@ int bgp_connect(struct peer_connection *connection)
/* If the peer is passive mode, force to move to Active mode. */
if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE)) {
BGP_EVENT_ADD(connection, TCP_connection_open_failed);
return BGP_FSM_SUCCESS;
return connect_error;
}

if (peer->conf_if || peer->ifname)
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern int bgp_socket(struct bgp *bgp, unsigned short port,
const char *address);
extern void bgp_close_vrf_socket(struct bgp *bgp);
extern void bgp_close(void);
extern int bgp_connect(struct peer_connection *connection);
extern enum connect_result bgp_connect(struct peer_connection *connection);
extern int bgp_getsockname(struct peer *peer);
extern void bgp_updatesockname(struct peer *peer);

Expand Down
28 changes: 17 additions & 11 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_rd.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_bfd.h"

DEFINE_MTYPE_STATIC(BGPD, MARTIAN_STRING, "BGP Martian Addr Intf String");

Expand Down Expand Up @@ -409,17 +410,6 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)
bgp_dest_set_bgp_connected_ref_info(dest, bc);
}

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->conf_if &&
(strcmp(peer->conf_if, ifc->ifp->name) == 0) &&
!peer_established(peer->connection) &&
!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) {
connection = peer->connection;
if (peer_active(peer))
BGP_EVENT_ADD(connection, BGP_Stop);
BGP_EVENT_ADD(connection, BGP_Start);
}
}
} else if (addr->family == AF_INET6) {
apply_mask_ipv6((struct prefix_ipv6 *)&p);

Expand All @@ -443,6 +433,22 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)
bgp_dest_set_bgp_connected_ref_info(dest, bc);
}
}

/*
* Iterate over all the peers and attempt to set the bfd session
* data and if it's a bgp unnumbered get her flowing if necessary
*/
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
bgp_peer_bfd_update_source(peer);
if (peer->conf_if && (strcmp(peer->conf_if, ifc->ifp->name) == 0) &&
!peer_established(peer->connection) &&
!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) {
connection = peer->connection;
if (peer_active(peer))
BGP_EVENT_ADD(connection, BGP_Stop);
BGP_EVENT_ADD(connection, BGP_Start);
}
}
}

void bgp_connected_delete(struct bgp *bgp, struct connected *ifc)
Expand Down
2 changes: 2 additions & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
!
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.1
neighbor 192.0.2.3 remote-as 65500
neighbor 192.0.2.3 update-source lo
neighbor 192.0.2.7 remote-as 65500
neighbor 192.0.2.7 ttl-security hops 10
neighbor 192.0.2.7 disable-connected-check
neighbor 192.0.2.7 update-source lo
neighbor 192.0.2.7 timers connect 5
!
address-family ipv4 unicast
network 192.0.2.1/32
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r2/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.2
neighbor 192.0.2.1 remote-as 65500
neighbor 192.0.2.1 update-source lo
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r3/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.3
neighbor 192.0.2.1 remote-as 65500
neighbor 192.0.2.1 update-source lo
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r4/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
!
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.4
neighbor 192.0.2.1 remote-as 65500
neighbor 192.0.2.1 ttl-security hops 10
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r5/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.5
neighbor 192.0.2.3 remote-as 65500
neighbor 192.0.2.3 update-source lo
Expand Down
2 changes: 2 additions & 0 deletions tests/topotests/zebra_fec_nexthop_resolution/r7/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
!
router bgp 65500
timers bgp 3 9
bgp router-id 192.0.2.7
neighbor 192.0.2.1 remote-as 65500
neighbor 192.0.2.1 ttl-security hops 10
neighbor 192.0.2.1 disable-connected-check
neighbor 192.0.2.1 update-source lo
neighbor 192.0.2.1 timers connect 5
neighbor 192.0.2.5 remote-as 65500
neighbor 192.0.2.5 update-source lo
!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,17 @@ def test_zebra_fec_nexthop_resolution_bgp():
def _check_bgp_session():
r1 = tgen.gears["r1"]

tgen.gears["r3"].vtysh_cmd("config \n no mpls fec nexthop-resolution \n end")
tgen.gears["r3"].vtysh_cmd("config \n mpls fec nexthop-resolution \n end")
tgen.gears["r5"].vtysh_cmd("config \n no mpls fec nexthop-resolution \n end")
tgen.gears["r5"].vtysh_cmd("config \n mpls fec nexthop-resolution \n end")
output = json.loads(r1.vtysh_cmd("show bgp summary json"))

if output["ipv4Unicast"]["peers"]["192.0.2.7"]["state"] == "Established":
return None
return False

tgen.gears["r3"].vtysh_cmd("config \n no mpls fec nexthop-resolution \n end")
tgen.gears["r3"].vtysh_cmd("config \n mpls fec nexthop-resolution \n end")
tgen.gears["r5"].vtysh_cmd("config \n no mpls fec nexthop-resolution \n end")
tgen.gears["r5"].vtysh_cmd("config \n mpls fec nexthop-resolution \n end")

test_func1 = functools.partial(_check_bgp_session)
_, result1 = topotest.run_and_expect(test_func1, None, count=60, wait=0.5)
assert result1 is None, "Failed to verify the fec_nexthop_resolution: bgp session"
Expand Down
Loading