-
Notifications
You must be signed in to change notification settings - Fork 3
/
4.19-iptables-raw-POSTROUTING.patch
207 lines (182 loc) · 5.46 KB
/
4.19-iptables-raw-POSTROUTING.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -9,7 +9,7 @@
#include <linux/slab.h>
#include <net/ip.h>
-#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
+#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_LOCAL_OUT))
static int __net_init iptable_raw_table_init(struct net *net);
@@ -22,16 +22,6 @@ static const struct xt_table packet_raw
.valid_hooks = RAW_VALID_HOOKS,
.me = THIS_MODULE,
.af = NFPROTO_IPV4,
- .priority = NF_IP_PRI_RAW,
- .table_init = iptable_raw_table_init,
-};
-
-static const struct xt_table packet_raw_before_defrag = {
- .name = "raw",
- .valid_hooks = RAW_VALID_HOOKS,
- .me = THIS_MODULE,
- .af = NFPROTO_IPV4,
- .priority = NF_IP_PRI_RAW_BEFORE_DEFRAG,
.table_init = iptable_raw_table_init,
};
@@ -43,16 +33,38 @@ iptable_raw_hook(void *priv, struct sk_b
return ipt_do_table(skb, state, state->net->ipv4.iptable_raw);
}
-static struct nf_hook_ops *rawtable_ops __read_mostly;
+static struct nf_hook_ops rawtable_ops[] = {
+ {
+ .hook = iptable_raw_hook,
+ .pf = NFPROTO_IPV4,
+ .hooknum = NF_INET_PRE_ROUTING,
+ .priority = NF_IP_PRI_RAW,
+ },
+ {
+ .hook = iptable_raw_hook,
+ .pf = NFPROTO_IPV4,
+ .hooknum = NF_INET_POST_ROUTING,
+ .priority = NF_IP_PRI_NAT_SRC + 1,
+ },
+ {
+ .hook = iptable_raw_hook,
+ .pf = NFPROTO_IPV4,
+ .hooknum = NF_INET_LOCAL_OUT,
+ .priority = NF_IP_PRI_RAW,
+ },
+};
static int __net_init iptable_raw_table_init(struct net *net)
{
struct ipt_replace *repl;
const struct xt_table *table = &packet_raw;
int ret;
+ int i;
if (raw_before_defrag)
- table = &packet_raw_before_defrag;
+ for (i = 0; i < ARRAY_SIZE(rawtable_ops); i++)
+ if (rawtable_ops[i].priority == NF_IP_PRI_RAW)
+ rawtable_ops[i].priority = NF_IP_PRI_RAW_BEFORE_DEFRAG;
if (net->ipv4.iptable_raw)
return 0;
@@ -84,25 +96,17 @@ static int __init iptable_raw_init(void)
const struct xt_table *table = &packet_raw;
if (raw_before_defrag) {
- table = &packet_raw_before_defrag;
-
pr_info("Enabling raw table before defrag\n");
}
- rawtable_ops = xt_hook_ops_alloc(table, iptable_raw_hook);
- if (IS_ERR(rawtable_ops))
- return PTR_ERR(rawtable_ops);
-
ret = register_pernet_subsys(&iptable_raw_net_ops);
if (ret < 0) {
- kfree(rawtable_ops);
return ret;
}
ret = iptable_raw_table_init(&init_net);
if (ret) {
unregister_pernet_subsys(&iptable_raw_net_ops);
- kfree(rawtable_ops);
}
return ret;
@@ -111,7 +115,6 @@ static int __init iptable_raw_init(void)
static void __exit iptable_raw_fini(void)
{
unregister_pernet_subsys(&iptable_raw_net_ops);
- kfree(rawtable_ops);
}
module_init(iptable_raw_init);
--- a/net/ipv6/netfilter/ip6table_raw.c
+++ b/net/ipv6/netfilter/ip6table_raw.c
@@ -8,7 +8,7 @@
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <linux/slab.h>
-#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
+#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_LOCAL_OUT))
static int __net_init ip6table_raw_table_init(struct net *net);
@@ -21,16 +21,6 @@ static const struct xt_table packet_raw
.valid_hooks = RAW_VALID_HOOKS,
.me = THIS_MODULE,
.af = NFPROTO_IPV6,
- .priority = NF_IP6_PRI_RAW,
- .table_init = ip6table_raw_table_init,
-};
-
-static const struct xt_table packet_raw_before_defrag = {
- .name = "raw",
- .valid_hooks = RAW_VALID_HOOKS,
- .me = THIS_MODULE,
- .af = NFPROTO_IPV6,
- .priority = NF_IP6_PRI_RAW_BEFORE_DEFRAG,
.table_init = ip6table_raw_table_init,
};
@@ -42,16 +32,38 @@ ip6table_raw_hook(void *priv, struct sk_
return ip6t_do_table(skb, state, state->net->ipv6.ip6table_raw);
}
-static struct nf_hook_ops *rawtable_ops __read_mostly;
+static struct nf_hook_ops rawtable_ops[] = {
+ {
+ .hook = ip6table_raw_hook,
+ .pf = NFPROTO_IPV6,
+ .hooknum = NF_INET_PRE_ROUTING,
+ .priority = NF_IP6_PRI_RAW,
+ },
+ {
+ .hook = ip6table_raw_hook,
+ .pf = NFPROTO_IPV6,
+ .hooknum = NF_INET_POST_ROUTING,
+ .priority = NF_IP6_PRI_NAT_SRC + 1,
+ },
+ {
+ .hook = ip6table_raw_hook,
+ .pf = NFPROTO_IPV6,
+ .hooknum = NF_INET_LOCAL_OUT,
+ .priority = NF_IP6_PRI_RAW,
+ },
+};
static int __net_init ip6table_raw_table_init(struct net *net)
{
struct ip6t_replace *repl;
const struct xt_table *table = &packet_raw;
int ret;
+ int i;
if (raw_before_defrag)
- table = &packet_raw_before_defrag;
+ for (i = 0; i < ARRAY_SIZE(rawtable_ops); i++)
+ if (rawtable_ops[i].priority == NF_IP6_PRI_RAW)
+ rawtable_ops[i].priority = NF_IP6_PRI_RAW_BEFORE_DEFRAG;
if (net->ipv6.ip6table_raw)
return 0;
@@ -83,26 +95,17 @@ static int __init ip6table_raw_init(void
const struct xt_table *table = &packet_raw;
if (raw_before_defrag) {
- table = &packet_raw_before_defrag;
-
pr_info("Enabling raw table before defrag\n");
}
- /* Register hooks */
- rawtable_ops = xt_hook_ops_alloc(table, ip6table_raw_hook);
- if (IS_ERR(rawtable_ops))
- return PTR_ERR(rawtable_ops);
-
ret = register_pernet_subsys(&ip6table_raw_net_ops);
if (ret < 0) {
- kfree(rawtable_ops);
return ret;
}
ret = ip6table_raw_table_init(&init_net);
if (ret) {
unregister_pernet_subsys(&ip6table_raw_net_ops);
- kfree(rawtable_ops);
}
return ret;
}
@@ -110,7 +113,6 @@ static int __init ip6table_raw_init(void
static void __exit ip6table_raw_fini(void)
{
unregister_pernet_subsys(&ip6table_raw_net_ops);
- kfree(rawtable_ops);
}
module_init(ip6table_raw_init);