]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_vty.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / ospfd / ospf_vty.c
index ddf9133ed96ff30ae1dc3c50e6af8990904a18e3..fb08833b61148626abee8ecb020dd9eca6b8d023 100644 (file)
@@ -145,6 +145,8 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
 
        if (argv_find(argv, argc, "vrf", &idx_vrf)) {
                vrf_name = argv[idx_vrf + 1]->arg;
+               if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME))
+                       vrf_name = NULL;
                if (enable) {
                        /* Allocate VRF aware instance */
                        ospf = ospf_get(*instance, vrf_name);
@@ -243,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++;
+                               }
                        }
                }
 
@@ -458,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);
@@ -531,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);
@@ -748,6 +753,7 @@ DEFUN (ospf_area_range_not_advertise,
        ospf_area_range_set(ospf, area_id, &p, 0);
        ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
                                     format);
+       ospf_area_range_substitute_unset(ospf, area_id, &p);
 
        return CMD_SUCCESS;
 }
@@ -2336,27 +2342,6 @@ DEFUN (no_ospf_timers_lsa_min_arrival,
        return CMD_SUCCESS;
 }
 
-#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
-CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
-#endif
-ALIAS_HIDDEN(ospf_timers_lsa_min_arrival, ospf_timers_lsa_arrival_cmd,
-            "timers lsa arrival (0-1000)",
-            "adjust routing timers\n"
-            "throttling link state advertisement delays\n"
-            "ospf minimum arrival interval delay\n"
-            "delay (msec) between accepted lsas\n");
-
-#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
-CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08")
-#endif
-ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival, no_ospf_timers_lsa_arrival_cmd,
-            "no timers lsa arrival (0-1000)", NO_STR
-            "adjust routing timers\n"
-            "throttling link state advertisement delays\n"
-            "ospf minimum arrival interval delay\n"
-            "delay (msec) between accepted lsas\n");
-
-
 DEFUN (ospf_neighbor,
        ospf_neighbor_cmd,
        "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
@@ -2642,7 +2627,7 @@ const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)",
 const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"};
 
 static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
