]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Rework IP encapsulation handling code.
authorAndrey V. Elsukov <ae@FreeBSD.org>
Tue, 5 Jun 2018 20:51:01 +0000 (20:51 +0000)
committerAndrey V. Elsukov <ae@FreeBSD.org>
Tue, 5 Jun 2018 20:51:01 +0000 (20:51 +0000)
commit6d8fdfa9d5e7d4871c5039b0131829f9cbefeee9
tree0ebd65e97a5973725170f97863d5c1133dc381ce
parent56009ba0ed678cffa7bece86518aef47767b791b
Rework IP encapsulation handling code.

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. All this work is done
  with exclusive lock held.

What this patch includes:
- the datapath is converted to be lockless using epoch(9) KPI.
- struct encaptab now linked using CK_LIST.
- all unused fields removed from struct encaptab. Several new fields
  addedr: min_length is the minimum packet length, that encapsulation
  handler expects to see; exact_match is maximum number of bits, that
  can return an encapsulation handler, when it wants to consume a packet.
- IPv6 and IPv4 handlers are stored in separate lists;
- 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_t method.
  encap_getarg() funtions is removed.
- 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() to determine the needed
  handler.
- introduced struct encap_config, it contains parameters of encap handler
  that is going to be registered by encap_attach() function.
- 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.
- all current consumers changed to use new KPI.

Reviewed by: mmacy
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D15617
16 files changed:
sys/net/if_gif.c
sys/net/if_gre.c
sys/net/if_gre.h
sys/net/if_me.c
sys/net/if_stf.c
sys/netinet/in_gif.c
sys/netinet/ip_encap.c
sys/netinet/ip_encap.h
sys/netinet/ip_gre.c
sys/netinet/ip_mroute.c
sys/netinet/pim_var.h
sys/netinet6/in6_gif.c
sys/netinet6/ip6_gre.c
sys/netinet6/ip6_mroute.c
sys/netinet6/pim6_var.h
sys/netipsec/xform_ipcomp.c