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

lib: Free Temporary Memory for AF_FLOWSPEC Prefix #14372

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bgpd/bgp_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ static void bgp_node_destroy(route_table_delegate_t *delegate,

if (family2afi(node->p.family) == AFI_LINKSTATE)
prefix_linkstate_ptr_free(&node->p);
else if (node->p.family == AF_FLOWSPEC)
prefix_flowspec_ptr_free(&node->p);

XFREE(MTYPE_ROUTE_NODE, node);
}
Expand Down
16 changes: 12 additions & 4 deletions lib/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,17 @@ void prefix_linkstate_ptr_free(struct prefix *p)
p->u.prefix_linkstate.ptr = (uintptr_t)NULL;
}

void prefix_flowspec_ptr_free(struct prefix *p)
{
void *temp;

if (!p || p->family != AF_FLOWSPEC || !p->u.prefix_flowspec.ptr)
return;

temp = (void *)p->u.prefix_flowspec.ptr;
XFREE(MTYPE_PREFIX_FLOWSPEC, temp);
p->u.prefix_flowspec.ptr = (uintptr_t)NULL;
}

struct prefix *prefix_new(void)
{
Expand Down Expand Up @@ -1455,7 +1466,6 @@ unsigned prefix_hash_key(const void *pp)
{
struct prefix copy;
uint32_t len;
void *temp;

/* make sure *all* unused bits are zero, particularly including
* alignment /
Expand All @@ -1467,9 +1477,7 @@ unsigned prefix_hash_key(const void *pp)
len = jhash((void *)copy.u.prefix_flowspec.ptr,
copy.u.prefix_flowspec.prefixlen,
0x55aa5a5a);
temp = (void *)copy.u.prefix_flowspec.ptr;
XFREE(MTYPE_PREFIX_FLOWSPEC, temp);
copy.u.prefix_flowspec.ptr = (uintptr_t)NULL;
prefix_flowspec_ptr_free(&copy);
return len;
} else if (((struct prefix *)pp)->family == AF_LINKSTATE) {
len = jhash((void *)copy.u.prefix_linkstate.ptr, copy.prefixlen,
Expand Down
1 change: 1 addition & 0 deletions lib/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ static inline afi_t prefix_afi(union prefixconstptr pu)
extern unsigned int prefix_bit(const uint8_t *prefix, const uint16_t bit_index);

extern void prefix_linkstate_ptr_free(struct prefix *p);
extern void prefix_flowspec_ptr_free(struct prefix *p);

extern struct prefix *prefix_new(void);
extern void prefix_free(struct prefix **p);
Expand Down
7 changes: 7 additions & 0 deletions lib/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ struct route_node *route_node_get(struct route_table *table,
if (node && node->info) {
if (family2afi(p->family) == AFI_LINKSTATE)
prefix_linkstate_ptr_free(p);
else if (p->family == AF_FLOWSPEC)
prefix_flowspec_ptr_free(p);

return route_lock_node(node);
}
Expand All @@ -295,6 +297,9 @@ struct route_node *route_node_get(struct route_table *table,
if (node->p.prefixlen == prefixlen) {
if (family2afi(p->family) == AFI_LINKSTATE)
prefix_linkstate_ptr_free(p);
else if (p->family == AF_FLOWSPEC)
prefix_flowspec_ptr_free(p);

return route_lock_node(node);
}

Expand Down Expand Up @@ -333,6 +338,8 @@ struct route_node *route_node_get(struct route_table *table,

if (family2afi(p->family) == AFI_LINKSTATE)
prefix_linkstate_ptr_free(p);
else if (p->family == AF_FLOWSPEC)
prefix_flowspec_ptr_free(p);

return new;
}
Expand Down