]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: hashing functions should take const arguments
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 14 May 2019 20:19:07 +0000 (20:19 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 14 May 2019 21:23:08 +0000 (21:23 +0000)
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.

BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
61 files changed:
bfdd/bfd.c
bgpd/bgp_advertise.c
bgpd/bgp_advertise.h
bgpd/bgp_aspath.c
bgpd/bgp_aspath.h
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_clist.c
bgpd/bgp_community.c
bgpd/bgp_community.h
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h
bgpd/bgp_evpn.c
bgpd/bgp_keepalives.c
bgpd/bgp_lcommunity.c
bgpd/bgp_lcommunity.h
bgpd/bgp_mac.c
bgpd/bgp_nexthop.c
bgpd/bgp_pbr.c
bgpd/bgp_pbr.h
bgpd/bgp_updgrp.c
bgpd/bgpd.c
isisd/fabricd.c
isisd/isis_spf_private.h
isisd/isis_tx_queue.c
lib/command.c
lib/distribute.c
lib/ferr.c
lib/hash.c
lib/hash.h
lib/if_rmap.c
lib/northbound.c
lib/routemap.c
lib/thread.c
lib/vrf.c
lib/wheel.c
lib/wheel.h
lib/yang_translator.c
nhrpd/nhrp_cache.c
nhrpd/nhrp_peer.c
nhrpd/nhrp_vc.c
nhrpd/reqid.c
ospfd/ospf_sr.c
pbrd/pbr_nht.c
pimd/pim_ifchannel.c
pimd/pim_ifchannel.h
pimd/pim_igmp.c
pimd/pim_msdp.c
pimd/pim_oil.c
pimd/pim_rpf.c
pimd/pim_rpf.h
pimd/pim_upstream.c
pimd/pim_upstream.h
pimd/pim_vxlan.c
staticd/static_zebra.c
tests/lib/test_srcdest_table.c
tools/coccinelle/hash_const.cocci [new file with mode: 0644]
zebra/zebra_mpls.c
zebra/zebra_pbr.c
zebra/zebra_pbr.h
zebra/zebra_vxlan.c

index a2e84e928d15c4cdfa4131a55edea2f79876eced..57d8ffa6d37aacfba5afa40b0821d01b45730ed5 100644 (file)
@@ -1271,16 +1271,16 @@ void bs_to_bpc(struct bfd_session *bs, struct bfd_peer_cfg *bpc)
 static struct hash *bfd_id_hash;
 static struct hash *bfd_key_hash;
 
-static unsigned int bfd_id_hash_do(void *p);
-static unsigned int bfd_key_hash_do(void *p);
+static unsigned int bfd_id_hash_do(const void *p);
+static unsigned int bfd_key_hash_do(const void *p);
 
 static void _bfd_free(struct hash_bucket *hb,
                      void *arg __attribute__((__unused__)));
 
 /* BFD hash for our discriminator. */
-static unsigned int bfd_id_hash_do(void *p)
+static unsigned int bfd_id_hash_do(const void *p)
 {
-       struct bfd_session *bs = p;
+       const struct bfd_session *bs = p;
 
        return jhash_1word(bs->discrs.my_discr, 0);
 }
@@ -1293,9 +1293,9 @@ static bool bfd_id_hash_cmp(const void *n1, const void *n2)
 }
 
 /* BFD hash for single hop. */
-static unsigned int bfd_key_hash_do(void *p)
+static unsigned int bfd_key_hash_do(const void *p)
 {
-       struct bfd_session *bs = p;
+       const struct bfd_session *bs = p;
 
        return jhash(&bs->key, sizeof(bs->key), 0);
 }
index c9f68d037bebc733f51d9997f1ff7dded09690f0..497fb0749e19063c9703bfa11fbf378695dbe182 100644 (file)
@@ -64,9 +64,9 @@ static void *baa_hash_alloc(void *p)
        return baa;
 }
 
-unsigned int baa_hash_key(void *p)
+unsigned int baa_hash_key(const void *p)
 {
-       struct bgp_advertise_attr *baa = (struct bgp_advertise_attr *)p;
+       const struct bgp_advertise_attr *baa = p;
 
        return attrhash_key_make(baa->attr);
 }
index cc845b93e751a025a7120231bd834080193fec3c..7d2fdf1f0b2e35454d286294bd7dd7b0a4b9ff66 100644 (file)
@@ -144,7 +144,7 @@ extern void bgp_adj_in_remove(struct bgp_node *, struct bgp_adj_in *);
 
 extern void bgp_sync_init(struct peer *);
 extern void bgp_sync_delete(struct peer *);
-extern unsigned int baa_hash_key(void *p);
+extern unsigned int baa_hash_key(const void *p);
 extern bool baa_hash_cmp(const void *p1, const void *p2);
 extern void bgp_advertise_add(struct bgp_advertise_attr *baa,
                              struct bgp_advertise *adv);
index 92c37fabd23483274b1e47adf9616aab38eda2f1..05577cb8bdb0779847fd7f04d321dc5398d9bbad 100644 (file)
@@ -2008,13 +2008,13 @@ struct aspath *aspath_str2aspath(const char *str)
 }
 
 /* Make hash value by raw aspath data. */
-unsigned int aspath_key_make(void *p)
+unsigned int aspath_key_make(const void *p)
 {
-       struct aspath *aspath = (struct aspath *)p;
+       const struct aspath *aspath = p;
        unsigned int key = 0;
 
        if (!aspath->str)
-               aspath_str_update(aspath, false);
+               aspath_str_update((struct aspath *)aspath, false);
 
        key = jhash(aspath->str, aspath->str_len, 2334325);
 
index be5725c1aea739a5aa088b0eb786aa5036f2c1a9..6f3d94cdb3f948c68f826626085a88faea2eca32 100644 (file)
@@ -102,7 +102,7 @@ extern const char *aspath_print(struct aspath *);
 extern void aspath_print_vty(struct vty *, const char *, struct aspath *,
                             const char *);
 extern void aspath_print_all_vty(struct vty *);
-extern unsigned int aspath_key_make(void *);
+extern unsigned int aspath_key_make(const void *);
 extern unsigned int aspath_get_first_as(struct aspath *);
 extern unsigned int aspath_get_last_as(struct aspath *);
 extern int aspath_loop_check(struct aspath *, as_t);
index cbfa166cf36620daa333b3a39d9375c7df7c12d3..9cc3cecd3c17de96fca4b16240794713fc1b3733 100644 (file)
@@ -140,7 +140,7 @@ int cluster_loop_check(struct cluster_list *cluster, struct in_addr originator)
        return 0;
 }
 
-static unsigned int cluster_hash_key_make(void *p)
+static unsigned int cluster_hash_key_make(const void *p)
 {
        const struct cluster_list *cluster = p;
 
@@ -348,7 +348,7 @@ static void encap_unintern(struct bgp_attr_encap_subtlv **encapp,
        }
 }
 
-static unsigned int encap_hash_key_make(void *p)
+static unsigned int encap_hash_key_make(const void *p)
 {
        const struct bgp_attr_encap_subtlv *encap = p;
 
@@ -433,7 +433,7 @@ void transit_unintern(struct transit *transit)
        }
 }
 
