From b0385873fafa4ce92f9e16469ab44f01eadd1b9f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 9 Aug 2022 19:56:08 -0400 Subject: [PATCH] zebra: Create a zebra_rib_route_entry_new function and use it Abstract the creation of the route_entry and use it. Signed-off-by: Donald Sharp --- zebra/redistribute.c | 13 ++++-------- zebra/rib.h | 6 ++++++ zebra/rt_netlink.c | 14 +++---------- zebra/zapi_msg.c | 27 ++++-------------------- zebra/zebra_rib.c | 50 +++++++++++++++++++++++++------------------- 5 files changed, 45 insertions(+), 65 deletions(-) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 1a28f8ceec..4a8fe938ed 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -685,15 +685,10 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, zebra_del_import_table_entry(zvrf, rn, same); } - newre = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); - newre->type = ZEBRA_ROUTE_TABLE; - newre->distance = zebra_import_table_distance[afi][re->table]; - newre->flags = re->flags; - newre->metric = re->metric; - newre->mtu = re->mtu; - newre->table = zvrf->table_id; - newre->uptime = monotime(NULL); - newre->instance = re->table; + newre = zebra_rib_route_entry_new( + 0, ZEBRA_ROUTE_TABLE, re->table, re->flags, re->nhe_id, + zvrf->table_id, re->metric, re->mtu, + zebra_import_table_distance[afi][re->table], re->tag); ng = nexthop_group_new(); copy_nexthops(&ng->nexthop, re->nhe->nhg.nexthop, NULL); diff --git a/zebra/rib.h b/zebra/rib.h index 2e8b05f9de..dec5b2b8d6 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -344,6 +344,12 @@ extern void _route_entry_dump(const char *func, union prefixconstptr pp, union prefixconstptr src_pp, const struct route_entry *re); +struct route_entry * +zebra_rib_route_entry_new(vrf_id_t vrf_id, int type, uint8_t instance, + uint32_t flags, uint32_t nhe_id, uint32_t table_id, + uint32_t metric, uint32_t mtu, uint8_t distance, + route_tag_t tag); + #define ZEBRA_RIB_LOOKUP_ERROR -1 #define ZEBRA_RIB_FOUND_EXACT 0 #define ZEBRA_RIB_FOUND_NOGATE 1 diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 0eab1fa850..fa11c7b8ca 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -956,17 +956,9 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, struct rtnexthop *rtnh = (struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]); - re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); - re->type = proto; - re->distance = distance; - re->flags = flags; - re->metric = metric; - re->mtu = mtu; - re->vrf_id = vrf_id; - re->table = table; - re->uptime = monotime(NULL); - re->tag = tag; - re->nhe_id = nhe_id; + re = zebra_rib_route_entry_new(vrf_id, proto, 0, flags, + nhe_id, table, metric, + mtu, distance, tag); if (!nhe_id) { uint8_t nhop_num; diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index b68dbb38b6..761ba789b8 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2052,17 +2052,10 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) (int)api.message, api.flags); /* Allocate new route. */ - re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); - re->type = api.type; - re->instance = api.instance; - re->flags = api.flags; - re->uptime = monotime(NULL); - re->vrf_id = vrf_id; - - if (api.tableid) - re->table = api.tableid; - else - re->table = zvrf->table_id; + re = zebra_rib_route_entry_new( + vrf_id, api.type, api.instance, api.flags, api.nhgid, + api.tableid ? api.tableid : zvrf->table_id, api.metric, api.mtu, + api.distance, api.tag); if (!CHECK_FLAG(api.message, ZAPI_MESSAGE_NHG) && (!CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) @@ -2087,9 +2080,6 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) &api.prefix); } - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NHG)) - re->nhe_id = api.nhgid; - if (!re->nhe_id && (!zapi_read_nexthops(client, &api.prefix, api.nexthops, api.flags, api.message, api.nexthop_num, @@ -2105,15 +2095,6 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) return; } - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) - re->distance = api.distance; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) - re->metric = api.metric; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_TAG)) - re->tag = api.tag; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_MTU)) - re->mtu = api.mtu; - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_OPAQUE)) { re->opaque = XMALLOC(MTYPE_RE_OPAQUE, diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 9596783e2b..bd7e8bbbd0 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -4037,6 +4037,30 @@ static int rib_meta_queue_early_route_add(struct meta_queue *mq, void *data) return 0; } +struct route_entry *zebra_rib_route_entry_new(vrf_id_t vrf_id, int type, + uint8_t instance, uint32_t flags, + uint32_t nhe_id, + uint32_t table_id, + uint32_t metric, uint32_t mtu, + uint8_t distance, route_tag_t tag) +{ + struct route_entry *re; + + re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); + re->type = type; + re->instance = instance; + re->distance = distance; + re->flags = flags; + re->metric = metric; + re->mtu = mtu; + re->table = table_id; + re->vrf_id = vrf_id; + re->uptime = monotime(NULL); + re->tag = tag; + re->nhe_id = nhe_id; + + return re; +} /* * Internal route-add implementation; there are a couple of different public * signatures. Callers in this path are responsible for the memory they @@ -4119,16 +4143,8 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, struct route_entry *re = NULL; struct nhg_hash_entry *nhe = NULL; - re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); - re->type = type; - re->instance = instance; - re->distance = distance; - re->flags = flags; - re->metric = metric; - re->table = table_id; - re->vrf_id = vrf_id; - re->uptime = monotime(NULL); - re->nhe_id = nhe_id; + re = zebra_rib_route_entry_new(vrf_id, type, instance, flags, nhe_id, + table_id, metric, 0, distance, 0); if (nh) { nhe = zebra_nhg_alloc(); @@ -4163,18 +4179,8 @@ int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, struct nexthop_group ng = {}; /* Allocate new route_entry structure. */ - re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); - re->type = type; - re->instance = instance; - re->distance = distance; - re->flags = flags; - re->metric = metric; - re->mtu = mtu; - re->table = table_id; - re->vrf_id = vrf_id; - re->uptime = monotime(NULL); - re->tag = tag; - re->nhe_id = nhe_id; + re = zebra_rib_route_entry_new(vrf_id, type, instance, flags, nhe_id, + table_id, metric, mtu, distance, tag); /* If the owner of the route supplies a shared nexthop-group id, * we'll use that. Otherwise, pass the nexthop along directly. -- 2.39.5