]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_vty.c
bgpd: `neighbor X:X::X default-originate` complains about (null)
[mirror_frr.git] / bgpd / bgp_vty.c
index 01144f5c78ae94346297540e51ed5a1972b89a87..d05432327d770d5efd52eebc7f5d3cf1e04f111e 100644 (file)
@@ -295,6 +295,7 @@ int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
  * afi  -> The parsed afi if it was included in the show command, returned here
  * safi -> The parsed safi if it was included in the show command, returned here
  * bgp  -> Pointer to the bgp data structure we need to fill in.
+ * use_json -> json is configured or not
  *
  * The function returns the correct location in the parse tree for the
  * last token found.
@@ -329,8 +330,17 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
                else {
                        *bgp = bgp_lookup_by_name(vrf_name);
                        if (!*bgp) {
-                               if (use_json)
-                                       vty_out(vty, "{}\n");
+                               if (use_json) {
+                                       json_object *json = NULL;
+                                       json = json_object_new_object();
+                                       json_object_string_add(
+                                         json, "warning",
+                                         "View/Vrf is unknown");
+                                       vty_out(vty, "%s\n",
+                                               json_object_to_json_string_ext(json,
+                                                       JSON_C_TO_STRING_PRETTY));
+                                       json_object_free(json);
+                               }
                                else
                                        vty_out(vty, "View/Vrf %s is unknown\n",
                                                vrf_name);
@@ -341,8 +351,17 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
        } else {
                *bgp = bgp_get_default();
                if (!*bgp) {
-                       if (use_json)
-                               vty_out(vty, "{}\n");
+                       if (use_json) {
+                               json_object *json = NULL;
+                               json = json_object_new_object();
+                               json_object_string_add(
+                                       json, "warning",
+                                       "Default BGP instance not found");
+                               vty_out(vty, "%s\n",
+                                       json_object_to_json_string_ext(json,
+                                               JSON_C_TO_STRING_PRETTY));
+                               json_object_free(json);
+                       }
                        else
                                vty_out(vty,
                                        "Default BGP instance not found\n");
@@ -2629,7 +2648,7 @@ static struct peer_group *listen_range_exists(struct bgp *bgp,
 
 DEFUN (bgp_listen_range,
        bgp_listen_range_cmd,
-       "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
+       "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
        "BGP specific commands\n"
        "Configure BGP dynamic neighbors listen range\n"
        "Configure BGP dynamic neighbors listen range\n"
@@ -2647,7 +2666,7 @@ DEFUN (bgp_listen_range,
        argv_find(argv, argc, "A.B.C.D/M", &idx);
        argv_find(argv, argc, "X:X::X:X/M", &idx);
        char *prefix = argv[idx]->arg;
-       argv_find(argv, argc, "WORD", &idx);
+       argv_find(argv, argc, "PGNAME", &idx);
        char *peergroup = argv[idx]->arg;
 
        /* Convert IP prefix string to struct prefix. */
@@ -2699,7 +2718,7 @@ DEFUN (bgp_listen_range,
 
 DEFUN (no_bgp_listen_range,
        no_bgp_listen_range_cmd,
-       "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
+       "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
        NO_STR
        "BGP specific commands\n"
        "Unconfigure BGP dynamic neighbors listen range\n"
@@ -2999,7 +3018,7 @@ static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
 
 DEFUN (neighbor_interface_config,
        neighbor_interface_config_cmd,
-       "neighbor WORD interface [peer-group WORD]",
+       "neighbor WORD interface [peer-group PGNAME]",
        NEIGHBOR_STR
        "Interface name or neighbor tag\n"
        "Enable BGP on interface\n"
@@ -3020,7 +3039,7 @@ DEFUN (neighbor_interface_config,
 
 DEFUN (neighbor_interface_config_v6only,
        neighbor_interface_config_v6only_cmd,
-       "neighbor WORD interface v6only [peer-group WORD]",
+       "neighbor WORD interface v6only [peer-group PGNAME]",
        NEIGHBOR_STR
        "Interface name or neighbor tag\n"
        "Enable BGP on interface\n"
@@ -3165,7 +3184,7 @@ DEFUN (no_neighbor,
 
 DEFUN (no_neighbor_interface_config,
        no_neighbor_interface_config_cmd,
-       "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
+       "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
        NO_STR
        NEIGHBOR_STR
        "Interface name\n"
@@ -3480,7 +3499,7 @@ ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
 
 DEFUN (neighbor_set_peer_group,
        neighbor_set_peer_group_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Member of the peer-group\n"
@@ -3538,14 +3557,14 @@ DEFUN (neighbor_set_peer_group,
 }
 
 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
-            "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
+            "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
             NEIGHBOR_STR NEIGHBOR_ADDR_STR2
             "Member of the peer-group\n"
             "Peer-group name\n")
 
 DEFUN (no_neighbor_set_peer_group,
        no_neighbor_set_peer_group_cmd,
-       "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
+       "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
        NO_STR
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
@@ -3575,7 +3594,7 @@ DEFUN (no_neighbor_set_peer_group,
 }
 
 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
-            "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
+            "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
             NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
             "Member of the peer-group\n"
             "Peer-group name\n")
@@ -4877,14 +4896,15 @@ static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
 {
        int ret;
        struct peer *peer;
-       struct route_map *route_map;
+       struct route_map *route_map = NULL;
 
        peer = peer_and_group_lookup_vty(vty, peer_str);
        if (!peer)
                return CMD_WARNING_CONFIG_FAILED;
 
        if (set) {
-               route_map = route_map_lookup_warn_noexist(vty, rmap);
+               if (rmap)
+                       route_map = route_map_lookup_warn_noexist(vty, rmap);
                ret = peer_default_originate_set(peer, afi, safi,
                                                 rmap, route_map);
        } else
@@ -7268,7 +7288,7 @@ static int bgp_clear_prefix(struct vty *vty, const char *view_name,
 /* one clear bgp command to rule them all */
 DEFUN (clear_ip_bgp_all,
        clear_ip_bgp_all_cmd,
-       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
+       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -7321,7 +7341,7 @@ DEFUN (clear_ip_bgp_all,
        if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
                argv_find_and_parse_safi(argv, argc, &idx, &safi);
 
-       /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
+       /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
        if (argv_find(argv, argc, "*", &idx)) {
                clr_sort = clear_all;
        } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
@@ -7334,7 +7354,7 @@ DEFUN (clear_ip_bgp_all,
                clr_sort = clear_group;
                idx++;
                clr_arg = argv[idx]->arg;
-       } else if (argv_find(argv, argc, "WORD", &idx)) {
+       } else if (argv_find(argv, argc, "PGNAME", &idx)) {
                clr_sort = clear_peer;
                clr_arg = argv[idx]->arg;
        } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
@@ -13252,20 +13272,44 @@ void bgp_vty_init(void)
        install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV4_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV4M_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV4L_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV6_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV6M_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_IPV6L_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_VPNV4_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
        install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
        install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
+       install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       install_element(BGP_VPNV6_NODE,
+                       &no_neighbor_nexthop_self_all_hidden_cmd);
 
        /* "neighbor as-override" commands. */
        install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
@@ -14951,14 +14995,16 @@ static void lcommunity_list_show(struct vty *vty, struct community_list *list)
                if (entry == list->head) {
                        if (all_digit(list->name))
                                vty_out(vty, "Large community %s list %s\n",
-                                       entry->style == EXTCOMMUNITY_LIST_STANDARD
+                                       entry->style ==
+                                               LARGE_COMMUNITY_LIST_STANDARD
                                                ? "standard"
                                                : "(expanded) access",
                                        list->name);
                        else
                                vty_out(vty,
                                        "Named large community %s list %s\n",
-                                       entry->style == EXTCOMMUNITY_LIST_STANDARD
+                                       entry->style ==
+                                               LARGE_COMMUNITY_LIST_STANDARD
                                                ? "standard"
                                                : "expanded",
                                        list->name);