diff options
author | Carmine Scarpitta <carmine.scarpitta@uniroma2.it> | 2022-10-29 17:04:35 +0200 |
---|---|---|
committer | Carmine Scarpitta <carmine.scarpitta@uniroma2.it> | 2022-10-29 17:04:35 +0200 |
commit | 6946731314fd04c499e576d0e133879f3e9c2edd (patch) | |
tree | 42d1cd47714e42cca90ef6fabb768d17ac3a0ec6 /bgpd | |
parent | Merge pull request #11673 from cscarpitta/srv6-per-vrf-sid (diff) | |
download | frr-6946731314fd04c499e576d0e133879f3e9c2edd.tar.xz frr-6946731314fd04c499e576d0e133879f3e9c2edd.zip |
lib, bgpd: Enhance `srv6_locator_chunk_free()` API
A programmer can use the `srv6_locator_chunk_free()` function to free
the memory allocated for a `struct srv6_locator_chunk`.
The programmer invokes `srv6_locator_chunk_free()` by passing a single
pointer to the `struct srv6_locator_chunk` to be freed.
`srv6_locator_chunk_free()` uses `XFREE()` to free the memory.
It is the responsibility of the programmer to set the
`struct srv6_locator_chunk` pointer to NULL after freeing memory with
`srv6_locator_chunk_free()`.
This commit modifies the `srv6_locator_chunk_free()` function to take a
double pointer instead of a single pointer. In this way, setting the
`struct srv6_locator_chunk` pointer to NULL is no longer the
programmer's responsibility but is the responsibility of
`srv6_locator_chunk_free()`. This prevents programmers from making
mistakes such as forgetting to set the pointer to NULL after invoking
`srv6_locator_chunk_free()`.
Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_mplsvpn.c | 8 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 10 | ||||
-rw-r--r-- | bgpd/bgp_zebra.c | 17 |
3 files changed, 21 insertions, 14 deletions
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index a68167977..ad4221d13 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -779,7 +779,7 @@ void ensure_vrf_tovpn_sid_per_af(struct bgp *bgp_vpn, struct bgp *bgp_vrf, zlog_debug( "%s: not allocated new sid for vrf %s: afi %s", __func__, bgp_vrf->name_pretty, afi2str(afi)); - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free(&tovpn_sid_locator); XFREE(MTYPE_BGP_SRV6_SID, tovpn_sid); return; } @@ -844,7 +844,7 @@ void ensure_vrf_tovpn_sid_per_vrf(struct bgp *bgp_vpn, struct bgp *bgp_vrf) if (debug) zlog_debug("%s: not allocated new sid for vrf %s", __func__, bgp_vrf->name_pretty); - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free(&tovpn_sid_locator); XFREE(MTYPE_BGP_SRV6_SID, tovpn_sid); return; } @@ -891,7 +891,7 @@ void delete_vrf_tovpn_sid_per_af(struct bgp *bgp_vpn, struct bgp *bgp_vrf, if (tovpn_sid_index != 0 || tovpn_sid_auto) return; - srv6_locator_chunk_free(bgp_vrf->vpn_policy[afi].tovpn_sid_locator); + srv6_locator_chunk_free(&bgp_vrf->vpn_policy[afi].tovpn_sid_locator); bgp_vrf->vpn_policy[afi].tovpn_sid_locator = NULL; if (bgp_vrf->vpn_policy[afi].tovpn_sid) { @@ -919,7 +919,7 @@ void delete_vrf_tovpn_sid_per_vrf(struct bgp *bgp_vpn, struct bgp *bgp_vrf) if (tovpn_sid_index != 0 || tovpn_sid_auto) return; - srv6_locator_chunk_free(bgp_vrf->tovpn_sid_locator); + srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator); bgp_vrf->tovpn_sid_locator = NULL; if (bgp_vrf->tovpn_sid) { diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f380460a9..09f4fada8 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -310,7 +310,7 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) /* refresh chunks */ for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) { listnode_delete(bgp->srv6_locator_chunks, chunk); - srv6_locator_chunk_free(chunk); + srv6_locator_chunk_free(&chunk); } /* refresh functions */ @@ -348,7 +348,8 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) tovpn_sid_locator = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator; if (tovpn_sid_locator) { - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free( + &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator); bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator = NULL; } @@ -356,12 +357,13 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) tovpn_sid_locator = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator; if (tovpn_sid_locator) { - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free(&bgp_vrf->vpn_policy[AFI_IP6] + .tovpn_sid_locator); bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator = NULL; } /* refresh per-vrf tovpn_sid_locator */ - srv6_locator_chunk_free(bgp_vrf->tovpn_sid_locator); + srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator); } /* clear locator name */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index f7dda74cc..f6c086324 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -3219,13 +3219,13 @@ static int bgp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) if (strcmp(bgp->srv6_locator_name, chunk->locator_name) != 0) { zlog_err("%s: Locator name unmatch %s:%s", __func__, bgp->srv6_locator_name, chunk->locator_name); - srv6_locator_chunk_free(chunk); + srv6_locator_chunk_free(&chunk); return 0; } for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, c)) { if (!prefix_cmp(&c->prefix, &chunk->prefix)) { - srv6_locator_chunk_free(chunk); + srv6_locator_chunk_free(&chunk); return 0; } } @@ -3272,7 +3272,7 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) if (prefix_match((struct prefix *)&loc.prefix, (struct prefix *)&chunk->prefix)) { listnode_delete(bgp->srv6_locator_chunks, chunk); - srv6_locator_chunk_free(chunk); + srv6_locator_chunk_free(&chunk); } // refresh functions @@ -3344,7 +3344,9 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) tmp_prefi.prefix = tovpn_sid_locator->prefix.prefix; if (prefix_match((struct prefix *)&loc.prefix, (struct prefix *)&tmp_prefi)) { - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free( + &bgp_vrf->vpn_policy[AFI_IP] + .tovpn_sid_locator); bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator = NULL; } @@ -3359,7 +3361,9 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) tmp_prefi.prefix = tovpn_sid_locator->prefix.prefix; if (prefix_match((struct prefix *)&loc.prefix, (struct prefix *)&tmp_prefi)) { - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free( + &bgp_vrf->vpn_policy[AFI_IP6] + .tovpn_sid_locator); bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator = NULL; } @@ -3373,7 +3377,8 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) tmp_prefi.prefix = tovpn_sid_locator->prefix.prefix; if (prefix_match((struct prefix *)&loc.prefix, (struct prefix *)&tmp_prefi)) - srv6_locator_chunk_free(tovpn_sid_locator); + srv6_locator_chunk_free( + &bgp_vrf->tovpn_sid_locator); } } |