From 0ce1ca805d607cec2c0f75dac8950f40e75fc971 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 14 Jun 2018 08:58:05 -0400 Subject: *: ALLOC calls cannot fail There is no need to check for failure of a ALLOC call as that any failure to do so will result in a assert happening. So we can safely remove all of this code. Signed-off-by: Donald Sharp --- pimd/pim_br.c | 1 - pimd/pim_cmd.c | 5 ----- pimd/pim_igmpv3.c | 31 ------------------------------- pimd/pim_rp.c | 17 ----------------- pimd/pimd.h | 1 - 5 files changed, 55 deletions(-) (limited to 'pimd') diff --git a/pimd/pim_br.c b/pimd/pim_br.c index 6184ea12c..fc6a02ec9 100644 --- a/pimd/pim_br.c +++ b/pimd/pim_br.c @@ -64,7 +64,6 @@ void pim_br_set_pmbr(struct prefix_sg *sg, struct in_addr br) if (!pim_br) { pim_br = XCALLOC(MTYPE_PIM_BR, sizeof(*pim_br)); - pim_br->sg = *sg; listnode_add(pim_br_list, pim_br); diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 460bbfeae..15717aa7a 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -5106,11 +5106,6 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, struct vty *vty, result = pim_rp_new(pim, rp, group, plist); - if (result == PIM_MALLOC_FAIL) { - vty_out(vty, "%% Out of memory\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if (result == PIM_GROUP_BAD_ADDRESS) { vty_out(vty, "%% Bad group address specified: %s\n", group); return CMD_WARNING_CONFIG_FAILED; diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index b32d71cc0..132fe4d56 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -486,9 +486,6 @@ static struct igmp_source *add_source_by_addr(struct igmp_sock *igmp, } src = source_new(group, src_addr); - if (!src) { - return 0; - } return src; } @@ -579,10 +576,6 @@ static void isex_excl(struct igmp_group *group, int num_sources, /* E.4: if not found, create source with timer=GMI: * (A-X-Y) */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ igmp_source_reset_gmi(group->group_igmp_sock, group, source); @@ -637,10 +630,6 @@ static void isex_incl(struct igmp_group *group, int num_sources, /* I.4: if not found, create source with timer=0 (B-A) */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* (B-A) timer=0 */ } @@ -720,10 +709,6 @@ static void toin_incl(struct igmp_group *group, int num_sources, } else { /* If not found, create new source */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } } /* (B)=GMI */ @@ -765,10 +750,6 @@ static void toin_excl(struct igmp_group *group, int num_sources, } else { /* If not found, create new source */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } } /* (A)=GMI */ @@ -854,10 +835,6 @@ static void toex_incl(struct igmp_group *group, int num_sources, /* If source not found, create source with timer=0: * (B-A)=0 */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* (B-A) timer=0 */ } @@ -917,10 +894,6 @@ static void toex_excl(struct igmp_group *group, int num_sources, * (A-X-Y)=Group Timer */ long group_timer_msec; source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ group_timer_msec = igmp_group_timer_remain_msec(group); @@ -1431,10 +1404,6 @@ static void block_excl(struct igmp_group *group, int num_sources, * (A-X-Y)=Group Timer */ long group_timer_msec; source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ group_timer_msec = igmp_group_timer_remain_msec(group); diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 783f93175..3b3e5eb69 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -102,19 +102,10 @@ void pim_rp_init(struct pim_instance *pim) struct route_node *rn; pim->rp_list = list_new(); - if (!pim->rp_list) { - zlog_err("Unable to alloc rp_list"); - return; - } pim->rp_list->del = (void (*)(void *))pim_rp_info_free; pim->rp_list->cmp = pim_rp_list_cmp; pim->rp_table = route_table_init(); - if (!pim->rp_table) { - zlog_err("Unable to alloc rp_table"); - list_delete_and_null(&pim->rp_list); - return; - } rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); @@ -133,14 +124,6 @@ void pim_rp_init(struct pim_instance *pim) listnode_add(pim->rp_list, rp_info); rn = route_node_get(pim->rp_table, &rp_info->group); - if (!rn) { - zlog_err("Failure to get route node for pim->rp_table"); - list_delete_and_null(&pim->rp_list); - route_table_finish(pim->rp_table); - XFREE(MTYPE_PIM_RP, rp_info); - return; - } - rn->info = rp_info; if (PIM_DEBUG_TRACE) zlog_debug( diff --git a/pimd/pimd.h b/pimd/pimd.h index 840e0d7e3..1b11dc3f7 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -117,7 +117,6 @@ /* PIM error codes */ #define PIM_SUCCESS 0 -#define PIM_MALLOC_FAIL -1 #define PIM_GROUP_BAD_ADDRESS -2 #define PIM_GROUP_OVERLAP -3 #define PIM_GROUP_PFXLIST_OVERLAP -4 -- cgit v1.2.3 From 91e5b43ab4d532cfbc38e71621c87fe98fb63130 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sun, 8 Jul 2018 21:39:37 -0300 Subject: lib, vtysh: fix inconsistent interface commands in vtysh The definition of the interface commands in vtysh.c were outdated. Currently, all daemons that call if_cmd_init() will have the "no interface IFNAME" command and the "[no] description" commands as well, so there's no need to define exceptions for these commands anymore. To fix this, make extract.pl parse the if.c file so that vtysh can get the interface commands from there automatically. Only the "interface IFNAME [vrf NAME]" must be kept in vtysh.c because it changes the vty node and thus needs special treatment. Finally, make pimd and pbrd display interface descriptions on "sh run" when they are configured. Signed-off-by: Renato Westphal --- lib/if.c | 16 ++++++++-------- pbrd/pbr_vty.c | 3 +++ pimd/pim_vty.c | 5 +++++ vtysh/Makefile.am | 2 +- vtysh/extract.pl.in | 3 +++ vtysh/vtysh.c | 29 ----------------------------- 6 files changed, 20 insertions(+), 38 deletions(-) (limited to 'pimd') diff --git a/lib/if.c b/lib/if.c index e31ccd856..dd7d21038 100644 --- a/lib/if.c +++ b/lib/if.c @@ -626,7 +626,7 @@ static struct interface *if_sunwzebra_get(char *name, vrf_id_t vrf_id) } #endif /* SUNOS_5 */ -DEFUN (interface, +DEFUN_NOSH (interface, interface_cmd, "interface IFNAME [vrf NAME]", "Select an interface to configure\n" @@ -669,13 +669,13 @@ DEFUN (interface, return CMD_SUCCESS; } -DEFUN_NOSH (no_interface, - no_interface_cmd, - "no interface IFNAME [vrf NAME]", - NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n" - VRF_CMD_HELP_STR) +DEFUN (no_interface, + no_interface_cmd, + "no interface IFNAME [vrf NAME]", + NO_STR + "Delete a pseudo interface's configuration\n" + "Interface's name\n" + VRF_CMD_HELP_STR) { int idx_vrf = 4; const char *ifname = argv[2]->arg; diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 44e14c547..a4b87f99d 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -580,6 +580,9 @@ static int pbr_interface_config_write(struct vty *vty) vty_frame(vty, "interface %s vrf %s\n", ifp->name, vrf->name); + if (ifp->desc) + vty_out(vty, " description %s\n", ifp->desc); + pbr_map_write_interfaces(vty, ifp); vty_endframe(vty, "!\n"); diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index f4d833c26..88be195be 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -258,6 +258,11 @@ int pim_interface_config_write(struct vty *vty) ifp->name, vrf->name); ++writes; + if (ifp->desc) { + vty_out(vty, " description %s\n", ifp->desc); + ++writes; + } + if (ifp->info) { struct pim_interface *pim_ifp = ifp->info; diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 6d0b4a8fd..9f81b42e3 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -154,7 +154,7 @@ vtysh_cmd_FILES = $(vtysh_scan) \ $(top_srcdir)/lib/keychain.c $(top_srcdir)/lib/routemap.c \ $(top_srcdir)/lib/filter.c $(top_srcdir)/lib/plist.c \ $(top_srcdir)/lib/distribute.c $(top_srcdir)/lib/if_rmap.c \ - $(top_srcdir)/lib/vrf.c \ + $(top_srcdir)/lib/vrf.c $(top_srcdir)/lib/if.c \ $(top_srcdir)/lib/vty.c $(top_srcdir)/zebra/debug.c \ $(top_srcdir)/lib/logicalrouter.c \ $(top_srcdir)/lib/nexthop_group.c \ diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index b93314c96..92b5686a9 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -87,6 +87,9 @@ foreach (@ARGV) { elsif ($file =~ /lib\/vrf\.c$/) { $protocol = "VTYSH_VRF"; } + elsif ($file =~ /lib\/if\.c$/) { + $protocol = "VTYSH_INTERFACE"; + } elsif ($file =~ /lib\/logicalrouter\.c$/) { $protocol = "VTYSH_ALL"; } diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 4e24bef92..229337d82 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2018,18 +2018,6 @@ DEFUNSH(VTYSH_ZEBRA, vtysh_pseudowire, vtysh_pseudowire_cmd, return CMD_SUCCESS; } -/* TODO Implement "no interface command in isisd. */ -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D - | VTYSH_EIGRPD, - vtysh_no_interface_cmd, "no interface IFNAME", NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n") - -DEFSH(VTYSH_ZEBRA, vtysh_no_interface_vrf_cmd, "no interface IFNAME vrf NAME", - NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n" VRF_CMD_HELP_STR) - DEFUNSH(VTYSH_ZEBRA, vtysh_logicalrouter, vtysh_logicalrouter_cmd, "logical-router (1-65535) ns NAME", "Enable a logical-router\n" @@ -2119,19 +2107,6 @@ DEFUNSH(VTYSH_VRF, vtysh_quit_nexthop_group, vtysh_quit_nexthop_group_cmd, return vtysh_exit_nexthop_group(self, vty, argc, argv); } -/* - * TODO Implement interface description commands in ripngd, ospf6d - * and isisd. - */ -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD, - vtysh_interface_desc_cmd, "description LINE...", - "Interface specific description\n" - "Characters describing this interface\n") - -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD, - vtysh_no_interface_desc_cmd, "no description", - NO_STR "Interface specific description\n") - DEFUNSH(VTYSH_INTERFACE, vtysh_exit_interface, vtysh_exit_interface_cmd, "exit", "Exit current mode and down to previous mode\n") { @@ -3584,8 +3559,6 @@ void vtysh_init_vty(void) install_element(PBRMAP_NODE, &vtysh_end_all_cmd); install_element(VTY_NODE, &vtysh_end_all_cmd); - install_element(INTERFACE_NODE, &vtysh_interface_desc_cmd); - install_element(INTERFACE_NODE, &vtysh_no_interface_desc_cmd); install_element(INTERFACE_NODE, &vtysh_end_all_cmd); install_element(INTERFACE_NODE, &vtysh_exit_interface_cmd); install_element(LINK_PARAMS_NODE, &exit_link_params_cmd); @@ -3689,8 +3662,6 @@ void vtysh_init_vty(void) install_element(KEYCHAIN_NODE, &key_chain_cmd); install_element(KEYCHAIN_KEY_NODE, &key_chain_cmd); install_element(CONFIG_NODE, &vtysh_interface_cmd); - install_element(CONFIG_NODE, &vtysh_no_interface_cmd); - install_element(CONFIG_NODE, &vtysh_no_interface_vrf_cmd); install_element(CONFIG_NODE, &vtysh_pseudowire_cmd); install_element(INTERFACE_NODE, &vtysh_link_params_cmd); install_element(ENABLE_NODE, &vtysh_show_running_config_cmd); -- cgit v1.2.3