more concise
[ikiwiki.git] / docs / ipfw2 / index.mdwn
1 [[!meta title="IPFW2 Documentation"]]
2 [[!meta robots="index, follow"]]
3
4 updated 14-Nov-2014 
5
6 bycn82
7
8 (under development)
9
10 ---
11
12 [[!toc  levels=3]]
13
14 # Introduction
15 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.
16
17 I am rewriting IPFW2 from scratch for DragonflyBSD, and 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 their own requirement.
18 ## Brief notes on design
19 Before user start to use the ipfw utility to add rules, the ipfw kernel should be enable/loaded into the kernel. by running below command
20
21         kldload ipfw
22
23 the basic ipfw module will be loaded into kernel, also the basic functionalities. in order to user more function which is implemented in other modules, users can run below command
24
25         kldload ipfw_layer2
26
27 so the 'layer2' module will be loaded, for example in this scenario, user can start to fire below command 
28
29         ipfw add allow all from any to any layer2
30
31 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.
32
33 1. ipfw retrieve the module name list from the kernel
34 2. ipfw load the module accordingly
35 3. ipfw start to parse the parameters 
36 4. inject into the kernel
37
38 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.
39
40 ## Compare with FreeBSD's ipfw
41 Comparing to the IPFW from FreeBSD,this IPFW for DragonflyBSD is:
42
43 **Much more extensible**
44
45 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.
46
47 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.
48
49 **Much more concise**
50
51 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.
52
53 **Much more flexible**
54
55
56
57 # Configuration
58 # Modules
59 Modules are loadable,and every module comes with a kernel part and userspace part. the kernel part need to be loaded manually, and the userpsace part can be loaded automatically when user fires the ipfw command.
60 ## Default Module
61 When the ipfw module 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
62       accept
63       deby
64 by fire command `kldload ipfw', the default module is loaded. and all other modules are relying on this module.
65 ## Basic Module
66 Basic Module contains all the basic features. it has multiple opcodes list below.
67         proto
68         from
69         to
70         in
71         out
72         via
73         recv
74         xmit
75
76         
77
78 ## Layer2 Module
79
80         layer2
81         mac-type
82
83 ## Layer4 Module
84        
85         tcpflag
86
87
88 ## Connection Module
89
90         pps
91         lps
92
93 # Development
94 ## How to create a module
95 # Roadmap