Skip to content

Commit

Permalink
Merge pull request #14811 from donaldsharp/zebra_final_shutdown_finally
Browse files Browse the repository at this point in the history
Zebra final shutdown finally
  • Loading branch information
choppsv1 authored Nov 28, 2023
2 parents a526795 + 71f7ecb commit bb6fe6b
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 69 deletions.
1 change: 1 addition & 0 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ void bfdd_cli_init(void);
*/
void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv);
void bfdd_zclient_stop(void);
void bfdd_zclient_terminate(void);
void bfdd_zclient_unregister(vrf_id_t vrf_id);
void bfdd_zclient_register(vrf_id_t vrf_id);
void bfdd_sessions_enable_vrf(struct vrf *vrf);
Expand Down
2 changes: 2 additions & 0 deletions bfdd/bfdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ static void sigterm_handler(void)

bfd_vrf_terminate();

bfdd_zclient_terminate();

/* Terminate and free() FRR related memory. */
frr_fini();

Expand Down
5 changes: 5 additions & 0 deletions bfdd/ptm_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ void bfdd_zclient_stop(void)
pc_free_all();
}

void bfdd_zclient_terminate(void)
{
zclient_free(zclient);
}


/*
* Client handling.
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -6097,7 +6097,7 @@ void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn)
snprintfrr(buf, sizeof(buf), "%pI4:%hu", &bgp->router_id, vpn->rd_id);
(void)str2prefix_rd(buf, &vpn->prd);
if (vpn->prd_pretty)
XFREE(MTYPE_BGP, vpn->prd_pretty);
XFREE(MTYPE_BGP_NAME, vpn->prd_pretty);
UNSET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD);
}

Expand Down Expand Up @@ -6203,7 +6203,7 @@ void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn)
hash_release(bgp->vni_svi_hash, vpn);
hash_release(bgp->vnihash, vpn);
if (vpn->prd_pretty)
XFREE(MTYPE_BGP, vpn->prd_pretty);
XFREE(MTYPE_BGP_NAME, vpn->prd_pretty);
QOBJ_UNREG(vpn);
XFREE(MTYPE_BGP_EVPN, vpn);
}
Expand Down Expand Up @@ -7080,7 +7080,7 @@ void bgp_evpn_cleanup(struct bgp *bgp)
}

if (bgp->vrf_prd_pretty)
XFREE(MTYPE_BGP, bgp->vrf_prd_pretty);
XFREE(MTYPE_BGP_NAME, bgp->vrf_prd_pretty);
}

/*
Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,11 +2294,11 @@ static void evpn_configure_vrf_rd(struct bgp *bgp_vrf, struct prefix_rd *rd,
bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1);

if (bgp_vrf->vrf_prd_pretty)
XFREE(MTYPE_BGP, bgp_vrf->vrf_prd_pretty);
XFREE(MTYPE_BGP_NAME, bgp_vrf->vrf_prd_pretty);

/* update RD */
memcpy(&bgp_vrf->vrf_prd, rd, sizeof(struct prefix_rd));
bgp_vrf->vrf_prd_pretty = XSTRDUP(MTYPE_BGP, rd_pretty);
bgp_vrf->vrf_prd_pretty = XSTRDUP(MTYPE_BGP_NAME, rd_pretty);
SET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD);

/* We have a new RD for VRF.
Expand All @@ -2321,7 +2321,7 @@ static void evpn_unconfigure_vrf_rd(struct bgp *bgp_vrf)
bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf);
UNSET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD);
if (bgp_vrf->vrf_prd_pretty)
XFREE(MTYPE_BGP, bgp_vrf->vrf_prd_pretty);
XFREE(MTYPE_BGP_NAME, bgp_vrf->vrf_prd_pretty);
/* We have a new RD for VRF.
* Advertise all type-5 routes again with the new RD
*/
Expand All @@ -2343,7 +2343,7 @@ static void evpn_configure_rd(struct bgp *bgp, struct bgpevpn *vpn,

/* update RD */
memcpy(&vpn->prd, rd, sizeof(struct prefix_rd));
vpn->prd_pretty = XSTRDUP(MTYPE_BGP, rd_pretty);
vpn->prd_pretty = XSTRDUP(MTYPE_BGP_NAME, rd_pretty);
SET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD);

