]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: minor cleanup
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 21 Aug 2020 00:44:27 +0000 (21:44 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Wed, 26 Aug 2020 23:16:19 +0000 (20:16 -0300)
* Bring back some consts that were removed;
* Replace ALL_LIST_ELEMENTS by ALL_LIST_ELEMENTS_RO whenever
  possible;
* Fix some CLI return values;
* Remove some unnecessary initializations.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
isisd/isis_misc.c
isisd/isis_misc.h
isisd/isis_spf.c
isisd/isis_sr.c
isisd/isis_te.c
isisd/isisd.c
isisd/isisd.h

index 3aedd8ba1f9b64b1086450a61442187e7cfdd758..27425f24a4c2e9aff0e4ce6de928078c9267fc51 100644 (file)
@@ -437,7 +437,7 @@ struct in_addr newprefix2inaddr(uint8_t *prefix_start, uint8_t prefix_masklen)
  * Returns the dynamic hostname associated with the passed system ID.
  * If no dynamic hostname found then returns formatted system ID.
  */
-const char *print_sys_hostname(uint8_t *sysid)
+const char *print_sys_hostname(const uint8_t *sysid)
 {
        struct isis_dynhn *dyn;
        struct isis *isis = NULL;
@@ -447,8 +447,7 @@ const char *print_sys_hostname(uint8_t *sysid)
 
        /* For our system ID return our host name */
        isis = isis_lookup_by_sysid(sysid);
-
-       if (isis != NULL)
+       if (isis)
                return cmd_hostname_get();
 
        dyn = dynhn_find_by_id(sysid);
index c6a5832f33c967e705f3a624aee594b62127d9b8..5cdbbfb0581513af01c1d340526440cd56f3ee4e 100644 (file)
@@ -49,7 +49,7 @@ const char *time2string(uint32_t);
 const char *nlpid2str(uint8_t nlpid);
 /* typedef struct nlpids nlpids; */
 char *nlpid2string(struct nlpids *);
-const char *print_sys_hostname(uint8_t *sysid);
+const char *print_sys_hostname(const uint8_t *sysid);
 void zlog_dump_data(void *data, int len);
 
 /*
index 174f4dfe85650e293f581cca6d0256fbeffc42e6..ec10bb77e64fcf8a6ddfcd93101779fd54fbce8e 100644 (file)
@@ -1484,7 +1484,7 @@ DEFUN(show_isis_topology, show_isis_topology_cmd,
 )
 {
        int levels = ISIS_LEVELS;
-       struct listnode *inode, *nnode;
+       struct listnode *node;
        struct isis *isis = NULL;
        int idx = 0;
        const char *vrf_name = VRF_DEFAULT_NAME;
@@ -1508,10 +1508,9 @@ DEFUN(show_isis_topology, show_isis_topology_cmd,
 
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                show_isis_topology_common(vty, levels, isis);
-                       }
-                       return 0;
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
index 5f6335c7d0f6fec4bab2c4ff1c136fcbaf85d6e9..d05afaa63081c8dcb6aa69f01cae852a1e5c7460 100644 (file)
@@ -210,7 +210,7 @@ int isis_sr_cfg_srlb_update(struct isis_area *area, uint32_t lower_bound,
                            uint32_t upper_bound)
 {
        struct isis_sr_db *srdb = &area->srdb;
-       struct listnode *node, *nnode;
+       struct listnode *node;
        struct sr_adjacency *sra;
 
        sr_debug("ISIS-Sr (%s): Update SRLB with new range [%u/%u]",
@@ -236,7 +236,7 @@ int isis_sr_cfg_srlb_update(struct isis_area *area, uint32_t lower_bound,
                        return -1;
 
                /* Reinstall local Adjacency-SIDs with new labels. */
-               for (ALL_LIST_ELEMENTS(area->srdb.adj_sids, node, nnode, sra))
+               for (ALL_LIST_ELEMENTS_RO(area->srdb.adj_sids, node, sra))
                        sr_adj_sid_update(sra, &srdb->srlb);
 
                /* Update and Flood LSP */
@@ -1986,7 +1986,7 @@ DEFUN(show_sr_prefix_sids, show_sr_prefix_sids_cmd,
       "Segment-Routing\n"
       "Segment-Routing Prefix-SIDs\n")
 {
-       struct listnode *node, *inode, *nnode;
+       struct listnode *node, *inode;
        struct isis_area *area;
        struct isis *isis = NULL;
        const char *vrf_name = VRF_DEFAULT_NAME;
@@ -1996,7 +1996,7 @@ DEFUN(show_sr_prefix_sids, show_sr_prefix_sids_cmd,
        ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                                for (ALL_LIST_ELEMENTS_RO(isis->area_list, node,
                                                          area)) {
                                        vty_out(vty, "Area %s:\n",
@@ -2084,11 +2084,11 @@ DEFUN(show_sr_node, show_sr_node_cmd,
       "Segment-Routing\n"
       "Segment-Routing node\n")
 {
-       struct listnode *node, *inode, *nnode;
+       struct listnode *node, *inode;
        struct isis_area *area;
-       struct isis *isis = NULL;
+       struct isis *isis;
 
-       for (ALL_LIST_ELEMENTS(im->isis, inode, nnode, isis)) {
+       for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
                        vty_out(vty, "Area %s:\n",
                                area->area_tag ? area->area_tag : "null");
index 016f811a728ae619dcfe975dadbe62cc5363e42a..87c44281558b31dcf8944adac98add6099d77e98 100644 (file)
@@ -311,7 +311,7 @@ DEFUN(show_isis_mpls_te_router,
       MPLS_TE_STR "Router information\n")
 {
 
-       struct listnode *anode, *nnode, *inode;
+       struct listnode *anode, *inode;
        struct isis_area *area;
        struct isis *isis = NULL;
        const char *vrf_name = VRF_DEFAULT_NAME;
@@ -325,7 +325,7 @@ DEFUN(show_isis_mpls_te_router,
        ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                                for (ALL_LIST_ELEMENTS_RO(isis->area_list,
                                                          anode, area)) {
                                        if (!IS_MPLS_TE(area->mta))
@@ -483,7 +483,7 @@ DEFUN (show_isis_mpls_te_interface,
        "Interface information\n"
        "Interface name\n")
 {
-       struct listnode *anode, *cnode, *nnode, *inode;
+       struct listnode *anode, *cnode, *inode;
        struct isis_area *area;
        struct isis_circuit *circuit;
        struct interface *ifp;
@@ -497,7 +497,7 @@ DEFUN (show_isis_mpls_te_interface,
 
        if (argc == idx_interface) {
                /* Show All Interfaces. */
-               for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+               for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                        for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode,
                                                  area)) {
 
index 0d39aba20b421138a9c0fad13e6e539753ed19f5..453b440e2384722df0656b5658e179c36db8039a 100644 (file)
@@ -125,33 +125,37 @@ void isis_vrf_unlink(struct isis *isis, struct vrf *vrf)
 
 struct isis *isis_lookup_by_vrfid(vrf_id_t vrf_id)
 {
-       struct isis *isis = NULL;
-       struct listnode *node, *nnode;
+       struct isis *isis;
+       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS(im->isis, node, nnode, isis))
+       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                if (isis->vrf_id == vrf_id)
                        return isis;
+
        return NULL;
 }
 
 struct isis *isis_lookup_by_vrfname(const char *vrfname)
 {
-       struct isis *isis = NULL;
-       struct listnode *node, *nnode;
+       struct isis *isis;
+       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS(im->isis, node, nnode, isis))
+       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                if (isis->name && vrfname && strcmp(isis->name, vrfname) == 0)
                        return isis;
+
        return NULL;
 }
 
-struct isis *isis_lookup_by_sysid(uint8_t *sysid)
+struct isis *isis_lookup_by_sysid(const uint8_t *sysid)
 {
-       struct isis *isis = NULL;
-       struct listnode *node, *nnode;
-       for (ALL_LIST_ELEMENTS(im->isis, node, nnode, isis))
+       struct isis *isis;
+       struct listnode *node;
+
+       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                if (!memcmp(isis->sysid, sysid, ISIS_SYS_ID_LEN))
                        return isis;
+
        return NULL;
 }
 
@@ -165,7 +169,7 @@ void isis_master_init(struct thread_master *master)
 
 void isis_global_instance_create()
 {
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        isis = isis_lookup_by_vrfid(VRF_DEFAULT);
        if (isis == NULL) {
@@ -176,8 +180,8 @@ void isis_global_instance_create()
 
 struct isis *isis_new(vrf_id_t vrf_id)
 {
-       struct vrf *vrf = NULL;
-       struct isis *isis = NULL;
+       struct vrf *vrf;
+       struct isis *isis;
 
        isis = XCALLOC(MTYPE_ISIS, sizeof(struct isis));
        isis->vrf_id = vrf_id;
@@ -335,7 +339,7 @@ struct isis_area *isis_area_lookup(const char *area_tag, vrf_id_t vrf_id)
 {
        struct isis_area *area;
        struct listnode *node;
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        isis = isis_lookup_by_vrfid(vrf_id);
        if (isis == NULL)
@@ -464,7 +468,7 @@ void isis_finish(struct isis *isis)
 
 void isis_terminate()
 {
-       struct isis *isis = NULL;
+       struct isis *isis;
        struct listnode *node, *nnode;
 
        if (listcount(im->isis) == 0)
@@ -643,10 +647,10 @@ int area_clear_net_title(struct vty *vty, const char *net_title)
 int show_isis_interface_common(struct vty *vty, const char *ifname, char detail,
                               const char *vrf_name, bool all_vrf)
 {
-       struct listnode *anode, *cnode, *mnode, *inode;
+       struct listnode *anode, *cnode, *inode;
        struct isis_area *area;
        struct isis_circuit *circuit;
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        if (!im) {
                vty_out(vty, "IS-IS Routing Process not enabled\n");
@@ -654,7 +658,7 @@ int show_isis_interface_common(struct vty *vty, const char *ifname, char detail,
        }
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, mnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                                for (ALL_LIST_ELEMENTS_RO(isis->area_list,
                                                          anode, area)) {
                                        vty_out(vty, "Area %s:\n",
@@ -677,7 +681,7 @@ int show_isis_interface_common(struct vty *vty, const char *ifname, char detail,
                                                                detail);
                                }
                        }
-                       return 0;
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL) {
@@ -822,10 +826,10 @@ static void isis_neighbor_common(struct vty *vty, const char *id, char detail,
 int show_isis_neighbor_common(struct vty *vty, const char *id, char detail,
                              const char *vrf_name, bool all_vrf)
 {
-       struct listnode *nnode, *inode;
+       struct listnode *node;
        struct isis_dynhn *dynhn;
        uint8_t sysid[ISIS_SYS_ID_LEN];
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        if (!im) {
                vty_out(vty, "IS-IS Routing Process not enabled\n");
@@ -846,11 +850,11 @@ int show_isis_neighbor_common(struct vty *vty, const char *id, char detail,
 
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
                                isis_neighbor_common(vty, id, detail, isis,
                                                     sysid);
                        }
-                       return 0;
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
@@ -863,7 +867,7 @@ int show_isis_neighbor_common(struct vty *vty, const char *id, char detail,
 static void isis_neighbor_common_clear(struct vty *vty, const char *id,
                                       uint8_t *sysid, struct isis *isis)
 {
-       struct listnode *anode, *cnode, *cnextnode, *node, *nnode;
+       struct listnode *anode, *cnode, *node, *nnode;
        struct isis_area *area;
        struct isis_circuit *circuit;
        struct list *adjdb;
@@ -871,8 +875,7 @@ static void isis_neighbor_common_clear(struct vty *vty, const char *id,
        int i;
 
        for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
-               for (ALL_LIST_ELEMENTS(area->circuit_list, cnode, cnextnode,
-                                      circuit)) {
+               for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit)) {
                        if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
                                for (i = 0; i < 2; i++) {
                                        adjdb = circuit->u.bc.adjdb[i];
@@ -910,10 +913,10 @@ static void isis_neighbor_common_clear(struct vty *vty, const char *id,
 int clear_isis_neighbor_common(struct vty *vty, const char *id, const char *vrf_name,
                               bool all_vrf)
 {
-       struct listnode *nnode, *inode;
+       struct listnode *node;
        struct isis_dynhn *dynhn;
        uint8_t sysid[ISIS_SYS_ID_LEN];
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        if (!im) {
                vty_out(vty, "IS-IS Routing Process not enabled\n");
@@ -933,11 +936,10 @@ int clear_isis_neighbor_common(struct vty *vty, const char *id, const char *vrf_
        }
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                isis_neighbor_common_clear(vty, id, sysid,
                                                           isis);
-                       }
-                       return 0;
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
@@ -1554,19 +1556,19 @@ DEFUN(show_hostname, show_hostname_cmd,
       "All VRFs\n"
       "IS-IS Dynamic hostname mapping\n")
 {
-       struct listnode *nnode, *inode;
+       struct listnode *node;
        const char *vrf_name = VRF_DEFAULT_NAME;
        bool all_vrf = false;
        int idx_vrf = 0;
-       struct isis *isis = NULL;
+       struct isis *isis;
 
        ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                dynhn_print_all(vty, isis);
-                       }
-                       return 0;
+
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
@@ -1621,8 +1623,8 @@ DEFUN(show_isis_spf_ietf, show_isis_spf_ietf_cmd,
       "All VRFs\n"
       "SPF delay IETF information\n")
 {
-       struct listnode *nnode, *inode;
-       struct isis *isis = NULL;
+       struct listnode *node;
+       struct isis *isis;
        int idx_vrf = 0;
        const char *vrf_name = VRF_DEFAULT_NAME;
        bool all_vrf = false;
@@ -1636,10 +1638,10 @@ DEFUN(show_isis_spf_ietf, show_isis_spf_ietf_cmd,
 
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                isis_spf_ietf_common(vty, isis);
-                       }
-                       return 0;
+
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
@@ -1755,9 +1757,9 @@ DEFUN(show_isis_summary, show_isis_summary_cmd,
       "All VRFs\n"
       "summary\n")
 {
-       struct listnode *inode, *nnode;
+       struct listnode *node;
        int idx_vrf = 0;
-       struct isis *isis = NULL;
+       struct isis *isis;
        const char *vrf_name = VRF_DEFAULT_NAME;
        bool all_vrf = false;
 
@@ -1768,10 +1770,10 @@ DEFUN(show_isis_summary, show_isis_summary_cmd,
        }
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                common_isis_summary(vty, isis);
-                       }
-                       return 0;
+
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
@@ -1918,19 +1920,19 @@ static int show_isis_database_common(struct vty *vty, const char *argv,
 static int show_isis_database(struct vty *vty, const char *argv, int ui_level,
                              const char *vrf_name, bool all_vrf)
 {
-       struct listnode *inode, *nnode;
-       struct isis *isis = NULL;
+       struct listnode *node;
+       struct isis *isis;
 
        if (vrf_name) {
                if (all_vrf) {
-                       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
+                       for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
                                show_isis_database_common(vty, argv, ui_level,
                                                          isis);
-                       }
-                       return 0;
+
+                       return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
-               if (isis != NULL)
+               if (isis)
                        show_isis_database_common(vty, argv, ui_level, isis);
        }
 
@@ -2352,16 +2354,15 @@ static int isis_config_write(struct vty *vty)
 {
        int write = 0;
        struct isis_area *area;
-       struct listnode *node, *node2, *inode, *nnode;
-       struct isis *isis = NULL;
+       struct listnode *node, *node2, *inode;
+       struct isis *isis;
 
        if (!im) {
                vty_out(vty, "IS-IS Routing Process not enabled\n");
                return CMD_SUCCESS;
        }
 
-       for (ALL_LIST_ELEMENTS(im->isis, nnode, inode, isis)) {
-
+       for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
                for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
                        /* ISIS - Area name */
                        vty_out(vty, "router " PROTO_NAME " %s\n", area->area_tag);
index 41b69df2bf3cf069fddb04ae67a2b6d94aa27e53..2314cc262c4390908ec30b018bdc16befb551782 100644 (file)
@@ -215,7 +215,7 @@ void isis_vrf_unlink(struct isis *isis, struct vrf *vrf);
 void isis_global_instance_create(void);
 struct isis *isis_lookup_by_vrfid(vrf_id_t vrf_id);
 struct isis *isis_lookup_by_vrfname(const char *vrfname);
-struct isis *isis_lookup_by_sysid(uint8_t *sysid);
+struct isis *isis_lookup_by_sysid(const uint8_t *sysid);
 
 void isis_init(void);
 struct isis *isis_new(vrf_id_t vrf_id);