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 ct->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 /* 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;
72 static unsigned int tcp_timeouts[TCP_CONNTRACK_MAX] __read_mostly = {
73 [TCP_CONNTRACK_SYN_SENT] = 2 MINS,
74 [TCP_CONNTRACK_SYN_RECV] = 60 SECS,
75 [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS,
76 [TCP_CONNTRACK_FIN_WAIT] = 2 MINS,
77 [TCP_CONNTRACK_CLOSE_WAIT] = 60 SECS,
78 [TCP_CONNTRACK_LAST_ACK] = 30 SECS,
79 [TCP_CONNTRACK_TIME_WAIT] = 2 MINS,
80 [TCP_CONNTRACK_CLOSE] = 10 SECS,
83 #define sNO TCP_CONNTRACK_NONE
84 #define sSS TCP_CONNTRACK_SYN_SENT
85 #define sSR TCP_CONNTRACK_SYN_RECV
86 #define sES TCP_CONNTRACK_ESTABLISHED
87 #define sFW TCP_CONNTRACK_FIN_WAIT
88 #define sCW TCP_CONNTRACK_CLOSE_WAIT
89 #define sLA TCP_CONNTRACK_LAST_ACK
90 #define sTW TCP_CONNTRACK_TIME_WAIT
91 #define sCL TCP_CONNTRACK_CLOSE
92 #define sLI TCP_CONNTRACK_LISTEN
93 #define sIV TCP_CONNTRACK_MAX
94 #define sIG TCP_CONNTRACK_IGNORE
96 /* What TCP flags are set from RST/SYN/FIN/ACK. */
107 * The TCP state transition table needs a few words...
109 * We are the man in the middle. All the packets go through us
110 * but might get lost in transit to the destination.
111 * It is assumed that the destinations can't receive segments
114 * The checked segment is in window, but our windows are *not*
115 * equivalent with the ones of the sender/receiver. We always
116 * try to guess the state of the current sender.
118 * The meaning of the states are:
120 * NONE: initial state
121 * SYN_SENT: SYN-only packet seen
122 * SYN_RECV: SYN-ACK packet seen
123 * ESTABLISHED: ACK packet seen
124 * FIN_WAIT: FIN packet seen
125 * CLOSE_WAIT: ACK seen (after FIN)
126 * LAST_ACK: FIN seen (after FIN)
127 * TIME_WAIT: last ACK seen
128 * CLOSE: closed connection
130 * LISTEN state is not used.
132 * Packets marked as IGNORED (sIG):
133 * if they may be either invalid or valid
134 * and the receiver may send back a connection
135 * closing RST or a SYN/ACK.
137 * Packets marked as INVALID (sIV):
138 * if they are invalid
139 * or we do not support the request (simultaneous open)
141 static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
144 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
145 /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sIV },
147 * sNO -> sSS Initialize a new connection
148 * sSS -> sSS Retransmitted SYN
149 * sSR -> sIG Late retransmitted SYN?
150 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
151 * are errors. Receiver will reply with RST
152 * and close the connection.
153 * Or we are not in sync and hold a dead connection.
157 * sTW -> sSS Reopened connection (RFC 1122).
160 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
161 /*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
163 * A SYN/ACK from the client is always invalid:
164 * - either it tries to set up a simultaneous open, which is
166 * - or the firewall has just been inserted between the two hosts
167 * during the session set-up. The SYN will be retransmitted
168 * by the true client (or it'll time out).
170 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
171 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
173 * sNO -> sIV Too late and no reason to do anything...
174 * sSS -> sIV Client migth not send FIN in this state:
175 * we enforce waiting for a SYN/ACK reply first.
176 * sSR -> sFW Close started.
178 * sFW -> sLA FIN seen in both directions, waiting for
180 * Migth be a retransmitted FIN as well...
182 * sLA -> sLA Retransmitted FIN. Remain in the same state.
186 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
187 /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV },
189 * sNO -> sES Assumed.
190 * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet.
191 * sSR -> sES Established state is reached.
193 * sFW -> sCW Normal close request answered by ACK.
195 * sLA -> sTW Last ACK detected.
196 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
199 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
200 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
201 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
205 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
206 /*syn*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
208 * sNO -> sIV Never reached.
209 * sSS -> sIV Simultaneous open, not supported
210 * sSR -> sIV Simultaneous open, not supported.
211 * sES -> sIV Server may not initiate a connection.
215 * sTW -> sIV Reopened connection, but server may not do it.
218 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
219 /*synack*/ { sIV, sSR, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIV },
221 * sSS -> sSR Standard open.
222 * sSR -> sSR Retransmitted SYN/ACK.
223 * sES -> sIG Late retransmitted SYN/ACK?
224 * sFW -> sIG Might be SYN/ACK answering ignored SYN
230 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
231 /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
233 * sSS -> sIV Server might not send FIN in this state.
234 * sSR -> sFW Close started.
236 * sFW -> sLA FIN seen in both directions.
238 * sLA -> sLA Retransmitted FIN.
242 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
243 /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIV },
245 * sSS -> sIG Might be a half-open connection.
246 * sSR -> sSR Might answer late resent SYN.
248 * sFW -> sCW Normal close request answered by ACK.
250 * sLA -> sTW Last ACK detected.
251 * sTW -> sTW Retransmitted last ACK.
254 /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
255 /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
256 /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
260 static int tcp_pkt_to_tuple(const struct sk_buff *skb,
261 unsigned int dataoff,
262 struct nf_conntrack_tuple *tuple)
264 struct tcphdr _hdr, *hp;
266 /* Actually only need first 8 bytes. */
267 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
271 tuple->src.u.tcp.port = hp->source;
272 tuple->dst.u.tcp.port = hp->dest;
277 static int tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
278 const struct nf_conntrack_tuple *orig)
280 tuple->src.u.tcp.port = orig->dst.u.tcp.port;
281 tuple->dst.u.tcp.port = orig->src.u.tcp.port;
285 /* Print out the per-protocol part of the tuple. */
286 static int tcp_print_tuple(struct seq_file *s,
287 const struct nf_conntrack_tuple *tuple)
289 return seq_printf(s, "sport=%hu dport=%hu ",
290 ntohs(tuple->src.u.tcp.port),
291 ntohs(tuple->dst.u.tcp.port));
294 /* Print out the private part of the conntrack. */
295 static int tcp_print_conntrack(struct seq_file *s, const struct nf_conn *ct)
297 enum tcp_conntrack state;
299 read_lock_bh(&tcp_lock);
300 state = ct->proto.tcp.state;
301 read_unlock_bh(&tcp_lock);
303 return seq_printf(s, "%s ", tcp_conntrack_names[state]);
306 static unsigned int get_conntrack_index(const struct tcphdr *tcph)
308 if (tcph->rst) return TCP_RST_SET;
309 else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET);
310 else if (tcph->fin) return TCP_FIN_SET;
311 else if (tcph->ack) return TCP_ACK_SET;
312 else return TCP_NONE_SET;
315 /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
316 in IP Filter' by Guido van Rooij.
318 http://www.nluug.nl/events/sane2000/papers.html
319 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
321 The boundaries and the conditions are changed according to RFC793:
322 the packet must intersect the window (i.e. segments may be
323 after the right or before the left edge) and thus receivers may ACK
324 segments after the right edge of the window.
326 td_maxend = max(sack + max(win,1)) seen in reply packets
327 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
328 td_maxwin += seq + len - sender.td_maxend
329 if seq + len > sender.td_maxend
330 td_end = max(seq + len) seen in sent packets
332 I. Upper bound for valid data: seq <= sender.td_maxend
333 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
334 III. Upper bound for valid ack: sack <= receiver.td_end
335 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
337 where sack is the highest right edge of sack block found in the packet.
339 The upper bound limit for a valid ack is not ignored -
340 we doesn't have to deal with fragments.
343 static inline __u32 segment_seq_plus_len(__u32 seq,
345 unsigned int dataoff,
348 /* XXX Should I use payload length field in IP/IPv6 header ?
350 return (seq + len - dataoff - tcph->doff*4
351 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
354 /* Fixme: what about big packets? */
355 #define MAXACKWINCONST 66000
356 #define MAXACKWINDOW(sender) \
357 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
361 * Simplified tcp_parse_options routine from tcp_input.c
363 static void tcp_options(const struct sk_buff *skb,
364 unsigned int dataoff,
366 struct ip_ct_tcp_state *state)
368 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
370 int length = (tcph->doff*4) - sizeof(struct tcphdr);
375 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
389 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
394 if (opsize < 2) /* "silly options" */
397 break; /* don't parse partial options */
399 if (opcode == TCPOPT_SACK_PERM
400 && opsize == TCPOLEN_SACK_PERM)
401 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
402 else if (opcode == TCPOPT_WINDOW
403 && opsize == TCPOLEN_WINDOW) {
404 state->td_scale = *(u_int8_t *)ptr;
406 if (state->td_scale > 14) {
408 state->td_scale = 14;
411 IP_CT_TCP_FLAG_WINDOW_SCALE;
419 static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
420 struct tcphdr *tcph, __u32 *sack)
422 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
424 int length = (tcph->doff*4) - sizeof(struct tcphdr);
430 ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
434 /* Fast path for timestamp-only option */
435 if (length == TCPOLEN_TSTAMP_ALIGNED*4
436 && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
438 | (TCPOPT_TIMESTAMP << 8)
439 | TCPOLEN_TIMESTAMP))
449 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
454 if (opsize < 2) /* "silly options" */
457 break; /* don't parse partial options */
459 if (opcode == TCPOPT_SACK
460 && opsize >= (TCPOLEN_SACK_BASE
461 + TCPOLEN_SACK_PERBLOCK)
462 && !((opsize - TCPOLEN_SACK_BASE)
463 % TCPOLEN_SACK_PERBLOCK)) {
465 i < (opsize - TCPOLEN_SACK_BASE);
466 i += TCPOLEN_SACK_PERBLOCK) {
467 tmp = ntohl(*((__be32 *)(ptr+i)+1));
469 if (after(tmp, *sack))
480 static int tcp_in_window(struct nf_conn *ct,
481 struct ip_ct_tcp *state,
482 enum ip_conntrack_dir dir,
484 const struct sk_buff *skb,
485 unsigned int dataoff,
489 struct ip_ct_tcp_state *sender = &state->seen[dir];
490 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
491 struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
492 __u32 seq, ack, sack, end, win, swin;
496 * Get the required data from the packet.
498 seq = ntohl(tcph->seq);
499 ack = sack = ntohl(tcph->ack_seq);
500 win = ntohs(tcph->window);
501 end = segment_seq_plus_len(seq, skb->len, dataoff, tcph);
503 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
504 tcp_sack(skb, dataoff, tcph, &sack);
506 pr_debug("tcp_in_window: START\n");
507 pr_debug("tcp_in_window: ");
508 NF_CT_DUMP_TUPLE(tuple);
509 pr_debug("seq=%u ack=%u sack=%u win=%u end=%u\n",
510 seq, ack, sack, win, end);
511 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
512 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
513 sender->td_end, sender->td_maxend, sender->td_maxwin,
515 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
518 if (sender->td_end == 0) {
520 * Initialize sender data.
522 if (tcph->syn && tcph->ack) {
524 * Outgoing SYN-ACK in reply to a SYN.
527 sender->td_maxend = end;
528 sender->td_maxwin = (win == 0 ? 1 : win);
530 tcp_options(skb, dataoff, tcph, sender);
533 * Both sides must send the Window Scale option
534 * to enable window scaling in either direction.
536 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
537 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
539 receiver->td_scale = 0;
542 * We are in the middle of a connection,
543 * its history is lost for us.
544 * Let's try to use the data from the packet.
546 sender->td_end = end;
547 sender->td_maxwin = (win == 0 ? 1 : win);
548 sender->td_maxend = end + sender->td_maxwin;
550 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
551 && dir == IP_CT_DIR_ORIGINAL)
552 || (state->state == TCP_CONNTRACK_SYN_RECV
553 && dir == IP_CT_DIR_REPLY))
554 && after(end, sender->td_end)) {
556 * RFC 793: "if a TCP is reinitialized ... then it need
557 * not wait at all; it must only be sure to use sequence
558 * numbers larger than those recently used."
561 sender->td_maxend = end;
562 sender->td_maxwin = (win == 0 ? 1 : win);
564 tcp_options(skb, dataoff, tcph, sender);
569 * If there is no ACK, just pretend it was set and OK.
571 ack = sack = receiver->td_end;
572 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
573 (TCP_FLAG_ACK|TCP_FLAG_RST))
576 * Broken TCP stacks, that set ACK in RST packets as well
577 * with zero ack value.
579 ack = sack = receiver->td_end;
584 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
586 * Packets contains no data: we assume it is valid
587 * and check the ack value only.
588 * However RST segments are always validated by their
589 * SEQ number, except when seq == 0 (reset sent answering
592 seq = end = sender->td_end;
594 pr_debug("tcp_in_window: ");
595 NF_CT_DUMP_TUPLE(tuple);
596 pr_debug("seq=%u ack=%u sack =%u win=%u end=%u\n",
597 seq, ack, sack, win, end);
598 pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
599 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
600 sender->td_end, sender->td_maxend, sender->td_maxwin,
602 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
605 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
606 before(seq, sender->td_maxend + 1),
607 after(end, sender->td_end - receiver->td_maxwin - 1),
608 before(sack, receiver->td_end + 1),
609 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
611 if (before(seq, sender->td_maxend + 1) &&
612 after(end, sender->td_end - receiver->td_maxwin - 1) &&
613 before(sack, receiver->td_end + 1) &&
614 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
616 * Take into account window scaling (RFC 1323).
619 win <<= sender->td_scale;
622 * Update sender data.
624 swin = win + (sack - ack);
625 if (sender->td_maxwin < swin)
626 sender->td_maxwin = swin;
627 if (after(end, sender->td_end))
628 sender->td_end = end;
630 * Update receiver data.
632 if (after(end, sender->td_maxend))
633 receiver->td_maxwin += end - sender->td_maxend;
634 if (after(sack + win, receiver->td_maxend - 1)) {
635 receiver->td_maxend = sack + win;
637 receiver->td_maxend++;
641 * Check retransmissions.
643 if (index == TCP_ACK_SET) {
644 if (state->last_dir == dir
645 && state->last_seq == seq
646 && state->last_ack == ack
647 && state->last_end == end
648 && state->last_win == win)
651 state->last_dir = dir;
652 state->last_seq = seq;
653 state->last_ack = ack;
654 state->last_end = end;
655 state->last_win = win;
662 if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL ||
663 nf_ct_tcp_be_liberal)
665 if (!res && LOG_INVALID(IPPROTO_TCP))
666 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
668 before(seq, sender->td_maxend + 1) ?
669 after(end, sender->td_end - receiver->td_maxwin - 1) ?
670 before(sack, receiver->td_end + 1) ?
671 after(ack, receiver->td_end - MAXACKWINDOW(sender)) ? "BUG"
672 : "ACK is under the lower bound (possible overly delayed ACK)"
673 : "ACK is over the upper bound (ACKed data not seen yet)"
674 : "SEQ is under the lower bound (already ACKed data retransmitted)"
675 : "SEQ is over the upper bound (over the window of the receiver)");
678 pr_debug("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
679 "receiver end=%u maxend=%u maxwin=%u\n",
680 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
681 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
686 #ifdef CONFIG_NF_NAT_NEEDED
687 /* Update sender->td_end after NAT successfully mangled the packet */
688 /* Caller must linearize skb at tcp header. */
689 void nf_conntrack_tcp_update(struct sk_buff *skb,
690 unsigned int dataoff,
694 struct tcphdr *tcph = (void *)skb->data + dataoff;
695 struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[dir];
696 struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[!dir];
699 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, dataoff, tcph);
701 write_lock_bh(&tcp_lock);
703 * We have to worry for the ack in the reply packet only...
705 if (after(end, ct->proto.tcp.seen[dir].td_end))
706 ct->proto.tcp.seen[dir].td_end = end;
707 ct->proto.tcp.last_end = end;
708 write_unlock_bh(&tcp_lock);
709 pr_debug("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
710 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
711 sender->td_end, sender->td_maxend, sender->td_maxwin,
713 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
716 EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);
728 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
729 static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
737 [TH_FIN|TH_ACK|TH_URG] = 1,
742 /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
743 static int tcp_error(struct sk_buff *skb,
744 unsigned int dataoff,
745 enum ip_conntrack_info *ctinfo,
747 unsigned int hooknum)
749 struct tcphdr _tcph, *th;
750 unsigned int tcplen = skb->len - dataoff;
753 /* Smaller that minimal TCP header? */
754 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
756 if (LOG_INVALID(IPPROTO_TCP))
757 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
758 "nf_ct_tcp: short packet ");
762 /* Not whole TCP header or malformed packet */
763 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
764 if (LOG_INVALID(IPPROTO_TCP))
765 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
766 "nf_ct_tcp: truncated/malformed packet ");
770 /* Checksum invalid? Ignore.
771 * We skip checking packets on the outgoing path
772 * because the checksum is assumed to be correct.
774 /* FIXME: Source route IP option packets --RR */
775 if (nf_conntrack_checksum && hooknum == NF_INET_PRE_ROUTING &&
776 nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) {
777 if (LOG_INVALID(IPPROTO_TCP))
778 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
779 "nf_ct_tcp: bad TCP checksum ");
783 /* Check TCP flags. */
784 tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
785 if (!tcp_valid_flags[tcpflags]) {
786 if (LOG_INVALID(IPPROTO_TCP))
787 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
788 "nf_ct_tcp: invalid TCP flag combination ");
795 /* Returns verdict for packet, or -1 for invalid. */
796 static int tcp_packet(struct nf_conn *ct,
797 const struct sk_buff *skb,
798 unsigned int dataoff,
799 enum ip_conntrack_info ctinfo,
801 unsigned int hooknum)
803 struct nf_conntrack_tuple *tuple;
804 enum tcp_conntrack new_state, old_state;
805 enum ip_conntrack_dir dir;
806 struct tcphdr *th, _tcph;
807 unsigned long timeout;
810 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
813 write_lock_bh(&tcp_lock);
814 old_state = ct->proto.tcp.state;
815 dir = CTINFO2DIR(ctinfo);
816 index = get_conntrack_index(th);
817 new_state = tcp_conntracks[dir][index][old_state];
818 tuple = &ct->tuplehash[dir].tuple;
821 case TCP_CONNTRACK_SYN_SENT:
822 if (old_state < TCP_CONNTRACK_TIME_WAIT)
824 if ((ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_CLOSE_INIT)
825 || (ct->proto.tcp.last_dir == dir
826 && ct->proto.tcp.last_index == TCP_RST_SET)) {
827 /* Attempt to reopen a closed/aborted connection.
828 * Delete this connection and look up again. */
829 write_unlock_bh(&tcp_lock);
830 if (del_timer(&ct->timeout))
831 ct->timeout.function((unsigned long)ct);
835 case TCP_CONNTRACK_IGNORE:
839 * b) SYN/ACK in REPLY
840 * c) ACK in reply direction after initial SYN in original.
842 if (index == TCP_SYNACK_SET
843 && ct->proto.tcp.last_index == TCP_SYN_SET
844 && ct->proto.tcp.last_dir != dir
845 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
846 /* This SYN/ACK acknowledges a SYN that we earlier
847 * ignored as invalid. This means that the client and
848 * the server are both in sync, while the firewall is
849 * not. We kill this session and block the SYN/ACK so
850 * that the client cannot but retransmit its SYN and
851 * thus initiate a clean new session.
853 write_unlock_bh(&tcp_lock);
854 if (LOG_INVALID(IPPROTO_TCP))
855 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
856 "nf_ct_tcp: killing out of sync session ");
857 if (del_timer(&ct->timeout))
858 ct->timeout.function((unsigned long)ct);
861 ct->proto.tcp.last_index = index;
862 ct->proto.tcp.last_dir = dir;
863 ct->proto.tcp.last_seq = ntohl(th->seq);
864 ct->proto.tcp.last_end =
865 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);
867 write_unlock_bh(&tcp_lock);
868 if (LOG_INVALID(IPPROTO_TCP))
869 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
870 "nf_ct_tcp: invalid packed ignored ");
872 case TCP_CONNTRACK_MAX:
874 pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",
875 dir, get_conntrack_index(th), old_state);
876 write_unlock_bh(&tcp_lock);
877 if (LOG_INVALID(IPPROTO_TCP))
878 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
879 "nf_ct_tcp: invalid state ");
881 case TCP_CONNTRACK_CLOSE:
882 if (index == TCP_RST_SET
883 && ((test_bit(IPS_SEEN_REPLY_BIT, &ct->status)
884 && ct->proto.tcp.last_index == TCP_SYN_SET)
885 || (!test_bit(IPS_ASSURED_BIT, &ct->status)
886 && ct->proto.tcp.last_index == TCP_ACK_SET))
887 && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
888 /* RST sent to invalid SYN or ACK we had let through
889 * at a) and c) above:
891 * a) SYN was in window then
892 * c) we hold a half-open connection.
894 * Delete our connection entry.
895 * We skip window checking, because packet might ACK
896 * segments we ignored. */
899 /* Just fall through */
901 /* Keep compilers happy. */
905 if (!tcp_in_window(ct, &ct->proto.tcp, dir, index,
906 skb, dataoff, th, pf)) {
907 write_unlock_bh(&tcp_lock);
911 /* From now on we have got in-window packets */
912 ct->proto.tcp.last_index = index;
913 ct->proto.tcp.last_dir = dir;
915 pr_debug("tcp_conntracks: ");
916 NF_CT_DUMP_TUPLE(tuple);
917 pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n",
918 (th->syn ? 1 : 0), (th->ack ? 1 : 0),
919 (th->fin ? 1 : 0), (th->rst ? 1 : 0),
920 old_state, new_state);
922 ct->proto.tcp.state = new_state;
923 if (old_state != new_state
924 && (new_state == TCP_CONNTRACK_FIN_WAIT
925 || new_state == TCP_CONNTRACK_CLOSE))
926 ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
927 timeout = ct->proto.tcp.retrans >= nf_ct_tcp_max_retrans
928 && tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans
929 ? nf_ct_tcp_timeout_max_retrans : tcp_timeouts[new_state];
930 write_unlock_bh(&tcp_lock);
932 nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
933 if (new_state != old_state)
934 nf_conntrack_event_cache(IPCT_PROTOINFO, skb);
936 if (!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
937 /* If only reply is a RST, we can consider ourselves not to
938 have an established connection: this is a fairly common
939 problem case, so we can delete the conntrack
942 if (del_timer(&ct->timeout))
943 ct->timeout.function((unsigned long)ct);
946 } else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
947 && (old_state == TCP_CONNTRACK_SYN_RECV
948 || old_state == TCP_CONNTRACK_ESTABLISHED)
949 && new_state == TCP_CONNTRACK_ESTABLISHED) {
950 /* Set ASSURED if we see see valid ack in ESTABLISHED
951 after SYN_RECV or a valid answer for a picked up
953 set_bit(IPS_ASSURED_BIT, &ct->status);
954 nf_conntrack_event_cache(IPCT_STATUS, skb);
956 nf_ct_refresh_acct(ct, ctinfo, skb, timeout);
961 /* Called when a new connection for this protocol found. */
962 static int tcp_new(struct nf_conn *ct,
963 const struct sk_buff *skb,
964 unsigned int dataoff)
966 enum tcp_conntrack new_state;
967 struct tcphdr *th, _tcph;
968 struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0];
969 struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1];
971 th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph);
974 /* Don't need lock here: this conntrack not in circulation yet */
976 = tcp_conntracks[0][get_conntrack_index(th)]
977 [TCP_CONNTRACK_NONE];
979 /* Invalid: delete conntrack */
980 if (new_state >= TCP_CONNTRACK_MAX) {
981 pr_debug("nf_ct_tcp: invalid new deleting.\n");
985 if (new_state == TCP_CONNTRACK_SYN_SENT) {
987 ct->proto.tcp.seen[0].td_end =
988 segment_seq_plus_len(ntohl(th->seq), skb->len,
990 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
991 if (ct->proto.tcp.seen[0].td_maxwin == 0)
992 ct->proto.tcp.seen[0].td_maxwin = 1;
993 ct->proto.tcp.seen[0].td_maxend =
994 ct->proto.tcp.seen[0].td_end;
996 tcp_options(skb, dataoff, th, &ct->proto.tcp.seen[0]);
997 ct->proto.tcp.seen[1].flags = 0;
998 } else if (nf_ct_tcp_loose == 0) {
999 /* Don't try to pick up connections. */
1003 * We are in the middle of a connection,
1004 * its history is lost for us.
1005 * Let's try to use the data from the packet.
1007 ct->proto.tcp.seen[0].td_end =
1008 segment_seq_plus_len(ntohl(th->seq), skb->len,
1010 ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window);
1011 if (ct->proto.tcp.seen[0].td_maxwin == 0)
1012 ct->proto.tcp.seen[0].td_maxwin = 1;
1013 ct->proto.tcp.seen[0].td_maxend =
1014 ct->proto.tcp.seen[0].td_end +
1015 ct->proto.tcp.seen[0].td_maxwin;
1016 ct->proto.tcp.seen[0].td_scale = 0;
1018 /* We assume SACK and liberal window checking to handle
1020 ct->proto.tcp.seen[0].flags =
1021 ct->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1022 IP_CT_TCP_FLAG_BE_LIBERAL;
1025 ct->proto.tcp.seen[1].td_end = 0;
1026 ct->proto.tcp.seen[1].td_maxend = 0;
1027 ct->proto.tcp.seen[1].td_maxwin = 1;
1028 ct->proto.tcp.seen[1].td_scale = 0;
1030 /* tcp_packet will set them */
1031 ct->proto.tcp.state = TCP_CONNTRACK_NONE;
1032 ct->proto.tcp.last_index = TCP_NONE_SET;
1034 pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1035 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1036 sender->td_end, sender->td_maxend, sender->td_maxwin,
1038 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1039 receiver->td_scale);
1043 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1045 #include <linux/netfilter/nfnetlink.h>
1046 #include <linux/netfilter/nfnetlink_conntrack.h>
1048 static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
1049 const struct nf_conn *ct)
1051 struct nlattr *nest_parms;
1052 struct nf_ct_tcp_flags tmp = {};
1054 read_lock_bh(&tcp_lock);
1055 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED);
1057 goto nla_put_failure;
1059 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state);
1061 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
1062 ct->proto.tcp.seen[0].td_scale);
1064 NLA_PUT_U8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY,
1065 ct->proto.tcp.seen[1].td_scale);
1067 tmp.flags = ct->proto.tcp.seen[0].flags;
1068 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
1069 sizeof(struct nf_ct_tcp_flags), &tmp);
1071 tmp.flags = ct->proto.tcp.seen[1].flags;
1072 NLA_PUT(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY,
1073 sizeof(struct nf_ct_tcp_flags), &tmp);
1074 read_unlock_bh(&tcp_lock);
1076 nla_nest_end(skb, nest_parms);
1081 read_unlock_bh(&tcp_lock);
1085 static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = {
1086 [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 },
1087 [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 },
1088 [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 },
1089 [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) },
1090 [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) },
1093 static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
1095 struct nlattr *pattr = cda[CTA_PROTOINFO_TCP];
1096 struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
1099 /* updates could not contain anything about the private
1100 * protocol info, in that case skip the parsing */
1104 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, tcp_nla_policy);
1108 if (!tb[CTA_PROTOINFO_TCP_STATE])
1111 write_lock_bh(&tcp_lock);
1112 ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]);
1114 if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) {
1115 struct nf_ct_tcp_flags *attr =
1116 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]);
1117 ct->proto.tcp.seen[0].flags &= ~attr->mask;
1118 ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask;
1121 if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) {
1122 struct nf_ct_tcp_flags *attr =
1123 nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]);
1124 ct->proto.tcp.seen[1].flags &= ~attr->mask;
1125 ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask;
1128 if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] &&
1129 tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] &&
1130 ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
1131 ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {
1132 ct->proto.tcp.seen[0].td_scale =
1133 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]);
1134 ct->proto.tcp.seen[1].td_scale =
1135 nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]);
1137 write_unlock_bh(&tcp_lock);
1143 #ifdef CONFIG_SYSCTL
1144 static unsigned int tcp_sysctl_table_users;
1145 static struct ctl_table_header *tcp_sysctl_header;
1146 static struct ctl_table tcp_sysctl_table[] = {
1148 .procname = "nf_conntrack_tcp_timeout_syn_sent",
1149 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1150 .maxlen = sizeof(unsigned int),
1152 .proc_handler = &proc_dointvec_jiffies,
1155 .procname = "nf_conntrack_tcp_timeout_syn_recv",
1156 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1157 .maxlen = sizeof(unsigned int),
1159 .proc_handler = &proc_dointvec_jiffies,
1162 .procname = "nf_conntrack_tcp_timeout_established",
1163 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1164 .maxlen = sizeof(unsigned int),
1166 .proc_handler = &proc_dointvec_jiffies,
1169 .procname = "nf_conntrack_tcp_timeout_fin_wait",
1170 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1171 .maxlen = sizeof(unsigned int),
1173 .proc_handler = &proc_dointvec_jiffies,
1176 .procname = "nf_conntrack_tcp_timeout_close_wait",
1177 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1178 .maxlen = sizeof(unsigned int),
1180 .proc_handler = &proc_dointvec_jiffies,
1183 .procname = "nf_conntrack_tcp_timeout_last_ack",
1184 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1185 .maxlen = sizeof(unsigned int),
1187 .proc_handler = &proc_dointvec_jiffies,
1190 .procname = "nf_conntrack_tcp_timeout_time_wait",
1191 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1192 .maxlen = sizeof(unsigned int),
1194 .proc_handler = &proc_dointvec_jiffies,
1197 .procname = "nf_conntrack_tcp_timeout_close",
1198 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1199 .maxlen = sizeof(unsigned int),
1201 .proc_handler = &proc_dointvec_jiffies,
1204 .procname = "nf_conntrack_tcp_timeout_max_retrans",
1205 .data = &nf_ct_tcp_timeout_max_retrans,
1206 .maxlen = sizeof(unsigned int),
1208 .proc_handler = &proc_dointvec_jiffies,
1211 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
1212 .procname = "nf_conntrack_tcp_loose",
1213 .data = &nf_ct_tcp_loose,
1214 .maxlen = sizeof(unsigned int),
1216 .proc_handler = &proc_dointvec,
1219 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
1220 .procname = "nf_conntrack_tcp_be_liberal",
1221 .data = &nf_ct_tcp_be_liberal,
1222 .maxlen = sizeof(unsigned int),
1224 .proc_handler = &proc_dointvec,
1227 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
1228 .procname = "nf_conntrack_tcp_max_retrans",
1229 .data = &nf_ct_tcp_max_retrans,
1230 .maxlen = sizeof(unsigned int),
1232 .proc_handler = &proc_dointvec,
1239 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1240 static struct ctl_table tcp_compat_sysctl_table[] = {
1242 .procname = "ip_conntrack_tcp_timeout_syn_sent",
1243 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_SENT],
1244 .maxlen = sizeof(unsigned int),
1246 .proc_handler = &proc_dointvec_jiffies,
1249 .procname = "ip_conntrack_tcp_timeout_syn_recv",
1250 .data = &tcp_timeouts[TCP_CONNTRACK_SYN_RECV],
1251 .maxlen = sizeof(unsigned int),
1253 .proc_handler = &proc_dointvec_jiffies,
1256 .procname = "ip_conntrack_tcp_timeout_established",
1257 .data = &tcp_timeouts[TCP_CONNTRACK_ESTABLISHED],
1258 .maxlen = sizeof(unsigned int),
1260 .proc_handler = &proc_dointvec_jiffies,
1263 .procname = "ip_conntrack_tcp_timeout_fin_wait",
1264 .data = &tcp_timeouts[TCP_CONNTRACK_FIN_WAIT],
1265 .maxlen = sizeof(unsigned int),
1267 .proc_handler = &proc_dointvec_jiffies,
1270 .procname = "ip_conntrack_tcp_timeout_close_wait",
1271 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE_WAIT],
1272 .maxlen = sizeof(unsigned int),
1274 .proc_handler = &proc_dointvec_jiffies,
1277 .procname = "ip_conntrack_tcp_timeout_last_ack",
1278 .data = &tcp_timeouts[TCP_CONNTRACK_LAST_ACK],
1279 .maxlen = sizeof(unsigned int),
1281 .proc_handler = &proc_dointvec_jiffies,
1284 .procname = "ip_conntrack_tcp_timeout_time_wait",
1285 .data = &tcp_timeouts[TCP_CONNTRACK_TIME_WAIT],
1286 .maxlen = sizeof(unsigned int),
1288 .proc_handler = &proc_dointvec_jiffies,
1291 .procname = "ip_conntrack_tcp_timeout_close",
1292 .data = &tcp_timeouts[TCP_CONNTRACK_CLOSE],
1293 .maxlen = sizeof(unsigned int),
1295 .proc_handler = &proc_dointvec_jiffies,
1298 .procname = "ip_conntrack_tcp_timeout_max_retrans",
1299 .data = &nf_ct_tcp_timeout_max_retrans,
1300 .maxlen = sizeof(unsigned int),
1302 .proc_handler = &proc_dointvec_jiffies,
1305 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
1306 .procname = "ip_conntrack_tcp_loose",
1307 .data = &nf_ct_tcp_loose,
1308 .maxlen = sizeof(unsigned int),
1310 .proc_handler = &proc_dointvec,
1313 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
1314 .procname = "ip_conntrack_tcp_be_liberal",
1315 .data = &nf_ct_tcp_be_liberal,
1316 .maxlen = sizeof(unsigned int),
1318 .proc_handler = &proc_dointvec,
1321 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
1322 .procname = "ip_conntrack_tcp_max_retrans",
1323 .data = &nf_ct_tcp_max_retrans,
1324 .maxlen = sizeof(unsigned int),
1326 .proc_handler = &proc_dointvec,
1332 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
1333 #endif /* CONFIG_SYSCTL */
1335 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
1338 .l4proto = IPPROTO_TCP,
1340 .pkt_to_tuple = tcp_pkt_to_tuple,
1341 .invert_tuple = tcp_invert_tuple,
1342 .print_tuple = tcp_print_tuple,
1343 .print_conntrack = tcp_print_conntrack,
1344 .packet = tcp_packet,
1347 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1348 .to_nlattr = tcp_to_nlattr,
1349 .from_nlattr = nlattr_to_tcp,
1350 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1351 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1352 .nla_policy = nf_ct_port_nla_policy,
1354 #ifdef CONFIG_SYSCTL
1355 .ctl_table_users = &tcp_sysctl_table_users,
1356 .ctl_table_header = &tcp_sysctl_header,
1357 .ctl_table = tcp_sysctl_table,
1358 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
1359 .ctl_compat_table = tcp_compat_sysctl_table,
1363 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);
1365 struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
1367 .l3proto = PF_INET6,
1368 .l4proto = IPPROTO_TCP,
1370 .pkt_to_tuple = tcp_pkt_to_tuple,
1371 .invert_tuple = tcp_invert_tuple,
1372 .print_tuple = tcp_print_tuple,
1373 .print_conntrack = tcp_print_conntrack,
1374 .packet = tcp_packet,
1377 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
1378 .to_nlattr = tcp_to_nlattr,
1379 .from_nlattr = nlattr_to_tcp,
1380 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
1381 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
1382 .nla_policy = nf_ct_port_nla_policy,
1384 #ifdef CONFIG_SYSCTL
1385 .ctl_table_users = &tcp_sysctl_table_users,
1386 .ctl_table_header = &tcp_sysctl_header,
1387 .ctl_table = tcp_sysctl_table,
1390 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);