if (is_vni_live(vpn))
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ void bgp_fsm_change_status(struct peer_connection *connection,
/* Transition into Clearing or Deleted must /always/ clear all routes..
* (and must do so before actually changing into Deleted..
*/
if (status >= Clearing) {
if (status >= Clearing && peer != bgp->peer_self) {
bgp_clear_route_all(peer);

/* If no route was queued for the clear-node processing,
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

DEFINE_MGROUP(BGPD, "bgpd");
DEFINE_MTYPE(BGPD, BGP, "BGP instance");
DEFINE_MTYPE(BGPD, BGP_NAME, "BGP Name data");
DEFINE_MTYPE(BGPD, BGP_LISTENER, "BGP listen socket details");
DEFINE_MTYPE(BGPD, BGP_PEER, "BGP peer");
DEFINE_MTYPE(BGPD, BGP_PEER_CONNECTION, "BGP peer connection");
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

DECLARE_MGROUP(BGPD);
DECLARE_MTYPE(BGP);
DECLARE_MTYPE(BGP_NAME);
DECLARE_MTYPE(BGP_LISTENER);
DECLARE_MTYPE(BGP_PEER);
DECLARE_MTYPE(BGP_PEER_CONNECTION);
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_mplsvpn_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ static int bgp_init_snmp_stats(struct bgp *bgp)
{
if (is_bgp_vrf_mplsvpn(bgp)) {
if (bgp->snmp_stats == NULL) {
bgp->snmp_stats = XCALLOC(
MTYPE_BGP, sizeof(struct bgp_snmp_stats));
bgp->snmp_stats = XCALLOC(MTYPE_BGP_NAME,
sizeof(struct bgp_snmp_stats));
/* fix up added routes */
if (bgp->snmp_stats) {
bgp->snmp_stats->routes_added =
Expand All @@ -523,7 +523,7 @@ static int bgp_init_snmp_stats(struct bgp *bgp)
}
} else {
if (bgp->snmp_stats) {
XFREE(MTYPE_BGP, bgp->snmp_stats);
XFREE(MTYPE_BGP_NAME, bgp->snmp_stats);
bgp->snmp_stats = NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -6301,7 +6301,7 @@ static void bgp_static_free(struct bgp_static *bgp_static)
route_map_counter_decrement(bgp_static->rmap.map);

if (bgp_static->prd_pretty)
XFREE(MTYPE_BGP, bgp_static->prd_pretty);
XFREE(MTYPE_BGP_NAME, bgp_static->prd_pretty);
XFREE(MTYPE_ATTR, bgp_static->eth_s_id);
XFREE(MTYPE_BGP_STATIC, bgp_static);
}
Expand Down
11 changes: 6 additions & 5 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,9 @@ DEFUN_NOSH (router_bgp,
* - update asnotation if explicitly mentioned
*/
if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
XFREE(MTYPE_BGP, bgp->as_pretty);
bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
XFREE(MTYPE_BGP_NAME, bgp->as_pretty);
bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME,
argv[idx_asn]->arg);
if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
asnotation != ASNOTATION_UNDEFINED) {
SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
Expand Down Expand Up @@ -9392,13 +9393,13 @@ DEFPY (af_rd_vpn_export,
bgp_get_default(), bgp);

if (yes) {
bgp->vpn_policy[afi].tovpn_rd_pretty =
XSTRDUP(MTYPE_BGP, rd_str);
bgp->vpn_policy[afi].tovpn_rd_pretty = XSTRDUP(MTYPE_BGP_NAME,
rd_str);
bgp->vpn_policy[afi].tovpn_rd = prd;
SET_FLAG(bgp->vpn_policy[afi].flags,
BGP_VPN_POLICY_TOVPN_RD_SET);
} else {
XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
XFREE(MTYPE_BGP_NAME, bgp->vpn_policy[afi].tovpn_rd_pretty);
UNSET_FLAG(bgp->vpn_policy[afi].flags,
BGP_VPN_POLICY_TOVPN_RD_SET);
}
Expand Down
55 changes: 28 additions & 27 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ void bgp_confederation_id_set(struct bgp *bgp, as_t as, const char *as_str)
already_confed = bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION);
bgp->confed_id = as;
if (bgp->confed_id_pretty)
XFREE(MTYPE_BGP, bgp->confed_id_pretty);
bgp->confed_id_pretty = XSTRDUP(MTYPE_BGP, as_str);
XFREE(MTYPE_BGP_NAME, bgp->confed_id_pretty);
bgp->confed_id_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str);
bgp_config_set(bgp, BGP_CONFIG_CONFEDERATION);

/* If we were doing confederation already, this is just an external
Expand Down Expand Up @@ -630,7 +630,7 @@ void bgp_confederation_id_unset(struct bgp *bgp)
struct listnode *node, *nnode;

bgp->confed_id = 0;
XFREE(MTYPE_BGP, bgp->confed_id_pretty);
XFREE(MTYPE_BGP_NAME, bgp->confed_id_pretty);
bgp_config_unset(bgp, BGP_CONFIG_CONFEDERATION);

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
Expand Down Expand Up @@ -684,7 +684,7 @@ void bgp_confederation_peers_add(struct bgp *bgp, as_t as, const char *as_str)

bgp->confed_peers[bgp->confed_peers_cnt].as = as;
bgp->confed_peers[bgp->confed_peers_cnt].as_pretty =
XSTRDUP(MTYPE_BGP, as_str);
XSTRDUP(MTYPE_BGP_NAME, as_str);
bgp->confed_peers_cnt++;

if (bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION)) {
Expand Down Expand Up @@ -722,7 +722,7 @@ void bgp_confederation_peers_remove(struct bgp *bgp, as_t as)

for (i = 0; i < bgp->confed_peers_cnt; i++)
if (bgp->confed_peers[i].as == as) {
XFREE(MTYPE_BGP, bgp->confed_peers[i].as_pretty);
XFREE(MTYPE_BGP_NAME, bgp->confed_peers[i].as_pretty);
for (j = i + 1; j < bgp->confed_peers_cnt; j++) {
bgp->confed_peers[j - 1].as =
bgp->confed_peers[j].as;
Expand Down Expand Up @@ -1265,9 +1265,9 @@ static void peer_free(struct peer *peer)
bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE, 0);

if (peer->change_local_as_pretty)
XFREE(MTYPE_BGP, peer->change_local_as_pretty);
XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty);
if (peer->as_pretty)
XFREE(MTYPE_BGP, peer->as_pretty);
XFREE(MTYPE_BGP_NAME, peer->as_pretty);

bgp_peer_connection_free(&peer->connection);

Expand Down Expand Up @@ -1861,7 +1861,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if,
peer->as = remote_as;
/* internal and external values do not use as_pretty */
if (as_str && asn_str2asn(as_str, NULL))
peer->as_pretty = XSTRDUP(MTYPE_BGP, as_str);
peer->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str);
peer->as_type = as_type;
peer->local_id = bgp->router_id;
peer->v_holdtime = bgp->default_holdtime;
Expand Down Expand Up @@ -1986,10 +1986,10 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified,
peer->as = as;
if (as_specified == AS_SPECIFIED && as_str) {
if (peer->as_pretty)
XFREE(MTYPE_BGP, peer->as_pretty);
peer->as_pretty = XSTRDUP(MTYPE_BGP, as_str);
XFREE(MTYPE_BGP_NAME, peer->as_pretty);
peer->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str);
} else if (peer->as_type == AS_UNSPECIFIED && peer->as_pretty)
XFREE(MTYPE_BGP, peer->as_pretty);
XFREE(MTYPE_BGP_NAME, peer->as_pretty);
peer->as_type = as_specified;

