powerpc/mm: Fix some SMP issues with MMU context handling
[deliverable/linux.git] / net / netfilter / nf_conntrack_proto_tcp.c
CommitLineData
9fb9cbb1
YK
1/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9fb9cbb1
YK
7 */
8
9fb9cbb1 9#include <linux/types.h>
9fb9cbb1 10#include <linux/timer.h>
9fb9cbb1
YK
11#include <linux/module.h>
12#include <linux/in.h>
13#include <linux/tcp.h>
14#include <linux/spinlock.h>
15#include <linux/skbuff.h>
16#include <linux/ipv6.h>
17#include <net/ip6_checksum.h>
534f81a5 18#include <asm/unaligned.h>
9fb9cbb1
YK
19
20#include <net/tcp.h>
21
22#include <linux/netfilter.h>
23#include <linux/netfilter_ipv4.h>
24#include <linux/netfilter_ipv6.h>
25#include <net/netfilter/nf_conntrack.h>
605dcad6 26#include <net/netfilter/nf_conntrack_l4proto.h>
f6180121 27#include <net/netfilter/nf_conntrack_ecache.h>
f01ffbd6 28#include <net/netfilter/nf_log.h>
9d2493f8
CP
29#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
30#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
9fb9cbb1 31
c88130bc 32/* Protects ct->proto.tcp */
9fb9cbb1
YK
33static DEFINE_RWLOCK(tcp_lock);
34
601e68e1
YH
35/* "Be conservative in what you do,
36 be liberal in what you accept from others."
9fb9cbb1 37 If it's non-zero, we mark only out of window RST segments as INVALID. */
3aef0fd9 38static int nf_ct_tcp_be_liberal __read_mostly = 0;
9fb9cbb1 39
a09113c2 40/* If it is set to zero, we disable picking up already established
9fb9cbb1 41 connections. */
3aef0fd9 42static int nf_ct_tcp_loose __read_mostly = 1;
9fb9cbb1 43
601e68e1
YH
44/* Max number of the retransmitted packets without receiving an (acceptable)
45 ACK from the destination. If this number is reached, a shorter timer
9fb9cbb1 46 will be started. */
3aef0fd9 47static int nf_ct_tcp_max_retrans __read_mostly = 3;
9fb9cbb1
YK
48
49 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
50 closely. They're more complex. --RR */
51
82f568fc 52static const char *const tcp_conntrack_names[] = {
9fb9cbb1
YK
53 "NONE",
54 "SYN_SENT",
55 "SYN_RECV",
56 "ESTABLISHED",
57 "FIN_WAIT",
58 "CLOSE_WAIT",
59 "LAST_ACK",
60 "TIME_WAIT",
61 "CLOSE",
62 "LISTEN"
63};
601e68e1 64
9fb9cbb1
YK
65#define SECS * HZ
66#define MINS * 60 SECS
67#define HOURS * 60 MINS
68#define DAYS * 24 HOURS
69
9fb9cbb1 70/* RFC1122 says the R2 limit should be at least 100 seconds.
601e68e1 71 Linux uses 15 packets as limit, which corresponds
9fb9cbb1 72 to ~13-30min depending on RTO. */
ae375044
PM
73static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
74static unsigned int nf_ct_tcp_timeout_unacknowledged __read_mostly = 5 MINS;
601e68e1 75
2d646286
PM
76static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
77 [TCP_CONNTRACK_SYN_SENT] = 2 MINS,
78 [TCP_CONNTRACK_SYN_RECV] = 60 SECS,
79 [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS,
80 [TCP_CONNTRACK_FIN_WAIT] = 2 MINS,
81 [TCP_CONNTRACK_CLOSE_WAIT] = 60 SECS,
82 [TCP_CONNTRACK_LAST_ACK] = 30 SECS,
83 [TCP_CONNTRACK_TIME_WAIT] = 2 MINS,
84 [TCP_CONNTRACK_CLOSE] = 10 SECS,
85};
601e68e1 86
9fb9cbb1
YK
87#define sNO TCP_CONNTRACK_NONE
88#define sSS TCP_CONNTRACK_SYN_SENT
89#define sSR TCP_CONNTRACK_SYN_RECV
90#define sES TCP_CONNTRACK_ESTABLISHED
91#define sFW TCP_CONNTRACK_FIN_WAIT
92#define sCW TCP_CONNTRACK_CLOSE_WAIT
93#define sLA TCP_CONNTRACK_LAST_ACK
94#define sTW TCP_CONNTRACK_TIME_WAIT
95#define sCL TCP_CONNTRACK_CLOSE
96#define sLI TCP_CONNTRACK_LISTEN
97#define sIV TCP_CONNTRACK_MAX
98#define sIG TCP_CONNTRACK_IGNORE
99
100/* What TCP flags are set from RST/SYN/FIN/ACK. */
101enum tcp_bit_set {
102 TCP_SYN_SET,
103 TCP_SYNACK_SET,
104 TCP_FIN_SET,
105 TCP_ACK_SET,
106 TCP_RST_SET,
107 TCP_NONE_SET,
108};
601e68e1 109
9fb9cbb1
YK
110/*
111 * The TCP state transition table needs a few words...
112 *
113 * We are the man in the middle. All the packets go through us
114 * but might get lost in transit to the destination.
601e68e1 115 * It is assumed that the destinations can't receive segments
9fb9cbb1
YK
116 * we haven't seen.
117 *
118 * The checked segment is in window, but our windows are *not*
119 * equivalent with the ones of the sender/receiver. We always
120 * try to guess the state of the current sender.
121 *
122 * The meaning of the states are:
123 *
124 * NONE: initial state
601e68e1 125 * SYN_SENT: SYN-only packet seen
9fb9cbb1
YK
126 * SYN_RECV: SYN-ACK packet seen
127 * ESTABLISHED: ACK packet seen
128 * FIN_WAIT: FIN packet seen
601e68e1 129 * CLOSE_WAIT: ACK seen (after FIN)
9fb9cbb1
YK
130 * LAST_ACK: FIN seen (after FIN)
131 * TIME_WAIT: last ACK seen
b2155e7f 132 * CLOSE: closed connection (RST)
9fb9cbb1
YK
133 *
134 * LISTEN state is not used.
135 *
136 * Packets marked as IGNORED (sIG):
601e68e1
YH
137 * if they may be either invalid or valid
138 * and the receiver may send back a connection
9fb9cbb1
YK
139 * closing RST or a SYN/ACK.
140 *
141 * Packets marked as INVALID (sIV):
142 * if they are invalid
143 * or we do not support the request (simultaneous open)
144 */
a5e73c29 145static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
9fb9cbb1
YK
146 {
147/* ORIGINAL */
148/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
149/*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
150/*
151 * sNO -> sSS Initialize a new connection
152 * sSS -> sSS Retransmitted SYN
153 * sSR -> sIG Late retransmitted SYN?
154 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
601e68e1 155 * are errors. Receiver will reply with RST
9fb9cbb1
YK
156 * and close the connection.
157 * Or we are not in sync and hold a dead connection.
158 * sFW -> sIG
159 * sCW -> sIG
160 * sLA -> sIG
161 * sTW -> sSS Reopened connection (RFC 1122).
162 * sCL -> sSS
163 */
164/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
165/*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
166/*
167 * A SYN/ACK from the client is always invalid:
601e68e1 168 * - either it tries to set up a simultaneous open, which is
9fb9cbb1
YK
169 * not supported;
170 * - or the firewall has just been inserted between the two hosts
601e68e1 171 * during the session set-up. The SYN will be retransmitted
9fb9cbb1
YK
172 * by the true client (or it'll time out).
173 */
174/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
175/*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
176/*
177 * sNO -> sIV Too late and no reason to do anything...
178 * sSS -> sIV Client migth not send FIN in this state:
179 * we enforce waiting for a SYN/ACK reply first.
180 * sSR -> sFW Close started.
181 * sES -> sFW
182 * sFW -> sLA FIN seen in both directions, waiting for
601e68e1 183 * the last ACK.
9fb9cbb1
YK
184 * Migth be a retransmitted FIN as well...
185 * sCW -> sLA
186 * sLA -> sLA Retransmitted FIN. Remain in the same state.
187 * sTW -> sTW
188 * sCL -> sCL
189 */
190/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
191/*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
192/*
193 * sNO -> sES Assumed.
194 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
195 * sSR -> sES Established state is reached.
196 * sES -> sES :-)
197 * sFW -> sCW Normal close request answered by ACK.
198 * sCW -> sCW
199 * sLA -> sTW Last ACK detected.
200 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
201 * sCL -> sCL
202 */
203/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
204/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
205/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
206 },
207 {
208/* REPLY */
209/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
210/*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
211/*
212 * sNO -> sIV Never reached.
213 * sSS -> sIV Simultaneous open, not supported
214 * sSR -> sIV Simultaneous open, not supported.
215 * sES -> sIV Server may not initiate a connection.
216 * sFW -> sIV
217 * sCW -> sIV
218 * sLA -> sIV
219 * sTW -> sIV Reopened connection, but server may not do it.
220 * sCL -> sIV
221 */
222/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
223/*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
224/*
225 * sSS -> sSR Standard open.
226 * sSR -> sSR Retransmitted SYN/ACK.
227 * sES -> sIG Late retransmitted SYN/ACK?
228 * sFW -> sIG Might be SYN/ACK answering ignored SYN
229 * sCW -> sIG
230 * sLA -> sIG
231 * sTW -> sIG
232 * sCL -> sIG
233 */
234/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
235/*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
236/*
237 * sSS -> sIV Server might not send FIN in this state.
238 * sSR -> sFW Close started.
239 * sES -> sFW
240 * sFW -> sLA FIN seen in both directions.
241 * sCW -> sLA
242 * sLA -> sLA Retransmitted FIN.
243 * sTW -> sTW
244 * sCL -> sCL
245 */
246/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
73f30602 247/*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
9fb9cbb1 248/*
73f30602 249 * sSS -> sIG Might be a half-open connection.
9fb9cbb1
YK
250 * sSR -> sSR Might answer late resent SYN.
251 * sES -> sES :-)
252 * sFW -> sCW Normal close request answered by ACK.
253 * sCW -> sCW
254 * sLA -> sTW Last ACK detected.
255 * sTW -> sTW Retransmitted last ACK.
256 * sCL -> sCL
257 */
258/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
259/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
260/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
601e68e1 261 }
9fb9cbb1
YK
262};
263
09f263cd
JE
264static bool tcp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
265 struct nf_conntrack_tuple *tuple)
9fb9cbb1 266{
82f568fc
JE
267 const struct tcphdr *hp;
268 struct tcphdr _hdr;
9fb9cbb1
YK
269
270 /* Actually only need first 8 bytes. */
271 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
272 if (hp == NULL)
09f263cd 273 return false;
9fb9cbb1
YK
274
275 tuple->src.u.tcp.port = hp->source;
276 tuple->dst.u.tcp.port = hp->dest;
277
09f263cd 278 return true;
9fb9cbb1
YK
279}
280
09f263cd
JE
281static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
282 const struct nf_conntrack_tuple *orig)
9fb9cbb1
YK
283{
284 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
285 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
09f263cd 286 return true;
9fb9cbb1
YK
287}
288
289/* Print out the per-protocol part of the tuple. */
290static int tcp_print_tuple(struct seq_file *s,
291 const struct nf_conntrack_tuple *tuple)
292{
293 return seq_printf(s, "sport=%hu dport=%hu ",
294 ntohs(tuple->src.u.tcp.port),
295 ntohs(tuple->dst.u.tcp.port));
296}
297
298/* Print out the private part of the conntrack. */
c88130bc 299static int tcp_print_conntrack(struct seq_file *s, const struct nf_conn *ct)
9fb9cbb1
YK
300{
301 enum tcp_conntrack state;
302
303 read_lock_bh(&tcp_lock);
c88130bc 304 state = ct->proto.tcp.state;
9fb9cbb1
YK
305 read_unlock_bh(&tcp_lock);
306
307 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
308}
309
310static unsigned int get_conntrack_index(const struct tcphdr *tcph)
311{
312 if (tcph->rst) return TCP_RST_SET;
313 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
314 else if (tcph->fin) return TCP_FIN_SET;
315 else if (tcph->ack) return TCP_ACK_SET;
316 else return TCP_NONE_SET;
317}
318
319/* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
320 in IP Filter' by Guido van Rooij.
601e68e1 321
9fb9cbb1
YK
322 http://www.nluug.nl/events/sane2000/papers.html
323 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
601e68e1 324
9fb9cbb1
YK
325 The boundaries and the conditions are changed according to RFC793:
326 the packet must intersect the window (i.e. segments may be
327 after the right or before the left edge) and thus receivers may ACK
328 segments after the right edge of the window.
329
601e68e1 330 td_maxend = max(sack + max(win,1)) seen in reply packets
9fb9cbb1
YK
331 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
332 td_maxwin += seq + len - sender.td_maxend
333 if seq + len > sender.td_maxend
334 td_end = max(seq + len) seen in sent packets
601e68e1 335
9fb9cbb1
YK
336 I. Upper bound for valid data: seq <= sender.td_maxend
337 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
84ebe1cd
JK
338 III. Upper bound for valid (s)ack: sack <= receiver.td_end
339 IV. Lower bound for valid (s)ack: sack >= receiver.td_end - MAXACKWINDOW
9fb9cbb1 340
84ebe1cd
JK
341 where sack is the highest right edge of sack block found in the packet
342 or ack in the case of packet without SACK option.
9fb9cbb1 343
84ebe1cd 344 The upper bound limit for a valid (s)ack is not ignored -
601e68e1 345 we doesn't have to deal with fragments.
9fb9cbb1
YK
346*/
347
348static inline __u32 segment_seq_plus_len(__u32 seq,
349 size_t len,
350 unsigned int dataoff,
82f568fc 351 const struct tcphdr *tcph)
9fb9cbb1
YK
352{
353 /* XXX Should I use payload length field in IP/IPv6 header ?
354 * - YK */
355 return (seq + len - dataoff - tcph->doff*4
356 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
357}
601e68e1 358
9fb9cbb1
YK
359/* Fixme: what about big packets? */
360#define MAXACKWINCONST 66000
361#define MAXACKWINDOW(sender) \
362 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
363 : MAXACKWINCONST)
601e68e1 364
9fb9cbb1
YK
365/*
366 * Simplified tcp_parse_options routine from tcp_input.c
367 */
368static void tcp_options(const struct sk_buff *skb,
369 unsigned int dataoff,
82f568fc 370 const struct tcphdr *tcph,
9fb9cbb1
YK
371 struct ip_ct_tcp_state *state)
372{
373 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
82f568fc 374 const unsigned char *ptr;
9fb9cbb1
YK
375 int length = (tcph->doff*4) - sizeof(struct tcphdr);
376
377 if (!length)
378 return;
379
380 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
381 length, buff);
382 BUG_ON(ptr == NULL);
383
601e68e1 384 state->td_scale =
9fb9cbb1
YK
385 state->flags = 0;
386
387 while (length > 0) {
388 int opcode=*ptr++;
389 int opsize;
390
391 switch (opcode) {
392 case TCPOPT_EOL:
393 return;
394 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
395 length--;
396 continue;
397 default:
398 opsize=*ptr++;
399 if (opsize < 2) /* "silly options" */
400 return;
401 if (opsize > length)
402 break; /* don't parse partial options */
403
601e68e1 404 if (opcode == TCPOPT_SACK_PERM
9fb9cbb1
YK
405 && opsize == TCPOLEN_SACK_PERM)
406 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
407 else if (opcode == TCPOPT_WINDOW
408 && opsize == TCPOLEN_WINDOW) {
409 state->td_scale = *(u_int8_t *)ptr;
410
411 if (state->td_scale > 14) {
412 /* See RFC1323 */
413 state->td_scale = 14;
414 }
415 state->flags |=
416 IP_CT_TCP_FLAG_WINDOW_SCALE;
417 }
418 ptr += opsize - 2;
419 length -= opsize;
420 }
421 }
422}
423
424static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
82f568fc 425 const struct tcphdr *tcph, __u32 *sack)
9fb9cbb1 426{
601e68e1 427 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
82f568fc 428 const unsigned char *ptr;
9fb9cbb1
YK
429 int length = (tcph->doff*4) - sizeof(struct tcphdr);
430 __u32 tmp;
431
432 if (!length)
433 return;
434
435 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
436 length, buff);
437 BUG_ON(ptr == NULL);
438
439 /* Fast path for timestamp-only option */
440 if (length == TCPOLEN_TSTAMP_ALIGNED*4
8f05ce91
YH
441 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
442 | (TCPOPT_NOP << 16)
443 | (TCPOPT_TIMESTAMP << 8)
444 | TCPOLEN_TIMESTAMP))
9fb9cbb1
YK
445 return;
446
447 while (length > 0) {
448 int opcode = *ptr++;
449 int opsize, i;
450
451 switch (opcode) {
452 case TCPOPT_EOL:
453 return;
454 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
455 length--;
456 continue;
457 default:
458 opsize = *ptr++;
459 if (opsize < 2) /* "silly options" */
460 return;
461 if (opsize > length)
462 break; /* don't parse partial options */
463
601e68e1
YH
464 if (opcode == TCPOPT_SACK
465 && opsize >= (TCPOLEN_SACK_BASE
466 + TCPOLEN_SACK_PERBLOCK)
467 && !((opsize - TCPOLEN_SACK_BASE)
468 % TCPOLEN_SACK_PERBLOCK)) {
469 for (i = 0;
470 i < (opsize - TCPOLEN_SACK_BASE);
471 i += TCPOLEN_SACK_PERBLOCK) {
534f81a5 472 tmp = get_unaligned_be32((__be32 *)(ptr+i)+1);
9fb9cbb1
YK
473
474 if (after(tmp, *sack))
475 *sack = tmp;
476 }
477 return;
478 }
479 ptr += opsize - 2;
480 length -= opsize;
481 }
482 }
483}
484
09f263cd
JE
485static bool tcp_in_window(const struct nf_conn *ct,
486 struct ip_ct_tcp *state,
487 enum ip_conntrack_dir dir,
488 unsigned int index,
489 const struct sk_buff *skb,
490 unsigned int dataoff,
491 const struct tcphdr *tcph,
76108cea 492 u_int8_t pf)
9fb9cbb1 493{
c2a2c7e0 494 struct net *net = nf_ct_net(ct);
9fb9cbb1
YK
495 struct ip_ct_tcp_state *sender = &state->seen[dir];
496 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
82f568fc 497 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
9fb9cbb1 498 __u32 seq, ack, sack, end, win, swin;
09f263cd 499 bool res;
9fb9cbb1
YK
500
501 /*
502 * Get the required data from the packet.
503 */
504 seq = ntohl(tcph->seq);
505 ack = sack = ntohl(tcph->ack_seq);
506 win = ntohs(tcph->window);
507 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
508
509 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
510 tcp_sack(skb, dataoff, tcph, &sack);
511
0d53778e
PM
512 pr_debug("tcp_in_window: START\n");
513 pr_debug("tcp_in_window: ");
3c9fba65 514 nf_ct_dump_tuple(tuple);
0d53778e
PM
515 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
516 seq, ack, sack, win, end);
517 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
518 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
519 sender->td_end, sender->td_maxend, sender->td_maxwin,
520 sender->td_scale,
521 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
522 receiver->td_scale);
9fb9cbb1
YK
523
524 if (sender->td_end == 0) {
525 /*
526 * Initialize sender data.
527 */
528 if (tcph->syn && tcph->ack) {
529 /*
530 * Outgoing SYN-ACK in reply to a SYN.
531 */
601e68e1 532 sender->td_end =
9fb9cbb1
YK
533 sender->td_maxend = end;
534 sender->td_maxwin = (win == 0 ? 1 : win);
535
536 tcp_options(skb, dataoff, tcph, sender);
601e68e1 537 /*
9fb9cbb1
YK
538 * RFC 1323:
539 * Both sides must send the Window Scale option
540 * to enable window scaling in either direction.
541 */
542 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
543 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
601e68e1 544 sender->td_scale =
9fb9cbb1
YK
545 receiver->td_scale = 0;
546 } else {
547 /*
548 * We are in the middle of a connection,
549 * its history is lost for us.
550 * Let's try to use the data from the packet.
601e68e1 551 */
9fb9cbb1
YK
552 sender->td_end = end;
553 sender->td_maxwin = (win == 0 ? 1 : win);
554 sender->td_maxend = end + sender->td_maxwin;
555 }
556 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
557 && dir == IP_CT_DIR_ORIGINAL)
558 || (state->state == TCP_CONNTRACK_SYN_RECV
559 && dir == IP_CT_DIR_REPLY))
560 && after(end, sender->td_end)) {
561 /*
562 * RFC 793: "if a TCP is reinitialized ... then it need
601e68e1 563 * not wait at all; it must only be sure to use sequence
9fb9cbb1
YK
564 * numbers larger than those recently used."
565 */
566 sender->td_end =
567 sender->td_maxend = end;
568 sender->td_maxwin = (win == 0 ? 1 : win);
569
570 tcp_options(skb, dataoff, tcph, sender);
571 }
572
573 if (!(tcph->ack)) {
574 /*
575 * If there is no ACK, just pretend it was set and OK.
576 */
577 ack = sack = receiver->td_end;
601e68e1
YH
578 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
579 (TCP_FLAG_ACK|TCP_FLAG_RST))
9fb9cbb1
YK
580 && (ack == 0)) {
581 /*
582 * Broken TCP stacks, that set ACK in RST packets as well
583 * with zero ack value.
584 */
585 ack = sack = receiver->td_end;
586 }
587
588 if (seq == end
589 && (!tcph->rst
590 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
591 /*
592 * Packets contains no data: we assume it is valid
593 * and check the ack value only.
594 * However RST segments are always validated by their
595 * SEQ number, except when seq == 0 (reset sent answering
596 * SYN.
597 */
598 seq = end = sender->td_end;
599
0d53778e 600 pr_debug("tcp_in_window: ");
3c9fba65 601 nf_ct_dump_tuple(tuple);
0d53778e
PM
602 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
603 seq, ack, sack, win, end);
604 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
605 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
606 sender->td_end, sender->td_maxend, sender->td_maxwin,
607 sender->td_scale,
608 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
609 receiver->td_scale);
610
611 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
612 before(seq, sender->td_maxend + 1),
613 after(end, sender->td_end - receiver->td_maxwin - 1),
614 before(sack, receiver->td_end + 1),
84ebe1cd 615 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
9fb9cbb1 616
a09113c2
PM
617 if (before(seq, sender->td_maxend + 1) &&
618 after(end, sender->td_end - receiver->td_maxwin - 1) &&
619 before(sack, receiver->td_end + 1) &&
84ebe1cd 620 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
601e68e1 621 /*
9fb9cbb1
YK
622 * Take into account window scaling (RFC 1323).
623 */
624 if (!tcph->syn)
625 win <<= sender->td_scale;
626
627 /*
628 * Update sender data.
629 */
630 swin = win + (sack - ack);
631 if (sender->td_maxwin < swin)
632 sender->td_maxwin = swin;
ae375044 633 if (after(end, sender->td_end)) {
9fb9cbb1 634 sender->td_end = end;
ae375044
PM
635 sender->flags |= IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
636 }
9fb9cbb1
YK
637 /*
638 * Update receiver data.
639 */
640 if (after(end, sender->td_maxend))
641 receiver->td_maxwin += end - sender->td_maxend;
642 if (after(sack + win, receiver->td_maxend - 1)) {
643 receiver->td_maxend = sack + win;
644 if (win == 0)
645 receiver->td_maxend++;
646 }
ae375044
PM
647 if (ack == receiver->td_end)
648 receiver->flags &= ~IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
9fb9cbb1 649
601e68e1 650 /*
9fb9cbb1
YK
651 * Check retransmissions.
652 */
653 if (index == TCP_ACK_SET) {
654 if (state->last_dir == dir
655 && state->last_seq == seq
656 && state->last_ack == ack
c1fe3ca5
GH
657 && state->last_end == end
658 && state->last_win == win)
9fb9cbb1
YK
659 state->retrans++;
660 else {
661 state->last_dir = dir;
662 state->last_seq = seq;
663 state->last_ack = ack;
664 state->last_end = end;
c1fe3ca5 665 state->last_win = win;
9fb9cbb1
YK
666 state->retrans = 0;
667 }
668 }
09f263cd 669 res = true;
9fb9cbb1 670 } else {
09f263cd 671 res = false;
a09113c2
PM
672 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
673 nf_ct_tcp_be_liberal)
09f263cd 674 res = true;
c2a2c7e0 675 if (!res && LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
676 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
677 "nf_ct_tcp: %s ",
678 before(seq, sender->td_maxend + 1) ?
679 after(end, sender->td_end - receiver->td_maxwin - 1) ?
680 before(sack, receiver->td_end + 1) ?
681 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
682 : "ACK is under the lower bound (possible overly delayed ACK)"
683 : "ACK is over the upper bound (ACKed data not seen yet)"
684 : "SEQ is under the lower bound (already ACKed data retransmitted)"
685 : "SEQ is over the upper bound (over the window of the receiver)");
601e68e1
YH
686 }
687
09f263cd 688 pr_debug("tcp_in_window: res=%u sender end=%u maxend=%u maxwin=%u "
0d53778e
PM
689 "receiver end=%u maxend=%u maxwin=%u\n",
690 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
691 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
9fb9cbb1
YK
692
693 return res;
694}
695
5b1158e9 696#ifdef CONFIG_NF_NAT_NEEDED
9fb9cbb1
YK
697/* Update sender->td_end after NAT successfully mangled the packet */
698/* Caller must linearize skb at tcp header. */
82f568fc 699void nf_conntrack_tcp_update(const struct sk_buff *skb,
9fb9cbb1 700 unsigned int dataoff,
c88130bc 701 struct nf_conn *ct,
9fb9cbb1
YK
702 int dir)
703{
82f568fc
JE
704 const struct tcphdr *tcph = (const void *)skb->data + dataoff;
705 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[dir];
706 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[!dir];
0d53778e 707 __u32 end;
9fb9cbb1
YK
708
709 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
710
711 write_lock_bh(&tcp_lock);
712 /*
713 * We have to worry for the ack in the reply packet only...
714 */
c88130bc
PM
715 if (after(end, ct->proto.tcp.seen[dir].td_end))
716 ct->proto.tcp.seen[dir].td_end = end;
717 ct->proto.tcp.last_end = end;
9fb9cbb1 718 write_unlock_bh(&tcp_lock);
0d53778e
PM
719 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
720 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
721 sender->td_end, sender->td_maxend, sender->td_maxwin,
722 sender->td_scale,
723 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
724 receiver->td_scale);
9fb9cbb1 725}
13b18339 726EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
9fb9cbb1
YK
727#endif
728
729#define TH_FIN 0x01
730#define TH_SYN 0x02
731#define TH_RST 0x04
732#define TH_PUSH 0x08
733#define TH_ACK 0x10
734#define TH_URG 0x20
735#define TH_ECE 0x40
736#define TH_CWR 0x80
737
5c8ce7c9 738/* table of valid flag combinations - PUSH, ECE and CWR are always valid */
82f568fc 739static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
9fb9cbb1
YK
740{
741 [TH_SYN] = 1,
d3ab4298 742 [TH_SYN|TH_URG] = 1,
d3ab4298 743 [TH_SYN|TH_ACK] = 1,
9fb9cbb1
YK
744 [TH_RST] = 1,
745 [TH_RST|TH_ACK] = 1,
9fb9cbb1 746 [TH_FIN|TH_ACK] = 1,
5c8ce7c9 747 [TH_FIN|TH_ACK|TH_URG] = 1,
9fb9cbb1 748 [TH_ACK] = 1,
9fb9cbb1 749 [TH_ACK|TH_URG] = 1,
9fb9cbb1
YK
750};
751
752/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
74c51a14
AD
753static int tcp_error(struct net *net,
754 struct sk_buff *skb,
9fb9cbb1
YK
755 unsigned int dataoff,
756 enum ip_conntrack_info *ctinfo,
76108cea 757 u_int8_t pf,
96f6bf82 758 unsigned int hooknum)
9fb9cbb1 759{
82f568fc
JE
760 const struct tcphdr *th;
761 struct tcphdr _tcph;
9fb9cbb1
YK
762 unsigned int tcplen = skb->len - dataoff;
763 u_int8_t tcpflags;
764
765 /* Smaller that minimal TCP header? */
766 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
767 if (th == NULL) {
c2a2c7e0 768 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
769 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
770 "nf_ct_tcp: short packet ");
771 return -NF_ACCEPT;
601e68e1
YH
772 }
773
9fb9cbb1
YK
774 /* Not whole TCP header or malformed packet */
775 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
c2a2c7e0 776 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
777 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
778 "nf_ct_tcp: truncated/malformed packet ");
779 return -NF_ACCEPT;
780 }
601e68e1 781
9fb9cbb1
YK
782 /* Checksum invalid? Ignore.
783 * We skip checking packets on the outgoing path
84fa7933 784 * because the checksum is assumed to be correct.
9fb9cbb1
YK
785 */
786 /* FIXME: Source route IP option packets --RR */
c04d0552 787 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
96f6bf82 788 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
c2a2c7e0 789 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
790 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
791 "nf_ct_tcp: bad TCP checksum ");
792 return -NF_ACCEPT;
793 }
794
795 /* Check TCP flags. */
5c8ce7c9 796 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
9fb9cbb1 797 if (!tcp_valid_flags[tcpflags]) {
c2a2c7e0 798 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
799 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
800 "nf_ct_tcp: invalid TCP flag combination ");
801 return -NF_ACCEPT;
802 }
803
804 return NF_ACCEPT;
805}
806
9fb9cbb1 807/* Returns verdict for packet, or -1 for invalid. */
c88130bc 808static int tcp_packet(struct nf_conn *ct,
9fb9cbb1
YK
809 const struct sk_buff *skb,
810 unsigned int dataoff,
811 enum ip_conntrack_info ctinfo,
76108cea 812 u_int8_t pf,
9fb9cbb1
YK
813 unsigned int hooknum)
814{
c2a2c7e0 815 struct net *net = nf_ct_net(ct);
0d53778e 816 struct nf_conntrack_tuple *tuple;
9fb9cbb1
YK
817 enum tcp_conntrack new_state, old_state;
818 enum ip_conntrack_dir dir;
82f568fc
JE
819 const struct tcphdr *th;
820 struct tcphdr _tcph;
9fb9cbb1
YK
821 unsigned long timeout;
822 unsigned int index;
823
824 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
825 BUG_ON(th == NULL);
826
827 write_lock_bh(&tcp_lock);
c88130bc 828 old_state = ct->proto.tcp.state;
9fb9cbb1
YK
829 dir = CTINFO2DIR(ctinfo);
830 index = get_conntrack_index(th);
831 new_state = tcp_conntracks[dir][index][old_state];
c88130bc 832 tuple = &ct->tuplehash[dir].tuple;
9fb9cbb1
YK
833
834 switch (new_state) {
17311393
JK
835 case TCP_CONNTRACK_SYN_SENT:
836 if (old_state < TCP_CONNTRACK_TIME_WAIT)
837 break;
b2155e7f
JK
838 /* RFC 1122: "When a connection is closed actively,
839 * it MUST linger in TIME-WAIT state for a time 2xMSL
840 * (Maximum Segment Lifetime). However, it MAY accept
841 * a new SYN from the remote TCP to reopen the connection
842 * directly from TIME-WAIT state, if..."
843 * We ignore the conditions because we are in the
844 * TIME-WAIT state anyway.
845 *
846 * Handle aborted connections: we and the server
847 * think there is an existing connection but the client
848 * aborts it and starts a new one.
849 */
850 if (((ct->proto.tcp.seen[dir].flags
851 | ct->proto.tcp.seen[!dir].flags)
852 & IP_CT_TCP_FLAG_CLOSE_INIT)
c88130bc
PM
853 || (ct->proto.tcp.last_dir == dir
854 && ct->proto.tcp.last_index == TCP_RST_SET)) {
bc34b841
JK
855 /* Attempt to reopen a closed/aborted connection.
856 * Delete this connection and look up again. */
17311393 857 write_unlock_bh(&tcp_lock);
2aec609f 858
6b69fe0c
PM
859 /* Only repeat if we can actually remove the timer.
860 * Destruction may already be in progress in process
861 * context and we must give it a chance to terminate.
862 */
2aec609f 863 if (nf_ct_kill(ct))
6b69fe0c 864 return -NF_REPEAT;
ec8d5409 865 return NF_DROP;
17311393
JK
866 }
867 /* Fall through */
9fb9cbb1 868 case TCP_CONNTRACK_IGNORE:
73f30602 869 /* Ignored packets:
b2155e7f
JK
870 *
871 * Our connection entry may be out of sync, so ignore
872 * packets which may signal the real connection between
873 * the client and the server.
73f30602
JK
874 *
875 * a) SYN in ORIGINAL
876 * b) SYN/ACK in REPLY
601e68e1 877 * c) ACK in reply direction after initial SYN in original.
b2155e7f
JK
878 *
879 * If the ignored packet is invalid, the receiver will send
880 * a RST we'll catch below.
73f30602 881 */
9fb9cbb1 882 if (index == TCP_SYNACK_SET
c88130bc
PM
883 && ct->proto.tcp.last_index == TCP_SYN_SET
884 && ct->proto.tcp.last_dir != dir
885 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
b2155e7f 886 /* b) This SYN/ACK acknowledges a SYN that we earlier
9fb9cbb1
YK
887 * ignored as invalid. This means that the client and
888 * the server are both in sync, while the firewall is
889 * not. We kill this session and block the SYN/ACK so
601e68e1 890 * that the client cannot but retransmit its SYN and
9fb9cbb1
YK
891 * thus initiate a clean new session.
892 */
601e68e1 893 write_unlock_bh(&tcp_lock);
c2a2c7e0 894 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
895 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
896 "nf_ct_tcp: killing out of sync session ");
51091764 897 nf_ct_kill(ct);
ec8d5409 898 return NF_DROP;
9fb9cbb1 899 }
c88130bc
PM
900 ct->proto.tcp.last_index = index;
901 ct->proto.tcp.last_dir = dir;
902 ct->proto.tcp.last_seq = ntohl(th->seq);
903 ct->proto.tcp.last_end =
9fb9cbb1
YK
904 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
905
906 write_unlock_bh(&tcp_lock);
c2a2c7e0 907 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1 908 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
b2155e7f 909 "nf_ct_tcp: invalid packet ignored ");
9fb9cbb1
YK
910 return NF_ACCEPT;
911 case TCP_CONNTRACK_MAX:
912 /* Invalid packet */
0d53778e
PM
913 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
914 dir, get_conntrack_index(th), old_state);
9fb9cbb1 915 write_unlock_bh(&tcp_lock);
c2a2c7e0 916 if (LOG_INVALID(net, IPPROTO_TCP))
9fb9cbb1
YK
917 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
918 "nf_ct_tcp: invalid state ");
919 return -NF_ACCEPT;
9fb9cbb1
YK
920 case TCP_CONNTRACK_CLOSE:
921 if (index == TCP_RST_SET
c88130bc
PM
922 && ((test_bit(IPS_SEEN_REPLY_BIT, &ct->status)
923 && ct->proto.tcp.last_index == TCP_SYN_SET)
924 || (!test_bit(IPS_ASSURED_BIT, &ct->status)
925 && ct->proto.tcp.last_index == TCP_ACK_SET))
926 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
93b1fae4 927 /* RST sent to invalid SYN or ACK we had let through
73f30602
JK
928 * at a) and c) above:
929 *
930 * a) SYN was in window then
931 * c) we hold a half-open connection.
932 *
933 * Delete our connection entry.
9fb9cbb1 934 * We skip window checking, because packet might ACK
73f30602 935 * segments we ignored. */
9fb9cbb1
YK
936 goto in_window;
937 }
93b1fae4 938 /* Just fall through */
9fb9cbb1
YK
939 default:
940 /* Keep compilers happy. */
941 break;
942 }
943
c88130bc 944 if (!tcp_in_window(ct, &ct->proto.tcp, dir, index,
9fb9cbb1
YK
945 skb, dataoff, th, pf)) {
946 write_unlock_bh(&tcp_lock);
947 return -NF_ACCEPT;
948 }
949 in_window:
950 /* From now on we have got in-window packets */
c88130bc
PM
951 ct->proto.tcp.last_index = index;
952 ct->proto.tcp.last_dir = dir;
9fb9cbb1 953
0d53778e 954 pr_debug("tcp_conntracks: ");
3c9fba65 955 nf_ct_dump_tuple(tuple);
0d53778e
PM
956 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
957 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
958 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
959 old_state, new_state);
9fb9cbb1 960
c88130bc 961 ct->proto.tcp.state = new_state;
9fb9cbb1 962 if (old_state != new_state
d0c1fd7a 963 && new_state == TCP_CONNTRACK_FIN_WAIT)
c88130bc 964 ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
ae375044
PM
965
966 if (ct->proto.tcp.retrans >= nf_ct_tcp_max_retrans &&
967 tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans)
968 timeout = nf_ct_tcp_timeout_max_retrans;
969 else if ((ct->proto.tcp.seen[0].flags | ct->proto.tcp.seen[1].flags) &
970 IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED &&
971 tcp_timeouts[new_state] > nf_ct_tcp_timeout_unacknowledged)
972 timeout = nf_ct_tcp_timeout_unacknowledged;
973 else
974 timeout = tcp_timeouts[new_state];
9fb9cbb1
YK
975 write_unlock_bh(&tcp_lock);
976
a71996fc 977 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, ct);
9fb9cbb1 978 if (new_state != old_state)
a71996fc 979 nf_conntrack_event_cache(IPCT_PROTOINFO, ct);
9fb9cbb1 980
c88130bc 981 if (!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
9fb9cbb1
YK
982 /* If only reply is a RST, we can consider ourselves not to
983 have an established connection: this is a fairly common
984 problem case, so we can delete the conntrack
985 immediately. --RR */
986 if (th->rst) {
718d4ad9 987 nf_ct_kill_acct(ct, ctinfo, skb);
9fb9cbb1
YK
988 return NF_ACCEPT;
989 }
c88130bc 990 } else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
9fb9cbb1
YK
991 && (old_state == TCP_CONNTRACK_SYN_RECV
992 || old_state == TCP_CONNTRACK_ESTABLISHED)
993 && new_state == TCP_CONNTRACK_ESTABLISHED) {
601e68e1
YH
994 /* Set ASSURED if we see see valid ack in ESTABLISHED
995 after SYN_RECV or a valid answer for a picked up
9fb9cbb1 996 connection. */
c88130bc 997 set_bit(IPS_ASSURED_BIT, &ct->status);
a71996fc 998 nf_conntrack_event_cache(IPCT_STATUS, ct);
9fb9cbb1 999 }
c88130bc 1000 nf_ct_refresh_acct(ct, ctinfo, skb, timeout);
9fb9cbb1
YK
1001
1002 return NF_ACCEPT;
1003}
601e68e1 1004
9fb9cbb1 1005/* Called when a new connection for this protocol found. */
09f263cd
JE
1006static bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb,
1007 unsigned int dataoff)
9fb9cbb1
YK
1008{
1009 enum tcp_conntrack new_state;
82f568fc
JE
1010 const struct tcphdr *th;
1011 struct tcphdr _tcph;
1012 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0];
1013 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1];
9fb9cbb1
YK
1014
1015 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
1016 BUG_ON(th == NULL);
1017
1018 /* Don't need lock here: this conntrack not in circulation yet */
1019 new_state
1020 = tcp_conntracks[0][get_conntrack_index(th)]
1021 [TCP_CONNTRACK_NONE];
1022
1023 /* Invalid: delete conntrack */
1024 if (new_state >= TCP_CONNTRACK_MAX) {
0d53778e 1025 pr_debug("nf_ct_tcp: invalid new deleting.\n");
09f263cd 1026 return false;
9fb9cbb1
YK
1027 }
1028
1029 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1030 /* SYN packet */
c88130bc 1031 ct->proto.tcp.seen[0].td_end =
9fb9cbb1
YK
1032 segment_seq_plus_len(ntohl(th->seq), skb->len,
1033 dataoff, th);
c88130bc
PM
1034 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1035 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1036 ct->proto.tcp.seen[0].td_maxwin = 1;
1037 ct->proto.tcp.seen[0].td_maxend =
1038 ct->proto.tcp.seen[0].td_end;
1039
1040 tcp_options(skb, dataoff, th, &ct->proto.tcp.seen[0]);
1041 ct->proto.tcp.seen[1].flags = 0;
9fb9cbb1
YK
1042 } else if (nf_ct_tcp_loose == 0) {
1043 /* Don't try to pick up connections. */
09f263cd 1044 return false;
9fb9cbb1
YK
1045 } else {
1046 /*
1047 * We are in the middle of a connection,
1048 * its history is lost for us.
1049 * Let's try to use the data from the packet.
1050 */
c88130bc 1051 ct->proto.tcp.seen[0].td_end =
9fb9cbb1
YK
1052 segment_seq_plus_len(ntohl(th->seq), skb->len,
1053 dataoff, th);
c88130bc
PM
1054 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1055 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1056 ct->proto.tcp.seen[0].td_maxwin = 1;
1057 ct->proto.tcp.seen[0].td_maxend =
1058 ct->proto.tcp.seen[0].td_end +
1059 ct->proto.tcp.seen[0].td_maxwin;
1060 ct->proto.tcp.seen[0].td_scale = 0;
9fb9cbb1 1061
a09113c2
PM
1062 /* We assume SACK and liberal window checking to handle
1063 * window scaling */
c88130bc
PM
1064 ct->proto.tcp.seen[0].flags =
1065 ct->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1066 IP_CT_TCP_FLAG_BE_LIBERAL;
9fb9cbb1 1067 }
601e68e1 1068
c88130bc
PM
1069 ct->proto.tcp.seen[1].td_end = 0;
1070 ct->proto.tcp.seen[1].td_maxend = 0;
1071 ct->proto.tcp.seen[1].td_maxwin = 1;
1072 ct->proto.tcp.seen[1].td_scale = 0;
9fb9cbb1
YK
1073
1074 /* tcp_packet will set them */
c88130bc
PM
1075 ct->proto.tcp.state = TCP_CONNTRACK_NONE;
1076 ct->proto.tcp.last_index = TCP_NONE_SET;
601e68e1 1077
0d53778e
PM
1078 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1079 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1080 sender->td_end, sender->td_maxend, sender->td_maxwin,
1081 sender->td_scale,
1082 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1083 receiver->td_scale);
09f263cd 1084 return true;
9fb9cbb1 1085}
c1d10adb 1086
e281db5c 1087#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
c1d10adb
PNA
1088
1089#include <linux/netfilter/nfnetlink.h>
1090#include <linux/netfilter/nfnetlink_conntrack.h>
1091
fdf70832 1092static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
c1d10adb
PNA
1093 const struct nf_conn *ct)
1094{
df6fb868 1095 struct nlattr *nest_parms;
c8e2078c 1096 struct nf_ct_tcp_flags tmp = {};
601e68e1 1097
c1d10adb 1098 read_lock_bh(&tcp_lock);
df6fb868
PM
1099 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED);
1100 if (!nest_parms)
1101 goto nla_put_failure;
1102
77236b6e 1103 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state);
c8e2078c 1104
77236b6e
PM
1105 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
1106 ct->proto.tcp.seen[0].td_scale);
c8e2078c 1107
77236b6e
PM
1108 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY,
1109 ct->proto.tcp.seen[1].td_scale);
c8e2078c
PNA
1110
1111 tmp.flags = ct->proto.tcp.seen[0].flags;
df6fb868 1112 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
c8e2078c
PNA
1113 sizeof(struct nf_ct_tcp_flags), &tmp);
1114
1115 tmp.flags = ct->proto.tcp.seen[1].flags;
df6fb868 1116 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
c8e2078c 1117 sizeof(struct nf_ct_tcp_flags), &tmp);
c1d10adb
PNA
1118 read_unlock_bh(&tcp_lock);
1119
df6fb868 1120 nla_nest_end(skb, nest_parms);
c1d10adb
PNA
1121
1122 return 0;
1123
df6fb868 1124nla_put_failure:
c1d10adb
PNA
1125 read_unlock_bh(&tcp_lock);
1126 return -1;
1127}
1128
f73e924c
PM
1129static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = {
1130 [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 },
1131 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 },
1132 [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 },
1133 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) },
1134 [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) },
c1d10adb
PNA
1135};
1136
fdf70832 1137static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
c1d10adb 1138{
2f0d2f10 1139 struct nlattr *pattr = cda[CTA_PROTOINFO_TCP];
df6fb868 1140 struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
f73e924c 1141 int err;
c1d10adb
PNA
1142
1143 /* updates could not contain anything about the private
1144 * protocol info, in that case skip the parsing */
2f0d2f10 1145 if (!pattr)
c1d10adb
PNA
1146 return 0;
1147
2f0d2f10 1148 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, tcp_nla_policy);
f73e924c
PM
1149 if (err < 0)
1150 return err;
c1d10adb 1151
5f7da4d2
PM
1152 if (tb[CTA_PROTOINFO_TCP_STATE] &&
1153 nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]) >= TCP_CONNTRACK_MAX)
c1d10adb
PNA
1154 return -EINVAL;
1155
1156 write_lock_bh(&tcp_lock);
5f7da4d2
PM
1157 if (tb[CTA_PROTOINFO_TCP_STATE])
1158 ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]);
c8e2078c 1159
df6fb868 1160 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) {
c8e2078c 1161 struct nf_ct_tcp_flags *attr =
df6fb868 1162 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]);
c8e2078c
PNA
1163 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1164 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1165 }
1166
df6fb868 1167 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) {
c8e2078c 1168 struct nf_ct_tcp_flags *attr =
df6fb868 1169 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]);
c8e2078c
PNA
1170 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1171 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1172 }
1173
df6fb868
PM
1174 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] &&
1175 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] &&
c8e2078c
PNA
1176 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1177 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
77236b6e
PM
1178 ct->proto.tcp.seen[0].td_scale =
1179 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]);
1180 ct->proto.tcp.seen[1].td_scale =
1181 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]);
c8e2078c 1182 }
c1d10adb
PNA
1183 write_unlock_bh(&tcp_lock);
1184
1185 return 0;
1186}
a400c30e
HE
1187
1188static int tcp_nlattr_size(void)
1189{
1190 return nla_total_size(0) /* CTA_PROTOINFO_TCP */
1191 + nla_policy_len(tcp_nla_policy, CTA_PROTOINFO_TCP_MAX + 1);
1192}
1193
1194static int tcp_nlattr_tuple_size(void)
1195{
1196 return nla_policy_len(nf_ct_port_nla_policy, CTA_PROTO_MAX + 1);
1197}
c1d10adb 1198#endif
933a41e7
PM
1199
1200#ifdef CONFIG_SYSCTL
1201static unsigned int tcp_sysctl_table_users;
1202static struct ctl_table_header *tcp_sysctl_header;
1203static struct ctl_table tcp_sysctl_table[] = {
1204 {
933a41e7 1205 .procname = "nf_conntrack_tcp_timeout_syn_sent",
2d646286 1206 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
933a41e7
PM
1207 .maxlen = sizeof(unsigned int),
1208 .mode = 0644,
6d9f239a 1209 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1210 },
1211 {
933a41e7 1212 .procname = "nf_conntrack_tcp_timeout_syn_recv",
2d646286 1213 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
933a41e7
PM
1214 .maxlen = sizeof(unsigned int),
1215 .mode = 0644,
6d9f239a 1216 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1217 },
1218 {
933a41e7 1219 .procname = "nf_conntrack_tcp_timeout_established",
2d646286 1220 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
933a41e7
PM
1221 .maxlen = sizeof(unsigned int),
1222 .mode = 0644,
6d9f239a 1223 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1224 },
1225 {
933a41e7 1226 .procname = "nf_conntrack_tcp_timeout_fin_wait",
2d646286 1227 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
933a41e7
PM
1228 .maxlen = sizeof(unsigned int),
1229 .mode = 0644,
6d9f239a 1230 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1231 },
1232 {
933a41e7 1233 .procname = "nf_conntrack_tcp_timeout_close_wait",
2d646286 1234 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
933a41e7
PM
1235 .maxlen = sizeof(unsigned int),
1236 .mode = 0644,
6d9f239a 1237 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1238 },
1239 {
933a41e7 1240 .procname = "nf_conntrack_tcp_timeout_last_ack",
2d646286 1241 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
933a41e7
PM
1242 .maxlen = sizeof(unsigned int),
1243 .mode = 0644,
6d9f239a 1244 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1245 },
1246 {
933a41e7 1247 .procname = "nf_conntrack_tcp_timeout_time_wait",
2d646286 1248 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
933a41e7
PM
1249 .maxlen = sizeof(unsigned int),
1250 .mode = 0644,
6d9f239a 1251 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1252 },
1253 {
933a41e7 1254 .procname = "nf_conntrack_tcp_timeout_close",
2d646286 1255 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
933a41e7
PM
1256 .maxlen = sizeof(unsigned int),
1257 .mode = 0644,
6d9f239a 1258 .proc_handler = proc_dointvec_jiffies,
933a41e7
PM
1259 },
1260 {
933a41e7
PM
1261 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1262 .data = &nf_ct_tcp_timeout_max_retrans,
1263 .maxlen = sizeof(unsigned int),
1264 .mode = 0644,
6d9f239a 1265 .proc_handler = proc_dointvec_jiffies,
933a41e7 1266 },
ae375044
PM
1267 {
1268 .procname = "nf_conntrack_tcp_timeout_unacknowledged",
1269 .data = &nf_ct_tcp_timeout_unacknowledged,
1270 .maxlen = sizeof(unsigned int),
1271 .mode = 0644,
6d9f239a 1272 .proc_handler = proc_dointvec_jiffies,
ae375044 1273 },
933a41e7
PM
1274 {
1275 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1276 .procname = "nf_conntrack_tcp_loose",
1277 .data = &nf_ct_tcp_loose,
1278 .maxlen = sizeof(unsigned int),
1279 .mode = 0644,
6d9f239a 1280 .proc_handler = proc_dointvec,
933a41e7
PM
1281 },
1282 {
1283 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1284 .procname = "nf_conntrack_tcp_be_liberal",
1285 .data = &nf_ct_tcp_be_liberal,
1286 .maxlen = sizeof(unsigned int),
1287 .mode = 0644,
6d9f239a 1288 .proc_handler = proc_dointvec,
933a41e7
PM
1289 },
1290 {
1291 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1292 .procname = "nf_conntrack_tcp_max_retrans",
1293 .data = &nf_ct_tcp_max_retrans,
1294 .maxlen = sizeof(unsigned int),
1295 .mode = 0644,
6d9f239a 1296 .proc_handler = proc_dointvec,
933a41e7
PM
1297 },
1298 {
1299 .ctl_name = 0
1300 }
1301};
a999e683
PM
1302
1303#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1304static struct ctl_table tcp_compat_sysctl_table[] = {
1305 {
a999e683 1306 .procname = "ip_conntrack_tcp_timeout_syn_sent",
2d646286 1307 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
a999e683
PM
1308 .maxlen = sizeof(unsigned int),
1309 .mode = 0644,
6d9f239a 1310 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1311 },
1312 {
a999e683 1313 .procname = "ip_conntrack_tcp_timeout_syn_recv",
2d646286 1314 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
a999e683
PM
1315 .maxlen = sizeof(unsigned int),
1316 .mode = 0644,
6d9f239a 1317 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1318 },
1319 {
a999e683 1320 .procname = "ip_conntrack_tcp_timeout_established",
2d646286 1321 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
a999e683
PM
1322 .maxlen = sizeof(unsigned int),
1323 .mode = 0644,
6d9f239a 1324 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1325 },
1326 {
a999e683 1327 .procname = "ip_conntrack_tcp_timeout_fin_wait",
2d646286 1328 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
a999e683
PM
1329 .maxlen = sizeof(unsigned int),
1330 .mode = 0644,
6d9f239a 1331 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1332 },
1333 {
a999e683 1334 .procname = "ip_conntrack_tcp_timeout_close_wait",
2d646286 1335 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
a999e683
PM
1336 .maxlen = sizeof(unsigned int),
1337 .mode = 0644,
6d9f239a 1338 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1339 },
1340 {
a999e683 1341 .procname = "ip_conntrack_tcp_timeout_last_ack",
2d646286 1342 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
a999e683
PM
1343 .maxlen = sizeof(unsigned int),
1344 .mode = 0644,
6d9f239a 1345 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1346 },
1347 {
a999e683 1348 .procname = "ip_conntrack_tcp_timeout_time_wait",
2d646286 1349 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
a999e683
PM
1350 .maxlen = sizeof(unsigned int),
1351 .mode = 0644,
6d9f239a 1352 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1353 },
1354 {
a999e683 1355 .procname = "ip_conntrack_tcp_timeout_close",
2d646286 1356 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
a999e683
PM
1357 .maxlen = sizeof(unsigned int),
1358 .mode = 0644,
6d9f239a 1359 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1360 },
1361 {
a999e683
PM
1362 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1363 .data = &nf_ct_tcp_timeout_max_retrans,
1364 .maxlen = sizeof(unsigned int),
1365 .mode = 0644,
6d9f239a 1366 .proc_handler = proc_dointvec_jiffies,
a999e683
PM
1367 },
1368 {
1369 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1370 .procname = "ip_conntrack_tcp_loose",
1371 .data = &nf_ct_tcp_loose,
1372 .maxlen = sizeof(unsigned int),
1373 .mode = 0644,
6d9f239a 1374 .proc_handler = proc_dointvec,
a999e683
PM
1375 },
1376 {
1377 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1378 .procname = "ip_conntrack_tcp_be_liberal",
1379 .data = &nf_ct_tcp_be_liberal,
1380 .maxlen = sizeof(unsigned int),
1381 .mode = 0644,
6d9f239a 1382 .proc_handler = proc_dointvec,
a999e683
PM
1383 },
1384 {
1385 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1386 .procname = "ip_conntrack_tcp_max_retrans",
1387 .data = &nf_ct_tcp_max_retrans,
1388 .maxlen = sizeof(unsigned int),
1389 .mode = 0644,
6d9f239a 1390 .proc_handler = proc_dointvec,
a999e683
PM
1391 },
1392 {
1393 .ctl_name = 0
1394 }
1395};
1396#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
933a41e7
PM
1397#endif /* CONFIG_SYSCTL */
1398
61075af5 1399struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
9fb9cbb1
YK
1400{
1401 .l3proto = PF_INET,
605dcad6 1402 .l4proto = IPPROTO_TCP,
9fb9cbb1
YK
1403 .name = "tcp",
1404 .pkt_to_tuple = tcp_pkt_to_tuple,
1405 .invert_tuple = tcp_invert_tuple,
1406 .print_tuple = tcp_print_tuple,
1407 .print_conntrack = tcp_print_conntrack,
1408 .packet = tcp_packet,
1409 .new = tcp_new,
96f6bf82 1410 .error = tcp_error,
e281db5c 1411#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
fdf70832 1412 .to_nlattr = tcp_to_nlattr,
a400c30e 1413 .nlattr_size = tcp_nlattr_size,
fdf70832
PM
1414 .from_nlattr = nlattr_to_tcp,
1415 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1416 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
a400c30e 1417 .nlattr_tuple_size = tcp_nlattr_tuple_size,
f73e924c 1418 .nla_policy = nf_ct_port_nla_policy,
c1d10adb 1419#endif
933a41e7
PM
1420#ifdef CONFIG_SYSCTL
1421 .ctl_table_users = &tcp_sysctl_table_users,
1422 .ctl_table_header = &tcp_sysctl_header,
1423 .ctl_table = tcp_sysctl_table,
a999e683
PM
1424#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1425 .ctl_compat_table = tcp_compat_sysctl_table,
1426#endif
933a41e7 1427#endif
9fb9cbb1 1428};
13b18339 1429EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
9fb9cbb1 1430
61075af5 1431struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
9fb9cbb1
YK
1432{
1433 .l3proto = PF_INET6,
605dcad6 1434 .l4proto = IPPROTO_TCP,
9fb9cbb1
YK
1435 .name = "tcp",
1436 .pkt_to_tuple = tcp_pkt_to_tuple,
1437 .invert_tuple = tcp_invert_tuple,
1438 .print_tuple = tcp_print_tuple,
1439 .print_conntrack = tcp_print_conntrack,
1440 .packet = tcp_packet,
1441 .new = tcp_new,
96f6bf82 1442 .error = tcp_error,
e281db5c 1443#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
fdf70832 1444 .to_nlattr = tcp_to_nlattr,
a400c30e 1445 .nlattr_size = tcp_nlattr_size,
fdf70832
PM
1446 .from_nlattr = nlattr_to_tcp,
1447 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1448 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
a400c30e 1449 .nlattr_tuple_size = tcp_nlattr_tuple_size,
f73e924c 1450 .nla_policy = nf_ct_port_nla_policy,
c1d10adb 1451#endif
933a41e7
PM
1452#ifdef CONFIG_SYSCTL
1453 .ctl_table_users = &tcp_sysctl_table_users,
1454 .ctl_table_header = &tcp_sysctl_header,
1455 .ctl_table = tcp_sysctl_table,
1456#endif
9fb9cbb1 1457};
13b18339 1458EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);
This page took 0.550433 seconds and 5 git commands to generate.