e45d52514c757248d199f457e79bd440dab7fb3d
[ikiwiki.git] / docs / ipfw2 / index.mdwn
1 [[!meta title="IPFW2 Documentation"]]
2 [[!meta robots="index, follow"]]
3
4
5 bycn82
6
7 (under development)
8
9 ---
10
11 [[!toc  levels=3]]
12
13 # Introduction
14 IPFW is a controlling utility for ipfw/ipacct facilities for FreeBSD 2.0 which released in November, 1994. After 20 years of evolution. it becomes a stateful firewall which supports Layer2 to Layer4. It is comprised of several components: the kernel firewall filter rule processor and its integrated packet accounting facility, the logging facility, NAT, the dummynet(4) traffic shaper, a forward facility, a bridge facility, and an ipstealth facility. It is one of the most advanced opensource firewall.
15
16 I am re-writing it from scratch for DragonflyBSD and call it IPFW2. This IPFW2 will be in modular design, all the functionality are originally from loadable modules and should be not that difficult for normal users/developer to create a module in order to meet their own requirements.
17 ## Brief notes on design
18 Before users start to use the IPFW2 utility to add rules, the IPFW2 kernel should be enable/loaded into the kernel. by running below command
19
20         kldload ipfw
21
22 the fundamental framework is loaded now, it can support the default rules only. continue run below command
23
24         kldload ipfw_basic
25
26 the basic IPFW2 module is loaded into kernel now,together with all the basic functionality. in order to user more function which is implemented in other modules, users can run below command
27
28         kldload ipfw_layer2
29
30 so the 'layer2' module will be loaded, for example in this scenario, user can start to fire below command 
31
32         ipfw add allow all from any to any layer2
33
34 it means user want to add add rule which allow all the layer2 traffic. when user fire the command in the console, actually in the back-end, it will do below things.
35
36 1. ipfw retrieve the module name list from the kernel
37 2. ipfw load the module accordingly
38 3. ipfw start to parse the parameters 
39 4. inject into the kernel
40
41 In the kernel space, when the traffic comes, it will filter again the rule, in each ipfw_insn has unique module + opcode. it will automatically link to the filter function which will be registered during the module was loaded.
42
43 ## Compare with FreeBSD's ipfw
44 Comparing to the IPFW from FreeBSD,this IPFW for DragonflyBSD is:
45
46 ### Much more extensible
47
48 Every feature/function needs to be identified by an ID, but there are only 8bits space to store the ID, so theoretically it can support 256 features/functions in maximum.
49
50 In this IPFW for DragonflyBSD, the space for ID are the same, so also 8bits, but one space for each module and it has 8bits for module ID, so so theoretically it can have 256 modules and 256 features/functions in each module, so 256*256 feature/functions in maximum.
51
52 ### Much more concise
53
54 In this IPFW for DragonflyBSD, the rules are much more concise. for example, the simple rule command like "ipfw add allow ip from any to any".  the "from any to any" actually is just try to make the rule more readable. but actually "ipfw add allow ip" is much more concise. and another example "ipfw add allow ip from 1.1.1.1 to any" cannot be better than "ipfw add allow from 1.1.1.1". because "from any " and "to any" are actually useless.
55
56     #1. ipfw add allow all 
57     #2. ipfw add allow icmp from 1.1.1.1
58     #3. ipfw add allow tcp via em0
59
60 ### Much more flexible
61
62 It supports concise mode and full mode which is same as IPFW in FreeBSD in user angle of view.
63
64
65 # Configuration
66 # Modules
67 Some modules are exists in the FreeBSD's ipfw,e.g. the dummynet and in-kernel NAT. they are "action modules" providing the functionalities which will be applied to the traffic whom successfully passed all the filters.
68
69 Some modules are "filter modules" which is new in this ipfw. And every "filter module" comes with a kernel part and user-space part. the kernel part need to be loaded manually, and the user-space part will be loaded automatically when user fires the ipfw command if it is needed to be loaded.
70
71 ## Filter Modules
72 When the ipfw was loaded, it comes with 2 opcodes in order to support the default behavior of the ipfw. so below 2 opcodes are embeded in the ipfw.ko
73       accept
74       deby
75 by firing command `kldload ipfw', the default ipfw will be loaded. and all other modules are relying on this module.
76 ### Basic Module
77 By firing command `kldload ipfw_basic', the basic module will be loaded. and this module brings all the basic functionalities lists below.
78         proto
79         from
80         to
81         in
82         out
83         via
84         recv
85         xmit
86         fwd
87         ...
88
89 ### Layer2 Module
90 By firing command `kldload ipfw_layer2', the layer2 module will be loaded. and this module brings all the functionlities which related to the layer2 traffic. 
91         layer2
92         MAC
93         ...
94 A sysctl 'net.link.ether.ipfw' to control whether the layer2 traffic will be processed by ipfw.
95 ### Layer4 Module
96 By firing command `kldload ipfw_layer4', the layer4 module will be loaded. and this module brings all the functionlities which related to the layer4 traffic. 
97         tcpflag
98         ...
99 It will be just a sample to demonstrate how to filter the traffic in different 
100 angle of view. it can be a good example to demonstrate how to do L7 traffic shaping or integrate with NDI technologies.
101 ### Connection Module
102 This modules is focusing on the connections. for example to limit X packets per second, or limit X connections between 2 IP addresses. 
103         pps
104         conns
105
106 ## Action Modules
107 ### Dummynet
108 ### NAT
109 ### LOG
110
111 # Development
112 ## How to create a module to filter the traffic skype
113 # Roadmap
114 [in plan]: Add layer2 support for 'forward' keyword.
115
116 [in plan]: Policy routing as PF/NPF.
117
118 [in plan]: Port in-kernel NAT from FreeBSD.
119
120 18-11-2014: Integrate with dummynet module.
121
122 18-11-2014: Add 'forward' keyword.
123
124 17-11-2014: Add 'skipto' keyword.
125
126 16-11-2014: Show the "from any to any" when 'from' and 'to' is not exists.
127
128 11-11-2014: Release alpha 0.1 version which is in modular.
129
130 29-10-2014: Extended the 'ipfw_insn' size.