if (bgp_config_check(peer->bgp, BGP_CONFIG_CONFEDERATION)
Expand Down Expand Up @@ -3289,9 +3289,9 @@ static struct bgp *bgp_create(as_t *as, const char *name,
bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp));
bgp->as = *as;
if (as_pretty)
bgp->as_pretty = XSTRDUP(MTYPE_BGP, as_pretty);
bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_pretty);
else
bgp->as_pretty = XSTRDUP(MTYPE_BGP, asn_asn2asplain(*as));
bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME, asn_asn2asplain(*as));

if (asnotation != ASNOTATION_UNDEFINED) {
bgp->asnotation = asnotation;
Expand Down Expand Up @@ -3420,14 +3420,14 @@ static struct bgp *bgp_create(as_t *as, const char *name,
bgp_mplsvpn_nh_label_bind_cache_init(&bgp->mplsvpn_nh_label_bind);

if (name)
bgp->name = XSTRDUP(MTYPE_BGP, name);
bgp->name = XSTRDUP(MTYPE_BGP_NAME, name);

event_add_timer(bm->master, bgp_startup_timer_expire, bgp,
bgp->restart_time, &bgp->t_startup);

/* printable name we can use in debug messages */
if (inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
bgp->name_pretty = XSTRDUP(MTYPE_BGP, "VRF default");
bgp->name_pretty = XSTRDUP(MTYPE_BGP_NAME, "VRF default");
} else {
const char *n;
int len;
Expand All @@ -3439,7 +3439,7 @@ static struct bgp *bgp_create(as_t *as, const char *name,

len = 4 + 1 + strlen(n) + 1; /* "view foo\0" */

bgp->name_pretty = XCALLOC(MTYPE_BGP, len);
bgp->name_pretty = XCALLOC(MTYPE_BGP_NAME, len);
snprintf(bgp->name_pretty, len, "%s %s",
(bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
? "VRF"
Expand Down Expand Up @@ -4042,7 +4042,8 @@ void bgp_free(struct bgp *bgp)
if (bgp->vpn_policy[afi].rtlist[dir])
ecommunity_free(&bgp->vpn_policy[afi].rtlist[dir]);
if (bgp->vpn_policy[afi].tovpn_rd_pretty)
XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
XFREE(MTYPE_BGP_NAME,
bgp->vpn_policy[afi].tovpn_rd_pretty);
if (bgp->vpn_policy[afi].tovpn_sid_locator != NULL)
srv6_locator_chunk_free(
&bgp->vpn_policy[afi].tovpn_sid_locator);
Expand All @@ -4059,10 +4060,10 @@ void bgp_free(struct bgp *bgp)
bgp_srv6_cleanup(bgp);
bgp_confederation_id_unset(bgp);

XFREE(MTYPE_BGP, bgp->as_pretty);
XFREE(MTYPE_BGP, bgp->name);
XFREE(MTYPE_BGP, bgp->name_pretty);
XFREE(MTYPE_BGP, bgp->snmp_stats);
XFREE(MTYPE_BGP_NAME, bgp->as_pretty);
XFREE(MTYPE_BGP_NAME, bgp->name);
XFREE(MTYPE_BGP_NAME, bgp->name_pretty);
XFREE(MTYPE_BGP_NAME, bgp->snmp_stats);

XFREE(MTYPE_BGP, bgp);
}
Expand Down Expand Up @@ -6464,8 +6465,8 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
peer->change_local_as = as;
if (as_str) {
if (peer->change_local_as_pretty)
XFREE(MTYPE_BGP, peer->change_local_as_pretty);
peer->change_local_as_pretty = XSTRDUP(MTYPE_BGP, as_str);
XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty);
peer->change_local_as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str);
}

(void)peer_sort(peer);
Expand Down Expand Up @@ -6502,8 +6503,8 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
replace_as);
member->change_local_as = as;
if (as_str)
member->change_local_as_pretty =
XSTRDUP(MTYPE_BGP, as_str);
member->change_local_as_pretty = XSTRDUP(MTYPE_BGP_NAME,
as_str);
}

return 0;
Expand All @@ -6529,7 +6530,7 @@ int peer_local_as_unset(struct peer *peer)
peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND);
peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS);
peer->change_local_as = 0;
XFREE(MTYPE_BGP, peer->change_local_as_pretty);
XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty);
}

