]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: remove unnecessary check for default vrf 11831/head
authoranlan_cs <vic.lan@pica8.com>
Wed, 17 Aug 2022 07:26:24 +0000 (03:26 -0400)
committeranlan_cs <vic.lan@pica8.com>
Wed, 12 Jul 2023 09:00:27 +0000 (17:00 +0800)
The default vrf is generally non-NULL, except when shutdown. So, most
of the time it is not necessary to check if it is NULL, we should
remove the useless checks for it.

Searched them with exact match:
```
grep -rI "zebra_vrf_lookup_by_id(VRF_DEFAULT)" | wc -l
31
```

Signed-off-by: anlan_cs <vic.lan@pica8.com>
zebra/table_manager.c
zebra/zapi_msg.c
zebra/zebra_mpls.c
zebra/zebra_mpls_vty.c
zebra/zebra_pw.c
zebra/zebra_vty.c
zebra/zebra_vxlan.c

index 77ec42e64bd6618d9483ae41b2b173a417f88693..512508b79f96cf30f2940e534cd400f99c1a2791 100644 (file)
@@ -63,8 +63,7 @@ void table_manager_enable(struct zebra_vrf *zvrf)
            && strcmp(zvrf_name(zvrf), VRF_DEFAULT_NAME)) {
                struct zebra_vrf *def = zebra_vrf_lookup_by_id(VRF_DEFAULT);
 
-               if (def)
-                       zvrf->tbl_mgr = def->tbl_mgr;
+               zvrf->tbl_mgr = def->tbl_mgr;
                return;
        }
        zvrf->tbl_mgr = XCALLOC(MTYPE_TM_TABLE, sizeof(struct table_manager));
index 5ac87540588ee4cd2280dce621bc064844db09fa..6a5b0b4a0eb6885066f75b5d75f55da523954306 100644 (file)
@@ -1337,8 +1337,6 @@ static void zread_fec_register(ZAPI_HANDLER_ARGS)
 
        s = msg;
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        /*
         * The minimum amount of data that can be sent for one fec
@@ -1400,8 +1398,6 @@ static void zread_fec_unregister(ZAPI_HANDLER_ARGS)
 
        s = msg;
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        /*
         * The minimum amount of data that can be sent for one
index ef109774d97d9b202d0db645a26ff279d9af6c1e..eac4fcc8e0605d4eb4f8fa4d42f6ffc8d261a5c0 100644 (file)
@@ -1029,8 +1029,6 @@ static void lsp_processq_del(struct work_queue *wq, void *data)
                return;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       assert(zvrf);
-
        lsp_table = zvrf->lsp_table;
        if (!lsp_table) // unexpected
                return;
@@ -1776,9 +1774,6 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx)
        case DPLANE_OP_LSP_UPDATE:
                /* Look for zebra LSP object */
                zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-               if (zvrf == NULL)
-                       break;
-
                lsp_table = zvrf->lsp_table;
 
                tmp_ile.in_label = label;
@@ -2093,9 +2088,6 @@ void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx)
 
        /* Look for zebra LSP object */
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (zvrf == NULL)
-               return;
-
        lsp_table = zvrf->lsp_table;
 
        tmp_ile.in_label = dplane_ctx_get_in_label(ctx);
