Merge pull request #7526 from donaldsharp/i_am_a_robot_wumpalump

Cleanup on Aisle 5: Memory leaks, Uninited data and code snarfles
This commit is contained in:
Donatas Abraitis 2020-11-16 17:32:30 +02:00 committed by GitHub
commit e5c317bcfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 133 additions and 107 deletions

View File

@ -187,6 +187,7 @@ babel_interface_address_delete (ZAPI_CALLBACK_ARGS)
send_request(ifc->ifp, NULL, 0); send_request(ifc->ifp, NULL, 0);
send_update(ifc->ifp, 0, NULL, 0); send_update(ifc->ifp, 0, NULL, 0);
connected_free(&ifc);
return 0; return 0;
} }

View File

@ -794,7 +794,10 @@ static int bfdd_interface_address_update(ZAPI_CALLBACK_ARGS)
: "delete", : "delete",
ifc->address); ifc->address);
bfdd_sessions_enable_address(ifc); if (cmd == ZEBRA_INTERFACE_ADDRESS_ADD)
bfdd_sessions_enable_address(ifc);
else
connected_free(&ifc);
return 0; return 0;
} }

View File

@ -80,14 +80,12 @@ void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d)
afi_t afi; afi_t afi;
int i; int i;
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { for (i = 0; i < BGP_ADDPATH_MAX; i++) {
for (i = 0; i < BGP_ADDPATH_MAX; i++) { d->id_allocators[afi][safi][i] = NULL;
d->id_allocators[afi][safi][i] = NULL; d->peercount[afi][safi][i] = 0;
d->peercount[afi][safi][i] = 0;
}
d->total_peercount[afi][safi] = 0;
} }
d->total_peercount[afi][safi] = 0;
} }
} }

View File

@ -279,18 +279,17 @@ static void bgp_update_explicit_eors(struct peer *peer)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("Peer %s: Checking explicit EORs", peer->host); zlog_debug("Peer %s: Checking explicit EORs", peer->host);
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { if (peer->afc_nego[afi][safi]
if (peer->afc_nego[afi][safi] && !CHECK_FLAG(peer->af_sflags[afi][safi],
&& !CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED)) {
PEER_STATUS_EOR_RECEIVED)) { if (bgp_debug_neighbor_events(peer))
if (bgp_debug_neighbor_events(peer)) zlog_debug(
zlog_debug( " afi %d safi %d didn't receive EOR",
" afi %d safi %d didn't receive EOR", afi, safi);
afi, safi); return;
return;
}
} }
}
peer->update_delay_over = 1; peer->update_delay_over = 1;
peer->bgp->explicit_eors++; peer->bgp->explicit_eors++;

View File

@ -241,6 +241,9 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra)
if (e->bgp_orig) if (e->bgp_orig)
bgp_unlock(e->bgp_orig); bgp_unlock(e->bgp_orig);
if (e->aggr_suppressors)
list_delete(&e->aggr_suppressors);
if ((*extra)->bgp_fs_iprule) if ((*extra)->bgp_fs_iprule)
list_delete(&((*extra)->bgp_fs_iprule)); list_delete(&((*extra)->bgp_fs_iprule));
if ((*extra)->bgp_fs_pbr) if ((*extra)->bgp_fs_pbr)
@ -11214,6 +11217,7 @@ static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc,
char *str; char *str;
int first = 0; int first = 0;
uint8_t show_flags = 0; uint8_t show_flags = 0;
int ret;
if (uj) if (uj)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON); SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
@ -11241,10 +11245,13 @@ static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc,
return CMD_WARNING; return CMD_WARNING;
} }
return bgp_show(vty, bgp, afi, safi, ret = bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_lcommunity_exact (exact ? bgp_show_type_lcommunity_exact
: bgp_show_type_lcommunity), : bgp_show_type_lcommunity),
lcom, show_flags); lcom, show_flags);
lcommunity_free(&lcom);
return ret;
} }
static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp, static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp,

View File

