From c58418c1107928a851aee28b98acae306b79c6e3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Oct 2016 14:25:29 -0400 Subject: [PATCH 1/4] zebra: Disable mpls slightly different When mpls is not turned on in the kernel, we are not installing the mpls commands into the cli. This results in vtysh attempting to run the command and receiving a 'WTF is this command' back from zebra. Modify the mpls code to install commands and to check to see if the command should be accepted based upon mpls working or not. Signed-off-by: Donald Sharp Reviewed-by: Daniel Walton --- zebra/zebra_mpls_vty.c | 10 +++++++--- zebra/zebra_vty.c | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index 6e95236c20..8b967c3af8 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -52,6 +52,13 @@ zebra_mpls_transit_lsp (struct vty *vty, int add_cmd, const char *inlabel_str, mpls_label_t label; mpls_label_t in_label, out_label; + if (!mpls_enabled) + { + vty_out (vty, "%% MPLS not turned on in kernel, ignoring command%s", + VTY_NEWLINE); + return CMD_WARNING; + } + zvrf = vrf_info_lookup(VRF_DEFAULT); if (!zvrf) { @@ -829,9 +836,6 @@ zebra_mpls_vty_init (void) { install_element (VIEW_NODE, &show_mpls_status_cmd); - if (! mpls_enabled) - return; - install_node (&mpls_node, zebra_mpls_config); install_element (CONFIG_NODE, &ip_route_label_cmd); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 6002b0d6fa..6a43da39b3 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -118,6 +118,12 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd, /* Labels */ if (label_str) { + if (!mpls_enabled) + { + vty_out (vty, "%% MPLS not turned on in kernel, ignoring command%s", + VTY_NEWLINE); + return CMD_WARNING; + } if (mpls_str2label (label_str, &snh_label.num_labels, snh_label.label)) { From 4f4caaa1390593d8d3ce45be915187943d53e0bf Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Oct 2016 14:43:07 -0400 Subject: [PATCH 2/4] zebra: Allow v6 static routes to handle mpls not in kernel When configuring v6 static routes, allow it to gracefully ignore mpls commands when mpls is not turned on in the kernel. Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 6a43da39b3..9b0fad93e0 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3734,7 +3734,6 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) return write; } -#ifdef HAVE_IPV6 /* General fucntion for IPv6 static route. */ int static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, @@ -3793,6 +3792,12 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, memset (&snh_label, 0, sizeof (struct static_nh_label)); if (label_str) { + if (!mpls_enabled) + { + vty_out (vty, "%% MPLS not turned on in kernel, ignoring command%s", + VTY_NEWLINE); + return CMD_WARNING; + } if (mpls_str2label (label_str, &snh_label.num_labels, snh_label.label)) { @@ -5841,7 +5846,6 @@ static_config_ipv6 (struct vty *vty) } return write; } -#endif /* HAVE_IPV6 */ DEFUN (allow_external_route_update, allow_external_route_update_cmd, From 5980c3a2682fcf6fa4139f0ff76d10dec3fe3f3a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Oct 2016 15:02:41 -0400 Subject: [PATCH 3/4] ospfd: Dissallow mpls-te commands unless mpls-te has been turned on If ospf mpls-te has not been turned on via a 'mpls-te on' dissallow other mpls-te commands from being silently accepted and ignored. Signed-off-by: Donald Sharp --- ospfd/ospf_te.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index c672500368..60fb7132cc 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -2457,6 +2457,11 @@ set_inter_as_mode (struct vty *vty, const char *mode_name, return CMD_WARNING; } } + else + { + vty_out (vty, "mpls-te has not been turned on%s", VTY_NEWLINE); + return CMD_WARNING; + } return CMD_SUCCESS; } From 284a4a0c81516e3e18cb170272a280ea5121b6d6 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Oct 2016 15:18:50 -0400 Subject: [PATCH 4/4] ospfd: Only allow ospf RI commands if RI is turned on When ospf RI commands are entered and we have not turned on the feature, gracefully tell the user that there is no going forward. Signed-off-by: Donald Sharp --- ospfd/ospf_ri.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index be06cc0a88..b85287197f 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -1266,6 +1266,18 @@ DEFUN (no_router_info, return CMD_SUCCESS; } +static int +ospf_ri_enabled (struct vty *vty) +{ + if (OspfRI.status == enabled) + return 1; + + if (vty) + vty_out (vty, "%% OSPF RI is not turned on%s", VTY_NEWLINE); + + return 0; +} + DEFUN (pce_address, pce_address_cmd, "pce address A.B.C.D", @@ -1276,6 +1288,9 @@ DEFUN (pce_address, struct in_addr value; struct ospf_pce_info *pi = &OspfRI.pce_info; + if (!ospf_ri_enabled (vty)) + return CMD_WARNING; + if (!inet_aton (argv[0], &value)) { vty_out (vty, "Please specify PCE Address by A.B.C.D%s", VTY_NEWLINE); @@ -1289,7 +1304,7 @@ DEFUN (pce_address, set_pce_address (value, pi); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if (OspfRI.flags & RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); } @@ -1323,6 +1338,9 @@ DEFUN (pce_path_scope, uint32_t scope; struct ospf_pce_info *pi = &OspfRI.pce_info; + if (!ospf_ri_enabled (vty)) + return CMD_WARNING; + if (sscanf (argv[0], "0x%x", &scope) != 1) { vty_out (vty, "pce_path_scope: fscanf: %s%s", safe_strerror (errno), @@ -1335,7 +1353,7 @@ DEFUN (pce_path_scope, set_pce_path_scope (scope, pi); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if (OspfRI.flags & RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); } @@ -1373,6 +1391,9 @@ DEFUN (pce_domain, struct listnode *node; struct ri_pce_subtlv_domain *domain; + if (!ospf_ri_enabled (vty)) + return CMD_WARNING; + if (sscanf (argv[0], "%d", &as) != 1) { vty_out (vty, "pce_domain: fscanf: %s%s", safe_strerror (errno), @@ -1384,17 +1405,17 @@ DEFUN (pce_domain, for (ALL_LIST_ELEMENTS_RO (pce->pce_domain, node, domain)) { if (ntohl (domain->header.type) == 0 && as == domain->value) - goto out; + return CMD_SUCCESS; } /* Create new domain if not found */ set_pce_domain (PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if (OspfRI.flags & RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); -out:return CMD_SUCCESS; + return CMD_SUCCESS; } DEFUN (no_pce_domain, @@ -1441,6 +1462,9 @@ DEFUN (pce_neigbhor, struct listnode *node; struct ri_pce_subtlv_neighbor *neighbor; + if (!ospf_ri_enabled (vty)) + return CMD_WARNING; + if (sscanf (argv[0], "%d", &as) != 1) { vty_out (vty, "pce_neighbor: fscanf: %s%s", safe_strerror (errno), @@ -1452,17 +1476,17 @@ DEFUN (pce_neigbhor, for (ALL_LIST_ELEMENTS_RO (pce->pce_neighbor, node, neighbor)) { if (ntohl (neighbor->header.type) == 0 && as == neighbor->value) - goto out; + return CMD_SUCCESS; } /* Create new domain if not found */ set_pce_neighbor (PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if (OspfRI.flags & RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); -out:return CMD_SUCCESS; + return CMD_SUCCESS; } DEFUN (no_pce_neighbor, @@ -1506,6 +1530,9 @@ DEFUN (pce_cap_flag, uint32_t cap; struct ospf_pce_info *pce = &OspfRI.pce_info; + if (!ospf_ri_enabled (vty)) + return CMD_WARNING; + if (sscanf (argv[0], "0x%x", &cap) != 1) { vty_out (vty, "pce_cap_flag: fscanf: %s%s", safe_strerror (errno), @@ -1519,7 +1546,7 @@ DEFUN (pce_cap_flag, set_pce_cap_flag (cap, pce); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if (OspfRI.flags & RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); }