/* Check if handling a regular peer. */
Expand Down Expand Up @@ -6560,7 +6561,7 @@ int peer_local_as_unset(struct peer *peer)
UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND);
UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS);
member->change_local_as = 0;
XFREE(MTYPE_BGP, member->change_local_as_pretty);
XFREE(MTYPE_BGP_NAME, member->change_local_as_pretty);

/* Send notification or stop peer depending on state. */
if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) {
Expand Down
2 changes: 2 additions & 0 deletions eigrpd/eigrp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static void sigint(void)
zlog_notice("Terminating on signal");
eigrp_terminate();

keychain_terminate();

exit(0);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/keychain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,20 @@ static const struct cmd_variable_handler keychain_var_handlers[] = {
{.completions = NULL}
};

void keychain_terminate(void)
{
struct keychain *keychain;

while (listcount(keychain_list)) {
keychain = listgetdata(listhead(keychain_list));

listnode_delete(keychain_list, keychain);
keychain_delete(keychain);
}

list_delete(&keychain_list);
}

void keychain_init(void)
{
keychain_list = list_new();
Expand Down
1 change: 1 addition & 0 deletions lib/keychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct key {
DECLARE_QOBJ_TYPE(key);

extern void keychain_init(void);
extern void keychain_terminate(void);
extern struct keychain *keychain_lookup(const char *);
extern struct key *key_lookup_for_accept(const struct keychain *, uint32_t);
extern struct key *key_match_for_accept(const struct keychain *, const char *);
Expand Down
3 changes: 3 additions & 0 deletions ospf6d/ospf6_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static void __attribute__((noreturn)) ospf6_exit(int status)
}

ospf6_master_delete();

frr_fini();

keychain_terminate();
exit(status);
}

Expand Down
Loading

0 comments on commit bb6fe6b

Please sign in to comment.