-                             json_object *json_areas, uint8_t use_json)
+                             json_object *json_areas, bool use_json)
 {
        json_object *json_area = NULL;
 
@@ -3262,7 +3247,7 @@ DEFUN (show_ip_ospf,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
        bool all_vrf = FALSE;
@@ -3282,11 +3267,15 @@ DEFUN (show_ip_ospf,
 
        /* vrf input is provided could be all or specific vrf*/
        if (vrf_name) {
+               bool ospf_output = FALSE;
+
                use_vrf = 1;
+
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
+                               ospf_output = TRUE;
                                ret = show_ip_ospf_common(vty, ospf, json,
                                                          use_vrf);
                        }
@@ -3295,21 +3284,34 @@ DEFUN (show_ip_ospf,
                                        json_object_to_json_string_ext(
                                                json, JSON_C_TO_STRING_PRETTY));
                                json_object_free(json);
-                       }
+                       } else if (!ospf_output)
+                               vty_out(vty, "%% OSPF instance not found\n");
                        return ret;
                }
                ospf = ospf_lookup_by_inst_name(inst, vrf_name);
                if ((ospf == NULL) || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        } else {
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                /* Display default ospf (instance 0) info */
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        }
@@ -3340,7 +3342,7 @@ DEFUN (show_ip_ospf_instance,
        int idx_number = 3;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        int ret = CMD_SUCCESS;
        json_object *json = NULL;
 
@@ -3369,7 +3371,7 @@ DEFUN (show_ip_ospf_instance,
 static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
                                       struct interface *ifp,
                                       json_object *json_interface_sub,
-                                      uint8_t use_json)
+                                      bool use_json)
 {
        int is_up;
        struct ospf_neighbor *nbr;
@@ -3686,7 +3688,7 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
 
 static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
                                         char *intf_name, uint8_t use_vrf,
-                                        json_object *json, uint8_t use_json)
+                                        json_object *json, bool use_json)
 {
        struct interface *ifp;
        struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
@@ -3779,7 +3781,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
 static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
                                               struct ospf_interface *oi,
                                               json_object *json_interface_sub,
-                                              uint8_t use_json)
+                                              bool use_json)
 {
        if (use_json) {
                json_object_int_add(json_interface_sub, "ifIndex",
@@ -3817,7 +3819,7 @@ static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
 /* OSPFv2 Packet Counters */
 static int show_ip_ospf_interface_traffic_common(
        struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
-       int display_once, uint8_t use_vrf, uint8_t use_json)
+       int display_once, uint8_t use_vrf, bool use_json)
 {
        struct vrf *vrf = NULL;
        struct interface *ifp = NULL;
@@ -3935,7 +3937,7 @@ DEFUN (show_ip_ospf_interface,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL, *intf_name = NULL;
        bool all_vrf = FALSE;
@@ -3970,14 +3972,21 @@ DEFUN (show_ip_ospf_interface,
                                        json_object_to_json_string_ext(
                                                json, JSON_C_TO_STRING_PRETTY));
                                json_object_free(json);
-                       }
+                       } else if (!ospf)
+                               vty_out(vty, "%% OSPF instance not found\n");
 
                        return ret;
                }
                ospf = ospf_lookup_by_inst_name(inst, vrf_name);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
                ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
@@ -3987,8 +3996,14 @@ DEFUN (show_ip_ospf_interface,
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
                ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
@@ -4019,7 +4034,7 @@ DEFUN (show_ip_ospf_instance_interface,
        int idx_intf = 0;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        char *intf_name = NULL;
        int ret = CMD_SUCCESS;
        json_object *json = NULL;
@@ -4068,7 +4083,7 @@ DEFUN (show_ip_ospf_interface_traffic,
        bool all_vrf = FALSE;
        int inst = 0;
        int idx_vrf = 0, idx_intf = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        int ret = CMD_SUCCESS;
        int display_once = 0;
@@ -4144,7 +4159,7 @@ static void show_ip_ospf_neighbour_header(struct vty *vty)
 
 static void show_ip_ospf_neighbor_sub(struct vty *vty,
                                      struct ospf_interface *oi,
-                                     json_object *json, uint8_t use_json)
+                                     json_object *json, bool use_json)
 {
        struct route_node *rn;
        struct ospf_neighbor *nbr, *prev_nbr = NULL;
@@ -4255,7 +4270,7 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
 }
 
 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
-                                       json_object *json, uint8_t use_json,
+                                       json_object *json, bool use_json,
                                        uint8_t use_vrf)
 {
        struct ospf_interface *oi;
@@ -4317,7 +4332,7 @@ DEFUN (show_ip_ospf_neighbor,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
        bool all_vrf = FALSE;
@@ -4348,23 +4363,36 @@ DEFUN (show_ip_ospf_neighbor,
                                        json_object_to_json_string_ext(
                                                json, JSON_C_TO_STRING_PRETTY));
                                json_object_free(json);
-                       }
+                       } else if (!ospf)
+                               vty_out(vty, "OSPF instance not found\n");
 
                        return ret;
                }
 
                ospf = ospf_lookup_by_inst_name(inst, vrf_name);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        }
@@ -4400,7 +4428,7 @@ DEFUN (show_ip_ospf_instance_neighbor,
        int idx_number = 3;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        int ret = CMD_SUCCESS;
 
@@ -4427,7 +4455,7 @@ DEFUN (show_ip_ospf_instance_neighbor,
 }
 
 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
-                                           json_object *json, uint8_t use_json,
+                                           json_object *json, bool use_json,
                                            uint8_t use_vrf)
 {
        struct listnode *node;
@@ -4530,7 +4558,7 @@ DEFUN (show_ip_ospf_neighbor_all,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
        bool all_vrf = FALSE;
@@ -4612,7 +4640,7 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
        int idx_number = 3;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        int ret = CMD_SUCCESS;
 
@@ -4640,7 +4668,7 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
                                            int arg_base,
                                            struct cmd_token **argv,
-                                           uint8_t use_json, uint8_t use_vrf)
+                                           bool use_json, uint8_t use_vrf)
 {
        struct interface *ifp;
        struct route_node *rn;
@@ -4659,7 +4687,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");
@@ -4689,34 +4717,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;
-       uint8_t uj = use_json(argc, argv);
-       struct listnode *node = NULL;
+       int idx_ifname = 0;
+       int idx_vrf = 0;
+       bool uj = use_json(argc, argv);
        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;
 }
 
@@ -4735,7 +4779,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int,
        int idx_ifname = 5;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
 
        if (!uj)
                show_ip_ospf_neighbour_header(vty);
@@ -4758,8 +4802,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int,
 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
                                             struct ospf_interface *oi,
                                             struct ospf_nbr_nbma *nbr_nbma,
