]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: show pbr iptable per iptable
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 29 Jun 2018 11:45:01 +0000 (13:45 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 24 Jul 2018 10:17:57 +0000 (12:17 +0200)
Add ability to pass a ip table parameter.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
zebra/zebra_pbr.c
zebra/zebra_pbr.h
zebra/zebra_vty.c

index 74ef25b031fb750c8dff6edeeab2b988d077fb48..35d808abea33f3582e536728f4f1e23341d77262 100644 (file)
@@ -832,6 +832,7 @@ struct zebra_pbr_ipset_entry_unique_display {
 struct zebra_pbr_env_display {
        struct zebra_ns *zns;
        struct vty *vty;
+       char *name;
 };
 
 static const char *zebra_pbr_prefix2str(union prefixconstptr pu,
@@ -1037,6 +1038,7 @@ void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname)
        }
        uniqueipset.zns = zns;
        uniqueipset.vty = vty;
+       uniqueipset.name = NULL;
        hash_walk(zns->ipset_hash, zebra_pbr_show_ipset_walkcb,
                  &uniqueipset);
 }
@@ -1060,13 +1062,10 @@ static int zebra_pbr_rule_lookup_fwmark_walkcb(struct hash_backet *backet,
        return HASHWALK_CONTINUE;
 }
 
-static int zebra_pbr_show_iptable_walkcb(struct hash_backet *backet, void *arg)
+static void zebra_pbr_show_iptable_unit(struct zebra_pbr_iptable *iptable,
+                                      struct vty *vty,
+                                      struct zebra_ns *zns)
 {
-       struct zebra_pbr_iptable *iptable =
-               (struct zebra_pbr_iptable *)backet->data;
-       struct zebra_pbr_env_display *env = (struct zebra_pbr_env_display *)arg;
-       struct vty *vty = env->vty;
-       struct zebra_ns *zns = env->zns;
        int ret;
        uint64_t pkts = 0, bytes = 0;
 
@@ -1129,17 +1128,34 @@ static int zebra_pbr_show_iptable_walkcb(struct hash_backet *backet, void *arg)
                                prfl.fwmark);
                }
        }
+}
+
+static int zebra_pbr_show_iptable_walkcb(struct hash_backet *backet, void *arg)
+{
+       struct zebra_pbr_iptable *iptable =
+               (struct zebra_pbr_iptable *)backet->data;
+       struct zebra_pbr_env_display *env = (struct zebra_pbr_env_display *)arg;
+       struct vty *vty = env->vty;
+       struct zebra_ns *zns = env->zns;
+       char *iptable_name = env->name;
+
+       if (!iptable_name)
+               zebra_pbr_show_iptable_unit(iptable, vty, zns);
+       else if (!strncmp(iptable_name,
+                         iptable->ipset_name,
+                         ZEBRA_IPSET_NAME_SIZE))
+               zebra_pbr_show_iptable_unit(iptable, vty, zns);
        return HASHWALK_CONTINUE;
 }
 
-void zebra_pbr_show_iptable(struct vty *vty)
+void zebra_pbr_show_iptable(struct vty *vty, char *iptable_name)
 {
        struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
        struct zebra_pbr_env_display env;
 
        env.vty = vty;
        env.zns = zns;
-
+       env.name = iptable_name;
        hash_walk(zns->iptable_hash, zebra_pbr_show_iptable_walkcb,
                  &env);
 }
index fd83502ae180e1f8982228b7a50c79474a7660ba..0db33d1f8c1981fc3f05e6056bc93aa60c59cdcf 100644 (file)
@@ -235,7 +235,7 @@ extern int zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2);
 
 extern void zebra_pbr_init(void);
 extern void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname);
-extern void zebra_pbr_show_iptable(struct vty *vty);
+extern void zebra_pbr_show_iptable(struct vty *vty, char *iptable);
 extern void zebra_pbr_iptable_update_interfacelist(struct stream *s,
                                   struct zebra_pbr_iptable *zpi);
 size_t zebra_pbr_tcpflags_snprintf(char *buffer, size_t len,
index 8ee47d2f1b6508c6864eebedb3802dbf8508b2d7..bed3b7f77cd3d69821d002bc99069759a5602c87 100644 (file)
@@ -3474,12 +3474,20 @@ DEFUN (show_pbr_ipset,
 /* policy routing contexts */
 DEFUN (show_pbr_iptable,
        show_pbr_iptable_cmd,
-       "show pbr iptable",
+       "show pbr iptable [WORD]",
        SHOW_STR
        "Policy-Based Routing\n"
-       "IPtable Context information\n")
+       "IPtable Context information\n"
+       "IPtable Name information\n")
 {
-       zebra_pbr_show_iptable(vty);
+       int idx = 0;
+       int found = 0;
+
+       found = argv_find(argv, argc, "WORD", &idx);
+       if (!found)
+               zebra_pbr_show_iptable(vty, NULL);
+       else
+               zebra_pbr_show_iptable(vty, argv[idx]->arg);
        return CMD_SUCCESS;
 }