aboutsummaryrefslogtreecommitdiff
path: root/sys/net/radix.c
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2022-07-28 13:04:43 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2022-08-01 07:32:40 +0000
commit97ffaff85968d09f2319156cb0ef56743667db6e (patch)
tree9f53d6b846bf7e0cfb83716a6317d485ecdd835a /sys/net/radix.c
parent2717e958df537b2885fdf42635d7b9dc793719b2 (diff)
downloadsrc-97ffaff85968d09f2319156cb0ef56743667db6e.tar.gz
src-97ffaff85968d09f2319156cb0ef56743667db6e.zip
net: constantify radix.c functions
Mark dst/mask public API functions fields as const to clearly indicate that these parameters are not modified or stored in the datastructure. Differential Revision: https://reviews.freebsd.org/D35971 MFC after: 2 weeks
Diffstat (limited to 'sys/net/radix.c')
-rw-r--r--sys/net/radix.c78
1 files changed, 40 insertions, 38 deletions
diff --git a/sys/net/radix.c b/sys/net/radix.c
index 2169361c7229..14e81ebbd414 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -58,9 +58,9 @@ static struct radix_node
*rn_insert(void *, struct radix_head *, int *,
struct radix_node [2]),
*rn_newpair(void *, int, struct radix_node[2]),
- *rn_search(void *, struct radix_node *),
- *rn_search_m(void *, struct radix_node *, void *);
-static struct radix_node *rn_addmask(void *, struct radix_mask_head *, int,int);
+ *rn_search(const void *, struct radix_node *),
+ *rn_search_m(const void *, struct radix_node *, void *);
+static struct radix_node *rn_addmask(const void *, struct radix_mask_head *, int,int);
static void rn_detachhead_internal(struct radix_head *);
@@ -74,11 +74,11 @@ static char rn_ones[RADIX_MAX_KEY_LEN] = {
-1, -1, -1, -1, -1, -1, -1, -1,
};
-static int rn_lexobetter(void *m_arg, void *n_arg);
+static int rn_lexobetter(const void *m_arg, const void *n_arg);
static struct radix_mask *
rn_new_radix_mask(struct radix_node *tt,
struct radix_mask *next);
-static int rn_satisfies_leaf(char *trial, struct radix_node *leaf,
+static int rn_satisfies_leaf(const char *trial, struct radix_node *leaf,
int skip);
/*
@@ -142,10 +142,10 @@ static int rn_satisfies_leaf(char *trial, struct radix_node *leaf,
* Search a node in the tree matching the key.
*/
static struct radix_node *
-rn_search(void *v_arg, struct radix_node *head)
+rn_search(const void *v_arg, struct radix_node *head)
{
struct radix_node *x;
- caddr_t v;
+ c_caddr_t v;
for (x = head, v = v_arg; x->rn_bit >= 0;) {
if (x->rn_bmask & v[x->rn_offset])
@@ -161,10 +161,10 @@ rn_search(void *v_arg, struct radix_node *head)
* XXX note this function is used only once.
*/
static struct radix_node *
-rn_search_m(void *v_arg, struct radix_node *head, void *m_arg)
+rn_search_m(const void *v_arg, struct radix_node *head, void *m_arg)
{
struct radix_node *x;
- caddr_t v = v_arg, m = m_arg;
+ c_caddr_t v = v_arg, m = m_arg;
for (x = head; x->rn_bit >= 0;) {
if ((x->rn_bmask & m[x->rn_offset]) &&
@@ -177,10 +177,10 @@ rn_search_m(void *v_arg, struct radix_node *head, void *m_arg)
}
int
-rn_refines(void *m_arg, void *n_arg)
+rn_refines(const void *m_arg, const void *n_arg)
{
- caddr_t m = m_arg, n = n_arg;
- caddr_t lim, lim2 = lim = n + LEN(n);
+ c_caddr_t m = m_arg, n = n_arg;
+ c_caddr_t lim, lim2 = lim = n + LEN(n);
int longer = LEN(n++) - LEN(m++);
int masks_are_equal = 1;
@@ -209,7 +209,7 @@ rn_refines(void *m_arg, void *n_arg)
* from host routes.
*/
struct radix_node *
-rn_lookup(void *v_arg, void *m_arg, struct radix_head *head)
+rn_lookup(const void *v_arg, const void *m_arg, struct radix_head *head)
{
struct radix_node *x;
caddr_t netmask;
@@ -250,10 +250,10 @@ rn_lookup(void *v_arg, void *m_arg, struct radix_head *head)
}
static int
-rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip)
+rn_satisfies_leaf(const char *trial, struct radix_node *leaf, int skip)
{
- char *cp = trial, *cp2 = leaf->rn_key, *cp3 = leaf->rn_mask;
- char *cplim;
+ const char *cp = trial, *cp2 = leaf->rn_key, *cp3 = leaf->rn_mask;
+ const char *cplim;
int length = min(LEN(cp), LEN(cp2));
if (cp3 == NULL)
@@ -271,12 +271,12 @@ rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip)
* Search for longest-prefix match in given @head
*/
struct radix_node *
-rn_match(void *v_arg, struct radix_head *head)
+rn_match(const void *v_arg, struct radix_head *head)
{
- caddr_t v = v_arg;
+ c_caddr_t v = v_arg;
struct radix_node *t = head->rnh_treetop, *x;
- caddr_t cp = v, cp2;
- caddr_t cplim;
+ c_caddr_t cp = v, cp2;
+ c_caddr_t cplim;
struct radix_node *saved_t, *top = t;
int off = t->rn_offset, vlen = LEN(cp), matched_off;
int test, b, rn_bit;
@@ -498,10 +498,11 @@ on1:
}
static struct radix_node *
-rn_addmask(void *n_arg, struct radix_mask_head *maskhead, int search, int skip)
+rn_addmask(const void *n_arg, struct radix_mask_head *maskhead, int search, int skip)
{
- unsigned char *netmask = n_arg;
- unsigned char *cp, *cplim;
+ const unsigned char *netmask = n_arg;
+ const unsigned char *c, *clim;
+ unsigned char *cp;
struct radix_node *x;
int b = 0, mlen, j;
int maskduplicated, isnormal;
@@ -552,17 +553,17 @@ rn_addmask(void *n_arg, struct radix_mask_head *maskhead, int search, int skip)
* a non-contiguous mask.
*/
#define CONTIG(_c) (((~(_c) + 1) & (_c)) == (unsigned char)(~(_c) + 1))
- cplim = netmask + mlen;
+ clim = netmask + mlen;
isnormal = 1;
- for (cp = netmask + skip; (cp < cplim) && *(u_char *)cp == 0xff;)
- cp++;
- if (cp != cplim) {
- for (j = 0x80; (j & *cp) != 0; j >>= 1)
+ for (c = netmask + skip; (c < clim) && *(const u_char *)c == 0xff;)
+ c++;
+ if (c != clim) {
+ for (j = 0x80; (j & *c) != 0; j >>= 1)
b++;
- if (!CONTIG(*cp) || cp != (cplim - 1))
+ if (!CONTIG(*c) || c != (clim - 1))
isnormal = 0;
}
- b += (cp - netmask) << 3;
+ b += (c - netmask) << 3;
x->rn_bit = -1 - b;
if (isnormal)
x->rn_flags |= RNF_NORMAL;
@@ -570,9 +571,9 @@ rn_addmask(void *n_arg, struct radix_mask_head *maskhead, int search, int skip)
}
static int /* XXX: arbitrary ordering for non-contiguous masks */
-rn_lexobetter(void *m_arg, void *n_arg)
+rn_lexobetter(const void *m_arg, const void *n_arg)
{
- u_char *mp = m_arg, *np = n_arg, *lim;
+ const u_char *mp = m_arg, *np = n_arg, *lim;
if (LEN(mp) > LEN(np))
return (1); /* not really, but need to check longer one first */
@@ -606,10 +607,10 @@ rn_new_radix_mask(struct radix_node *tt, struct radix_mask *next)
}
struct radix_node *
-rn_addroute(void *v_arg, void *n_arg, struct radix_head *head,
+rn_addroute(void *v_arg, const void *n_arg, struct radix_head *head,
struct radix_node treenodes[2])
{
- caddr_t v = (caddr_t)v_arg, netmask = (caddr_t)n_arg;
+ caddr_t v = (caddr_t)v_arg, netmask = NULL;
struct radix_node *t, *x = NULL, *tt;
struct radix_node *saved_tt, *top = head->rnh_treetop;
short b = 0, b_leaf = 0;
@@ -624,8 +625,8 @@ rn_addroute(void *v_arg, void *n_arg, struct radix_head *head,
* the mask to speed avoiding duplicate references at
* nodes and possibly save time in calculating indices.
*/
- if (netmask) {
- x = rn_addmask(netmask, head->rnh_masks, 0, top->rn_offset);
+ if (n_arg) {
+ x = rn_addmask(n_arg, head->rnh_masks, 0, top->rn_offset);
if (x == NULL)
return (0);
b_leaf = x->rn_bit;
@@ -763,12 +764,13 @@ on2:
}
struct radix_node *
-rn_delete(void *v_arg, void *netmask_arg, struct radix_head *head)
+rn_delete(const void *v_arg, const void *netmask_arg, struct radix_head *head)
{
struct radix_node *t, *p, *x, *tt;
struct radix_mask *m, *saved_m, **mp;
struct radix_node *dupedkey, *saved_tt, *top;
- caddr_t v, netmask;
+ c_caddr_t v;
+ c_caddr_t netmask;
int b, head_off, vlen;
v = v_arg;