]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: constify a few parameters of helper functions
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 7 Aug 2019 23:00:58 +0000 (20:00 -0300)
committerOlivier Dugeon <olivier.dugeon@orange.com>
Thu, 30 Apr 2020 09:27:20 +0000 (11:27 +0200)
Parameters should be const whenever possible to improve code
readability and remove the need to cast away the constness of
const arguments.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/if.c
lib/if.h
lib/prefix.h

index ff95cd9043438824a1dc57874f418af06c820ce1..5c0f5e61aacc0a7d26f381ad492323c407a1aa5d 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -410,7 +410,7 @@ struct interface *if_lookup_by_index_all_vrf(ifindex_t ifindex)
 }
 
 /* Lookup interface by IP address. */
-struct interface *if_lookup_exact_address(void *src, int family,
+struct interface *if_lookup_exact_address(const void *src, int family,
                                          vrf_id_t vrf_id)
 {
        struct vrf *vrf = vrf_lookup_by_id(vrf_id);
@@ -442,7 +442,7 @@ struct interface *if_lookup_exact_address(void *src, int family,
 }
 
 /* Lookup interface by IP address. */
-struct connected *if_lookup_address(void *matchaddr, int family,
+struct connected *if_lookup_address(const void *matchaddr, int family,
                                    vrf_id_t vrf_id)
 {
        struct vrf *vrf = vrf_lookup_by_id(vrf_id);
@@ -479,7 +479,7 @@ struct connected *if_lookup_address(void *matchaddr, int family,
 }
 
 /* Lookup interface by prefix */
-struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id)
+struct interface *if_lookup_prefix(const struct prefix *prefix, vrf_id_t vrf_id)
 {
        struct vrf *vrf = vrf_lookup_by_id(vrf_id);
        struct listnode *cnode;
@@ -982,7 +982,8 @@ nbr_connected_log(struct nbr_connected *connected, char *str)
 }
 
 /* If two connected address has same prefix return 1. */
-static int connected_same_prefix(struct prefix *p1, struct prefix *p2)
+static int connected_same_prefix(const struct prefix *p1,
+                                const struct prefix *p2)
 {
        if (p1->family == p2->family) {
                if (p1->family == AF_INET
@@ -1010,7 +1011,7 @@ unsigned int connected_count_by_family(struct interface *ifp, int family)
 }
 
 struct connected *connected_lookup_prefix_exact(struct interface *ifp,
-                                               struct prefix *p)
+                                               const struct prefix *p)
 {
        struct listnode *node;
        struct listnode *next;
@@ -1049,7 +1050,7 @@ struct connected *connected_delete_by_prefix(struct interface *ifp,
 /* Find the address on our side that will be used when packets
    are sent to dst. */
 struct connected *connected_lookup_prefix(struct interface *ifp,
-                                         struct prefix *addr)
+                                         const struct prefix *addr)
 {
        struct listnode *cnode;
        struct connected *c;
index ac8d8e70ba2f024388017fab9abd2709a4d1414b..6a36806566d03ea344275dc03f0cd2f9680347ce 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -512,11 +512,11 @@ extern struct interface *if_create_name(const char *name, vrf_id_t vrf_id);
 extern struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
 extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
 extern struct interface *if_lookup_by_index_all_vrf(ifindex_t);
-extern struct interface *if_lookup_exact_address(void *matchaddr, int family,
-                                                vrf_id_t vrf_id);
-extern struct connected *if_lookup_address(void *matchaddr, int family,
+extern struct interface *if_lookup_exact_address(const void *matchaddr,
+                                                int family, vrf_id_t vrf_id);
+extern struct connected *if_lookup_address(const void *matchaddr, int family,
                                           vrf_id_t vrf_id);
-extern struct interface *if_lookup_prefix(struct prefix *prefix,
+extern struct interface *if_lookup_prefix(const struct prefix *prefix,
                                          vrf_id_t vrf_id);
 size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
                           struct interface ***result, vrf_id_t vrf_id);
@@ -575,9 +575,9 @@ connected_add_by_prefix(struct interface *, struct prefix *, struct prefix *);
 extern struct connected *connected_delete_by_prefix(struct interface *,
                                                    struct prefix *);
 extern struct connected *connected_lookup_prefix(struct interface *,
-                                                struct prefix *);
+                                                const struct prefix *);
 extern struct connected *connected_lookup_prefix_exact(struct interface *,
-                                                      struct prefix *);
+                                                      const struct prefix *);
 extern unsigned int connected_count_by_family(struct interface *, int family);
 extern struct nbr_connected *nbr_connected_new(void);
 extern void nbr_connected_free(struct nbr_connected *);
index f2952c38c3710cf36b85945cd1ba3856f09c83f8..4b2d90d63abd8fec9389637905f58fe9ad46b4a0 100644 (file)
@@ -522,7 +522,7 @@ static inline int is_default_prefix(const struct prefix *p)
        return 0;
 }
 
-static inline int is_host_route(struct prefix *p)
+static inline int is_host_route(const struct prefix *p)
 {
        if (p->family == AF_INET)
                return (p->prefixlen == IPV4_MAX_BITLEN);