standardize the ipfw2 name
[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('ipfw too'). This ipfw2 will be designed in modular, all the functionalities are originally from loadable modules and should be not that difficult for normal users/developers to create a module in order to meet their own requirements.
17
18 In order to achieve best performance, it inherited the "SMP-Friendly" feature from DragonflyBSD, then it becomes a "lockless" stateful firewall.
19
20 ## Brief notes on design
21 Before user starts to use the ipfw2 utility to add rules, the ipfw2 kernel module should be loaded into the kernel by running below command.
22
23         kldload ipfw2
24
25 the fundamental framework is loaded now, it can support the default rules only. And continue run below command
26
27         kldload ipfw2_basic
28
29 the basic module together with all the basic functionalities have been loaded. If user wants more functions which implemented in other modules, for example, the 'layer2' module in order to filer the layer2 traffic, so user should run below 
30
31         kldload ipfw2_layer2
32
33 and the 'layer2' module is loaded now, for example in this scenario, user can start to fire below command 
34
35         ipfw add allow all from any to any layer2
36
37 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, below steps will be done.
38
39 1. ipfw2 retrieve the module list from the kernel
40 2. ipfw2 load the module accordingly
41 3. ipfw2 start to parse the parameters 
42 4. inject into the kernel
43
44 In the kernel space, when the traffic comes, it will filter again the rules, 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.
45
46 ## Compare with FreeBSD's ipfw
47 Comparing to the IPFW from FreeBSD,this IPFW2 for DragonflyBSD is:
48
49 ### Much more extensible
50
51 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.
52
53 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.
54
55 ### Much more concise
56
57 In this ipfw2 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.
58
59     #1. ipfw add allow all 
60     #2. ipfw add allow icmp from 1.1.1.1
61     #3. ipfw add allow tcp via em0
62
63 ### Higher Performance
64
65 It is using LWKT of DragonflyBSD, so every has one copy per cpu, it is lockless stateful firewall which can fully utilize the CPUs.
66
67
68 # Modules
69
70 This ipfw2 is modular, there are two type of modules.
71
72 "Action Modules" are exists in the FreeBSD's ipfw,e.g. the dummynet and in-kernel NAT. they are providing the functionalities which will be applied to the traffic whom successfully passed all the filters.
73
74 "Filter modules" are come with a kernel part and user-space part. the kernel part contains all the "check-function" and it requires to be loaded manually, while the user-space part contains all the "parse-and-show functions" and it will be loaded automatically when user fires the ipfw2 command if it is needed to be loaded. 
75
76 So the core ipfw2 module is just a framework, all the feature and functionalities are bring by the modules. more detail and examples of the modules can be found [here](/docs/ipfw2/modules).
77
78
79 # Development
80 This section will explain this ipfw2 in developer's angle or views
81
82 ##PFIL framework
83 The PFIL framework was designed to tidy the kernel, all the packet filters can register it's filter function into the PFIL hook, and the functions in the hook will be triggered when the traffic reach different positions in the IP stack.
84
85 ##Tunnel between userspace and kernel
86 in BSD,socketopt is the tunnel between userspace and kernel, so in ipfw2, all the operation are warpped in `IP_FW_X`in order to isolated the changes in ipfw2 modules only.
87
88 ##Performance
89 IPFW2 is a `lock-free` stateful firewall, so everything should have a copy `per-cpu`. By fully use of multiple CPU at the same time,it can have a better performance.
90
91
92 # Roadmap
93 Submit log history can be found via
94 https://github.com/bycn82