From 11884868d4b091a7e82e80258d676122239ad6b8 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 13 Jun 2019 19:36:54 -0400 Subject: [PATCH] pimd: ALLOC functions cannot fail. There is no need to check for ALLOC function failures in the code base. If we cannot get more memory we assert. Signed-off-by: Donald Sharp --- pimd/pim_assert.c | 6 ------ pimd/pim_bsm.c | 31 ------------------------------- pimd/pim_cmd.c | 19 ++++--------------- pimd/pim_iface.c | 6 +----- pimd/pim_ifchannel.c | 11 ----------- pimd/pim_mroute.c | 8 -------- pimd/pim_static.c | 3 --- pimd/pim_zebra.c | 29 +---------------------------- 8 files changed, 6 insertions(+), 107 deletions(-) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 438a0c9b64..228218e3a3 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -148,12 +148,6 @@ static int dispatch_assert(struct interface *ifp, struct in_addr source_addr, sg.src = source_addr; sg.grp = group_addr; ch = pim_ifchannel_add(ifp, &sg, 0, 0); - if (!ch) { - zlog_warn( - "%s: (S,G)=%s failure creating channel on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), ifp->name); - return -1; - } switch (ch->ifassert_state) { case PIM_IFASSERT_NOINFO: diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index 266d3ffcf5..9995b5e31f 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -152,14 +152,6 @@ static struct bsgrp_node *pim_bsm_new_bsgrp_node(struct route_table *rt, } bsgrp = XCALLOC(MTYPE_PIM_BSGRP_NODE, sizeof(struct bsgrp_node)); - if (!bsgrp) { - if (PIM_DEBUG_BSM) - zlog_debug("%s: bsgrp alloc failed", - __PRETTY_FUNCTION__); - route_unlock_node(rn); - return NULL; - } - rn->info = bsgrp; bsgrp->bsrp_list = pim_alloc_bsrp_list(); bsgrp->partial_bsrp_list = pim_alloc_bsrp_list(); @@ -730,12 +722,6 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, pak_start = XCALLOC(MTYPE_PIM_BSM_PKT_VAR_MEM, pim_mtu); - if (!pak_start) { - if (PIM_DEBUG_BSM) - zlog_debug("%s: malloc failed", __PRETTY_FUNCTION__); - return false; - } - pkt = pak_start; /* Fill PIM header later before sending packet to calc checksum */ @@ -1057,13 +1043,6 @@ static bool pim_install_bsm_grp_rp(struct pim_instance *pim, /*memory allocation for bsm_rpinfo */ bsm_rpinfo = XCALLOC(MTYPE_PIM_BSRP_NODE, sizeof(*bsm_rpinfo)); - if (!bsm_rpinfo) { - if (PIM_DEBUG_BSM) - zlog_debug("%s, Memory allocation failed.\r\n", - __PRETTY_FUNCTION__); - return false; - } - bsm_rpinfo->rp_prio = rp->rp_pri; bsm_rpinfo->rp_holdtime = rp->rp_holdtime; memcpy(&bsm_rpinfo->rp_address, &rp->rpaddr.addr, @@ -1387,18 +1366,8 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (!no_fwd) { pim_bsm_fwd_whole_sz(pim_ifp->pim, buf, buf_size, sz); bsminfo = XCALLOC(MTYPE_PIM_BSM_INFO, sizeof(struct bsm_info)); - if (!bsminfo) { - zlog_warn("%s: bsminfo alloc failed", - __PRETTY_FUNCTION__); - return 0; - } bsminfo->bsm = XCALLOC(MTYPE_PIM_BSM_PKT_VAR_MEM, buf_size); - if (!bsminfo->bsm) { - zlog_warn("%s: bsm alloc failed", __PRETTY_FUNCTION__); - XFREE(MTYPE_PIM_BSM_INFO, bsminfo); - return 0; - } bsminfo->size = buf_size; memcpy(bsminfo->bsm, buf, buf_size); diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index c6617d9d21..064e91d893 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -6653,13 +6653,7 @@ static int pim_cmd_igmp_start(struct vty *vty, struct interface *ifp) pim_ifp = ifp->info; if (!pim_ifp) { - pim_ifp = pim_if_new(ifp, true, false, false, - false /*vxlan_term*/); - if (!pim_ifp) { - vty_out(vty, "Could not enable IGMP on interface %s\n", - ifp->name); - return CMD_WARNING_CONFIG_FAILED; - } + (void)pim_if_new(ifp, true, false, false, false); need_startup = 1; } else { if (!PIM_IF_TEST_IGMP(pim_ifp->options)) { @@ -7364,15 +7358,10 @@ static int pim_cmd_interface_add(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; - if (!pim_ifp) { - pim_ifp = pim_if_new(ifp, false, true, false, - false /*vxlan_term*/); - if (!pim_ifp) { - return 0; - } - } else { + if (!pim_ifp) + (void)pim_if_new(ifp, false, true, false, false); + else PIM_IF_DO_PIM(pim_ifp->options); - } pim_if_addr_add_all(ifp); pim_if_membership_refresh(ifp); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 7b8f045697..0511a1a157 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1293,11 +1293,7 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, return ferr_ok(); } - ij = igmp_join_new(ifp, group_addr, source_addr); - if (!ij) { - return ferr_cfg_invalid( - "Failure to create new join data structure, see log file for more information"); - } + (void)igmp_join_new(ifp, group_addr, source_addr); if (PIM_DEBUG_IGMP_EVENTS) { char group_str[INET_ADDRSTRLEN]; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 3fb3da8f44..1460c8bb6d 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -791,8 +791,6 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, ch = pim_ifchannel_add(ifp, sg, source_flags, PIM_UPSTREAM_FLAG_MASK_SRC_PIM); - if (!ch) - return; /* RFC 4601: 4.6.1. (S,G) Assert Message State Machine @@ -953,8 +951,6 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, ch = pim_ifchannel_add(ifp, sg, source_flags, PIM_UPSTREAM_FLAG_MASK_SRC_PIM); - if (!ch) - return; pim_ifp = ifp->info; @@ -1082,13 +1078,6 @@ int pim_ifchannel_local_membership_add(struct interface *ifp, } ch = pim_ifchannel_add(ifp, sg, 0, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP); - if (!ch) { - if (PIM_DEBUG_EVENTS) - zlog_debug("%s:%s Unable to add ifchannel", - __PRETTY_FUNCTION__, - pim_str_sg_dump(sg)); - return 0; - } ifmembership_set(ch, PIM_IFMEMBERSHIP_INCLUDE); diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 2bdec12cd1..d0cd27008e 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -212,14 +212,6 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, up = pim_upstream_find_or_add(&sg, ifp, PIM_UPSTREAM_FLAG_MASK_FHR, __PRETTY_FUNCTION__); - if (!up) { - if (PIM_DEBUG_MROUTE) { - zlog_debug( - "%s: Failure to add upstream information for %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); - } - return 0; - } /* * I moved this debug till after the actual add because diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 442b22e06f..62c3216e86 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -124,9 +124,6 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, * back if it fails. */ original_s_route = static_route_alloc(); - if (!original_s_route) { - return -5; - } memcpy(original_s_route, s_route, sizeof(struct static_route)); diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index e09163a527..32cd81b1b2 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -976,16 +976,6 @@ void igmp_source_forward_start(struct pim_instance *pim, /*Create a dummy channel oil */ source->source_channel_oil = pim_channel_oil_add( pim, &sg, MAXVIFS, __PRETTY_FUNCTION__); - - if (!source->source_channel_oil) { - if (PIM_DEBUG_IGMP_TRACE) { - zlog_debug( - "%s %s: could not create OIL for channel (S,G)=%s", - __FILE__, __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg)); - } - return; - } } else { @@ -1248,19 +1238,10 @@ void pim_forward_start(struct pim_ifchannel *ch) pim, &up->sg, MAXVIFS, __PRETTY_FUNCTION__); } - else { + else up->channel_oil = pim_channel_oil_add( pim, &up->sg, input_iface_vif_index, __PRETTY_FUNCTION__); - if (!up->channel_oil) { - if (PIM_DEBUG_PIM_TRACE) - zlog_debug( - "%s %s: could not create OIL for channel (S,G)=%s", - __FILE__, __PRETTY_FUNCTION__, - up->sg_str); - return; - } - } if (PIM_DEBUG_TRACE) { struct interface *in_intf = pim_if_find_by_vif_index( @@ -1275,14 +1256,6 @@ void pim_forward_start(struct pim_ifchannel *ch) up->channel_oil = pim_channel_oil_add(pim, &up->sg, input_iface_vif_index, __PRETTY_FUNCTION__); - if (!up->channel_oil) { - if (PIM_DEBUG_PIM_TRACE) - zlog_debug( - "%s %s: could not create OIL for channel (S,G)=%s", - __FILE__, __PRETTY_FUNCTION__, - up->sg_str); - return; - } } if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP) -- 2.39.5