freebsd-dev/sys/netgraph
Andre Oppermann 9b932e9e04 Convert ipfw to use PFIL_HOOKS. This is change is transparent to userland
and preserves the ipfw ABI.  The ipfw core packet inspection and filtering
functions have not been changed, only how ipfw is invoked is different.

However there are many changes how ipfw is and its add-on's are handled:

 In general ipfw is now called through the PFIL_HOOKS and most associated
 magic, that was in ip_input() or ip_output() previously, is now done in
 ipfw_check_[in|out]() in the ipfw PFIL handler.

 IPDIVERT is entirely handled within the ipfw PFIL handlers.  A packet to
 be diverted is checked if it is fragmented, if yes, ip_reass() gets in for
 reassembly.  If not, or all fragments arrived and the packet is complete,
 divert_packet is called directly.  For 'tee' no reassembly attempt is made
 and a copy of the packet is sent to the divert socket unmodified.  The
 original packet continues its way through ip_input/output().

 ipfw 'forward' is done via m_tag's.  The ipfw PFIL handlers tag the packet
 with the new destination sockaddr_in.  A check if the new destination is a
 local IP address is made and the m_flags are set appropriately.  ip_input()
 and ip_output() have some more work to do here.  For ip_input() the m_flags
 are checked and a packet for us is directly sent to the 'ours' section for
 further processing.  Destination changes on the input path are only tagged
 and the 'srcrt' flag to ip_forward() is set to disable destination checks
 and ICMP replies at this stage.  The tag is going to be handled on output.
 ip_output() again checks for m_flags and the 'ours' tag.  If found, the
 packet will be dropped back to the IP netisr where it is going to be picked
 up by ip_input() again and the directly sent to the 'ours' section.  When
 only the destination changes, the route's 'dst' is overwritten with the
 new destination from the forward m_tag.  Then it jumps back at the route
 lookup again and skips the firewall check because it has been marked with
 M_SKIP_FIREWALL.  ipfw 'forward' has to be compiled into the kernel with
 'option IPFIREWALL_FORWARD' to enable it.

 DUMMYNET is entirely handled within the ipfw PFIL handlers.  A packet for
 a dummynet pipe or queue is directly sent to dummynet_io().  Dummynet will
 then inject it back into ip_input/ip_output() after it has served its time.
 Dummynet packets are tagged and will continue from the next rule when they
 hit the ipfw PFIL handlers again after re-injection.

 BRIDGING and IPFW_ETHER are not changed yet and use ipfw_chk() directly as
 they did before.  Later this will be changed to dedicated ETHER PFIL_HOOKS.

More detailed changes to the code:

 conf/files
	Add netinet/ip_fw_pfil.c.

 conf/options
	Add IPFIREWALL_FORWARD option.

 modules/ipfw/Makefile
	Add ip_fw_pfil.c.

 net/bridge.c
	Disable PFIL_HOOKS if ipfw for bridging is active.  Bridging ipfw
	is still directly invoked to handle layer2 headers and packets would
	get a double ipfw when run through PFIL_HOOKS as well.

 netinet/ip_divert.c
	Removed divert_clone() function.  It is no longer used.

 netinet/ip_dummynet.[ch]
	Neither the route 'ro' nor the destination 'dst' need to be stored
	while in dummynet transit.  Structure members and associated macros
	are removed.

 netinet/ip_fastfwd.c
	Removed all direct ipfw handling code and replace it with the new
	'ipfw forward' handling code.

 netinet/ip_fw.h
	Removed 'ro' and 'dst' from struct ip_fw_args.

 netinet/ip_fw2.c
	(Re)moved some global variables and the module handling.

 netinet/ip_fw_pfil.c
	New file containing the ipfw PFIL handlers and module initialization.

 netinet/ip_input.c
	Removed all direct ipfw handling code and replace it with the new
	'ipfw forward' handling code.  ip_forward() does not longer require
	the 'next_hop' struct sockaddr_in argument.  Disable early checks
	if 'srcrt' is set.

 netinet/ip_output.c
	Removed all direct ipfw handling code and replace it with the new
	'ipfw forward' handling code.

 netinet/ip_var.h
	Add ip_reass() as general function.  (Used from ipfw PFIL handlers
	for IPDIVERT.)

 netinet/raw_ip.c
	Directly check if ipfw and dummynet control pointers are active.

 netinet/tcp_input.c
	Rework the 'ipfw forward' to local code to work with the new way of
	forward tags.

 netinet/tcp_sack.c
	Remove include 'opt_ipfw.h' which is not needed here.

 sys/mbuf.h
	Remove m_claim_next() macro which was exclusively for ipfw 'forward'
	and is no longer needed.

