]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_vty.c
*: s/TRUE/true/, s/FALSE/false/
[mirror_frr.git] / ospfd / ospf_vty.c
index 652c47387ac8d08032f1dba1633250e43315162d..dfa34f15efa47d25a789eaf3ed94bfd8a9580197 100644 (file)
@@ -245,8 +245,11 @@ DEFUN_NOSH (router_ospf,
                                                return ret;
                                        }
                                }
-                               ospf_interface_area_set(ospf, ifp);
-                               ospf->if_ospf_cli_count++;
+                               if (!ospf_interface_area_is_already_set(ospf,
+                                                                       ifp)) {
+                                       ospf_interface_area_set(ospf, ifp);
+                                       ospf->if_ospf_cli_count++;
+                               }
                        }
                }
 
@@ -460,7 +463,7 @@ DEFUN (ospf_passive_interface,
                return CMD_SUCCESS;
        }
        if (ospf->vrf_id != VRF_UNKNOWN)
-               ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0);
+               ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
 
        if (ifp == NULL) {
                vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
@@ -533,7 +536,7 @@ DEFUN (no_ospf_passive_interface,
        }
 
        if (ospf->vrf_id != VRF_UNKNOWN)
-               ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0);
+               ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
 
        if (ifp == NULL) {
                vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
@@ -951,8 +954,9 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
        if (vl_config->auth_key) {
                memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
                       OSPF_AUTH_SIMPLE_SIZE + 1);
-               strncpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
-                       vl_config->auth_key, OSPF_AUTH_SIMPLE_SIZE);
+               strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
+                       vl_config->auth_key,
+                       sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
        } else if (vl_config->md5_key) {
                if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
                                          vl_config->crypto_key_id)
@@ -964,8 +968,8 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
                ck = ospf_crypt_key_new();
                ck->key_id = vl_config->crypto_key_id;
                memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
-               strncpy((char *)ck->auth_key, vl_config->md5_key,
-                       OSPF_AUTH_MD5_SIZE);
+               strlcpy((char *)ck->auth_key, vl_config->md5_key,
+                       sizeof(ck->auth_key));
 
                ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
        } else if (vl_config->crypto_key_id != 0) {
@@ -1144,14 +1148,12 @@ DEFUN (ospf_area_vlink,
                if (vl_config.crypto_key_id < 0)
                        return CMD_WARNING_CONFIG_FAILED;
 
-               memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1);
-               strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE);
+               strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key));
                vl_config.md5_key = md5_key;
        }
 
        if (argv_find(argv, argc, "authentication-key", &idx)) {
-               memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
-               strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE);
+               strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key));
                vl_config.auth_key = auth_key;
        }
 
@@ -1202,14 +1204,17 @@ DEFUN (no_ospf_area_vlink,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer);
+       if (!vl_data) {
+               vty_out(vty, "Virtual link does not exist\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        if (argc <= 5) {
                /* Basic VLink no command */
                /* Thats all folks! - BUGS B. strikes again!!!*/
-               if ((vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer)))
-                       ospf_vl_delete(ospf, vl_data);
-
+               ospf_vl_delete(ospf, vl_data);
                ospf_area_check_free(ospf, vl_config.area_id);
-
                return CMD_SUCCESS;
        }
 
