]> 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 5350ebeec7c7a13cf2dcd3b2f28d07da509486c9..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");
@@ -771,19 +790,23 @@ static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
 /* clear soft inbound */
 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
 {
-       bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
-                     BGP_CLEAR_SOFT_IN, NULL);
-       bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
-                     BGP_CLEAR_SOFT_IN, NULL);
+       afi_t afi;
+       safi_t safi;
+
+       FOREACH_AFI_SAFI (afi, safi)
+               bgp_clear_vty(vty, name, afi, safi, clear_all,
+                             BGP_CLEAR_SOFT_IN, NULL);
 }
 
 /* clear soft outbound */
 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
 {
-       bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
-                     BGP_CLEAR_SOFT_OUT, NULL);
-       bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
-                     BGP_CLEAR_SOFT_OUT, NULL);
+       afi_t afi;
+       safi_t safi;
+
+       FOREACH_AFI_SAFI (afi, safi)
+               bgp_clear_vty(vty, name, afi, safi, clear_all,
+                             BGP_CLEAR_SOFT_OUT, NULL);
 }
 
 
@@ -2625,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"
@@ -2643,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. */
@@ -2695,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"
@@ -2995,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"
@@ -3016,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"
@@ -3161,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"
@@ -3476,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"
@@ -3534,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
@@ -3571,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")
@@ -3939,6 +3962,13 @@ ALIAS_HIDDEN(neighbor_nexthop_self_force,
             "Disable the next hop calculation for this neighbor\n"
             "Set the next hop to self for reflected routes\n")
 
+ALIAS_HIDDEN(neighbor_nexthop_self_force,
+            neighbor_nexthop_self_all_hidden_cmd,
+            "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
+            NEIGHBOR_STR NEIGHBOR_ADDR_STR2
+            "Disable the next hop calculation for this neighbor\n"
+            "Set the next hop to self for reflected routes\n")
+
 DEFUN (no_neighbor_nexthop_self,
        no_neighbor_nexthop_self_cmd,
        "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
@@ -3980,6 +4010,13 @@ ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
             "Disable the next hop calculation for this neighbor\n"
             "Set the next hop to self for reflected routes\n")
 
+ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
+            no_neighbor_nexthop_self_all_hidden_cmd,
+            "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
+            NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
+            "Disable the next hop calculation for this neighbor\n"
+            "Set the next hop to self for reflected routes\n")
+
 /* neighbor as-override */
 DEFUN (neighbor_as_override,
        neighbor_as_override_cmd,
@@ -4859,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
@@ -7250,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
@@ -7303,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)) {
@@ -7316,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)) {
@@ -13230,22 +13268,48 @@ void bgp_vty_init(void)
        /* "neighbor next-hop-self force" commands. */
        install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
        install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
+       install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
+       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);
@@ -14931,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);