]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_vty.c
ospfd: use ospf_get_name() wherever possible
[mirror_frr.git] / ospfd / ospf_vty.c
index 715aa896af446af9ba6c3036fabafe3d8dc45116..84aa4afe97d960823657fec797e3db6fb6df6fe4 100644 (file)
@@ -178,19 +178,11 @@ static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
 {
        if (use_vrf) {
                if (json) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_string_add(json, "vrfName",
-                                                      "default");
-                       else
-                               json_object_string_add(json, "vrfName",
-                                                      ospf->name);
+                       json_object_string_add(json, "vrfName",
+                                              ospf_get_name(ospf));
                        json_object_int_add(json, "vrfId", ospf->vrf_id);
-               } else {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               vty_out(vty, "VRF Name: %s\n", "default");
-                       else if (ospf->name)
-                               vty_out(vty, "VRF Name: %s\n", ospf->name);
-               }
+               } else
+                       vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf));
        }
 }
 
@@ -230,8 +222,8 @@ DEFUN_NOSH (router_ospf,
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug(
                        "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
-                       ospf->instance, ospf->name ? ospf->name : "NIL",
-                       ospf->vrf_id, ospf->oi_running);
+                       ospf->instance, ospf_get_name(ospf), ospf->vrf_id,
+                       ospf->oi_running);
 
        VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
 
@@ -571,8 +563,7 @@ DEFUN (ospf_network_area,
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
                                "%s ospf vrf %s num of %u ip ospf area x config",
-                               __func__, ospf->name ? ospf->name : "NIL",
-                               count);
+                               __func__, ospf_get_name(ospf), count);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
@@ -3343,12 +3334,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
        if (json) {
                if (use_vrf) {
                        json_object_object_add(json_vrf, "areas", json_areas);
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
                } else {
                        json_object_object_add(json, "areas", json_areas);
                }
@@ -3970,12 +3957,8 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
 
        if (use_json) {
                if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
                }
        } else
                vty_out(vty, "\n");
@@ -4115,14 +4098,9 @@ static int show_ip_ospf_interface_traffic_common(
        }
 
        if (use_json) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -4519,14 +4497,9 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
 
        if (use_json) {
                json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -4682,7 +4655,6 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
                        json_vrf = json_object_new_object();
                else
                        json_vrf = json;
-               json_neighbor_sub = json_object_new_object();
        }
 
        ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
@@ -4708,6 +4680,8 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
                        if (nbr_nbma->nbr == NULL
                            || nbr_nbma->nbr->state == NSM_Down) {
                                if (use_json) {
+                                       json_neighbor_sub =
+                                               json_object_new_object();
                                        json_object_int_add(json_neighbor_sub,
                                                            "nbrNbmaPriority",
                                                            nbr_nbma->priority);
@@ -4747,14 +4721,9 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
        }
 
        if (use_json) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -5540,14 +5509,9 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
        if (use_json) {
                json_object_object_add(json_vrf, "neighbors",
                                       json_nbr_sub);
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -5731,14 +5695,9 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
        }
 
        if (use_json) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else {
                vty_out(vty, "\n");
        }
@@ -7048,14 +7007,9 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
        if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
                show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
                if (json) {
-                       if (use_vrf) {
-                               if (ospf->vrf_id == VRF_DEFAULT)
-                                       json_object_object_add(json, "default",
-                                                              json_vrf);
-                               else
-                                       json_object_object_add(json, ospf->name,
-                                                              json_vrf);
-                       }
+                       if (use_vrf)
+                               json_object_object_add(
+                                       json, ospf_get_name(ospf), json_vrf);
                }
                return CMD_SUCCESS;
        }
@@ -7076,27 +7030,17 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
        else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
                show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
                if (json) {
-                       if (use_vrf) {
-                               if (ospf->vrf_id == VRF_DEFAULT)
-                                       json_object_object_add(json, "default",
-                                                              json_vrf);
-                               else
-                                       json_object_object_add(json, ospf->name,
-                                                              json_vrf);
-                       }
+                       if (use_vrf)
+                               json_object_object_add(
+                                       json, ospf_get_name(ospf), json_vrf);
                }
                return CMD_SUCCESS;
        } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
                show_ip_ospf_database_maxage(vty, ospf, json_vrf);
                if (json) {
-                       if (use_vrf) {
-                               if (ospf->vrf_id == VRF_DEFAULT)
-                                       json_object_object_add(json, "default",
-                                                              json_vrf);
-                               else
-                                       json_object_object_add(json, ospf->name,
-                                                              json_vrf);
-                       }
+                       if (use_vrf)
+                               json_object_object_add(
+                                       json, ospf_get_name(ospf), json_vrf);
                }
                return CMD_SUCCESS;
        } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