@ -531,9 +531,9 @@ static int zebra_read_route(ZAPI_CALLBACK_ARGS)
api.instance, &api.prefix, buf, nhtype, ifindex, api.instance, &api.prefix, buf, nhtype, ifindex,
api.metric, api.tag); api.metric, api.tag);
} else { } else {
zlog_debug("Rx route DEL VRF %u %s[%d] %s", vrf_id, zlog_debug("Rx route DEL VRF %u %s[%d] %pFX", vrf_id,
zebra_route_string(api.type), api.instance, zebra_route_string(api.type), api.instance,
buf); &api.prefix);
} }
} }
@ -2840,6 +2840,7 @@ static int bgp_zebra_process_local_macip(ZAPI_CALLBACK_ARGS)
stream_get(&esi, s, sizeof(esi_t)); stream_get(&esi, s, sizeof(esi_t));
} else { } else {
state = stream_getl(s); state = stream_getl(s);
memset(&esi, 0, sizeof(esi_t));
} }
bgp = bgp_lookup_by_vrf_id(vrf_id); bgp = bgp_lookup_by_vrf_id(vrf_id);

View File

@ -1094,6 +1094,15 @@ static void peer_free(struct peer *peer)
bgp_delete_connected_nexthop(family2afi(peer->su.sa.sa_family), bgp_delete_connected_nexthop(family2afi(peer->su.sa.sa_family),
peer); peer);
FOREACH_AFI_SAFI (afi, safi) {
if (peer->filter[afi][safi].advmap.aname)
XFREE(MTYPE_BGP_FILTER_NAME,
peer->filter[afi][safi].advmap.aname);
if (peer->filter[afi][safi].advmap.cname)
XFREE(MTYPE_BGP_FILTER_NAME,
peer->filter[afi][safi].advmap.cname);
}
XFREE(MTYPE_PEER_TX_SHUTDOWN_MSG, peer->tx_shutdown_message); XFREE(MTYPE_PEER_TX_SHUTDOWN_MSG, peer->tx_shutdown_message);
XFREE(MTYPE_PEER_DESC, peer->desc); XFREE(MTYPE_PEER_DESC, peer->desc);
@ -1121,12 +1130,8 @@ static void peer_free(struct peer *peer)
bfd_info_free(&(peer->bfd_info)); bfd_info_free(&(peer->bfd_info));
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi)
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE);
bgp_addpath_set_peer_type(peer, afi, safi,
BGP_ADDPATH_NONE);
}
}
bgp_unlock(peer->bgp); bgp_unlock(peer->bgp);

View File

