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 bgp core with a possible Intf delete (backport #17624) #17625

Closed
wants to merge 1 commit into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
144 changes: 144 additions & 0 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,12 @@ void bfd_set_echo(struct bfd_session *bs, bool echo)
if (bs->bdc == NULL)
ptm_bfd_echo_stop(bs);
}
<<<<<<< HEAD
=======

if (bs->vrf && bs->vrf->info)
bfd_vrf_toggle_echo(bs->vrf->info);
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
}

void bfd_set_shutdown(struct bfd_session *bs, bool shutdown)
Expand Down Expand Up @@ -1800,6 +1806,72 @@ void bfd_profiles_remove(void)
bfd_profile_free(bp);
}

<<<<<<< HEAD
=======
struct __bfd_session_echo {
/* VRF peers must match */
struct vrf *vrf;
/* Echo enabled or not */
bool enabled;
};

static int __bfd_session_has_echo(struct hash_bucket *hb, void *arg)
{
const struct bfd_session *session = hb->data;
struct __bfd_session_echo *has_echo = arg;

if (session->vrf != has_echo->vrf)
return HASHWALK_CONTINUE;
if (!CHECK_FLAG(session->flags, BFD_SESS_FLAG_ECHO))
return HASHWALK_CONTINUE;

has_echo->enabled = true;
return HASHWALK_ABORT;
}

void bfd_vrf_toggle_echo(struct bfd_vrf_global *bfd_vrf)
{
struct __bfd_session_echo has_echo = {
.enabled = false,
.vrf = bfd_vrf->vrf,
};

/* Check for peers using echo */
hash_walk(bfd_id_hash, __bfd_session_has_echo, &has_echo);

/*
* No peers using echo, close all echo sockets.
*/
if (!has_echo.enabled) {
if (bfd_vrf->bg_echo != -1) {
event_cancel(&bfd_vrf->bg_ev[4]);
close(bfd_vrf->bg_echo);
bfd_vrf->bg_echo = -1;
}

if (bfd_vrf->bg_echov6 != -1) {
event_cancel(&bfd_vrf->bg_ev[5]);
close(bfd_vrf->bg_echov6);
bfd_vrf->bg_echov6 = -1;
}
return;
}

/*
* At least one peer using echo, open echo sockets.
*/
if (bfd_vrf->bg_echo == -1)
bfd_vrf->bg_echo = bp_echo_socket(bfd_vrf->vrf);
if (bfd_vrf->bg_echov6 == -1)
bfd_vrf->bg_echov6 = bp_echov6_socket(bfd_vrf->vrf);

if (bfd_vrf->bg_ev[4] == NULL && bfd_vrf->bg_echo != -1)
event_add_read(master, bfd_recv_cb, bfd_vrf, bfd_vrf->bg_echo, &bfd_vrf->bg_ev[4]);
if (bfd_vrf->bg_ev[5] == NULL && bfd_vrf->bg_echov6 != -1)
event_add_read(master, bfd_recv_cb, bfd_vrf, bfd_vrf->bg_echov6, &bfd_vrf->bg_ev[5]);
}

>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
/*
* Profile related hash functions.
*/
Expand Down Expand Up @@ -1842,9 +1914,29 @@ static void bfd_profile_detach(struct bfd_profile *bp)
*/
static int bfd_vrf_new(struct vrf *vrf)
{
<<<<<<< HEAD
if (bglobal.debug_zebra)
zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);

=======
struct bfd_vrf_global *bvrf;

if (bglobal.debug_zebra)
zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);

bvrf = XCALLOC(MTYPE_BFDD_VRF, sizeof(struct bfd_vrf_global));
bvrf->vrf = vrf;
vrf->info = bvrf;

/* Invalidate all sockets */
bvrf->bg_shop = -1;
bvrf->bg_mhop = -1;
bvrf->bg_shop6 = -1;
bvrf->bg_mhop6 = -1;
bvrf->bg_echo = -1;
bvrf->bg_echov6 = -1;

>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
return 0;
}

Expand All @@ -1853,11 +1945,17 @@ static int bfd_vrf_delete(struct vrf *vrf)
if (bglobal.debug_zebra)
zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);

<<<<<<< HEAD
=======
XFREE(MTYPE_BFDD_VRF, vrf->info);

