Index: art.c =================================================================== RCS file: /cvs/src/sys/net/art.c,v retrieving revision 1.22 diff -u -p -r1.22 art.c --- art.c 19 Jul 2016 10:51:44 -0000 1.22 +++ art.c 15 Aug 2016 09:58:18 -0000 @@ -172,33 +172,12 @@ art_check_duplicate(struct art_root *ar, return (0); } -/* - * Return the base index of the part of ``addr'' and ``plen'' - * corresponding to the range covered by the table ``at''. - * - * In other words, this function take the multi-level (complete) - * address ``addr'' and prefix length ``plen'' and return the - * single level base index for the table ``at''. - * - * For example with an address size of 32bit divided into four - * 8bit-long tables, there's a maximum of 4 base indexes if the - * prefix length is > 24. - */ -int -art_bindex(struct art_table *at, uint8_t *addr, int plen) +static inline int +art_bits(const struct art_table *at, const uint8_t *addr) { uint8_t boff, bend; uint32_t k; - if (plen < at->at_offset || plen > (at->at_offset + at->at_bits)) - return (-1); - - /* - * We are only interested in the part of the prefix length - * corresponding to the range of this table. - */ - plen -= at->at_offset; - /* * Jump to the first byte of the address containing bits * covered by this table. @@ -227,10 +206,38 @@ art_bindex(struct art_table *at, uint8_t k = (addr[0] >> (8 - bend)) & ((1 << at->at_bits) - 1); } + return (k); +} + + +/* + * Return the base index of the part of ``addr'' and ``plen'' + * corresponding to the range covered by the table ``at''. + * + * In other words, this function take the multi-level (complete) + * address ``addr'' and prefix length ``plen'' and return the + * single level base index for the table ``at''. + * + * For example with an address size of 32bit divided into four + * 8bit-long tables, there's a maximum of 4 base indexes if the + * prefix length is > 24. + */ +int +art_bindex(struct art_table *at, uint8_t *addr, int plen) +{ + if (plen < at->at_offset || plen > (at->at_offset + at->at_bits)) + return (-1); + + /* + * We are only interested in the part of the prefix length + * corresponding to the range of this table. + */ + plen -= at->at_offset; + /* * Single level base index formula: */ - return ((k >> (at->at_bits - plen)) + (1 << plen)); + return ((art_bits(at, addr) >> (at->at_bits - plen)) + (1 << plen)); } /* @@ -245,6 +252,15 @@ art_findex(struct art_table *at, uint8_t return art_bindex(at, addr, (at->at_offset + at->at_bits)); } +static inline int +art_index(const struct art_table *at, const uint8_t *addr) +{ + /* + * Single level base index formula: + */ + return (art_bits(at, addr) + (1 << at->at_bits)); +} + /* * (Non-perfect) lookup API function. * @@ -276,7 +292,7 @@ art_match(struct art_root *ar, uint8_t * */ while (1) { /* Do a single level route lookup. */ - j = art_findex(at, addr); + j = art_index(at, addr); entry = srp_follow(nsr, &at->at_heap[j].node); /* If this is a leaf (NULL is a leaf) we're done. */