1 /* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
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.
9 #include <linux/types.h>
10 #include <linux/timer.h>
11 #include <linux/module.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>
21 #include <linux/netfilter.h>
22 #include <linux/netfilter_ipv4.h>
23 #include <linux/netfilter_ipv6.h>
24 #include <net/netfilter/nf_conntrack.h>
25 #include <net/netfilter/nf_conntrack_l4proto.h>
26 #include <net/netfilter/nf_conntrack_ecache.h>
28 /* Protects conntrack->proto.tcp */
29 static DEFINE_RWLOCK(tcp_lock);
31 /* "Be conservative in what you do,
32 be liberal in what you accept from others."
33 If it's non-zero, we mark only out of window RST segments as INVALID. */
34 static int nf_ct_tcp_be_liberal __read_mostly = 0;
36 /* If it is set to zero, we disable picking up already established
38 static int nf_ct_tcp_loose __read_mostly = 1;
40 /* Max number of the retransmitted packets without receiving an (acceptable)
41 ACK from the destination. If this number is reached, a shorter timer
43 static int nf_ct_tcp_max_retrans __read_mostly = 3;
45 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
46 closely. They're more complex. --RR */
48 static const char *tcp_conntrack_names[] = {
62 #define MINS * 60 SECS
63 #define HOURS * 60 MINS
64 #define DAYS * 24 HOURS
66 static unsigned int nf_ct_tcp_timeout_syn_sent __read_mostly = 2 MINS;
67 static unsigned int nf_ct_tcp_timeout_syn_recv __read_mostly = 60 SECS;
68 static unsigned int nf_ct_tcp_timeout_established __read_mostly = 5 DAYS;
69 static unsigned int nf_ct_tcp_timeout_fin_wait __read_mostly = 2 MINS;
70 static unsigned int nf_ct_tcp_timeout_close_wait __read_mostly = 60 SECS;
71 static unsigned int nf_ct_tcp_timeout_last_ack __read_mostly = 30 SECS;
72 static unsigned int nf_ct_tcp_timeout_time_wait __read_mostly = 2 MINS;
73 static unsigned int nf_ct_tcp_timeout_close __read_mostly = 10 SECS;
75 /* RFC1122 says the R2 limit should be at least 100 seconds.
76 Linux uses 15 packets as limit, which corresponds
77 to ~13-30min depending on RTO. */
78 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
80 static unsigned int * tcp_timeouts[] = {
81 NULL, /* TCP_CONNTRACK_NONE */
82 &nf_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */
83 &nf_ct_tcp_timeout_syn_recv, /* TCP_CONNTRACK_SYN_RECV, */
84 &nf_ct_tcp_timeout_established, /* TCP_CONNTRACK_ESTABLISHED, */
85 &nf_ct_tcp_timeout_fin_wait, /* TCP_CONNTRACK_FIN_WAIT, */
86 &nf_ct_tcp_timeout_close_wait, /* TCP_CONNTRACK_CLOSE_WAIT, */
87 &nf_ct_tcp_timeout_last_ack, /* TCP_CONNTRACK_LAST_ACK, */
88 &nf_ct_tcp_timeout_time_wait, /* TCP_CONNTRACK_TIME_WAIT, */
89 &nf_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */
90 NULL, /* TCP_CONNTRACK_LISTEN */
93 #define sNO TCP_CONNTRACK_NONE
94 #define sSS TCP_CONNTRACK_SYN_SENT
95 #define sSR TCP_CONNTRACK_SYN_RECV
96 #define sES TCP_CONNTRACK_ESTABLISHED
97 #define sFW TCP_CONNTRACK_FIN_WAIT
98 #define sCW TCP_CONNTRACK_CLOSE_WAIT
99 #define sLA TCP_CONNTRACK_LAST_ACK
100 #define sTW TCP_CONNTRACK_TIME_WAIT
101 #define sCL TCP_CONNTRACK_CLOSE
102 #define sLI TCP_CONNTRACK_LISTEN
103 #define sIV TCP_CONNTRACK_MAX
104 #define sIG TCP_CONNTRACK_IGNORE
106 /* What TCP flags are set from RST/SYN/FIN/ACK. */
117 * The TCP state transition table needs a few words...
119 * We are the man in the middle. All the packets go through us
120 * but might get lost in transit to the destination.
121 * It is assumed that the destinations can't receive segments
124 * The checked segment is in window, but our windows are *not*
125 * equivalent with the ones of the sender/receiver. We always
126 * try to guess the state of the current sender.
128 * The meaning of the states are:
130 * NONE: initial state
131 * SYN_SENT: SYN-only packet seen
132 * SYN_RECV: SYN-ACK packet seen
133 * ESTABLISHED: ACK packet seen
134 * FIN_WAIT: FIN packet seen
135 * CLOSE_WAIT: ACK seen (after FIN)
136 * LAST_ACK: FIN seen (after FIN)
137 * TIME_WAIT: last ACK seen
138 * CLOSE: closed connection
140 * LISTEN state is not used.
142 * Packets marked as IGNORED (sIG):
143 * if they may be either invalid or valid
144 * and the receiver may send back a connection
145 * closing RST or a SYN/ACK.
147 * Packets marked as INVALID (sIV):
148 * if they are invalid
149 * or we do not support the request (simultaneous open)
151 static enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
154 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
155 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
157 * sNO -> sSS Initialize a new connection
158 * sSS -> sSS Retransmitted SYN
159 * sSR -> sIG Late retransmitted SYN?
160 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
161 * are errors. Receiver will reply with RST
162 * and close the connection.
163 * Or we are not in sync and hold a dead connection.
167 * sTW -> sSS Reopened connection (RFC 1122).
170 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
171 /*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
173 * A SYN/ACK from the client is always invalid:
174 * - either it tries to set up a simultaneous open, which is
176 * - or the firewall has just been inserted between the two hosts
177 * during the session set-up. The SYN will be retransmitted
178 * by the true client (or it'll time out).
180 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
181 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
183 * sNO -> sIV Too late and no reason to do anything...
184 * sSS -> sIV Client migth not send FIN in this state:
185 * we enforce waiting for a SYN/ACK reply first.
186 * sSR -> sFW Close started.
188 * sFW -> sLA FIN seen in both directions, waiting for
190 * Migth be a retransmitted FIN as well...
192 * sLA -> sLA Retransmitted FIN. Remain in the same state.
196 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
197 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
199 * sNO -> sES Assumed.
200 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
201 * sSR -> sES Established state is reached.
203 * sFW -> sCW Normal close request answered by ACK.
205 * sLA -> sTW Last ACK detected.
206 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
209 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
210 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
211 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
215 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
216 /*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
218 * sNO -> sIV Never reached.
219 * sSS -> sIV Simultaneous open, not supported
220 * sSR -> sIV Simultaneous open, not supported.
221 * sES -> sIV Server may not initiate a connection.
225 * sTW -> sIV Reopened connection, but server may not do it.
228 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
229 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
231 * sSS -> sSR Standard open.
232 * sSR -> sSR Retransmitted SYN/ACK.
233 * sES -> sIG Late retransmitted SYN/ACK?
234 * sFW -> sIG Might be SYN/ACK answering ignored SYN
240 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
241 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
243 * sSS -> sIV Server might not send FIN in this state.
244 * sSR -> sFW Close started.
246 * sFW -> sLA FIN seen in both directions.
248 * sLA -> sLA Retransmitted FIN.
252 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
253 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
255 * sSS -> sIG Might be a half-open connection.
256 * sSR -> sSR Might answer late resent SYN.
258 * sFW -> sCW Normal close request answered by ACK.
260 * sLA -> sTW Last ACK detected.
261 * sTW -> sTW Retransmitted last ACK.
264 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
265 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
266 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
270 static int tcp_pkt_to_tuple(const struct sk_buff *skb,
271 unsigned int dataoff,
272 struct nf_conntrack_tuple *tuple)
274 struct tcphdr _hdr, *hp;
276 /* Actually only need first 8 bytes. */
277 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
281 tuple->src.u.tcp.port = hp->source;
282 tuple->dst.u.tcp.port = hp->dest;
287 static int tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
288 const struct nf_conntrack_tuple *orig)
290 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
291 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
295 /* Print out the per-protocol part of the tuple. */
296 static int tcp_print_tuple(struct seq_file *s,
297 const struct nf_conntrack_tuple *tuple)
299 return seq_printf(s, "sport=%hu dport=%hu ",
300 ntohs(tuple->src.u.tcp.port),
301 ntohs(tuple->dst.u.tcp.port));
304 /* Print out the private part of the conntrack. */
305 static int tcp_print_conntrack(struct seq_file *s,
306 const struct nf_conn *conntrack)
308 enum tcp_conntrack state;
310 read_lock_bh(&tcp_lock);
311 state = conntrack->proto.tcp.state;
312 read_unlock_bh(&tcp_lock);
314 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
317 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
319 if (tcph->rst) return TCP_RST_SET;
320 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
321 else if (tcph->fin) return TCP_FIN_SET;
322 else if (tcph->ack) return TCP_ACK_SET;
323 else return TCP_NONE_SET;
326 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
327 in IP Filter' by Guido van Rooij.
329 http://www.nluug.nl/events/sane2000/papers.html
330 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
332 The boundaries and the conditions are changed according to RFC793:
333 the packet must intersect the window (i.e. segments may be
334 after the right or before the left edge) and thus receivers may ACK
335 segments after the right edge of the window.
337 td_maxend = max(sack + max(win,1)) seen in reply packets
338 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
339 td_maxwin += seq + len - sender.td_maxend
340 if seq + len > sender.td_maxend
341 td_end = max(seq + len) seen in sent packets
343 I. Upper bound for valid data: seq <= sender.td_maxend
344 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
345 III. Upper bound for valid ack: sack <= receiver.td_end
346 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
348 where sack is the highest right edge of sack block found in the packet.
350 The upper bound limit for a valid ack is not ignored -
351 we doesn't have to deal with fragments.
354 static inline __u32 segment_seq_plus_len(__u32 seq,
356 unsigned int dataoff,
359 /* XXX Should I use payload length field in IP/IPv6 header ?
361 return (seq + len - dataoff - tcph->doff*4
362 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
365 /* Fixme: what about big packets? */
366 #define MAXACKWINCONST 66000
367 #define MAXACKWINDOW(sender) \
368 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
372 * Simplified tcp_parse_options routine from tcp_input.c
374 static void tcp_options(const struct sk_buff *skb,
375 unsigned int dataoff,
377 struct ip_ct_tcp_state *state)
379 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
381 int length = (tcph->doff*4) - sizeof(struct tcphdr);
386 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
400 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
405 if (opsize < 2) /* "silly options" */
408 break; /* don't parse partial options */
410 if (opcode == TCPOPT_SACK_PERM
411 && opsize == TCPOLEN_SACK_PERM)
412 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
413 else if (opcode == TCPOPT_WINDOW
414 && opsize == TCPOLEN_WINDOW) {
415 state->td_scale = *(u_int8_t *)ptr;
417 if (state->td_scale > 14) {
419 state->td_scale = 14;
422 IP_CT_TCP_FLAG_WINDOW_SCALE;
430 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
431 struct tcphdr *tcph, __u32 *sack)
433 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
435 int length = (tcph->doff*4) - sizeof(struct tcphdr);
441 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
445 /* Fast path for timestamp-only option */
446 if (length == TCPOLEN_TSTAMP_ALIGNED*4
447 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
449 | (TCPOPT_TIMESTAMP << 8)
450 | TCPOLEN_TIMESTAMP))
460 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
465 if (opsize < 2) /* "silly options" */
468 break; /* don't parse partial options */
470 if (opcode == TCPOPT_SACK
471 && opsize >= (TCPOLEN_SACK_BASE
472 + TCPOLEN_SACK_PERBLOCK)
473 && !((opsize - TCPOLEN_SACK_BASE)
474 % TCPOLEN_SACK_PERBLOCK)) {
476 i < (opsize - TCPOLEN_SACK_BASE);
477 i += TCPOLEN_SACK_PERBLOCK) {
478 tmp = ntohl(*((__be32 *)(ptr+i)+1));
480 if (after(tmp, *sack))
491 static int tcp_in_window(struct nf_conn *ct,
492 struct ip_ct_tcp *state,
493 enum ip_conntrack_dir dir,
495 const struct sk_buff *skb,
496 unsigned int dataoff,
500 struct ip_ct_tcp_state *sender = &state->seen[dir];
501 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
502 struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
503 __u32 seq, ack, sack, end, win, swin;
507 * Get the required data from the packet.
509 seq = ntohl(tcph->seq);
510 ack = sack = ntohl(tcph->ack_seq);
511 win = ntohs(tcph->window);
512 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
514 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
515 tcp_sack(skb, dataoff, tcph, &sack);
517 pr_debug("tcp_in_window: START\n");
518 pr_debug("tcp_in_window: ");
519 NF_CT_DUMP_TUPLE(tuple);
520 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
521 seq, ack, sack, win, end);
522 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
523 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
524 sender->td_end, sender->td_maxend, sender->td_maxwin,
526 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
529 if (sender->td_end == 0) {
531 * Initialize sender data.
533 if (tcph->syn && tcph->ack) {
535 * Outgoing SYN-ACK in reply to a SYN.
538 sender->td_maxend = end;
539 sender->td_maxwin = (win == 0 ? 1 : win);
541 tcp_options(skb, dataoff, tcph, sender);
544 * Both sides must send the Window Scale option
545 * to enable window scaling in either direction.
547 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
548 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
550 receiver->td_scale = 0;
553 * We are in the middle of a connection,
554 * its history is lost for us.
555 * Let's try to use the data from the packet.
557 sender->td_end = end;
558 sender->td_maxwin = (win == 0 ? 1 : win);
559 sender->td_maxend = end + sender->td_maxwin;
561 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
562 && dir == IP_CT_DIR_ORIGINAL)
563 || (state->state == TCP_CONNTRACK_SYN_RECV
564 && dir == IP_CT_DIR_REPLY))
565 && after(end, sender->td_end)) {
567 * RFC 793: "if a TCP is reinitialized ... then it need
568 * not wait at all; it must only be sure to use sequence
569 * numbers larger than those recently used."
572 sender->td_maxend = end;
573 sender->td_maxwin = (win == 0 ? 1 : win);
575 tcp_options(skb, dataoff, tcph, sender);
580 * If there is no ACK, just pretend it was set and OK.
582 ack = sack = receiver->td_end;
583 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
584 (TCP_FLAG_ACK|TCP_FLAG_RST))
587 * Broken TCP stacks, that set ACK in RST packets as well
588 * with zero ack value.
590 ack = sack = receiver->td_end;
595 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
597 * Packets contains no data: we assume it is valid
598 * and check the ack value only.
599 * However RST segments are always validated by their
600 * SEQ number, except when seq == 0 (reset sent answering
603 seq = end = sender->td_end;
605 pr_debug("tcp_in_window: ");
606 NF_CT_DUMP_TUPLE(tuple);
607 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
608 seq, ack, sack, win, end);
609 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
610 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
611 sender->td_end, sender->td_maxend, sender->td_maxwin,
613 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
616 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
617 before(seq, sender->td_maxend + 1),
618 after(end, sender->td_end - receiver->td_maxwin - 1),
619 before(sack, receiver->td_end + 1),
620 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
622 if (before(seq, sender->td_maxend + 1) &&
623 after(end, sender->td_end - receiver->td_maxwin - 1) &&
624 before(sack, receiver->td_end + 1) &&
625 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
627 * Take into account window scaling (RFC 1323).
630 win <<= sender->td_scale;
633 * Update sender data.
635 swin = win + (sack - ack);
636 if (sender->td_maxwin < swin)
637 sender->td_maxwin = swin;
638 if (after(end, sender->td_end))
639 sender->td_end = end;
641 * Update receiver data.
643 if (after(end, sender->td_maxend))
644 receiver->td_maxwin += end - sender->td_maxend;
645 if (after(sack + win, receiver->td_maxend - 1)) {
646 receiver->td_maxend = sack + win;
648 receiver->td_maxend++;
652 * Check retransmissions.
654 if (index == TCP_ACK_SET) {
655 if (state->last_dir == dir
656 && state->last_seq == seq
657 && state->last_ack == ack
658 && state->last_end == end
659 && state->last_win == win)
662 state->last_dir = dir;
663 state->last_seq = seq;
664 state->last_ack = ack;
665 state->last_end = end;
666 state->last_win = win;
673 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
674 nf_ct_tcp_be_liberal)
676 if (!res && LOG_INVALID(IPPROTO_TCP))
677 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
679 before(seq, sender->td_maxend + 1) ?
680 after(end, sender->td_end - receiver->td_maxwin - 1) ?
681 before(sack, receiver->td_end + 1) ?
682 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
683 : "ACK is under the lower bound (possible overly delayed ACK)"
684 : "ACK is over the upper bound (ACKed data not seen yet)"
685 : "SEQ is under the lower bound (already ACKed data retransmitted)"
686 : "SEQ is over the upper bound (over the window of the receiver)");
689 pr_debug("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
690 "receiver end=%u maxend=%u maxwin=%u\n",
691 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
692 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
697 #ifdef CONFIG_NF_NAT_NEEDED
698 /* Update sender->td_end after NAT successfully mangled the packet */
699 /* Caller must linearize skb at tcp header. */
700 void nf_conntrack_tcp_update(struct sk_buff *skb,
701 unsigned int dataoff,
702 struct nf_conn *conntrack,
705 struct tcphdr *tcph = (void *)skb->data + dataoff;
706 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[dir];
707 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[!dir];
710 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
712 write_lock_bh(&tcp_lock);
714 * We have to worry for the ack in the reply packet only...
716 if (after(end, conntrack->proto.tcp.seen[dir].td_end))
717 conntrack->proto.tcp.seen[dir].td_end = end;
718 conntrack->proto.tcp.last_end = end;
719 write_unlock_bh(&tcp_lock);
720 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
721 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
722 sender->td_end, sender->td_maxend, sender->td_maxwin,
724 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
727 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
739 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
740 static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
748 [TH_FIN|TH_ACK|TH_URG] = 1,
753 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
754 static int tcp_error(struct sk_buff *skb,
755 unsigned int dataoff,
756 enum ip_conntrack_info *ctinfo,
758 unsigned int hooknum)
760 struct tcphdr _tcph, *th;
761 unsigned int tcplen = skb->len - dataoff;
764 /* Smaller that minimal TCP header? */
765 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
767 if (LOG_INVALID(IPPROTO_TCP))
768 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
769 "nf_ct_tcp: short packet ");
773 /* Not whole TCP header or malformed packet */
774 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
775 if (LOG_INVALID(IPPROTO_TCP))
776 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
777 "nf_ct_tcp: truncated/malformed packet ");
781 /* Checksum invalid? Ignore.
782 * We skip checking packets on the outgoing path
783 * because the checksum is assumed to be correct.
785 /* FIXME: Source route IP option packets --RR */
786 if (nf_conntrack_checksum &&
787 ((pf == PF_INET && hooknum == NF_IP_PRE_ROUTING) ||
788 (pf == PF_INET6 && hooknum == NF_IP6_PRE_ROUTING)) &&
789 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
790 if (LOG_INVALID(IPPROTO_TCP))
791 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
792 "nf_ct_tcp: bad TCP checksum ");
796 /* Check TCP flags. */
797 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
798 if (!tcp_valid_flags[tcpflags]) {
799 if (LOG_INVALID(IPPROTO_TCP))
800 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
801 "nf_ct_tcp: invalid TCP flag combination ");
808 /* Returns verdict for packet, or -1 for invalid. */
809 static int tcp_packet(struct nf_conn *conntrack,
810 const struct sk_buff *skb,
811 unsigned int dataoff,
812 enum ip_conntrack_info ctinfo,
814 unsigned int hooknum)
816 struct nf_conntrack_tuple *tuple;
817 enum tcp_conntrack new_state, old_state;
818 enum ip_conntrack_dir dir;
819 struct tcphdr *th, _tcph;
820 unsigned long timeout;
823 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
826 write_lock_bh(&tcp_lock);
827 old_state = conntrack->proto.tcp.state;
828 dir = CTINFO2DIR(ctinfo);
829 index = get_conntrack_index(th);
830 new_state = tcp_conntracks[dir][index][old_state];
831 tuple = &conntrack->tuplehash[dir].tuple;
834 case TCP_CONNTRACK_IGNORE:
838 * b) SYN/ACK in REPLY
839 * c) ACK in reply direction after initial SYN in original.
841 if (index == TCP_SYNACK_SET
842 && conntrack->proto.tcp.last_index == TCP_SYN_SET
843 && conntrack->proto.tcp.last_dir != dir
844 && ntohl(th->ack_seq) ==
845 conntrack->proto.tcp.last_end) {
846 /* This SYN/ACK acknowledges a SYN that we earlier
847 * ignored as invalid. This means that the client and
848 * the server are both in sync, while the firewall is
849 * not. We kill this session and block the SYN/ACK so
850 * that the client cannot but retransmit its SYN and
851 * thus initiate a clean new session.
853 write_unlock_bh(&tcp_lock);
854 if (LOG_INVALID(IPPROTO_TCP))
855 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
856 "nf_ct_tcp: killing out of sync session ");
857 if (del_timer(&conntrack->timeout))
858 conntrack->timeout.function((unsigned long)
862 conntrack->proto.tcp.last_index = index;
863 conntrack->proto.tcp.last_dir = dir;
864 conntrack->proto.tcp.last_seq = ntohl(th->seq);
865 conntrack->proto.tcp.last_end =
866 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
868 write_unlock_bh(&tcp_lock);
869 if (LOG_INVALID(IPPROTO_TCP))
870 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
871 "nf_ct_tcp: invalid packed ignored ");
873 case TCP_CONNTRACK_MAX:
875 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
876 dir, get_conntrack_index(th), old_state);
877 write_unlock_bh(&tcp_lock);
878 if (LOG_INVALID(IPPROTO_TCP))
879 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
880 "nf_ct_tcp: invalid state ");
882 case TCP_CONNTRACK_SYN_SENT:
883 if (old_state < TCP_CONNTRACK_TIME_WAIT)
885 if ((conntrack->proto.tcp.seen[dir].flags &
886 IP_CT_TCP_FLAG_CLOSE_INIT)
887 || after(ntohl(th->seq),
888 conntrack->proto.tcp.seen[dir].td_end)) {
889 /* Attempt to reopen a closed connection.
890 * Delete this connection and look up again. */
891 write_unlock_bh(&tcp_lock);
892 if (del_timer(&conntrack->timeout))
893 conntrack->timeout.function((unsigned long)
897 write_unlock_bh(&tcp_lock);
898 if (LOG_INVALID(IPPROTO_TCP))
899 nf_log_packet(pf, 0, skb, NULL, NULL,
900 NULL, "nf_ct_tcp: invalid SYN");
903 case TCP_CONNTRACK_CLOSE:
904 if (index == TCP_RST_SET
905 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)
906 && conntrack->proto.tcp.last_index == TCP_SYN_SET)
907 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
908 && conntrack->proto.tcp.last_index == TCP_ACK_SET))
909 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) {
910 /* RST sent to invalid SYN or ACK we had let through
911 * at a) and c) above:
913 * a) SYN was in window then
914 * c) we hold a half-open connection.
916 * Delete our connection entry.
917 * We skip window checking, because packet might ACK
918 * segments we ignored. */
921 /* Just fall through */
923 /* Keep compilers happy. */
927 if (!tcp_in_window(conntrack, &conntrack->proto.tcp, dir, index,
928 skb, dataoff, th, pf)) {
929 write_unlock_bh(&tcp_lock);
933 /* From now on we have got in-window packets */
934 conntrack->proto.tcp.last_index = index;
936 pr_debug("tcp_conntracks: ");
937 NF_CT_DUMP_TUPLE(tuple);
938 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
939 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
940 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
941 old_state, new_state);
943 conntrack->proto.tcp.state = new_state;
944 if (old_state != new_state
945 && (new_state == TCP_CONNTRACK_FIN_WAIT
946 || new_state == TCP_CONNTRACK_CLOSE))
947 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
948 timeout = conntrack->proto.tcp.retrans >= nf_ct_tcp_max_retrans
949 && *tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans
950 ? nf_ct_tcp_timeout_max_retrans : *tcp_timeouts[new_state];
951 write_unlock_bh(&tcp_lock);
953 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
954 if (new_state != old_state)
955 nf_conntrack_event_cache(IPCT_PROTOINFO, skb);
957 if (!test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
958 /* If only reply is a RST, we can consider ourselves not to
959 have an established connection: this is a fairly common
960 problem case, so we can delete the conntrack
963 if (del_timer(&conntrack->timeout))
964 conntrack->timeout.function((unsigned long)
968 } else if (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
969 && (old_state == TCP_CONNTRACK_SYN_RECV
970 || old_state == TCP_CONNTRACK_ESTABLISHED)
971 && new_state == TCP_CONNTRACK_ESTABLISHED) {
972 /* Set ASSURED if we see see valid ack in ESTABLISHED
973 after SYN_RECV or a valid answer for a picked up
975 set_bit(IPS_ASSURED_BIT, &conntrack->status);
976 nf_conntrack_event_cache(IPCT_STATUS, skb);
978 nf_ct_refresh_acct(conntrack, ctinfo, skb, timeout);
983 /* Called when a new connection for this protocol found. */
984 static int tcp_new(struct nf_conn *conntrack,
985 const struct sk_buff *skb,
986 unsigned int dataoff)
988 enum tcp_conntrack new_state;
989 struct tcphdr *th, _tcph;
990 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[0];
991 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[1];
993 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
996 /* Don't need lock here: this conntrack not in circulation yet */
998 = tcp_conntracks[0][get_conntrack_index(th)]
999 [TCP_CONNTRACK_NONE];
1001 /* Invalid: delete conntrack */
1002 if (new_state >= TCP_CONNTRACK_MAX) {
1003 pr_debug("nf_ct_tcp: invalid new deleting.\n");
1007 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1009 conntrack->proto.tcp.seen[0].td_end =
1010 segment_seq_plus_len(ntohl(th->seq), skb->len,
1012 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1013 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1014 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1015 conntrack->proto.tcp.seen[0].td_maxend =
1016 conntrack->proto.tcp.seen[0].td_end;
1018 tcp_options(skb, dataoff, th, &conntrack->proto.tcp.seen[0]);
1019 conntrack->proto.tcp.seen[1].flags = 0;
1020 } else if (nf_ct_tcp_loose == 0) {
1021 /* Don't try to pick up connections. */
1025 * We are in the middle of a connection,
1026 * its history is lost for us.
1027 * Let's try to use the data from the packet.
1029 conntrack->proto.tcp.seen[0].td_end =
1030 segment_seq_plus_len(ntohl(th->seq), skb->len,
1032 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1033 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1034 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1035 conntrack->proto.tcp.seen[0].td_maxend =
1036 conntrack->proto.tcp.seen[0].td_end +
1037 conntrack->proto.tcp.seen[0].td_maxwin;
1038 conntrack->proto.tcp.seen[0].td_scale = 0;
1040 /* We assume SACK and liberal window checking to handle
1042 conntrack->proto.tcp.seen[0].flags =
1043 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1044 IP_CT_TCP_FLAG_BE_LIBERAL;
1047 conntrack->proto.tcp.seen[1].td_end = 0;
1048 conntrack->proto.tcp.seen[1].td_maxend = 0;
1049 conntrack->proto.tcp.seen[1].td_maxwin = 1;
1050 conntrack->proto.tcp.seen[1].td_scale = 0;
1052 /* tcp_packet will set them */
1053 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE;
1054 conntrack->proto.tcp.last_index = TCP_NONE_SET;
1056 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1057 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1058 sender->td_end, sender->td_maxend, sender->td_maxwin,
1060 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1061 receiver->td_scale);
1065 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1067 #include <linux/netfilter/nfnetlink.h>
1068 #include <linux/netfilter/nfnetlink_conntrack.h>
1070 static int tcp_to_nfattr(struct sk_buff *skb, struct nfattr *nfa,
1071 const struct nf_conn *ct)
1073 struct nfattr *nest_parms;
1074 struct nf_ct_tcp_flags tmp = {};
1076 read_lock_bh(&tcp_lock);
1077 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP);
1078 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t),
1079 &ct->proto.tcp.state);
1081 NFA_PUT(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL, sizeof(u_int8_t),
1082 &ct->proto.tcp.seen[0].td_scale);
1084 NFA_PUT(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY, sizeof(u_int8_t),
1085 &ct->proto.tcp.seen[1].td_scale);
1087 tmp.flags = ct->proto.tcp.seen[0].flags;
1088 NFA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1089 sizeof(struct nf_ct_tcp_flags), &tmp);
1091 tmp.flags = ct->proto.tcp.seen[1].flags;
1092 NFA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1093 sizeof(struct nf_ct_tcp_flags), &tmp);
1094 read_unlock_bh(&tcp_lock);
1096 NFA_NEST_END(skb, nest_parms);
1101 read_unlock_bh(&tcp_lock);
1105 static const size_t cta_min_tcp[CTA_PROTOINFO_TCP_MAX] = {
1106 [CTA_PROTOINFO_TCP_STATE-1] = sizeof(u_int8_t),
1107 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1] = sizeof(u_int8_t),
1108 [CTA_PROTOINFO_TCP_WSCALE_REPLY-1] = sizeof(u_int8_t),
1109 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1] = sizeof(struct nf_ct_tcp_flags),
1110 [CTA_PROTOINFO_TCP_FLAGS_REPLY-1] = sizeof(struct nf_ct_tcp_flags)
1113 static int nfattr_to_tcp(struct nfattr *cda[], struct nf_conn *ct)
1115 struct nfattr *attr = cda[CTA_PROTOINFO_TCP-1];
1116 struct nfattr *tb[CTA_PROTOINFO_TCP_MAX];
1118 /* updates could not contain anything about the private
1119 * protocol info, in that case skip the parsing */
1123 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr);
1125 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp))
1128 if (!tb[CTA_PROTOINFO_TCP_STATE-1])
1131 write_lock_bh(&tcp_lock);
1132 ct->proto.tcp.state =
1133 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]);
1135 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1]) {
1136 struct nf_ct_tcp_flags *attr =
1137 NFA_DATA(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1]);
1138 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1139 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1142 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY-1]) {
1143 struct nf_ct_tcp_flags *attr =
1144 NFA_DATA(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY-1]);
1145 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1146 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1149 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1] &&
1150 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY-1] &&
1151 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1152 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1153 ct->proto.tcp.seen[0].td_scale = *(u_int8_t *)
1154 NFA_DATA(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1]);
1155 ct->proto.tcp.seen[1].td_scale = *(u_int8_t *)
1156 NFA_DATA(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY-1]);
1158 write_unlock_bh(&tcp_lock);
1164 #ifdef CONFIG_SYSCTL
1165 static unsigned int tcp_sysctl_table_users;
1166 static struct ctl_table_header *tcp_sysctl_header;
1167 static struct ctl_table tcp_sysctl_table[] = {
1169 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
1170 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1171 .data = &nf_ct_tcp_timeout_syn_sent,
1172 .maxlen = sizeof(unsigned int),
1174 .proc_handler = &proc_dointvec_jiffies,
1177 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
1178 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1179 .data = &nf_ct_tcp_timeout_syn_recv,
1180 .maxlen = sizeof(unsigned int),
1182 .proc_handler = &proc_dointvec_jiffies,
1185 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
1186 .procname = "nf_conntrack_tcp_timeout_established",
1187 .data = &nf_ct_tcp_timeout_established,
1188 .maxlen = sizeof(unsigned int),
1190 .proc_handler = &proc_dointvec_jiffies,
1193 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
1194 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1195 .data = &nf_ct_tcp_timeout_fin_wait,
1196 .maxlen = sizeof(unsigned int),
1198 .proc_handler = &proc_dointvec_jiffies,
1201 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
1202 .procname = "nf_conntrack_tcp_timeout_close_wait",
1203 .data = &nf_ct_tcp_timeout_close_wait,
1204 .maxlen = sizeof(unsigned int),
1206 .proc_handler = &proc_dointvec_jiffies,
1209 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
1210 .procname = "nf_conntrack_tcp_timeout_last_ack",
1211 .data = &nf_ct_tcp_timeout_last_ack,
1212 .maxlen = sizeof(unsigned int),
1214 .proc_handler = &proc_dointvec_jiffies,
1217 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
1218 .procname = "nf_conntrack_tcp_timeout_time_wait",
1219 .data = &nf_ct_tcp_timeout_time_wait,
1220 .maxlen = sizeof(unsigned int),
1222 .proc_handler = &proc_dointvec_jiffies,
1225 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
1226 .procname = "nf_conntrack_tcp_timeout_close",
1227 .data = &nf_ct_tcp_timeout_close,
1228 .maxlen = sizeof(unsigned int),
1230 .proc_handler = &proc_dointvec_jiffies,
1233 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
1234 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1235 .data = &nf_ct_tcp_timeout_max_retrans,
1236 .maxlen = sizeof(unsigned int),
1238 .proc_handler = &proc_dointvec_jiffies,
1241 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1242 .procname = "nf_conntrack_tcp_loose",
1243 .data = &nf_ct_tcp_loose,
1244 .maxlen = sizeof(unsigned int),
1246 .proc_handler = &proc_dointvec,
1249 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1250 .procname = "nf_conntrack_tcp_be_liberal",
1251 .data = &nf_ct_tcp_be_liberal,
1252 .maxlen = sizeof(unsigned int),
1254 .proc_handler = &proc_dointvec,
1257 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1258 .procname = "nf_conntrack_tcp_max_retrans",
1259 .data = &nf_ct_tcp_max_retrans,
1260 .maxlen = sizeof(unsigned int),
1262 .proc_handler = &proc_dointvec,
1269 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1270 static struct ctl_table tcp_compat_sysctl_table[] = {
1272 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
1273 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1274 .data = &nf_ct_tcp_timeout_syn_sent,
1275 .maxlen = sizeof(unsigned int),
1277 .proc_handler = &proc_dointvec_jiffies,
1280 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
1281 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1282 .data = &nf_ct_tcp_timeout_syn_recv,
1283 .maxlen = sizeof(unsigned int),
1285 .proc_handler = &proc_dointvec_jiffies,
1288 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
1289 .procname = "ip_conntrack_tcp_timeout_established",
1290 .data = &nf_ct_tcp_timeout_established,
1291 .maxlen = sizeof(unsigned int),
1293 .proc_handler = &proc_dointvec_jiffies,
1296 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
1297 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1298 .data = &nf_ct_tcp_timeout_fin_wait,
1299 .maxlen = sizeof(unsigned int),
1301 .proc_handler = &proc_dointvec_jiffies,
1304 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
1305 .procname = "ip_conntrack_tcp_timeout_close_wait",
1306 .data = &nf_ct_tcp_timeout_close_wait,
1307 .maxlen = sizeof(unsigned int),
1309 .proc_handler = &proc_dointvec_jiffies,
1312 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
1313 .procname = "ip_conntrack_tcp_timeout_last_ack",
1314 .data = &nf_ct_tcp_timeout_last_ack,
1315 .maxlen = sizeof(unsigned int),
1317 .proc_handler = &proc_dointvec_jiffies,
1320 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
1321 .procname = "ip_conntrack_tcp_timeout_time_wait",
1322 .data = &nf_ct_tcp_timeout_time_wait,
1323 .maxlen = sizeof(unsigned int),
1325 .proc_handler = &proc_dointvec_jiffies,
1328 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
1329 .procname = "ip_conntrack_tcp_timeout_close",
1330 .data = &nf_ct_tcp_timeout_close,
1331 .maxlen = sizeof(unsigned int),
1333 .proc_handler = &proc_dointvec_jiffies,
1336 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
1337 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1338 .data = &nf_ct_tcp_timeout_max_retrans,
1339 .maxlen = sizeof(unsigned int),
1341 .proc_handler = &proc_dointvec_jiffies,
1344 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1345 .procname = "ip_conntrack_tcp_loose",
1346 .data = &nf_ct_tcp_loose,
1347 .maxlen = sizeof(unsigned int),
1349 .proc_handler = &proc_dointvec,
1352 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1353 .procname = "ip_conntrack_tcp_be_liberal",
1354 .data = &nf_ct_tcp_be_liberal,
1355 .maxlen = sizeof(unsigned int),
1357 .proc_handler = &proc_dointvec,
1360 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1361 .procname = "ip_conntrack_tcp_max_retrans",
1362 .data = &nf_ct_tcp_max_retrans,
1363 .maxlen = sizeof(unsigned int),
1365 .proc_handler = &proc_dointvec,
1371 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1372 #endif /* CONFIG_SYSCTL */
1374 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
1377 .l4proto = IPPROTO_TCP,
1379 .pkt_to_tuple = tcp_pkt_to_tuple,
1380 .invert_tuple = tcp_invert_tuple,
1381 .print_tuple = tcp_print_tuple,
1382 .print_conntrack = tcp_print_conntrack,
1383 .packet = tcp_packet,
1386 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1387 .to_nfattr = tcp_to_nfattr,
1388 .from_nfattr = nfattr_to_tcp,
1389 .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr,
1390 .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple,
1392 #ifdef CONFIG_SYSCTL
1393 .ctl_table_users = &tcp_sysctl_table_users,
1394 .ctl_table_header = &tcp_sysctl_header,
1395 .ctl_table = tcp_sysctl_table,
1396 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1397 .ctl_compat_table = tcp_compat_sysctl_table,
1401 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1403 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
1405 .l3proto = PF_INET6,
1406 .l4proto = IPPROTO_TCP,
1408 .pkt_to_tuple = tcp_pkt_to_tuple,
1409 .invert_tuple = tcp_invert_tuple,
1410 .print_tuple = tcp_print_tuple,
1411 .print_conntrack = tcp_print_conntrack,
1412 .packet = tcp_packet,
1415 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1416 .to_nfattr = tcp_to_nfattr,
1417 .from_nfattr = nfattr_to_tcp,
1418 .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr,
1419 .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple,
1421 #ifdef CONFIG_SYSCTL
1422 .ctl_table_users = &tcp_sysctl_table_users,
1423 .ctl_table_header = &tcp_sysctl_header,
1424 .ctl_table = tcp_sysctl_table,
1427 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);