Approved by:	re (scottl)
2004-08-17 22:05:54 +00:00
..
atm This is the netgraph node framework for the user side call control 2004-08-12 14:22:00 +00:00
bluetooth Introduce ng_hci_inquiry_response structure and use it in the hccontrol(8) 2004-08-10 00:38:50 +00:00
netgraph.h When making a peer of unknown type framework tries to load module 2004-07-27 20:30:56 +00:00
ng_async.c
ng_async.h
ng_atmllc.c
ng_atmllc.h
ng_base.c When making a peer of unknown type framework tries to load module 2004-07-27 20:30:56 +00:00
ng_bpf.c
ng_bpf.h
ng_bridge.c Convert ipfw to use PFIL_HOOKS. This is change is transparent to userland 2004-08-17 22:05:54 +00:00
ng_bridge.h
ng_cisco.c
ng_cisco.h
ng_device.c In ng_device_newhook(): 2004-07-20 13:16:17 +00:00
ng_device.h
ng_echo.c
ng_echo.h
ng_eiface.c
ng_eiface.h
ng_etf.c
ng_etf.h
ng_ether.c Avoid casts as lvalues. 2004-07-28 06:59:55 +00:00
ng_ether.h
ng_fec.c Avoid casts as lvalues. 2004-07-28 06:59:55 +00:00
ng_fec.h
ng_frame_relay.c
ng_frame_relay.h
ng_gif_demux.c
ng_gif_demux.h
ng_gif.c Avoid casts as lvalues. 2004-07-28 06:59:55 +00:00
ng_gif.h
ng_hole.c
ng_hole.h
ng_hub.c
ng_hub.h
ng_iface.c
ng_iface.h
ng_ip_input.c
ng_ip_input.h
ng_ksocket.c
ng_ksocket.h
ng_l2tp.c Implement minimalistic L2TP sessions statistics and correct man page 2004-08-03 06:52:55 +00:00
ng_l2tp.h Implement minimalistic L2TP sessions statistics and correct man page 2004-08-03 06:52:55 +00:00
ng_lmi.c
ng_lmi.h
ng_message.h
ng_mppc.c
ng_mppc.h
ng_one2many.c
ng_one2many.h
ng_parse.c Avoid casts as lvalues. 2004-07-28 06:59:55 +00:00
ng_parse.h
ng_ppp.c Do not change link[n].conf.latency for internal usage but have 2004-08-03 06:34:55 +00:00
ng_ppp.h
ng_pppoe.c Another stupid error from my side. PPPOE_NONSTANDARD was first defined 2004-08-01 20:39:33 +00:00
ng_pppoe.h When node is server serve both standard RFC2516 and non-standard 3Com 2004-07-27 19:47:13 +00:00
ng_pptpgre.c
ng_pptpgre.h
ng_rfc1490.c
ng_rfc1490.h
ng_sample.c Address node in a less complex way. 2004-07-29 08:05:02 +00:00
ng_sample.h
ng_socket.c Fix a stupid error in my previous commit, which broke operation 2004-07-31 21:32:55 +00:00
ng_socket.h
ng_socketvar.h
ng_source.c Slight cosmetic changes. 2004-07-20 17:15:38 +00:00
ng_source.h
ng_split.c
ng_split.h
ng_sppp.c
ng_sppp.h
ng_tee.c
ng_tee.h
ng_tty.c
ng_tty.h
ng_UI.c
ng_UI.h
ng_vjc.c
ng_vjc.h
ng_vlan.c
ng_vlan.h
NOTES