]> git.proxmox.com Git - mirror_frr.git/blobdiff - staticd/static_vty.c
*: Replace __PRETTY_FUNCTION__/__FUNCTION__ to __func__
[mirror_frr.git] / staticd / static_vty.c
index ae0026cc97bd0e53e1309e19d6157d721c2aed8d..3903a5a5c5c6fea876b9f871f43814349f2aa1cb 100644 (file)
 #include "static_memory.h"
 #include "static_vty.h"
 #include "static_routes.h"
+#include "static_debug.h"
 #ifndef VTYSH_EXTRACT_PL
 #include "staticd/static_vty_clippy.c"
 #endif
 
+#define STATICD_STR "Static route daemon\n"
+
 static struct static_vrf *static_vty_get_unknown_vrf(struct vty *vty,
                                                     const char *vrf_name)
 {
@@ -104,30 +107,18 @@ static int static_list_compare_helper(const char *s1, const char *s2)
 
 static void static_list_delete(struct static_hold_route *shr)
 {
-       if (shr->vrf_name)
-               XFREE(MTYPE_STATIC_ROUTE, shr->vrf_name);
-       if (shr->nhvrf_name)
-               XFREE(MTYPE_STATIC_ROUTE, shr->nhvrf_name);
-       if (shr->dest_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->dest_str);
-       if (shr->mask_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->mask_str);
-       if (shr->src_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->src_str);
-       if (shr->gate_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->gate_str);
-       if (shr->ifname)
-               XFREE(MTYPE_STATIC_ROUTE, shr->ifname);
-       if (shr->flag_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->flag_str);
-       if (shr->tag_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->tag_str);
-       if (shr->distance_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->distance_str);
-       if (shr->label_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->label_str);
-       if (shr->table_str)
-               XFREE(MTYPE_STATIC_ROUTE, shr->table_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->vrf_name);
+       XFREE(MTYPE_STATIC_ROUTE, shr->nhvrf_name);
+       XFREE(MTYPE_STATIC_ROUTE, shr->dest_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->mask_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->src_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->gate_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->ifname);
+       XFREE(MTYPE_STATIC_ROUTE, shr->flag_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->tag_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->distance_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->label_str);
+       XFREE(MTYPE_STATIC_ROUTE, shr->table_str);
 
        XFREE(MTYPE_STATIC_ROUTE, shr);
 }
@@ -296,8 +287,8 @@ static int static_route_leak(
                if (vty)
                        vty_out(vty, "%% Malformed address\n");
                else
-                       zlog_warn("%s: Malformed address: %s",
-                                 __PRETTY_FUNCTION__, dest_str);
+                       zlog_warn("%s: Malformed address: %s", __func__,
+                                 dest_str);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
@@ -311,8 +302,7 @@ static int static_route_leak(
                                        vty_out(vty, "%% Malformed address\n");
                                else
                                        zlog_warn("%s: Malformed address: %s",
-                                                 __PRETTY_FUNCTION__,
-                                                 mask_str);
+                                                 __func__, mask_str);
                                return CMD_WARNING_CONFIG_FAILED;
                        }
                        p.prefixlen = ip_masklen(mask);
@@ -329,7 +319,7 @@ static int static_route_leak(
                                else
                                        zlog_warn(
                                                "%s: Malformed source address: %s",
-                                               __PRETTY_FUNCTION__, src_str);
+                                               __func__, src_str);
                                return CMD_WARNING_CONFIG_FAILED;
                        }
                        src_p = (struct prefix_ipv6 *)&src;
@@ -360,10 +350,9 @@ static int static_route_leak(
                                    "%% Table %s overlaps vrf table %u\n",
                                    table_str, svrf->vrf->data.l.table_id);
                        else
-                               zlog_warn(
-                                   "%s: Table %s overlaps vrf table %u",
-                                   __PRETTY_FUNCTION__,
-                                   table_str, svrf->vrf->data.l.table_id);
+                               zlog_warn("%s: Table %s overlaps vrf table %u",
+                                         __func__, table_str,
+                                         svrf->vrf->data.l.table_id);
                        return CMD_WARNING_CONFIG_FAILED;
                }
        }