>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
return 0;
}

static int bfd_vrf_enable(struct vrf *vrf)
{
<<<<<<< HEAD
struct bfd_vrf_global *bvrf;

/* a different name */
Expand All @@ -1877,10 +1975,14 @@ static int bfd_vrf_enable(struct vrf *vrf)
}
} else
bvrf = vrf->info;
=======
struct bfd_vrf_global *bvrf = vrf->info;
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)

if (bglobal.debug_zebra)
zlog_debug("VRF enable add %s id %u", vrf->name, vrf->vrf_id);

<<<<<<< HEAD
if (!bvrf->bg_shop)
bvrf->bg_shop = bp_udp_shop(vrf);
if (!bvrf->bg_mhop)
Expand Down Expand Up @@ -1913,10 +2015,46 @@ static int bfd_vrf_enable(struct vrf *vrf)
event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6,
&bvrf->bg_ev[5]);

=======
/* Don't open sockets when using data plane */
if (bglobal.bg_use_dplane)
goto skip_sockets;

if (bvrf->bg_shop == -1)
bvrf->bg_shop = bp_udp_shop(vrf);
if (bvrf->bg_mhop == -1)
bvrf->bg_mhop = bp_udp_mhop(vrf);
if (bvrf->bg_shop6 == -1)
bvrf->bg_shop6 = bp_udp6_shop(vrf);
if (bvrf->bg_mhop6 == -1)
bvrf->bg_mhop6 = bp_udp6_mhop(vrf);

if (bvrf->bg_ev[0] == NULL && bvrf->bg_shop != -1)
event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop,
&bvrf->bg_ev[0]);
if (bvrf->bg_ev[1] == NULL && bvrf->bg_mhop != -1)
event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop,
&bvrf->bg_ev[1]);
if (bvrf->bg_ev[2] == NULL && bvrf->bg_shop6 != -1)
event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop6,
&bvrf->bg_ev[2]);
if (bvrf->bg_ev[3] == NULL && bvrf->bg_mhop6 != -1)
event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6,
&bvrf->bg_ev[3]);

/* Toggle echo if VRF was disabled. */
bfd_vrf_toggle_echo(bvrf);

skip_sockets:
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
if (vrf->vrf_id != VRF_DEFAULT) {
bfdd_zclient_register(vrf->vrf_id);
bfdd_sessions_enable_vrf(vrf);
}
<<<<<<< HEAD
=======

>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
return 0;
}

Expand Down Expand Up @@ -1948,6 +2086,7 @@ static int bfd_vrf_disable(struct vrf *vrf)
socket_close(&bvrf->bg_echo);
socket_close(&bvrf->bg_shop);
socket_close(&bvrf->bg_mhop);
<<<<<<< HEAD
if (bvrf->bg_shop6 != -1)
socket_close(&bvrf->bg_shop6);
if (bvrf->bg_mhop6 != -1)
Expand All @@ -1959,6 +2098,11 @@ static int bfd_vrf_disable(struct vrf *vrf)
/* free context */
XFREE(MTYPE_BFDD_VRF, bvrf);
vrf->info = NULL;
=======
socket_close(&bvrf->bg_shop6);
socket_close(&bvrf->bg_mhop6);
socket_close(&bvrf->bg_echov6);
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ void bfd_sessions_remove_manual(void);
void bfd_profiles_remove(void);
void bfd_rtt_init(struct bfd_session *bfd);

<<<<<<< HEAD
=======
extern void bfd_vrf_toggle_echo(struct bfd_vrf_global *bfd_vrf);

