1 /* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/types.h>
10 #include <linux/timer.h>
11 #include <linux/module.h>
13 #include <linux/tcp.h>
14 #include <linux/spinlock.h>
15 #include <linux/skbuff.h>
16 #include <linux/ipv6.h>
17 #include <net/ip6_checksum.h>
21 #include <linux/netfilter.h>
22 #include <linux/netfilter_ipv4.h>
23 #include <linux/netfilter_ipv6.h>
24 #include <net/netfilter/nf_conntrack.h>
25 #include <net/netfilter/nf_conntrack_l4proto.h>
26 #include <net/netfilter/nf_conntrack_ecache.h>
27 #include <net/netfilter/nf_log.h>
29 /* Protects conntrack->proto.tcp */
30 static DEFINE_RWLOCK(tcp_lock);
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 *tcp_conntrack_names[] = {
63 #define MINS * 60 SECS
64 #define HOURS * 60 MINS
65 #define DAYS * 24 HOURS
67 static unsigned int nf_ct_tcp_timeout_syn_sent __read_mostly = 2 MINS;
68 static unsigned int nf_ct_tcp_timeout_syn_recv __read_mostly = 60 SECS;
69 static unsigned int nf_ct_tcp_timeout_established __read_mostly = 5 DAYS;
70 static unsigned int nf_ct_tcp_timeout_fin_wait __read_mostly = 2 MINS;
71 static unsigned int nf_ct_tcp_timeout_close_wait __read_mostly = 60 SECS;
72 static unsigned int nf_ct_tcp_timeout_last_ack __read_mostly = 30 SECS;
73 static unsigned int nf_ct_tcp_timeout_time_wait __read_mostly = 2 MINS;
74 static unsigned int nf_ct_tcp_timeout_close __read_mostly = 10 SECS;
76 /* RFC1122 says the R2 limit should be at least 100 seconds.
77 Linux uses 15 packets as limit, which corresponds
78 to ~13-30min depending on RTO. */
79 static unsigned int nf_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
81 static unsigned int * tcp_timeouts[] = {
82 NULL, /* TCP_CONNTRACK_NONE */
83 &nf_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */
84 &nf_ct_tcp_timeout_syn_recv, /* TCP_CONNTRACK_SYN_RECV, */
85 &nf_ct_tcp_timeout_established, /* TCP_CONNTRACK_ESTABLISHED, */
86 &nf_ct_tcp_timeout_fin_wait, /* TCP_CONNTRACK_FIN_WAIT, */
87 &nf_ct_tcp_timeout_close_wait, /* TCP_CONNTRACK_CLOSE_WAIT, */
88 &nf_ct_tcp_timeout_last_ack, /* TCP_CONNTRACK_LAST_ACK, */
89 &nf_ct_tcp_timeout_time_wait, /* TCP_CONNTRACK_TIME_WAIT, */
90 &nf_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */
91 NULL, /* TCP_CONNTRACK_LISTEN */
94 #define sNO TCP_CONNTRACK_NONE
95 #define sSS TCP_CONNTRACK_SYN_SENT
96 #define sSR TCP_CONNTRACK_SYN_RECV
97 #define sES TCP_CONNTRACK_ESTABLISHED
98 #define sFW TCP_CONNTRACK_FIN_WAIT
99 #define sCW TCP_CONNTRACK_CLOSE_WAIT
100 #define sLA TCP_CONNTRACK_LAST_ACK
101 #define sTW TCP_CONNTRACK_TIME_WAIT
102 #define sCL TCP_CONNTRACK_CLOSE
103 #define sLI TCP_CONNTRACK_LISTEN
104 #define sIV TCP_CONNTRACK_MAX
105 #define sIG TCP_CONNTRACK_IGNORE
107 /* What TCP flags are set from RST/SYN/FIN/ACK. */
118 * The TCP state transition table needs a few words...
120 * We are the man in the middle. All the packets go through us
121 * but might get lost in transit to the destination.
122 * It is assumed that the destinations can't receive segments
125 * The checked segment is in window, but our windows are *not*
126 * equivalent with the ones of the sender/receiver. We always
127 * try to guess the state of the current sender.
129 * The meaning of the states are:
131 * NONE: initial state
132 * SYN_SENT: SYN-only packet seen
133 * SYN_RECV: SYN-ACK packet seen
134 * ESTABLISHED: ACK packet seen
135 * FIN_WAIT: FIN packet seen
136 * CLOSE_WAIT: ACK seen (after FIN)
137 * LAST_ACK: FIN seen (after FIN)
138 * TIME_WAIT: last ACK seen
139 * CLOSE: closed connection
141 * LISTEN state is not used.
143 * Packets marked as IGNORED (sIG):
144 * if they may be either invalid or valid
145 * and the receiver may send back a connection
146 * closing RST or a SYN/ACK.
148 * Packets marked as INVALID (sIV):
149 * if they are invalid
150 * or we do not support the request (simultaneous open)
152 static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
155 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
156 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
158 * sNO -> sSS Initialize a new connection
159 * sSS -> sSS Retransmitted SYN
160 * sSR -> sIG Late retransmitted SYN?
161 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
162 * are errors. Receiver will reply with RST
163 * and close the connection.
164 * Or we are not in sync and hold a dead connection.
168 * sTW -> sSS Reopened connection (RFC 1122).
171 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
172 /*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
174 * A SYN/ACK from the client is always invalid:
175 * - either it tries to set up a simultaneous open, which is
177 * - or the firewall has just been inserted between the two hosts
178 * during the session set-up. The SYN will be retransmitted
179 * by the true client (or it'll time out).
181 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
182 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
184 * sNO -> sIV Too late and no reason to do anything...
185 * sSS -> sIV Client migth not send FIN in this state:
186 * we enforce waiting for a SYN/ACK reply first.
187 * sSR -> sFW Close started.
189 * sFW -> sLA FIN seen in both directions, waiting for
191 * Migth be a retransmitted FIN as well...
193 * sLA -> sLA Retransmitted FIN. Remain in the same state.
197 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
198 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
200 * sNO -> sES Assumed.
201 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
202 * sSR -> sES Established state is reached.
204 * sFW -> sCW Normal close request answered by ACK.
206 * sLA -> sTW Last ACK detected.
207 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
210 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
211 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
212 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
216 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
217 /*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
219 * sNO -> sIV Never reached.
220 * sSS -> sIV Simultaneous open, not supported
221 * sSR -> sIV Simultaneous open, not supported.
222 * sES -> sIV Server may not initiate a connection.
226 * sTW -> sIV Reopened connection, but server may not do it.
229 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
230 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
232 * sSS -> sSR Standard open.
233 * sSR -> sSR Retransmitted SYN/ACK.
234 * sES -> sIG Late retransmitted SYN/ACK?
235 * sFW -> sIG Might be SYN/ACK answering ignored SYN
241 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
242 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
244 * sSS -> sIV Server might not send FIN in this state.
245 * sSR -> sFW Close started.
247 * sFW -> sLA FIN seen in both directions.
249 * sLA -> sLA Retransmitted FIN.
253 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
254 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
256 * sSS -> sIG Might be a half-open connection.
257 * sSR -> sSR Might answer late resent SYN.
259 * sFW -> sCW Normal close request answered by ACK.
261 * sLA -> sTW Last ACK detected.
262 * sTW -> sTW Retransmitted last ACK.
265 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
266 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
267 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
271 static int tcp_pkt_to_tuple(const struct sk_buff *skb,
272 unsigned int dataoff,
273 struct nf_conntrack_tuple *tuple)
275 struct tcphdr _hdr, *hp;
277 /* Actually only need first 8 bytes. */
278 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
282 tuple->src.u.tcp.port = hp->source;
283 tuple->dst.u.tcp.port = hp->dest;
288 static int tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
289 const struct nf_conntrack_tuple *orig)
291 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
292 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
296 /* Print out the per-protocol part of the tuple. */
297 static int tcp_print_tuple(struct seq_file *s,
298 const struct nf_conntrack_tuple *tuple)
300 return seq_printf(s, "sport=%hu dport=%hu ",
301 ntohs(tuple->src.u.tcp.port),
302 ntohs(tuple->dst.u.tcp.port));
305 /* Print out the private part of the conntrack. */
306 static int tcp_print_conntrack(struct seq_file *s,
307 const struct nf_conn *conntrack)
309 enum tcp_conntrack state;
311 read_lock_bh(&tcp_lock);
312 state = conntrack->proto.tcp.state;
313 read_unlock_bh(&tcp_lock);
315 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
318 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
320 if (tcph->rst) return TCP_RST_SET;
321 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
322 else if (tcph->fin) return TCP_FIN_SET;
323 else if (tcph->ack) return TCP_ACK_SET;
324 else return TCP_NONE_SET;
327 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
328 in IP Filter' by Guido van Rooij.
330 http://www.nluug.nl/events/sane2000/papers.html
331 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
333 The boundaries and the conditions are changed according to RFC793:
334 the packet must intersect the window (i.e. segments may be
335 after the right or before the left edge) and thus receivers may ACK
336 segments after the right edge of the window.
338 td_maxend = max(sack + max(win,1)) seen in reply packets
339 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
340 td_maxwin += seq + len - sender.td_maxend
341 if seq + len > sender.td_maxend
342 td_end = max(seq + len) seen in sent packets
344 I. Upper bound for valid data: seq <= sender.td_maxend
345 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
346 III. Upper bound for valid ack: sack <= receiver.td_end
347 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
349 where sack is the highest right edge of sack block found in the packet.
351 The upper bound limit for a valid ack is not ignored -
352 we doesn't have to deal with fragments.
355 static inline __u32 segment_seq_plus_len(__u32 seq,
357 unsigned int dataoff,
360 /* XXX Should I use payload length field in IP/IPv6 header ?
362 return (seq + len - dataoff - tcph->doff*4
363 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
366 /* Fixme: what about big packets? */
367 #define MAXACKWINCONST 66000
368 #define MAXACKWINDOW(sender) \
369 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
373 * Simplified tcp_parse_options routine from tcp_input.c
375 static void tcp_options(const struct sk_buff *skb,
376 unsigned int dataoff,
378 struct ip_ct_tcp_state *state)
380 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
382 int length = (tcph->doff*4) - sizeof(struct tcphdr);
387 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
401 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
406 if (opsize < 2) /* "silly options" */
409 break; /* don't parse partial options */
411 if (opcode == TCPOPT_SACK_PERM
412 && opsize == TCPOLEN_SACK_PERM)
413 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
414 else if (opcode == TCPOPT_WINDOW
415 && opsize == TCPOLEN_WINDOW) {
416 state->td_scale = *(u_int8_t *)ptr;
418 if (state->td_scale > 14) {
420 state->td_scale = 14;
423 IP_CT_TCP_FLAG_WINDOW_SCALE;
431 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
432 struct tcphdr *tcph, __u32 *sack)
434 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
436 int length = (tcph->doff*4) - sizeof(struct tcphdr);
442 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
446 /* Fast path for timestamp-only option */
447 if (length == TCPOLEN_TSTAMP_ALIGNED*4
448 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
450 | (TCPOPT_TIMESTAMP << 8)
451 | TCPOLEN_TIMESTAMP))
461 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
466 if (opsize < 2) /* "silly options" */
469 break; /* don't parse partial options */
471 if (opcode == TCPOPT_SACK
472 && opsize >= (TCPOLEN_SACK_BASE
473 + TCPOLEN_SACK_PERBLOCK)
474 && !((opsize - TCPOLEN_SACK_BASE)
475 % TCPOLEN_SACK_PERBLOCK)) {
477 i < (opsize - TCPOLEN_SACK_BASE);
478 i += TCPOLEN_SACK_PERBLOCK) {
479 tmp = ntohl(*((__be32 *)(ptr+i)+1));
481 if (after(tmp, *sack))
492 static int tcp_in_window(struct nf_conn *ct,
493 struct ip_ct_tcp *state,
494 enum ip_conntrack_dir dir,
496 const struct sk_buff *skb,
497 unsigned int dataoff,
501 struct ip_ct_tcp_state *sender = &state->seen[dir];
502 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
503 struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
504 __u32 seq, ack, sack, end, win, swin;
508 * Get the required data from the packet.
510 seq = ntohl(tcph->seq);
511 ack = sack = ntohl(tcph->ack_seq);
512 win = ntohs(tcph->window);
513 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
515 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
516 tcp_sack(skb, dataoff, tcph, &sack);
518 pr_debug("tcp_in_window: START\n");
519 pr_debug("tcp_in_window: ");
520 NF_CT_DUMP_TUPLE(tuple);
521 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
522 seq, ack, sack, win, end);
523 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
524 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
525 sender->td_end, sender->td_maxend, sender->td_maxwin,
527 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
530 if (sender->td_end == 0) {
532 * Initialize sender data.
534 if (tcph->syn && tcph->ack) {
536 * Outgoing SYN-ACK in reply to a SYN.
539 sender->td_maxend = end;
540 sender->td_maxwin = (win == 0 ? 1 : win);
542 tcp_options(skb, dataoff, tcph, sender);
545 * Both sides must send the Window Scale option
546 * to enable window scaling in either direction.
548 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
549 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
551 receiver->td_scale = 0;
554 * We are in the middle of a connection,
555 * its history is lost for us.
556 * Let's try to use the data from the packet.
558 sender->td_end = end;
559 sender->td_maxwin = (win == 0 ? 1 : win);
560 sender->td_maxend = end + sender->td_maxwin;
562 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
563 && dir == IP_CT_DIR_ORIGINAL)
564 || (state->state == TCP_CONNTRACK_SYN_RECV
565 && dir == IP_CT_DIR_REPLY))
566 && after(end, sender->td_end)) {
568 * RFC 793: "if a TCP is reinitialized ... then it need
569 * not wait at all; it must only be sure to use sequence
570 * numbers larger than those recently used."
573 sender->td_maxend = end;
574 sender->td_maxwin = (win == 0 ? 1 : win);
576 tcp_options(skb, dataoff, tcph, sender);
581 * If there is no ACK, just pretend it was set and OK.
583 ack = sack = receiver->td_end;
584 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
585 (TCP_FLAG_ACK|TCP_FLAG_RST))
588 * Broken TCP stacks, that set ACK in RST packets as well
589 * with zero ack value.
591 ack = sack = receiver->td_end;
596 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
598 * Packets contains no data: we assume it is valid
599 * and check the ack value only.
600 * However RST segments are always validated by their
601 * SEQ number, except when seq == 0 (reset sent answering
604 seq = end = sender->td_end;
606 pr_debug("tcp_in_window: ");
607 NF_CT_DUMP_TUPLE(tuple);
608 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
609 seq, ack, sack, win, end);
610 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
611 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
612 sender->td_end, sender->td_maxend, sender->td_maxwin,
614 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
617 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
618 before(seq, sender->td_maxend + 1),
619 after(end, sender->td_end - receiver->td_maxwin - 1),
620 before(sack, receiver->td_end + 1),
621 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
623 if (before(seq, sender->td_maxend + 1) &&
624 after(end, sender->td_end - receiver->td_maxwin - 1) &&
625 before(sack, receiver->td_end + 1) &&
626 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
628 * Take into account window scaling (RFC 1323).
631 win <<= sender->td_scale;
634 * Update sender data.
636 swin = win + (sack - ack);
637 if (sender->td_maxwin < swin)
638 sender->td_maxwin = swin;
639 if (after(end, sender->td_end))
640 sender->td_end = end;
642 * Update receiver data.
644 if (after(end, sender->td_maxend))
645 receiver->td_maxwin += end - sender->td_maxend;
646 if (after(sack + win, receiver->td_maxend - 1)) {
647 receiver->td_maxend = sack + win;
649 receiver->td_maxend++;
653 * Check retransmissions.
655 if (index == TCP_ACK_SET) {
656 if (state->last_dir == dir
657 && state->last_seq == seq
658 && state->last_ack == ack
659 && state->last_end == end
660 && state->last_win == win)
663 state->last_dir = dir;
664 state->last_seq = seq;
665 state->last_ack = ack;
666 state->last_end = end;
667 state->last_win = win;
674 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
675 nf_ct_tcp_be_liberal)
677 if (!res && LOG_INVALID(IPPROTO_TCP))
678 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
680 before(seq, sender->td_maxend + 1) ?
681 after(end, sender->td_end - receiver->td_maxwin - 1) ?
682 before(sack, receiver->td_end + 1) ?
683 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
684 : "ACK is under the lower bound (possible overly delayed ACK)"
685 : "ACK is over the upper bound (ACKed data not seen yet)"
686 : "SEQ is under the lower bound (already ACKed data retransmitted)"
687 : "SEQ is over the upper bound (over the window of the receiver)");
690 pr_debug("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
691 "receiver end=%u maxend=%u maxwin=%u\n",
692 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
693 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
698 #ifdef CONFIG_NF_NAT_NEEDED
699 /* Update sender->td_end after NAT successfully mangled the packet */
700 /* Caller must linearize skb at tcp header. */
701 void nf_conntrack_tcp_update(struct sk_buff *skb,
702 unsigned int dataoff,
703 struct nf_conn *conntrack,
706 struct tcphdr *tcph = (void *)skb->data + dataoff;
707 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[dir];
708 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[!dir];
711 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
713 write_lock_bh(&tcp_lock);
715 * We have to worry for the ack in the reply packet only...
717 if (after(end, conntrack->proto.tcp.seen[dir].td_end))
718 conntrack->proto.tcp.seen[dir].td_end = end;
719 conntrack->proto.tcp.last_end = end;
720 write_unlock_bh(&tcp_lock);
721 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
722 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
723 sender->td_end, sender->td_maxend, sender->td_maxwin,
725 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
728 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
740 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
741 static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
749 [TH_FIN|TH_ACK|TH_URG] = 1,
754 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
755 static int tcp_error(struct sk_buff *skb,
756 unsigned int dataoff,
757 enum ip_conntrack_info *ctinfo,
759 unsigned int hooknum)
761 struct tcphdr _tcph, *th;
762 unsigned int tcplen = skb->len - dataoff;
765 /* Smaller that minimal TCP header? */
766 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
768 if (LOG_INVALID(IPPROTO_TCP))
769 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
770 "nf_ct_tcp: short packet ");
774 /* Not whole TCP header or malformed packet */
775 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
776 if (LOG_INVALID(IPPROTO_TCP))
777 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
778 "nf_ct_tcp: truncated/malformed packet ");
782 /* Checksum invalid? Ignore.
783 * We skip checking packets on the outgoing path
784 * because the checksum is assumed to be correct.
786 /* FIXME: Source route IP option packets --RR */
787 if (nf_conntrack_checksum && hooknum == NF_INET_PRE_ROUTING &&
788 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
789 if (LOG_INVALID(IPPROTO_TCP))
790 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
791 "nf_ct_tcp: bad TCP checksum ");
795 /* Check TCP flags. */
796 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
797 if (!tcp_valid_flags[tcpflags]) {
798 if (LOG_INVALID(IPPROTO_TCP))
799 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
800 "nf_ct_tcp: invalid TCP flag combination ");
807 /* Returns verdict for packet, or -1 for invalid. */
808 static int tcp_packet(struct nf_conn *conntrack,
809 const struct sk_buff *skb,
810 unsigned int dataoff,
811 enum ip_conntrack_info ctinfo,
813 unsigned int hooknum)
815 struct nf_conntrack_tuple *tuple;
816 enum tcp_conntrack new_state, old_state;
817 enum ip_conntrack_dir dir;
818 struct tcphdr *th, _tcph;
819 unsigned long timeout;
822 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
825 write_lock_bh(&tcp_lock);
826 old_state = conntrack->proto.tcp.state;
827 dir = CTINFO2DIR(ctinfo);
828 index = get_conntrack_index(th);
829 new_state = tcp_conntracks[dir][index][old_state];
830 tuple = &conntrack->tuplehash[dir].tuple;
833 case TCP_CONNTRACK_SYN_SENT:
834 if (old_state < TCP_CONNTRACK_TIME_WAIT)
836 if ((conntrack->proto.tcp.seen[!dir].flags &
837 IP_CT_TCP_FLAG_CLOSE_INIT)
838 || (conntrack->proto.tcp.last_dir == dir
839 && conntrack->proto.tcp.last_index == TCP_RST_SET)) {
840 /* Attempt to reopen a closed/aborted connection.
841 * Delete this connection and look up again. */
842 write_unlock_bh(&tcp_lock);
843 if (del_timer(&conntrack->timeout))
844 conntrack->timeout.function((unsigned long)
849 case TCP_CONNTRACK_IGNORE:
853 * b) SYN/ACK in REPLY
854 * c) ACK in reply direction after initial SYN in original.
856 if (index == TCP_SYNACK_SET
857 && conntrack->proto.tcp.last_index == TCP_SYN_SET
858 && conntrack->proto.tcp.last_dir != dir
859 && ntohl(th->ack_seq) ==
860 conntrack->proto.tcp.last_end) {
861 /* This SYN/ACK acknowledges a SYN that we earlier
862 * ignored as invalid. This means that the client and
863 * the server are both in sync, while the firewall is
864 * not. We kill this session and block the SYN/ACK so
865 * that the client cannot but retransmit its SYN and
866 * thus initiate a clean new session.
868 write_unlock_bh(&tcp_lock);
869 if (LOG_INVALID(IPPROTO_TCP))
870 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
871 "nf_ct_tcp: killing out of sync session ");
872 if (del_timer(&conntrack->timeout))
873 conntrack->timeout.function((unsigned long)
877 conntrack->proto.tcp.last_index = index;
878 conntrack->proto.tcp.last_dir = dir;
879 conntrack->proto.tcp.last_seq = ntohl(th->seq);
880 conntrack->proto.tcp.last_end =
881 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
883 write_unlock_bh(&tcp_lock);
884 if (LOG_INVALID(IPPROTO_TCP))
885 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
886 "nf_ct_tcp: invalid packed ignored ");
888 case TCP_CONNTRACK_MAX:
890 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
891 dir, get_conntrack_index(th), old_state);
892 write_unlock_bh(&tcp_lock);
893 if (LOG_INVALID(IPPROTO_TCP))
894 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
895 "nf_ct_tcp: invalid state ");
897 case TCP_CONNTRACK_CLOSE:
898 if (index == TCP_RST_SET
899 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)
900 && conntrack->proto.tcp.last_index == TCP_SYN_SET)
901 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
902 && conntrack->proto.tcp.last_index == TCP_ACK_SET))
903 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) {
904 /* RST sent to invalid SYN or ACK we had let through
905 * at a) and c) above:
907 * a) SYN was in window then
908 * c) we hold a half-open connection.
910 * Delete our connection entry.
911 * We skip window checking, because packet might ACK
912 * segments we ignored. */
915 /* Just fall through */
917 /* Keep compilers happy. */
921 if (!tcp_in_window(conntrack, &conntrack->proto.tcp, dir, index,
922 skb, dataoff, th, pf)) {
923 write_unlock_bh(&tcp_lock);
927 /* From now on we have got in-window packets */
928 conntrack->proto.tcp.last_index = index;
929 conntrack->proto.tcp.last_dir = dir;
931 pr_debug("tcp_conntracks: ");
932 NF_CT_DUMP_TUPLE(tuple);
933 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
934 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
935 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
936 old_state, new_state);
938 conntrack->proto.tcp.state = new_state;
939 if (old_state != new_state
940 && (new_state == TCP_CONNTRACK_FIN_WAIT
941 || new_state == TCP_CONNTRACK_CLOSE))
942 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
943 timeout = conntrack->proto.tcp.retrans >= nf_ct_tcp_max_retrans
944 && *tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans
945 ? nf_ct_tcp_timeout_max_retrans : *tcp_timeouts[new_state];
946 write_unlock_bh(&tcp_lock);
948 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
949 if (new_state != old_state)
950 nf_conntrack_event_cache(IPCT_PROTOINFO, skb);
952 if (!test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
953 /* If only reply is a RST, we can consider ourselves not to
954 have an established connection: this is a fairly common
955 problem case, so we can delete the conntrack
958 if (del_timer(&conntrack->timeout))
959 conntrack->timeout.function((unsigned long)
963 } else if (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
964 && (old_state == TCP_CONNTRACK_SYN_RECV
965 || old_state == TCP_CONNTRACK_ESTABLISHED)
966 && new_state == TCP_CONNTRACK_ESTABLISHED) {
967 /* Set ASSURED if we see see valid ack in ESTABLISHED
968 after SYN_RECV or a valid answer for a picked up
970 set_bit(IPS_ASSURED_BIT, &conntrack->status);
971 nf_conntrack_event_cache(IPCT_STATUS, skb);
973 nf_ct_refresh_acct(conntrack, ctinfo, skb, timeout);
978 /* Called when a new connection for this protocol found. */
979 static int tcp_new(struct nf_conn *conntrack,
980 const struct sk_buff *skb,
981 unsigned int dataoff)
983 enum tcp_conntrack new_state;
984 struct tcphdr *th, _tcph;
985 struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[0];
986 struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[1];
988 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
991 /* Don't need lock here: this conntrack not in circulation yet */
993 = tcp_conntracks[0][get_conntrack_index(th)]
994 [TCP_CONNTRACK_NONE];
996 /* Invalid: delete conntrack */
997 if (new_state >= TCP_CONNTRACK_MAX) {
998 pr_debug("nf_ct_tcp: invalid new deleting.\n");
1002 if (new_state == TCP_CONNTRACK_SYN_SENT) {
1004 conntrack->proto.tcp.seen[0].td_end =
1005 segment_seq_plus_len(ntohl(th->seq), skb->len,
1007 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1008 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1009 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1010 conntrack->proto.tcp.seen[0].td_maxend =
1011 conntrack->proto.tcp.seen[0].td_end;
1013 tcp_options(skb, dataoff, th, &conntrack->proto.tcp.seen[0]);
1014 conntrack->proto.tcp.seen[1].flags = 0;
1015 } else if (nf_ct_tcp_loose == 0) {
1016 /* Don't try to pick up connections. */
1020 * We are in the middle of a connection,
1021 * its history is lost for us.
1022 * Let's try to use the data from the packet.
1024 conntrack->proto.tcp.seen[0].td_end =
1025 segment_seq_plus_len(ntohl(th->seq), skb->len,
1027 conntrack->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1028 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1029 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1030 conntrack->proto.tcp.seen[0].td_maxend =
1031 conntrack->proto.tcp.seen[0].td_end +
1032 conntrack->proto.tcp.seen[0].td_maxwin;
1033 conntrack->proto.tcp.seen[0].td_scale = 0;
1035 /* We assume SACK and liberal window checking to handle
1037 conntrack->proto.tcp.seen[0].flags =
1038 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1039 IP_CT_TCP_FLAG_BE_LIBERAL;
1042 conntrack->proto.tcp.seen[1].td_end = 0;
1043 conntrack->proto.tcp.seen[1].td_maxend = 0;
1044 conntrack->proto.tcp.seen[1].td_maxwin = 1;
1045 conntrack->proto.tcp.seen[1].td_scale = 0;
1047 /* tcp_packet will set them */
1048 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE;
1049 conntrack->proto.tcp.last_index = TCP_NONE_SET;
1051 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1052 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1053 sender->td_end, sender->td_maxend, sender->td_maxwin,
1055 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1056 receiver->td_scale);
1060 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1062 #include <linux/netfilter/nfnetlink.h>
1063 #include <linux/netfilter/nfnetlink_conntrack.h>
1065 static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
1066 const struct nf_conn *ct)
1068 struct nlattr *nest_parms;
1069 struct nf_ct_tcp_flags tmp = {};
1071 read_lock_bh(&tcp_lock);
1072 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED);
1074 goto nla_put_failure;
1076 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state);
1078 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
1079 ct->proto.tcp.seen[0].td_scale);
1081 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY,
1082 ct->proto.tcp.seen[1].td_scale);
1084 tmp.flags = ct->proto.tcp.seen[0].flags;
1085 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1086 sizeof(struct nf_ct_tcp_flags), &tmp);
1088 tmp.flags = ct->proto.tcp.seen[1].flags;
1089 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1090 sizeof(struct nf_ct_tcp_flags), &tmp);
1091 read_unlock_bh(&tcp_lock);
1093 nla_nest_end(skb, nest_parms);
1098 read_unlock_bh(&tcp_lock);
1102 static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = {
1103 [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 },
1104 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 },
1105 [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 },
1106 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) },
1107 [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) },
1110 static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
1112 struct nlattr *attr = cda[CTA_PROTOINFO_TCP];
1113 struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
1116 /* updates could not contain anything about the private
1117 * protocol info, in that case skip the parsing */
1121 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr, tcp_nla_policy);
1125 if (!tb[CTA_PROTOINFO_TCP_STATE])
1128 write_lock_bh(&tcp_lock);
1129 ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]);
1131 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) {
1132 struct nf_ct_tcp_flags *attr =
1133 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]);
1134 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1135 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1138 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) {
1139 struct nf_ct_tcp_flags *attr =
1140 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]);
1141 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1142 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1145 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] &&
1146 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] &&
1147 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1148 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1149 ct->proto.tcp.seen[0].td_scale =
1150 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]);
1151 ct->proto.tcp.seen[1].td_scale =
1152 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]);
1154 write_unlock_bh(&tcp_lock);
1160 #ifdef CONFIG_SYSCTL
1161 static unsigned int tcp_sysctl_table_users;
1162 static struct ctl_table_header *tcp_sysctl_header;
1163 static struct ctl_table tcp_sysctl_table[] = {
1165 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1166 .data = &nf_ct_tcp_timeout_syn_sent,
1167 .maxlen = sizeof(unsigned int),
1169 .proc_handler = &proc_dointvec_jiffies,
1172 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1173 .data = &nf_ct_tcp_timeout_syn_recv,
1174 .maxlen = sizeof(unsigned int),
1176 .proc_handler = &proc_dointvec_jiffies,
1179 .procname = "nf_conntrack_tcp_timeout_established",
1180 .data = &nf_ct_tcp_timeout_established,
1181 .maxlen = sizeof(unsigned int),
1183 .proc_handler = &proc_dointvec_jiffies,
1186 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1187 .data = &nf_ct_tcp_timeout_fin_wait,
1188 .maxlen = sizeof(unsigned int),
1190 .proc_handler = &proc_dointvec_jiffies,
1193 .procname = "nf_conntrack_tcp_timeout_close_wait",
1194 .data = &nf_ct_tcp_timeout_close_wait,
1195 .maxlen = sizeof(unsigned int),
1197 .proc_handler = &proc_dointvec_jiffies,
1200 .procname = "nf_conntrack_tcp_timeout_last_ack",
1201 .data = &nf_ct_tcp_timeout_last_ack,
1202 .maxlen = sizeof(unsigned int),
1204 .proc_handler = &proc_dointvec_jiffies,
1207 .procname = "nf_conntrack_tcp_timeout_time_wait",
1208 .data = &nf_ct_tcp_timeout_time_wait,
1209 .maxlen = sizeof(unsigned int),
1211 .proc_handler = &proc_dointvec_jiffies,
1214 .procname = "nf_conntrack_tcp_timeout_close",
1215 .data = &nf_ct_tcp_timeout_close,
1216 .maxlen = sizeof(unsigned int),
1218 .proc_handler = &proc_dointvec_jiffies,
1221 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1222 .data = &nf_ct_tcp_timeout_max_retrans,
1223 .maxlen = sizeof(unsigned int),
1225 .proc_handler = &proc_dointvec_jiffies,
1228 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1229 .procname = "nf_conntrack_tcp_loose",
1230 .data = &nf_ct_tcp_loose,
1231 .maxlen = sizeof(unsigned int),
1233 .proc_handler = &proc_dointvec,
1236 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1237 .procname = "nf_conntrack_tcp_be_liberal",
1238 .data = &nf_ct_tcp_be_liberal,
1239 .maxlen = sizeof(unsigned int),
1241 .proc_handler = &proc_dointvec,
1244 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1245 .procname = "nf_conntrack_tcp_max_retrans",
1246 .data = &nf_ct_tcp_max_retrans,
1247 .maxlen = sizeof(unsigned int),
1249 .proc_handler = &proc_dointvec,
1256 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1257 static struct ctl_table tcp_compat_sysctl_table[] = {
1259 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1260 .data = &nf_ct_tcp_timeout_syn_sent,
1261 .maxlen = sizeof(unsigned int),
1263 .proc_handler = &proc_dointvec_jiffies,
1266 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1267 .data = &nf_ct_tcp_timeout_syn_recv,
1268 .maxlen = sizeof(unsigned int),
1270 .proc_handler = &proc_dointvec_jiffies,
1273 .procname = "ip_conntrack_tcp_timeout_established",
1274 .data = &nf_ct_tcp_timeout_established,
1275 .maxlen = sizeof(unsigned int),
1277 .proc_handler = &proc_dointvec_jiffies,
1280 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1281 .data = &nf_ct_tcp_timeout_fin_wait,
1282 .maxlen = sizeof(unsigned int),
1284 .proc_handler = &proc_dointvec_jiffies,
1287 .procname = "ip_conntrack_tcp_timeout_close_wait",
1288 .data = &nf_ct_tcp_timeout_close_wait,
1289 .maxlen = sizeof(unsigned int),
1291 .proc_handler = &proc_dointvec_jiffies,
1294 .procname = "ip_conntrack_tcp_timeout_last_ack",
1295 .data = &nf_ct_tcp_timeout_last_ack,
1296 .maxlen = sizeof(unsigned int),
1298 .proc_handler = &proc_dointvec_jiffies,
1301 .procname = "ip_conntrack_tcp_timeout_time_wait",
1302 .data = &nf_ct_tcp_timeout_time_wait,
1303 .maxlen = sizeof(unsigned int),
1305 .proc_handler = &proc_dointvec_jiffies,
1308 .procname = "ip_conntrack_tcp_timeout_close",
1309 .data = &nf_ct_tcp_timeout_close,
1310 .maxlen = sizeof(unsigned int),
1312 .proc_handler = &proc_dointvec_jiffies,
1315 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1316 .data = &nf_ct_tcp_timeout_max_retrans,
1317 .maxlen = sizeof(unsigned int),
1319 .proc_handler = &proc_dointvec_jiffies,
1322 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1323 .procname = "ip_conntrack_tcp_loose",
1324 .data = &nf_ct_tcp_loose,
1325 .maxlen = sizeof(unsigned int),
1327 .proc_handler = &proc_dointvec,
1330 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1331 .procname = "ip_conntrack_tcp_be_liberal",
1332 .data = &nf_ct_tcp_be_liberal,
1333 .maxlen = sizeof(unsigned int),
1335 .proc_handler = &proc_dointvec,
1338 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1339 .procname = "ip_conntrack_tcp_max_retrans",
1340 .data = &nf_ct_tcp_max_retrans,
1341 .maxlen = sizeof(unsigned int),
1343 .proc_handler = &proc_dointvec,
1349 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1350 #endif /* CONFIG_SYSCTL */
1352 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
1355 .l4proto = IPPROTO_TCP,
1357 .pkt_to_tuple = tcp_pkt_to_tuple,
1358 .invert_tuple = tcp_invert_tuple,
1359 .print_tuple = tcp_print_tuple,
1360 .print_conntrack = tcp_print_conntrack,
1361 .packet = tcp_packet,
1364 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1365 .to_nlattr = tcp_to_nlattr,
1366 .from_nlattr = nlattr_to_tcp,
1367 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1368 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1369 .nla_policy = nf_ct_port_nla_policy,
1371 #ifdef CONFIG_SYSCTL
1372 .ctl_table_users = &tcp_sysctl_table_users,
1373 .ctl_table_header = &tcp_sysctl_header,
1374 .ctl_table = tcp_sysctl_table,
1375 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1376 .ctl_compat_table = tcp_compat_sysctl_table,
1380 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1382 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
1384 .l3proto = PF_INET6,
1385 .l4proto = IPPROTO_TCP,
1387 .pkt_to_tuple = tcp_pkt_to_tuple,
1388 .invert_tuple = tcp_invert_tuple,
1389 .print_tuple = tcp_print_tuple,
1390 .print_conntrack = tcp_print_conntrack,
1391 .packet = tcp_packet,
1394 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1395 .to_nlattr = tcp_to_nlattr,
1396 .from_nlattr = nlattr_to_tcp,
1397 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1398 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1399 .nla_policy = nf_ct_port_nla_policy,
1401 #ifdef CONFIG_SYSCTL
1402 .ctl_table_users = &tcp_sysctl_table_users,
1403 .ctl_table_header = &tcp_sysctl_header,
1404 .ctl_table = tcp_sysctl_table,
1407 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);