]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Add autocomplete for as-path filters
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 19 Oct 2021 12:31:39 +0000 (15:31 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 19 Oct 2021 12:44:20 +0000 (15:44 +0300)
```
exit1-debian-9# show bgp as-path-access-list
  <cr>
  AS_PATH_FILTER_NAME  AS path access list name
     acl1 acl2
  json                 JavaScript Object Notation
exit1-debian-9(config)# route-map testas permit 10
exit1-debian-9(config-route-map)# match as-path ?
  AS_PATH_FILTER_NAME  AS path access-list name
     acl1 acl2
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_filter.c
bgpd/bgp_routemap.c

index 641cc7605fd17eb9524f217e249266b48cee3f00..7dda4f0180c56a92b7c187f28f3725b4ef702fcf 100644 (file)
@@ -440,7 +440,7 @@ bool config_bgp_aspath_validate(const char *regstr)
 }
 
 DEFUN(as_path, bgp_as_path_cmd,
-      "bgp as-path access-list WORD [seq (0-4294967295)] <deny|permit> LINE...",
+      "bgp as-path access-list AS_PATH_FILTER_NAME [seq (0-4294967295)] <deny|permit> LINE...",
       BGP_STR
       "BGP autonomous system path filter\n"
       "Specify an access list name\n"
@@ -460,7 +460,7 @@ DEFUN(as_path, bgp_as_path_cmd,
        int64_t seqnum = ASPATH_SEQ_NUMBER_AUTO;
 
        /* Retrieve access list name */
-       argv_find(argv, argc, "WORD", &idx);
+       argv_find(argv, argc, "AS_PATH_FILTER_NAME", &idx);
        char *alname = argv[idx]->arg;
 
        if (argv_find(argv, argc, "(0-4294967295)", &idx))
@@ -509,7 +509,7 @@ DEFUN(as_path, bgp_as_path_cmd,
 }
 
 DEFUN(no_as_path, no_bgp_as_path_cmd,
-      "no bgp as-path access-list WORD [seq (0-4294967295)] <deny|permit> LINE...",
+      "no bgp as-path access-list AS_PATH_FILTER_NAME [seq (0-4294967295)] <deny|permit> LINE...",
       NO_STR
       BGP_STR
       "BGP autonomous system path filter\n"
@@ -529,7 +529,7 @@ DEFUN(no_as_path, no_bgp_as_path_cmd,
        regex_t *regex;
 
        char *aslistname =
-               argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
+               argv_find(argv, argc, "AS_PATH_FILTER_NAME", &idx) ? argv[idx]->arg : NULL;
 
        /* Lookup AS list from AS path list. */
        aslist = as_list_lookup(aslistname);
@@ -586,7 +586,7 @@ DEFUN(no_as_path, no_bgp_as_path_cmd,
 
 DEFUN (no_as_path_all,
        no_bgp_as_path_all_cmd,
-       "no bgp as-path access-list WORD",
+       "no bgp as-path access-list AS_PATH_FILTER_NAME",
        NO_STR
        BGP_STR
        "BGP autonomous system path filter\n"
@@ -653,7 +653,7 @@ static void as_list_show_all(struct vty *vty, json_object *json)
 
 DEFUN (show_as_path_access_list,
        show_bgp_as_path_access_list_cmd,
-       "show bgp as-path-access-list WORD [json]",
+       "show bgp as-path-access-list AS_PATH_FILTER_NAME [json]",
        SHOW_STR
        BGP_STR
        "List AS path access lists\n"
@@ -684,7 +684,7 @@ DEFUN (show_as_path_access_list,
 
 ALIAS (show_as_path_access_list,
        show_ip_as_path_access_list_cmd,
-       "show ip as-path-access-list WORD [json]",
+       "show ip as-path-access-list AS_PATH_FILTER_NAME [json]",
        SHOW_STR
        IP_STR
        "List AS path access lists\n"
@@ -753,6 +753,20 @@ static struct cmd_node as_list_node = {
        .config_write = config_write_as_list,
 };
 
+static void bgp_aspath_filter_cmd_completion(vector comps,
+                                            struct cmd_token *token)
+{
+       struct as_list *aslist;
+
+       for (aslist = as_list_master.str.head; aslist; aslist = aslist->next)
+               vector_set(comps, XSTRDUP(MTYPE_COMPLETION, aslist->name));
+}
+
+static const struct cmd_variable_handler aspath_filter_handlers[] = {
+       {.tokenname = "AS_PATH_FILTER_NAME",
+        .completions = bgp_aspath_filter_cmd_completion},
+       {.completions = NULL}};
+
 /* Register functions. */
 void bgp_filter_init(void)
 {
@@ -766,6 +780,8 @@ void bgp_filter_init(void)
        install_element(VIEW_NODE, &show_ip_as_path_access_list_cmd);
        install_element(VIEW_NODE, &show_bgp_as_path_access_list_all_cmd);
        install_element(VIEW_NODE, &show_ip_as_path_access_list_all_cmd);
+
+       cmd_variable_handler_register(aspath_filter_handlers);
 }
 
 void bgp_filter_reset(void)
index 2f37367a8fba110e67ae4dfe479ebaf15354c22f..75dbc7f3e386f8b068236afc22b10c901a306bec 100644 (file)
@@ -4927,7 +4927,7 @@ DEFUN_YANG (no_match_ecommunity,
 
 DEFUN_YANG (match_aspath,
            match_aspath_cmd,
-           "match as-path WORD",
+           "match as-path AS_PATH_FILTER_NAME",
            MATCH_STR
            "Match BGP AS path list\n"
            "AS path access-list name\n")
@@ -4950,7 +4950,7 @@ DEFUN_YANG (match_aspath,
 
 DEFUN_YANG (no_match_aspath,
            no_match_aspath_cmd,
-           "no match as-path [WORD]",
+           "no match as-path [AS_PATH_FILTER_NAME]",
            NO_STR
            MATCH_STR
            "Match BGP AS path list\n"