@@ -388,7 +377,7 @@ static int static_route_leak(
                        else
                                zlog_warn(
                                        "%s: MPLS not turned on in kernel ignoring static route to %s",
-                                       __PRETTY_FUNCTION__, dest_str);
+                                       __func__, dest_str);
                        return CMD_WARNING_CONFIG_FAILED;
                }
                int rc = mpls_str2label(label_str, &snh_label.num_labels,
@@ -401,7 +390,7 @@ static int static_route_leak(
                                else
                                        zlog_warn(
                                                "%s: Malformed labels specified for route %s",
-                                               __PRETTY_FUNCTION__, dest_str);
+                                               __func__, dest_str);
                                break;
                        case -2:
                                if (vty)
@@ -412,7 +401,7 @@ static int static_route_leak(
                                else
                                        zlog_warn(
                                                "%s: Cannot use reserved labels (%d-%d) for %s",
-                                               __PRETTY_FUNCTION__,
+                                               __func__,
                                                MPLS_LABEL_RESERVED_MIN,
                                                MPLS_LABEL_RESERVED_MAX,
                                                dest_str);
@@ -425,8 +414,8 @@ static int static_route_leak(
                                else
                                        zlog_warn(
                                                "%s: Too many labels, Enter %d or fewer for %s",
-                                               __PRETTY_FUNCTION__,
-                                               MPLS_MAX_LABELS, dest_str);
+                                               __func__, MPLS_MAX_LABELS,
+                                               dest_str);
                                break;
                        }
                        return CMD_WARNING_CONFIG_FAILED;
@@ -439,16 +428,16 @@ static int static_route_leak(
 
        /* Null0 static route.  */
        if (ifname != NULL) {
-               if (strncasecmp(ifname, "Null0", strlen(ifname)) == 0
-                   || strncasecmp(ifname, "reject", strlen(ifname)) == 0
-                   || strncasecmp(ifname, "blackhole", strlen(ifname)) == 0) {
+               if (strcasecmp(ifname, "Null0") == 0
+                   || strcasecmp(ifname, "reject") == 0
+                   || strcasecmp(ifname, "blackhole") == 0) {
                        if (vty)
                                vty_out(vty,
-                                       "%% Nexthop interface cannot be Null0, reject or blackhole\n");
+                                       "%% Nexthop interface name can not be from reserved keywords (Null0, reject, blackhole)\n");
                        else
                                zlog_warn(
-                                       "%s: Nexthop interface cannot be Null0, reject or blackhole for %s",
-                                       __PRETTY_FUNCTION__, dest_str);
+                                       "%s: %s: Nexthop interface name can not be from reserved keywords (Null0, reject, blackhole)",
+                                       __func__, dest_str);
                        return CMD_WARNING_CONFIG_FAILED;
                }
        }
@@ -471,8 +460,7 @@ static int static_route_leak(
                                        flag_str);
                        else
                                zlog_warn("%s: Malformed flag %s for %s",
-                                         __PRETTY_FUNCTION__, flag_str,
-                                         dest_str);
+                                         __func__, flag_str, dest_str);
                        return CMD_WARNING_CONFIG_FAILED;
                }
        }
@@ -486,11 +474,27 @@ static int static_route_leak(
                        else
                                zlog_warn(
                                        "%s: Malformed nexthop address %s for %s",
-                                       __PRETTY_FUNCTION__, gate_str,
-                                       dest_str);
+                                       __func__, gate_str, dest_str);
                        return CMD_WARNING_CONFIG_FAILED;
                }
                gatep = &gate;
+
+               if (afi == AFI_IP && !negate) {
+                       if (if_lookup_exact_address(&gatep->ipv4, AF_INET,
+                                                       svrf->vrf->vrf_id))
+                               if (vty)
+                                       vty_out(vty,
+                                               "%% Warning!! Local connected address is configured as Gateway IP(%s)\n",
+                                               gate_str);
+               } else if (afi == AFI_IP6 && !negate) {
+                       if (if_lookup_exact_address(&gatep->ipv6, AF_INET6,
+                                                       svrf->vrf->vrf_id))
+                               if (vty)
+                                       vty_out(vty,
+                                               "%% Warning!! Local connected address is configured as Gateway IPv6(%s)\n",
+                                               gate_str);
+               }
+
        }
 
        if (gate_str == NULL && ifname == NULL)