@@ -7136,14 +7080,9 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
        }
 
        if (json) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        }
 
        return CMD_SUCCESS;
@@ -7372,14 +7311,9 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
        show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
 
        if (json) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        }
 
        return CMD_SUCCESS;
@@ -9893,24 +9827,17 @@ DEFUN (no_ospf_proactive_arp,
 
 /* Graceful Restart HELPER Commands */
 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
-      "graceful-restart helper-only [A.B.C.D]",
+      "graceful-restart helper enable [A.B.C.D$address]",
       "OSPF Graceful Restart\n"
+      "OSPF GR Helper\n"
       "Enable Helper support\n"
-      "Advertising router id\n")
+      "Advertising Router-ID\n")
 {
        VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
-       struct in_addr addr;
-       int ret;
-
-       if (argc == 3) {
-               ret = inet_aton(argv[2]->arg, &addr);
-               if (!ret) {
-                       vty_out(vty,
-                               "Please specify the valid routerid address.\n");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
 
-               ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE);
+       if (address_str) {
+               ospf_gr_helper_support_set_per_routerid(ospf, &address,
+                                                       OSPF_GR_TRUE);
                return CMD_SUCCESS;
        }
 
@@ -9921,33 +9848,68 @@ DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
 
 DEFPY(no_ospf_gr_helper_enable,
       no_ospf_gr_helper_enable_cmd,
-      "no graceful-restart helper-only [A.B.C.D]",
+      "no graceful-restart helper enable [A.B.C.D$address]",
       NO_STR
       "OSPF Graceful Restart\n"
-      "Disable Helper support\n"
+      "OSPF GR Helper\n"
+      "Enable Helper support\n"
+      "Advertising Router-ID\n")
+{
+       VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+
+       if (address_str) {
+               ospf_gr_helper_support_set_per_routerid(ospf, &address,
+                                                       OSPF_GR_FALSE);
+               return CMD_SUCCESS;
+       }
+
+       ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
+       return CMD_SUCCESS;
+}
+
+#if CONFDATE > 20220921
+CPP_NOTICE(
+       "Time to remove the deprecated \"[no] graceful-restart helper-only\" commands")
+#endif
+
+DEFPY_HIDDEN(ospf_gr_helper_only, ospf_gr_helper_only_cmd,
+      "graceful-restart helper-only [A.B.C.D]",
+      "OSPF Graceful Restart\n"
+      "Enable Helper support\n"
       "Advertising router id\n")
 {
        VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
        struct in_addr addr;
        int ret;
 
-       if (argc == 4) {
-               ret = inet_aton(argv[3]->arg, &addr);
+       vty_out(vty,
+               "%% This command is deprecated. Please, use `graceful-restart helper enable` instead.\n");
+
+       if (argc == 3) {
+               ret = inet_aton(argv[2]->arg, &addr);
                if (!ret) {
                        vty_out(vty,
                                "Please specify the valid routerid address.\n");
                        return CMD_WARNING_CONFIG_FAILED;
                }
 
-               ospf_gr_helper_support_set_per_routerid(ospf, &addr,
-                                                       OSPF_GR_FALSE);
+               ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE);
                return CMD_SUCCESS;
        }
 
-       ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
+       ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
+
        return CMD_SUCCESS;
 }
 
+ALIAS_HIDDEN(no_ospf_gr_helper_enable,
+      no_ospf_gr_helper_only_cmd,
+      "no graceful-restart helper-only [A.B.C.D]",
+      NO_STR
+      "OSPF Graceful Restart\n"
+      "Disable Helper support\n"
+      "Advertising router id\n")
+
 DEFPY(ospf_gr_helper_enable_lsacheck,
       ospf_gr_helper_enable_lsacheck_cmd,
       "graceful-restart helper strict-lsa-checking",
@@ -10158,14 +10120,9 @@ static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
        ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
 
        if (uj) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -10606,11 +10563,9 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
 
                prefix2str(&rn->p, buf1, sizeof(buf1));
 
-               json_route = json_object_new_object();
                if (json) {
+                       json_route = json_object_new_object();
                        json_object_object_add(json, buf1, json_route);
-                       json_object_to_json_string_ext(
-                               json, JSON_C_TO_STRING_NOSLASHESCAPE);
                }
 
                switch (or->path_type) {
@@ -10732,8 +10687,6 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
                                }
                        }
                }
-               if (!json)
-                       json_object_free(json_route);
        }
        if (!json)
                vty_out(vty, "\n");
@@ -10761,8 +10714,8 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
                        continue;
                int flag = 0;
 
