summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-08-14 16:25:25 +0100
committerPaul Jakma <paul@quagga.net>2008-08-22 19:52:58 +0100
commitffe11cfb0a808ae514193438616dfabc512b4cf6 (patch)
tree94452dba2c1a49d6e6a0782c6513acb36823cefc /bgpd
parent9fd4958a4eef88c536e4a5aeefce302e10ee8ee6 (diff)
[lib] hash compare function arguments ought to be const qualified
2008-08-14 Stephen Hemminger <stephen.hemminger@vyatta.com> * lib/hash.h: (struct hash) Hash comparator callback really ought to treat storage behind arguments as constant - a compare function with side-effects would be evil. * */*.c: Adjust comparator functions similarly, thus fixing at least a few compiler warnings about const qualifier being dropped. Signed-off-by: Paul Jakma <paul@quagga.net>
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgp_advertise.c6
-rw-r--r--bgpd/bgp_aspath.c14
-rw-r--r--bgpd/bgp_aspath.h4
-rw-r--r--bgpd/bgp_attr.c36
-rw-r--r--bgpd/bgp_attr.h2
-rw-r--r--bgpd/bgp_community.c3
-rw-r--r--bgpd/bgp_ecommunity.c8
-rw-r--r--bgpd/bgp_ecommunity.h2
8 files changed, 35 insertions, 40 deletions
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index 870aab13..b9f4a85b 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -72,10 +72,10 @@ baa_hash_key (void *p)
}
static int
-baa_hash_cmp (void *p1, void *p2)
+baa_hash_cmp (const void *p1, const void *p2)
{
- struct bgp_advertise_attr * baa1 = (struct bgp_advertise_attr *) p1;
- struct bgp_advertise_attr * baa2 = (struct bgp_advertise_attr *) p2;
+ const struct bgp_advertise_attr * baa1 = p1;
+ const struct bgp_advertise_attr * baa2 = p2;
return attrhash_cmp (baa1->attr, baa2->attr);
}
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 38c9caa6..006fc917 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -1347,10 +1347,10 @@ aspath_add_seq (struct aspath *aspath, as_t asno)
/* Compare leftmost AS value for MED check. If as1's leftmost AS and
as2's leftmost AS is same return 1. */
int
-aspath_cmp_left (struct aspath *aspath1, struct aspath *aspath2)
+aspath_cmp_left (const struct aspath *aspath1, const struct aspath *aspath2)
{
- struct assegment *seg1 = NULL;
- struct assegment *seg2 = NULL;
+ const struct assegment *seg1 = NULL;
+ const struct assegment *seg2 = NULL;
if (!(aspath1 && aspath2))
return 0;
@@ -1484,7 +1484,7 @@ aspath_reconcile_as4 ( struct aspath *aspath, struct aspath *as4path)
as2's leftmost AS is same return 1. (confederation as-path
only). */
int
-aspath_cmp_left_confed (struct aspath *aspath1, struct aspath *aspath2)
+aspath_cmp_left_confed (const struct aspath *aspath1, const struct aspath *aspath2)
{
if (! (aspath1 && aspath2) )
return 0;
@@ -1769,10 +1769,10 @@ aspath_key_make (void *p)
/* If two aspath have same value then return 1 else return 0 */
static int
-aspath_cmp (void *arg1, void *arg2)
+aspath_cmp (const void *arg1, const void *arg2)
{
- struct assegment *seg1 = ((struct aspath *)arg1)->segments;
- struct assegment *seg2 = ((struct aspath *)arg2)->segments;
+ const struct assegment *seg1 = ((struct aspath *)arg1)->segments;
+ const struct assegment *seg2 = ((struct aspath *)arg2)->segments;
while (seg1 || seg2)
{
diff --git a/bgpd/bgp_aspath.h b/bgpd/bgp_aspath.h
index d8b41fa9..2b4625c8 100644
--- a/bgpd/bgp_aspath.h
+++ b/bgpd/bgp_aspath.h
@@ -72,8 +72,8 @@ extern struct aspath *aspath_prepend (struct aspath *, struct aspath *);
extern struct aspath *aspath_filter_exclude (struct aspath *, struct aspath *);
extern struct aspath *aspath_add_seq (struct aspath *, as_t);
extern struct aspath *aspath_add_confed_seq (struct aspath *, as_t);
-extern int aspath_cmp_left (struct aspath *, struct aspath *);
-extern int aspath_cmp_left_confed (struct aspath *, struct aspath *);
+extern int aspath_cmp_left (const struct aspath *, const struct aspath *);
+extern int aspath_cmp_left_confed (const struct aspath *, const struct aspath *);
extern struct aspath *aspath_delete_confed_seq (struct aspath *);
extern struct aspath *aspath_empty (void);
extern struct aspath *aspath_empty_get (void);
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 752099d1..6f139742 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -131,15 +131,13 @@ cluster_hash_key_make (void *p)
}
static int
-cluster_hash_cmp (void *p1, void *p2)
+cluster_hash_cmp (const void *p1, const void *p2)
{
- struct cluster_list * cluster1 = (struct cluster_list *) p1;
- struct cluster_list * cluster2 = (struct cluster_list *) p2;
+ const struct cluster_list * cluster1 = p1;
+ const struct cluster_list * cluster2 = p2;
- if (cluster1->length == cluster2->length &&
- memcmp (cluster1->list, cluster2->list, cluster1->length) == 0)
- return 1;
- return 0;
+ return (cluster1->length == cluster2->length &&
+ memcmp (cluster1->list, cluster2->list, cluster1->length) == 0);
}
static void
@@ -267,15 +265,13 @@ transit_hash_key_make (void *p)
}
static int
-transit_hash_cmp (void *p1, void *p2)
+transit_hash_cmp (const void *p1, const void *p2)
{
- struct transit * transit1 = (struct transit *) p1;
- struct transit * transit2 = (struct transit *) p2;
+ const struct transit * transit1 = p1;
+ const struct transit * transit2 = p2;
- if (transit1->length == transit2->length &&
- memcmp (transit1->val, transit2->val, transit1->length) == 0)
- return 1;
- return 0;
+ return (transit1->length == transit2->length &&
+ memcmp (transit1->val, transit2->val, transit1->length) == 0);
}
static void
@@ -393,10 +389,10 @@ attrhash_key_make (void *p)
}
int
-attrhash_cmp (void *p1, void *p2)
+attrhash_cmp (const void *p1, const void *p2)
{
- struct attr * attr1 = (struct attr *) p1;
- struct attr * attr2 = (struct attr *) p2;
+ const struct attr * attr1 = p1;
+ const struct attr * attr2 = p2;
if (attr1->flag == attr2->flag
&& attr1->origin == attr2->origin
@@ -408,8 +404,8 @@ attrhash_cmp (void *p1, void *p2)
&& attr1->pathlimit.ttl == attr2->pathlimit.ttl
&& attr1->pathlimit.as == attr2->pathlimit.as)
{
- struct attr_extra *ae1 = attr1->extra;
- struct attr_extra *ae2 = attr2->extra;
+ const struct attr_extra *ae1 = attr1->extra;
+ const struct attr_extra *ae2 = attr2->extra;
if (ae1 && ae2
&& ae1->aggregator_as == ae2->aggregator_as
@@ -435,7 +431,7 @@ attrhash_cmp (void *p1, void *p2)
}
static void
-attrhash_init ()
+attrhash_init (void)
{
attrhash = hash_create (attrhash_key_make, attrhash_cmp);
}
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 9647ccf8..12149a17 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -163,7 +163,7 @@ extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
struct prefix_rd *, u_char *);
extern void bgp_dump_routes_attr (struct stream *, struct attr *,
struct prefix *);
-extern int attrhash_cmp (void *, void *);
+extern int attrhash_cmp (const void *, const void *);
extern unsigned int attrhash_key_make (void *);
extern void attr_show_all (struct vty *);
extern unsigned long int attr_count (void);
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index 592b810d..1cafdb3e 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -633,5 +633,6 @@ community_hash (void)
void
community_init (void)
{
- comhash = hash_create (community_hash_make, community_cmp);
+ comhash = hash_create ((unsigned int (*) (void *))community_hash_make,
+ (int (*) (const void *, const void *))community_cmp);
}
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 9e7ae1b3..c08673ce 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -247,15 +247,13 @@ ecommunity_hash_make (void *arg)
/* Compare two Extended Communities Attribute structure. */
int
-ecommunity_cmp (void *arg1, void *arg2)
+ecommunity_cmp (const void *arg1, const void *arg2)
{
const struct ecommunity *ecom1 = arg1;
const struct ecommunity *ecom2 = arg2;
- if (ecom1->size == ecom2->size
- && memcmp (ecom1->val, ecom2->val, ecom1->size * ECOMMUNITY_SIZE) == 0)
- return 1;
- return 0;
+ return (ecom1->size == ecom2->size
+ && memcmp (ecom1->val, ecom2->val, ecom1->size * ECOMMUNITY_SIZE) == 0);
}
/* Initialize Extended Comminities related hash. */
diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h
index 69014237..278721c8 100644
--- a/bgpd/bgp_ecommunity.h
+++ b/bgpd/bgp_ecommunity.h
@@ -72,7 +72,7 @@ extern struct ecommunity *ecommunity_parse (u_int8_t *, u_short);
extern struct ecommunity *ecommunity_dup (struct ecommunity *);
extern struct ecommunity *ecommunity_merge (struct ecommunity *, struct ecommunity *);
extern struct ecommunity *ecommunity_intern (struct ecommunity *);
-extern int ecommunity_cmp (void *, void *);
+extern int ecommunity_cmp (const void *, const void *);
extern void ecommunity_unintern (struct ecommunity *);
extern unsigned int ecommunity_hash_make (void *);
extern struct ecommunity *ecommunity_str2com (const char *, int, int);