20
20
#include <net/netfilter/nf_conntrack_synproxy.h>
21
21
22
22
static struct ipv6hdr *
23
- synproxy_build_ip (struct sk_buff * skb , const struct in6_addr * saddr ,
24
- const struct in6_addr * daddr )
23
+ synproxy_build_ip (struct net * net , struct sk_buff * skb ,
24
+ const struct in6_addr * saddr ,
25
+ const struct in6_addr * daddr )
25
26
{
26
27
struct ipv6hdr * iph ;
27
28
28
29
skb_reset_network_header (skb );
29
30
iph = (struct ipv6hdr * )skb_put (skb , sizeof (* iph ));
30
31
ip6_flow_hdr (iph , 0 , 0 );
31
- iph -> hop_limit = 64 ; //XXX
32
+ iph -> hop_limit = net -> ipv6 . devconf_all -> hop_limit ;
32
33
iph -> nexthdr = IPPROTO_TCP ;
33
34
iph -> saddr = * saddr ;
34
35
iph -> daddr = * daddr ;
@@ -37,13 +38,12 @@ synproxy_build_ip(struct sk_buff *skb, const struct in6_addr *saddr,
37
38
}
38
39
39
40
static void
40
- synproxy_send_tcp (const struct synproxy_net * snet ,
41
+ synproxy_send_tcp (struct net * net ,
41
42
const struct sk_buff * skb , struct sk_buff * nskb ,
42
43
struct nf_conntrack * nfct , enum ip_conntrack_info ctinfo ,
43
44
struct ipv6hdr * niph , struct tcphdr * nth ,
44
45
unsigned int tcp_hdr_size )
45
46
{
46
- struct net * net = nf_ct_net (snet -> tmpl );
47
47
struct dst_entry * dst ;
48
48
struct flowi6 fl6 ;
49
49
@@ -84,7 +84,7 @@ synproxy_send_tcp(const struct synproxy_net *snet,
84
84
}
85
85
86
86
static void
87
- synproxy_send_client_synack (const struct synproxy_net * snet ,
87
+ synproxy_send_client_synack (struct net * net ,
88
88
const struct sk_buff * skb , const struct tcphdr * th ,
89
89
const struct synproxy_options * opts )
90
90
{
@@ -103,7 +103,7 @@ synproxy_send_client_synack(const struct synproxy_net *snet,
103
103
return ;
104
104
skb_reserve (nskb , MAX_TCP_HEADER );
105
105
106
- niph = synproxy_build_ip (nskb , & iph -> daddr , & iph -> saddr );
106
+ niph = synproxy_build_ip (net , nskb , & iph -> daddr , & iph -> saddr );
107
107
108
108
skb_reset_transport_header (nskb );
109
109
nth = (struct tcphdr * )skb_put (nskb , tcp_hdr_size );
@@ -121,15 +121,16 @@ synproxy_send_client_synack(const struct synproxy_net *snet,
121
121
122
122
synproxy_build_options (nth , opts );
123
123
124
- synproxy_send_tcp (snet , skb , nskb , skb -> nfct , IP_CT_ESTABLISHED_REPLY ,
124
+ synproxy_send_tcp (net , skb , nskb , skb -> nfct , IP_CT_ESTABLISHED_REPLY ,
125
125
niph , nth , tcp_hdr_size );
126
126
}
127
127
128
128
static void
129
- synproxy_send_server_syn (const struct synproxy_net * snet ,
129
+ synproxy_send_server_syn (struct net * net ,
130
130
const struct sk_buff * skb , const struct tcphdr * th ,
131
131
const struct synproxy_options * opts , u32 recv_seq )
132
132
{
133
+ struct synproxy_net * snet = synproxy_pernet (net );
133
134
struct sk_buff * nskb ;
134
135
struct ipv6hdr * iph , * niph ;
135
136
struct tcphdr * nth ;
@@ -144,7 +145,7 @@ synproxy_send_server_syn(const struct synproxy_net *snet,
144
145
return ;
145
146
skb_reserve (nskb , MAX_TCP_HEADER );
146
147
147
- niph = synproxy_build_ip (nskb , & iph -> saddr , & iph -> daddr );
148
+ niph = synproxy_build_ip (net , nskb , & iph -> saddr , & iph -> daddr );
148
149
149
150
skb_reset_transport_header (nskb );
150
151
nth = (struct tcphdr * )skb_put (nskb , tcp_hdr_size );
@@ -165,12 +166,12 @@ synproxy_send_server_syn(const struct synproxy_net *snet,
165
166
166
167
synproxy_build_options (nth , opts );
167
168
168
- synproxy_send_tcp (snet , skb , nskb , & snet -> tmpl -> ct_general , IP_CT_NEW ,
169
+ synproxy_send_tcp (net , skb , nskb , & snet -> tmpl -> ct_general , IP_CT_NEW ,
169
170
niph , nth , tcp_hdr_size );
170
171
}
171
172
172
173
static void
173
- synproxy_send_server_ack (const struct synproxy_net * snet ,
174
+ synproxy_send_server_ack (struct net * net ,
174
175
const struct ip_ct_tcp * state ,
175
176
const struct sk_buff * skb , const struct tcphdr * th ,
176
177
const struct synproxy_options * opts )
@@ -189,7 +190,7 @@ synproxy_send_server_ack(const struct synproxy_net *snet,
189
190
return ;
190
191
skb_reserve (nskb , MAX_TCP_HEADER );
191
192
192
- niph = synproxy_build_ip (nskb , & iph -> daddr , & iph -> saddr );
193
+ niph = synproxy_build_ip (net , nskb , & iph -> daddr , & iph -> saddr );
193
194
194
195
skb_reset_transport_header (nskb );
195
196
nth = (struct tcphdr * )skb_put (nskb , tcp_hdr_size );
@@ -205,11 +206,11 @@ synproxy_send_server_ack(const struct synproxy_net *snet,
205
206
206
207
synproxy_build_options (nth , opts );
207
208
208
- synproxy_send_tcp (snet , skb , nskb , NULL , 0 , niph , nth , tcp_hdr_size );
209
+ synproxy_send_tcp (net , skb , nskb , NULL , 0 , niph , nth , tcp_hdr_size );
209
210
}
210
211
211
212
static void
212
- synproxy_send_client_ack (const struct synproxy_net * snet ,
213
+ synproxy_send_client_ack (struct net * net ,
213
214
const struct sk_buff * skb , const struct tcphdr * th ,
214
215
const struct synproxy_options * opts )
215
216
{
@@ -227,7 +228,7 @@ synproxy_send_client_ack(const struct synproxy_net *snet,
227
228
return ;
228
229
skb_reserve (nskb , MAX_TCP_HEADER );
229
230
230
- niph = synproxy_build_ip (nskb , & iph -> saddr , & iph -> daddr );
231
+ niph = synproxy_build_ip (net , nskb , & iph -> saddr , & iph -> daddr );
231
232
232
233
skb_reset_transport_header (nskb );
233
234
nth = (struct tcphdr * )skb_put (nskb , tcp_hdr_size );
@@ -243,15 +244,16 @@ synproxy_send_client_ack(const struct synproxy_net *snet,
243
244
244
245
synproxy_build_options (nth , opts );
245
246
246
- synproxy_send_tcp (snet , skb , nskb , skb -> nfct , IP_CT_ESTABLISHED_REPLY ,
247
+ synproxy_send_tcp (net , skb , nskb , skb -> nfct , IP_CT_ESTABLISHED_REPLY ,
247
248
niph , nth , tcp_hdr_size );
248
249
}
249
250
250
251
static bool
251
- synproxy_recv_client_ack (const struct synproxy_net * snet ,
252
+ synproxy_recv_client_ack (struct net * net ,
252
253
const struct sk_buff * skb , const struct tcphdr * th ,
253
254
struct synproxy_options * opts , u32 recv_seq )
254
255
{
256
+ struct synproxy_net * snet = synproxy_pernet (net );
255
257
int mss ;
256
258
257
259
mss = __cookie_v6_check (ipv6_hdr (skb ), th , ntohl (th -> ack_seq ) - 1 );
@@ -267,15 +269,16 @@ synproxy_recv_client_ack(const struct synproxy_net *snet,
267
269
if (opts -> options & XT_SYNPROXY_OPT_TIMESTAMP )
268
270
synproxy_check_timestamp_cookie (opts );
269
271
270
- synproxy_send_server_syn (snet , skb , th , opts , recv_seq );
272
+ synproxy_send_server_syn (net , skb , th , opts , recv_seq );
271
273
return true;
272
274
}
273
275
274
276
static unsigned int
275
277
synproxy_tg6 (struct sk_buff * skb , const struct xt_action_param * par )
276
278
{
277
279
const struct xt_synproxy_info * info = par -> targinfo ;
278
- struct synproxy_net * snet = synproxy_pernet (par -> net );
280
+ struct net * net = par -> net ;
281
+ struct synproxy_net * snet = synproxy_pernet (net );
279
282
struct synproxy_options opts = {};
280
283
struct tcphdr * th , _th ;
281
284
@@ -304,12 +307,12 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
304
307
XT_SYNPROXY_OPT_SACK_PERM |
305
308
XT_SYNPROXY_OPT_ECN );
306
309
307
- synproxy_send_client_synack (snet , skb , th , & opts );
310
+ synproxy_send_client_synack (net , skb , th , & opts );
308
311
return NF_DROP ;
309
312
310
313
} else if (th -> ack && !(th -> fin || th -> rst || th -> syn )) {
311
314
/* ACK from client */
312
- synproxy_recv_client_ack (snet , skb , th , & opts , ntohl (th -> seq ));
315
+ synproxy_recv_client_ack (net , skb , th , & opts , ntohl (th -> seq ));
313
316
return NF_DROP ;
314
317
}
315
318
@@ -320,7 +323,8 @@ static unsigned int ipv6_synproxy_hook(void *priv,
320
323
struct sk_buff * skb ,
321
324
const struct nf_hook_state * nhs )
322
325
{
323
- struct synproxy_net * snet = synproxy_pernet (nhs -> net );
326
+ struct net * net = nhs -> net ;
327
+ struct synproxy_net * snet = synproxy_pernet (net );
324
328
enum ip_conntrack_info ctinfo ;
325
329
struct nf_conn * ct ;
326
330
struct nf_conn_synproxy * synproxy ;
@@ -384,7 +388,7 @@ static unsigned int ipv6_synproxy_hook(void *priv,
384
388
* therefore we need to add 1 to make the SYN sequence
385
389
* number match the one of first SYN.
386
390
*/
387
- if (synproxy_recv_client_ack (snet , skb , th , & opts ,
391
+ if (synproxy_recv_client_ack (net , skb , th , & opts ,
388
392
ntohl (th -> seq ) + 1 ))
389
393
this_cpu_inc (snet -> stats -> cookie_retrans );
390
394
@@ -410,12 +414,12 @@ static unsigned int ipv6_synproxy_hook(void *priv,
410
414
XT_SYNPROXY_OPT_SACK_PERM );
411
415
412
416
swap (opts .tsval , opts .tsecr );
413
- synproxy_send_server_ack (snet , state , skb , th , & opts );
417
+ synproxy_send_server_ack (net , state , skb , th , & opts );
414
418
415
419
nf_ct_seqadj_init (ct , ctinfo , synproxy -> isn - ntohl (th -> seq ));
416
420
417
421
swap (opts .tsval , opts .tsecr );
418
- synproxy_send_client_ack (snet , skb , th , & opts );
422
+ synproxy_send_client_ack (net , skb , th , & opts );
419
423
420
424
consume_skb (skb );
421
425
return NF_STOLEN ;
0 commit comments