@ -104,10 +104,6 @@ enum bgp_af_index {
#define AF_FOREACH(af) for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++) #define AF_FOREACH(af) for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++)
#define FOREACH_AFI_SAFI(afi, safi) \
for (afi = AFI_IP; afi < AFI_MAX; afi++) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
#define FOREACH_SAFI(safi) \ #define FOREACH_SAFI(safi) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)

View File

@ -380,6 +380,19 @@ static void isis_redist_update_zebra_subscriptions(struct isis *isis)
} }
} }
void isis_redist_free(struct isis *isis)
{
int i;
for (i = 0; i < REDIST_PROTOCOL_COUNT; i++) {
if (!isis->ext_info[i])
continue;
route_table_finish(isis->ext_info[i]);
isis->ext_info[i] = NULL;
}
}
void isis_redist_set(struct isis_area *area, int level, int family, int type, void isis_redist_set(struct isis_area *area, int level, int family, int type,
uint32_t metric, const char *routemap, int originate_type) uint32_t metric, const char *routemap, int originate_type)
{ {

View File

@ -62,4 +62,5 @@ void isis_redist_set(struct isis_area *area, int level, int family, int type,
uint32_t metric, const char *routemap, int originate_type); uint32_t metric, const char *routemap, int originate_type);
void isis_redist_unset(struct isis_area *area, int level, int family, int type); void isis_redist_unset(struct isis_area *area, int level, int family, int type);
void isis_redist_free(struct isis *isis);
#endif #endif

View File

@ -1727,6 +1727,11 @@ static struct isis_spf_run *isis_run_spf_arg(struct isis_area *area, int level)
return run; return run;
} }
void isis_spf_timer_free(void *run)
{
XFREE(MTYPE_ISIS_SPF_RUN, run);
}
int _isis_spf_schedule(struct isis_area *area, int level, int _isis_spf_schedule(struct isis_area *area, int level,
const char *func, const char *file, int line) const char *func, const char *file, int line)
{ {

View File

@ -78,4 +78,5 @@ struct isis_spftree *isis_run_hopcount_spf(struct isis_area *area,
uint8_t *sysid, uint8_t *sysid,
struct isis_spftree *spftree); struct isis_spftree *spftree);
void isis_spf_timer_free(void *run);
#endif /* _ZEBRA_ISIS_SPF_H */ #endif /* _ZEBRA_ISIS_SPF_H */

View File

@ -442,7 +442,11 @@ void isis_area_destroy(struct isis_area *area)
spftree_area_del(area); spftree_area_del(area);
if (area->spf_timer[0])
isis_spf_timer_free(THREAD_ARG(area->spf_timer[0]));
thread_cancel(&area->spf_timer[0]); thread_cancel(&area->spf_timer[0]);
if (area->spf_timer[1])
isis_spf_timer_free(THREAD_ARG(area->spf_timer[1]));
thread_cancel(&area->spf_timer[1]); thread_cancel(&area->spf_timer[1]);
spf_backoff_free(area->spf_delay_ietf[0]); spf_backoff_free(area->spf_delay_ietf[0]);
@ -583,6 +587,7 @@ void isis_finish(struct isis *isis)
isis_vrf_unlink(isis, vrf); isis_vrf_unlink(isis, vrf);
} }
isis_redist_free(isis);
list_delete(&isis->area_list); list_delete(&isis->area_list);
list_delete(&isis->init_circ_list); list_delete(&isis->init_circ_list);
XFREE(MTYPE_ISIS, isis); XFREE(MTYPE_ISIS, isis);
@ -2375,6 +2380,9 @@ static void area_resign_level(struct isis_area *area, int level)
} }
} }
if (area->spf_timer[level - 1])
isis_spf_timer_free(THREAD_ARG(area->spf_timer[level - 1]));
thread_cancel(&area->spf_timer[level - 1]); thread_cancel(&area->spf_timer[level - 1]);
sched_debug( sched_debug(

View File

@ -359,6 +359,10 @@ typedef enum {
SAFI_MAX = 8 SAFI_MAX = 8
} safi_t; } safi_t;
#define FOREACH_AFI_SAFI(afi, safi) \
for (afi = AFI_IP; afi < AFI_MAX; afi++) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
/* Default Administrative Distance of each protocol. */ /* Default Administrative Distance of each protocol. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0

View File

@ -546,19 +546,15 @@ void static_fixup_vrf_ids(struct static_vrf *enable_svrf)
svrf = vrf->info; svrf = vrf->info;
/* Install any static routes configured for this VRF. */ /* Install any static routes configured for this VRF. */
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { stable = svrf->stable[afi][safi];
stable = svrf->stable[afi][safi]; if (!stable)
if (!stable) continue;
continue;
static_fixup_vrf(enable_svrf, stable, static_fixup_vrf(enable_svrf, stable, afi, safi);
afi, safi);
if (enable_svrf == svrf) if (enable_svrf == svrf)
static_enable_vrf(svrf, stable, static_enable_vrf(svrf, stable, afi, safi);
afi, safi);
}
} }
} }
} }
@ -649,20 +645,17 @@ void static_cleanup_vrf_ids(struct static_vrf *disable_svrf)
svrf = vrf->info; svrf = vrf->info;
/* Uninstall any static routes configured for this VRF. */ /* Uninstall any static routes configured for this VRF. */
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { struct route_table *stable;
struct route_table *stable;
stable = svrf->stable[afi][safi]; stable = svrf->stable[afi][safi];
if (!stable) if (!stable)
continue; continue;
static_cleanup_vrf(disable_svrf, stable, static_cleanup_vrf(disable_svrf, stable, afi, safi);
afi, safi);
if (disable_svrf == svrf) if (disable_svrf == svrf)
static_disable_vrf(stable, afi, safi); static_disable_vrf(stable, afi, safi);
}
} }
} }
} }
@ -725,14 +718,12 @@ void static_install_intf_nh(struct interface *ifp)
continue; continue;
/* Install any static routes configured for this interface. */ /* Install any static routes configured for this interface. */
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { stable = svrf->stable[afi][safi];
stable = svrf->stable[afi][safi]; if (!stable)
if (!stable) continue;
continue;
static_fixup_intf_nh(stable, ifp, afi, safi); static_fixup_intf_nh(stable, ifp, afi, safi);
}
} }
} }
} }

