mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-11 20:48:27 +00:00
Merge pull request #11855 from cscarpitta/fix-srv6-memleaks
*: Fix several memory leaks in SRv6 implementation
This commit is contained in:
commit
c29b1ce67c
@ -306,12 +306,16 @@ static int bgp_srv6_locator_unset(struct bgp *bgp)
|
||||
return -1;
|
||||
|
||||
/* refresh chunks */
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
|
||||
listnode_delete(bgp->srv6_locator_chunks, chunk);
|
||||
srv6_locator_chunk_free(chunk);
|
||||
}
|
||||
|
||||
/* refresh functions */
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
|
||||
listnode_delete(bgp->srv6_functions, func);
|
||||
XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
|
||||
}
|
||||
|
||||
/* refresh tovpn_sid */
|
||||
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
|
||||
@ -334,6 +338,20 @@ static int bgp_srv6_locator_unset(struct bgp *bgp)
|
||||
/* update vpn bgp processes */
|
||||
vpn_leak_postchange_all();
|
||||
|
||||
/* refresh tovpn_sid_locator */
|
||||
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
|
||||
if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
|
||||
continue;
|
||||
|
||||
/* refresh vpnv4 tovpn_sid_locator */
|
||||
XFREE(MTYPE_BGP_SRV6_SID,
|
||||
bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
|
||||
|
||||
/* refresh vpnv6 tovpn_sid_locator */
|
||||
XFREE(MTYPE_BGP_SRV6_SID,
|
||||
bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
|
||||
}
|
||||
|
||||
/* clear locator name */
|
||||
memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
|
||||
|
||||
|
@ -3209,7 +3209,7 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS)
|
||||
struct srv6_locator_chunk *chunk;
|
||||
struct bgp_srv6_function *func;
|
||||
struct bgp *bgp_vrf;
|
||||
struct in6_addr *tovpn_sid;
|
||||
struct in6_addr *tovpn_sid, *tovpn_sid_locator;
|
||||
struct prefix_ipv6 tmp_prefi;
|
||||
|
||||
if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0)
|
||||
@ -3218,8 +3218,10 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS)
|
||||
// refresh chunks
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
|
||||
if (prefix_match((struct prefix *)&loc.prefix,
|
||||
(struct prefix *)&chunk->prefix))
|
||||
(struct prefix *)&chunk->prefix)) {
|
||||
listnode_delete(bgp->srv6_locator_chunks, chunk);
|
||||
srv6_locator_chunk_free(chunk);
|
||||
}
|
||||
|
||||
// refresh functions
|
||||
for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
|
||||
@ -3227,8 +3229,10 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS)
|
||||
tmp_prefi.prefixlen = 128;
|
||||
tmp_prefi.prefix = func->sid;
|
||||
if (prefix_match((struct prefix *)&loc.prefix,
|
||||
(struct prefix *)&tmp_prefi))
|
||||
(struct prefix *)&tmp_prefi)) {
|
||||
listnode_delete(bgp->srv6_functions, func);
|
||||
XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
|
||||
}
|
||||
}
|
||||
|
||||
// refresh tovpn_sid
|
||||
@ -3262,6 +3266,37 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS)
|
||||
}
|
||||
|
||||
vpn_leak_postchange_all();
|
||||
|
||||
/* refresh tovpn_sid_locator */
|
||||
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
|
||||
if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
|
||||
continue;
|
||||
|
||||
/* refresh vpnv4 tovpn_sid_locator */
|
||||
tovpn_sid_locator =
|
||||
bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator;
|
||||
if (tovpn_sid_locator) {
|
||||
tmp_prefi.family = AF_INET6;
|
||||
tmp_prefi.prefixlen = IPV6_MAX_BITLEN;
|
||||
tmp_prefi.prefix = *tovpn_sid_locator;
|
||||
if (prefix_match((struct prefix *)&loc.prefix,
|
||||
(struct prefix *)&tmp_prefi))
|
||||
XFREE(MTYPE_BGP_SRV6_SID, tovpn_sid_locator);
|
||||
}
|
||||
|
||||
/* refresh vpnv6 tovpn_sid_locator */
|
||||
tovpn_sid_locator =
|
||||
bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator;
|
||||
if (tovpn_sid_locator) {
|
||||
tmp_prefi.family = AF_INET6;
|
||||
tmp_prefi.prefixlen = IPV6_MAX_BITLEN;
|
||||
tmp_prefi.prefix = *tovpn_sid_locator;
|
||||
if (prefix_match((struct prefix *)&loc.prefix,
|
||||
(struct prefix *)&tmp_prefi))
|
||||
XFREE(MTYPE_BGP_SRV6_SID, tovpn_sid_locator);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient,
|
||||
{
|
||||
struct prefix_ipv6 p = {};
|
||||
struct zapi_route api = {};
|
||||
struct nexthop nh = {};
|
||||
struct zapi_nexthop *znh;
|
||||
|
||||
p.family = AF_INET6;
|
||||
p.prefixlen = IPV6_MAX_BITLEN;
|
||||
@ -465,12 +465,16 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient,
|
||||
SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
|
||||
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
|
||||
|
||||
nh.type = NEXTHOP_TYPE_IFINDEX;
|
||||
nh.ifindex = oif;
|
||||
SET_FLAG(nh.flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL);
|
||||
nexthop_add_srv6_seg6local(&nh, action, context);
|
||||
znh = &api.nexthops[0];
|
||||
|
||||
memset(znh, 0, sizeof(*znh));
|
||||
|
||||
znh->type = NEXTHOP_TYPE_IFINDEX;
|
||||
znh->ifindex = oif;
|
||||
SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL);
|
||||
znh->seg6local_action = action;
|
||||
memcpy(&znh->seg6local_ctx, context, sizeof(struct seg6local_context));
|
||||
|
||||
zapi_nexthop_from_nexthop(&api.nexthops[0], &nh);
|
||||
api.nexthop_num = 1;
|
||||
|
||||
return zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
|
||||
|
@ -234,6 +234,8 @@ DEFPY (install_routes,
|
||||
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
|
||||
nexthop_del_srv6_seg6local(&sg.r.nhop);
|
||||
nexthop_del_srv6_seg6(&sg.r.nhop);
|
||||
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
|
||||
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
|
||||
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
|
||||
@ -376,6 +378,8 @@ DEFPY (install_seg6_routes,
|
||||
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
|
||||
nexthop_del_srv6_seg6local(&sg.r.nhop);
|
||||
nexthop_del_srv6_seg6(&sg.r.nhop);
|
||||
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
|
||||
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
|
||||
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
|
||||
@ -467,6 +471,8 @@ DEFPY (install_seg6local_routes,
|
||||
sg.r.repeat = 0;
|
||||
|
||||
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
|
||||
nexthop_del_srv6_seg6local(&sg.r.nhop);
|
||||
nexthop_del_srv6_seg6(&sg.r.nhop);
|
||||
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
|
||||
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
|
||||
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
|
||||
@ -924,6 +930,11 @@ DEFPY (import_te,
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static void sharp_srv6_locator_chunk_free(struct prefix_ipv6 *chunk)
|
||||
{
|
||||
prefix_ipv6_free((struct prefix_ipv6 **)&chunk);
|
||||
}
|
||||
|
||||
DEFPY (sharp_srv6_manager_get_locator_chunk,
|
||||
sharp_srv6_manager_get_locator_chunk_cmd,
|
||||
"sharp srv6-manager get-locator-chunk NAME$locator_name",
|
||||
@ -947,6 +958,8 @@ DEFPY (sharp_srv6_manager_get_locator_chunk,
|
||||
loc = XCALLOC(MTYPE_SRV6_LOCATOR,
|
||||
sizeof(struct sharp_srv6_locator));
|
||||
loc->chunks = list_new();
|
||||
loc->chunks->del =
|
||||
(void (*)(void *))sharp_srv6_locator_chunk_free;
|
||||
snprintf(loc->name, SRV6_LOCNAME_SIZE, "%s", locator_name);
|
||||
listnode_add(sg.srv6_locators, loc);
|
||||
}
|
||||
@ -1096,6 +1109,7 @@ DEFPY (sharp_srv6_manager_release_locator_chunk,
|
||||
list_delete_all_node(loc->chunks);
|
||||
list_delete(&loc->chunks);
|
||||
listnode_delete(sg.srv6_locators, loc);
|
||||
XFREE(MTYPE_SRV6_LOCATOR, loc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,7 @@ void zebra_srv6_locator_delete(struct srv6_locator *locator)
|
||||
}
|
||||
|
||||
listnode_delete(srv6->locators, locator);
|
||||
srv6_locator_free(locator);
|
||||
}
|
||||
|
||||
struct srv6_locator *zebra_srv6_locator_lookup(const char *name)
|
||||
|
Loading…
Reference in New Issue
Block a user