*: Use a struct prefix *p instead of a struct prefix in functions

When passing a prefix into a function let's pass by address instead
of pass by value.  Let's save our stack space.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2023-03-30 15:48:53 -04:00
parent cf35e49354
commit b589466918
6 changed files with 27 additions and 26 deletions

View file

@ -1077,7 +1077,7 @@ static int lsp_to_subnet_cb(const struct prefix *prefix, uint32_t metric,
prefix_copy(&p, prefix); prefix_copy(&p, prefix);
else { else {
/* Remove old subnet if any before prefix adjustment */ /* Remove old subnet if any before prefix adjustment */
subnet = ls_find_subnet(args->ted, *prefix); subnet = ls_find_subnet(args->ted, prefix);
if (subnet) { if (subnet) {
if (args->export) { if (args->export) {
subnet->status = DELETE; subnet->status = DELETE;
@ -1092,10 +1092,10 @@ static int lsp_to_subnet_cb(const struct prefix *prefix, uint32_t metric,
} }
/* Search existing Subnet in TED ... */ /* Search existing Subnet in TED ... */
subnet = ls_find_subnet(args->ted, p); subnet = ls_find_subnet(args->ted, &p);
/* ... and create a new Subnet if not found */ /* ... and create a new Subnet if not found */
if (!subnet) { if (!subnet) {
ls_pref = ls_prefix_new(vertex->node->adv, p); ls_pref = ls_prefix_new(vertex->node->adv, &p);
subnet = ls_subnet_add(args->ted, ls_pref); subnet = ls_subnet_add(args->ted, ls_pref);
/* Stop processing if we are unable to create a new subnet */ /* Stop processing if we are unable to create a new subnet */
if (!subnet) if (!subnet)
@ -1835,7 +1835,7 @@ static int show_ted(struct vty *vty, struct cmd_token *argv[], int argc,
return CMD_WARNING_CONFIG_FAILED; return CMD_WARNING_CONFIG_FAILED;
} }
/* Get the Subnet from the Link State Database */ /* Get the Subnet from the Link State Database */
subnet = ls_find_subnet(ted, pref); subnet = ls_find_subnet(ted, &pref);
if (!subnet) { if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n", vty_out(vty, "No subnet found for ID %pFX\n",
&pref); &pref);
@ -1848,7 +1848,7 @@ static int show_ted(struct vty *vty, struct cmd_token *argv[], int argc,
return CMD_WARNING_CONFIG_FAILED; return CMD_WARNING_CONFIG_FAILED;
} }
/* Get the Subnet from the Link State Database */ /* Get the Subnet from the Link State Database */
subnet = ls_find_subnet(ted, pref); subnet = ls_find_subnet(ted, &pref);
if (!subnet) { if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n", vty_out(vty, "No subnet found for ID %pFX\n",
&pref); &pref);

View file

@ -333,7 +333,7 @@ int ls_attributes_same(struct ls_attributes *l1, struct ls_attributes *l2)
/** /**
* Link State prefix management functions * Link State prefix management functions
*/ */
struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p) struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix *p)
{ {
struct ls_prefix *new; struct ls_prefix *new;
@ -342,7 +342,7 @@ struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p)
new = XCALLOC(MTYPE_LS_DB, sizeof(struct ls_prefix)); new = XCALLOC(MTYPE_LS_DB, sizeof(struct ls_prefix));
new->adv = adv; new->adv = adv;
new->pref = p; new->pref = *p;
return new; return new;
} }
@ -889,7 +889,7 @@ struct ls_subnet *ls_subnet_update(struct ls_ted *ted, struct ls_prefix *pref)
if (pref == NULL) if (pref == NULL)
return NULL; return NULL;
old = ls_find_subnet(ted, pref->pref); old = ls_find_subnet(ted, &pref->pref);
if (old) { if (old) {
if (!ls_prefix_same(old->ls_pref, pref)) { if (!ls_prefix_same(old->ls_pref, pref)) {
ls_prefix_del(old->ls_pref); ls_prefix_del(old->ls_pref);
@ -942,11 +942,12 @@ void ls_subnet_del_all(struct ls_ted *ted, struct ls_subnet *subnet)
ls_subnet_del(ted, subnet); ls_subnet_del(ted, subnet);
} }
struct ls_subnet *ls_find_subnet(struct ls_ted *ted, const struct prefix prefix) struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
const struct prefix *prefix)
{ {
struct ls_subnet subnet = {}; struct ls_subnet subnet = {};
subnet.key = prefix; subnet.key = *prefix;
return subnets_find(&ted->subnets, &subnet); return subnets_find(&ted->subnets, &subnet);
} }
@ -1846,7 +1847,7 @@ struct ls_subnet *ls_msg2subnet(struct ls_ted *ted, struct ls_message *msg,
subnet->status = UPDATE; subnet->status = UPDATE;
break; break;
case LS_MSG_EVENT_DELETE: case LS_MSG_EVENT_DELETE:
subnet = ls_find_subnet(ted, pref->pref); subnet = ls_find_subnet(ted, &pref->pref);
if (subnet) { if (subnet) {
if (delete) if (delete)
ls_subnet_del_all(ted, subnet); ls_subnet_del_all(ted, subnet);

View file

@ -314,7 +314,7 @@ extern int ls_attributes_same(struct ls_attributes *a1,
* *
* @return New Link State Prefix * @return New Link State Prefix
*/ */
extern struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p); extern struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix *p);
/** /**
* Remove Link State Prefix. Data Structure is freed. * Remove Link State Prefix. Data Structure is freed.
@ -709,7 +709,7 @@ extern void ls_subnet_del_all(struct ls_ted *ted, struct ls_subnet *subnet);
* @return Subnet if found, NULL otherwise * @return Subnet if found, NULL otherwise
*/ */
extern struct ls_subnet *ls_find_subnet(struct ls_ted *ted, extern struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
const struct prefix prefix); const struct prefix *prefix);
/** /**
* Create a new Link State Data Base. * Create a new Link State Data Base.

View file

@ -1781,7 +1781,7 @@ static void ospf_te_update_link(struct ls_ted *ted, struct ls_vertex *vertex,
* @param metric Standard metric attached to this Edge * @param metric Standard metric attached to this Edge
*/ */
static void ospf_te_update_subnet(struct ls_ted *ted, struct ls_vertex *vertex, static void ospf_te_update_subnet(struct ls_ted *ted, struct ls_vertex *vertex,
struct prefix p, uint8_t metric) struct prefix *p, uint8_t metric)
{ {
struct ls_subnet *subnet; struct ls_subnet *subnet;
struct ls_prefix *ls_pref; struct ls_prefix *ls_pref;
@ -1840,7 +1840,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr)
p.family = AF_INET; p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN; p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = addr; p.u.prefix4 = addr;
subnet = ls_find_subnet(ted, p); subnet = ls_find_subnet(ted, &p);
/* Remove subnet if found */ /* Remove subnet if found */
if (subnet) { if (subnet) {
@ -1933,7 +1933,7 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
p.prefixlen = IPV4_MAX_BITLEN; p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = rl->link[i].link_data; p.u.prefix4 = rl->link[i].link_data;
metric = ntohs(rl->link[i].metric); metric = ntohs(rl->link[i].metric);
ospf_te_update_subnet(ted, vertex, p, metric); ospf_te_update_subnet(ted, vertex, &p, metric);
break; break;
case LSA_LINK_TYPE_STUB: case LSA_LINK_TYPE_STUB:
/* Keep only /32 prefix */ /* Keep only /32 prefix */
@ -1942,7 +1942,7 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
p.family = AF_INET; p.family = AF_INET;
p.u.prefix4 = rl->link[i].link_id; p.u.prefix4 = rl->link[i].link_id;
metric = ntohs(rl->link[i].metric); metric = ntohs(rl->link[i].metric);
ospf_te_update_subnet(ted, vertex, p, metric); ospf_te_update_subnet(ted, vertex, &p, metric);
} }
break; break;
default: default:
@ -2074,12 +2074,12 @@ static void ospf_te_update_remote_asbr(struct ls_ted *ted, struct ls_edge *edge)
p.family = AF_INET; p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN; p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.local; p.u.prefix4 = attr->standard.local;
ospf_te_update_subnet(ted, edge->source, p, attr->standard.te_metric); ospf_te_update_subnet(ted, edge->source, &p, attr->standard.te_metric);
p.family = AF_INET; p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN; p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.remote_addr; p.u.prefix4 = attr->standard.remote_addr;
ospf_te_update_subnet(ted, vertex, p, attr->standard.te_metric); ospf_te_update_subnet(ted, vertex, &p, attr->standard.te_metric);
/* Connect Edge to the remote Vertex */ /* Connect Edge to the remote Vertex */
if (edge->destination == NULL) { if (edge->destination == NULL) {
@ -2625,14 +2625,14 @@ static int ospf_te_parse_ext_pref(struct ls_ted *ted, struct ospf_lsa *lsa)
pref.family = AF_INET; pref.family = AF_INET;
pref.prefixlen = ext->pref_length; pref.prefixlen = ext->pref_length;
pref.u.prefix4 = ext->address; pref.u.prefix4 = ext->address;
subnet = ls_find_subnet(ted, pref); subnet = ls_find_subnet(ted, &pref);
/* Create new Link State Prefix if not found */ /* Create new Link State Prefix if not found */
if (!subnet) { if (!subnet) {
lnid.origin = OSPFv2; lnid.origin = OSPFv2;
lnid.id.ip.addr = lsa->data->adv_router; lnid.id.ip.addr = lsa->data->adv_router;
lnid.id.ip.area_id = lsa->area->area_id; lnid.id.ip.area_id = lsa->area->area_id;
ls_pref = ls_prefix_new(lnid, pref); ls_pref = ls_prefix_new(lnid, &pref);
/* and add it to the TED */ /* and add it to the TED */
subnet = ls_subnet_add(ted, ls_pref); subnet = ls_subnet_add(ted, ls_pref);
} }
@ -2698,7 +2698,7 @@ static int ospf_te_delete_ext_pref(struct ls_ted *ted, struct ospf_lsa *lsa)
pref.family = AF_INET; pref.family = AF_INET;
pref.prefixlen = ext->pref_length; pref.prefixlen = ext->pref_length;
pref.u.prefix4 = ext->address; pref.u.prefix4 = ext->address;
subnet = ls_find_subnet(ted, pref); subnet = ls_find_subnet(ted, &pref);
/* Check if there is a corresponding subnet */ /* Check if there is a corresponding subnet */
if (!subnet) if (!subnet)
@ -4398,7 +4398,7 @@ DEFUN (show_ip_ospf_mpls_te_db,
return CMD_WARNING_CONFIG_FAILED; return CMD_WARNING_CONFIG_FAILED;
} }
/* Get the Subnet from the Link State Database */ /* Get the Subnet from the Link State Database */
subnet = ls_find_subnet(OspfMplsTE.ted, pref); subnet = ls_find_subnet(OspfMplsTE.ted, &pref);
if (!subnet) { if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n", vty_out(vty, "No subnet found for ID %pFX\n",
&pref); &pref);

View file

@ -268,7 +268,7 @@ uint32_t path_ted_query_type_c(struct prefix *prefix, uint8_t algo)
switch (prefix->family) { switch (prefix->family) {
case AF_INET: case AF_INET:
case AF_INET6: case AF_INET6:
subnet = ls_find_subnet(ted_state_g.ted, *prefix); subnet = ls_find_subnet(ted_state_g.ted, prefix);
if (subnet) { if (subnet) {
if ((CHECK_FLAG(subnet->ls_pref->flags, LS_PREF_SR)) if ((CHECK_FLAG(subnet->ls_pref->flags, LS_PREF_SR))
&& (subnet->ls_pref->sr.algo == algo)) && (subnet->ls_pref->sr.algo == algo))
@ -298,7 +298,7 @@ uint32_t path_ted_query_type_e(struct prefix *prefix, uint32_t iface_id)
switch (prefix->family) { switch (prefix->family) {
case AF_INET: case AF_INET:
case AF_INET6: case AF_INET6:
subnet = ls_find_subnet(ted_state_g.ted, *prefix); subnet = ls_find_subnet(ted_state_g.ted, prefix);
if (subnet && subnet->vertex if (subnet && subnet->vertex
&& subnet->vertex->outgoing_edges) { && subnet->vertex->outgoing_edges) {
/* from the vertex linked in subnet */ /* from the vertex linked in subnet */

View file

@ -1059,7 +1059,7 @@ DEFUN (show_sharp_ted,
return CMD_WARNING_CONFIG_FAILED; return CMD_WARNING_CONFIG_FAILED;
} }
/* Get the Subnet from the Link State Database */ /* Get the Subnet from the Link State Database */
subnet = ls_find_subnet(sg.ted, pref); subnet = ls_find_subnet(sg.ted, &pref);
if (!subnet) { if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n", vty_out(vty, "No subnet found for ID %pFX\n",
&pref); &pref);