View File

@ -238,14 +238,12 @@ int static_vrf_has_config(struct static_vrf *svrf)
* NOTE: This is a don't care for the default VRF, but we go through * NOTE: This is a don't care for the default VRF, but we go through
* the motions to keep things consistent. * the motions to keep things consistent.
*/ */
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { table = svrf->stable[afi][safi];
table = svrf->stable[afi][safi]; if (!table)
if (!table) continue;
continue; if (route_table_count(table))
if (route_table_count(table)) return 1;
return 1;
}
} }
return 0; return 0;

View File

@ -106,15 +106,13 @@ static struct bgp *bgp_create_fake(as_t *as, const char *name)
// bgp->group->cmp = (int (*)(void *, void *)) peer_group_cmp; // bgp->group->cmp = (int (*)(void *, void *)) peer_group_cmp;
bgp_evpn_init(bgp); bgp_evpn_init(bgp);
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi);
bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi); bgp->aggregate[afi][safi] = bgp_table_init(bgp, afi, safi);
bgp->aggregate[afi][safi] = bgp_table_init( bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi);
bgp, afi, safi); bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM;
bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi); bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM;
bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM; }
bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM;
}
bgp_scan_init(bgp); bgp_scan_init(bgp);
bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF; bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF;
@ -152,36 +150,33 @@ static int run_bgp_cfg_maximum_paths(testcase_t *t)
int test_result = TEST_PASSED; int test_result = TEST_PASSED;
bgp = t->tmp_data; bgp = t->tmp_data;
for (afi = AFI_IP; afi < AFI_MAX; afi++) FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { /* test bgp_maximum_paths_set */
/* test bgp_maximum_paths_set */ api_result = bgp_maximum_paths_set(bgp, afi, safi,
api_result = bgp_maximum_paths_set( BGP_PEER_EBGP, 10, 0);
bgp, afi, safi, BGP_PEER_EBGP, 10, 0); EXPECT_TRUE(api_result == 0, test_result);
EXPECT_TRUE(api_result == 0, test_result); api_result = bgp_maximum_paths_set(bgp, afi, safi,
api_result = bgp_maximum_paths_set( BGP_PEER_IBGP, 10, 0);
bgp, afi, safi, BGP_PEER_IBGP, 10, 0); EXPECT_TRUE(api_result == 0, test_result);
EXPECT_TRUE(api_result == 0, test_result); EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ebgp == 10,
EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ebgp test_result);
== 10, EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ibgp == 10,
test_result); test_result);
EXPECT_TRUE(bgp->maxpaths[afi][safi].maxpaths_ibgp
== 10,
test_result);
/* test bgp_maximum_paths_unset */ /* test bgp_maximum_paths_unset */
api_result = bgp_maximum_paths_unset(bgp, afi, safi, api_result =
BGP_PEER_EBGP); bgp_maximum_paths_unset(bgp, afi, safi, BGP_PEER_EBGP);
EXPECT_TRUE(api_result == 0, test_result); EXPECT_TRUE(api_result == 0, test_result);
api_result = bgp_maximum_paths_unset(bgp, afi, safi, api_result =
BGP_PEER_IBGP); bgp_maximum_paths_unset(bgp, afi, safi, BGP_PEER_IBGP);
EXPECT_TRUE(api_result == 0, test_result); EXPECT_TRUE(api_result == 0, test_result);
EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ebgp EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ebgp
== MULTIPATH_NUM), == MULTIPATH_NUM),
test_result); test_result);
EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ibgp EXPECT_TRUE((bgp->maxpaths[afi][safi].maxpaths_ibgp
== MULTIPATH_NUM), == MULTIPATH_NUM),
test_result); test_result);
} }
return test_result; return test_result;
} }