@@ -3024,13 +3029,13 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
                        if (ospf->stub_router_startup_time
                            != OSPF_STUB_ROUTER_UNCONFIGURED)
                                json_object_int_add(
-                                       json_vrf, "postStartEnabledMsecs",
-                                       ospf->stub_router_startup_time / 1000);
+                                       json_vrf, "postStartEnabledSecs",
+                                       ospf->stub_router_startup_time);
                        if (ospf->stub_router_shutdown_time
                            != OSPF_STUB_ROUTER_UNCONFIGURED)
                                json_object_int_add(
-                                       json_vrf, "preShutdownEnabledMsecs",
-                                       ospf->stub_router_shutdown_time / 1000);
+                                       json_vrf, "preShutdownEnabledSecs",
+                                       ospf->stub_router_shutdown_time);
                } else {
                        vty_out(vty,
                                " Stub router advertisement is configured\n");
@@ -3247,7 +3252,7 @@ DEFUN (show_ip_ospf,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -3264,7 +3269,7 @@ DEFUN (show_ip_ospf,
 
        /* vrf input is provided could be all or specific vrf*/
        if (vrf_name) {
-               bool ospf_output = FALSE;
+               bool ospf_output = false;
 
                use_vrf = 1;
 
@@ -3272,7 +3277,7 @@ DEFUN (show_ip_ospf,
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
-                               ospf_output = TRUE;
+                               ospf_output = true;
                                ret = show_ip_ospf_common(vty, ospf, json,
                                                          use_vrf);
                        }
@@ -3506,8 +3511,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
                        json_object_int_add(json_interface_sub, "cost",
                                            oi->output_cost);
                        json_object_int_add(
-                               json_interface_sub, "transmitDelayMsecs",
-                               1000 / OSPF_IF_PARAM(oi, transmit_delay));
+                               json_interface_sub, "transmitDelaySecs",
+                               OSPF_IF_PARAM(oi, transmit_delay));
                        json_object_string_add(json_interface_sub, "state",
                                               lookup_msg(ospf_ism_state_msg,
                                                          oi->state, NULL));
@@ -3611,20 +3616,20 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
                        if (OSPF_IF_PARAM(oi, fast_hello) == 0)
                                json_object_int_add(
                                        json_interface_sub, "timerMsecs",
-                                       1000 / OSPF_IF_PARAM(oi, v_hello));
+                                       OSPF_IF_PARAM(oi, v_hello) * 1000);
                        else
                                json_object_int_add(
                                        json_interface_sub, "timerMsecs",
                                        1000 / OSPF_IF_PARAM(oi, fast_hello));
                        json_object_int_add(json_interface_sub,
-                                           "timerDeadMsecs",
-                                           1000 / OSPF_IF_PARAM(oi, v_wait));
+                                           "timerDeadSecs",
+                                           OSPF_IF_PARAM(oi, v_wait));
                        json_object_int_add(json_interface_sub,
-                                           "timerWaitMsecs",
-                                           1000 / OSPF_IF_PARAM(oi, v_wait));
+                                           "timerWaitSecs",
+                                           OSPF_IF_PARAM(oi, v_wait));
                        json_object_int_add(
-                               json_interface_sub, "timerRetransmit",
-                               1000 / OSPF_IF_PARAM(oi, retransmit_interval));
+                               json_interface_sub, "timerRetransmitSecs",
+                               OSPF_IF_PARAM(oi, retransmit_interval));
                } else {
                        vty_out(vty, "  Timer intervals configured,");
                        vty_out(vty, " Hello ");
@@ -3937,7 +3942,7 @@ DEFUN (show_ip_ospf_interface,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL, *intf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0, idx_intf = 0;
@@ -4077,7 +4082,7 @@ DEFUN (show_ip_ospf_interface_traffic,
        struct ospf *ospf = NULL;
        struct listnode *node = NULL;
        char *vrf_name = NULL, *intf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int inst = 0;
        int idx_vrf = 0, idx_intf = 0;
        bool uj = use_json(argc, argv);
@@ -4332,7 +4337,7 @@ DEFUN (show_ip_ospf_neighbor,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -4558,7 +4563,7 @@ DEFUN (show_ip_ospf_neighbor_all,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -4684,7 +4689,7 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
 
        ospf_show_vrf_name(ospf, vty, json, use_vrf);
 
-       ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
+       ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
        if (!ifp) {
                if (use_json)
                        json_object_boolean_true_add(json, "noSuchIface");
@@ -4714,34 +4719,50 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
 
 DEFUN (show_ip_ospf_neighbor_int,
        show_ip_ospf_neighbor_int_cmd,
-       "show ip ospf neighbor IFNAME [json]",
+       "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
        SHOW_STR
        IP_STR
        "OSPF information\n"
+       VRF_CMD_HELP_STR
        "Neighbor list\n"
        "Interface name\n"
        JSON_STR)
 {
        struct ospf *ospf;
-       int idx_ifname = 4;
+       int idx_ifname = 0;
+       int idx_vrf = 0;
        bool uj = use_json(argc, argv);
-       struct listnode *node = NULL;
        int ret = CMD_SUCCESS;
        struct interface *ifp = NULL;
+       char *vrf_name = NULL;
+       vrf_id_t vrf_id = VRF_DEFAULT;
+       struct vrf *vrf = NULL;
+
+       if (argv_find(argv, argc, "vrf", &idx_vrf))
+               vrf_name = argv[idx_vrf + 1]->arg;
+       if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
+               vrf_name = NULL;
+       if (vrf_name) {
+               vrf = vrf_lookup_by_name(vrf_name);
+               if (vrf)
+                       vrf_id = vrf->vrf_id;
+       }
+       ospf = ospf_lookup_by_vrf_id(vrf_id);
+
+       if (!ospf || !ospf->oi_running)
+               return ret;
 
        if (!uj)
                show_ip_ospf_neighbour_header(vty);
 
-       ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
-       for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
-               if (!ospf->oi_running)
-                       continue;
-               if (!ifp || ifp->vrf_id != ospf->vrf_id)
-                       continue;
-               ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
-                                                      argv, uj, 0);
-       }
+       argv_find(argv, argc, "IFNAME", &idx_ifname);
+
+       ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
+       if (!ifp)
+               return ret;
 
+       ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
+                                              argv, uj, 0);
        return ret;
 }
 
@@ -5077,15 +5098,12 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
 }
 
 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
-                                          int arg_base,
-                                          struct cmd_token **argv,
+                                          struct in_addr *router_id,
                                           bool use_json, uint8_t use_vrf)
 {
        struct listnode *node;
        struct ospf_neighbor *nbr;
        struct ospf_interface *oi;
-       struct in_addr router_id;
-       int ret;
        json_object *json = NULL;
 
        if (use_json)
@@ -5101,19 +5119,8 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
 
        ospf_show_vrf_name(ospf, vty, json, use_vrf);
 
-       ret = inet_aton(argv[arg_base]->arg, &router_id);
-       if (!ret) {
-               if (!use_json)
-                       vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
-               else {
-                       vty_out(vty, "{}\n");
-                       json_object_free(json);
-               }
-               return CMD_WARNING;
-       }
-
        for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
-               if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) {
+               if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) {
                        show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
                                                         use_json);
                }
