]> git.proxmox.com Git - mirror_frr.git/blobdiff - pbrd/pbr_vty.c
Merge pull request #8488 from mjstapp/more_workqueue
[mirror_frr.git] / pbrd / pbr_vty.c
index a73d885ea66abcf3021cf1e7a98edcd92a9019df..216834fe0c60c6b84ccdc044b6e3c52eb870eb18 100644 (file)
@@ -137,6 +137,11 @@ DEFPY(pbr_map_match_src, pbr_map_match_src_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       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;
+       }
+
        pbrms->family = prefix->family;
 
        if (!no) {
@@ -165,6 +170,11 @@ DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd,
 {
        struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
 
+       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;
+       }
+
        pbrms->family = prefix->family;
 
        if (!no) {
@@ -618,10 +628,36 @@ DEFPY (show_pbr,
        return CMD_SUCCESS;
 }
 
+static void
+pbrms_nexthop_group_write_individual_nexthop(
+       struct vty *vty, const struct pbr_map_sequence *pbrms)
+{
+       struct pbr_nexthop_group_cache find;
+       struct pbr_nexthop_group_cache *pnhgc;
+       struct pbr_nexthop_cache lookup;
+       struct pbr_nexthop_cache *pnhc;
+
+       memset(&find, 0, sizeof(find));
+       strlcpy(find.name, pbrms->internal_nhg_name, sizeof(find.name));
+
+       pnhgc = hash_lookup(pbr_nhg_hash, &find);
+       assert(pnhgc);
+
+       lookup.nexthop = *pbrms->nhg->nexthop;
+       pnhc = hash_lookup(pnhgc->nhh, &lookup);
+
+       nexthop_group_write_nexthop_simple(
+               vty, pbrms->nhg->nexthop,
+               pnhc->nexthop.ifindex != 0 ? pnhc->intf_name : NULL);
+       if (pnhc->nexthop.vrf_id != VRF_DEFAULT)
+               vty_out(vty, " nexthop-vrf %s", pnhc->vrf_name);
+
+       vty_out(vty, "\n");
+}
+
 static void vty_show_pbrms(struct vty *vty,
                           const struct pbr_map_sequence *pbrms, bool detail)
 {
-       char buf[PREFIX_STRLEN];
        char rbuf[64];
 
        if (pbrms->reason)
@@ -639,11 +675,9 @@ static void vty_show_pbrms(struct vty *vty,
                        pbrms->reason ? rbuf : "Valid");
 
        if (pbrms->src)
-               vty_out(vty, "        SRC Match: %s\n",
-                       prefix2str(pbrms->src, buf, sizeof(buf)));
+               vty_out(vty, "        SRC Match: %pFX\n", pbrms->src);
        if (pbrms->dst)
-               vty_out(vty, "        DST Match: %s\n",
-                       prefix2str(pbrms->dst, buf, sizeof(buf)));
+               vty_out(vty, "        DST Match: %pFX\n", pbrms->dst);
        if (pbrms->dsfield & PBR_DSFIELD_DSCP)
                vty_out(vty, "        DSCP Match: %u\n",
                        (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2);
@@ -670,7 +704,7 @@ static void vty_show_pbrms(struct vty *vty,
 
        } else if (pbrms->nhg) {
                vty_out(vty, "        ");
-               nexthop_group_write_nexthop(vty, pbrms->nhg->nexthop);
+               pbrms_nexthop_group_write_individual_nexthop(vty, pbrms);
                if (detail)
                        vty_out(vty,
                                "          Installed: %u(%d) Tableid: %d\n",
@@ -883,16 +917,22 @@ DEFPY (show_pbr_interface,
                        if (j)
                                this_iface = json_object_new_object();
 
-                       if (!ifp->info)
+                       if (!ifp->info) {
+                               json_object_free(this_iface);
                                continue;
+                       }
 
-                       if (name && strcmp(ifp->name, name) != 0)
+                       if (name && strcmp(ifp->name, name) != 0) {
+                               json_object_free(this_iface);
                                continue;
+                       }
 
                        pbr_ifp = ifp->info;
 
-                       if (strcmp(pbr_ifp->mapname, "") == 0)
+                       if (strcmp(pbr_ifp->mapname, "") == 0) {
+                               json_object_free(this_iface);
                                continue;
+                       }
 
                        pbrm = pbrm_find(pbr_ifp->mapname);
 
@@ -1031,17 +1071,13 @@ static int pbr_vty_map_config_write_sequence(struct vty *vty,
                                             struct pbr_map *pbrm,
                                             struct pbr_map_sequence *pbrms)
 {
-       char buff[PREFIX_STRLEN];
-
        vty_out(vty, "pbr-map %s seq %u\n", pbrm->name, pbrms->seqno);
 
        if (pbrms->src)
-               vty_out(vty, " match src-ip %s\n",
-                       prefix2str(pbrms->src, buff, sizeof(buff)));
+               vty_out(vty, " match src-ip %pFX\n", pbrms->src);
 
        if (pbrms->dst)
-               vty_out(vty, " match dst-ip %s\n",
-                       prefix2str(pbrms->dst, buff, sizeof(buff)));
+               vty_out(vty, " match dst-ip %pFX\n", pbrms->dst);
 
        if (pbrms->dsfield & PBR_DSFIELD_DSCP)
                vty_out(vty, " match dscp %u\n",
@@ -1065,7 +1101,7 @@ static int pbr_vty_map_config_write_sequence(struct vty *vty,
 
        if (pbrms->nhg) {
                vty_out(vty, " set ");
-               nexthop_group_write_nexthop(vty, pbrms->nhg->nexthop);
+               pbrms_nexthop_group_write_individual_nexthop(vty, pbrms);
        }
 
        vty_out(vty, "!\n");
@@ -1118,9 +1154,9 @@ void pbr_vty_init(void)
 
        /* debug */
        install_node(&debug_node);
-       install_element(VIEW_NODE, &debug_pbr_cmd);
+       install_element(ENABLE_NODE, &debug_pbr_cmd);
        install_element(CONFIG_NODE, &debug_pbr_cmd);
-       install_element(VIEW_NODE, &show_debugging_pbr_cmd);
+       install_element(ENABLE_NODE, &show_debugging_pbr_cmd);
 
        install_default(PBRMAP_NODE);