-                                            uint8_t use_json,
-                                            json_object *json)
+                                            bool use_json, json_object *json)
 {
        char timebuf[OSPF_TIME_DUMP_SIZE];
        json_object *json_sub = NULL;
@@ -4809,16 +4852,19 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
                vty_out(vty, "    Poll interval %d\n", nbr_nbma->v_poll);
 
        /* Show poll-interval timer. */
-       if (use_json) {
-               long time_store;
-               time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL)
-                            / 1000LL;
-               json_object_int_add(json_sub, "pollIntervalTimerDueMsec",
-                                   time_store);
-       } else
-               vty_out(vty, "    Poll timer due in %s\n",
-                       ospf_timer_dump(nbr_nbma->t_poll, timebuf,
-                                       sizeof(timebuf)));
+       if (nbr_nbma->t_poll) {
+               if (use_json) {
+                       long time_store;
+                       time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
+                                                   NULL) / 1000LL;
+                       json_object_int_add(json_sub,
+                                           "pollIntervalTimerDueMsec",
+                                           time_store);
+               } else
+                       vty_out(vty, "    Poll timer due in %s\n",
+                               ospf_timer_dump(nbr_nbma->t_poll, timebuf,
+                                               sizeof(timebuf)));
+       }
 
        /* Show poll-interval timer thread. */
        if (use_json) {
@@ -4836,8 +4882,7 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
                                             struct ospf_interface *oi,
                                             struct ospf_neighbor *nbr,
-                                            json_object *json,
-                                            uint8_t use_json)
+                                            json_object *json, bool use_json)
 {
        char timebuf[OSPF_TIME_DUMP_SIZE];
        json_object *json_sub = NULL;
@@ -5053,7 +5098,7 @@ 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,
-                                          uint8_t use_json, uint8_t use_vrf)
+                                          bool use_json, uint8_t use_vrf)
 {
        struct listnode *node;
        struct ospf_neighbor *nbr;
@@ -5114,7 +5159,7 @@ DEFUN (show_ip_ospf_neighbor_id,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        int ret = CMD_SUCCESS;
 
@@ -5143,7 +5188,7 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
        int idx_router_id = 5;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
 
        instance = strtoul(argv[idx_number]->arg, NULL, 10);
        ospf = ospf_lookup_instance(instance);
@@ -5159,8 +5204,7 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
 
 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
                                               struct ospf *ospf,
-                                              json_object *json,
-                                              uint8_t use_json,
+                                              json_object *json, bool use_json,
                                               uint8_t use_vrf)
 {
        struct ospf_interface *oi;
@@ -5228,7 +5272,7 @@ DEFUN (show_ip_ospf_neighbor_detail,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
        bool all_vrf = FALSE;
@@ -5308,7 +5352,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
        int idx_number = 3;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        int ret = CMD_SUCCESS;
 
@@ -5337,7 +5381,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
                                                   struct ospf *ospf,
                                                   json_object *json,
-                                                  uint8_t use_json,
+                                                  bool use_json,
                                                   uint8_t use_vrf)
 {
        struct listnode *node;
@@ -5417,7 +5461,7 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        char *vrf_name = NULL;
        bool all_vrf = FALSE;
@@ -5499,7 +5543,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all,
        int idx_number = 3;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        int ret = CMD_SUCCESS;
 
@@ -5529,7 +5573,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
                                                   struct ospf *ospf,
                                                   int arg_base,
                                                   struct cmd_token **argv,
-                                                  uint8_t use_json)
+                                                  bool use_json)
 {
        struct ospf_interface *oi;
        struct interface *ifp;
@@ -5548,7 +5592,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");
@@ -5597,17 +5641,22 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
        JSON_STR)
 {
        struct ospf *ospf;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        struct listnode *node = NULL;
        int ret = CMD_SUCCESS;
+       bool ospf_output = FALSE;
 
        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                if (!ospf->oi_running)
                        continue;
+               ospf_output = TRUE;
                ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
                                                              argv, uj);
        }
 
+       if (!ospf_output)
+               vty_out(vty, "%% OSPF instance not found\n");
+
        return ret;
 }
 
@@ -5627,7 +5676,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int_detail,
        int idx_ifname = 5;
        struct ospf *ospf;
        unsigned short instance = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
 
        instance = strtoul(argv[idx_number]->arg, NULL, 10);
        ospf = ospf_lookup_instance(instance);
@@ -6312,19 +6361,28 @@ 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;
+
                use_vrf = 1;
+
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
+                               ospf_output = TRUE;
                                ret = show_ip_ospf_database_common(
                                        vty, ospf, idx_vrf ? 2 : 0, argc, argv,
                                        use_vrf);
                        }