-static unsigned int transit_hash_key_make(void *p)
+static unsigned int transit_hash_key_make(const void *p)
 {
        const struct transit *transit = p;
 
@@ -484,7 +484,7 @@ unsigned long int attr_unknown_count(void)
        return transit_hash->count;
 }
 
-unsigned int attrhash_key_make(void *p)
+unsigned int attrhash_key_make(const void *p)
 {
        const struct attr *attr = (struct attr *)p;
        uint32_t key = 0;
index f6b23a36bd6e054d912a74726d7c71c0edd26a03..a163cf92a4546022e1b83fdf6234bf8d55c2e3a8 100644 (file)
@@ -282,7 +282,7 @@ extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *,
 extern void bgp_dump_routes_attr(struct stream *, struct attr *,
                                 struct prefix *);
 extern bool attrhash_cmp(const void *arg1, const void *arg2);
-extern unsigned int attrhash_key_make(void *);
+extern unsigned int attrhash_key_make(const void *);
 extern void attr_show_all(struct vty *);
 extern unsigned long int attr_count(void);
 extern unsigned long int attr_unknown_count(void);
index e308e963b55f47e555fbb70d370e04fe48c605db..b9a5784799c6df89e0ebb8ebda00aeaeb9ae5ed8 100644 (file)
@@ -36,9 +36,9 @@
 #include "bgpd/bgp_regex.h"
 #include "bgpd/bgp_clist.h"
 
-static uint32_t bgp_clist_hash_key_community_list(void *data)
+static uint32_t bgp_clist_hash_key_community_list(const void *data)
 {
-       struct community_list *cl = data;
+       struct community_list *cl = (struct community_list *) data;
 
        if (cl->name_hash)
                return cl->name_hash;
index 67cd2be214897036c6d713d84ade54c0ba547445..82762072df0966e37d2776ecef0beeea18fd7506 100644 (file)
@@ -574,7 +574,7 @@ char *community_str(struct community *com, bool make_json)
 
 /* Make hash value of community attribute. This function is used by
    hash package.*/
-unsigned int community_hash_make(struct community *com)
+unsigned int community_hash_make(const struct community *com)
 {
        uint32_t *pnt = (uint32_t *)com->val;
 
@@ -897,7 +897,7 @@ struct hash *community_hash(void)
 void community_init(void)
 {
        comhash =
-               hash_create((unsigned int (*)(void *))community_hash_make,
+               hash_create((unsigned int (*)(const void *))community_hash_make,
                            (bool (*)(const void *, const void *))community_cmp,
                            "BGP Community Hash");
 }
@@ -957,7 +957,7 @@ void bgp_compute_aggregate_community(struct bgp_aggregate *aggregate,
         */
        if (aggregate->community_hash == NULL)
                aggregate->community_hash = hash_create(
-                       (unsigned int (*)(void *))community_hash_make,
+                       (unsigned int (*)(const void *))community_hash_make,
                        (bool (*)(const void *, const void *))community_cmp,
                        "BGP Aggregator community hash");
 
index 4ff4d214a5606e0de610c909cad11ccf5f492122..f761a8f5e0f6b4d56200e8593c6d0e1788a9e1d5 100644 (file)
@@ -75,7 +75,7 @@ extern struct community *community_parse(uint32_t *, unsigned short);
 extern struct community *community_intern(struct community *);
 extern void community_unintern(struct community **);
 extern char *community_str(struct community *, bool make_json);
-extern unsigned int community_hash_make(struct community *);
+extern unsigned int community_hash_make(const struct community *);
 extern struct community *community_str2com(const char *);
 extern int community_match(const struct community *, const struct community *);
 extern bool community_cmp(const struct community *c1,
index 8ef398952d3a59217006ad37fea9aa17f6fc8c1d..76bd0e815e6771cc81bfe8ea3c59b3b8da6efa2f 100644 (file)
@@ -241,7 +241,7 @@ void ecommunity_unintern(struct ecommunity **ecom)
 }
 
 /* Utinity function to make hash key.  */
-unsigned int ecommunity_hash_make(void *arg)
+unsigned int ecommunity_hash_make(const void *arg)
 {
        const struct ecommunity *ecom = arg;
        int size = ecom->size * ECOMMUNITY_SIZE;
index 62b213775391f64f599c94567a97423cacde894c..ddad952f7036ebd1b61d6d883563ed0bb99264a9 100644 (file)
@@ -162,7 +162,7 @@ extern struct ecommunity *ecommunity_uniq_sort(struct ecommunity *);
 extern struct ecommunity *ecommunity_intern(struct ecommunity *);
 extern bool ecommunity_cmp(const void *arg1, const void *arg2);
 extern void ecommunity_unintern(struct ecommunity **);
-extern unsigned int ecommunity_hash_make(void *);
+extern unsigned int ecommunity_hash_make(const void *);
 extern struct ecommunity *ecommunity_str2com(const char *, int, int);
 extern char *ecommunity_ecom2str(struct ecommunity *, int, int);
 extern void ecommunity_strfree(char **s);
index 52aa923959a91cc9870799f2dfec29694b773d4c..112e4b836c2e90857663501204f17ccc88e960e4 100644 (file)
@@ -83,9 +83,9 @@ static int evpn_vtep_ip_cmp(void *p1, void *p2)
 /*
  * Make hash key for ESI.
  */
-static unsigned int esi_hash_keymake(void *p)
+static unsigned int esi_hash_keymake(const void *p)
 {
-       struct evpnes *pes = p;
+       const struct evpnes *pes = p;
        const void *pnt = (void *)pes->esi.val;
 
        return jhash(pnt, ESI_BYTES, 0xa5a5a55a);
@@ -111,9 +111,9 @@ static bool esi_cmp(const void *p1, const void *p2)
 /*
  * Make vni hash key.
  */
-static unsigned int vni_hash_key_make(void *p)
+static unsigned int vni_hash_key_make(const void *p)
 {
-       struct bgpevpn *vpn = p;
+       const struct bgpevpn *vpn = p;
        return (jhash_1word(vpn->vni, 0));
 }
 
@@ -143,10 +143,10 @@ static int vni_list_cmp(void *p1, void *p2)
 /*
  * Make vrf import route target hash key.
  */
-static unsigned int vrf_import_rt_hash_key_make(void *p)
+static unsigned int vrf_import_rt_hash_key_make(const void *p)
 {
-       struct vrf_irt_node *irt = p;
-       char *pnt = irt->rt.val;
+       const struct vrf_irt_node *irt = p;
+       const char *pnt = irt->rt.val;
 
        return jhash(pnt, 8, 0x5abc1234);
 }
@@ -259,10 +259,10 @@ static int is_vrf_present_in_irt_vrfs(struct list *vrfs, struct bgp *bgp_vrf)
 /*
  * Make import route target hash key.
  */
-static unsigned int import_rt_hash_key_make(void *p)
+static unsigned int import_rt_hash_key_make(const void *p)
 {
-       struct irt_node *irt = p;
-       char *pnt = irt->rt.val;
+       const struct irt_node *irt = p;
+       const char *pnt = irt->rt.val;
 
        return jhash(pnt, 8, 0xdeadbeef);
 }
index c2f0baff76ca4b6dda387f829cd4193aeeceb788..bec3bdcb8d0e1320b957e00b8c4f7694a2c71848 100644 (file)
@@ -131,9 +131,9 @@ static bool peer_hash_cmp(const void *f, const void *s)
        return p1->peer == p2->peer;
 }
 
-static unsigned int peer_hash_key(void *arg)
+static unsigned int peer_hash_key(const void *arg)
 {
-       struct pkat *pkat = arg;
+       const struct pkat *pkat = arg;
        return (uintptr_t)pkat->peer;
 }
 
index 44766c9b6e30700bf4718ea9860b6202ce16fb02..098374fa9f7b92b89e8f342e66afe37853ea3915 100644 (file)
@@ -301,7 +301,7 @@ char *lcommunity_str(struct lcommunity *lcom, bool make_json)
 }
 
 /* Utility function to make hash key.  */
-unsigned int lcommunity_hash_make(void *arg)
+unsigned int lcommunity_hash_make(const void *arg)
 {
        const struct lcommunity *lcom = arg;
        int size = lcom_length(lcom);
index aa4e8c69fe4744e9a8eb3c24b6898ae26224ba90..a512395492f9788e92a39273012845b4a71f66d6 100644 (file)
@@ -63,7 +63,7 @@ extern struct lcommunity *lcommunity_uniq_sort(struct lcommunity *);
 extern struct lcommunity *lcommunity_intern(struct lcommunity *);
 extern bool lcommunity_cmp(const void *arg1, const void *arg2);
 extern void lcommunity_unintern(struct lcommunity **);
-extern unsigned int lcommunity_hash_make(void *);
+extern unsigned int lcommunity_hash_make(const void *);
 extern struct hash *lcommunity_hash(void);
 extern struct lcommunity *lcommunity_str2com(const char *);
 extern int lcommunity_match(const struct lcommunity *,
index 49b585402090352723efee25f32948c72f0a6a10..f19453fecb68db648532a1da44d79f9b19d7a6e0 100644 (file)
@@ -40,9 +40,9 @@ struct bgp_self_mac {
        struct list *ifp_list;
 };
 
-static unsigned int bgp_mac_hash_key_make(void *data)
+static unsigned int bgp_mac_hash_key_make(const void *data)
 {
-       struct bgp_self_mac *bsm = data;
+       const struct bgp_self_mac *bsm = data;
 
        return jhash(&bsm->macaddr, ETH_ALEN, 0xa5a5dead);
 }
index de97b73c7210ab41d1b534d4e33b4af72c1130b0..ea5e02d00ebf97133edea39eefaf40043d7aadc7 100644 (file)
@@ -114,7 +114,7 @@ static void bgp_tip_hash_free(void *addr)
        XFREE(MTYPE_TIP_ADDR, addr);
 }
 
-static unsigned int bgp_tip_hash_key_make(void *p)
+static unsigned int bgp_tip_hash_key_make(const void *p)
 {
        const struct tip_addr *addr = p;
 
@@ -237,7 +237,7 @@ static void bgp_address_hash_free(void *data)
        XFREE(MTYPE_BGP_ADDR, addr);
 }
 
-static unsigned int bgp_address_hash_key_make(void *p)
+static unsigned int bgp_address_hash_key_make(const void *p)
 {
        const struct bgp_addr *addr = p;
 
index 0fddfa75a1e88a87f33cd38cefeecc8529e1be3f..5eef6ac6ccc36ad7ba6ff4ffd29c093bf27ed835 100644 (file)
@@ -964,9 +964,9 @@ static void *bgp_pbr_match_entry_alloc_intern(void *arg)
        return new;
 }
 
-uint32_t bgp_pbr_match_hash_key(void *arg)
+uint32_t bgp_pbr_match_hash_key(const void *arg)
 {
-       struct bgp_pbr_match *pbm = (struct bgp_pbr_match *)arg;
+       const struct bgp_pbr_match *pbm = arg;
        uint32_t key;
 
        key = jhash_1word(pbm->vrf_id, 0x4312abde);
@@ -1019,9 +1019,9 @@ bool bgp_pbr_match_hash_equal(const void *arg1, const void *arg2)
        return true;
 }
 
-uint32_t bgp_pbr_rule_hash_key(void *arg)
+uint32_t bgp_pbr_rule_hash_key(const void *arg)
 {
-       struct bgp_pbr_rule *pbr = (struct bgp_pbr_rule *)arg;
+       const struct bgp_pbr_rule *pbr = arg;
        uint32_t key;
 
        key = prefix_hash_key(&pbr->src);
@@ -1057,12 +1057,12 @@ bool bgp_pbr_rule_hash_equal(const void *arg1, const void *arg2)
        return true;
 }
 
-uint32_t bgp_pbr_match_entry_hash_key(void *arg)
+uint32_t bgp_pbr_match_entry_hash_key(const void *arg)
 {
-       struct bgp_pbr_match_entry *pbme;
+       const struct bgp_pbr_match_entry *pbme;
        uint32_t key;
 
-       pbme = (struct bgp_pbr_match_entry *)arg;
+       pbme = arg;
        key = prefix_hash_key(&pbme->src);
        key = jhash_1word(prefix_hash_key(&pbme->dst), key);
        key = jhash(&pbme->dst_port_min, 2, key);
@@ -1111,12 +1111,12 @@ bool bgp_pbr_match_entry_hash_equal(const void *arg1, const void *arg2)
        return true;
 }
 
-uint32_t bgp_pbr_action_hash_key(void *arg)
+uint32_t bgp_pbr_action_hash_key(const void *arg)
 {
-       struct bgp_pbr_action *pbra;
+       const struct bgp_pbr_action *pbra;
        uint32_t key;
 
-       pbra = (struct bgp_pbr_action *)arg;
+       pbra = arg;
        key = jhash_1word(pbra->table_id, 0x4312abde);
        key = jhash_1word(pbra->fwmark, key);
        return key;
index f7fddac7fbf7ddb422c27ab1a50d933eff5fa680..b368d8892def96e76559095a0dc53e71b28016d8 100644 (file)
@@ -273,16 +273,16 @@ extern struct bgp_pbr_match *bgp_pbr_match_iptable_lookup(vrf_id_t vrf_id,
 extern void bgp_pbr_cleanup(struct bgp *bgp);
 extern void bgp_pbr_init(struct bgp *bgp);
 
-extern uint32_t bgp_pbr_rule_hash_key(void *arg);
+extern uint32_t bgp_pbr_rule_hash_key(const void *arg);
 extern bool bgp_pbr_rule_hash_equal(const void *arg1,
                                   const void *arg2);
-extern uint32_t bgp_pbr_action_hash_key(void *arg);
+extern uint32_t bgp_pbr_action_hash_key(const void *arg);
 extern bool bgp_pbr_action_hash_equal(const void *arg1,
                                     const void *arg2);
-extern uint32_t bgp_pbr_match_entry_hash_key(void *arg);
+extern uint32_t bgp_pbr_match_entry_hash_key(const void *arg);
 extern bool bgp_pbr_match_entry_hash_equal(const void *arg1,
                                          const void *arg2);
-extern uint32_t bgp_pbr_match_hash_key(void *arg);
+extern uint32_t bgp_pbr_match_hash_key(const void *arg);
 extern bool bgp_pbr_match_hash_equal(const void *arg1,
                                    const void *arg2);
 
index 57717bf59b5d0f22858228c087f5cfaf6618d49a..d0be2471af02b841a4ca9b376739732b26697bf9 100644 (file)
@@ -288,7 +288,7 @@ static void *updgrp_hash_alloc(void *p)
  *       16. Local-as should match, if configured.
  *      )
  */
-static unsigned int updgrp_hash_key_make(void *p)
+static unsigned int updgrp_hash_key_make(const void *p)
 {
        const struct update_group *updgrp;
        const struct peer *peer;
index 6183bbd4714eebc6691263b7e4da1b3ec5dfdd58..c0f1f3184a8a0b202bfac773c08daddc8dd9cccc 100644 (file)
@@ -812,9 +812,9 @@ int peer_cmp(struct peer *p1, struct peer *p2)
        return sockunion_cmp(&p1->su, &p2->su);
 }
 
-static unsigned int peer_hash_key_make(void *p)
+static unsigned int peer_hash_key_make(const void *p)
 {
-       struct peer *peer = p;
+       const struct peer *peer = p;
        return sockunion_hash(&peer->su);
 }
 
index 96af28f0a1cc2037cb5a9ed9778257246cbb0b38..b9c27d51bd89d0dc6aeac9fe32b98844cc500f0b 100644 (file)
@@ -108,9 +108,9 @@ static void neighbor_lists_clear(struct fabricd *f)
        hash_clean(f->neighbors_neighbors, neighbor_entry_del_void);
 }
 
-static unsigned neighbor_entry_hash_key(void *np)
+static unsigned neighbor_entry_hash_key(const void *np)
 {
-       struct neighbor_entry *n = np;
+       const struct neighbor_entry *n = np;
 
        return jhash(n->id, sizeof(n->id), 0x55aa5a5a);
 }
index 3a2a52afac28c5b04badd9edfe67d4e53ff6dd33..a8185a8be0fec76b0a5170457d87d453e9f9d503 100644 (file)
@@ -79,9 +79,9 @@ struct isis_vertex_queue {
 };
 
 __attribute__((__unused__))
-static unsigned isis_vertex_queue_hash_key(void *vp)
+static unsigned isis_vertex_queue_hash_key(const void *vp)
 {
-       struct isis_vertex *vertex = vp;
+       const struct isis_vertex *vertex = vp;
 
        if (VTYPE_IP(vertex->type)) {
                uint32_t key;
index 6f46e6bec0c24a1084feaceeb67318e2a1975994..507fd489bc621fb3e50bd9f73f1d39e665bf1c46 100644 (file)
@@ -50,9 +50,9 @@ struct isis_tx_queue_entry {
        struct isis_tx_queue *queue;
 };
 
-static unsigned tx_queue_hash_key(void *p)
+static unsigned tx_queue_hash_key(const void *p)
 {
-       struct isis_tx_queue_entry *e = p;
+       const struct isis_tx_queue_entry *e = p;
 
        uint32_t id_key = jhash(e->lsp->hdr.lsp_id,
                                ISIS_SYS_ID_LEN + 2, 0x55aa5a5a);
index d6fd1fa561d4edfc20b876cb0d19dfa88085879f..b7a323e35865c3c891a4830332107b79483be450 100644 (file)
@@ -332,7 +332,7 @@ int argv_find(struct cmd_token **argv, int argc, const char *text, int *index)
        return found;
 }
 
-static unsigned int cmd_hash_key(void *p)
+static unsigned int cmd_hash_key(const void *p)
 {
        int size = sizeof(p);
 
index be40bd2603d5acf78b16e0632aca5e53279d417e..2aa6b927fb01afcc3f1f64f82ca8f2e6afc59857 100644 (file)
@@ -131,7 +131,7 @@ static struct distribute *distribute_get(struct distribute_ctx *ctx,
        return ret;
 }
 
-static unsigned int distribute_hash_make(void *arg)
+static unsigned int distribute_hash_make(const void *arg)
 {
        const struct distribute *dist = arg;
 
index d7fa1a84f8955960e010cb7a673368262103dc9b..65c0cf886d3fbfaf677b144bb6072d87354dd645 100644 (file)
@@ -72,9 +72,9 @@ static bool ferr_hash_cmp(const void *a, const void *b)
        return f_a->code == f_b->code;
 }
 
-static inline unsigned int ferr_hash_key(void *a)
+static inline unsigned int ferr_hash_key(const void *a)
 {
-       struct log_ref *f = a;
+       const struct log_ref *f = a;
 
        return f->code;
 }
index 884c8f22af72baabc740bc0af1f758bded705f05..fad7de51385d4e6866e893eefb3e76fa3c543983 100644 (file)
@@ -37,7 +37,7 @@ static pthread_mutex_t _hashes_mtx = PTHREAD_MUTEX_INITIALIZER;
 static struct list *_hashes;
 
 struct hash *hash_create_size(unsigned int size,
-                             unsigned int (*hash_key)(void *),
+                             unsigned int (*hash_key)(const void *),
                              bool (*hash_cmp)(const void *, const void *),
                              const char *name)
 {
@@ -66,7 +66,7 @@ struct hash *hash_create_size(unsigned int size,
        return hash;
 }
 
-struct hash *hash_create(unsigned int (*hash_key)(void *),
+struct hash *hash_create(unsigned int (*hash_key)(const void *),
                         bool (*hash_cmp)(const void *, const void *),
                         const char *name)
 {
index 60c412b8e0716de194bfcdfc1f589ad950512076..c56a98d50c64adc3a6cbaba5a1dede33e423aa04 100644 (file)
@@ -79,7 +79,7 @@ struct hash {
        unsigned int max_size;
 
        /* Key make function. */
-       unsigned int (*hash_key)(void *);
+       unsigned int (*hash_key)(const void *);
 
        /* Data compare function. */
        bool (*hash_cmp)(const void *, const void *);
@@ -123,7 +123,7 @@ struct hash {
  * Returns:
  *    a new hash table
  */
-extern struct hash *hash_create(unsigned int (*hash_key)(void *),
+extern struct hash *hash_create(unsigned int (*hash_key)(const void *),
                                bool (*hash_cmp)(const void *, const void *),
                                const char *name);
 
@@ -158,7 +158,7 @@ extern struct hash *hash_create(unsigned int (*hash_key)(void *),
  *    a new hash table
  */
 extern struct hash *
-hash_create_size(unsigned int size, unsigned int (*hash_key)(void *),
+hash_create_size(unsigned int size, unsigned int (*hash_key)(const void *),
                 bool (*hash_cmp)(const void *, const void *),
                 const char *name);
 
index b0802da96147950c5848ed87d552b1d0e6d4e719..ca6f512ec6d6f2d85f2a4d2ff76bd0231128743a 100644 (file)
@@ -107,7 +107,7 @@ static struct if_rmap *if_rmap_get(struct if_rmap_ctx *ctx, const char *ifname)
        return ret;
 }
 
-static unsigned int if_rmap_hash_make(void *data)
+static unsigned int if_rmap_hash_make(const void *data)
 {
        const struct if_rmap *if_rmap = data;
 
index e8b3e46c19deb2c624f35ee4c9ba654204781a59..dbf90c58d4870975c4fe05d991000ec94aa39f24 100644 (file)
@@ -1654,7 +1654,7 @@ static bool running_config_entry_cmp(const void *value1, const void *value2)
        return strmatch(c1->xpath, c2->xpath);
 }
 
-static unsigned int running_config_entry_key_make(void *value)
+static unsigned int running_config_entry_key_make(const void *value)
 {
        return string_hash_make(value);
 }
index 0c75be3323bb19fd2237d28961b8ef444b1fdc54..9133b808950c64e2c0dc1718beb262c39de542eb 100644 (file)
@@ -623,7 +623,7 @@ struct route_map_list {
 static struct route_map_list route_map_master = {NULL, NULL, NULL, NULL, NULL};
 struct hash *route_map_master_hash = NULL;
 
-static unsigned int route_map_hash_key_make(void *p)
+static unsigned int route_map_hash_key_make(const void *p)
 {
        const struct route_map *map = p;
        return string_hash_make(map->name);
@@ -673,7 +673,7 @@ struct route_map_dep {
 /* Hashes maintaining dependency between various sublists used by route maps */
 struct hash *route_map_dep_hash[ROUTE_MAP_DEP_MAX];
 
-static unsigned int route_map_dep_hash_make_key(void *p);
+static unsigned int route_map_dep_hash_make_key(const void *p);
 static void route_map_clear_all_references(char *rmap_name);
 static void route_map_rule_delete(struct route_map_rule_list *,
                                  struct route_map_rule *);
@@ -1709,7 +1709,7 @@ static void *route_map_name_hash_alloc(void *p)
        return ((void *)XSTRDUP(MTYPE_ROUTE_MAP_NAME, (const char *)p));
 }
 
-static unsigned int route_map_dep_hash_make_key(void *p)
+static unsigned int route_map_dep_hash_make_key(const void *p)
 {
        return (string_hash_make((char *)p));
 }
index 5ca859a74d4c2d093c23a1ea1a5a6693711913d3..9489e3e923f31ed54a65639a4b3a6fa33908edef 100644 (file)
@@ -63,7 +63,7 @@ static struct list *masters;
 static void thread_free(struct thread_master *master, struct thread *thread);
 
 /* CLI start ---------------------------------------------------------------- */
-static unsigned int cpu_record_hash_key(struct cpu_thread_history *a)
+static unsigned int cpu_record_hash_key(const struct cpu_thread_history *a)
 {
        int size = sizeof(a->func);
 
@@ -433,7 +433,7 @@ struct thread_master *thread_master_create(const char *name)
                            sizeof(struct thread *) * rv->fd_limit);
 
        rv->cpu_record = hash_create_size(
-               8, (unsigned int (*)(void *))cpu_record_hash_key,
+               8, (unsigned int (*)(const void *))cpu_record_hash_key,
                (bool (*)(const void *, const void *))cpu_record_hash_cmp,
                "Thread Hash");
 
index 6ec3cc8e0d288b4abfc4ca7387129eab5147bcd8..229f19f29ae877a2f2b02ae7c9b65c27e36ae634 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -362,9 +362,9 @@ struct vrf_bit_set {
        bool set;
 };
 
-static unsigned int vrf_hash_bitmap_key(void *data)
+static unsigned int vrf_hash_bitmap_key(const void *data)
 {
-       struct vrf_bit_set *bit = data;
+       const struct vrf_bit_set *bit = data;
 
        return bit->vrf_id;
 }
index 69d2fa48dc0b382d2875049139f99a5ec589c5cf..8e479c931b5ac7c8cc590bd4dadcf2f9e48b4d46 100644 (file)
@@ -80,7 +80,7 @@ static int wheel_timer_thread(struct thread *t)
 }
 
 struct timer_wheel *wheel_init(struct thread_master *master, int period,
-                              size_t slots, unsigned int (*slot_key)(void *),
+                              size_t slots, unsigned int (*slot_key)(const void *),
                               void (*slot_run)(void *),
                               const char *run_name)
 {
index e66751c1d092a135dee1fb8f0c243ac522a34c94..401789e1a01d547446c0e6c55ac43d7d083d7f78 100644 (file)
@@ -38,7 +38,7 @@ struct timer_wheel {
        /*
         * Key to determine what slot the item belongs in
         */
-       unsigned int (*slot_key)(void *);
+       unsigned int (*slot_key)(const void *);
 
        void (*slot_run)(void *);
 };
@@ -80,9 +80,9 @@ struct timer_wheel {
  * of running your code.
  */
 struct timer_wheel *wheel_init(struct thread_master *master, int period,
-                              size_t slots, unsigned int (*slot_key)(void *),
-                              void (*slot_run)(void *),
-                              const char *run_name);
+                              size_t slots,
+                              unsigned int (*slot_key)(const void *),
+                              void (*slot_run)(void *), const char *run_name);
 
 /*
  * Delete the specified timer wheel created
index 69fff5dbffb0981f0dabd186d5115e34d005b9c5..341420eeda45e2360f143420f1c8c11c3c49591b 100644 (file)
@@ -61,7 +61,7 @@ static bool yang_mapping_hash_cmp(const void *value1, const void *value2)
        return strmatch(c1->xpath_from_canonical, c2->xpath_from_canonical);
 }
 
-static unsigned int yang_mapping_hash_key(void *value)
+static unsigned int yang_mapping_hash_key(const void *value)
 {
        return string_hash_make(value);
 }
index 5508778243d557e055baccc3617a764f99ec67d0..cc18b36f6ae585081b268149574434b302ea9201 100644 (file)
@@ -30,9 +30,9 @@ const char *const nhrp_cache_type_str[] = {
                [NHRP_CACHE_LOCAL] = "local",
 };
 
-static unsigned int nhrp_cache_protocol_key(void *peer_data)
+static unsigned int nhrp_cache_protocol_key(const void *peer_data)
 {
-       struct nhrp_cache *p = peer_data;
+       const struct nhrp_cache *p = peer_data;
        return sockunion_hash(&p->remote_addr);
 }
 
index db2f72ac2211e4d4e19ba320c9e51f6448f151c9..ca309f25061e936d439859394e1ca7c285e0069a 100644 (file)
@@ -151,9 +151,9 @@ static void nhrp_peer_ifp_notify(struct notifier_block *n, unsigned long cmd)
        nhrp_peer_unref(p);
 }
 
-static unsigned int nhrp_peer_key(void *peer_data)
+static unsigned int nhrp_peer_key(const void *peer_data)
 {
-       struct nhrp_peer *p = peer_data;
+       const struct nhrp_peer *p = peer_data;
        return sockunion_hash(&p->vc->remote.nbma);
 }
 
index fa3549f5edac0f8902dbc056f438fa3388acc4b2..605aa34ff9bd454e57be63d33f135a00153c2347 100644 (file)
@@ -28,9 +28,9 @@ struct child_sa {
 static struct hash *nhrp_vc_hash;
 static struct list_head childlist_head[512];
 
-static unsigned int nhrp_vc_key(void *peer_data)
+static unsigned int nhrp_vc_key(const void *peer_data)
 {
-       struct nhrp_vc *vc = peer_data;
+       const struct nhrp_vc *vc = peer_data;
        return jhash_2words(sockunion_hash(&vc->local.nbma),
                            sockunion_hash(&vc->remote.nbma), 0);
 }
index 08a007bdf933c19adb3537e16f1aef517a997419..e56bbe3bf779b238c7598a4c66f1bc100bd8a492 100644 (file)
@@ -2,9 +2,9 @@
 #include "hash.h"
 #include "nhrpd.h"
 
-static unsigned int nhrp_reqid_key(void *data)
+static unsigned int nhrp_reqid_key(const void *data)
 {
-       struct nhrp_reqid *r = data;
+       const struct nhrp_reqid *r = data;
        return r->request_id;
 }
 
index a49352086828ef72692f70d72de54638459c265d..6947393a6086b1983cfa0b3a77f7cadec4b91487 100644 (file)
@@ -86,7 +86,7 @@ static inline void del_sid_nhlfe(struct sr_nhlfe nhlfe);
  */
 
 /* Hash function for Segment Routing entry */
-static unsigned int sr_hash(void *p)
+static unsigned int sr_hash(const void *p)
 {
        const struct in_addr *rid = p;
 
index 7504752725df4d601454ab2b617dc80d296d6819..52506542bc89657e2065181768556e589bac3b36 100644 (file)
@@ -129,10 +129,10 @@ static void pbr_nh_delete_iterate(struct hash_bucket *b, void *p)
        pbr_nh_delete((struct pbr_nexthop_cache **)&b->data);
 }
 
-static uint32_t pbr_nh_hash_key(void *arg)
+static uint32_t pbr_nh_hash_key(const void *arg)
 {
        uint32_t key;
-       struct pbr_nexthop_cache *pbrnc = (struct pbr_nexthop_cache *)arg;
+       const struct pbr_nexthop_cache *pbrnc = arg;
 
        key = nexthop_hash(pbrnc->nexthop);
 
@@ -789,10 +789,9 @@ void pbr_nht_nexthop_interface_update(struct interface *ifp)
                     ifp);
 }
 
-static uint32_t pbr_nhg_hash_key(void *arg)
+static uint32_t pbr_nhg_hash_key(const void *arg)
 {
-       struct pbr_nexthop_group_cache *nhgc =
-               (struct pbr_nexthop_group_cache *)arg;
+       const struct pbr_nexthop_group_cache *nhgc = arg;
 
        return jhash(&nhgc->name, strlen(nhgc->name), 0x52c34a96);
 }
@@ -940,7 +939,7 @@ void pbr_nht_init(void)
        pbr_nhg_hash = hash_create_size(
                16, pbr_nhg_hash_key, pbr_nhg_hash_equal, "PBR NHG Cache Hash");
        pbr_nhrc_hash =
-               hash_create_size(16, (unsigned int (*)(void *))nexthop_hash,
+               hash_create_size(16, (unsigned int (*)(const void *))nexthop_hash,
                                 pbr_nhrc_hash_equal, "PBR NH Hash");
 
        pbr_nhg_low_table = PBR_NHT_DEFAULT_LOW_TABLEID;
index 3a68176510213dbd9210c13351a16fe3167a5219..352177db2bb44f3e44b11de347b62657a82bd33b 100644 (file)
@@ -1425,9 +1425,9 @@ void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel *ch, int eom,
                pim_jp_agg_single_upstream_send(&starup->rpf, starup, true);
 }
 
-unsigned int pim_ifchannel_hash_key(void *arg)
+unsigned int pim_ifchannel_hash_key(const void *arg)
 {
-       struct pim_ifchannel *ch = (struct pim_ifchannel *)arg;
+       const struct pim_ifchannel *ch = arg;
 
        return jhash_2words(ch->sg.src.s_addr, ch->sg.grp.s_addr, 0);
 }
index b9d4d291d854d910aeb96bd58048878b1786050d..b36c3236b0bd2f649d24c45a6ce010cf8ee764ea 100644 (file)
@@ -155,5 +155,5 @@ void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel *ch, int eom,
 int pim_ifchannel_compare(const struct pim_ifchannel *ch1,
                          const struct pim_ifchannel *ch2);
 
-unsigned int pim_ifchannel_hash_key(void *arg);
+unsigned int pim_ifchannel_hash_key(const void *arg);
 #endif /* PIM_IFCHANNEL_H */
index cdd156b96fa331b428748bce2b71499a93300a16..213ca48bb502efd8b74245985c6b791a3530ea73 100644 (file)
@@ -829,9 +829,9 @@ void igmp_sock_delete_all(struct interface *ifp)
        }
 }
 
-static unsigned int igmp_group_hash_key(void *arg)
+static unsigned int igmp_group_hash_key(const void *arg)
 {
-       struct igmp_group *group = (struct igmp_group *)arg;
+       const struct igmp_group *group = arg;
 
        return jhash_1word(group->group_addr.s_addr, 0);
 }
index 395c4af35f941b93f6778f691e4e599cc3f6a096..3287e137193c3eb6083036d9ff0e109b64dc9187 100644 (file)
@@ -680,9 +680,9 @@ void pim_msdp_up_del(struct pim_instance *pim, struct prefix_sg *sg)
 }
 
 /* sa hash and peer list helpers */
-static unsigned int pim_msdp_sa_hash_key_make(void *p)
+static unsigned int pim_msdp_sa_hash_key_make(const void *p)
 {
-       struct pim_msdp_sa *sa = p;
+       const struct pim_msdp_sa *sa = p;
 
        return (jhash_2words(sa->sg.src.s_addr, sa->sg.grp.s_addr, 0));
 }
@@ -1215,9 +1215,9 @@ enum pim_msdp_err pim_msdp_peer_del(struct pim_instance *pim,
 }
 
 /* peer hash and peer list helpers */
-static unsigned int pim_msdp_peer_hash_key_make(void *p)
+static unsigned int pim_msdp_peer_hash_key_make(const void *p)
 {
-       struct pim_msdp_peer *mp = p;
+       const struct pim_msdp_peer *mp = p;
        return (jhash_1word(mp->peer.s_addr, 0));
 }
 
index 5945bc55fd9299577ef155fb863a248e92e1ed1d..22045c2d337c99ac27aa2b60fa2a768e43959018 100644 (file)
@@ -91,9 +91,9 @@ static bool pim_oil_equal(const void *arg1, const void *arg2)
        return false;
 }
 
-static unsigned int pim_oil_hash_key(void *arg)
+static unsigned int pim_oil_hash_key(const void *arg)
 {
-       struct channel_oil *oil = (struct channel_oil *)arg;
+       const struct channel_oil *oil = arg;
 
        return jhash_2words(oil->oil.mfcc_mcastgrp.s_addr,
                            oil->oil.mfcc_origin.s_addr, 0);
index afe3886aa5b98e32f7d2bdb41352f89eeadf20cc..dba46e63f03a3006cdb1d7b8adc675131a98267e 100644 (file)
@@ -426,9 +426,9 @@ int pim_rpf_is_same(struct pim_rpf *rpf1, struct pim_rpf *rpf2)
        return 0;
 }
 
-unsigned int pim_rpf_hash_key(void *arg)
+unsigned int pim_rpf_hash_key(const void *arg)
 {
-       struct pim_nexthop_cache *r = (struct pim_nexthop_cache *)arg;
+       const struct pim_nexthop_cache *r = arg;
 
        return jhash_1word(r->rpf.rpf_addr.u.prefix4.s_addr, 0);
 }
index 57bb22674fa6209b64d9935b5c70b24f86e9b2ba..1172acb4b229c6196739d859f25591af2ae8e762 100644 (file)
@@ -56,7 +56,7 @@ enum pim_rpf_result { PIM_RPF_OK = 0, PIM_RPF_CHANGED, PIM_RPF_FAILURE };
 
 struct pim_upstream;
 
-unsigned int pim_rpf_hash_key(void *arg);
+unsigned int pim_rpf_hash_key(const void *arg);
 bool pim_rpf_equal(const void *arg1, const void *arg2);
 
 bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
index d829d01347e4e613b78ac3a30d99851d62bc28f8..55d998f27084bdf2e68ab7e9835c351a2fcc1dcc 100644 (file)
@@ -1629,9 +1629,9 @@ void pim_upstream_find_new_rpf(struct pim_instance *pim)
        }
 }
 
-unsigned int pim_upstream_hash_key(void *arg)
+unsigned int pim_upstream_hash_key(const void *arg)
 {
-       struct pim_upstream *up = (struct pim_upstream *)arg;
+       const struct pim_upstream *up = arg;
 
        return jhash_2words(up->sg.src.s_addr, up->sg.grp.s_addr, 0);
 }
index 13a3dcdf8ca7472c0b26fcc5b742df64ea0e2d06..102826ac71ca84af665ad5c73e5986da4352d058 100644 (file)
@@ -308,7 +308,7 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim,
 void pim_upstream_spt_prefix_list_update(struct pim_instance *pim,
                                         struct prefix_list *pl);
 
-unsigned int pim_upstream_hash_key(void *arg);
+unsigned int pim_upstream_hash_key(const void *arg);
 bool pim_upstream_equal(const void *arg1, const void *arg2);
 struct pim_upstream *pim_upstream_keep_alive_timer_proc(
                struct pim_upstream *up);
index af76c6d732cbf548c77741076b81c60b4f8752a2..1c6b56568f62202fca1803966b04012f881d84da 100644 (file)
@@ -623,9 +623,9 @@ static void pim_vxlan_term_mr_del(struct pim_vxlan_sg *vxlan_sg)
 }
 
 /************************** vxlan SG cache management ************************/
-static unsigned int pim_vxlan_sg_hash_key_make(void *p)
+static unsigned int pim_vxlan_sg_hash_key_make(const void *p)
 {
-       struct pim_vxlan_sg *vxlan_sg = p;
+       const struct pim_vxlan_sg *vxlan_sg = p;
 
        return (jhash_2words(vxlan_sg->sg.src.s_addr,
                                vxlan_sg->sg.grp.s_addr, 0));
index c03a371d885f4d2ef6383b355b9d7ca63c1a486a..c6da00418b4ab9408b056c07c17871ac6560f76b 100644 (file)
@@ -223,9 +223,9 @@ static void static_zebra_capabilities(struct zclient_capabilities *cap)
        mpls_enabled = cap->mpls_enabled;
 }
 
-static unsigned int static_nht_hash_key(void *data)
+static unsigned int static_nht_hash_key(const void *data)
 {
-       struct static_nht_data *nhtd = data;
+       const struct static_nht_data *nhtd = data;
        unsigned int key = 0;
 
        key = prefix_hash_key(nhtd->nh);
index 19a40b21841f964ac583c9121106191a980391a2..0fca571d28b07220342e48aff13c4e016c867ef0 100644 (file)
@@ -81,9 +81,9 @@ static char *format_srcdest(const struct prefix_ipv6 *dst_p,
        return rv;
 }
 
-static unsigned int log_key(void *data)
+static unsigned int log_key(const void *data)
 {
-       struct prefix *hash_entry = data;
+       const struct prefix *hash_entry = data;
        struct prefix_ipv6 *dst_p = (struct prefix_ipv6 *)&hash_entry[0];
        struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1];
        unsigned int hash = 0;
diff --git a/tools/coccinelle/hash_const.cocci b/tools/coccinelle/hash_const.cocci
new file mode 100644 (file)
index 0000000..9c53cb0
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Transition hash key signatures to take their argument as const.
+// Does not handle headers or weirdly named hash functions.
+//
+@noconst disable optional_qualifier@
+identifier A;
+identifier func =~ ".*key$|.*key_make$|.*hash_make$|.*hash_keymake$|.*hash_key$|.*hash_key.*";
+@@
+
+- func (void *A)
++ func (const void *A)
+  { ... }
+
+@ depends on noconst disable optional_qualifier @
+identifier noconst.A;
+identifier noconst.func;
+identifier b;
+type T;
+@@
+
+func( ... ) {
+<...
+-  T b = A;
++  const T b = A;
+...>
+  }
+
+@ depends on noconst disable optional_qualifier @
+identifier noconst.A;
+identifier noconst.func;
+identifier b;
+type T;
+@@
+
+func(...)
+  {
+<...
+-  T b = (T) A;
++  const T b = A;
+...>
+  }
+
+@ depends on noconst disable optional_qualifier @
+identifier noconst.A;
+identifier noconst.func;
+identifier b;
+type T;
+@@
+
+func(...)
+  {
+<...
+-  T b;
++  const T b;
+...
+   b = A;
+...>
+  }
+
+@ depends on noconst disable optional_qualifier @
+identifier noconst.A;
+identifier noconst.func;
+identifier b;
+type T;
+@@
+
+func(...)
+  {
+<...
+-  T b;
++  const T b;
+...
+-  b = (T) A;
++  b = A;
+...>
+  }
index f1082a5996cafe1a9e91e4cf4a4b3363212d9b7d..5356a7f498de3ef60fc82c2afde806e7b7ccd6ef 100644 (file)
@@ -76,7 +76,7 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p,
                            uint32_t label_index);
 static int fec_del(zebra_fec_t *fec);
 
-static unsigned int label_hash(void *p);
+static unsigned int label_hash(const void *p);
 static bool label_cmp(const void *p1, const void *p2);
 static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe,
                                     struct nexthop *nexthop);
@@ -577,7 +577,7 @@ static int fec_del(zebra_fec_t *fec)
 /*
  * Hash function for label.
  */
-static unsigned int label_hash(void *p)
+static unsigned int label_hash(const void *p)
 {
        const zebra_ile_t *ile = p;
 
index 73db567eace35a52a1e6427f120504060025ae27..a82dd4c24a856e0fb1921950b68ef6081d8589c6 100644 (file)
@@ -135,12 +135,12 @@ void zebra_pbr_rules_free(void *arg)
        XFREE(MTYPE_TMP, rule);
 }
 
-uint32_t zebra_pbr_rules_hash_key(void *arg)
+uint32_t zebra_pbr_rules_hash_key(const void *arg)
 {
-       struct zebra_pbr_rule *rule;
+       const struct zebra_pbr_rule *rule;
        uint32_t key;
 
-       rule = (struct zebra_pbr_rule *)arg;
+       rule = arg;
        key = jhash_3words(rule->rule.seq, rule->rule.priority,
                           rule->rule.action.table,
                           prefix_hash_key(&rule->rule.filter.src_ip));
@@ -250,9 +250,9 @@ void zebra_pbr_ipset_free(void *arg)
        XFREE(MTYPE_TMP, ipset);
 }
 
-uint32_t zebra_pbr_ipset_hash_key(void *arg)
+uint32_t zebra_pbr_ipset_hash_key(const void *arg)
 {
-       struct zebra_pbr_ipset *ipset = (struct zebra_pbr_ipset *)arg;
+       const struct zebra_pbr_ipset *ipset = arg;
        uint32_t *pnt = (uint32_t *)&ipset->ipset_name;
        uint32_t key = jhash_1word(ipset->vrf_id, 0x63ab42de);
 
@@ -290,12 +290,12 @@ void zebra_pbr_ipset_entry_free(void *arg)
        XFREE(MTYPE_TMP, ipset);
 }
 
-uint32_t zebra_pbr_ipset_entry_hash_key(void *arg)
+uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg)
 {
-       struct zebra_pbr_ipset_entry *ipset;
+       const struct zebra_pbr_ipset_entry *ipset;
        uint32_t key;
 
-       ipset = (struct zebra_pbr_ipset_entry *)arg;
+       ipset = arg;
        key = prefix_hash_key(&ipset->src);
        key = jhash_1word(ipset->unique, key);
        key = jhash_1word(prefix_hash_key(&ipset->dst), key);
@@ -359,9 +359,9 @@ void zebra_pbr_iptable_free(void *arg)
        XFREE(MTYPE_TMP, iptable);
 }
 
-uint32_t zebra_pbr_iptable_hash_key(void *arg)
+uint32_t zebra_pbr_iptable_hash_key(const void *arg)
 {
-       struct zebra_pbr_iptable *iptable = (struct zebra_pbr_iptable *)arg;
+       const struct zebra_pbr_iptable *iptable = arg;
        uint32_t *pnt = (uint32_t *)&(iptable->ipset_name);
        uint32_t key;
 
index 0d55491107604c39635939a8475b7affe9b43eaa..cc1cc5acd58d127386c008c6f712bb24d4b4ec6b 100644 (file)
@@ -211,7 +211,7 @@ extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable *iptable,
 extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule);
 
 extern void zebra_pbr_rules_free(void *arg);
-extern uint32_t zebra_pbr_rules_hash_key(void *arg);
+extern uint32_t zebra_pbr_rules_hash_key(const void *arg);
 extern bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2);
 
 /* has operates on 32bit pointer
@@ -220,16 +220,16 @@ extern bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2);
 #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4)
 
 extern void zebra_pbr_ipset_free(void *arg);
-extern uint32_t zebra_pbr_ipset_hash_key(void *arg);
+extern uint32_t zebra_pbr_ipset_hash_key(const void *arg);
 extern bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2);
 
 extern void zebra_pbr_ipset_entry_free(void *arg);
-extern uint32_t zebra_pbr_ipset_entry_hash_key(void *arg);
+extern uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg);
 extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1,
                                             const void *arg2);
 
 extern void zebra_pbr_iptable_free(void *arg);
-extern uint32_t zebra_pbr_iptable_hash_key(void *arg);
+extern uint32_t zebra_pbr_iptable_hash_key(const void *arg);
 extern bool zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2);
 
 extern void zebra_pbr_init(void);
index 605e9eae6683f4d52e599864e10dc0435b6f046a..feb0aadfa814ad396c0415ff2fdd83625f0dc6e5 100644 (file)
@@ -93,7 +93,7 @@ static void zvni_print_hash(struct hash_bucket *bucket, void *ctxt[]);
 static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
                                         struct ipaddr *ip, uint8_t flags,
                                         uint32_t seq, int state, uint16_t cmd);
-static unsigned int neigh_hash_keymake(void *p);
+static unsigned int neigh_hash_keymake(const void *p);
 static void *zvni_neigh_alloc(void *p);
 static zebra_neigh_t *zvni_neigh_add(zebra_vni_t *zvni, struct ipaddr *ip,
                                     struct ethaddr *mac);
@@ -149,7 +149,7 @@ static struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni);
 static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t *zl3vni);
 static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t *zl3vni);
 
-static unsigned int mac_hash_keymake(void *p);
+static unsigned int mac_hash_keymake(const void *p);
 static bool mac_cmp(const void *p1, const void *p2);
 static void *zvni_mac_alloc(void *p);
 static zebra_mac_t *zvni_mac_add(zebra_vni_t *zvni, struct ethaddr *macaddr);
@@ -168,7 +168,7 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac);
 static int zvni_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac);
 static void zvni_install_mac_hash(struct hash_bucket *bucket, void *ctxt);
 
-static unsigned int vni_hash_keymake(void *p);
+static unsigned int vni_hash_keymake(const void *p);
 static void *zvni_alloc(void *p);
 static zebra_vni_t *zvni_lookup(vni_t vni);
 static zebra_vni_t *zvni_add(vni_t vni);
@@ -213,7 +213,7 @@ static void zebra_vxlan_dup_addr_detect_for_mac(struct zebra_vrf *zvrf,
                                                bool do_dad,
                                                bool *is_dup_detect,
                                                bool is_local);
-static unsigned int zebra_vxlan_sg_hash_key_make(void *p);
+static unsigned int zebra_vxlan_sg_hash_key_make(const void *p);
 static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2);
 static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf,
                struct in_addr sip, struct in_addr mcast_grp);
@@ -2158,10 +2158,10 @@ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
 /*
  * Make hash key for neighbors.
  */
-static unsigned int neigh_hash_keymake(void *p)
+static unsigned int neigh_hash_keymake(const void *p)
 {
-       zebra_neigh_t *n = p;
-       struct ipaddr *ip = &n->ip;
+       const zebra_neigh_t *n = p;
+       const struct ipaddr *ip = &n->ip;
 
        if (IS_IPADDR_V4(ip))
                return jhash_1word(ip->ipaddr_v4.s_addr, 0);
@@ -3296,9 +3296,9 @@ static int zvni_remote_neigh_update(zebra_vni_t *zvni,
 /*
  * Make hash key for MAC.
  */
-static unsigned int mac_hash_keymake(void *p)
+static unsigned int mac_hash_keymake(const void *p)
 {
-       zebra_mac_t *pmac = p;
+       const zebra_mac_t *pmac = p;
        const void *pnt = (void *)pmac->macaddr.octet;
 
        return jhash(pnt, ETH_ALEN, 0xa5a5a55a);
@@ -3815,7 +3815,7 @@ static void zvni_read_mac_neigh(zebra_vni_t *zvni, struct interface *ifp)
 /*
  * Hash function for VNI.
  */
-static unsigned int vni_hash_keymake(void *p)
+static unsigned int vni_hash_keymake(const void *p)
 {
        const zebra_vni_t *zvni = p;
 
@@ -4688,7 +4688,7 @@ static int zl3vni_local_nh_del(zebra_l3vni_t *zl3vni, struct ipaddr *ip)
 /*
  * Hash function for L3 VNI.
  */
-static unsigned int l3vni_hash_keymake(void *p)
+static unsigned int l3vni_hash_keymake(const void *p)
 {
        const zebra_l3vni_t *zl3vni = p;
 
@@ -9457,9 +9457,9 @@ static int zebra_vxlan_sg_send(struct prefix_sg *sg,
        return zserv_send_message(client, s);
 }
 
-static unsigned int zebra_vxlan_sg_hash_key_make(void *p)
+static unsigned int zebra_vxlan_sg_hash_key_make(const void *p)
 {
-       zebra_vxlan_sg_t *vxlan_sg = p;
+       const zebra_vxlan_sg_t *vxlan_sg = p;
 
        return (jhash_2words(vxlan_sg->sg.src.s_addr,
                                vxlan_sg->sg.grp.s_addr, 0));