>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
/**
* Set the BFD session echo state.
*
Expand Down
48 changes: 48 additions & 0 deletions bfdd/bfdd_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ void bfd_cli_show_minimum_ttl(struct vty *vty, const struct lyd_node *dnode,

DEFPY_YANG(
bfd_peer_mult, bfd_peer_mult_cmd,
<<<<<<< HEAD
"[no] detect-multiplier ![(2-255)$multiplier]",
=======
"[no] detect-multiplier ![(1-255)$multiplier]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer detection multiplier\n"
"Configure peer detection multiplier value\n")
Expand All @@ -357,7 +361,11 @@ void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode,

DEFPY_YANG(
bfd_peer_rx, bfd_peer_rx_cmd,
<<<<<<< HEAD
"[no] receive-interval ![(10-60000)$interval]",
=======
"[no] receive-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer receive interval\n"
"Configure peer receive interval value in milliseconds\n")
Expand All @@ -381,7 +389,11 @@ void bfd_cli_show_rx(struct vty *vty, const struct lyd_node *dnode,

DEFPY_YANG(
bfd_peer_tx, bfd_peer_tx_cmd,
<<<<<<< HEAD
"[no] transmit-interval ![(10-60000)$interval]",
=======
"[no] transmit-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer transmit interval\n"
"Configure peer transmit interval value in milliseconds\n")
Expand Down Expand Up @@ -439,7 +451,11 @@ void bfd_cli_show_echo(struct vty *vty, const struct lyd_node *dnode,

DEFPY_YANG(
bfd_peer_echo_interval, bfd_peer_echo_interval_cmd,
<<<<<<< HEAD
"[no] echo-interval ![(10-60000)$interval]",
=======
"[no] echo-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo intervals\n"
"Configure peer echo rx/tx intervals value in milliseconds\n")
Expand All @@ -462,7 +478,11 @@ DEFPY_YANG(

DEFPY_YANG(
bfd_peer_echo_transmit_interval, bfd_peer_echo_transmit_interval_cmd,
<<<<<<< HEAD
"[no] echo transmit-interval ![(10-60000)$interval]",
=======
"[no] echo transmit-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo intervals\n"
"Configure desired transmit interval\n"
Expand Down Expand Up @@ -492,7 +512,11 @@ void bfd_cli_show_desired_echo_transmission_interval(

DEFPY_YANG(
bfd_peer_echo_receive_interval, bfd_peer_echo_receive_interval_cmd,
<<<<<<< HEAD
"[no] echo receive-interval ![<disabled$disabled|(10-60000)$interval>]",
=======
"[no] echo receive-interval ![<disabled$disabled|(10-4294967)$interval>]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo intervals\n"
"Configure required receive interval\n"
Expand Down Expand Up @@ -577,19 +601,31 @@ void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode,
}

ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd,
<<<<<<< HEAD
"[no] detect-multiplier ![(2-255)$multiplier]",
=======
"[no] detect-multiplier ![(1-255)$multiplier]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer detection multiplier\n"
"Configure peer detection multiplier value\n")

ALIAS_YANG(bfd_peer_tx, bfd_profile_tx_cmd,
<<<<<<< HEAD
"[no] transmit-interval ![(10-60000)$interval]",
=======
"[no] transmit-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer transmit interval\n"
"Configure peer transmit interval value in milliseconds\n")

ALIAS_YANG(bfd_peer_rx, bfd_profile_rx_cmd,
<<<<<<< HEAD
"[no] receive-interval ![(10-60000)$interval]",
=======
"[no] receive-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer receive interval\n"
"Configure peer receive interval value in milliseconds\n")
Expand Down Expand Up @@ -621,22 +657,34 @@ ALIAS_YANG(bfd_peer_echo, bfd_profile_echo_cmd,
"Configure echo mode\n")

ALIAS_YANG(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd,
<<<<<<< HEAD
"[no] echo-interval ![(10-60000)$interval]",
=======
"[no] echo-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo interval\n"
"Configure peer echo interval value in milliseconds\n")

ALIAS_YANG(
bfd_peer_echo_transmit_interval, bfd_profile_echo_transmit_interval_cmd,
<<<<<<< HEAD
"[no] echo transmit-interval ![(10-60000)$interval]",
=======
"[no] echo transmit-interval ![(10-4294967)$interval]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo intervals\n"
"Configure desired transmit interval\n"
"Configure interval value in milliseconds\n")

ALIAS_YANG(
bfd_peer_echo_receive_interval, bfd_profile_echo_receive_interval_cmd,
<<<<<<< HEAD
"[no] echo receive-interval ![<disabled$disabled|(10-60000)$interval>]",
=======
"[no] echo receive-interval ![<disabled$disabled|(10-4294967)$interval>]",
>>>>>>> 9b0b9282d (bgpd: Fix bgp core with a possible Intf delete)
NO_STR
"Configure peer echo intervals\n"
"Configure required receive interval\n"
Expand Down
Loading
Loading