]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_flowspec_vty.c
bgpd: Convert `struct bgp_info` to `struct bgp_path_info`
[mirror_frr.git] / bgpd / bgp_flowspec_vty.c
index c695e7f12509b22132eca3db7f94e32400ef2a55..293b9debb45cac8670393275edbd7bde9169fb2f 100644 (file)
@@ -253,8 +253,8 @@ void bgp_fs_nlri_get_string(unsigned char *nlri_content, size_t len,
 }
 
 void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
-                           struct bgp_info *binfo,
-                           int display, json_object *json_paths)
+                           struct bgp_path_info *binfo, int display,
+                           json_object *json_paths)
 {
        struct attr *attr;
        char return_string[BGP_FLOWSPEC_STRING_DISPLAY_MAX];
@@ -329,19 +329,35 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
                        json_object_array_add(json_paths, json_time_path);
        }
        if (display == NLRI_STRING_FORMAT_LARGE) {
-               struct bgp_info_extra *extra = bgp_info_extra_get(binfo);
+               struct bgp_path_info_extra *extra = bgp_info_extra_get(binfo);
 
                if (extra->bgp_fs_pbr) {
+                       struct listnode *node;
                        struct bgp_pbr_match_entry *bpme;
                        struct bgp_pbr_match *bpm;
+                       bool list_began = false;
+                       struct list *list_bpm;
 
-                       bpme = (struct bgp_pbr_match_entry *)extra->bgp_fs_pbr;
-                       bpm = bpme->backpointer;
-                       vty_out(vty, "\tinstalled in PBR");
-                       if (bpm)
-                               vty_out(vty, " (%s)\n", bpm->ipset_name);
-                       else
-                               vty_out(vty, "\n");
+                       list_bpm = list_new();
+                       if (listcount(extra->bgp_fs_pbr))
+                               vty_out(vty, "\tinstalled in PBR");
+                       for (ALL_LIST_ELEMENTS_RO(extra->bgp_fs_pbr,
+                                                 node, bpme)) {
+                               bpm = bpme->backpointer;
+                               if (listnode_lookup(list_bpm, bpm))
+                                       continue;
+                               listnode_add(list_bpm, bpm);
+                               if (!list_began) {
+                                       vty_out(vty, " (");
+                                       list_began = true;
+                               } else
+                                       vty_out(vty, ", ");
+                               vty_out(vty, "%s", bpm->ipset_name);
+                       }
+                       if (list_began)
+                               vty_out(vty, ")");
+                       vty_out(vty, "\n");
+                       list_delete(&list_bpm);
                } else
                        vty_out(vty, "\tnot installed in PBR\n");
        }
@@ -349,11 +365,10 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
 
 int bgp_show_table_flowspec(struct vty *vty, struct bgp *bgp, afi_t afi,
                            struct bgp_table *table, enum bgp_show_type type,
-                           void *output_arg, uint8_t use_json,
-                           int is_last, unsigned long *output_cum,
-                           unsigned long *total_cum)
+                           void *output_arg, bool use_json, int is_last,
+                           unsigned long *output_cum, unsigned long *total_cum)
 {
-       struct bgp_info *ri;
+       struct bgp_path_info *ri;
        struct bgp_node *rn;
        unsigned long total_count = 0;
        json_object *json_paths = NULL;
@@ -444,8 +459,6 @@ int bgp_fs_config_write_pbr(struct vty *vty, struct bgp *bgp,
        RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) {
                vty_out(vty, "  local-install %s\n", pbr_if->name);
        }
-       if (!bgp_pbr_interface_any)
-               vty_out(vty, "  no local-install any\n");
        return declare_node ? 1 : 0;
 }
 
@@ -506,24 +519,39 @@ DEFUN (bgp_fs_local_install_ifname,
 {
        struct bgp *bgp = VTY_GET_CONTEXT(bgp);
        int idx = 0;
-       const char *no = strmatch(argv[0]->text, (char *)"no") ? "no" : NULL;
+       const char *no = strmatch(argv[0]->text, "no") ? "no" : NULL;
        char *ifname = argv_find(argv, argc, "INTERFACE", &idx) ?
                argv[idx]->arg : NULL;
 
        return bgp_fs_local_install_interface(bgp, no, ifname);
 }
 
-DEFUN (bgp_fs_local_install_any,
-       bgp_fs_local_install_any_cmd,
-       "[no] local-install any",
-       NO_STR
-       "Apply local policy routing\n"
-       "Any Interface\n")
+extern int bgp_flowspec_display_match_per_ip(afi_t afi, struct bgp_table *rib,
+                                            struct prefix *match,
+                                            int prefix_check, struct vty *vty,
+                                            bool use_json,
+                                            json_object *json_paths)
 {
-       struct bgp *bgp = VTY_GET_CONTEXT(bgp);
-       const char *no = strmatch(argv[0]->text, (char *)"no") ? "no" : NULL;
+       struct bgp_node *rn;
+       struct prefix *prefix;
+       int display = 0;
+
+       for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
+               prefix = &rn->p;
 
-       return bgp_fs_local_install_interface(bgp, no, NULL);
+               if (prefix->family != AF_FLOWSPEC)
+                       continue;
+
+               if (bgp_flowspec_contains_prefix(prefix, match, prefix_check)) {
+                       route_vty_out_flowspec(vty, &rn->p,
+                                              rn->info, use_json ?
+                                              NLRI_STRING_FORMAT_JSON :
+                                              NLRI_STRING_FORMAT_LARGE,
+                                              json_paths);
+                       display++;
+               }
+       }
+       return display;
 }
 
 void bgp_flowspec_vty_init(void)
@@ -532,6 +560,5 @@ void bgp_flowspec_vty_init(void)
        install_element(CONFIG_NODE, &debug_bgp_flowspec_cmd);
        install_element(ENABLE_NODE, &no_debug_bgp_flowspec_cmd);
        install_element(CONFIG_NODE, &no_debug_bgp_flowspec_cmd);
-       install_element(BGP_FLOWSPECV4_NODE, &bgp_fs_local_install_any_cmd);
        install_element(BGP_FLOWSPECV4_NODE, &bgp_fs_local_install_ifname_cmd);
 }