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.
8 * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>:
9 * - Real stateful connection tracking
10 * - Modified state transitions table
11 * - Window scaling support added
12 * - SACK support added
15 * - State table bugfixes
16 * - More robust state changes
17 * - Tuning timer parameters
19 * 27 Oct 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
20 * - genelized Layer 3 protocol part.
22 * Derived from net/ipv4/netfilter/ip_conntrack_proto_tcp.c
27 #include <linux/types.h>
28 #include <linux/timer.h>
29 #include <linux/netfilter.h>
30 #include <linux/module.h>
32 #include <linux/tcp.h>
33 #include <linux/spinlock.h>
34 #include <linux/skbuff.h>
35 #include <linux/ipv6.h>
36 #include <net/ip6_checksum.h>
40 #include <linux/netfilter.h>
41 #include <linux/netfilter_ipv4.h>
42 #include <linux/netfilter_ipv6.h>
43 #include <net/netfilter/nf_conntrack.h>
44 #include <net/netfilter/nf_conntrack_l4proto.h>
45 #include <net/netfilter/nf_conntrack_ecache.h>
51 #define DEBUGP(format, args...)
54 /* Protects conntrack->proto.tcp */
55 static DEFINE_RWLOCK(tcp_lock);
57 /* "Be conservative in what you do,
58 be liberal in what you accept from others."
59 If it's non-zero, we mark only out of window RST segments as INVALID. */
60 static int nf_ct_tcp_be_liberal __read_mostly = 0;
62 /* If it is set to zero, we disable picking up already established
64 static int nf_ct_tcp_loose __read_mostly = 1;
66 /* Max number of the retransmitted packets without receiving an (acceptable)
67 ACK from the destination. If this number is reached, a shorter timer
69 static int nf_ct_tcp_max_retrans __read_mostly = 3;
71 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
72 closely. They're more complex. --RR */
74 static const char *tcp_conntrack_names[] = {
88 #define MINS * 60 SECS
89 #define HOURS * 60 MINS
90 #define DAYS * 24 HOURS
92 static unsigned int nf_ct_tcp_timeout_syn_sent __read_mostly = 2 MINS;
93 static unsigned int nf_ct_tcp_timeout_syn_recv __read_mostly = 60 SECS;
94 static unsigned int nf_ct_tcp_timeout_established __read_mostly = 5 DAYS;
95 static unsigned int nf_ct_tcp_timeout_fin_wait __read_mostly = 2 MINS;
96 static unsigned int nf_ct_tcp_timeout_close_wait __read_mostly = 60 SECS;
97 static unsigned int nf_ct_tcp_timeout_last_ack __read_mostly = 30 SECS;
98 static unsigned int nf_ct_tcp_timeout_time_wait __read_mostly = 2 MINS;
99 static unsigned int nf_ct_tcp_timeout_close __read_mostly = 10 SECS;
101 /* RFC1122 says the R2 limit should be at least 100 seconds.
102 Linux uses 15 packets as limit, which corresponds
103 to ~13-30min depending on RTO. */
104 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
106 static unsigned int * tcp_timeouts[] = {
107 NULL, /* TCP_CONNTRACK_NONE */
108 &nf_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */
109 &nf_ct_tcp_timeout_syn_recv, /* TCP_CONNTRACK_SYN_RECV, */
110 &nf_ct_tcp_timeout_established, /* TCP_CONNTRACK_ESTABLISHED, */
111 &nf_ct_tcp_timeout_fin_wait, /* TCP_CONNTRACK_FIN_WAIT, */
112 &nf_ct_tcp_timeout_close_wait, /* TCP_CONNTRACK_CLOSE_WAIT, */
113 &nf_ct_tcp_timeout_last_ack, /* TCP_CONNTRACK_LAST_ACK, */
114 &nf_ct_tcp_timeout_time_wait, /* TCP_CONNTRACK_TIME_WAIT, */
115 &nf_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */
116 NULL, /* TCP_CONNTRACK_LISTEN */
119 #define sNO TCP_CONNTRACK_NONE
120 #define sSS TCP_CONNTRACK_SYN_SENT
121 #define sSR TCP_CONNTRACK_SYN_RECV
122 #define sES TCP_CONNTRACK_ESTABLISHED
123 #define sFW TCP_CONNTRACK_FIN_WAIT
124 #define sCW TCP_CONNTRACK_CLOSE_WAIT
125 #define sLA TCP_CONNTRACK_LAST_ACK
126 #define sTW TCP_CONNTRACK_TIME_WAIT
127 #define sCL TCP_CONNTRACK_CLOSE
128 #define sLI TCP_CONNTRACK_LISTEN
129 #define sIV TCP_CONNTRACK_MAX
130 #define sIG TCP_CONNTRACK_IGNORE
132 /* What TCP flags are set from RST/SYN/FIN/ACK. */
143 * The TCP state transition table needs a few words...
145 * We are the man in the middle. All the packets go through us
146 * but might get lost in transit to the destination.
147 * It is assumed that the destinations can't receive segments
150 * The checked segment is in window, but our windows are *not*
151 * equivalent with the ones of the sender/receiver. We always
152 * try to guess the state of the current sender.
154 * The meaning of the states are:
156 * NONE: initial state
157 * SYN_SENT: SYN-only packet seen
158 * SYN_RECV: SYN-ACK packet seen
159 * ESTABLISHED: ACK packet seen
160 * FIN_WAIT: FIN packet seen
161 * CLOSE_WAIT: ACK seen (after FIN)
162 * LAST_ACK: FIN seen (after FIN)
163 * TIME_WAIT: last ACK seen
164 * CLOSE: closed connection
166 * LISTEN state is not used.
168 * Packets marked as IGNORED (sIG):
169 * if they may be either invalid or valid
170 * and the receiver may send back a connection
171 * closing RST or a SYN/ACK.
173 * Packets marked as INVALID (sIV):
174 * if they are invalid
175 * or we do not support the request (simultaneous open)
177 static enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
180 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
181 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
183 * sNO -> sSS Initialize a new connection
184 * sSS -> sSS Retransmitted SYN
185 * sSR -> sIG Late retransmitted SYN?
186 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
187 * are errors. Receiver will reply with RST
188 * and close the connection.
189 * Or we are not in sync and hold a dead connection.
193 * sTW -> sSS Reopened connection (RFC 1122).
196 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
197 /*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
199 * A SYN/ACK from the client is always invalid:
200 * - either it tries to set up a simultaneous open, which is
202 * - or the firewall has just been inserted between the two hosts
203 * during the session set-up. The SYN will be retransmitted
204 * by the true client (or it'll time out).
206 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
207 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
209 * sNO -> sIV Too late and no reason to do anything...
210 * sSS -> sIV Client migth not send FIN in this state:
211 * we enforce waiting for a SYN/ACK reply first.
212 * sSR -> sFW Close started.
214 * sFW -> sLA FIN seen in both directions, waiting for
216 * Migth be a retransmitted FIN as well...
218 * sLA -> sLA Retransmitted FIN. Remain in the same state.
222 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
223 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
225 * sNO -> sES Assumed.
226 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
227 * sSR -> sES Established state is reached.
229 * sFW -> sCW Normal close request answered by ACK.
231 * sLA -> sTW Last ACK detected.
232 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
235 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
236 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
237 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
241 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
242 /*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
244 * sNO -> sIV Never reached.
245 * sSS -> sIV Simultaneous open, not supported
246 * sSR -> sIV Simultaneous open, not supported.
247 * sES -> sIV Server may not initiate a connection.
251 * sTW -> sIV Reopened connection, but server may not do it.
254 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
255 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
257 * sSS -> sSR Standard open.
258 * sSR -> sSR Retransmitted SYN/ACK.
259 * sES -> sIG Late retransmitted SYN/ACK?
260 * sFW -> sIG Might be SYN/ACK answering ignored SYN
266 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
267 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
269 * sSS -> sIV Server might not send FIN in this state.
270 * sSR -> sFW Close started.
272 * sFW -> sLA FIN seen in both directions.
274 * sLA -> sLA Retransmitted FIN.
278 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
279 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
281 * sSS -> sIG Might be a half-open connection.
282 * sSR -> sSR Might answer late resent SYN.
284 * sFW -> sCW Normal close request answered by ACK.
286 * sLA -> sTW Last ACK detected.
287 * sTW -> sTW Retransmitted last ACK.
290 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
291 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
292 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
296 static int tcp_pkt_to_tuple(const struct sk_buff *skb,
297 unsigned int dataoff,
298 struct nf_conntrack_tuple *tuple)
300 struct tcphdr _hdr, *hp;
302 /* Actually only need first 8 bytes. */
303 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
307 tuple->src.u.tcp.port = hp->source;
308 tuple->dst.u.tcp.port = hp->dest;
313 static int tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
314 const struct nf_conntrack_tuple *orig)
316 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
317 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
321 /* Print out the per-protocol part of the tuple. */
322 static int tcp_print_tuple(struct seq_file *s,
323 const struct nf_conntrack_tuple *tuple)
325 return seq_printf(s, "sport=%hu dport=%hu ",
326 ntohs(tuple->src.u.tcp.port),
327 ntohs(tuple->dst.u.tcp.port));
330 /* Print out the private part of the conntrack. */
331 static int tcp_print_conntrack(struct seq_file *s,
332 const struct nf_conn *conntrack)
334 enum tcp_conntrack state;
336 read_lock_bh(&tcp_lock);
337 state = conntrack->proto.tcp.state;
338 read_unlock_bh(&tcp_lock);
340 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
343 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
345 if (tcph->rst) return TCP_RST_SET;
346 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
347 else if (tcph->fin) return TCP_FIN_SET;
348 else if (tcph->ack) return TCP_ACK_SET;
349 else return TCP_NONE_SET;
352 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
353 in IP Filter' by Guido van Rooij.
355 http://www.nluug.nl/events/sane2000/papers.html
356 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
358 The boundaries and the conditions are changed according to RFC793:
359 the packet must intersect the window (i.e. segments may be
360 after the right or before the left edge) and thus receivers may ACK
361 segments after the right edge of the window.
363 td_maxend = max(sack + max(win,1)) seen in reply packets
364 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
365 td_maxwin += seq + len - sender.td_maxend
366 if seq + len > sender.td_maxend
367 td_end = max(seq + len) seen in sent packets
369 I. Upper bound for valid data: seq <= sender.td_maxend
370 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
371 III. Upper bound for valid ack: sack <= receiver.td_end
372 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
374 where sack is the highest right edge of sack block found in the packet.
376 The upper bound limit for a valid ack is not ignored -
377 we doesn't have to deal with fragments.
380 static inline __u32 segment_seq_plus_len(__u32 seq,
382 unsigned int dataoff,
385 /* XXX Should I use payload length field in IP/IPv6 header ?
387 return (seq + len - dataoff - tcph->doff*4
388 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
391 /* Fixme: what about big packets? */
392 #define MAXACKWINCONST 66000
393 #define MAXACKWINDOW(sender) \
394 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
398 * Simplified tcp_parse_options routine from tcp_input.c
400 static void tcp_options(const struct sk_buff *skb,
401 unsigned int dataoff,
403 struct ip_ct_tcp_state *state)
405 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
407 int length = (tcph->doff*4) - sizeof(struct tcphdr);
412 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
426 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
431 if (opsize < 2) /* "silly options" */
434 break; /* don't parse partial options */
436 if (opcode == TCPOPT_SACK_PERM
437 && opsize == TCPOLEN_SACK_PERM)
438 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
439 else if (opcode == TCPOPT_WINDOW
440 && opsize == TCPOLEN_WINDOW) {
441 state->td_scale = *(u_int8_t *)ptr;
443 if (state->td_scale > 14) {
445 state->td_scale = 14;
448 IP_CT_TCP_FLAG_WINDOW_SCALE;
456 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
457 struct tcphdr *tcph, __u32 *sack)
459 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
461 int length = (tcph->doff*4) - sizeof(struct tcphdr);
467 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
471 /* Fast path for timestamp-only option */
472 if (length == TCPOLEN_TSTAMP_ALIGNED*4
473 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
475 | (TCPOPT_TIMESTAMP << 8)
476 | TCPOLEN_TIMESTAMP))
486 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
491 if (opsize < 2) /* "silly options" */
494 break; /* don't parse partial options */
496 if (opcode == TCPOPT_SACK
497 && opsize >= (TCPOLEN_SACK_BASE
498 + TCPOLEN_SACK_PERBLOCK)
499 && !((opsize - TCPOLEN_SACK_BASE)
500 % TCPOLEN_SACK_PERBLOCK)) {
502 i < (opsize - TCPOLEN_SACK_BASE);
503 i += TCPOLEN_SACK_PERBLOCK) {
504 tmp = ntohl(*((__be32 *)(ptr+i)+1));
506 if (after(tmp, *sack))
517 static int tcp_in_window(struct ip_ct_tcp *state,
518 enum ip_conntrack_dir dir,
520 const struct sk_buff *skb,
521 unsigned int dataoff,
525 struct ip_ct_tcp_state *sender = &state->seen[dir];
526 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
527 __u32 seq, ack, sack, end, win, swin;
531 * Get the required data from the packet.
533 seq = ntohl(tcph->seq);
534 ack = sack = ntohl(tcph->ack_seq);
535 win = ntohs(tcph->window);
536 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
538 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
539 tcp_sack(skb, dataoff, tcph, &sack);
541 DEBUGP("tcp_in_window: START\n");
542 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
543 "seq=%u ack=%u sack=%u win=%u end=%u\n",
544 NIPQUAD(iph->saddr), ntohs(tcph->source),
545 NIPQUAD(iph->daddr), ntohs(tcph->dest),
546 seq, ack, sack, win, end);
547 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
548 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
549 sender->td_end, sender->td_maxend, sender->td_maxwin,
551 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
554 if (sender->td_end == 0) {
556 * Initialize sender data.
558 if (tcph->syn && tcph->ack) {
560 * Outgoing SYN-ACK in reply to a SYN.
563 sender->td_maxend = end;
564 sender->td_maxwin = (win == 0 ? 1 : win);
566 tcp_options(skb, dataoff, tcph, sender);
569 * Both sides must send the Window Scale option
570 * to enable window scaling in either direction.
572 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
573 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
575 receiver->td_scale = 0;
578 * We are in the middle of a connection,
579 * its history is lost for us.
580 * Let's try to use the data from the packet.
582 sender->td_end = end;
583 sender->td_maxwin = (win == 0 ? 1 : win);
584 sender->td_maxend = end + sender->td_maxwin;
586 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
587 && dir == IP_CT_DIR_ORIGINAL)
588 || (state->state == TCP_CONNTRACK_SYN_RECV
589 && dir == IP_CT_DIR_REPLY))
590 && after(end, sender->td_end)) {
592 * RFC 793: "if a TCP is reinitialized ... then it need
593 * not wait at all; it must only be sure to use sequence
594 * numbers larger than those recently used."
597 sender->td_maxend = end;
598 sender->td_maxwin = (win == 0 ? 1 : win);
600 tcp_options(skb, dataoff, tcph, sender);
605 * If there is no ACK, just pretend it was set and OK.
607 ack = sack = receiver->td_end;
608 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
609 (TCP_FLAG_ACK|TCP_FLAG_RST))
612 * Broken TCP stacks, that set ACK in RST packets as well
613 * with zero ack value.
615 ack = sack = receiver->td_end;
620 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
622 * Packets contains no data: we assume it is valid
623 * and check the ack value only.
624 * However RST segments are always validated by their
625 * SEQ number, except when seq == 0 (reset sent answering
628 seq = end = sender->td_end;
630 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
631 "seq=%u ack=%u sack =%u win=%u end=%u\n",
632 NIPQUAD(iph->saddr), ntohs(tcph->source),
633 NIPQUAD(iph->daddr), ntohs(tcph->dest),
634 seq, ack, sack, win, end);
635 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
636 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
637 sender->td_end, sender->td_maxend, sender->td_maxwin,
639 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
642 DEBUGP("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
643 before(seq, sender->td_maxend + 1),
644 after(end, sender->td_end - receiver->td_maxwin - 1),
645 before(sack, receiver->td_end + 1),
646 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
648 if (before(seq, sender->td_maxend + 1) &&
649 after(end, sender->td_end - receiver->td_maxwin - 1) &&
650 before(sack, receiver->td_end + 1) &&
651 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
653 * Take into account window scaling (RFC 1323).
656 win <<= sender->td_scale;
659 * Update sender data.
661 swin = win + (sack - ack);
662 if (sender->td_maxwin < swin)
663 sender->td_maxwin = swin;
664 if (after(end, sender->td_end))
665 sender->td_end = end;
667 * Update receiver data.
669 if (after(end, sender->td_maxend))
670 receiver->td_maxwin += end - sender->td_maxend;
671 if (after(sack + win, receiver->td_maxend - 1)) {
672 receiver->td_maxend = sack + win;
674 receiver->td_maxend++;
678 * Check retransmissions.
680 if (index == TCP_ACK_SET) {
681 if (state->last_dir == dir
682 && state->last_seq == seq
683 && state->last_ack == ack
684 && state->last_end == end
685 && state->last_win == win)
688 state->last_dir = dir;
689 state->last_seq = seq;
690 state->last_ack = ack;
691 state->last_end = end;
692 state->last_win = win;
699 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
700 nf_ct_tcp_be_liberal)
702 if (!res && LOG_INVALID(IPPROTO_TCP))
703 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
705 before(seq, sender->td_maxend + 1) ?
706 after(end, sender->td_end - receiver->td_maxwin - 1) ?
707 before(sack, receiver->td_end + 1) ?
708 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
709 : "ACK is under the lower bound (possible overly delayed ACK)"
710 : "ACK is over the upper bound (ACKed data not seen yet)"
711 : "SEQ is under the lower bound (already ACKed data retransmitted)"
712 : "SEQ is over the upper bound (over the window of the receiver)");
715 DEBUGP("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
716 "receiver end=%u maxend=%u maxwin=%u\n",
717 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
718 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
723 #ifdef CONFIG_NF_NAT_NEEDED
724 /* Update sender->td_end after NAT successfully mangled the packet */
725 /* Caller must linearize skb at tcp header. */
726 void nf_conntrack_tcp_update(struct sk_buff *skb,
727 unsigned int dataoff,
728 struct nf_conn *conntrack,
731 struct tcphdr *tcph = (void *)skb->data + dataoff;
734 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[dir];
735 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[!dir];
738 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
740 write_lock_bh(&tcp_lock);
742 * We have to worry for the ack in the reply packet only...
744 if (after(end, conntrack->proto.tcp.seen[dir].td_end))
745 conntrack->proto.tcp.seen[dir].td_end = end;
746 conntrack->proto.tcp.last_end = end;
747 write_unlock_bh(&tcp_lock);
748 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
749 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
750 sender->td_end, sender->td_maxend, sender->td_maxwin,
752 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
755 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
767 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
768 static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
776 [TH_FIN|TH_ACK|TH_URG] = 1,
781 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
782 static int tcp_error(struct sk_buff *skb,
783 unsigned int dataoff,
784 enum ip_conntrack_info *ctinfo,
786 unsigned int hooknum)
788 struct tcphdr _tcph, *th;
789 unsigned int tcplen = skb->len - dataoff;
792 /* Smaller that minimal TCP header? */
793 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
795 if (LOG_INVALID(IPPROTO_TCP))
796 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
797 "nf_ct_tcp: short packet ");
801 /* Not whole TCP header or malformed packet */
802 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
803 if (LOG_INVALID(IPPROTO_TCP))
804 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
805 "nf_ct_tcp: truncated/malformed packet ");
809 /* Checksum invalid? Ignore.
810 * We skip checking packets on the outgoing path
811 * because the checksum is assumed to be correct.
813 /* FIXME: Source route IP option packets --RR */
814 if (nf_conntrack_checksum &&
815 ((pf == PF_INET && hooknum == NF_IP_PRE_ROUTING) ||
816 (pf == PF_INET6 && hooknum == NF_IP6_PRE_ROUTING)) &&
817 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
818 if (LOG_INVALID(IPPROTO_TCP))
819 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
820 "nf_ct_tcp: bad TCP checksum ");
824 /* Check TCP flags. */
825 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
826 if (!tcp_valid_flags[tcpflags]) {
827 if (LOG_INVALID(IPPROTO_TCP))
828 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
829 "nf_ct_tcp: invalid TCP flag combination ");
836 /* Returns verdict for packet, or -1 for invalid. */
837 static int tcp_packet(struct nf_conn *conntrack,
838 const struct sk_buff *skb,
839 unsigned int dataoff,
840 enum ip_conntrack_info ctinfo,
842 unsigned int hooknum)
844 enum tcp_conntrack new_state, old_state;
845 enum ip_conntrack_dir dir;
846 struct tcphdr *th, _tcph;
847 unsigned long timeout;
850 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
853 write_lock_bh(&tcp_lock);
854 old_state = conntrack->proto.tcp.state;
855 dir = CTINFO2DIR(ctinfo);
856 index = get_conntrack_index(th);
857 new_state = tcp_conntracks[dir][index][old_state];
860 case TCP_CONNTRACK_IGNORE:
864 * b) SYN/ACK in REPLY
865 * c) ACK in reply direction after initial SYN in original.
867 if (index == TCP_SYNACK_SET
868 && conntrack->proto.tcp.last_index == TCP_SYN_SET
869 && conntrack->proto.tcp.last_dir != dir
870 && ntohl(th->ack_seq) ==
871 conntrack->proto.tcp.last_end) {
872 /* This SYN/ACK acknowledges a SYN that we earlier
873 * ignored as invalid. This means that the client and
874 * the server are both in sync, while the firewall is
875 * not. We kill this session and block the SYN/ACK so
876 * that the client cannot but retransmit its SYN and
877 * thus initiate a clean new session.
879 write_unlock_bh(&tcp_lock);
880 if (LOG_INVALID(IPPROTO_TCP))
881 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
882 "nf_ct_tcp: killing out of sync session ");
883 if (del_timer(&conntrack->timeout))
884 conntrack->timeout.function((unsigned long)
888 conntrack->proto.tcp.last_index = index;
889 conntrack->proto.tcp.last_dir = dir;
890 conntrack->proto.tcp.last_seq = ntohl(th->seq);
891 conntrack->proto.tcp.last_end =
892 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
894 write_unlock_bh(&tcp_lock);
895 if (LOG_INVALID(IPPROTO_TCP))
896 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
897 "nf_ct_tcp: invalid packed ignored ");
899 case TCP_CONNTRACK_MAX:
901 DEBUGP("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
902 dir, get_conntrack_index(th),
904 write_unlock_bh(&tcp_lock);
905 if (LOG_INVALID(IPPROTO_TCP))
906 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
907 "nf_ct_tcp: invalid state ");
909 case TCP_CONNTRACK_SYN_SENT:
910 if (old_state < TCP_CONNTRACK_TIME_WAIT)
912 if ((conntrack->proto.tcp.seen[dir].flags &
913 IP_CT_TCP_FLAG_CLOSE_INIT)
914 || after(ntohl(th->seq),
915 conntrack->proto.tcp.seen[dir].td_end)) {
916 /* Attempt to reopen a closed connection.
917 * Delete this connection and look up again. */
918 write_unlock_bh(&tcp_lock);
919 if (del_timer(&conntrack->timeout))
920 conntrack->timeout.function((unsigned long)
924 write_unlock_bh(&tcp_lock);
925 if (LOG_INVALID(IPPROTO_TCP))
926 nf_log_packet(pf, 0, skb, NULL, NULL,
927 NULL, "nf_ct_tcp: invalid SYN");
930 case TCP_CONNTRACK_CLOSE:
931 if (index == TCP_RST_SET
932 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)
933 && conntrack->proto.tcp.last_index == TCP_SYN_SET)
934 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
935 && conntrack->proto.tcp.last_index == TCP_ACK_SET))
936 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) {
937 /* RST sent to invalid SYN or ACK we had let through
938 * at a) and c) above:
940 * a) SYN was in window then
941 * c) we hold a half-open connection.
943 * Delete our connection entry.
944 * We skip window checking, because packet might ACK
945 * segments we ignored. */
948 /* Just fall through */
950 /* Keep compilers happy. */
954 if (!tcp_in_window(&conntrack->proto.tcp, dir, index,
955 skb, dataoff, th, pf)) {
956 write_unlock_bh(&tcp_lock);
960 /* From now on we have got in-window packets */
961 conntrack->proto.tcp.last_index = index;
963 DEBUGP("tcp_conntracks: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
964 "syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
965 NIPQUAD(iph->saddr), ntohs(th->source),
966 NIPQUAD(iph->daddr), ntohs(th->dest),
967 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
968 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
969 old_state, new_state);
971 conntrack->proto.tcp.state = new_state;
972 if (old_state != new_state
973 && (new_state == TCP_CONNTRACK_FIN_WAIT
974 || new_state == TCP_CONNTRACK_CLOSE))
975 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
976 timeout = conntrack->proto.tcp.retrans >= nf_ct_tcp_max_retrans
977 && *tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans
978 ? nf_ct_tcp_timeout_max_retrans : *tcp_timeouts[new_state];
979 write_unlock_bh(&tcp_lock);
981 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
982 if (new_state != old_state)
983 nf_conntrack_event_cache(IPCT_PROTOINFO, skb);
985 if (!test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
986 /* If only reply is a RST, we can consider ourselves not to
987 have an established connection: this is a fairly common
988 problem case, so we can delete the conntrack
991 if (del_timer(&conntrack->timeout))
992 conntrack->timeout.function((unsigned long)
996 } else if (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
997 && (old_state == TCP_CONNTRACK_SYN_RECV
998 || old_state == TCP_CONNTRACK_ESTABLISHED)
999 && new_state == TCP_CONNTRACK_ESTABLISHED) {
1000 /* Set ASSURED if we see see valid ack in ESTABLISHED
1001 after SYN_RECV or a valid answer for a picked up
1003 set_bit(IPS_ASSURED_BIT, &conntrack->status);
1004 nf_conntrack_event_cache(IPCT_STATUS, skb);
1006 nf_ct_refresh_acct(conntrack, ctinfo, skb, timeout);
1011 /* Called when a new connection for this protocol found. */
1012 static int tcp_new(struct nf_conn *conntrack,
1013 const struct sk_buff *skb,
1014 unsigned int dataoff)
1016 enum tcp_conntrack new_state;
1017 struct tcphdr *th, _tcph;
1019 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[0];
1020 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[1];
1023 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
1026 /* Don't need lock here: this conntrack not in circulation yet */
1028 = tcp_conntracks[0][get_conntrack_index(th)]
1029 [TCP_CONNTRACK_NONE];
1031 /* Invalid: delete conntrack */
1032 if (new_state >= TCP_CONNTRACK_MAX) {
1033 DEBUGP("nf_ct_tcp: invalid new deleting.\n");
1037 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1039 conntrack->proto.tcp.seen[0].td_end =
1040 segment_seq_plus_len(ntohl(th->seq), skb->len,
1042 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1043 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1044 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1045 conntrack->proto.tcp.seen[0].td_maxend =
1046 conntrack->proto.tcp.seen[0].td_end;
1048 tcp_options(skb, dataoff, th, &conntrack->proto.tcp.seen[0]);
1049 conntrack->proto.tcp.seen[1].flags = 0;
1050 } else if (nf_ct_tcp_loose == 0) {
1051 /* Don't try to pick up connections. */
1055 * We are in the middle of a connection,
1056 * its history is lost for us.
1057 * Let's try to use the data from the packet.
1059 conntrack->proto.tcp.seen[0].td_end =
1060 segment_seq_plus_len(ntohl(th->seq), skb->len,
1062 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1063 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1064 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1065 conntrack->proto.tcp.seen[0].td_maxend =
1066 conntrack->proto.tcp.seen[0].td_end +
1067 conntrack->proto.tcp.seen[0].td_maxwin;
1068 conntrack->proto.tcp.seen[0].td_scale = 0;
1070 /* We assume SACK and liberal window checking to handle
1072 conntrack->proto.tcp.seen[0].flags =
1073 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1074 IP_CT_TCP_FLAG_BE_LIBERAL;
1077 conntrack->proto.tcp.seen[1].td_end = 0;
1078 conntrack->proto.tcp.seen[1].td_maxend = 0;
1079 conntrack->proto.tcp.seen[1].td_maxwin = 1;
1080 conntrack->proto.tcp.seen[1].td_scale = 0;
1082 /* tcp_packet will set them */
1083 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE;
1084 conntrack->proto.tcp.last_index = TCP_NONE_SET;
1086 DEBUGP("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1087 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1088 sender->td_end, sender->td_maxend, sender->td_maxwin,
1090 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1091 receiver->td_scale);
1095 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1097 #include <linux/netfilter/nfnetlink.h>
1098 #include <linux/netfilter/nfnetlink_conntrack.h>
1100 static int tcp_to_nfattr(struct sk_buff *skb, struct nfattr *nfa,
1101 const struct nf_conn *ct)
1103 struct nfattr *nest_parms;
1104 struct nf_ct_tcp_flags tmp = {};
1106 read_lock_bh(&tcp_lock);
1107 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP);
1108 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t),
1109 &ct->proto.tcp.state);
1111 NFA_PUT(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL, sizeof(u_int8_t),
1112 &ct->proto.tcp.seen[0].td_scale);
1114 NFA_PUT(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY, sizeof(u_int8_t),
1115 &ct->proto.tcp.seen[1].td_scale);
1117 tmp.flags = ct->proto.tcp.seen[0].flags;
1118 NFA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1119 sizeof(struct nf_ct_tcp_flags), &tmp);
1121 tmp.flags = ct->proto.tcp.seen[1].flags;
1122 NFA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1123 sizeof(struct nf_ct_tcp_flags), &tmp);
1124 read_unlock_bh(&tcp_lock);
1126 NFA_NEST_END(skb, nest_parms);
1131 read_unlock_bh(&tcp_lock);
1135 static const size_t cta_min_tcp[CTA_PROTOINFO_TCP_MAX] = {
1136 [CTA_PROTOINFO_TCP_STATE-1] = sizeof(u_int8_t),
1137 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1] = sizeof(u_int8_t),
1138 [CTA_PROTOINFO_TCP_WSCALE_REPLY-1] = sizeof(u_int8_t),
1139 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1] = sizeof(struct nf_ct_tcp_flags),
1140 [CTA_PROTOINFO_TCP_FLAGS_REPLY-1] = sizeof(struct nf_ct_tcp_flags)
1143 static int nfattr_to_tcp(struct nfattr *cda[], struct nf_conn *ct)
1145 struct nfattr *attr = cda[CTA_PROTOINFO_TCP-1];
1146 struct nfattr *tb[CTA_PROTOINFO_TCP_MAX];
1148 /* updates could not contain anything about the private
1149 * protocol info, in that case skip the parsing */
1153 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr);
1155 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp))
1158 if (!tb[CTA_PROTOINFO_TCP_STATE-1])
1161 write_lock_bh(&tcp_lock);
1162 ct->proto.tcp.state =
1163 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]);
1165 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1]) {
1166 struct nf_ct_tcp_flags *attr =
1167 NFA_DATA(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL-1]);
1168 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1169 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1172 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY-1]) {
1173 struct nf_ct_tcp_flags *attr =
1174 NFA_DATA(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY-1]);
1175 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1176 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1179 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1] &&
1180 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY-1] &&
1181 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1182 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1183 ct->proto.tcp.seen[0].td_scale = *(u_int8_t *)
1184 NFA_DATA(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL-1]);
1185 ct->proto.tcp.seen[1].td_scale = *(u_int8_t *)
1186 NFA_DATA(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY-1]);
1188 write_unlock_bh(&tcp_lock);
1194 #ifdef CONFIG_SYSCTL
1195 static unsigned int tcp_sysctl_table_users;
1196 static struct ctl_table_header *tcp_sysctl_header;
1197 static struct ctl_table tcp_sysctl_table[] = {
1199 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
1200 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1201 .data = &nf_ct_tcp_timeout_syn_sent,
1202 .maxlen = sizeof(unsigned int),
1204 .proc_handler = &proc_dointvec_jiffies,
1207 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
1208 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1209 .data = &nf_ct_tcp_timeout_syn_recv,
1210 .maxlen = sizeof(unsigned int),
1212 .proc_handler = &proc_dointvec_jiffies,
1215 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
1216 .procname = "nf_conntrack_tcp_timeout_established",
1217 .data = &nf_ct_tcp_timeout_established,
1218 .maxlen = sizeof(unsigned int),
1220 .proc_handler = &proc_dointvec_jiffies,
1223 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
1224 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1225 .data = &nf_ct_tcp_timeout_fin_wait,
1226 .maxlen = sizeof(unsigned int),
1228 .proc_handler = &proc_dointvec_jiffies,
1231 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
1232 .procname = "nf_conntrack_tcp_timeout_close_wait",
1233 .data = &nf_ct_tcp_timeout_close_wait,
1234 .maxlen = sizeof(unsigned int),
1236 .proc_handler = &proc_dointvec_jiffies,
1239 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
1240 .procname = "nf_conntrack_tcp_timeout_last_ack",
1241 .data = &nf_ct_tcp_timeout_last_ack,
1242 .maxlen = sizeof(unsigned int),
1244 .proc_handler = &proc_dointvec_jiffies,
1247 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
1248 .procname = "nf_conntrack_tcp_timeout_time_wait",
1249 .data = &nf_ct_tcp_timeout_time_wait,
1250 .maxlen = sizeof(unsigned int),
1252 .proc_handler = &proc_dointvec_jiffies,
1255 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
1256 .procname = "nf_conntrack_tcp_timeout_close",
1257 .data = &nf_ct_tcp_timeout_close,
1258 .maxlen = sizeof(unsigned int),
1260 .proc_handler = &proc_dointvec_jiffies,
1263 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
1264 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1265 .data = &nf_ct_tcp_timeout_max_retrans,
1266 .maxlen = sizeof(unsigned int),
1268 .proc_handler = &proc_dointvec_jiffies,
1271 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1272 .procname = "nf_conntrack_tcp_loose",
1273 .data = &nf_ct_tcp_loose,
1274 .maxlen = sizeof(unsigned int),
1276 .proc_handler = &proc_dointvec,
1279 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1280 .procname = "nf_conntrack_tcp_be_liberal",
1281 .data = &nf_ct_tcp_be_liberal,
1282 .maxlen = sizeof(unsigned int),
1284 .proc_handler = &proc_dointvec,
1287 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1288 .procname = "nf_conntrack_tcp_max_retrans",
1289 .data = &nf_ct_tcp_max_retrans,
1290 .maxlen = sizeof(unsigned int),
1292 .proc_handler = &proc_dointvec,
1299 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1300 static struct ctl_table tcp_compat_sysctl_table[] = {
1302 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
1303 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1304 .data = &nf_ct_tcp_timeout_syn_sent,
1305 .maxlen = sizeof(unsigned int),
1307 .proc_handler = &proc_dointvec_jiffies,
1310 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
1311 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1312 .data = &nf_ct_tcp_timeout_syn_recv,
1313 .maxlen = sizeof(unsigned int),
1315 .proc_handler = &proc_dointvec_jiffies,
1318 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
1319 .procname = "ip_conntrack_tcp_timeout_established",
1320 .data = &nf_ct_tcp_timeout_established,
1321 .maxlen = sizeof(unsigned int),
1323 .proc_handler = &proc_dointvec_jiffies,
1326 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
1327 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1328 .data = &nf_ct_tcp_timeout_fin_wait,
1329 .maxlen = sizeof(unsigned int),
1331 .proc_handler = &proc_dointvec_jiffies,
1334 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
1335 .procname = "ip_conntrack_tcp_timeout_close_wait",
1336 .data = &nf_ct_tcp_timeout_close_wait,
1337 .maxlen = sizeof(unsigned int),
1339 .proc_handler = &proc_dointvec_jiffies,
1342 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
1343 .procname = "ip_conntrack_tcp_timeout_last_ack",
1344 .data = &nf_ct_tcp_timeout_last_ack,
1345 .maxlen = sizeof(unsigned int),
1347 .proc_handler = &proc_dointvec_jiffies,
1350 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
1351 .procname = "ip_conntrack_tcp_timeout_time_wait",
1352 .data = &nf_ct_tcp_timeout_time_wait,
1353 .maxlen = sizeof(unsigned int),
1355 .proc_handler = &proc_dointvec_jiffies,
1358 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
1359 .procname = "ip_conntrack_tcp_timeout_close",
1360 .data = &nf_ct_tcp_timeout_close,
1361 .maxlen = sizeof(unsigned int),
1363 .proc_handler = &proc_dointvec_jiffies,
1366 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
1367 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1368 .data = &nf_ct_tcp_timeout_max_retrans,
1369 .maxlen = sizeof(unsigned int),
1371 .proc_handler = &proc_dointvec_jiffies,
1374 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1375 .procname = "ip_conntrack_tcp_loose",
1376 .data = &nf_ct_tcp_loose,
1377 .maxlen = sizeof(unsigned int),
1379 .proc_handler = &proc_dointvec,
1382 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1383 .procname = "ip_conntrack_tcp_be_liberal",
1384 .data = &nf_ct_tcp_be_liberal,
1385 .maxlen = sizeof(unsigned int),
1387 .proc_handler = &proc_dointvec,
1390 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1391 .procname = "ip_conntrack_tcp_max_retrans",
1392 .data = &nf_ct_tcp_max_retrans,
1393 .maxlen = sizeof(unsigned int),
1395 .proc_handler = &proc_dointvec,
1401 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1402 #endif /* CONFIG_SYSCTL */
1404 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 =
1407 .l4proto = IPPROTO_TCP,
1409 .pkt_to_tuple = tcp_pkt_to_tuple,
1410 .invert_tuple = tcp_invert_tuple,
1411 .print_tuple = tcp_print_tuple,
1412 .print_conntrack = tcp_print_conntrack,
1413 .packet = tcp_packet,
1416 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1417 .to_nfattr = tcp_to_nfattr,
1418 .from_nfattr = nfattr_to_tcp,
1419 .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr,
1420 .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple,
1422 #ifdef CONFIG_SYSCTL
1423 .ctl_table_users = &tcp_sysctl_table_users,
1424 .ctl_table_header = &tcp_sysctl_header,
1425 .ctl_table = tcp_sysctl_table,
1426 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1427 .ctl_compat_table = tcp_compat_sysctl_table,
1431 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1433 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 =
1435 .l3proto = PF_INET6,
1436 .l4proto = IPPROTO_TCP,
1438 .pkt_to_tuple = tcp_pkt_to_tuple,
1439 .invert_tuple = tcp_invert_tuple,
1440 .print_tuple = tcp_print_tuple,
1441 .print_conntrack = tcp_print_conntrack,
1442 .packet = tcp_packet,
1445 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1446 .to_nfattr = tcp_to_nfattr,
1447 .from_nfattr = nfattr_to_tcp,
1448 .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr,
1449 .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple,
1451 #ifdef CONFIG_SYSCTL
1452 .ctl_table_users = &tcp_sysctl_table_users,
1453 .ctl_table_header = &tcp_sysctl_header,
1454 .ctl_table = tcp_sysctl_table,
1457 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);