freebsd-dev/sys/netgraph
Luigi Rizzo de240d1013 merge code from ipfw3-head to reduce contention on the ipfw lock
and remove all O(N) sequences from kernel critical sections in ipfw.

In detail:

 1. introduce a IPFW_UH_LOCK to arbitrate requests from
     the upper half of the kernel. Some things, such as 'ipfw show',
     can be done holding this lock in read mode, whereas insert and
     delete require IPFW_UH_WLOCK.

  2. introduce a mapping structure to keep rules together. This replaces
     the 'next' chain currently used in ipfw rules. At the moment
     the map is a simple array (sorted by rule number and then rule_id),
     so we can find a rule quickly instead of having to scan the list.
     This reduces many expensive lookups from O(N) to O(log N).

  3. when an expensive operation (such as insert or delete) is done
     by userland, we grab IPFW_UH_WLOCK, create a new copy of the map
     without blocking the bottom half of the kernel, then acquire
     IPFW_WLOCK and quickly update pointers to the map and related info.
     After dropping IPFW_LOCK we can then continue the cleanup protected
     by IPFW_UH_LOCK. So userland still costs O(N) but the kernel side
     is only blocked for O(1).

  4. do not pass pointers to rules through dummynet, netgraph, divert etc,
     but rather pass a <slot, chain_id, rulenum, rule_id> tuple.
     We validate the slot index (in the array of #2) with chain_id,
     and if successful do a O(1) dereference; otherwise, we can find
     the rule in O(log N) through <rulenum, rule_id>

All the above does not change the userland/kernel ABI, though there
are some disgusting casts between pointers and uint32_t

Operation costs now are as follows:

  Function				Old	Now	  Planned
-------------------------------------------------------------------
  + skipto X, non cached		O(N)	O(log N)
  + skipto X, cached			O(1)	O(1)
XXX dynamic rule lookup			O(1)	O(log N)  O(1)
  + skipto tablearg			O(N)	O(1)
  + reinject, non cached		O(N)	O(log N)
  + reinject, cached			O(1)	O(1)
  + kernel blocked during setsockopt()	O(N)	O(1)
-------------------------------------------------------------------

The only (very small) regression is on dynamic rule lookup and this will
be fixed in a day or two, without changing the userland/kernel ABI

Supported by: Valeria Paoli
MFC after:	1 month
2009-12-22 19:01:47 +00:00
..
atm Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
bluetooth Get those pesky RFCOMM RPM data bits right. This is likely a noop. 2009-09-10 23:30:13 +00:00
netflow Fix copy-paste bug in NGM_NETFLOW_SETCONFIG argument size verification. 2009-05-13 02:26:34 +00:00
netgraph.h Introduce and use a sysinit-based initialization scheme for virtual 2009-07-23 20:46:49 +00:00
ng_async.c
ng_async.h
ng_atmllc.c
ng_atmllc.h
ng_base.c Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
ng_bpf.c
ng_bpf.h
ng_bridge.c add ip_fw_private.h to ng_ipfw.c, forgotten in previous commit; 2009-12-15 18:33:12 +00:00
ng_bridge.h
ng_car.c
ng_car.h
ng_cisco.c
ng_cisco.h
ng_deflate.c Use m_unshare()+m_copyback() instead of m_freem()+m_devget() to keep 2009-01-18 19:25:36 +00:00
ng_deflate.h
ng_device.c
ng_device.h
ng_echo.c
ng_echo.h
ng_eiface.c Take a step towards removing if_watchdog/if_timer. Don't explicitly set 2009-11-06 14:55:01 +00:00
ng_eiface.h
ng_etf.c
ng_etf.h
ng_ether_echo.c Add a trivial node to reflect ethernet frames to whence they came. 2008-12-25 00:01:29 +00:00
ng_ether_echo.h Add a trivial node to reflect ethernet frames to whence they came. 2008-12-25 00:01:29 +00:00
ng_ether.c Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
ng_ether.h
ng_fec.c Take a step towards removing if_watchdog/if_timer. Don't explicitly set 2009-11-06 14:55:01 +00:00
ng_fec.h
ng_frame_relay.c
ng_frame_relay.h
ng_gif_demux.c
ng_gif_demux.h
ng_gif.c Rework global locks for interface list and index management, correcting 2009-08-23 20:40:19 +00:00
ng_gif.h
ng_hole.c
ng_hole.h
ng_hub.c
ng_hub.h
ng_iface.c Take a step towards removing if_watchdog/if_timer. Don't explicitly set 2009-11-06 14:55:01 +00:00
ng_iface.h Check for infinite recursion possible on some broken PPTP/L2TP/... VPN setups. 2009-01-20 22:26:09 +00:00
ng_ip_input.c Introduce a mechanism for detecting calls from outbound path of the 2009-06-11 16:50:49 +00:00
ng_ip_input.h
ng_ipfw.c merge code from ipfw3-head to reduce contention on the ipfw lock 2009-12-22 19:01:47 +00:00
ng_ipfw.h merge code from ipfw3-head to reduce contention on the ipfw lock 2009-12-22 19:01:47 +00:00
ng_ksocket.c - Turn the third (islocked) argument of the knote call into flags parameter. 2009-06-28 21:49:43 +00:00
ng_ksocket.h
ng_l2tp.c Add memmove() to the kernel, making the kernel compile with Clang. 2009-02-28 16:21:25 +00:00
ng_l2tp.h
ng_lmi.c
ng_lmi.h
ng_message.h World now builds without these defines, so eliminate them. 2009-06-09 07:07:20 +00:00
ng_mppc.c If source mbuf chain consists of only one mbuf, use it directly as source 2009-01-18 21:09:34 +00:00
ng_mppc.h
ng_nat.c
ng_nat.h
ng_one2many.c
ng_one2many.h
ng_parse.c
ng_parse.h
ng_pipe.c Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
ng_pipe.h
ng_ppp.c Remove strict limitation on minimal multilink MRRU. RFC claims that MRRU 2009-01-18 12:03:43 +00:00
ng_ppp.h
ng_pppoe.c Make Netgraph compile with Clang. 2009-03-03 18:47:33 +00:00
ng_pppoe.h Make Netgraph compile with Clang. 2009-03-03 18:47:33 +00:00
ng_pptpgre.c
ng_pptpgre.h
ng_pred1.c Use m_unshare()+m_copyback() instead of m_freem()+m_devget() to keep 2009-01-18 19:25:36 +00:00
ng_pred1.h
ng_rfc1490.c
ng_rfc1490.h
ng_sample.c
ng_sample.h
ng_socket.c Introduce and use a sysinit-based initialization scheme for virtual 2009-07-23 20:46:49 +00:00
ng_socket.h
ng_socketvar.h
ng_source.c Merge the remainder of kern_vimage.c and vimage.h into vnet.c and 2009-08-01 19:26:27 +00:00
ng_source.h
ng_split.c
ng_split.h
ng_sppp.c Take a step towards removing if_watchdog/if_timer. Don't explicitly set 2009-11-06 14:55:01 +00:00
ng_sppp.h
ng_tag.c
ng_tag.h
ng_tcpmss.c
ng_tcpmss.h
ng_tee.c
ng_tee.h
ng_tty.c
ng_tty.h
ng_UI.c
ng_UI.h
ng_vjc.c Mark ng_vjc node as FORCE_WRITER to protect slcompress state. 2009-01-08 17:51:15 +00:00
ng_vjc.h
ng_vlan.c
ng_vlan.h
NOTES Spell DIAGNOSTIC correctly. 2009-10-24 18:49:17 +00:00