-               json_route = json_object_new_object();
                if (json) {
+                       json_route = json_object_new_object();
                        json_object_object_add(
                                json, inet_ntop(AF_INET, &rn->p.u.prefix4,
                                                buf, sizeof(buf)),
@@ -10877,8 +10830,6 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
                                }
                        }
                }
-               if (!json)
-                       json_object_free(json_route);
        }
        if (!json)
                vty_out(vty, "\n");
@@ -10907,11 +10858,9 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
                char buf1[19];
 
                snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
-               json_route = json_object_new_object();
                if (json) {
+                       json_route = json_object_new_object();
                        json_object_object_add(json, buf1, json_route);
-                       json_object_to_json_string_ext(
-                               json, JSON_C_TO_STRING_NOSLASHESCAPE);
                }
 
                switch (er->path_type) {
@@ -11009,8 +10958,6 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
                                }
                        }
                }
-               if (!json)
-                       json_object_free(json_route);
        }
        if (!json)
                vty_out(vty, "\n");
@@ -11164,12 +11111,8 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
                if (use_vrf) {
                        // json_object_object_add(json_vrf, "areas",
                        // json_areas);
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
                }
        } else {
                vty_out(vty, "\n");
@@ -11223,7 +11166,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                /* Keep Non-pretty format */
                                vty_out(vty, "%s\n",
-                                       json_object_to_json_string(json));
+                                       json_object_to_json_string_ext(
+                                               json,
+                                               JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else if (!ospf_output)
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11235,7 +11180,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                vty_out(vty, "%s\n",
                                        json_object_to_json_string_ext(
-                                               json, JSON_C_TO_STRING_PRETTY));
+                                               json,
+                                               JSON_C_TO_STRING_PRETTY
+                                                       | JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11249,7 +11196,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                vty_out(vty, "%s\n",
                                        json_object_to_json_string_ext(
-                                               json, JSON_C_TO_STRING_PRETTY));
+                                               json,
+                                               JSON_C_TO_STRING_PRETTY
+                                                       | JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11262,7 +11211,9 @@ DEFUN (show_ip_ospf_route,
                ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
                /* Keep Non-pretty format */
                if (uj)
-                       vty_out(vty, "%s\n", json_object_to_json_string(json));
+                       vty_out(vty, "%s\n",
+                               json_object_to_json_string_ext(
+                                       json, JSON_C_TO_STRING_NOSLASHESCAPE));
        }
 
        if (uj)
@@ -11331,10 +11282,7 @@ DEFUN (show_ip_ospf_vrfs,
                if (uj)
                        json_vrf = json_object_new_object();
 
-               if (ospf->vrf_id == VRF_DEFAULT)
-                       name = VRF_DEFAULT_NAME;
-               else
-                       name = ospf->name;
+               name = ospf_get_name(ospf);
 
                vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
                                    ? -1
@@ -11596,14 +11544,9 @@ static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
                }
 
        if (uj) {
-               if (use_vrf) {
-                       if (ospf->vrf_id == VRF_DEFAULT)
-                               json_object_object_add(json, "default",
-                                                      json_vrf);
-                       else
-                               json_object_object_add(json, ospf->name,
-                                                      json_vrf);
-               }
+               if (use_vrf)
+                       json_object_object_add(json, ospf_get_name(ospf),
+                                              json_vrf);
        } else
                vty_out(vty, "\n");
 
@@ -11845,9 +11788,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
 
                        /* Router Dead Interval print. */
                        if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
-                           && params->is_v_wait_set
-                           && params->v_wait
-                                      != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) {
+                           && params->is_v_wait_set) {
                                vty_out(vty, " ip ospf dead-interval ");
 
                                /* fast hello ? */
@@ -12262,7 +12203,7 @@ static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
        struct advRtr *rtr = bucket->data;
        struct vty *vty = (struct vty *)arg;
 
-       vty_out(vty, " graceful-restart helper-only %pI4\n",
+       vty_out(vty, " graceful-restart helper enable %pI4\n",
                &rtr->advRtrAddr);
        return HASHWALK_CONTINUE;
 }
@@ -12282,7 +12223,7 @@ static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
 {
        if (ospf->is_helper_supported)
-               vty_out(vty, " graceful-restart helper-only\n");
+               vty_out(vty, " graceful-restart helper enable\n");
 
        if (!ospf->strict_lsa_check)
                vty_out(vty,
@@ -12745,6 +12686,8 @@ static void ospf_vty_zebra_init(void)
        /*Ospf garcefull restart helper configurations */
        install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
        install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
+       install_element(OSPF_NODE, &ospf_gr_helper_only_cmd);
+       install_element(OSPF_NODE, &no_ospf_gr_helper_only_cmd);
        install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
        install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
        install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);