+
+                       if (!ospf_output)
+                               vty_out(vty, "%% OSPF instance not found\n");
                } else {
                        ospf = ospf_lookup_by_inst_name(inst, vrf_name);
-                       if (ospf == NULL || !ospf->oi_running)
+                       if (ospf == NULL || !ospf->oi_running) {
+                               vty_out(vty, "%% OSPF instance not found\n");
                                return CMD_SUCCESS;
+                       }
                        ret = (show_ip_ospf_database_common(
                                vty, ospf, idx_vrf ? 2 : 0, argc, argv,
                                use_vrf));
@@ -6332,8 +6390,11 @@ DEFUN (show_ip_ospf_database_max,
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
-               if (ospf == NULL || !ospf->oi_running)
+               if (ospf == NULL || !ospf->oi_running) {
+                       vty_out(vty, "%% OSPF instance not found\n");
                        return CMD_SUCCESS;
+               }
+
                ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
                                                   use_vrf);
        }
@@ -6393,16 +6454,22 @@ DEFUN (show_ip_ospf_instance_database,
                        }
                } else {
                        ospf = ospf_lookup_by_inst_name(inst, vrf_name);
-                       if ((ospf == NULL) || !ospf->oi_running)
+                       if ((ospf == NULL) || !ospf->oi_running) {
+                               vty_out(vty, "%% OSPF instance not found\n");
                                return CMD_SUCCESS;
+                       }
+
                        ret = (show_ip_ospf_database_common(
                                vty, ospf, idx ? 2 : 0, argc, argv, use_vrf));
                }
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
-               if (ospf == NULL || !ospf->oi_running)
+               if (ospf == NULL || !ospf->oi_running) {
+                       vty_out(vty, "%% OSPF instance not found\n");
                        return CMD_SUCCESS;
+               }
+
                ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
                                                    use_vrf));
        }
@@ -6431,8 +6498,10 @@ DEFUN (show_ip_ospf_instance_database_max,
        if (ospf == NULL)
                return CMD_NOT_MY_INSTANCE;
 
-       if (!ospf->oi_running)
+       if (!ospf->oi_running) {
+               vty_out(vty, "%% OSPF instance not found\n");
                return CMD_SUCCESS;
+       }
 
        return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0);
 }
@@ -6521,8 +6590,11 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
                ospf = ospf_lookup_instance(instance);
                if (ospf == NULL)
                        return CMD_NOT_MY_INSTANCE;
-               if (!ospf->oi_running)
+               if (!ospf->oi_running) {
+                       vty_out(vty, "%% OSPF instance not found\n");
                        return CMD_SUCCESS;
+               }
+
                return (show_ip_ospf_database_type_adv_router_common(
                        vty, ospf, idx ? 1 : 0, argc, argv, use_vrf));
        }
@@ -6530,27 +6602,39 @@ 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;
+
                use_vrf = 1;
+
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
+                               ospf_output = TRUE;
                                ret = show_ip_ospf_database_type_adv_router_common(
                                        vty, ospf, idx ? 1 : 0, argc, argv,
                                        use_vrf);
                        }
