From 04fd828f3fec7b76be6de73eafc5af081c3b4714 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 8 Jul 2022 20:53:43 -0400 Subject: [PATCH] bgpd: rfapi code does not need to assert on memory allocations cleanup memory allocations asserting that it didn't fail as well as clean up some thread shenanigans. Signed-off-by: Donald Sharp --- bgpd/rfapi/rfapi.c | 5 +---- bgpd/rfapi/rfapi_ap.c | 1 - bgpd/rfapi/rfapi_encap_tlv.c | 1 - bgpd/rfapi/rfapi_import.c | 8 -------- bgpd/rfapi/rfapi_rib.c | 6 +----- bgpd/rfapi/vnc_export_bgp.c | 1 - bgpd/rfapi/vnc_export_table.c | 1 - 7 files changed, 2 insertions(+), 21 deletions(-) diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 35a76e7836..f0e68d7f3f 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -721,7 +721,6 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ encaptlv = XCALLOC(MTYPE_ENCAP_TLV, sizeof(struct bgp_attr_encap_subtlv) + 4); - assert(encaptlv); encaptlv->type = BGP_VNC_SUBTLV_TYPE_LIFETIME; /* prefix lifetime */ encaptlv->length = 4; @@ -766,7 +765,6 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ MTYPE_ENCAP_TLV, sizeof(struct bgp_attr_encap_subtlv) + 2 + hop->length); - assert(encaptlv); encaptlv->type = BGP_VNC_SUBTLV_TYPE_RFPOPTION; /* RFP option @@ -1041,7 +1039,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ SET_FLAG(new->flags, BGP_PATH_VALID); /* save backref to rfapi handle */ - assert(bgp_path_info_extra_get(new)); + bgp_path_info_extra_get(new); new->extra->vnc.export.rfapi_handle = (void *)rfd; encode_label(label_val, &new->extra->label[0]); @@ -1963,7 +1961,6 @@ int rfapi_open(void *rfp_start_val, struct rfapi_ip_addr *vn, rfd = XCALLOC(MTYPE_RFAPI_DESC, sizeof(struct rfapi_descriptor)); } - assert(rfd); rfd->bgp = bgp; if (default_options) { diff --git a/bgpd/rfapi/rfapi_ap.c b/bgpd/rfapi/rfapi_ap.c index abb18aeb2c..fcc6168cfa 100644 --- a/bgpd/rfapi/rfapi_ap.c +++ b/bgpd/rfapi/rfapi_ap.c @@ -459,7 +459,6 @@ int rfapiApAdd(struct bgp *bgp, struct rfapi_descriptor *rfd, if (rc) { /* Not found */ adb = XCALLOC(MTYPE_RFAPI_ADB, sizeof(struct rfapi_adb)); - assert(adb); adb->lifetime = lifetime; adb->u.key = rk; diff --git a/bgpd/rfapi/rfapi_encap_tlv.c b/bgpd/rfapi/rfapi_encap_tlv.c index a7bc909c58..d4e875df2a 100644 --- a/bgpd/rfapi/rfapi_encap_tlv.c +++ b/bgpd/rfapi/rfapi_encap_tlv.c @@ -170,7 +170,6 @@ struct rfapi_un_option *rfapi_encap_tlv_to_un_option(struct attr *attr) stlv = attr->encap_subtlvs; uo = XCALLOC(MTYPE_RFAPI_UN_OPTION, sizeof(struct rfapi_un_option)); - assert(uo); uo->type = RFAPI_UN_OPTION_TYPE_TUNNELTYPE; uo->v.tunnel.type = attr->encap_tunneltype; tto = &uo->v.tunnel; diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 1d58c03313..91b68b13d8 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -1273,7 +1273,6 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, #endif new = XCALLOC(MTYPE_RFAPI_NEXTHOP, sizeof(struct rfapi_next_hop_entry)); - assert(new); new->prefix = *rprefix; @@ -1286,7 +1285,6 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, vo = XCALLOC(MTYPE_RFAPI_VN_OPTION, sizeof(struct rfapi_vn_option)); - assert(vo); vo->type = RFAPI_VN_OPTION_TYPE_L2ADDR; @@ -2308,7 +2306,6 @@ rfapiMonitorEncapAdd(struct rfapi_import_table *import_table, m = XCALLOC(MTYPE_RFAPI_MONITOR_ENCAP, sizeof(struct rfapi_monitor_encap)); - assert(m); m->node = vpn_rn; m->bpi = vpn_bpi; @@ -2791,7 +2788,6 @@ rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table, * service routine, which is supposed to free the wcb. */ wcb = XCALLOC(MTYPE_RFAPI_WITHDRAW, sizeof(struct rfapi_withdraw)); - assert(wcb); wcb->node = rn; wcb->info = bpi; wcb->import_table = import_table; @@ -3224,7 +3220,6 @@ static void rfapiBgpInfoFilteredImportEncap( struct agg_table *referenced_vpn_table; referenced_vpn_table = agg_table_init(); - assert(referenced_vpn_table); /* * iterate over the set of monitors at this ENCAP node. @@ -3282,7 +3277,6 @@ static void rfapiBgpInfoFilteredImportEncap( mnext = XCALLOC( MTYPE_RFAPI_MONITOR_ENCAP, sizeof(struct rfapi_monitor_encap)); - assert(mnext); mnext->node = m->node; mnext->next = referenced_vpn_prefix->info; referenced_vpn_prefix->info = mnext; @@ -4332,7 +4326,6 @@ rfapiImportTableRefAdd(struct bgp *bgp, struct ecommunity *rt_import_list, if (!it) { it = XCALLOC(MTYPE_RFAPI_IMPORTTABLE, sizeof(struct rfapi_import_table)); - assert(it); it->next = h->imports; h->imports = it; @@ -4551,7 +4544,6 @@ static void rfapiDeleteRemotePrefixesIt( MTYPE_RFAPI_NVE_ADDR, sizeof(struct rfapi_nve_addr)); - assert(nap); *nap = na; nap->info = is_active ? pAHcount diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 44eebe961c..c4fc96f5ae 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -357,10 +357,9 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd, vnc_zlog_debug_verbose("%s: rfd %p pfx %pRN life %u", __func__, rfd, rn, ri->lifetime); - ri->timer = NULL; + thread_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime, &ri->timer); - assert(ri->timer); } extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */ @@ -1179,7 +1178,6 @@ callback: new = XCALLOC(MTYPE_RFAPI_NEXTHOP, sizeof(struct rfapi_next_hop_entry)); - assert(new); if (ri->rk.aux_prefix.family) { rfapiQprefix2Rprefix(&ri->rk.aux_prefix, @@ -1269,7 +1267,6 @@ callback: new = XCALLOC( MTYPE_RFAPI_NEXTHOP, sizeof(struct rfapi_next_hop_entry)); - assert(new); if (ri->rk.aux_prefix.family) { rfapiQprefix2Rprefix(&ri->rk.aux_prefix, @@ -1718,7 +1715,6 @@ void rfapiRibUpdatePendingNode( urq = XCALLOC(MTYPE_RFAPI_UPDATED_RESPONSE_QUEUE, sizeof(struct rfapi_updated_responses_queue)); - assert(urq); if (!rfd->updated_responses_queue) updated_responses_queue_init(rfd); diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 7cfa2ed67d..2152a55ca3 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -564,7 +564,6 @@ static struct ecommunity *vnc_route_origin_ecom_single(struct in_addr *origin) roec.val[7] = 0; new = ecommunity_new(); - assert(new); ecommunity_add_val(new, &roec, false, false); if (!new->size) { diff --git a/bgpd/rfapi/vnc_export_table.c b/bgpd/rfapi/vnc_export_table.c index 255f868bdf..743576d265 100644 --- a/bgpd/rfapi/vnc_export_table.c +++ b/bgpd/rfapi/vnc_export_table.c @@ -119,7 +119,6 @@ struct vnc_export_info *vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype, agg_unlock_node(etn); } else { eti = XCALLOC(MTYPE_RFAPI_ETI, sizeof(struct vnc_export_info)); - assert(eti); eti->node = etn; eti->peer = peer; peer_lock(peer); -- 2.39.5