ip_encap KPI is used by network stack to handle various IP encapsulation types.
Currently it has several disadvantages:
- it uses single mutex to protect internal structures. It is used by data- and control- path, thus there are no parallelism at all.
- it uses single list to keep encap handlers for both INET and INET6 families.
- struct encaptab keeps unneeded information (src, dst, masks, protosw), that isn't used by code in the source tree.
- matches are prioritized and when many tunneling interfaces are registered, encapcheck handler of each interface is invoked for each packet. the search takes O(n) for n interfaces.
What is contained in this patch:
- data path converted to be lockless using epoch(9) KPI
- struct epochtab now linked using CK_LIST
- struct epochtab now contains new fields: "min_length" and "exact_match". min_length is the minimal value of packet length, that encap handler expects to see. exact_match is value that returned by the encapcheck handler, and it means that handler wants to handle this packet.
- two lists are created to separate IPv4 and IPv6 handlers;
- added new "encap_lookup_t" method, that will be used later. It is targeted to speedup lookup of needed interface, when gif(4)/gre(4) have many interfaces.
- the need to use protosw structure is eliminated. The only pr_input method was used from this structure, so I don't see the need to keep using it.
- encap_input_t method changed to avoid using mbuf tags to store softc pointer. Now it is passed directly trough encap_input method.
- all sockaddr structures and code that uses them removed. We don't have any code in the tree that uses them. All consumers use encap_attach_func() method, that relies on invoking of encapcheck callback to get the needed handler.
- struct encap_config introduced, it contains parameters of encap handler that is going to be registered by encap_attach() functions.
- attach/detach functions are separated by address family to ip_encap_attach() and ip6_encap_attach().
- all current consumers changed to use new KPI.
- encap[46]_input() function now stops the search if returned by encapcheck method value matches exact_match value.
- encap handlers are stored in lists ordered by exact_match value, thus handlers that need more bits to match will be checked first, and if encapcheck method returns exact_match value, the search will be stopped.