@@ -775,7 +779,7 @@ DEFPY(ip_route_blackhole,
       "Table to configure\n"
       "The table number to configure\n")
 {
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -814,7 +818,7 @@ DEFPY(ip_route_blackhole_vrf,
        VTY_DECLVAR_CONTEXT(vrf, vrf);
        struct static_vrf *svrf = vrf->info;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -880,7 +884,7 @@ DEFPY(ip_route_address_interface,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -938,7 +942,7 @@ DEFPY(ip_route_address_interface_vrf,
        struct static_vrf *svrf = vrf->info;
        struct static_vrf *nh_svrf;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -999,7 +1003,7 @@ DEFPY(ip_route,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1065,7 +1069,7 @@ DEFPY(ip_route_vrf,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1119,7 +1123,7 @@ DEFPY(ipv6_route_blackhole,
       "Table to configure\n"
       "The table number to configure\n")
 {
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1158,7 +1162,7 @@ DEFPY(ipv6_route_blackhole_vrf,
        VTY_DECLVAR_CONTEXT(vrf, vrf);
        struct static_vrf *svrf = vrf->info;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1213,7 +1217,7 @@ DEFPY(ipv6_route_address_interface,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1282,7 +1286,7 @@ DEFPY(ipv6_route_address_interface_vrf,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1343,7 +1347,7 @@ DEFPY(ipv6_route,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && vrf && !vrf_is_mapped_on_netns(vrf_lookup_by_name(vrf))) {
+       if (table_str && vrf && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1409,7 +1413,7 @@ DEFPY(ipv6_route_vrf,
        struct static_vrf *nh_svrf;
        const char *flag = NULL;
 
-       if (table_str && !vrf_is_mapped_on_netns(vrf)) {
+       if (table_str && !vrf_is_backend_netns()) {
                vty_out(vty,
                        "%% table param only available when running on netns-based vrfs\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1435,21 +1439,43 @@ DEFPY(ipv6_route_vrf,
                from_str, gate_str, ifname, flag, tag_str, distance_str, label,
                table_str, false);
 }
+DEFPY(debug_staticd,
+      debug_staticd_cmd,
+      "[no] debug static [{events$events}]",
+      NO_STR
+      DEBUG_STR
+      STATICD_STR
+      "Debug events\n")
+{
+       /* If no specific category, change all */
+       if (strmatch(argv[argc - 1]->text, "static"))
+               static_debug_set(vty->node, !no, true);
+       else
+               static_debug_set(vty->node, !no, !!events);
 
-DEFUN_NOSH (show_debugging_staticd,
-           show_debugging_staticd_cmd,
+       return CMD_SUCCESS;
+}
+
+DEFUN_NOSH (show_debugging_static,
+           show_debugging_static_cmd,
            "show debugging [static]",
            SHOW_STR
            DEBUG_STR
            "Static Information\n")
 {
-       vty_out(vty, "Static debugging status\n");
+       vty_out(vty, "Staticd debugging status\n");
+
+       static_debug_status_write(vty);
 
        return CMD_SUCCESS;
 }
 
+static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
+
 void static_vty_init(void)
 {
+       install_node(&debug_node, static_config_write_debug);
+
        install_element(CONFIG_NODE, &ip_mroute_dist_cmd);
 
        install_element(CONFIG_NODE, &ip_route_blackhole_cmd);
@@ -1466,7 +1492,9 @@ void static_vty_init(void)
        install_element(CONFIG_NODE, &ipv6_route_cmd);
        install_element(VRF_NODE, &ipv6_route_vrf_cmd);
 
-       install_element(VIEW_NODE, &show_debugging_staticd_cmd);
+       install_element(VIEW_NODE, &show_debugging_static_cmd);
+       install_element(VIEW_NODE, &debug_staticd_cmd);
+       install_element(CONFIG_NODE, &debug_staticd_cmd);
 
        static_list = list_new();
        static_list->cmp = (int (*)(void *, void *))static_list_compare;