bgpd, isisd, lib: Make key values const for skiplist

Make some key values const for the skiplist code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2020-03-21 22:56:03 -04:00
parent cb9f254c01
commit 1a4189d4a1
14 changed files with 49 additions and 46 deletions

View File

@ -81,10 +81,10 @@
* is used to spread out the sort for adbs with the same lifetime
* and thereby make the skip list operations more efficient.
*/
static int sl_adb_lifetime_cmp(void *adb1, void *adb2)
static int sl_adb_lifetime_cmp(const void *adb1, const void *adb2)
{
struct rfapi_adb *a1 = adb1;
struct rfapi_adb *a2 = adb2;
const struct rfapi_adb *a1 = adb1;
const struct rfapi_adb *a2 = adb2;
if (a1->lifetime < a2->lifetime)
return -1;

View File

@ -2006,10 +2006,10 @@ static void rfapiBgpInfoDetach(struct agg_node *rn, struct bgp_path_info *bpi)
/*
* For L3-indexed import tables
*/
static int rfapi_bi_peer_rd_cmp(void *b1, void *b2)
static int rfapi_bi_peer_rd_cmp(const void *b1, const void *b2)
{
struct bgp_path_info *bpi1 = b1;
struct bgp_path_info *bpi2 = b2;
const struct bgp_path_info *bpi1 = b1;
const struct bgp_path_info *bpi2 = b2;
/*
* Compare peers
@ -2022,8 +2022,9 @@ static int rfapi_bi_peer_rd_cmp(void *b1, void *b2)
/*
* compare RDs
*/
return vnc_prefix_cmp((struct prefix *)&bpi1->extra->vnc.import.rd,
(struct prefix *)&bpi2->extra->vnc.import.rd);
return vnc_prefix_cmp(
(const struct prefix *)&bpi1->extra->vnc.import.rd,
(const struct prefix *)&bpi2->extra->vnc.import.rd);
}
/*
@ -2031,10 +2032,10 @@ static int rfapi_bi_peer_rd_cmp(void *b1, void *b2)
* The BPIs in these tables should ALWAYS have an aux_prefix set because
* they arrive via IPv4 or IPv6 advertisements.
*/
static int rfapi_bi_peer_rd_aux_cmp(void *b1, void *b2)
static int rfapi_bi_peer_rd_aux_cmp(const void *b1, const void *b2)
{
struct bgp_path_info *bpi1 = b1;
struct bgp_path_info *bpi2 = b2;
const struct bgp_path_info *bpi1 = b1;
const struct bgp_path_info *bpi2 = b2;
int rc;
/*

View File

@ -1103,10 +1103,10 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m)
m->rfd->response_lifetime, &m->timer);
}
static int mon_eth_cmp(void *a, void *b)
static int mon_eth_cmp(const void *a, const void *b)
{
struct rfapi_monitor_eth *m1;
struct rfapi_monitor_eth *m2;
const struct rfapi_monitor_eth *m1;
const struct rfapi_monitor_eth *m2;
int i;

View File

@ -58,10 +58,10 @@ static void logdifferent(const char *tag, struct rfapi_nve_addr *a,
#endif
int rfapi_nve_addr_cmp(void *k1, void *k2)
int rfapi_nve_addr_cmp(const void *k1, const void *k2)
{
struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1;
struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2;
const struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1;
const struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2;
int ret = 0;
if (!a || !b) {

View File

@ -30,7 +30,7 @@ struct rfapi_nve_addr {
};
extern int rfapi_nve_addr_cmp(void *k1, void *k2);
extern int rfapi_nve_addr_cmp(const void *k1, const void *k2);
extern void rfapiNveAddr2Str(struct rfapi_nve_addr *na, char *buf, int bufsize);

View File

@ -388,10 +388,10 @@ extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */
/*
* Compares two <struct rfapi_rib_key>s
*/
int rfapi_rib_key_cmp(void *k1, void *k2)
int rfapi_rib_key_cmp(const void *k1, const void *k2)
{
struct rfapi_rib_key *a = (struct rfapi_rib_key *)k1;
struct rfapi_rib_key *b = (struct rfapi_rib_key *)k2;
const struct rfapi_rib_key *a = (struct rfapi_rib_key *)k1;
const struct rfapi_rib_key *b = (struct rfapi_rib_key *)k2;
int ret;
if (!a || !b)

View File

@ -147,7 +147,7 @@ extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */
struct prefix *aux, /* may be NULL */
struct rfapi_rib_key *rk);
extern int rfapi_rib_key_cmp(void *k1, void *k2);
extern int rfapi_rib_key_cmp(const void *k1, const void *k2);
extern void rfapiAdbFree(struct rfapi_adb *adb);

View File

@ -2754,10 +2754,10 @@ static void nve_addr_free(void *hap)
XFREE(MTYPE_RFAPI_NVE_ADDR, hap);
}
static int nve_addr_cmp(void *k1, void *k2)
static int nve_addr_cmp(const void *k1, const void *k2)
{
struct nve_addr *a = (struct nve_addr *)k1;
struct nve_addr *b = (struct nve_addr *)k2;
const struct nve_addr *a = (struct nve_addr *)k1;
const struct nve_addr *b = (struct nve_addr *)k2;
int ret = 0;
if (!a || !b) {

View File

@ -128,14 +128,14 @@ struct prefix_bag {
static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0,
0xf8, 0xfc, 0xfe, 0xff};
int vnc_prefix_cmp(void *pfx1, void *pfx2)
int vnc_prefix_cmp(const void *pfx1, const void *pfx2)
{
int offset;
int shift;
uint8_t mask;
struct prefix *p1 = pfx1;
struct prefix *p2 = pfx2;
const struct prefix *p1 = pfx1;
const struct prefix *p2 = pfx2;
if (p1->family < p2->family)
return -1;

View File

@ -32,7 +32,7 @@
extern uint32_t calc_local_pref(struct attr *attr, struct peer *peer);
extern int vnc_prefix_cmp(void *pfx1, void *pfx2);
extern int vnc_prefix_cmp(const void *pfx1, const void *pfx2);
extern void vnc_import_bgp_add_route(struct bgp *bgp, struct prefix *prefix,
struct bgp_path_info *info);

View File

@ -122,9 +122,9 @@ static bool neighbor_entry_hash_cmp(const void *a, const void *b)
return memcmp(na->id, nb->id, sizeof(na->id)) == 0;
}
static int neighbor_entry_list_cmp(void *a, void *b)
static int neighbor_entry_list_cmp(const void *a, const void *b)
{
struct neighbor_entry *na = a, *nb = b;
const struct neighbor_entry *na = a, *nb = b;
return -memcmp(na->id, nb->id, sizeof(na->id));
}

View File

@ -117,11 +117,11 @@ static bool isis_vertex_queue_hash_cmp(const void *a, const void *b)
* Compares vertizes for sorting in the TENT list. Returns true
* if candidate should be considered before current, false otherwise.
*/
__attribute__((__unused__))
static int isis_vertex_queue_tent_cmp(void *a, void *b)
__attribute__((__unused__)) static int isis_vertex_queue_tent_cmp(const void *a,
const void *b)
{
struct isis_vertex *va = a;
struct isis_vertex *vb = b;
const struct isis_vertex *va = a;
const struct isis_vertex *vb = b;
if (va->d_N < vb->d_N)
return -1;

View File

@ -112,7 +112,7 @@ static int randomLevel(void)
return level;
}
static int default_cmp(void *key1, void *key2)
static int default_cmp(const void *key1, const void *key2)
{
if (key1 < key2)
return -1;
@ -126,7 +126,8 @@ unsigned int skiplist_count(struct skiplist *l)
return l->count;
}
struct skiplist *skiplist_new(int flags, int (*cmp)(void *key1, void *key2),
struct skiplist *skiplist_new(int flags,
int (*cmp)(const void *key1, const void *key2),
void (*del)(void *val))
{
struct skiplist *new;
@ -329,7 +330,7 @@ int skiplist_delete(register struct skiplist *l, register void *key,
* Also set a cursor for use with skiplist_next_value.
*/
int skiplist_first_value(register struct skiplist *l, /* in */
register void *key, /* in */
register const void *key, /* in */
void **valuePointer, /* out */
void **cursor) /* out */
{
@ -374,7 +375,7 @@ int skiplist_search(register struct skiplist *l, register void *key,
* last element with the given key, -1 is returned.
*/
int skiplist_next_value(register struct skiplist *l, /* in */
register void *key, /* in */
register const void *key, /* in */
void **valuePointer, /* in/out */
void **cursor) /* in/out */
{

View File

@ -68,7 +68,7 @@ struct skiplist {
* Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2.
* Used as definition of sorted for listnode_add_sort
*/
int (*cmp)(void *val1, void *val2);
int (*cmp)(const void *val1, const void *val2);
/* callback to free user-owned data when listnode is deleted. supplying
* this callback is very much encouraged!
@ -81,7 +81,8 @@ struct skiplist {
extern struct skiplist *
skiplist_new(/* encouraged: set list.del callback on new lists */
int flags,
int (*cmp)(void *key1, void *key2), /* NULL => default cmp */
int (*cmp)(const void *key1,
const void *key2), /* NULL => default cmp */
void (*del)(void *val)); /* NULL => no auto val free */
extern void skiplist_free(struct skiplist *);
@ -96,12 +97,12 @@ extern int skiplist_search(register struct skiplist *l, register void *key,
void **valuePointer);
extern int skiplist_first_value(register struct skiplist *l, /* in */
register void *key, /* in */
register const void *key, /* in */
void **valuePointer, /* in/out */
void **cursor); /* out */
extern int skiplist_next_value(register struct skiplist *l, /* in */
register void *key, /* in */
register const void *key, /* in */
void **valuePointer, /* in/out */
void **cursor); /* in/out */