This source file includes following definitions.
- register_firewall
- unregister_firewall
- call_fw_firewall
- call_in_firewall
- call_out_firewall
- fwchain_init
1
2
3
4
5
6
7
8
9 #include <linux/skbuff.h>
10 #include <linux/firewall.h>
11
12 static int firewall_lock=0;
13 static int firewall_policy[NPROTO];
14 static struct firewall_ops *firewall_chain[NPROTO];
15
16
17
18
19
20 int register_firewall(int pf, struct firewall_ops *fw)
21 {
22 struct firewall_ops **p;
23
24 if(pf<0||pf>=NPROTO)
25 return -EINVAL;
26
27
28
29
30
31 while(firewall_lock)
32 schedule();
33 firewall_lock=1;
34
35 p=&firewall_chain[pf];
36
37 while(*p)
38 {
39 if(fw->fw_priority > (*p)->fw_priority)
40 break;
41 p=&((*p)->next);
42 }
43
44 fw->next=*p;
45
46
47
48
49
50 xchg(p,fw);
51
52
53
54
55
56 firewall_lock=0;
57 return 0;
58 }
59
60
61
62
63
64 int unregister_firewall(int pf, struct firewall_ops *fw)
65 {
66 struct firewall_ops **nl;
67
68 if(pf<0||pf>=NPROTO)
69 return -EINVAL;
70
71
72
73
74
75 while(firewall_lock)
76 schedule();
77 firewall_lock=1;
78
79 nl=&firewall_chain[pf];
80
81 while(*nl!=NULL)
82 {
83 if(*nl==fw)
84 {
85 struct firewall_ops *f=fw->next;
86 xchg(nl,f);
87 firewall_lock=0;
88 return 0;
89 }
90 nl=&((*nl)->next);
91 }
92 firewall_lock=0;
93 return -ENOENT;
94 }
95
96 int call_fw_firewall(int pf, struct sk_buff *skb, void *phdr)
97 {
98 struct firewall_ops *fw=firewall_chain[pf];
99
100 while(fw!=NULL)
101 {
102 int rc=fw->fw_forward(fw,pf,skb,phdr);
103 if(rc!=FW_SKIP)
104 return rc;
105 fw=fw->next;
106 }
107 return firewall_policy[pf];
108 }
109
110
111
112
113
114 int call_in_firewall(int pf, struct sk_buff *skb, void *phdr)
115 {
116 struct firewall_ops *fw=firewall_chain[pf];
117
118 while(fw!=NULL)
119 {
120 int rc=fw->fw_input(fw,pf,skb,phdr);
121 if(rc!=FW_SKIP)
122 return rc;
123 fw=fw->next;
124 }
125 return firewall_policy[pf];
126 }
127
128 int call_out_firewall(int pf, struct sk_buff *skb, void *phdr)
129 {
130 struct firewall_ops *fw=firewall_chain[pf];
131
132 while(fw!=NULL)
133 {
134 int rc=fw->fw_output(fw,pf,skb,phdr);
135 if(rc!=FW_SKIP)
136 return rc;
137 fw=fw->next;
138 }
139
140 return firewall_policy[pf];
141 }
142
143 void fwchain_init(void)
144 {
145 int i;
146 for(i=0;i<NPROTO;i++)
147 firewall_policy[i]=FW_ACCEPT;
148 }