+                       if (!ospf_output)
+                               vty_out(vty, "%% OSPF instance not found\n");
                } else {
                        ospf = ospf_lookup_by_inst_name(inst, vrf_name);
-                       if ((ospf == NULL) || !ospf->oi_running)
+                       if ((ospf == NULL) || !ospf->oi_running) {
+                               vty_out(vty, "%% OSPF instance not found\n");
                                return CMD_SUCCESS;
+                       }
+
                        ret = show_ip_ospf_database_type_adv_router_common(
                                vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
                }
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
-               if (ospf == NULL || !ospf->oi_running)
+               if (ospf == NULL || !ospf->oi_running) {
+                       vty_out(vty, "%% OSPF instance not found\n");
                        return CMD_SUCCESS;
+               }
+
                ret = show_ip_ospf_database_type_adv_router_common(
                        vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
        }
@@ -8137,6 +8221,8 @@ DEFUN (no_ospf_redistribute_source,
                return CMD_SUCCESS;
 
        ospf_routemap_unset(red);
+       ospf_redist_del(ospf, source, 0);
+
        return ospf_redistribute_unset(ospf, source, 0);
 }
 
@@ -8251,6 +8337,8 @@ DEFUN (no_ospf_redistribute_instance_source,
                return CMD_SUCCESS;
 
        ospf_routemap_unset(red);
+       ospf_redist_del(ospf, source, instance);
+
        return ospf_redistribute_unset(ospf, source, instance);
 }
 
@@ -8318,6 +8406,9 @@ DEFUN (ospf_default_information_originate,
        int metric = -1;
        struct ospf_redist *red;
        int idx = 0;
+       int cur_originate = ospf->default_originate;
+       int sameRtmap = 0;
+       char *rtmap = NULL;
 
        red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
 
@@ -8339,7 +8430,28 @@ DEFUN (ospf_default_information_originate,
        idx = 1;
        /* Get route-map */
        if (argv_find(argv, argc, "WORD", &idx))
-               ospf_routemap_set(red, argv[idx]->arg);
+               rtmap = argv[idx]->arg;
+
+       /* To check ,if user is providing same route map */
+       if ((rtmap == ROUTEMAP_NAME(red)) ||
+           (rtmap && ROUTEMAP_NAME(red)
+           && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
+               sameRtmap = 1;
+
+       /* Don't allow if the same lsa is aleardy originated. */
+       if ((sameRtmap)
+           && (red->dmetric.type == type)
+           && (red->dmetric.value == metric)
+           && (cur_originate == default_originate))
+               return CMD_SUCCESS;
+
+       /* Updating Metric details */
+       red->dmetric.type = type;
+       red->dmetric.value = metric;
+
+       /* updating route map details */
+       if (rtmap)
+               ospf_routemap_set(red, rtmap);
        else
                ospf_routemap_unset(red);
 
@@ -8383,6 +8495,8 @@ DEFUN (no_ospf_default_information_originate,
                return CMD_SUCCESS;
 
        ospf_routemap_unset(red);
+       ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
+
        return ospf_redistribute_default_unset(ospf);
 }
 
@@ -9287,19 +9401,28 @@ 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;
+
                use_vrf = 1;
+
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
 
+                               ospf_output = TRUE;
                                ret = show_ip_ospf_border_routers_common(
                                        vty, ospf, use_vrf);
                        }
+
+                       if (!ospf_output)
+                               vty_out(vty, "%% OSPF instance not found\n");
                } else {
                        ospf = ospf_lookup_by_inst_name(inst, vrf_name);
-                       if (ospf == NULL || !ospf->oi_running)
+                       if (ospf == NULL || !ospf->oi_running) {
+                               vty_out(vty, "%% OSPF instance not found\n");
                                return CMD_SUCCESS;
+                       }
 
                        ret = show_ip_ospf_border_routers_common(vty, ospf,
                                                                 use_vrf);
@@ -9307,8 +9430,11 @@ DEFUN (show_ip_ospf_border_routers,
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
-               if (ospf == NULL || !ospf->oi_running)
+               if (ospf == NULL || !ospf->oi_running) {
+                       vty_out(vty, "%% OSPF instance not found\n");
                        return CMD_SUCCESS;
+               }
+
                ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
        }
 
@@ -9409,7 +9535,7 @@ DEFUN (show_ip_ospf_route,
        int inst = 0;
        int idx_vrf = 0;
        uint8_t use_vrf = 0;
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
 
        if (uj)
@@ -9419,11 +9545,15 @@ DEFUN (show_ip_ospf_route,
 
        /* vrf input is provided could be all or specific vrf*/
        if (vrf_name) {
+               bool ospf_output = FALSE;
+
                use_vrf = 1;
+
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
                                if (!ospf->oi_running)
                                        continue;
+                               ospf_output = TRUE;
                                ret = show_ip_ospf_route_common(vty, ospf, json,
                                                                use_vrf);
                        }
@@ -9433,22 +9563,35 @@ DEFUN (show_ip_ospf_route,
                                vty_out(vty, "%s\n",
                                        json_object_to_json_string(json));
                                json_object_free(json);
-                       }
+                       } else if (!ospf_output)
+                               vty_out(vty, "%% OSPF instance not found\n");
 
                        return ret;
                }
                ospf = ospf_lookup_by_inst_name(inst, vrf_name);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        } else {
                /* Display default ospf (instance 0) info */
                ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                if (ospf == NULL || !ospf->oi_running) {
-                       if (uj)
+                       if (uj) {
+                               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, "%% OSPF instance not found\n");
+
                        return CMD_SUCCESS;
                }
        }
@@ -9500,7 +9643,7 @@ DEFUN (show_ip_ospf_vrfs,
        "Show OSPF VRFs \n"
        JSON_STR)
 {
-       uint8_t uj = use_json(argc, argv);
+       bool uj = use_json(argc, argv);
        json_object *json = NULL;
        json_object *json_vrfs = NULL;
        struct ospf *ospf = NULL;
@@ -10521,28 +10664,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
@@ -10658,8 +10818,6 @@ void ospf_vty_init(void)
        install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
        install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
        install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
-       install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd);
-       install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd);
 
        /* refresh timer commands */
        install_element(OSPF_NODE, &ospf_refresh_timer_cmd);