@@ -5129,9 +5136,9 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_ospf_neighbor_id,
+DEFPY (show_ip_ospf_neighbor_id,
        show_ip_ospf_neighbor_id_cmd,
-       "show ip ospf neighbor A.B.C.D [json]",
+       "show ip ospf neighbor A.B.C.D$router_id [json$json]",
        SHOW_STR
        IP_STR
        "OSPF information\n"
@@ -5140,23 +5147,22 @@ DEFUN (show_ip_ospf_neighbor_id,
        JSON_STR)
 {
        struct ospf *ospf;
-       bool uj = use_json(argc, argv);
-       struct listnode *node = NULL;
+       struct listnode *node;
        int ret = CMD_SUCCESS;
 
        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                if (!ospf->oi_running)
                        continue;
-               ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj,
-                                                     0);
+               ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
+                                                     !!json, 0);
        }
 
        return ret;
 }
 
-DEFUN (show_ip_ospf_instance_neighbor_id,
+DEFPY (show_ip_ospf_instance_neighbor_id,
        show_ip_ospf_instance_neighbor_id_cmd,
-       "show ip ospf (1-65535) neighbor A.B.C.D [json]",
+       "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
        SHOW_STR
        IP_STR
        "OSPF information\n"
@@ -5165,13 +5171,8 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
        "Neighbor ID\n"
        JSON_STR)
 {
-       int idx_number = 3;
-       int idx_router_id = 5;
        struct ospf *ospf;
-       unsigned short instance = 0;
-       bool uj = use_json(argc, argv);
 
-       instance = strtoul(argv[idx_number]->arg, NULL, 10);
        ospf = ospf_lookup_instance(instance);
        if (ospf == NULL)
                return CMD_NOT_MY_INSTANCE;
@@ -5179,8 +5180,8 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
        if (!ospf->oi_running)
                return CMD_SUCCESS;
 
-       return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv,
-                                              uj, 0);
+       return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
+                                              0);
 }
 
 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
@@ -5256,7 +5257,7 @@ DEFUN (show_ip_ospf_neighbor_detail,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -5445,7 +5446,7 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -5573,7 +5574,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
                        vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
        }
 
-       ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
+       ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
        if (!ifp) {
                if (!use_json)
                        vty_out(vty, "No such interface.\n");
@@ -5625,12 +5626,12 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
        bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        int ret = CMD_SUCCESS;
-       bool ospf_output = FALSE;
+       bool ospf_output = false;
 
        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                if (!ospf->oi_running)
                        continue;
-               ospf_output = TRUE;
+               ospf_output = true;
                ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
                                                              argv, uj);
        }
