]> git.proxmox.com Git - mirror_frr.git/blobdiff - pbrd/pbr_vty.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pbrd / pbr_vty.c
index d68bcfa160424d192044b6543ea50ab814f0e26d..bb09a10b982924df0cc8d4101400cfcad838ec02 100644 (file)
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * PBR - vty code
  * Copyright (C) 2018 Cumulus Networks, Inc.
  *               Donald Sharp
- *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include <zebra.h>
 
@@ -36,9 +23,7 @@
 #include "pbrd/pbr_zebra.h"
 #include "pbrd/pbr_vty.h"
 #include "pbrd/pbr_debug.h"
-#ifndef VTYSH_EXTRACT_PL
 #include "pbrd/pbr_vty_clippy.c"
-#endif
 
 DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map PBRMAP seq (1-700)",
           "Create pbr-map or enter pbr-map command mode\n"
@@ -137,6 +122,9 @@ DEFPY(pbr_map_match_src, pbr_map_match_src_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (pbrms->dst && pbrms->family && prefix->family != pbrms->family) {
                vty_out(vty, "Cannot mismatch families within match src/dst\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -170,6 +158,9 @@ DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (pbrms->src && pbrms->family && prefix->family != pbrms->family) {
                vty_out(vty, "Cannot mismatch families within match src/dst\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -204,6 +195,9 @@ DEFPY(pbr_map_match_ip_proto, pbr_map_match_ip_proto_cmd,
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
        struct protoent *p;
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no) {
                p = getprotobyname(ip_proto);
                if (!p) {
@@ -228,6 +222,9 @@ DEFPY(pbr_map_match_src_port, pbr_map_match_src_port_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no) {
                if (pbrms->src_prt == port)
                        return CMD_SUCCESS;
@@ -250,6 +247,9 @@ DEFPY(pbr_map_match_dst_port, pbr_map_match_dst_port_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no) {
                if (pbrms->dst_prt == port)
                        return CMD_SUCCESS;
@@ -274,6 +274,9 @@ DEFPY(pbr_map_match_dscp, pbr_map_match_dscp_cmd,
        char dscpname[100];
        uint8_t rawDscp;
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        /* Discriminate dscp enums (cs0, cs1 etc.) and numbers */
        bool isANumber = true;
        for (int i = 0; i < (int)strlen(dscp); i++) {
@@ -333,6 +336,9 @@ DEFPY(pbr_map_match_ecn, pbr_map_match_ecn_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no) {
                if ((pbrms->dsfield & PBR_DSFIELD_ECN) == ecn)
                        return CMD_SUCCESS;
@@ -357,6 +363,9 @@ DEFPY(pbr_map_match_mark, pbr_map_match_mark_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
 #ifndef GNU_LINUX
        vty_out(vty, "pbr marks are not supported on this platform\n");
        return CMD_WARNING_CONFIG_FAILED;
@@ -417,6 +426,9 @@ DEFPY(pbr_map_action_queue_id, pbr_map_action_queue_id_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no)
                pbrms->action_queue_id = queue_id;
        else if ((uint32_t)queue_id == pbrms->action_queue_id)
@@ -435,6 +447,9 @@ DEFPY(pbr_map_action_pcp, pbr_map_action_pcp_cmd, "[no] set pcp <(0-7)$pcp>",
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no)
                pbrms->action_pcp = pcp;
        else if (pcp == pbrms->action_pcp)
@@ -454,6 +469,9 @@ DEFPY(pbr_map_action_vlan_id, pbr_map_action_vlan_id_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no)
                pbrms->action_vlan_id = vlan_id;
        else if (pbrms->action_vlan_id == vlan_id)
@@ -472,6 +490,9 @@ DEFPY(pbr_map_action_strip_vlan, pbr_map_action_strip_vlan_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (!no)
                pbrms->action_vlan_flags = PBR_MAP_STRIP_INNER_ANY;
        else
@@ -492,6 +513,9 @@ DEFPY(pbr_map_nexthop_group, pbr_map_nexthop_group_cmd,
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
        struct nexthop_group_cmd *nhgc;
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        nhgc = nhgc_find(name);
        if (!nhgc) {
                vty_out(vty, "Specified nexthop-group %s does not exist\n",
@@ -522,6 +546,9 @@ DEFPY(no_pbr_map_nexthop_group, no_pbr_map_nexthop_group_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        pbrms_clear_set_config(pbrms);
 
        return CMD_SUCCESS;
@@ -548,6 +575,9 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd,
        struct nexthop nhop;
        struct nexthop *nh = NULL;
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        if (vrf_name)
                vrf = vrf_lookup_by_name(vrf_name);
        else
@@ -670,6 +700,9 @@ DEFPY(no_pbr_map_nexthop, no_pbr_map_nexthop_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        pbrms_clear_set_config(pbrms);
 
        return CMD_SUCCESS;
@@ -684,6 +717,9 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        /*
         * If an equivalent set vrf * exists, just return success.
         */
@@ -722,6 +758,9 @@ DEFPY(no_pbr_map_vrf, no_pbr_map_vrf_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       if (!pbrms)
+               return CMD_WARNING_CONFIG_FAILED;
+
        pbrms_clear_set_config(pbrms);
 
        return CMD_SUCCESS;
@@ -881,12 +920,12 @@ static void vty_show_pbrms(struct vty *vty,
 
                if (detail)
                        vty_out(vty,
-                               "          Installed: %u(%d) Tableid: %d\n",
+                               "          Installed: %u(%d) Tableid: %u\n",
                                pbrms->nhs_installed,
                                pbr_nht_get_installed(pbrms->nhgrp_name),
                                pbr_nht_get_table(pbrms->nhgrp_name));
                else
-                       vty_out(vty, "          Installed: %s Tableid: %d\n",
+                       vty_out(vty, "          Installed: %s Tableid: %u\n",
                                pbr_nht_get_installed(pbrms->nhgrp_name) ? "yes"
                                                                         : "no",
                                pbr_nht_get_table(pbrms->nhgrp_name));
@@ -896,12 +935,12 @@ static void vty_show_pbrms(struct vty *vty,
                pbrms_nexthop_group_write_individual_nexthop(vty, pbrms);
                if (detail)
                        vty_out(vty,
-                               "          Installed: %u(%d) Tableid: %d\n",
+                               "          Installed: %u(%d) Tableid: %u\n",
                                pbrms->nhs_installed,
                                pbr_nht_get_installed(pbrms->internal_nhg_name),
                                pbr_nht_get_table(pbrms->internal_nhg_name));
                else
-                       vty_out(vty, "          Installed: %s Tableid: %d\n",
+                       vty_out(vty, "          Installed: %s Tableid: %u\n",
                                pbr_nht_get_installed(pbrms->internal_nhg_name)
                                        ? "yes"
                                        : "no",
@@ -1189,6 +1228,8 @@ DEFUN_NOSH(show_debugging_pbr,
 
        pbr_debug_config_write_helper(vty, false);
 
+       cmd_show_lib_debugs(vty);
+
        return CMD_SUCCESS;
 }