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>
29 #include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
30 #include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
32 /* "Be conservative in what you do,
33 be liberal in what you accept from others."
34 If it's non-zero, we mark only out of window RST segments as INVALID. */
35 static int nf_ct_tcp_be_liberal __read_mostly = 0;
37 /* If it is set to zero, we disable picking up already established
39 static int nf_ct_tcp_loose __read_mostly = 1;
41 /* Max number of the retransmitted packets without receiving an (acceptable)
42 ACK from the destination. If this number is reached, a shorter timer
44 static int nf_ct_tcp_max_retrans __read_mostly = 3;
46 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
47 closely. They're more complex. --RR */
49 static const char *const tcp_conntrack_names[] = {
63 #define MINS * 60 SECS
64 #define HOURS * 60 MINS
65 #define DAYS * 24 HOURS
67 /* RFC1122 says the R2 limit should be at least 100 seconds.
68 Linux uses 15 packets as limit, which corresponds
69 to ~13-30min depending on RTO. */
70 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
71 static unsigned int nf_ct_tcp_timeout_unacknowledged __read_mostly = 5 MINS;
73 static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
74 [TCP_CONNTRACK_SYN_SENT] = 2 MINS,
75 [TCP_CONNTRACK_SYN_RECV] = 60 SECS,
76 [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS,
77 [TCP_CONNTRACK_FIN_WAIT] = 2 MINS,
78 [TCP_CONNTRACK_CLOSE_WAIT] = 60 SECS,
79 [TCP_CONNTRACK_LAST_ACK] = 30 SECS,
80 [TCP_CONNTRACK_TIME_WAIT] = 2 MINS,
81 [TCP_CONNTRACK_CLOSE] = 10 SECS,
82 [TCP_CONNTRACK_SYN_SENT2] = 2 MINS,
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 sS2 TCP_CONNTRACK_SYN_SENT2
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_SENT2: SYN-only packet seen from reply dir, simultaneous open
125 * SYN_RECV: SYN-ACK packet seen
126 * ESTABLISHED: ACK packet seen
127 * FIN_WAIT: FIN packet seen
128 * CLOSE_WAIT: ACK seen (after FIN)
129 * LAST_ACK: FIN seen (after FIN)
130 * TIME_WAIT: last ACK seen
131 * CLOSE: closed connection (RST)
133 * Packets marked as IGNORED (sIG):
134 * if they may be either invalid or valid
135 * and the receiver may send back a connection
136 * closing RST or a SYN/ACK.
138 * Packets marked as INVALID (sIV):
139 * if we regard them as truly invalid packets
141 static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
144 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
145 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sS2 },
147 * sNO -> sSS Initialize a new connection
148 * sSS -> sSS Retransmitted SYN
149 * sS2 -> sS2 Late retransmitted SYN
151 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
152 * are errors. Receiver will reply with RST
153 * and close the connection.
154 * Or we are not in sync and hold a dead connection.
158 * sTW -> sSS Reopened connection (RFC 1122).
161 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
162 /*synack*/ { sIV, sIV, sIG, sIG, sIG, sIG, sIG, sIG, sIG, sSR },
164 * sNO -> sIV Too late and no reason to do anything
165 * sSS -> sIV Client can't send SYN and then SYN/ACK
166 * sS2 -> sSR SYN/ACK sent to SYN2 in simultaneous open
168 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
169 * are errors. Receiver will reply with RST
170 * and close the connection.
171 * Or we are not in sync and hold a dead connection.
178 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
179 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
181 * sNO -> sIV Too late and no reason to do anything...
182 * sSS -> sIV Client migth not send FIN in this state:
183 * we enforce waiting for a SYN/ACK reply first.
185 * sSR -> sFW Close started.
187 * sFW -> sLA FIN seen in both directions, waiting for
189 * Migth be a retransmitted FIN as well...
191 * sLA -> sLA Retransmitted FIN. Remain in the same state.
195 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
196 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
198 * sNO -> sES Assumed.
199 * 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, sS2 */
210 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL },
211 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
215 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
216 /*syn*/ { sIV, sS2, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sS2 },
218 * sNO -> sIV Never reached.
219 * sSS -> sS2 Simultaneous open
220 * sS2 -> sS2 Retransmitted simultaneous SYN
221 * sSR -> sIV Invalid SYN packets sent by the server
226 * sTW -> sIV Reopened connection, but server may not do it.
229 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
230 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sSR },
232 * sSS -> sSR Standard open.
233 * sS2 -> sSR Simultaneous open
234 * sSR -> sSR Retransmitted SYN/ACK.
235 * sES -> sIG Late retransmitted SYN/ACK?
236 * sFW -> sIG Might be SYN/ACK answering ignored SYN
242 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
243 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
245 * sSS -> sIV Server might not send FIN in this state.
247 * sSR -> sFW Close started.
249 * sFW -> sLA FIN seen in both directions.
251 * sLA -> sLA Retransmitted FIN.
255 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
256 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIG },
258 * sSS -> sIG Might be a half-open connection.
260 * sSR -> sSR Might answer late resent SYN.
262 * sFW -> sCW Normal close request answered by ACK.
264 * sLA -> sTW Last ACK detected.
265 * sTW -> sTW Retransmitted last ACK.
268 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
269 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL },
270 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
274 static bool tcp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
275 struct nf_conntrack_tuple *tuple)
277 const struct tcphdr *hp;
280 /* Actually only need first 8 bytes. */
281 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
285 tuple->src.u.tcp.port = hp->source;
286 tuple->dst.u.tcp.port = hp->dest;
291 static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
292 const struct nf_conntrack_tuple *orig)
294 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
295 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
299 /* Print out the per-protocol part of the tuple. */
300 static int tcp_print_tuple(struct seq_file *s,
301 const struct nf_conntrack_tuple *tuple)
303 return seq_printf(s, "sport=%hu dport=%hu ",
304 ntohs(tuple->src.u.tcp.port),
305 ntohs(tuple->dst.u.tcp.port));
308 /* Print out the private part of the conntrack. */
309 static int tcp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
311 enum tcp_conntrack state;
313 spin_lock_bh(&ct->lock);
314 state = ct->proto.tcp.state;
315 spin_unlock_bh(&ct->lock);
317 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
320 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
322 if (tcph->rst) return TCP_RST_SET;
323 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
324 else if (tcph->fin) return TCP_FIN_SET;
325 else if (tcph->ack) return TCP_ACK_SET;
326 else return TCP_NONE_SET;
329 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
330 in IP Filter' by Guido van Rooij.
332 http://www.nluug.nl/events/sane2000/papers.html
333 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
335 The boundaries and the conditions are changed according to RFC793:
336 the packet must intersect the window (i.e. segments may be
337 after the right or before the left edge) and thus receivers may ACK
338 segments after the right edge of the window.
340 td_maxend = max(sack + max(win,1)) seen in reply packets
341 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
342 td_maxwin += seq + len - sender.td_maxend
343 if seq + len > sender.td_maxend
344 td_end = max(seq + len) seen in sent packets
346 I. Upper bound for valid data: seq <= sender.td_maxend
347 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
348 III. Upper bound for valid (s)ack: sack <= receiver.td_end
349 IV. Lower bound for valid (s)ack: sack >= receiver.td_end - MAXACKWINDOW
351 where sack is the highest right edge of sack block found in the packet
352 or ack in the case of packet without SACK option.
354 The upper bound limit for a valid (s)ack is not ignored -
355 we doesn't have to deal with fragments.
358 static inline __u32 segment_seq_plus_len(__u32 seq,
360 unsigned int dataoff,
361 const struct tcphdr *tcph)
363 /* XXX Should I use payload length field in IP/IPv6 header ?
365 return (seq + len - dataoff - tcph->doff*4
366 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
369 /* Fixme: what about big packets? */
370 #define MAXACKWINCONST 66000
371 #define MAXACKWINDOW(sender) \
372 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
376 * Simplified tcp_parse_options routine from tcp_input.c
378 static void tcp_options(const struct sk_buff *skb,
379 unsigned int dataoff,
380 const struct tcphdr *tcph,
381 struct ip_ct_tcp_state *state)
383 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
384 const unsigned char *ptr;
385 int length = (tcph->doff*4) - sizeof(struct tcphdr);
390 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
404 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
409 if (opsize < 2) /* "silly options" */
412 break; /* don't parse partial options */
414 if (opcode == TCPOPT_SACK_PERM
415 && opsize == TCPOLEN_SACK_PERM)
416 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
417 else if (opcode == TCPOPT_WINDOW
418 && opsize == TCPOLEN_WINDOW) {
419 state->td_scale = *(u_int8_t *)ptr;
421 if (state->td_scale > 14) {
423 state->td_scale = 14;
426 IP_CT_TCP_FLAG_WINDOW_SCALE;
434 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
435 const struct tcphdr *tcph, __u32 *sack)
437 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
438 const unsigned char *ptr;
439 int length = (tcph->doff*4) - sizeof(struct tcphdr);
445 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
449 /* Fast path for timestamp-only option */
450 if (length == TCPOLEN_TSTAMP_ALIGNED*4
451 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
453 | (TCPOPT_TIMESTAMP << 8)
454 | TCPOLEN_TIMESTAMP))
464 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
469 if (opsize < 2) /* "silly options" */
472 break; /* don't parse partial options */
474 if (opcode == TCPOPT_SACK
475 && opsize >= (TCPOLEN_SACK_BASE
476 + TCPOLEN_SACK_PERBLOCK)
477 && !((opsize - TCPOLEN_SACK_BASE)
478 % TCPOLEN_SACK_PERBLOCK)) {
480 i < (opsize - TCPOLEN_SACK_BASE);
481 i += TCPOLEN_SACK_PERBLOCK) {
482 tmp = get_unaligned_be32((__be32 *)(ptr+i)+1);
484 if (after(tmp, *sack))
495 static bool tcp_in_window(const struct nf_conn *ct,
496 struct ip_ct_tcp *state,
497 enum ip_conntrack_dir dir,
499 const struct sk_buff *skb,
500 unsigned int dataoff,
501 const struct tcphdr *tcph,
504 struct net *net = nf_ct_net(ct);
505 struct ip_ct_tcp_state *sender = &state->seen[dir];
506 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
507 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
508 __u32 seq, ack, sack, end, win, swin;
512 * Get the required data from the packet.
514 seq = ntohl(tcph->seq);
515 ack = sack = ntohl(tcph->ack_seq);
516 win = ntohs(tcph->window);
517 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
519 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
520 tcp_sack(skb, dataoff, tcph, &sack);
522 pr_debug("tcp_in_window: START\n");
523 pr_debug("tcp_in_window: ");
524 nf_ct_dump_tuple(tuple);
525 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
526 seq, ack, sack, win, end);
527 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
528 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
529 sender->td_end, sender->td_maxend, sender->td_maxwin,
531 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
534 if (sender->td_maxwin == 0) {
536 * Initialize sender data.
540 * SYN-ACK in reply to a SYN
541 * or SYN from reply direction in simultaneous open.
544 sender->td_maxend = end;
545 sender->td_maxwin = (win == 0 ? 1 : win);
547 tcp_options(skb, dataoff, tcph, sender);
550 * Both sides must send the Window Scale option
551 * to enable window scaling in either direction.
553 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
554 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
556 receiver->td_scale = 0;
558 /* Simultaneous open */
562 * We are in the middle of a connection,
563 * its history is lost for us.
564 * Let's try to use the data from the packet.
566 sender->td_end = end;
567 sender->td_maxwin = (win == 0 ? 1 : win);
568 sender->td_maxend = end + sender->td_maxwin;
570 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
571 && dir == IP_CT_DIR_ORIGINAL)
572 || (state->state == TCP_CONNTRACK_SYN_RECV
573 && dir == IP_CT_DIR_REPLY))
574 && after(end, sender->td_end)) {
576 * RFC 793: "if a TCP is reinitialized ... then it need
577 * not wait at all; it must only be sure to use sequence
578 * numbers larger than those recently used."
581 sender->td_maxend = end;
582 sender->td_maxwin = (win == 0 ? 1 : win);
584 tcp_options(skb, dataoff, tcph, sender);
589 * If there is no ACK, just pretend it was set and OK.
591 ack = sack = receiver->td_end;
592 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
593 (TCP_FLAG_ACK|TCP_FLAG_RST))
596 * Broken TCP stacks, that set ACK in RST packets as well
597 * with zero ack value.
599 ack = sack = receiver->td_end;
604 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
606 * Packets contains no data: we assume it is valid
607 * and check the ack value only.
608 * However RST segments are always validated by their
609 * SEQ number, except when seq == 0 (reset sent answering
612 seq = end = sender->td_end;
614 pr_debug("tcp_in_window: ");
615 nf_ct_dump_tuple(tuple);
616 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
617 seq, ack, sack, win, end);
618 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
619 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
620 sender->td_end, sender->td_maxend, sender->td_maxwin,
622 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
625 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
626 before(seq, sender->td_maxend + 1),
627 after(end, sender->td_end - receiver->td_maxwin - 1),
628 before(sack, receiver->td_end + 1),
629 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
631 if (before(seq, sender->td_maxend + 1) &&
632 after(end, sender->td_end - receiver->td_maxwin - 1) &&
633 before(sack, receiver->td_end + 1) &&
634 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
636 * Take into account window scaling (RFC 1323).
639 win <<= sender->td_scale;
642 * Update sender data.
644 swin = win + (sack - ack);
645 if (sender->td_maxwin < swin)
646 sender->td_maxwin = swin;
647 if (after(end, sender->td_end)) {
648 sender->td_end = end;
649 sender->flags |= IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
652 * Update receiver data.
654 if (after(end, sender->td_maxend))
655 receiver->td_maxwin += end - sender->td_maxend;
656 if (after(sack + win, receiver->td_maxend - 1)) {
657 receiver->td_maxend = sack + win;
659 receiver->td_maxend++;
661 if (ack == receiver->td_end)
662 receiver->flags &= ~IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED;
665 * Check retransmissions.
667 if (index == TCP_ACK_SET) {
668 if (state->last_dir == dir
669 && state->last_seq == seq
670 && state->last_ack == ack
671 && state->last_end == end
672 && state->last_win == win)
675 state->last_dir = dir;
676 state->last_seq = seq;
677 state->last_ack = ack;
678 state->last_end = end;
679 state->last_win = win;
686 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
687 nf_ct_tcp_be_liberal)
689 if (!res && LOG_INVALID(net, IPPROTO_TCP))
690 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
692 before(seq, sender->td_maxend + 1) ?
693 after(end, sender->td_end - receiver->td_maxwin - 1) ?
694 before(sack, receiver->td_end + 1) ?
695 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
696 : "ACK is under the lower bound (possible overly delayed ACK)"
697 : "ACK is over the upper bound (ACKed data not seen yet)"
698 : "SEQ is under the lower bound (already ACKed data retransmitted)"
699 : "SEQ is over the upper bound (over the window of the receiver)");
702 pr_debug("tcp_in_window: res=%u sender end=%u maxend=%u maxwin=%u "
703 "receiver end=%u maxend=%u maxwin=%u\n",
704 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
705 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
710 #ifdef CONFIG_NF_NAT_NEEDED
711 /* Update sender->td_end after NAT successfully mangled the packet */
712 /* Caller must linearize skb at tcp header. */
713 void nf_conntrack_tcp_update(const struct sk_buff *skb,
714 unsigned int dataoff,
718 const struct tcphdr *tcph = (const void *)skb->data + dataoff;
719 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[dir];
720 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[!dir];
723 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
725 spin_lock_bh(&ct->lock);
727 * We have to worry for the ack in the reply packet only...
729 if (after(end, ct->proto.tcp.seen[dir].td_end))
730 ct->proto.tcp.seen[dir].td_end = end;
731 ct->proto.tcp.last_end = end;
732 spin_unlock_bh(&ct->lock);
733 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
734 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
735 sender->td_end, sender->td_maxend, sender->td_maxwin,
737 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
740 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
752 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
753 static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
761 [TH_FIN|TH_ACK|TH_URG] = 1,
766 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
767 static int tcp_error(struct net *net,
769 unsigned int dataoff,
770 enum ip_conntrack_info *ctinfo,
772 unsigned int hooknum)
774 const struct tcphdr *th;
776 unsigned int tcplen = skb->len - dataoff;
779 /* Smaller that minimal TCP header? */
780 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
782 if (LOG_INVALID(net, IPPROTO_TCP))
783 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
784 "nf_ct_tcp: short packet ");
788 /* Not whole TCP header or malformed packet */
789 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
790 if (LOG_INVALID(net, IPPROTO_TCP))
791 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
792 "nf_ct_tcp: truncated/malformed packet ");
796 /* Checksum invalid? Ignore.
797 * We skip checking packets on the outgoing path
798 * because the checksum is assumed to be correct.
800 /* FIXME: Source route IP option packets --RR */
801 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
802 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
803 if (LOG_INVALID(net, IPPROTO_TCP))
804 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
805 "nf_ct_tcp: bad TCP checksum ");
809 /* Check TCP flags. */
810 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
811 if (!tcp_valid_flags[tcpflags]) {
812 if (LOG_INVALID(net, IPPROTO_TCP))
813 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
814 "nf_ct_tcp: invalid TCP flag combination ");
821 /* Returns verdict for packet, or -1 for invalid. */
822 static int tcp_packet(struct nf_conn *ct,
823 const struct sk_buff *skb,
824 unsigned int dataoff,
825 enum ip_conntrack_info ctinfo,
827 unsigned int hooknum)
829 struct net *net = nf_ct_net(ct);
830 struct nf_conntrack_tuple *tuple;
831 enum tcp_conntrack new_state, old_state;
832 enum ip_conntrack_dir dir;
833 const struct tcphdr *th;
835 unsigned long timeout;
838 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
841 spin_lock_bh(&ct->lock);
842 old_state = ct->proto.tcp.state;
843 dir = CTINFO2DIR(ctinfo);
844 index = get_conntrack_index(th);
845 new_state = tcp_conntracks[dir][index][old_state];
846 tuple = &ct->tuplehash[dir].tuple;
849 case TCP_CONNTRACK_SYN_SENT:
850 if (old_state < TCP_CONNTRACK_TIME_WAIT)
852 /* RFC 1122: "When a connection is closed actively,
853 * it MUST linger in TIME-WAIT state for a time 2xMSL
854 * (Maximum Segment Lifetime). However, it MAY accept
855 * a new SYN from the remote TCP to reopen the connection
856 * directly from TIME-WAIT state, if..."
857 * We ignore the conditions because we are in the
858 * TIME-WAIT state anyway.
860 * Handle aborted connections: we and the server
861 * think there is an existing connection but the client
862 * aborts it and starts a new one.
864 if (((ct->proto.tcp.seen[dir].flags
865 | ct->proto.tcp.seen[!dir].flags)
866 & IP_CT_TCP_FLAG_CLOSE_INIT)
867 || (ct->proto.tcp.last_dir == dir
868 && ct->proto.tcp.last_index == TCP_RST_SET)) {
869 /* Attempt to reopen a closed/aborted connection.
870 * Delete this connection and look up again. */
871 spin_unlock_bh(&ct->lock);
873 /* Only repeat if we can actually remove the timer.
874 * Destruction may already be in progress in process
875 * context and we must give it a chance to terminate.
882 case TCP_CONNTRACK_IGNORE:
885 * Our connection entry may be out of sync, so ignore
886 * packets which may signal the real connection between
887 * the client and the server.
890 * b) SYN/ACK in REPLY
891 * c) ACK in reply direction after initial SYN in original.
893 * If the ignored packet is invalid, the receiver will send
894 * a RST we'll catch below.
896 if (index == TCP_SYNACK_SET
897 && ct->proto.tcp.last_index == TCP_SYN_SET
898 && ct->proto.tcp.last_dir != dir
899 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
900 /* b) This SYN/ACK acknowledges a SYN that we earlier
901 * ignored as invalid. This means that the client and
902 * the server are both in sync, while the firewall is
903 * not. We kill this session and block the SYN/ACK so
904 * that the client cannot but retransmit its SYN and
905 * thus initiate a clean new session.
907 spin_unlock_bh(&ct->lock);
908 if (LOG_INVALID(net, IPPROTO_TCP))
909 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
910 "nf_ct_tcp: killing out of sync session ");
914 ct->proto.tcp.last_index = index;
915 ct->proto.tcp.last_dir = dir;
916 ct->proto.tcp.last_seq = ntohl(th->seq);
917 ct->proto.tcp.last_end =
918 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
920 spin_unlock_bh(&ct->lock);
921 if (LOG_INVALID(net, IPPROTO_TCP))
922 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
923 "nf_ct_tcp: invalid packet ignored ");
925 case TCP_CONNTRACK_MAX:
927 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
928 dir, get_conntrack_index(th), old_state);
929 spin_unlock_bh(&ct->lock);
930 if (LOG_INVALID(net, IPPROTO_TCP))
931 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
932 "nf_ct_tcp: invalid state ");
934 case TCP_CONNTRACK_CLOSE:
935 if (index == TCP_RST_SET
936 && ((test_bit(IPS_SEEN_REPLY_BIT, &ct->status)
937 && ct->proto.tcp.last_index == TCP_SYN_SET)
938 || (!test_bit(IPS_ASSURED_BIT, &ct->status)
939 && ct->proto.tcp.last_index == TCP_ACK_SET))
940 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
941 /* RST sent to invalid SYN or ACK we had let through
942 * at a) and c) above:
944 * a) SYN was in window then
945 * c) we hold a half-open connection.
947 * Delete our connection entry.
948 * We skip window checking, because packet might ACK
949 * segments we ignored. */
952 /* Just fall through */
954 /* Keep compilers happy. */
958 if (!tcp_in_window(ct, &ct->proto.tcp, dir, index,
959 skb, dataoff, th, pf)) {
960 spin_unlock_bh(&ct->lock);
964 /* From now on we have got in-window packets */
965 ct->proto.tcp.last_index = index;
966 ct->proto.tcp.last_dir = dir;
968 pr_debug("tcp_conntracks: ");
969 nf_ct_dump_tuple(tuple);
970 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
971 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
972 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
973 old_state, new_state);
975 ct->proto.tcp.state = new_state;
976 if (old_state != new_state
977 && new_state == TCP_CONNTRACK_FIN_WAIT)
978 ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
980 if (ct->proto.tcp.retrans >= nf_ct_tcp_max_retrans &&
981 tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans)
982 timeout = nf_ct_tcp_timeout_max_retrans;
983 else if ((ct->proto.tcp.seen[0].flags | ct->proto.tcp.seen[1].flags) &
984 IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED &&
985 tcp_timeouts[new_state] > nf_ct_tcp_timeout_unacknowledged)
986 timeout = nf_ct_tcp_timeout_unacknowledged;
988 timeout = tcp_timeouts[new_state];
989 spin_unlock_bh(&ct->lock);
991 if (new_state != old_state)
992 nf_conntrack_event_cache(IPCT_PROTOINFO, ct);
994 if (!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
995 /* If only reply is a RST, we can consider ourselves not to
996 have an established connection: this is a fairly common
997 problem case, so we can delete the conntrack
1000 nf_ct_kill_acct(ct, ctinfo, skb);
1003 } else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
1004 && (old_state == TCP_CONNTRACK_SYN_RECV
1005 || old_state == TCP_CONNTRACK_ESTABLISHED)
1006 && new_state == TCP_CONNTRACK_ESTABLISHED) {
1007 /* Set ASSURED if we see see valid ack in ESTABLISHED
1008 after SYN_RECV or a valid answer for a picked up
1010 set_bit(IPS_ASSURED_BIT, &ct->status);
1011 nf_conntrack_event_cache(IPCT_STATUS, ct);
1013 nf_ct_refresh_acct(ct, ctinfo, skb, timeout);
1018 /* Called when a new connection for this protocol found. */
1019 static bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb,
1020 unsigned int dataoff)
1022 enum tcp_conntrack new_state;
1023 const struct tcphdr *th;
1024 struct tcphdr _tcph;
1025 const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0];
1026 const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1];
1028 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
1031 /* Don't need lock here: this conntrack not in circulation yet */
1033 = tcp_conntracks[0][get_conntrack_index(th)]
1034 [TCP_CONNTRACK_NONE];
1036 /* Invalid: delete conntrack */
1037 if (new_state >= TCP_CONNTRACK_MAX) {
1038 pr_debug("nf_ct_tcp: invalid new deleting.\n");
1042 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1044 ct->proto.tcp.seen[0].td_end =
1045 segment_seq_plus_len(ntohl(th->seq), skb->len,
1047 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1048 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1049 ct->proto.tcp.seen[0].td_maxwin = 1;
1050 ct->proto.tcp.seen[0].td_maxend =
1051 ct->proto.tcp.seen[0].td_end;
1053 tcp_options(skb, dataoff, th, &ct->proto.tcp.seen[0]);
1054 ct->proto.tcp.seen[1].flags = 0;
1055 } else if (nf_ct_tcp_loose == 0) {
1056 /* Don't try to pick up connections. */
1060 * We are in the middle of a connection,
1061 * its history is lost for us.
1062 * Let's try to use the data from the packet.
1064 ct->proto.tcp.seen[0].td_end =
1065 segment_seq_plus_len(ntohl(th->seq), skb->len,
1067 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1068 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1069 ct->proto.tcp.seen[0].td_maxwin = 1;
1070 ct->proto.tcp.seen[0].td_maxend =
1071 ct->proto.tcp.seen[0].td_end +
1072 ct->proto.tcp.seen[0].td_maxwin;
1073 ct->proto.tcp.seen[0].td_scale = 0;
1075 /* We assume SACK and liberal window checking to handle
1077 ct->proto.tcp.seen[0].flags =
1078 ct->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1079 IP_CT_TCP_FLAG_BE_LIBERAL;
1082 ct->proto.tcp.seen[1].td_end = 0;
1083 ct->proto.tcp.seen[1].td_maxend = 0;
1084 ct->proto.tcp.seen[1].td_maxwin = 0;
1085 ct->proto.tcp.seen[1].td_scale = 0;
1087 /* tcp_packet will set them */
1088 ct->proto.tcp.state = TCP_CONNTRACK_NONE;
1089 ct->proto.tcp.last_index = TCP_NONE_SET;
1091 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1092 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1093 sender->td_end, sender->td_maxend, sender->td_maxwin,
1095 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1096 receiver->td_scale);
1100 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1102 #include <linux/netfilter/nfnetlink.h>
1103 #include <linux/netfilter/nfnetlink_conntrack.h>
1105 static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
1108 struct nlattr *nest_parms;
1109 struct nf_ct_tcp_flags tmp = {};
1111 spin_lock_bh(&ct->lock);
1112 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED);
1114 goto nla_put_failure;
1116 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state);
1118 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
1119 ct->proto.tcp.seen[0].td_scale);
1121 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY,
1122 ct->proto.tcp.seen[1].td_scale);
1124 tmp.flags = ct->proto.tcp.seen[0].flags;
1125 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1126 sizeof(struct nf_ct_tcp_flags), &tmp);
1128 tmp.flags = ct->proto.tcp.seen[1].flags;
1129 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1130 sizeof(struct nf_ct_tcp_flags), &tmp);
1131 spin_unlock_bh(&ct->lock);
1133 nla_nest_end(skb, nest_parms);
1138 spin_unlock_bh(&ct->lock);
1142 static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = {
1143 [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 },
1144 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 },
1145 [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 },
1146 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) },
1147 [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) },
1150 static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
1152 struct nlattr *pattr = cda[CTA_PROTOINFO_TCP];
1153 struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
1156 /* updates could not contain anything about the private
1157 * protocol info, in that case skip the parsing */
1161 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, tcp_nla_policy);
1165 if (tb[CTA_PROTOINFO_TCP_STATE] &&
1166 nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]) >= TCP_CONNTRACK_MAX)
1169 spin_lock_bh(&ct->lock);
1170 if (tb[CTA_PROTOINFO_TCP_STATE])
1171 ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]);
1173 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) {
1174 struct nf_ct_tcp_flags *attr =
1175 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]);
1176 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1177 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1180 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) {
1181 struct nf_ct_tcp_flags *attr =
1182 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]);
1183 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1184 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1187 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] &&
1188 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] &&
1189 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1190 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1191 ct->proto.tcp.seen[0].td_scale =
1192 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]);
1193 ct->proto.tcp.seen[1].td_scale =
1194 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]);
1196 spin_unlock_bh(&ct->lock);
1201 static int tcp_nlattr_size(void)
1203 return nla_total_size(0) /* CTA_PROTOINFO_TCP */
1204 + nla_policy_len(tcp_nla_policy, CTA_PROTOINFO_TCP_MAX + 1);
1207 static int tcp_nlattr_tuple_size(void)
1209 return nla_policy_len(nf_ct_port_nla_policy, CTA_PROTO_MAX + 1);
1213 #ifdef CONFIG_SYSCTL
1214 static unsigned int tcp_sysctl_table_users;
1215 static struct ctl_table_header *tcp_sysctl_header;
1216 static struct ctl_table tcp_sysctl_table[] = {
1218 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1219 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1220 .maxlen = sizeof(unsigned int),
1222 .proc_handler = proc_dointvec_jiffies,
1225 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1226 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1227 .maxlen = sizeof(unsigned int),
1229 .proc_handler = proc_dointvec_jiffies,
1232 .procname = "nf_conntrack_tcp_timeout_established",
1233 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1234 .maxlen = sizeof(unsigned int),
1236 .proc_handler = proc_dointvec_jiffies,
1239 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1240 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1241 .maxlen = sizeof(unsigned int),
1243 .proc_handler = proc_dointvec_jiffies,
1246 .procname = "nf_conntrack_tcp_timeout_close_wait",
1247 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1248 .maxlen = sizeof(unsigned int),
1250 .proc_handler = proc_dointvec_jiffies,
1253 .procname = "nf_conntrack_tcp_timeout_last_ack",
1254 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1255 .maxlen = sizeof(unsigned int),
1257 .proc_handler = proc_dointvec_jiffies,
1260 .procname = "nf_conntrack_tcp_timeout_time_wait",
1261 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1262 .maxlen = sizeof(unsigned int),
1264 .proc_handler = proc_dointvec_jiffies,
1267 .procname = "nf_conntrack_tcp_timeout_close",
1268 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1269 .maxlen = sizeof(unsigned int),
1271 .proc_handler = proc_dointvec_jiffies,
1274 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1275 .data = &nf_ct_tcp_timeout_max_retrans,
1276 .maxlen = sizeof(unsigned int),
1278 .proc_handler = proc_dointvec_jiffies,
1281 .procname = "nf_conntrack_tcp_timeout_unacknowledged",
1282 .data = &nf_ct_tcp_timeout_unacknowledged,
1283 .maxlen = sizeof(unsigned int),
1285 .proc_handler = proc_dointvec_jiffies,
1288 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1289 .procname = "nf_conntrack_tcp_loose",
1290 .data = &nf_ct_tcp_loose,
1291 .maxlen = sizeof(unsigned int),
1293 .proc_handler = proc_dointvec,
1296 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1297 .procname = "nf_conntrack_tcp_be_liberal",
1298 .data = &nf_ct_tcp_be_liberal,
1299 .maxlen = sizeof(unsigned int),
1301 .proc_handler = proc_dointvec,
1304 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1305 .procname = "nf_conntrack_tcp_max_retrans",
1306 .data = &nf_ct_tcp_max_retrans,
1307 .maxlen = sizeof(unsigned int),
1309 .proc_handler = proc_dointvec,
1316 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1317 static struct ctl_table tcp_compat_sysctl_table[] = {
1319 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1320 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1321 .maxlen = sizeof(unsigned int),
1323 .proc_handler = proc_dointvec_jiffies,
1326 .procname = "ip_conntrack_tcp_timeout_syn_sent2",
1327 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT2],
1328 .maxlen = sizeof(unsigned int),
1330 .proc_handler = proc_dointvec_jiffies,
1333 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1334 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1335 .maxlen = sizeof(unsigned int),
1337 .proc_handler = proc_dointvec_jiffies,
1340 .procname = "ip_conntrack_tcp_timeout_established",
1341 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1342 .maxlen = sizeof(unsigned int),
1344 .proc_handler = proc_dointvec_jiffies,
1347 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1348 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1349 .maxlen = sizeof(unsigned int),
1351 .proc_handler = proc_dointvec_jiffies,
1354 .procname = "ip_conntrack_tcp_timeout_close_wait",
1355 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1356 .maxlen = sizeof(unsigned int),
1358 .proc_handler = proc_dointvec_jiffies,
1361 .procname = "ip_conntrack_tcp_timeout_last_ack",
1362 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1363 .maxlen = sizeof(unsigned int),
1365 .proc_handler = proc_dointvec_jiffies,
1368 .procname = "ip_conntrack_tcp_timeout_time_wait",
1369 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1370 .maxlen = sizeof(unsigned int),
1372 .proc_handler = proc_dointvec_jiffies,
1375 .procname = "ip_conntrack_tcp_timeout_close",
1376 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1377 .maxlen = sizeof(unsigned int),
1379 .proc_handler = proc_dointvec_jiffies,
1382 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1383 .data = &nf_ct_tcp_timeout_max_retrans,
1384 .maxlen = sizeof(unsigned int),
1386 .proc_handler = proc_dointvec_jiffies,
1389 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1390 .procname = "ip_conntrack_tcp_loose",
1391 .data = &nf_ct_tcp_loose,
1392 .maxlen = sizeof(unsigned int),
1394 .proc_handler = proc_dointvec,
1397 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1398 .procname = "ip_conntrack_tcp_be_liberal",
1399 .data = &nf_ct_tcp_be_liberal,
1400 .maxlen = sizeof(unsigned int),
1402 .proc_handler = proc_dointvec,
1405 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1406 .procname = "ip_conntrack_tcp_max_retrans",
1407 .data = &nf_ct_tcp_max_retrans,
1408 .maxlen = sizeof(unsigned int),
1410 .proc_handler = proc_dointvec,
1416 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1417 #endif /* CONFIG_SYSCTL */
1419 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
1422 .l4proto = IPPROTO_TCP,
1424 .pkt_to_tuple = tcp_pkt_to_tuple,
1425 .invert_tuple = tcp_invert_tuple,
1426 .print_tuple = tcp_print_tuple,
1427 .print_conntrack = tcp_print_conntrack,
1428 .packet = tcp_packet,
1431 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1432 .to_nlattr = tcp_to_nlattr,
1433 .nlattr_size = tcp_nlattr_size,
1434 .from_nlattr = nlattr_to_tcp,
1435 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1436 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1437 .nlattr_tuple_size = tcp_nlattr_tuple_size,
1438 .nla_policy = nf_ct_port_nla_policy,
1440 #ifdef CONFIG_SYSCTL
1441 .ctl_table_users = &tcp_sysctl_table_users,
1442 .ctl_table_header = &tcp_sysctl_header,
1443 .ctl_table = tcp_sysctl_table,
1444 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1445 .ctl_compat_table = tcp_compat_sysctl_table,
1449 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1451 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
1453 .l3proto = PF_INET6,
1454 .l4proto = IPPROTO_TCP,
1456 .pkt_to_tuple = tcp_pkt_to_tuple,
1457 .invert_tuple = tcp_invert_tuple,
1458 .print_tuple = tcp_print_tuple,
1459 .print_conntrack = tcp_print_conntrack,
1460 .packet = tcp_packet,
1463 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1464 .to_nlattr = tcp_to_nlattr,
1465 .nlattr_size = tcp_nlattr_size,
1466 .from_nlattr = nlattr_to_tcp,
1467 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1468 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1469 .nlattr_tuple_size = tcp_nlattr_tuple_size,
1470 .nla_policy = nf_ct_port_nla_policy,
1472 #ifdef CONFIG_SYSCTL
1473 .ctl_table_users = &tcp_sysctl_table_users,
1474 .ctl_table_header = &tcp_sysctl_header,
1475 .ctl_table = tcp_sysctl_table,
1478 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);