diff --git a/sys/netpfil/ipfilter/netinet/radix_ipf.h b/sys/netpfil/ipfilter/netinet/radix_ipf.h --- a/sys/netpfil/ipfilter/netinet/radix_ipf.h +++ b/sys/netpfil/ipfilter/netinet/radix_ipf.h @@ -6,15 +6,23 @@ #ifndef __RADIX_IPF_H__ #define __RADIX_IPF_H__ -#ifndef U_32_T -typedef unsigned int u_32_t; -# define U_32_T 1 +#ifndef RADIX_T +# ifdef __LP64__ +/* 128-bit keys are easily supported on 64-bit platforms, */ +/* supporting IPv6. */ +typedef unsigned __int128 radix_t; +# else +/* 32-bit platforms will disappear in a short while, */ +/* are therefore not supported by 128-bit (IPv6) keys. */ +typedef unsigned int radix_t; +# endif +# define RADIX_T 1 #endif typedef struct ipf_rdx_mask { struct ipf_rdx_mask *next; struct ipf_rdx_node *node; - u_32_t *mask; + radix_t *mask; int maskbitcount; } ipf_rdx_mask_t; @@ -25,12 +33,12 @@ struct ipf_rdx_node *dupkey; struct ipf_rdx_mask *masks; struct ipf_rdx_mask *mymask; - u_32_t *addrkey; - u_32_t *maskkey; - u_32_t *addroff; - u_32_t *maskoff; - u_32_t lastmask; - u_32_t bitmask; + radix_t *addrkey; + radix_t *maskkey; + radix_t *addroff; + radix_t *maskoff; + radix_t lastmask; + radix_t bitmask; int offset; int index; int maskbitcount; diff --git a/sys/netpfil/ipfilter/netinet/radix_ipf.c b/sys/netpfil/ipfilter/netinet/radix_ipf.c --- a/sys/netpfil/ipfilter/netinet/radix_ipf.c +++ b/sys/netpfil/ipfilter/netinet/radix_ipf.c @@ -32,10 +32,10 @@ static ipf_rdx_node_t *ipf_rx_insert(ipf_rdx_head_t *, ipf_rdx_node_t nodes[2], int *); static void ipf_rx_attach_mask(ipf_rdx_node_t *, ipf_rdx_mask_t *); -static int count_mask_bits(addrfamily_t *, u_32_t **); +static int count_mask_bits(addrfamily_t *, radix_t **); static void buildnodes(addrfamily_t *, addrfamily_t *, ipf_rdx_node_t n[2]); -static ipf_rdx_node_t *ipf_rx_find_addr(ipf_rdx_node_t *, u_32_t *); +static ipf_rdx_node_t *ipf_rx_find_addr(ipf_rdx_node_t *, radix_t *); static ipf_rdx_node_t *ipf_rx_lookup(ipf_rdx_head_t *, addrfamily_t *, addrfamily_t *); static ipf_rdx_node_t *ipf_rx_match(ipf_rdx_head_t *, addrfamily_t *); @@ -63,10 +63,10 @@ /* as the guide for which bit is the most significant bit. */ /* ------------------------------------------------------------------------ */ static int -count_mask_bits(addrfamily_t *mask, u_32_t **lastp) +count_mask_bits(addrfamily_t *mask, radix_t **lastp) { - u_32_t *mp = (u_32_t *)&mask->adf_addr; - u_32_t m; + radix_t *mp = (radix_t *)&mask->adf_addr; + radix_t m; int count = 0; int mlen; @@ -100,9 +100,9 @@ static void buildnodes(addrfamily_t *addr, addrfamily_t *mask, ipf_rdx_node_t nodes[2]) { - u_32_t maskbits; - u_32_t lastmask; - u_32_t *last; + radix_t maskbits; + radix_t lastmask; + radix_t *last; int masklen; last = NULL; @@ -111,15 +111,15 @@ masklen = 0; lastmask = 0; } else { - masklen = last - (u_32_t *)mask; + masklen = last - (radix_t *)mask; lastmask = *last; } bzero(&nodes[0], sizeof(ipf_rdx_node_t) * 2); nodes[0].maskbitcount = maskbits; nodes[0].index = -1 - (ADF_OFF_BITS + maskbits); - nodes[0].addrkey = (u_32_t *)addr; - nodes[0].maskkey = (u_32_t *)mask; + nodes[0].addrkey = (radix_t *)addr; + nodes[0].maskkey = (radix_t *)mask; nodes[0].addroff = nodes[0].addrkey + masklen; nodes[0].maskoff = nodes[0].maskkey + masklen; nodes[0].parent = &nodes[1]; @@ -145,7 +145,7 @@ /* match for the address given by "addr". */ /* ------------------------------------------------------------------------ */ static ipf_rdx_node_t * -ipf_rx_find_addr(ipf_rdx_node_t *tree, u_32_t *addr) +ipf_rx_find_addr(ipf_rdx_node_t *tree, radix_t *addr) { ipf_rdx_node_t *cur; @@ -180,16 +180,16 @@ ipf_rdx_node_t *prev; ipf_rdx_node_t *node; ipf_rdx_node_t *cur; - u_32_t *data; - u_32_t *mask; - u_32_t *key; - u_32_t *end; + radix_t *data; + radix_t *mask; + radix_t *key; + radix_t *end; int len; int i; len = addr->adf_len; - end = (u_32_t *)((u_char *)addr + len); - node = ipf_rx_find_addr(head->root, (u_32_t *)addr); + end = (radix_t *)((u_char *)addr + len); + node = ipf_rx_find_addr(head->root, (radix_t *)addr); /* * Search the dupkey list for a potential match. @@ -198,7 +198,7 @@ i = cur[0].addroff - cur[0].addrkey; data = cur[0].addrkey + i; mask = cur[0].maskkey + i; - key = (u_32_t *)addr + i; + key = (radix_t *)addr + i; for (; key < end; data++, key++, mask++) if ((*key & *mask) != *data) break; @@ -206,7 +206,7 @@ return (cur); /* Equal keys */ } prev = node->parent; - key = (u_32_t *)addr; + key = (radix_t *)addr; for (node = prev; node->root == 0; node = node->parent) { /* @@ -247,10 +247,10 @@ { ipf_rdx_node_t *found; ipf_rdx_node_t *node; - u_32_t *akey; + radix_t *akey; int count; - found = ipf_rx_find_addr(head->root, (u_32_t *)addr); + found = ipf_rx_find_addr(head->root, (radix_t *)addr); if (found->root == 1) return (NULL); @@ -263,7 +263,7 @@ if (count != found->maskbitcount && found->dupkey == NULL) return (NULL); - akey = (u_32_t *)addr; + akey = (radix_t *)addr; if ((found->addrkey[found->offset] & found->maskkey[found->offset]) != akey[found->offset]) return (NULL); @@ -325,13 +325,13 @@ ipf_rdx_node_t *prev; ipf_rdx_mask_t *mask; ipf_rdx_node_t *cur; - u_32_t nodemask; - u_32_t *addr; - u_32_t *data; + radix_t nodemask; + radix_t *addr; + radix_t *data; int nodebits; - u_32_t *key; - u_32_t *end; - u_32_t bits; + radix_t *key; + radix_t *end; + radix_t bits; int nodekey; int nodeoff; int nlen; @@ -339,11 +339,11 @@ addr = nodes[0].addrkey; - node = ipf_rx_find_addr(head->root, addr); + node = ipf_rx_find_addr(head->root, (radix_t *) addr); len = ((addrfamily_t *)addr)->adf_len; - key = (u_32_t *)&((addrfamily_t *)addr)->adf_addr; - data= (u_32_t *)&((addrfamily_t *)node->addrkey)->adf_addr; - end = (u_32_t *)((u_char *)addr + len); + key = (radix_t *)&((addrfamily_t *)addr)->adf_addr; + data= (radix_t *)&((addrfamily_t *)node->addrkey)->adf_addr; + end = (radix_t *)((u_char *)addr + len); for (nlen = 0; key < end; data++, key++, nlen += 32) if (*key != *data) break; @@ -577,7 +577,7 @@ ipf_rdx_mask_t *m; int count; - found = ipf_rx_find_addr(head->root, (u_32_t *)addr); + found = ipf_rx_find_addr(head->root, (radix_t *)addr); if (found == NULL) return (NULL); if (found->root == 1) @@ -817,8 +817,8 @@ node[2].offset = ADF_OFF_BITS >> 5; node[1].left = &node[0]; node[1].right = &node[2]; - node[0].addrkey = (u_32_t *)softr->zeros; - node[2].addrkey = (u_32_t *)softr->ones; + node[0].addrkey = (radix_t *)softr->zeros; + node[2].addrkey = (radix_t *)softr->ones; #ifdef RDX_DEBUG (void) strcpy(node[0].name, "0_ROOT"); (void) strcpy(node[1].name, "1_ROOT");