@@ -6333,7 +6334,7 @@ DEFUN (show_ip_ospf_database_max,
        struct ospf *ospf = NULL;
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -6342,7 +6343,7 @@ DEFUN (show_ip_ospf_database_max,
        OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
 
        if (vrf_name) {
-               bool ospf_output = FALSE;
+               bool ospf_output = false;
 
                use_vrf = 1;
 
@@ -6350,7 +6351,7 @@ DEFUN (show_ip_ospf_database_max,
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
-                               ospf_output = TRUE;
+                               ospf_output = true;
                                ret = show_ip_ospf_database_common(
                                        vty, ospf, idx_vrf ? 2 : 0, argc, argv,
                                        use_vrf);
@@ -6402,7 +6403,7 @@ DEFUN (show_ip_ospf_instance_database,
        unsigned short instance = 0;
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx = 0;
@@ -6560,7 +6561,7 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
        unsigned short instance = 0;
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx = 0, idx_vrf = 0;
@@ -6583,7 +6584,7 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
        OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
 
        if (vrf_name) {
-               bool ospf_output = FALSE;
+               bool ospf_output = false;
 
                use_vrf = 1;
 
@@ -6591,7 +6592,7 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
-                               ospf_output = TRUE;
+                               ospf_output = true;
                                ret = show_ip_ospf_database_type_adv_router_common(
                                        vty, ospf, idx ? 1 : 0, argc, argv,
                                        use_vrf);
@@ -6893,9 +6894,8 @@ DEFUN (ip_ospf_authentication_key,
                ospf_if_update_params(ifp, addr);
        }
 
-       memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
-       strncpy((char *)params->auth_simple, argv[3]->arg,
-               OSPF_AUTH_SIMPLE_SIZE);
+       strlcpy((char *)params->auth_simple, argv[3]->arg,
+               sizeof(params->auth_simple));
        SET_IF_PARAM(params, auth_simple);
 
        return CMD_SUCCESS;
@@ -7004,8 +7004,7 @@ DEFUN (ip_ospf_message_digest_key,
 
        ck = ospf_crypt_key_new();
        ck->key_id = (uint8_t)key_id;
-       memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
-       strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
+       strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
 
        ospf_crypt_key_add(params->auth_crypt, ck);
        SET_IF_PARAM(params, auth_crypt);
@@ -9373,7 +9372,7 @@ DEFUN (show_ip_ospf_border_routers,
        struct ospf *ospf = NULL;
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -9382,7 +9381,7 @@ DEFUN (show_ip_ospf_border_routers,
        OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
 
        if (vrf_name) {
-               bool ospf_output = FALSE;
+               bool ospf_output = false;
 
                use_vrf = 1;
 
@@ -9391,7 +9390,7 @@ DEFUN (show_ip_ospf_border_routers,
                                if (!ospf->oi_running)
                                        continue;
 
-                               ospf_output = TRUE;
+                               ospf_output = true;
                                ret = show_ip_ospf_border_routers_common(
                                        vty, ospf, use_vrf);
                        }
@@ -9511,7 +9510,7 @@ DEFUN (show_ip_ospf_route,
        struct ospf *ospf = NULL;
        struct listnode *node = NULL;
        char *vrf_name = NULL;
-       bool all_vrf = FALSE;
+       bool all_vrf = false;
        int ret = CMD_SUCCESS;
        int inst = 0;
        int idx_vrf = 0;
@@ -9526,7 +9525,7 @@ DEFUN (show_ip_ospf_route,
 
        /* vrf input is provided could be all or specific vrf*/
        if (vrf_name) {
-               bool ospf_output = FALSE;
+               bool ospf_output = false;
 
                use_vrf = 1;
 
@@ -9534,7 +9533,7 @@ DEFUN (show_ip_ospf_route,
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
-                               ospf_output = TRUE;
+                               ospf_output = true;
                                ret = show_ip_ospf_route_common(vty, ospf, json,
                                                                use_vrf);
                        }
@@ -9734,7 +9733,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                        vty_out(vty, " ip ospf network %s",
                                                ospf_int_type_str
                                                        [params->type]);
-                                       if (params != IF_DEF_PARAMS(ifp))
+                                       if (params != IF_DEF_PARAMS(ifp) && rn)
                                                vty_out(vty, " %s",
                                                        inet_ntoa(
                                                                rn->p.u.prefix4));
@@ -9771,7 +9770,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
 
                                vty_out(vty, " ip ospf authentication%s",
                                        auth_str);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9782,7 +9781,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                            && params->auth_simple[0] != '\0') {
                                vty_out(vty, " ip ospf authentication-key %s",
                                        params->auth_simple);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9795,7 +9794,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                        vty_out(vty,
                                                " ip ospf message-digest-key %d md5 %s",
                                                ck->key_id, ck->auth_key);
-                                       if (params != IF_DEF_PARAMS(ifp))
+                                       if (params != IF_DEF_PARAMS(ifp) && rn)
                                                vty_out(vty, " %s",
                                                        inet_ntoa(
                                                                rn->p.u.prefix4));
@@ -9807,7 +9806,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                        if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
                                vty_out(vty, " ip ospf cost %u",
                                        params->output_cost_cmd);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9818,7 +9817,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                            && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
                                vty_out(vty, " ip ospf hello-interval %u",
                                        params->v_hello);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9840,7 +9839,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                else
                                        vty_out(vty, "%u", params->v_wait);
 
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9852,7 +9851,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                       != OSPF_ROUTER_PRIORITY_DEFAULT) {
                                vty_out(vty, " ip ospf priority %u",
                                        params->priority);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9865,7 +9864,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                       != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
                                vty_out(vty, " ip ospf retransmit-interval %u",
                                        params->retransmit_interval);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9877,7 +9876,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                       != OSPF_TRANSMIT_DELAY_DEFAULT) {
                                vty_out(vty, " ip ospf transmit-delay %u",
                                        params->transmit_delay);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9896,7 +9895,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                area_id2str(buf, sizeof(buf), &params->if_area,
                                            params->if_area_id_fmt);
                                vty_out(vty, " area %s", buf);
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -9913,7 +9912,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                                        vty_out(vty, " no ip ospf mtu-ignore");
                                else
                                        vty_out(vty, " ip ospf mtu-ignore");
-                               if (params != IF_DEF_PARAMS(ifp))
+                               if (params != IF_DEF_PARAMS(ifp) && rn)
                                        vty_out(vty, " %s",
                                                inet_ntoa(rn->p.u.prefix4));
                                vty_out(vty, "\n");
@@ -10645,28 +10644,45 @@ static void ospf_interface_clear(struct interface *ifp)
 
 DEFUN (clear_ip_ospf_interface,
        clear_ip_ospf_interface_cmd,
-       "clear ip ospf interface [IFNAME]",
+       "clear ip ospf [vrf <NAME>] interface [IFNAME]",
        CLEAR_STR
        IP_STR
        "OSPF information\n"
+       VRF_CMD_HELP_STR
        "Interface information\n"
        "Interface name\n")
 {
-       int idx_ifname = 4;
+       int idx_ifname = 0;
+       int idx_vrf = 0;
        struct interface *ifp;
        struct listnode *node;
        struct ospf *ospf = NULL;
+       char *vrf_name = NULL;
+       vrf_id_t vrf_id = VRF_DEFAULT;
+       struct vrf *vrf = NULL;
 
-       if (argc == 4) /* Clear all the ospfv2 interfaces. */
-       {
+       if (argv_find(argv, argc, "vrf", &idx_vrf))
+               vrf_name = argv[idx_vrf + 1]->arg;
+       if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
+               vrf_name = NULL;
+       if (vrf_name) {
+               vrf = vrf_lookup_by_name(vrf_name);
+               if (vrf)
+                       vrf_id = vrf->vrf_id;
+       }
+       if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
+               /* Clear all the ospfv2 interfaces. */
                for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
-                       struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
+                       if (vrf_id != ospf->vrf_id)
+                               continue;
+                       if (!vrf)
+                               vrf = vrf_lookup_by_id(ospf->vrf_id);
                        FOR_ALL_INTERFACES (vrf, ifp)
                                ospf_interface_clear(ifp);
                }
        } else {
                /* Interface name is specified. */
-               ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
+               ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
                if (ifp == NULL)
                        vty_out(vty, "No such interface name\n");
                else