Generic Helper Routines and Macros
The routing code uses quite a few small routines and macros that make the code more readable. This section lists some of the generic ones; more-specialized ones will be introduced later in the section "Helper Routines." It is important to keep in mind that the same function or macro can have different definitions, depending on such factors as:
Support for policy routing in the kernel
Support for multipath routing in the kernel
L3 protocol (e.g., IPv4 versus DECnet)
The generic routines follow:
-
FIB_RES_XXX Given a
fib_resultstructure, these macros extract specific fields. For example,FIB_RES_DEVextracts thenh_devfield. These macros are defined in include/net/ip_fib.h.-
change_nexthops -
for_nexthops -
endfor_nexthops Used to browse all the
fib_nhstructures of a givenfib_infoinstance.change_nexthopsstarts a loop over the structures, designating the local variablenhto represent each structure; as the name of the macro suggests, it can be used to alter the structures.for_nexthopsis very similar and ends with the sameendfor_nexthopsmacro. The only difference is thatfor_nexthopdefines the local variablenhas a pointer to a constant and therefore the code inside the loop cannot change the content of any of thefib_nhinstances browsed.For IPv4, these macros are defined in net/ipv4/fib_semantics.c. Note that for each macro there are two versions: one used when there is Policy Routing support in the kernel and one when there is no Policy Routing. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access