net/radix: Various minor improvements and cleanups - Change 'rn_bit' and 'rm_bit' from type 'short' to 'int', for consistency with the other types. This doesn't change the structure size because of the implicit padding. However, the userland netstat(1) utility must be recompiled with the updated header. - Rename variable 'b' to 'bit' for clarity. - Adjust the parameter orders of rn_search_m() for consistency. - Various style cleanups.
net/radix: Update parameter types to save callers from boring casts Change the function parameters of key/address/mask from type 'const char *' to 'const void *', so the callers don't need to do boring casts in passing them without causing any compilation warnings. In addition, change rn_key/rn_mask/rmu_mask to 'const u_char *' type as that makes more sense. Referred to FreeBSD.
net/radix: Implement rn_flush() and rn_freehead() rn_flush() flushes all nodes in the given radix tree and thus makes the tree empty; rn_freehead() can then free the emptied tree. The separation of flushing and freeing is required to support the use case in ipfw2, which needs to flush a table without destroying it. A mask tree is somewhat special, because its nodes are allocated inside this radix code, so the rn_freemask() callback function is provided to be used in rn_flush() to flush a mask tree and reclaim its memory. These APIs can help the radix users to easily flush and free the radix trees without rolling their own versions.
net/radix: Document rn_inithead() and change to use byte offset The radix code only supports offset bit being multiple of bytes but not any byte fraction, so it's clearer and better to just use byte offset instead of bit offset. In addition, the caller can be easier to determine this argument using offsetof(). On the other hand, ignore this off_bytes parameter and auto set it to zero when to create a mask tree. Also add a detailed description for rn_inithead().
net/radix: Fix a subtle type cast error in rn_lexobetter() The char byte comparison should be cast to 'unsigned'; otherwise, the result is wrong in some special cases, e.g., rn_lexobetter(<255.255.0.0>, <255.255.128.0>) was giving 'true' while 'false' is expected. While there, add a brief function description and clean up a bit for readability.
net/radix: Simplify mask manipulation in rn_addmask() Since the max key length is known, so use an on-stack variable instead of memory allocation for the 'addmask_key' variable. Therefore also get rid of the 'rnh_last_zeroed' member from 'radix_node_head' struct. Rename 'rnh_last_zeroed' to its origin 'rnh_addrsize' instead of removing it. Referred-to: FreeBSD