freebsd-dev/sys/net
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
..
bpf_buffer.c
bpf_buffer.h
bpf_filter.c
bpf_jitter.c General style cleanup, no functional change. 2009-11-20 21:12:40 +00:00
bpf_jitter.h - Allocate scratch memory on stack instead of pre-allocating it with 2009-11-20 18:49:20 +00:00
bpf_zerocopy.c
bpf_zerocopy.h
bpf.c Remove unneeded blank line from bpf_drvinit(). 2009-10-23 17:26:29 +00:00
bpf.h
bpfdesc.h
bridgestp.c
bridgestp.h
ethernet.h
fddi.h
firewire.h
flowtable.c Verify "smp_started" is true before calling 2009-10-22 00:32:01 +00:00
flowtable.h
ieee8023ad_lacp.c
ieee8023ad_lacp.h
if_arc.h
if_arcsubr.c
if_arp.h
if_atm.h
if_atmsubr.c
if_bridge.c merge code from ipfw3-head to reduce contention on the ipfw lock 2009-12-22 19:01:47 +00:00
if_bridgevar.h
if_clone.c
if_clone.h
if_dead.c Remove if_timer/if_watchdog now that they are no longer used. The space 2009-11-30 21:25:57 +00:00
if_disc.c
if_dl.h
if_edsc.c
if_ef.c Take a step towards removing if_watchdog/if_timer. Don't explicitly set 2009-11-06 14:55:01 +00:00
if_enc.c Unbreak the VIMAGE build with IPSEC, broken with r197952 by 2009-10-14 11:55:55 +00:00
if_enc.h
if_epair.c
if_ethersubr.c merge code from ipfw3-head to reduce contention on the ipfw lock 2009-12-22 19:01:47 +00:00
if_faith.c
if_fddisubr.c
if_fwsubr.c
if_gif.c Check pointer for NULL before dereferencing it, not after. 2009-10-22 06:17:04 +00:00
if_gif.h
if_gre.c
if_gre.h
if_iso88025subr.c
if_lagg.c
if_lagg.h
if_llatbl.c
if_llatbl.h
if_llc.h
if_loop.c
if_media.c
if_media.h
if_mib.c
if_mib.h
if_sppp.h
if_spppfr.c
if_spppsubr.c
if_stf.c
if_stf.h
if_tap.c
if_tap.h
if_tapvar.h
if_tun.c
if_tun.h
if_types.h
if_var.h Remove commented out prototype for ifinit(). This prototype has been 2009-12-21 20:09:19 +00:00
if_vlan_var.h
if_vlan.c
if.c Remove if_timer/if_watchdog now that they are no longer used. The space 2009-11-30 21:25:57 +00:00
if.h Revert revision 199201 for now as it has introduced a kernel vulnerability 2009-11-12 19:02:10 +00:00
iso88025.h
netisr.c
netisr.h
pfil.c Clean up comments, white space, and style in pfil.c (especially new VNET 2009-10-19 15:19:14 +00:00
pfil.h Remove unused pfil_flags field in packet_filter_hook. 2009-10-18 22:54:09 +00:00
pfkeyv2.h
ppp_defs.h
radix_mpath.c
radix_mpath.h
radix.c Move the scan for max_keylen into route.c::route_init(), 2009-12-14 20:12:51 +00:00
radix.h Move the scan for max_keylen into route.c::route_init(), 2009-12-14 20:12:51 +00:00
raw_cb.c
raw_cb.h
raw_usrreq.c
route.c Move the scan for max_keylen into route.c::route_init(), 2009-12-14 20:12:51 +00:00
route.h
rtsock.c Throughout the network stack we have a few places of 2009-12-13 13:57:32 +00:00
slcompress.c
slcompress.h
vnet.c
vnet.h
zlib.c
zlib.h