index 6b8859e0cae348bdf31e46b733e71a4d8251570b..e64e7009b4d2422692066af6c9207bb396d76dbe 100644 (file)
@@ -42,10 +42,6 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd,
        }
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf) {
-               vty_out(vty, "%% Default VRF does not exist\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
 
        if (!inlabel_str) {
                vty_out(vty, "%% No Label Information\n");
@@ -186,10 +182,6 @@ static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix,
        int ret;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf) {
-               vty_out(vty, "%% Default VRF does not exist\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
 
        memset(&p, 0, sizeof(p));
        ret = str2prefix(prefix, &p);
@@ -274,8 +266,6 @@ static int zebra_mpls_config(struct vty *vty)
        struct zebra_vrf *zvrf;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return 0;
 
        write += zebra_mpls_write_lsp_config(vty, zvrf);
        write += zebra_mpls_write_fec_config(vty, zvrf);
@@ -297,8 +287,6 @@ DEFUN (show_mpls_fec,
        int ret;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return 0;
 
        if (argc == 3)
                zebra_mpls_print_fec_table(vty, zvrf);
@@ -373,10 +361,6 @@ static int zebra_mpls_global_block(struct vty *vty, int add_cmd,
        struct zebra_vrf *zvrf;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf) {
-               vty_out(vty, "%% Default VRF does not exist\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
 
        if (add_cmd) {
                if (!start_label_str || !end_label_str) {
index 12dcac1de5f54bb4b1e109b65b388be3c9db5a08..f76bf747d6a6c423507ec98c9ffeecbb4cb00a14 100644 (file)
@@ -408,8 +408,6 @@ DEFUN_NOSH (pseudowire_if,
        int idx = 0;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return CMD_WARNING;
 
        argv_find(argv, argc, "IFNAME", &idx);
        ifname = argv[idx]->arg;
@@ -440,8 +438,6 @@ DEFUN (no_pseudowire_if,
        int idx = 0;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return CMD_WARNING;
 
        argv_find(argv, argc, "IFNAME", &idx);
        ifname = argv[idx]->arg;
@@ -564,8 +560,6 @@ DEFUN (show_pseudowires,
        struct zebra_pw *pw;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return 0;
 
        vty_out(vty, "%-16s %-24s %-12s %-8s %-10s\n", "Interface", "Neighbor",
                "Labels", "Protocol", "Status");
@@ -603,8 +597,6 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty)
        struct nexthop_group *nhg;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        RB_FOREACH (pw, zebra_pw_head, &zvrf->pseudowires) {
                char buf_nbr[INET6_ADDRSTRLEN];
@@ -759,8 +751,6 @@ static void vty_show_mpls_pseudowire_detail_json(struct vty *vty)
        struct zebra_pw *pw;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        json = json_object_new_object();
        json_pws = json_object_new_array();
@@ -795,8 +785,6 @@ static int zebra_pw_config(struct vty *vty)
        struct zebra_pw *pw;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return 0;
 
        RB_FOREACH (pw, zebra_static_pw_head, &zvrf->static_pseudowires) {
                vty_out(vty, "pseudowire %s\n", pw->ifname);
index d100dc0e69623231e6aad105d4fbffac1c282ca8..19366eb2c1c1b9720f526eded857f2859aff5901 100644 (file)
@@ -2703,13 +2703,8 @@ DEFUN (default_vrf_vni_mapping,
        "Prefix routes only \n")
 {
        char xpath[XPATH_MAXLEN];
-       struct zebra_vrf *zvrf = NULL;
        int filter = 0;
 
-       zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return CMD_WARNING;
-
        if (argc == 3)
                filter = 1;
 
@@ -2746,8 +2741,6 @@ DEFUN (no_default_vrf_vni_mapping,
        struct zebra_vrf *zvrf = NULL;
 
        zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
-       if (!zvrf)
-               return CMD_WARNING;
 
        if (argc == 4)
                filter = 1;
index 132862e690f60759494fedac311794423096d657..417f8302384321fbc9e864b4205beca17a735c4e 100644 (file)
@@ -5937,8 +5937,6 @@ static void zebra_vxlan_sg_del(struct zebra_vxlan_sg *vxlan_sg)
        struct zebra_vrf *zvrf;
 
        zvrf = vrf_info_lookup(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        /* On SG entry deletion remove the reference to its parent XG
         * entry
@@ -6008,8 +6006,6 @@ void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip,
                return;
 
        zvrf = vrf_info_lookup(VRF_DEFAULT);
-       if (!zvrf)
-               return;
 
        zebra_vxlan_sg_do_deref(zvrf, local_vtep_ip, mcast_grp);
 }
@@ -6023,8 +6019,7 @@ void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, struct in_addr mcast_grp)
                return;
 
        zvrf = vrf_info_lookup(VRF_DEFAULT);
-       if (!zvrf)
-               return;
+
        zebra_vxlan_sg_do_ref(zvrf, local_vtep_ip, mcast_grp);
 }