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>
18 #include <asm/unaligned.h>
22 #include <linux/netfilter.h>
23 #include <linux/netfilter_ipv4.h>
24 #include <linux/netfilter_ipv6.h>
25 #include <net/netfilter/nf_conntrack.h>
26 #include <net/netfilter/nf_conntrack_l4proto.h>
27 #include <net/netfilter/nf_conntrack_ecache.h>
28 #include <net/netfilter/nf_log.h>
30 /* Protects ct->proto.tcp */
31 static DEFINE_RWLOCK(tcp_lock);
33 /* "Be conservative in what you do,
34 be liberal in what you accept from others."
35 If it's non-zero, we mark only out of window RST segments as INVALID. */
36 static int nf_ct_tcp_be_liberal __read_mostly = 0;
38 /* If it is set to zero, we disable picking up already established
40 static int nf_ct_tcp_loose __read_mostly = 1;
42 /* Max number of the retransmitted packets without receiving an (acceptable)
43 ACK from the destination. If this number is reached, a shorter timer
45 static int nf_ct_tcp_max_retrans __read_mostly = 3;
47 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
48 closely. They're more complex. --RR */
50 static const char *const tcp_conntrack_names[] = {
64 #define MINS * 60 SECS
65 #define HOURS * 60 MINS
66 #define DAYS * 24 HOURS
68 /* RFC1122 says the R2 limit should be at least 100 seconds.
69 Linux uses 15 packets as limit, which corresponds
70 to ~13-30min depending on RTO. */
71 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
72 static unsigned int nf_ct_tcp_timeout_unacknowledged __read_mostly = 5 MINS;
74 static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
75 [TCP_CONNTRACK_SYN_SENT] = 2 MINS,
76 [TCP_CONNTRACK_SYN_RECV] = 60 SECS,
77 [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS,
78 [TCP_CONNTRACK_FIN_WAIT] = 2 MINS,
79 [TCP_CONNTRACK_CLOSE_WAIT] = 60 SECS,
80 [TCP_CONNTRACK_LAST_ACK] = 30 SECS,
81 [TCP_CONNTRACK_TIME_WAIT] = 2 MINS,
82 [TCP_CONNTRACK_CLOSE] = 10 SECS,
85 #define sNO TCP_CONNTRACK_NONE
86 #define sSS TCP_CONNTRACK_SYN_SENT
87 #define sSR TCP_CONNTRACK_SYN_RECV
88 #define sES TCP_CONNTRACK_ESTABLISHED
89 #define sFW TCP_CONNTRACK_FIN_WAIT
90 #define sCW TCP_CONNTRACK_CLOSE_WAIT
91 #define sLA TCP_CONNTRACK_LAST_ACK
92 #define sTW TCP_CONNTRACK_TIME_WAIT
93 #define sCL TCP_CONNTRACK_CLOSE
94 #define sLI TCP_CONNTRACK_LISTEN
95 #define sIV TCP_CONNTRACK_MAX
96 #define sIG TCP_CONNTRACK_IGNORE
98 /* What TCP flags are set from RST/SYN/FIN/ACK. */
109 * The TCP state transition table needs a few words...
111 * We are the man in the middle. All the packets go through us
112 * but might get lost in transit to the destination.
113 * It is assumed that the destinations can't receive segments
116 * The checked segment is in window, but our windows are *not*
117 * equivalent with the ones of the sender/receiver. We always
118 * try to guess the state of the current sender.
120 * The meaning of the states are:
122 * NONE: initial state
123 * SYN_SENT: SYN-only packet seen
124 * SYN_RECV: SYN-ACK packet seen
125 * ESTABLISHED: ACK packet seen
126 * FIN_WAIT: FIN packet seen
127 * CLOSE_WAIT: ACK seen (after FIN)
128 * LAST_ACK: FIN seen (after FIN)
129 * TIME_WAIT: last ACK seen
130 * CLOSE: closed connection (RST)
132 * LISTEN state is not used.
134 * Packets marked as IGNORED (sIG):
135 * if they may be either invalid or valid
136 * and the receiver may send back a connection
137 * closing RST or a SYN/ACK.
139 * Packets marked as INVALID (sIV):
140 * if they are invalid
141 * or we do not support the request (simultaneous open)
143 static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
146 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
147 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
149 * sNO -> sSS Initialize a new connection
150 * sSS -> sSS Retransmitted SYN
151 * sSR -> sIG Late retransmitted SYN?
152 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
153 * are errors. Receiver will reply with RST
154 * and close the connection.
155 * Or we are not in sync and hold a dead connection.
159 * sTW -> sSS Reopened connection (RFC 1122).
162 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
163 /*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
165 * A SYN/ACK from the client is always invalid:
166 * - either it tries to set up a simultaneous open, which is
168 * - or the firewall has just been inserted between the two hosts
169 * during the session set-up. The SYN will be retransmitted
170 * by the true client (or it'll time out).
172 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
173 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
175 * sNO -> sIV Too late and no reason to do anything...
176 * sSS -> sIV Client migth not send FIN in this state:
177 * we enforce waiting for a SYN/ACK reply first.
178 * sSR -> sFW Close started.
180 * sFW -> sLA FIN seen in both directions, waiting for
182 * Migth be a retransmitted FIN as well...
184 * sLA -> sLA Retransmitted FIN. Remain in the same state.
188 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
189 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
191 * sNO -> sES Assumed.
192 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
193 * sSR -> sES Established state is reached.
195 * sFW -> sCW Normal close request answered by ACK.
197 * sLA -> sTW Last ACK detected.
198 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
201 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
202 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
203 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
207 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
208 /*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
210 * sNO -> sIV Never reached.
211 * sSS -> sIV Simultaneous open, not supported
212 * sSR -> sIV Simultaneous open, not supported.
213 * sES -> sIV Server may not initiate a connection.
217 * sTW -> sIV Reopened connection, but server may not do it.
220 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
221 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
223 * sSS -> sSR Standard open.
224 * sSR -> sSR Retransmitted SYN/ACK.
225 * sES -> sIG Late retransmitted SYN/ACK?
226 * sFW -> sIG Might be SYN/ACK answering ignored SYN
232 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
233 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
235 * sSS -> sIV Server might not send FIN in this state.
236 * sSR -> sFW Close started.
238 * sFW -> sLA FIN seen in both directions.
240 * sLA -> sLA Retransmitted FIN.
244 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
245 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
247 * sSS -> sIG Might be a half-open connection.
248 * sSR -> sSR Might answer late resent SYN.
250 * sFW -> sCW Normal close request answered by ACK.
252 * sLA -> sTW Last ACK detected.
253 * sTW -> sTW Retransmitted last ACK.
256 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
257 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
258 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
262 static bool tcp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
263 struct nf_conntrack_tuple *tuple)
265 const struct tcphdr *hp;
268 /* Actually only need first 8 bytes. */
269 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
273 tuple->src.u.tcp.port = hp->source;
274 tuple->dst.u.tcp.port = hp->dest;
279 static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
280 const struct nf_conntrack_tuple *orig)
282 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
283 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
287 /* Print out the per-protocol part of the tuple. */
288 static int tcp_print_tuple(struct seq_file *s,
289 const struct nf_conntrack_tuple *tuple)
291 return seq_printf(s, "sport=%hu dport=%hu ",
292 ntohs(tuple->src.u.tcp.port),
293 ntohs(tuple->dst.u.tcp.port));
296 /* Print out the private part of the conntrack. */
297 static int tcp_print_conntrack(struct seq_file *s, const struct nf_conn *ct)
299 enum tcp_conntrack state;
301 read_lock_bh(&tcp_lock);
302 state = ct->proto.tcp.state;
303 read_unlock_bh(&tcp_lock);
305 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
308 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
310 if (tcph->rst) return TCP_RST_SET;
311 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
312 else if (tcph->fin) return TCP_FIN_SET;
313 else if (tcph->ack) return TCP_ACK_SET;
314 else return TCP_NONE_SET;
317 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
318 in IP Filter' by Guido van Rooij.
320 http://www.nluug.nl/events/sane2000/papers.html
321 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
323 The boundaries and the conditions are changed according to RFC793:
324 the packet must intersect the window (i.e. segments may be
325 after the right or before the left edge) and thus receivers may ACK
326 segments after the right edge of the window.
328 td_maxend = max(sack + max(win,1)) seen in reply packets
329 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
330 td_maxwin += seq + len - sender.td_maxend
331 if seq + len > sender.td_maxend
332 td_end = max(seq + len) seen in sent packets
334 I. Upper bound for valid data: seq <= sender.td_maxend
335 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
336 III. Upper bound for valid (s)ack: sack <= receiver.td_end
337 IV. Lower bound for valid (s)ack: sack >= receiver.td_end - MAXACKWINDOW
339 where sack is the highest right edge of sack block found in the packet
340 or ack in the case of packet without SACK option.
342 The upper bound limit for a valid (s)ack is not ignored -
343 we doesn't have to deal with fragments.
346 static inline __u32 segment_seq_plus_len(__u32 seq,
348 unsigned int dataoff,
349 const struct tcphdr *tcph)
351 /* XXX Should I use payload length field in IP/IPv6 header ?
353 return (seq + len - dataoff - tcph->doff*4
354 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
357 /* Fixme: what about big packets? */
358 #define MAXACKWINCONST 66000
359 #define MAXACKWINDOW(sender) \
360 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
364 * Simplified tcp_parse_options routine from tcp_input.c
366 static void tcp_options(const struct sk_buff *skb,
367 unsigned int dataoff,
368 const struct tcphdr *tcph,
369 struct ip_ct_tcp_state *state)
371 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
372 const unsigned char *ptr;
373 int length = (tcph->doff*4) - sizeof(struct tcphdr);
378 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
392 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
397 if (opsize < 2) /* "silly options" */
400 break; /* don't parse partial options */
402 if (opcode == TCPOPT_SACK_PERM
403 && opsize == TCPOLEN_SACK_PERM)
404 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
405 else if (opcode == TCPOPT_WINDOW
406 && opsize == TCPOLEN_WINDOW) {
407 state->td_scale = *(u_int8_t *)ptr;
409 if (state->td_scale > 14) {
411 state->td_scale = 14;
414 IP_CT_TCP_FLAG_WINDOW_SCALE;
422 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
423 const struct tcphdr *tcph, __u32 *sack)
425 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
426 const unsigned char *ptr;
427 int length = (tcph->doff*4) - sizeof(struct tcphdr);
433 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
437 /* Fast path for timestamp-only option */
438 if (length == TCPOLEN_TSTAMP_ALIGNED*4
439 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
441 | (TCPOPT_TIMESTAMP << 8)
442 | TCPOLEN_TIMESTAMP))
452 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
457 if (opsize < 2) /* "silly options" */
460 break; /* don't parse partial options */
462 if (opcode == TCPOPT_SACK
463 && opsize >= (TCPOLEN_SACK_BASE
464 + TCPOLEN_SACK_PERBLOCK)
465 && !((opsize - TCPOLEN_SACK_BASE)
466 % TCPOLEN_SACK_PERBLOCK)) {
468 i < (opsize - TCPOLEN_SACK_BASE);
469 i += TCPOLEN_SACK_PERBLOCK) {
470 tmp = get_unaligned_be32((__be32 *)(ptr+i)+1);
472 if (after(tmp, *sack))
483 static bool tcp_in_window(const struct nf_conn *ct,
484 struct ip_ct_tcp *state,
485 enum ip_conntrack_dir dir,
487 const struct sk_buff *skb,
488 unsigned int dataoff,
489 const struct tcphdr *tcph,
492 struct ip_ct_tcp_state *sender = &state->seen[dir];
493 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
494 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
495 __u32 seq, ack, sack, end, win, swin;
499 * Get the required data from the packet.
501 seq = ntohl(tcph->seq);
502 ack = sack = ntohl(tcph->ack_seq);
503 win = ntohs(tcph->window);
504 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
506 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
507 tcp_sack(skb, dataoff, tcph, &sack);
509 pr_debug("tcp_in_window: START\n");
510 pr_debug("tcp_in_window: ");
511 nf_ct_dump_tuple(tuple);
512 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
513 seq, ack, sack, win, end);
514 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
515 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
516 sender->td_end, sender->td_maxend, sender->td_maxwin,
518 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
521 if (sender->td_end == 0) {
523 * Initialize sender data.
525 if (tcph->syn && tcph->ack) {
527 * Outgoing SYN-ACK in reply to a SYN.
530 sender->td_maxend = end;
531 sender->td_maxwin = (win == 0 ? 1 : win);
533 tcp_options(skb, dataoff, tcph, sender);
536 * Both sides must send the Window Scale option
537 * to enable window scaling in either direction.
539 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
540 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
542 receiver->td_scale = 0;
545 * We are in the middle of a connection,
546 * its history is lost for us.
547 * Let's try to use the data from the packet.
549 sender->td_end = end;
550 sender->td_maxwin = (win == 0 ? 1 : win);
551 sender->td_maxend = end + sender->td_maxwin;
553 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
554 && dir == IP_CT_DIR_ORIGINAL)
555 || (state->state == TCP_CONNTRACK_SYN_RECV
556 && dir == IP_CT_DIR_REPLY))
557 && after(end, sender->td_end)) {
559 * RFC 793: "if a TCP is reinitialized ... then it need
560 * not wait at all; it must only be sure to use sequence
561 * numbers larger than those recently used."
564 sender->td_maxend = end;
565 sender->td_maxwin = (win == 0 ? 1 : win);
567 tcp_options(skb, dataoff, tcph, sender);
572 * If there is no ACK, just pretend it was set and OK.
574 ack = sack = receiver->td_end;
575 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
576 (TCP_FLAG_ACK|TCP_FLAG_RST))
579 * Broken TCP stacks, that set ACK in RST packets as well
580 * with zero ack value.
582 ack = sack = receiver->td_end;
587 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
589 * Packets contains no data: we assume it is valid
590 * and check the ack value only.
591 * However RST segments are always validated by their
592 * SEQ number, except when seq == 0 (reset sent answering
595 seq = end = sender->td_end;
597 pr_debug("tcp_in_window: ");
598 nf_ct_dump_tuple(tuple);
599 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
600 seq, ack, sack, win, end);
601 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
602 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
603 sender->td_end, sender->td_maxend, sender->td_maxwin,
605 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
608 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
609 before(seq, sender->td_maxend + 1),
610 after(end, sender->td_end - receiver->td_maxwin - 1),
611 before(sack, receiver->td_end + 1),
612 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
614 if (before(seq, sender->td_maxend + 1) &&
615 after(end, sender->td_end - receiver->td_maxwin - 1) &&
616 before(sack, receiver->td_end + 1) &&
617 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
619 * Take into account window scaling (RFC 1323).
622 win <<= sender->td_scale;
625 * Update sender data.
627 swin = win + (sack - ack);
628 if (sender->td_maxwin < swin)
629 sender->td_maxwin = swin;
630 if (after(end, sender->td_end)) {
631 sender->td_end = end;
632 sender->flags |= IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
635 * Update receiver data.
637 if (after(end, sender->td_maxend))
638 receiver->td_maxwin += end - sender->td_maxend;
639 if (after(sack + win, receiver->td_maxend - 1)) {
640 receiver->td_maxend = sack + win;
642 receiver->td_maxend++;
644 if (ack == receiver->td_end)
645 receiver->flags &= ~IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
648 * Check retransmissions.
650 if (index == TCP_ACK_SET) {
651 if (state->last_dir == dir
652 && state->last_seq == seq
653 && state->last_ack == ack
654 && state->last_end == end
655 && state->last_win == win)
658 state->last_dir = dir;
659 state->last_seq = seq;
660 state->last_ack = ack;
661 state->last_end = end;
662 state->last_win = win;
669 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
670 nf_ct_tcp_be_liberal)
672 if (!res && LOG_INVALID(IPPROTO_TCP))
673 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
675 before(seq, sender->td_maxend + 1) ?
676 after(end, sender->td_end - receiver->td_maxwin - 1) ?
677 before(sack, receiver->td_end + 1) ?
678 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
679 : "ACK is under the lower bound (possible overly delayed ACK)"
680 : "ACK is over the upper bound (ACKed data not seen yet)"
681 : "SEQ is under the lower bound (already ACKed data retransmitted)"
682 : "SEQ is over the upper bound (over the window of the receiver)");
685 pr_debug("tcp_in_window: res=%u sender end=%u maxend=%u maxwin=%u "
686 "receiver end=%u maxend=%u maxwin=%u\n",
687 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
688 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
693 #ifdef CONFIG_NF_NAT_NEEDED
694 /* Update sender->td_end after NAT successfully mangled the packet */
695 /* Caller must linearize skb at tcp header. */
696 void nf_conntrack_tcp_update(const struct sk_buff *skb,
697 unsigned int dataoff,
701 const struct tcphdr *tcph = (const void *)skb->data + dataoff;
702 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[dir];
703 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[!dir];
706 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
708 write_lock_bh(&tcp_lock);
710 * We have to worry for the ack in the reply packet only...
712 if (after(end, ct->proto.tcp.seen[dir].td_end))
713 ct->proto.tcp.seen[dir].td_end = end;
714 ct->proto.tcp.last_end = end;
715 write_unlock_bh(&tcp_lock);
716 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
717 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
718 sender->td_end, sender->td_maxend, sender->td_maxwin,
720 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
723 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
735 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
736 static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
744 [TH_FIN|TH_ACK|TH_URG] = 1,
749 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
750 static int tcp_error(struct sk_buff *skb,
751 unsigned int dataoff,
752 enum ip_conntrack_info *ctinfo,
754 unsigned int hooknum)
756 const struct tcphdr *th;
758 unsigned int tcplen = skb->len - dataoff;
761 /* Smaller that minimal TCP header? */
762 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
764 if (LOG_INVALID(IPPROTO_TCP))
765 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
766 "nf_ct_tcp: short packet ");
770 /* Not whole TCP header or malformed packet */
771 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
772 if (LOG_INVALID(IPPROTO_TCP))
773 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
774 "nf_ct_tcp: truncated/malformed packet ");
778 /* Checksum invalid? Ignore.
779 * We skip checking packets on the outgoing path
780 * because the checksum is assumed to be correct.
782 /* FIXME: Source route IP option packets --RR */
783 if (nf_conntrack_checksum && hooknum == NF_INET_PRE_ROUTING &&
784 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
785 if (LOG_INVALID(IPPROTO_TCP))
786 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
787 "nf_ct_tcp: bad TCP checksum ");
791 /* Check TCP flags. */
792 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
793 if (!tcp_valid_flags[tcpflags]) {
794 if (LOG_INVALID(IPPROTO_TCP))
795 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
796 "nf_ct_tcp: invalid TCP flag combination ");
803 /* Returns verdict for packet, or -1 for invalid. */
804 static int tcp_packet(struct nf_conn *ct,
805 const struct sk_buff *skb,
806 unsigned int dataoff,
807 enum ip_conntrack_info ctinfo,
809 unsigned int hooknum)
811 struct nf_conntrack_tuple *tuple;
812 enum tcp_conntrack new_state, old_state;
813 enum ip_conntrack_dir dir;
814 const struct tcphdr *th;
816 unsigned long timeout;
819 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
822 write_lock_bh(&tcp_lock);
823 old_state = ct->proto.tcp.state;
824 dir = CTINFO2DIR(ctinfo);
825 index = get_conntrack_index(th);
826 new_state = tcp_conntracks[dir][index][old_state];
827 tuple = &ct->tuplehash[dir].tuple;
830 case TCP_CONNTRACK_SYN_SENT:
831 if (old_state < TCP_CONNTRACK_TIME_WAIT)
833 /* RFC 1122: "When a connection is closed actively,
834 * it MUST linger in TIME-WAIT state for a time 2xMSL
835 * (Maximum Segment Lifetime). However, it MAY accept
836 * a new SYN from the remote TCP to reopen the connection
837 * directly from TIME-WAIT state, if..."
838 * We ignore the conditions because we are in the
839 * TIME-WAIT state anyway.
841 * Handle aborted connections: we and the server
842 * think there is an existing connection but the client
843 * aborts it and starts a new one.
845 if (((ct->proto.tcp.seen[dir].flags
846 | ct->proto.tcp.seen[!dir].flags)
847 & IP_CT_TCP_FLAG_CLOSE_INIT)
848 || (ct->proto.tcp.last_dir == dir
849 && ct->proto.tcp.last_index == TCP_RST_SET)) {
850 /* Attempt to reopen a closed/aborted connection.
851 * Delete this connection and look up again. */
852 write_unlock_bh(&tcp_lock);
854 /* Only repeat if we can actually remove the timer.
855 * Destruction may already be in progress in process
856 * context and we must give it a chance to terminate.
863 case TCP_CONNTRACK_IGNORE:
866 * Our connection entry may be out of sync, so ignore
867 * packets which may signal the real connection between
868 * the client and the server.
871 * b) SYN/ACK in REPLY
872 * c) ACK in reply direction after initial SYN in original.
874 * If the ignored packet is invalid, the receiver will send
875 * a RST we'll catch below.
877 if (index == TCP_SYNACK_SET
878 && ct->proto.tcp.last_index == TCP_SYN_SET
879 && ct->proto.tcp.last_dir != dir
880 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
881 /* b) This SYN/ACK acknowledges a SYN that we earlier
882 * ignored as invalid. This means that the client and
883 * the server are both in sync, while the firewall is
884 * not. We kill this session and block the SYN/ACK so
885 * that the client cannot but retransmit its SYN and
886 * thus initiate a clean new session.
888 write_unlock_bh(&tcp_lock);
889 if (LOG_INVALID(IPPROTO_TCP))
890 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
891 "nf_ct_tcp: killing out of sync session ");
895 ct->proto.tcp.last_index = index;
896 ct->proto.tcp.last_dir = dir;
897 ct->proto.tcp.last_seq = ntohl(th->seq);
898 ct->proto.tcp.last_end =
899 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
901 write_unlock_bh(&tcp_lock);
902 if (LOG_INVALID(IPPROTO_TCP))
903 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
904 "nf_ct_tcp: invalid packet ignored ");
906 case TCP_CONNTRACK_MAX:
908 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
909 dir, get_conntrack_index(th), old_state);
910 write_unlock_bh(&tcp_lock);
911 if (LOG_INVALID(IPPROTO_TCP))
912 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
913 "nf_ct_tcp: invalid state ");
915 case TCP_CONNTRACK_CLOSE:
916 if (index == TCP_RST_SET
917 && ((test_bit(IPS_SEEN_REPLY_BIT, &ct->status)
918 && ct->proto.tcp.last_index == TCP_SYN_SET)
919 || (!test_bit(IPS_ASSURED_BIT, &ct->status)
920 && ct->proto.tcp.last_index == TCP_ACK_SET))
921 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
922 /* RST sent to invalid SYN or ACK we had let through
923 * at a) and c) above:
925 * a) SYN was in window then
926 * c) we hold a half-open connection.
928 * Delete our connection entry.
929 * We skip window checking, because packet might ACK
930 * segments we ignored. */
933 /* Just fall through */
935 /* Keep compilers happy. */
939 if (!tcp_in_window(ct, &ct->proto.tcp, dir, index,
940 skb, dataoff, th, pf)) {
941 write_unlock_bh(&tcp_lock);
945 /* From now on we have got in-window packets */
946 ct->proto.tcp.last_index = index;
947 ct->proto.tcp.last_dir = dir;
949 pr_debug("tcp_conntracks: ");
950 nf_ct_dump_tuple(tuple);
951 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
952 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
953 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
954 old_state, new_state);
956 ct->proto.tcp.state = new_state;
957 if (old_state != new_state
958 && new_state == TCP_CONNTRACK_FIN_WAIT)
959 ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
961 if (ct->proto.tcp.retrans >= nf_ct_tcp_max_retrans &&
962 tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans)
963 timeout = nf_ct_tcp_timeout_max_retrans;
964 else if ((ct->proto.tcp.seen[0].flags | ct->proto.tcp.seen[1].flags) &
965 IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED &&
966 tcp_timeouts[new_state] > nf_ct_tcp_timeout_unacknowledged)
967 timeout = nf_ct_tcp_timeout_unacknowledged;
969 timeout = tcp_timeouts[new_state];
970 write_unlock_bh(&tcp_lock);
972 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
973 if (new_state != old_state)
974 nf_conntrack_event_cache(IPCT_PROTOINFO, skb);
976 if (!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
977 /* If only reply is a RST, we can consider ourselves not to
978 have an established connection: this is a fairly common
979 problem case, so we can delete the conntrack
982 nf_ct_kill_acct(ct, ctinfo, skb);
985 } else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
986 && (old_state == TCP_CONNTRACK_SYN_RECV
987 || old_state == TCP_CONNTRACK_ESTABLISHED)
988 && new_state == TCP_CONNTRACK_ESTABLISHED) {
989 /* Set ASSURED if we see see valid ack in ESTABLISHED
990 after SYN_RECV or a valid answer for a picked up
992 set_bit(IPS_ASSURED_BIT, &ct->status);
993 nf_conntrack_event_cache(IPCT_STATUS, skb);
995 nf_ct_refresh_acct(ct, ctinfo, skb, timeout);
1000 /* Called when a new connection for this protocol found. */
1001 static bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb,
1002 unsigned int dataoff)
1004 enum tcp_conntrack new_state;
1005 const struct tcphdr *th;
1006 struct tcphdr _tcph;
1007 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0];
1008 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1];
1010 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
1013 /* Don't need lock here: this conntrack not in circulation yet */
1015 = tcp_conntracks[0][get_conntrack_index(th)]
1016 [TCP_CONNTRACK_NONE];
1018 /* Invalid: delete conntrack */
1019 if (new_state >= TCP_CONNTRACK_MAX) {
1020 pr_debug("nf_ct_tcp: invalid new deleting.\n");
1024 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1026 ct->proto.tcp.seen[0].td_end =
1027 segment_seq_plus_len(ntohl(th->seq), skb->len,
1029 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1030 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1031 ct->proto.tcp.seen[0].td_maxwin = 1;
1032 ct->proto.tcp.seen[0].td_maxend =
1033 ct->proto.tcp.seen[0].td_end;
1035 tcp_options(skb, dataoff, th, &ct->proto.tcp.seen[0]);
1036 ct->proto.tcp.seen[1].flags = 0;
1037 } else if (nf_ct_tcp_loose == 0) {
1038 /* Don't try to pick up connections. */
1042 * We are in the middle of a connection,
1043 * its history is lost for us.
1044 * Let's try to use the data from the packet.
1046 ct->proto.tcp.seen[0].td_end =
1047 segment_seq_plus_len(ntohl(th->seq), skb->len,
1049 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1050 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1051 ct->proto.tcp.seen[0].td_maxwin = 1;
1052 ct->proto.tcp.seen[0].td_maxend =
1053 ct->proto.tcp.seen[0].td_end +
1054 ct->proto.tcp.seen[0].td_maxwin;
1055 ct->proto.tcp.seen[0].td_scale = 0;
1057 /* We assume SACK and liberal window checking to handle
1059 ct->proto.tcp.seen[0].flags =
1060 ct->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1061 IP_CT_TCP_FLAG_BE_LIBERAL;
1064 ct->proto.tcp.seen[1].td_end = 0;
1065 ct->proto.tcp.seen[1].td_maxend = 0;
1066 ct->proto.tcp.seen[1].td_maxwin = 1;
1067 ct->proto.tcp.seen[1].td_scale = 0;
1069 /* tcp_packet will set them */
1070 ct->proto.tcp.state = TCP_CONNTRACK_NONE;
1071 ct->proto.tcp.last_index = TCP_NONE_SET;
1073 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1074 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1075 sender->td_end, sender->td_maxend, sender->td_maxwin,
1077 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1078 receiver->td_scale);
1082 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1084 #include <linux/netfilter/nfnetlink.h>
1085 #include <linux/netfilter/nfnetlink_conntrack.h>
1087 static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
1088 const struct nf_conn *ct)
1090 struct nlattr *nest_parms;
1091 struct nf_ct_tcp_flags tmp = {};
1093 read_lock_bh(&tcp_lock);
1094 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED);
1096 goto nla_put_failure;
1098 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state);
1100 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
1101 ct->proto.tcp.seen[0].td_scale);
1103 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY,
1104 ct->proto.tcp.seen[1].td_scale);
1106 tmp.flags = ct->proto.tcp.seen[0].flags;
1107 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1108 sizeof(struct nf_ct_tcp_flags), &tmp);
1110 tmp.flags = ct->proto.tcp.seen[1].flags;
1111 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1112 sizeof(struct nf_ct_tcp_flags), &tmp);
1113 read_unlock_bh(&tcp_lock);
1115 nla_nest_end(skb, nest_parms);
1120 read_unlock_bh(&tcp_lock);
1124 static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = {
1125 [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 },
1126 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 },
1127 [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 },
1128 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) },
1129 [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) },
1132 static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
1134 struct nlattr *pattr = cda[CTA_PROTOINFO_TCP];
1135 struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
1138 /* updates could not contain anything about the private
1139 * protocol info, in that case skip the parsing */
1143 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, tcp_nla_policy);
1147 if (tb[CTA_PROTOINFO_TCP_STATE] &&
1148 nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]) >= TCP_CONNTRACK_MAX)
1151 write_lock_bh(&tcp_lock);
1152 if (tb[CTA_PROTOINFO_TCP_STATE])
1153 ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]);
1155 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) {
1156 struct nf_ct_tcp_flags *attr =
1157 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]);
1158 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1159 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1162 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) {
1163 struct nf_ct_tcp_flags *attr =
1164 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]);
1165 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1166 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1169 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] &&
1170 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] &&
1171 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1172 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1173 ct->proto.tcp.seen[0].td_scale =
1174 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]);
1175 ct->proto.tcp.seen[1].td_scale =
1176 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]);
1178 write_unlock_bh(&tcp_lock);
1184 #ifdef CONFIG_SYSCTL
1185 static unsigned int tcp_sysctl_table_users;
1186 static struct ctl_table_header *tcp_sysctl_header;
1187 static struct ctl_table tcp_sysctl_table[] = {
1189 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1190 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1191 .maxlen = sizeof(unsigned int),
1193 .proc_handler = &proc_dointvec_jiffies,
1196 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1197 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1198 .maxlen = sizeof(unsigned int),
1200 .proc_handler = &proc_dointvec_jiffies,
1203 .procname = "nf_conntrack_tcp_timeout_established",
1204 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1205 .maxlen = sizeof(unsigned int),
1207 .proc_handler = &proc_dointvec_jiffies,
1210 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1211 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1212 .maxlen = sizeof(unsigned int),
1214 .proc_handler = &proc_dointvec_jiffies,
1217 .procname = "nf_conntrack_tcp_timeout_close_wait",
1218 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1219 .maxlen = sizeof(unsigned int),
1221 .proc_handler = &proc_dointvec_jiffies,
1224 .procname = "nf_conntrack_tcp_timeout_last_ack",
1225 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1226 .maxlen = sizeof(unsigned int),
1228 .proc_handler = &proc_dointvec_jiffies,
1231 .procname = "nf_conntrack_tcp_timeout_time_wait",
1232 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1233 .maxlen = sizeof(unsigned int),
1235 .proc_handler = &proc_dointvec_jiffies,
1238 .procname = "nf_conntrack_tcp_timeout_close",
1239 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1240 .maxlen = sizeof(unsigned int),
1242 .proc_handler = &proc_dointvec_jiffies,
1245 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1246 .data = &nf_ct_tcp_timeout_max_retrans,
1247 .maxlen = sizeof(unsigned int),
1249 .proc_handler = &proc_dointvec_jiffies,
1252 .procname = "nf_conntrack_tcp_timeout_unacknowledged",
1253 .data = &nf_ct_tcp_timeout_unacknowledged,
1254 .maxlen = sizeof(unsigned int),
1256 .proc_handler = &proc_dointvec_jiffies,
1259 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1260 .procname = "nf_conntrack_tcp_loose",
1261 .data = &nf_ct_tcp_loose,
1262 .maxlen = sizeof(unsigned int),
1264 .proc_handler = &proc_dointvec,
1267 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1268 .procname = "nf_conntrack_tcp_be_liberal",
1269 .data = &nf_ct_tcp_be_liberal,
1270 .maxlen = sizeof(unsigned int),
1272 .proc_handler = &proc_dointvec,
1275 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1276 .procname = "nf_conntrack_tcp_max_retrans",
1277 .data = &nf_ct_tcp_max_retrans,
1278 .maxlen = sizeof(unsigned int),
1280 .proc_handler = &proc_dointvec,
1287 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1288 static struct ctl_table tcp_compat_sysctl_table[] = {
1290 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1291 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1292 .maxlen = sizeof(unsigned int),
1294 .proc_handler = &proc_dointvec_jiffies,
1297 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1298 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1299 .maxlen = sizeof(unsigned int),
1301 .proc_handler = &proc_dointvec_jiffies,
1304 .procname = "ip_conntrack_tcp_timeout_established",
1305 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1306 .maxlen = sizeof(unsigned int),
1308 .proc_handler = &proc_dointvec_jiffies,
1311 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1312 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1313 .maxlen = sizeof(unsigned int),
1315 .proc_handler = &proc_dointvec_jiffies,
1318 .procname = "ip_conntrack_tcp_timeout_close_wait",
1319 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1320 .maxlen = sizeof(unsigned int),
1322 .proc_handler = &proc_dointvec_jiffies,
1325 .procname = "ip_conntrack_tcp_timeout_last_ack",
1326 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1327 .maxlen = sizeof(unsigned int),
1329 .proc_handler = &proc_dointvec_jiffies,
1332 .procname = "ip_conntrack_tcp_timeout_time_wait",
1333 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1334 .maxlen = sizeof(unsigned int),
1336 .proc_handler = &proc_dointvec_jiffies,
1339 .procname = "ip_conntrack_tcp_timeout_close",
1340 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1341 .maxlen = sizeof(unsigned int),
1343 .proc_handler = &proc_dointvec_jiffies,
1346 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1347 .data = &nf_ct_tcp_timeout_max_retrans,
1348 .maxlen = sizeof(unsigned int),
1350 .proc_handler = &proc_dointvec_jiffies,
1353 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1354 .procname = "ip_conntrack_tcp_loose",
1355 .data = &nf_ct_tcp_loose,
1356 .maxlen = sizeof(unsigned int),
1358 .proc_handler = &proc_dointvec,
1361 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1362 .procname = "ip_conntrack_tcp_be_liberal",
1363 .data = &nf_ct_tcp_be_liberal,
1364 .maxlen = sizeof(unsigned int),
1366 .proc_handler = &proc_dointvec,
1369 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1370 .procname = "ip_conntrack_tcp_max_retrans",
1371 .data = &nf_ct_tcp_max_retrans,
1372 .maxlen = sizeof(unsigned int),
1374 .proc_handler = &proc_dointvec,
1380 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1381 #endif /* CONFIG_SYSCTL */
1383 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
1386 .l4proto = IPPROTO_TCP,
1388 .pkt_to_tuple = tcp_pkt_to_tuple,
1389 .invert_tuple = tcp_invert_tuple,
1390 .print_tuple = tcp_print_tuple,
1391 .print_conntrack = tcp_print_conntrack,
1392 .packet = tcp_packet,
1395 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1396 .to_nlattr = tcp_to_nlattr,
1397 .from_nlattr = nlattr_to_tcp,
1398 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1399 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1400 .nla_policy = nf_ct_port_nla_policy,
1402 #ifdef CONFIG_SYSCTL
1403 .ctl_table_users = &tcp_sysctl_table_users,
1404 .ctl_table_header = &tcp_sysctl_header,
1405 .ctl_table = tcp_sysctl_table,
1406 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1407 .ctl_compat_table = tcp_compat_sysctl_table,
1411 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1413 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
1415 .l3proto = PF_INET6,
1416 .l4proto = IPPROTO_TCP,
1418 .pkt_to_tuple = tcp_pkt_to_tuple,
1419 .invert_tuple = tcp_invert_tuple,
1420 .print_tuple = tcp_print_tuple,
1421 .print_conntrack = tcp_print_conntrack,
1422 .packet = tcp_packet,
1425 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1426 .to_nlattr = tcp_to_nlattr,
1427 .from_nlattr = nlattr_to_tcp,
1428 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1429 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1430 .nla_policy = nf_ct_port_nla_policy,
1432 #ifdef CONFIG_SYSCTL
1433 .ctl_table_users = &tcp_sysctl_table_users,
1434 .ctl_table_header = &tcp_sysctl_header,
1435 .ctl_table = tcp_sysctl_table,
1438 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);