Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1 | /* (C) 1999-2001 Paul `Rusty' Russell |
| 2 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> |
Patrick McHardy | f229f6c | 2013-04-06 15:24:29 +0200 | [diff] [blame] | 3 | * (C) 2002-2013 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> |
| 4 | * (C) 2006-2012 Patrick McHardy <kaber@trash.net> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 11 | #include <linux/types.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 12 | #include <linux/timer.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/in.h> |
| 15 | #include <linux/tcp.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/skbuff.h> |
| 18 | #include <linux/ipv6.h> |
| 19 | #include <net/ip6_checksum.h> |
Mark H. Weaver | 534f81a | 2009-03-23 13:46:12 +0100 | [diff] [blame] | 20 | #include <asm/unaligned.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 21 | |
| 22 | #include <net/tcp.h> |
| 23 | |
| 24 | #include <linux/netfilter.h> |
| 25 | #include <linux/netfilter_ipv4.h> |
| 26 | #include <linux/netfilter_ipv6.h> |
| 27 | #include <net/netfilter/nf_conntrack.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 28 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 29 | #include <net/netfilter/nf_conntrack_ecache.h> |
Patrick McHardy | 41d73ec | 2013-08-27 08:50:12 +0200 | [diff] [blame] | 30 | #include <net/netfilter/nf_conntrack_seqadj.h> |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 31 | #include <net/netfilter/nf_conntrack_synproxy.h> |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 32 | #include <net/netfilter/nf_log.h> |
Christoph Paasch | 9d2493f | 2009-03-16 15:15:35 +0100 | [diff] [blame] | 33 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> |
| 34 | #include <net/netfilter/ipv6/nf_conntrack_ipv6.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 35 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 36 | /* "Be conservative in what you do, |
| 37 | be liberal in what you accept from others." |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 38 | If it's non-zero, we mark only out of window RST segments as INVALID. */ |
Patrick McHardy | 3aef0fd | 2007-02-12 11:16:58 -0800 | [diff] [blame] | 39 | static int nf_ct_tcp_be_liberal __read_mostly = 0; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 40 | |
Patrick McHardy | a09113c | 2007-02-07 15:05:33 -0800 | [diff] [blame] | 41 | /* If it is set to zero, we disable picking up already established |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 42 | connections. */ |
Patrick McHardy | 3aef0fd | 2007-02-12 11:16:58 -0800 | [diff] [blame] | 43 | static int nf_ct_tcp_loose __read_mostly = 1; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 44 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 45 | /* Max number of the retransmitted packets without receiving an (acceptable) |
| 46 | ACK from the destination. If this number is reached, a shorter timer |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 47 | will be started. */ |
Patrick McHardy | 3aef0fd | 2007-02-12 11:16:58 -0800 | [diff] [blame] | 48 | static int nf_ct_tcp_max_retrans __read_mostly = 3; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 49 | |
| 50 | /* FIXME: Examine ipfilter's timeouts and conntrack transitions more |
| 51 | closely. They're more complex. --RR */ |
| 52 | |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 53 | static const char *const tcp_conntrack_names[] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 54 | "NONE", |
| 55 | "SYN_SENT", |
| 56 | "SYN_RECV", |
| 57 | "ESTABLISHED", |
| 58 | "FIN_WAIT", |
| 59 | "CLOSE_WAIT", |
| 60 | "LAST_ACK", |
| 61 | "TIME_WAIT", |
| 62 | "CLOSE", |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 63 | "SYN_SENT2", |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 64 | }; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 65 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 66 | #define SECS * HZ |
| 67 | #define MINS * 60 SECS |
| 68 | #define HOURS * 60 MINS |
| 69 | #define DAYS * 24 HOURS |
| 70 | |
Pablo Neira Ayuso | 33ee446 | 2012-02-28 16:56:31 +0100 | [diff] [blame] | 71 | static unsigned int tcp_timeouts[TCP_CONNTRACK_TIMEOUT_MAX] __read_mostly = { |
Patrick McHardy | 2d64628 | 2008-01-14 23:45:32 -0800 | [diff] [blame] | 72 | [TCP_CONNTRACK_SYN_SENT] = 2 MINS, |
| 73 | [TCP_CONNTRACK_SYN_RECV] = 60 SECS, |
| 74 | [TCP_CONNTRACK_ESTABLISHED] = 5 DAYS, |
| 75 | [TCP_CONNTRACK_FIN_WAIT] = 2 MINS, |
| 76 | [TCP_CONNTRACK_CLOSE_WAIT] = 60 SECS, |
| 77 | [TCP_CONNTRACK_LAST_ACK] = 30 SECS, |
| 78 | [TCP_CONNTRACK_TIME_WAIT] = 2 MINS, |
| 79 | [TCP_CONNTRACK_CLOSE] = 10 SECS, |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 80 | [TCP_CONNTRACK_SYN_SENT2] = 2 MINS, |
Pablo Neira Ayuso | 33ee446 | 2012-02-28 16:56:31 +0100 | [diff] [blame] | 81 | /* RFC1122 says the R2 limit should be at least 100 seconds. |
| 82 | Linux uses 15 packets as limit, which corresponds |
| 83 | to ~13-30min depending on RTO. */ |
| 84 | [TCP_CONNTRACK_RETRANS] = 5 MINS, |
| 85 | [TCP_CONNTRACK_UNACK] = 5 MINS, |
Patrick McHardy | 2d64628 | 2008-01-14 23:45:32 -0800 | [diff] [blame] | 86 | }; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 87 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 88 | #define sNO TCP_CONNTRACK_NONE |
| 89 | #define sSS TCP_CONNTRACK_SYN_SENT |
| 90 | #define sSR TCP_CONNTRACK_SYN_RECV |
| 91 | #define sES TCP_CONNTRACK_ESTABLISHED |
| 92 | #define sFW TCP_CONNTRACK_FIN_WAIT |
| 93 | #define sCW TCP_CONNTRACK_CLOSE_WAIT |
| 94 | #define sLA TCP_CONNTRACK_LAST_ACK |
| 95 | #define sTW TCP_CONNTRACK_TIME_WAIT |
| 96 | #define sCL TCP_CONNTRACK_CLOSE |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 97 | #define sS2 TCP_CONNTRACK_SYN_SENT2 |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 98 | #define sIV TCP_CONNTRACK_MAX |
| 99 | #define sIG TCP_CONNTRACK_IGNORE |
| 100 | |
| 101 | /* What TCP flags are set from RST/SYN/FIN/ACK. */ |
| 102 | enum tcp_bit_set { |
| 103 | TCP_SYN_SET, |
| 104 | TCP_SYNACK_SET, |
| 105 | TCP_FIN_SET, |
| 106 | TCP_ACK_SET, |
| 107 | TCP_RST_SET, |
| 108 | TCP_NONE_SET, |
| 109 | }; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 110 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 111 | /* |
| 112 | * The TCP state transition table needs a few words... |
| 113 | * |
| 114 | * We are the man in the middle. All the packets go through us |
| 115 | * but might get lost in transit to the destination. |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 116 | * It is assumed that the destinations can't receive segments |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 117 | * we haven't seen. |
| 118 | * |
| 119 | * The checked segment is in window, but our windows are *not* |
| 120 | * equivalent with the ones of the sender/receiver. We always |
| 121 | * try to guess the state of the current sender. |
| 122 | * |
| 123 | * The meaning of the states are: |
| 124 | * |
| 125 | * NONE: initial state |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 126 | * SYN_SENT: SYN-only packet seen |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 127 | * SYN_SENT2: SYN-only packet seen from reply dir, simultaneous open |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 128 | * SYN_RECV: SYN-ACK packet seen |
| 129 | * ESTABLISHED: ACK packet seen |
| 130 | * FIN_WAIT: FIN packet seen |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 131 | * CLOSE_WAIT: ACK seen (after FIN) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 132 | * LAST_ACK: FIN seen (after FIN) |
| 133 | * TIME_WAIT: last ACK seen |
Jozsef Kadlecsik | b2155e7 | 2008-02-07 17:54:56 -0800 | [diff] [blame] | 134 | * CLOSE: closed connection (RST) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 135 | * |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 136 | * Packets marked as IGNORED (sIG): |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 137 | * if they may be either invalid or valid |
| 138 | * and the receiver may send back a connection |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 139 | * closing RST or a SYN/ACK. |
| 140 | * |
| 141 | * Packets marked as INVALID (sIV): |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 142 | * if we regard them as truly invalid packets |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 143 | */ |
Patrick McHardy | a5e73c2 | 2008-01-14 23:45:11 -0800 | [diff] [blame] | 144 | static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 145 | { |
| 146 | /* ORIGINAL */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 147 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
| 148 | /*syn*/ { sSS, sSS, sIG, sIG, sIG, sIG, sIG, sSS, sSS, sS2 }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 149 | /* |
| 150 | * sNO -> sSS Initialize a new connection |
| 151 | * sSS -> sSS Retransmitted SYN |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 152 | * sS2 -> sS2 Late retransmitted SYN |
| 153 | * sSR -> sIG |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 154 | * sES -> sIG Error: SYNs in window outside the SYN_SENT state |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 155 | * are errors. Receiver will reply with RST |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 156 | * and close the connection. |
| 157 | * Or we are not in sync and hold a dead connection. |
| 158 | * sFW -> sIG |
| 159 | * sCW -> sIG |
| 160 | * sLA -> sIG |
| 161 | * sTW -> sSS Reopened connection (RFC 1122). |
| 162 | * sCL -> sSS |
| 163 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 164 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
Jozsef Kadlecsik | 64f509c | 2012-08-31 09:55:53 +0000 | [diff] [blame] | 165 | /*synack*/ { sIV, sIV, sSR, sIV, sIV, sIV, sIV, sIV, sIV, sSR }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 166 | /* |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 167 | * sNO -> sIV Too late and no reason to do anything |
| 168 | * sSS -> sIV Client can't send SYN and then SYN/ACK |
| 169 | * sS2 -> sSR SYN/ACK sent to SYN2 in simultaneous open |
Jozsef Kadlecsik | 64f509c | 2012-08-31 09:55:53 +0000 | [diff] [blame] | 170 | * sSR -> sSR Late retransmitted SYN/ACK in simultaneous open |
| 171 | * sES -> sIV Invalid SYN/ACK packets sent by the client |
| 172 | * sFW -> sIV |
| 173 | * sCW -> sIV |
| 174 | * sLA -> sIV |
| 175 | * sTW -> sIV |
| 176 | * sCL -> sIV |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 177 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 178 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 179 | /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV }, |
| 180 | /* |
| 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. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 184 | * sS2 -> sIV |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 185 | * sSR -> sFW Close started. |
| 186 | * sES -> sFW |
| 187 | * sFW -> sLA FIN seen in both directions, waiting for |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 188 | * the last ACK. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 189 | * Migth be a retransmitted FIN as well... |
| 190 | * sCW -> sLA |
| 191 | * sLA -> sLA Retransmitted FIN. Remain in the same state. |
| 192 | * sTW -> sTW |
| 193 | * sCL -> sCL |
| 194 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 195 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 196 | /*ack*/ { sES, sIV, sES, sES, sCW, sCW, sTW, sTW, sCL, sIV }, |
| 197 | /* |
| 198 | * sNO -> sES Assumed. |
| 199 | * sSS -> sIV ACK is invalid: we haven't seen a SYN/ACK yet. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 200 | * sS2 -> sIV |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 201 | * sSR -> sES Established state is reached. |
| 202 | * sES -> sES :-) |
| 203 | * sFW -> sCW Normal close request answered by ACK. |
| 204 | * sCW -> sCW |
| 205 | * sLA -> sTW Last ACK detected. |
| 206 | * sTW -> sTW Retransmitted last ACK. Remain in the same state. |
| 207 | * sCL -> sCL |
| 208 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 209 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
| 210 | /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 211 | /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV } |
| 212 | }, |
| 213 | { |
| 214 | /* REPLY */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 215 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
| 216 | /*syn*/ { sIV, sS2, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sS2 }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 217 | /* |
| 218 | * sNO -> sIV Never reached. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 219 | * sSS -> sS2 Simultaneous open |
| 220 | * sS2 -> sS2 Retransmitted simultaneous SYN |
| 221 | * sSR -> sIV Invalid SYN packets sent by the server |
| 222 | * sES -> sIV |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 223 | * sFW -> sIV |
| 224 | * sCW -> sIV |
| 225 | * sLA -> sIV |
| 226 | * sTW -> sIV Reopened connection, but server may not do it. |
| 227 | * sCL -> sIV |
| 228 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 229 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
Pablo Neira Ayuso | 8a80c79 | 2011-02-28 17:59:15 +0100 | [diff] [blame] | 230 | /*synack*/ { sIV, sSR, sIG, sIG, sIG, sIG, sIG, sIG, sIG, sSR }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 231 | /* |
| 232 | * sSS -> sSR Standard open. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 233 | * sS2 -> sSR Simultaneous open |
Pablo Neira Ayuso | 8a80c79 | 2011-02-28 17:59:15 +0100 | [diff] [blame] | 234 | * sSR -> sIG Retransmitted SYN/ACK, ignore it. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 235 | * sES -> sIG Late retransmitted SYN/ACK? |
| 236 | * sFW -> sIG Might be SYN/ACK answering ignored SYN |
| 237 | * sCW -> sIG |
| 238 | * sLA -> sIG |
| 239 | * sTW -> sIG |
| 240 | * sCL -> sIG |
| 241 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 242 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 243 | /*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV }, |
| 244 | /* |
| 245 | * sSS -> sIV Server might not send FIN in this state. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 246 | * sS2 -> sIV |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 247 | * sSR -> sFW Close started. |
| 248 | * sES -> sFW |
| 249 | * sFW -> sLA FIN seen in both directions. |
| 250 | * sCW -> sLA |
| 251 | * sLA -> sLA Retransmitted FIN. |
| 252 | * sTW -> sTW |
| 253 | * sCL -> sCL |
| 254 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 255 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
| 256 | /*ack*/ { sIV, sIG, sSR, sES, sCW, sCW, sTW, sTW, sCL, sIG }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 257 | /* |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 258 | * sSS -> sIG Might be a half-open connection. |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 259 | * sS2 -> sIG |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 260 | * sSR -> sSR Might answer late resent SYN. |
| 261 | * sES -> sES :-) |
| 262 | * sFW -> sCW Normal close request answered by ACK. |
| 263 | * sCW -> sCW |
| 264 | * sLA -> sTW Last ACK detected. |
| 265 | * sTW -> sTW Retransmitted last ACK. |
| 266 | * sCL -> sCL |
| 267 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 268 | /* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ |
| 269 | /*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 270 | /*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV } |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 271 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 272 | }; |
| 273 | |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 274 | static inline struct nf_tcp_net *tcp_pernet(struct net *net) |
| 275 | { |
| 276 | return &net->ct.nf_ct_proto.tcp; |
| 277 | } |
| 278 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 279 | static bool tcp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff, |
| 280 | struct nf_conntrack_tuple *tuple) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 281 | { |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 282 | const struct tcphdr *hp; |
| 283 | struct tcphdr _hdr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 284 | |
| 285 | /* Actually only need first 8 bytes. */ |
| 286 | hp = skb_header_pointer(skb, dataoff, 8, &_hdr); |
| 287 | if (hp == NULL) |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 288 | return false; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 289 | |
| 290 | tuple->src.u.tcp.port = hp->source; |
| 291 | tuple->dst.u.tcp.port = hp->dest; |
| 292 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 293 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 296 | static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 297 | const struct nf_conntrack_tuple *orig) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 298 | { |
| 299 | tuple->src.u.tcp.port = orig->dst.u.tcp.port; |
| 300 | tuple->dst.u.tcp.port = orig->src.u.tcp.port; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 301 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* Print out the per-protocol part of the tuple. */ |
| 305 | static int tcp_print_tuple(struct seq_file *s, |
| 306 | const struct nf_conntrack_tuple *tuple) |
| 307 | { |
| 308 | return seq_printf(s, "sport=%hu dport=%hu ", |
| 309 | ntohs(tuple->src.u.tcp.port), |
| 310 | ntohs(tuple->dst.u.tcp.port)); |
| 311 | } |
| 312 | |
| 313 | /* Print out the private part of the conntrack. */ |
Steven Rostedt (Red Hat) | 37246a5 | 2014-10-27 16:02:47 -0400 | [diff] [blame^] | 314 | static void tcp_print_conntrack(struct seq_file *s, struct nf_conn *ct) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 315 | { |
| 316 | enum tcp_conntrack state; |
| 317 | |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 318 | spin_lock_bh(&ct->lock); |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 319 | state = ct->proto.tcp.state; |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 320 | spin_unlock_bh(&ct->lock); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 321 | |
Steven Rostedt (Red Hat) | 37246a5 | 2014-10-27 16:02:47 -0400 | [diff] [blame^] | 322 | seq_printf(s, "%s ", tcp_conntrack_names[state]); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static unsigned int get_conntrack_index(const struct tcphdr *tcph) |
| 326 | { |
| 327 | if (tcph->rst) return TCP_RST_SET; |
| 328 | else if (tcph->syn) return (tcph->ack ? TCP_SYNACK_SET : TCP_SYN_SET); |
| 329 | else if (tcph->fin) return TCP_FIN_SET; |
| 330 | else if (tcph->ack) return TCP_ACK_SET; |
| 331 | else return TCP_NONE_SET; |
| 332 | } |
| 333 | |
| 334 | /* TCP connection tracking based on 'Real Stateful TCP Packet Filtering |
| 335 | in IP Filter' by Guido van Rooij. |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 336 | |
Justin P. Mattock | 631dd1a | 2010-10-18 11:03:14 +0200 | [diff] [blame] | 337 | http://www.sane.nl/events/sane2000/papers.html |
| 338 | http://www.darkart.com/mirrors/www.obfuscation.org/ipf/ |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 339 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 340 | The boundaries and the conditions are changed according to RFC793: |
| 341 | the packet must intersect the window (i.e. segments may be |
| 342 | after the right or before the left edge) and thus receivers may ACK |
| 343 | segments after the right edge of the window. |
| 344 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 345 | td_maxend = max(sack + max(win,1)) seen in reply packets |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 346 | td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets |
| 347 | td_maxwin += seq + len - sender.td_maxend |
| 348 | if seq + len > sender.td_maxend |
| 349 | td_end = max(seq + len) seen in sent packets |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 350 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 351 | I. Upper bound for valid data: seq <= sender.td_maxend |
| 352 | II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin |
Jozsef Kadlecsik | 84ebe1c | 2008-06-30 12:41:30 -0700 | [diff] [blame] | 353 | III. Upper bound for valid (s)ack: sack <= receiver.td_end |
| 354 | IV. Lower bound for valid (s)ack: sack >= receiver.td_end - MAXACKWINDOW |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 355 | |
Jozsef Kadlecsik | 84ebe1c | 2008-06-30 12:41:30 -0700 | [diff] [blame] | 356 | where sack is the highest right edge of sack block found in the packet |
| 357 | or ack in the case of packet without SACK option. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 358 | |
Jozsef Kadlecsik | 84ebe1c | 2008-06-30 12:41:30 -0700 | [diff] [blame] | 359 | The upper bound limit for a valid (s)ack is not ignored - |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 360 | we doesn't have to deal with fragments. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 361 | */ |
| 362 | |
| 363 | static inline __u32 segment_seq_plus_len(__u32 seq, |
| 364 | size_t len, |
| 365 | unsigned int dataoff, |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 366 | const struct tcphdr *tcph) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 367 | { |
| 368 | /* XXX Should I use payload length field in IP/IPv6 header ? |
| 369 | * - YK */ |
| 370 | return (seq + len - dataoff - tcph->doff*4 |
| 371 | + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0)); |
| 372 | } |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 373 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 374 | /* Fixme: what about big packets? */ |
| 375 | #define MAXACKWINCONST 66000 |
| 376 | #define MAXACKWINDOW(sender) \ |
| 377 | ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \ |
| 378 | : MAXACKWINCONST) |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 379 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 380 | /* |
| 381 | * Simplified tcp_parse_options routine from tcp_input.c |
| 382 | */ |
| 383 | static void tcp_options(const struct sk_buff *skb, |
| 384 | unsigned int dataoff, |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 385 | const struct tcphdr *tcph, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 386 | struct ip_ct_tcp_state *state) |
| 387 | { |
| 388 | unsigned char buff[(15 * 4) - sizeof(struct tcphdr)]; |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 389 | const unsigned char *ptr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 390 | int length = (tcph->doff*4) - sizeof(struct tcphdr); |
| 391 | |
| 392 | if (!length) |
| 393 | return; |
| 394 | |
| 395 | ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr), |
| 396 | length, buff); |
| 397 | BUG_ON(ptr == NULL); |
| 398 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 399 | state->td_scale = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 400 | state->flags = 0; |
| 401 | |
| 402 | while (length > 0) { |
| 403 | int opcode=*ptr++; |
| 404 | int opsize; |
| 405 | |
| 406 | switch (opcode) { |
| 407 | case TCPOPT_EOL: |
| 408 | return; |
| 409 | case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */ |
| 410 | length--; |
| 411 | continue; |
| 412 | default: |
| 413 | opsize=*ptr++; |
| 414 | if (opsize < 2) /* "silly options" */ |
| 415 | return; |
| 416 | if (opsize > length) |
Jozsef Kadlecsik | 4a5cc84a | 2011-08-30 15:45:10 +0200 | [diff] [blame] | 417 | return; /* don't parse partial options */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 418 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 419 | if (opcode == TCPOPT_SACK_PERM |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 420 | && opsize == TCPOLEN_SACK_PERM) |
| 421 | state->flags |= IP_CT_TCP_FLAG_SACK_PERM; |
| 422 | else if (opcode == TCPOPT_WINDOW |
| 423 | && opsize == TCPOLEN_WINDOW) { |
| 424 | state->td_scale = *(u_int8_t *)ptr; |
| 425 | |
| 426 | if (state->td_scale > 14) { |
| 427 | /* See RFC1323 */ |
| 428 | state->td_scale = 14; |
| 429 | } |
| 430 | state->flags |= |
| 431 | IP_CT_TCP_FLAG_WINDOW_SCALE; |
| 432 | } |
| 433 | ptr += opsize - 2; |
| 434 | length -= opsize; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff, |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 440 | const struct tcphdr *tcph, __u32 *sack) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 441 | { |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 442 | unsigned char buff[(15 * 4) - sizeof(struct tcphdr)]; |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 443 | const unsigned char *ptr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 444 | int length = (tcph->doff*4) - sizeof(struct tcphdr); |
| 445 | __u32 tmp; |
| 446 | |
| 447 | if (!length) |
| 448 | return; |
| 449 | |
| 450 | ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr), |
| 451 | length, buff); |
| 452 | BUG_ON(ptr == NULL); |
| 453 | |
| 454 | /* Fast path for timestamp-only option */ |
Jozsef Kadlecsik | bb9fc37 | 2011-08-30 15:46:13 +0200 | [diff] [blame] | 455 | if (length == TCPOLEN_TSTAMP_ALIGNED |
YOSHIFUJI Hideaki | 8f05ce9 | 2007-03-07 14:21:00 +0900 | [diff] [blame] | 456 | && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24) |
| 457 | | (TCPOPT_NOP << 16) |
| 458 | | (TCPOPT_TIMESTAMP << 8) |
| 459 | | TCPOLEN_TIMESTAMP)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 460 | return; |
| 461 | |
| 462 | while (length > 0) { |
| 463 | int opcode = *ptr++; |
| 464 | int opsize, i; |
| 465 | |
| 466 | switch (opcode) { |
| 467 | case TCPOPT_EOL: |
| 468 | return; |
| 469 | case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */ |
| 470 | length--; |
| 471 | continue; |
| 472 | default: |
| 473 | opsize = *ptr++; |
| 474 | if (opsize < 2) /* "silly options" */ |
| 475 | return; |
| 476 | if (opsize > length) |
Jozsef Kadlecsik | 4a5cc84a | 2011-08-30 15:45:10 +0200 | [diff] [blame] | 477 | return; /* don't parse partial options */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 478 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 479 | if (opcode == TCPOPT_SACK |
| 480 | && opsize >= (TCPOLEN_SACK_BASE |
| 481 | + TCPOLEN_SACK_PERBLOCK) |
| 482 | && !((opsize - TCPOLEN_SACK_BASE) |
| 483 | % TCPOLEN_SACK_PERBLOCK)) { |
| 484 | for (i = 0; |
| 485 | i < (opsize - TCPOLEN_SACK_BASE); |
| 486 | i += TCPOLEN_SACK_PERBLOCK) { |
Mark H. Weaver | 534f81a | 2009-03-23 13:46:12 +0100 | [diff] [blame] | 487 | tmp = get_unaligned_be32((__be32 *)(ptr+i)+1); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 488 | |
| 489 | if (after(tmp, *sack)) |
| 490 | *sack = tmp; |
| 491 | } |
| 492 | return; |
| 493 | } |
| 494 | ptr += opsize - 2; |
| 495 | length -= opsize; |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 500 | static bool tcp_in_window(const struct nf_conn *ct, |
| 501 | struct ip_ct_tcp *state, |
| 502 | enum ip_conntrack_dir dir, |
| 503 | unsigned int index, |
| 504 | const struct sk_buff *skb, |
| 505 | unsigned int dataoff, |
| 506 | const struct tcphdr *tcph, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 507 | u_int8_t pf) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 508 | { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 509 | struct net *net = nf_ct_net(ct); |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 510 | struct nf_tcp_net *tn = tcp_pernet(net); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 511 | struct ip_ct_tcp_state *sender = &state->seen[dir]; |
| 512 | struct ip_ct_tcp_state *receiver = &state->seen[!dir]; |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 513 | const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 514 | __u32 seq, ack, sack, end, win, swin; |
Patrick McHardy | 2d89c68 | 2013-07-28 22:54:10 +0200 | [diff] [blame] | 515 | s32 receiver_offset; |
Yuchung Cheng | 356d7d8 | 2013-08-09 17:21:27 -0700 | [diff] [blame] | 516 | bool res, in_recv_win; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * Get the required data from the packet. |
| 520 | */ |
| 521 | seq = ntohl(tcph->seq); |
| 522 | ack = sack = ntohl(tcph->ack_seq); |
| 523 | win = ntohs(tcph->window); |
| 524 | end = segment_seq_plus_len(seq, skb->len, dataoff, tcph); |
| 525 | |
| 526 | if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM) |
| 527 | tcp_sack(skb, dataoff, tcph, &sack); |
| 528 | |
Jozsef Kadlecsik | f9dd09c | 2009-11-06 00:43:42 -0800 | [diff] [blame] | 529 | /* Take into account NAT sequence number mangling */ |
Patrick McHardy | 41d73ec | 2013-08-27 08:50:12 +0200 | [diff] [blame] | 530 | receiver_offset = nf_ct_seq_offset(ct, !dir, ack - 1); |
Jozsef Kadlecsik | f9dd09c | 2009-11-06 00:43:42 -0800 | [diff] [blame] | 531 | ack -= receiver_offset; |
| 532 | sack -= receiver_offset; |
| 533 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 534 | pr_debug("tcp_in_window: START\n"); |
| 535 | pr_debug("tcp_in_window: "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 536 | nf_ct_dump_tuple(tuple); |
Jozsef Kadlecsik | f9dd09c | 2009-11-06 00:43:42 -0800 | [diff] [blame] | 537 | pr_debug("seq=%u ack=%u+(%d) sack=%u+(%d) win=%u end=%u\n", |
| 538 | seq, ack, receiver_offset, sack, receiver_offset, win, end); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 539 | pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " |
| 540 | "receiver end=%u maxend=%u maxwin=%u scale=%i\n", |
| 541 | sender->td_end, sender->td_maxend, sender->td_maxwin, |
| 542 | sender->td_scale, |
| 543 | receiver->td_end, receiver->td_maxend, receiver->td_maxwin, |
| 544 | receiver->td_scale); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 545 | |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 546 | if (sender->td_maxwin == 0) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 547 | /* |
| 548 | * Initialize sender data. |
| 549 | */ |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 550 | if (tcph->syn) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 551 | /* |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 552 | * SYN-ACK in reply to a SYN |
| 553 | * or SYN from reply direction in simultaneous open. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 554 | */ |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 555 | sender->td_end = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 556 | sender->td_maxend = end; |
| 557 | sender->td_maxwin = (win == 0 ? 1 : win); |
| 558 | |
| 559 | tcp_options(skb, dataoff, tcph, sender); |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 560 | /* |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 561 | * RFC 1323: |
| 562 | * Both sides must send the Window Scale option |
| 563 | * to enable window scaling in either direction. |
| 564 | */ |
| 565 | if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE |
| 566 | && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE)) |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 567 | sender->td_scale = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 568 | receiver->td_scale = 0; |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 569 | if (!tcph->ack) |
| 570 | /* Simultaneous open */ |
| 571 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 572 | } else { |
| 573 | /* |
| 574 | * We are in the middle of a connection, |
| 575 | * its history is lost for us. |
| 576 | * Let's try to use the data from the packet. |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 577 | */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 578 | sender->td_end = end; |
Changli Gao | 6ee0b69 | 2012-04-01 17:25:06 +0000 | [diff] [blame] | 579 | swin = win << sender->td_scale; |
| 580 | sender->td_maxwin = (swin == 0 ? 1 : swin); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 581 | sender->td_maxend = end + sender->td_maxwin; |
Pablo Neira Ayuso | fac42a9 | 2010-07-15 17:09:04 +0200 | [diff] [blame] | 582 | /* |
| 583 | * We haven't seen traffic in the other direction yet |
| 584 | * but we have to tweak window tracking to pass III |
| 585 | * and IV until that happens. |
| 586 | */ |
| 587 | if (receiver->td_maxwin == 0) |
| 588 | receiver->td_end = receiver->td_maxend = sack; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 589 | } |
| 590 | } else if (((state->state == TCP_CONNTRACK_SYN_SENT |
| 591 | && dir == IP_CT_DIR_ORIGINAL) |
| 592 | || (state->state == TCP_CONNTRACK_SYN_RECV |
| 593 | && dir == IP_CT_DIR_REPLY)) |
| 594 | && after(end, sender->td_end)) { |
| 595 | /* |
| 596 | * RFC 793: "if a TCP is reinitialized ... then it need |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 597 | * not wait at all; it must only be sure to use sequence |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 598 | * numbers larger than those recently used." |
| 599 | */ |
| 600 | sender->td_end = |
| 601 | sender->td_maxend = end; |
| 602 | sender->td_maxwin = (win == 0 ? 1 : win); |
| 603 | |
| 604 | tcp_options(skb, dataoff, tcph, sender); |
| 605 | } |
| 606 | |
| 607 | if (!(tcph->ack)) { |
| 608 | /* |
| 609 | * If there is no ACK, just pretend it was set and OK. |
| 610 | */ |
| 611 | ack = sack = receiver->td_end; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 612 | } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) == |
| 613 | (TCP_FLAG_ACK|TCP_FLAG_RST)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 614 | && (ack == 0)) { |
| 615 | /* |
| 616 | * Broken TCP stacks, that set ACK in RST packets as well |
| 617 | * with zero ack value. |
| 618 | */ |
| 619 | ack = sack = receiver->td_end; |
| 620 | } |
| 621 | |
Jozsef Kadlecsik | 4a70bbf | 2012-08-31 09:55:54 +0000 | [diff] [blame] | 622 | if (tcph->rst && seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 623 | /* |
Jozsef Kadlecsik | 4a70bbf | 2012-08-31 09:55:54 +0000 | [diff] [blame] | 624 | * RST sent answering SYN. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 625 | */ |
| 626 | seq = end = sender->td_end; |
| 627 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 628 | pr_debug("tcp_in_window: "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 629 | nf_ct_dump_tuple(tuple); |
Jozsef Kadlecsik | f9dd09c | 2009-11-06 00:43:42 -0800 | [diff] [blame] | 630 | pr_debug("seq=%u ack=%u+(%d) sack=%u+(%d) win=%u end=%u\n", |
| 631 | seq, ack, receiver_offset, sack, receiver_offset, win, end); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 632 | pr_debug("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " |
| 633 | "receiver end=%u maxend=%u maxwin=%u scale=%i\n", |
| 634 | sender->td_end, sender->td_maxend, sender->td_maxwin, |
| 635 | sender->td_scale, |
| 636 | receiver->td_end, receiver->td_maxend, receiver->td_maxwin, |
| 637 | receiver->td_scale); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 638 | |
Yuchung Cheng | 356d7d8 | 2013-08-09 17:21:27 -0700 | [diff] [blame] | 639 | /* Is the ending sequence in the receive window (if available)? */ |
| 640 | in_recv_win = !receiver->td_maxwin || |
| 641 | after(end, sender->td_end - receiver->td_maxwin - 1); |
| 642 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 643 | pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n", |
| 644 | before(seq, sender->td_maxend + 1), |
Yuchung Cheng | 356d7d8 | 2013-08-09 17:21:27 -0700 | [diff] [blame] | 645 | (in_recv_win ? 1 : 0), |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 646 | before(sack, receiver->td_end + 1), |
Jozsef Kadlecsik | 84ebe1c | 2008-06-30 12:41:30 -0700 | [diff] [blame] | 647 | after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 648 | |
Patrick McHardy | a09113c | 2007-02-07 15:05:33 -0800 | [diff] [blame] | 649 | if (before(seq, sender->td_maxend + 1) && |
Yuchung Cheng | 356d7d8 | 2013-08-09 17:21:27 -0700 | [diff] [blame] | 650 | in_recv_win && |
Patrick McHardy | a09113c | 2007-02-07 15:05:33 -0800 | [diff] [blame] | 651 | before(sack, receiver->td_end + 1) && |
Jozsef Kadlecsik | 84ebe1c | 2008-06-30 12:41:30 -0700 | [diff] [blame] | 652 | after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) { |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 653 | /* |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 654 | * Take into account window scaling (RFC 1323). |
| 655 | */ |
| 656 | if (!tcph->syn) |
| 657 | win <<= sender->td_scale; |
| 658 | |
| 659 | /* |
| 660 | * Update sender data. |
| 661 | */ |
| 662 | swin = win + (sack - ack); |
| 663 | if (sender->td_maxwin < swin) |
| 664 | sender->td_maxwin = swin; |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 665 | if (after(end, sender->td_end)) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 666 | sender->td_end = end; |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 667 | sender->flags |= IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED; |
| 668 | } |
Jozsef Kadlecsik | bfcaa502 | 2009-05-25 17:23:15 +0200 | [diff] [blame] | 669 | if (tcph->ack) { |
| 670 | if (!(sender->flags & IP_CT_TCP_FLAG_MAXACK_SET)) { |
| 671 | sender->td_maxack = ack; |
| 672 | sender->flags |= IP_CT_TCP_FLAG_MAXACK_SET; |
| 673 | } else if (after(ack, sender->td_maxack)) |
| 674 | sender->td_maxack = ack; |
| 675 | } |
| 676 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 677 | /* |
| 678 | * Update receiver data. |
| 679 | */ |
Pablo Neira Ayuso | fac42a9 | 2010-07-15 17:09:04 +0200 | [diff] [blame] | 680 | if (receiver->td_maxwin != 0 && after(end, sender->td_maxend)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 681 | receiver->td_maxwin += end - sender->td_maxend; |
| 682 | if (after(sack + win, receiver->td_maxend - 1)) { |
| 683 | receiver->td_maxend = sack + win; |
| 684 | if (win == 0) |
| 685 | receiver->td_maxend++; |
| 686 | } |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 687 | if (ack == receiver->td_end) |
| 688 | receiver->flags &= ~IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 689 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 690 | /* |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 691 | * Check retransmissions. |
| 692 | */ |
| 693 | if (index == TCP_ACK_SET) { |
| 694 | if (state->last_dir == dir |
| 695 | && state->last_seq == seq |
| 696 | && state->last_ack == ack |
George Hansper | c1fe3ca | 2006-09-20 12:03:23 -0700 | [diff] [blame] | 697 | && state->last_end == end |
| 698 | && state->last_win == win) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 699 | state->retrans++; |
| 700 | else { |
| 701 | state->last_dir = dir; |
| 702 | state->last_seq = seq; |
| 703 | state->last_ack = ack; |
| 704 | state->last_end = end; |
George Hansper | c1fe3ca | 2006-09-20 12:03:23 -0700 | [diff] [blame] | 705 | state->last_win = win; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 706 | state->retrans = 0; |
| 707 | } |
| 708 | } |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 709 | res = true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 710 | } else { |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 711 | res = false; |
Patrick McHardy | a09113c | 2007-02-07 15:05:33 -0800 | [diff] [blame] | 712 | if (sender->flags & IP_CT_TCP_FLAG_BE_LIBERAL || |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 713 | tn->tcp_be_liberal) |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 714 | res = true; |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 715 | if (!res && LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 716 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 717 | "nf_ct_tcp: %s ", |
| 718 | before(seq, sender->td_maxend + 1) ? |
Yuchung Cheng | 356d7d8 | 2013-08-09 17:21:27 -0700 | [diff] [blame] | 719 | in_recv_win ? |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 720 | before(sack, receiver->td_end + 1) ? |
Jozsef Kadlecsik | f9dd09c | 2009-11-06 00:43:42 -0800 | [diff] [blame] | 721 | after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1) ? "BUG" |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 722 | : "ACK is under the lower bound (possible overly delayed ACK)" |
| 723 | : "ACK is over the upper bound (ACKed data not seen yet)" |
| 724 | : "SEQ is under the lower bound (already ACKed data retransmitted)" |
| 725 | : "SEQ is over the upper bound (over the window of the receiver)"); |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 728 | pr_debug("tcp_in_window: res=%u sender end=%u maxend=%u maxwin=%u " |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 729 | "receiver end=%u maxend=%u maxwin=%u\n", |
| 730 | res, sender->td_end, sender->td_maxend, sender->td_maxwin, |
| 731 | receiver->td_end, receiver->td_maxend, receiver->td_maxwin); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 732 | |
| 733 | return res; |
| 734 | } |
| 735 | |
Willy Tarreau | 5c8ce7c | 2007-03-14 16:44:53 -0700 | [diff] [blame] | 736 | /* table of valid flag combinations - PUSH, ECE and CWR are always valid */ |
Changli Gao | a3433f3 | 2010-06-12 14:01:43 +0000 | [diff] [blame] | 737 | static const u8 tcp_valid_flags[(TCPHDR_FIN|TCPHDR_SYN|TCPHDR_RST|TCPHDR_ACK| |
| 738 | TCPHDR_URG) + 1] = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 739 | { |
Changli Gao | a3433f3 | 2010-06-12 14:01:43 +0000 | [diff] [blame] | 740 | [TCPHDR_SYN] = 1, |
| 741 | [TCPHDR_SYN|TCPHDR_URG] = 1, |
| 742 | [TCPHDR_SYN|TCPHDR_ACK] = 1, |
| 743 | [TCPHDR_RST] = 1, |
| 744 | [TCPHDR_RST|TCPHDR_ACK] = 1, |
| 745 | [TCPHDR_FIN|TCPHDR_ACK] = 1, |
| 746 | [TCPHDR_FIN|TCPHDR_ACK|TCPHDR_URG] = 1, |
| 747 | [TCPHDR_ACK] = 1, |
| 748 | [TCPHDR_ACK|TCPHDR_URG] = 1, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 749 | }; |
| 750 | |
| 751 | /* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */ |
Patrick McHardy | 8fea97e | 2010-02-15 17:45:08 +0100 | [diff] [blame] | 752 | static int tcp_error(struct net *net, struct nf_conn *tmpl, |
Alexey Dobriyan | 74c51a1 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 753 | struct sk_buff *skb, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 754 | unsigned int dataoff, |
| 755 | enum ip_conntrack_info *ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 756 | u_int8_t pf, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 757 | unsigned int hooknum) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 758 | { |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 759 | const struct tcphdr *th; |
| 760 | struct tcphdr _tcph; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 761 | unsigned int tcplen = skb->len - dataoff; |
| 762 | u_int8_t tcpflags; |
| 763 | |
| 764 | /* Smaller that minimal TCP header? */ |
| 765 | th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph); |
| 766 | if (th == NULL) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 767 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 768 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 769 | "nf_ct_tcp: short packet "); |
| 770 | return -NF_ACCEPT; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 771 | } |
| 772 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 773 | /* Not whole TCP header or malformed packet */ |
| 774 | if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 775 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 776 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 777 | "nf_ct_tcp: truncated/malformed packet "); |
| 778 | return -NF_ACCEPT; |
| 779 | } |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 780 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 781 | /* Checksum invalid? Ignore. |
| 782 | * We skip checking packets on the outgoing path |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 783 | * because the checksum is assumed to be correct. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 784 | */ |
| 785 | /* FIXME: Source route IP option packets --RR */ |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 786 | if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING && |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 787 | nf_checksum(skb, hooknum, dataoff, IPPROTO_TCP, pf)) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 788 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 789 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 790 | "nf_ct_tcp: bad TCP checksum "); |
| 791 | return -NF_ACCEPT; |
| 792 | } |
| 793 | |
| 794 | /* Check TCP flags. */ |
Changli Gao | a3433f3 | 2010-06-12 14:01:43 +0000 | [diff] [blame] | 795 | tcpflags = (tcp_flag_byte(th) & ~(TCPHDR_ECE|TCPHDR_CWR|TCPHDR_PSH)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 796 | if (!tcp_valid_flags[tcpflags]) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 797 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 798 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 799 | "nf_ct_tcp: invalid TCP flag combination "); |
| 800 | return -NF_ACCEPT; |
| 801 | } |
| 802 | |
| 803 | return NF_ACCEPT; |
| 804 | } |
| 805 | |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 806 | static unsigned int *tcp_get_timeouts(struct net *net) |
| 807 | { |
Pablo Neira Ayuso | be0593c | 2012-06-29 05:23:25 +0000 | [diff] [blame] | 808 | return tcp_pernet(net)->timeouts; |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 811 | /* Returns verdict for packet, or -1 for invalid. */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 812 | static int tcp_packet(struct nf_conn *ct, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 813 | const struct sk_buff *skb, |
| 814 | unsigned int dataoff, |
| 815 | enum ip_conntrack_info ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 816 | u_int8_t pf, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 817 | unsigned int hooknum, |
| 818 | unsigned int *timeouts) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 819 | { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 820 | struct net *net = nf_ct_net(ct); |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 821 | struct nf_tcp_net *tn = tcp_pernet(net); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 822 | struct nf_conntrack_tuple *tuple; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 823 | enum tcp_conntrack new_state, old_state; |
| 824 | enum ip_conntrack_dir dir; |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 825 | const struct tcphdr *th; |
| 826 | struct tcphdr _tcph; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 827 | unsigned long timeout; |
| 828 | unsigned int index; |
| 829 | |
| 830 | th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph); |
| 831 | BUG_ON(th == NULL); |
| 832 | |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 833 | spin_lock_bh(&ct->lock); |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 834 | old_state = ct->proto.tcp.state; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 835 | dir = CTINFO2DIR(ctinfo); |
| 836 | index = get_conntrack_index(th); |
| 837 | new_state = tcp_conntracks[dir][index][old_state]; |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 838 | tuple = &ct->tuplehash[dir].tuple; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 839 | |
| 840 | switch (new_state) { |
Jozsef Kadlecsik | 1731139 | 2007-10-11 14:35:52 -0700 | [diff] [blame] | 841 | case TCP_CONNTRACK_SYN_SENT: |
| 842 | if (old_state < TCP_CONNTRACK_TIME_WAIT) |
| 843 | break; |
Jozsef Kadlecsik | b2155e7 | 2008-02-07 17:54:56 -0800 | [diff] [blame] | 844 | /* RFC 1122: "When a connection is closed actively, |
| 845 | * it MUST linger in TIME-WAIT state for a time 2xMSL |
| 846 | * (Maximum Segment Lifetime). However, it MAY accept |
| 847 | * a new SYN from the remote TCP to reopen the connection |
| 848 | * directly from TIME-WAIT state, if..." |
| 849 | * We ignore the conditions because we are in the |
| 850 | * TIME-WAIT state anyway. |
| 851 | * |
| 852 | * Handle aborted connections: we and the server |
| 853 | * think there is an existing connection but the client |
| 854 | * aborts it and starts a new one. |
| 855 | */ |
| 856 | if (((ct->proto.tcp.seen[dir].flags |
| 857 | | ct->proto.tcp.seen[!dir].flags) |
| 858 | & IP_CT_TCP_FLAG_CLOSE_INIT) |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 859 | || (ct->proto.tcp.last_dir == dir |
| 860 | && ct->proto.tcp.last_index == TCP_RST_SET)) { |
Jozsef Kadlecsik | bc34b84 | 2007-10-18 05:20:12 -0700 | [diff] [blame] | 861 | /* Attempt to reopen a closed/aborted connection. |
| 862 | * Delete this connection and look up again. */ |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 863 | spin_unlock_bh(&ct->lock); |
David S. Miller | 2aec609 | 2008-07-14 20:23:54 -0700 | [diff] [blame] | 864 | |
Patrick McHardy | 6b69fe0 | 2008-07-09 15:06:12 -0700 | [diff] [blame] | 865 | /* Only repeat if we can actually remove the timer. |
| 866 | * Destruction may already be in progress in process |
| 867 | * context and we must give it a chance to terminate. |
| 868 | */ |
David S. Miller | 2aec609 | 2008-07-14 20:23:54 -0700 | [diff] [blame] | 869 | if (nf_ct_kill(ct)) |
Patrick McHardy | 6b69fe0 | 2008-07-09 15:06:12 -0700 | [diff] [blame] | 870 | return -NF_REPEAT; |
Christoph Paasch | ec8d540 | 2009-03-16 15:51:29 +0100 | [diff] [blame] | 871 | return NF_DROP; |
Jozsef Kadlecsik | 1731139 | 2007-10-11 14:35:52 -0700 | [diff] [blame] | 872 | } |
| 873 | /* Fall through */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 874 | case TCP_CONNTRACK_IGNORE: |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 875 | /* Ignored packets: |
| 876 | * |
Jozsef Kadlecsik | b2155e7 | 2008-02-07 17:54:56 -0800 | [diff] [blame] | 877 | * Our connection entry may be out of sync, so ignore |
| 878 | * packets which may signal the real connection between |
| 879 | * the client and the server. |
| 880 | * |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 881 | * a) SYN in ORIGINAL |
| 882 | * b) SYN/ACK in REPLY |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 883 | * c) ACK in reply direction after initial SYN in original. |
Jozsef Kadlecsik | b2155e7 | 2008-02-07 17:54:56 -0800 | [diff] [blame] | 884 | * |
| 885 | * If the ignored packet is invalid, the receiver will send |
| 886 | * a RST we'll catch below. |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 887 | */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 888 | if (index == TCP_SYNACK_SET |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 889 | && ct->proto.tcp.last_index == TCP_SYN_SET |
| 890 | && ct->proto.tcp.last_dir != dir |
| 891 | && ntohl(th->ack_seq) == ct->proto.tcp.last_end) { |
Jozsef Kadlecsik | b2155e7 | 2008-02-07 17:54:56 -0800 | [diff] [blame] | 892 | /* b) This SYN/ACK acknowledges a SYN that we earlier |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 893 | * ignored as invalid. This means that the client and |
| 894 | * the server are both in sync, while the firewall is |
Pablo Neira Ayuso | c4832c7 | 2009-11-23 10:34:39 +0100 | [diff] [blame] | 895 | * not. We get in sync from the previously annotated |
| 896 | * values. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 897 | */ |
Pablo Neira Ayuso | c4832c7 | 2009-11-23 10:34:39 +0100 | [diff] [blame] | 898 | old_state = TCP_CONNTRACK_SYN_SENT; |
| 899 | new_state = TCP_CONNTRACK_SYN_RECV; |
| 900 | ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_end = |
| 901 | ct->proto.tcp.last_end; |
| 902 | ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxend = |
| 903 | ct->proto.tcp.last_end; |
| 904 | ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxwin = |
| 905 | ct->proto.tcp.last_win == 0 ? |
| 906 | 1 : ct->proto.tcp.last_win; |
| 907 | ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_scale = |
| 908 | ct->proto.tcp.last_wscale; |
| 909 | ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags = |
| 910 | ct->proto.tcp.last_flags; |
| 911 | memset(&ct->proto.tcp.seen[dir], 0, |
| 912 | sizeof(struct ip_ct_tcp_state)); |
| 913 | break; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 914 | } |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 915 | ct->proto.tcp.last_index = index; |
| 916 | ct->proto.tcp.last_dir = dir; |
| 917 | ct->proto.tcp.last_seq = ntohl(th->seq); |
| 918 | ct->proto.tcp.last_end = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 919 | segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th); |
Pablo Neira Ayuso | c4832c7 | 2009-11-23 10:34:39 +0100 | [diff] [blame] | 920 | ct->proto.tcp.last_win = ntohs(th->window); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 921 | |
Pablo Neira Ayuso | c4832c7 | 2009-11-23 10:34:39 +0100 | [diff] [blame] | 922 | /* a) This is a SYN in ORIGINAL. The client and the server |
| 923 | * may be in sync but we are not. In that case, we annotate |
| 924 | * the TCP options and let the packet go through. If it is a |
| 925 | * valid SYN packet, the server will reply with a SYN/ACK, and |
| 926 | * then we'll get in sync. Otherwise, the server ignores it. */ |
| 927 | if (index == TCP_SYN_SET && dir == IP_CT_DIR_ORIGINAL) { |
| 928 | struct ip_ct_tcp_state seen = {}; |
| 929 | |
| 930 | ct->proto.tcp.last_flags = |
| 931 | ct->proto.tcp.last_wscale = 0; |
| 932 | tcp_options(skb, dataoff, th, &seen); |
| 933 | if (seen.flags & IP_CT_TCP_FLAG_WINDOW_SCALE) { |
| 934 | ct->proto.tcp.last_flags |= |
| 935 | IP_CT_TCP_FLAG_WINDOW_SCALE; |
| 936 | ct->proto.tcp.last_wscale = seen.td_scale; |
| 937 | } |
| 938 | if (seen.flags & IP_CT_TCP_FLAG_SACK_PERM) { |
| 939 | ct->proto.tcp.last_flags |= |
| 940 | IP_CT_TCP_FLAG_SACK_PERM; |
| 941 | } |
| 942 | } |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 943 | spin_unlock_bh(&ct->lock); |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 944 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 945 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Pablo Neira Ayuso | 1a4ac98 | 2012-05-14 10:55:03 +0200 | [diff] [blame] | 946 | "nf_ct_tcp: invalid packet ignored in " |
| 947 | "state %s ", tcp_conntrack_names[old_state]); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 948 | return NF_ACCEPT; |
| 949 | case TCP_CONNTRACK_MAX: |
Patrick McHardy | 48b1de4 | 2013-08-27 08:50:14 +0200 | [diff] [blame] | 950 | /* Special case for SYN proxy: when the SYN to the server or |
| 951 | * the SYN/ACK from the server is lost, the client may transmit |
| 952 | * a keep-alive packet while in SYN_SENT state. This needs to |
| 953 | * be associated with the original conntrack entry in order to |
| 954 | * generate a new SYN with the correct sequence number. |
| 955 | */ |
| 956 | if (nfct_synproxy(ct) && old_state == TCP_CONNTRACK_SYN_SENT && |
| 957 | index == TCP_ACK_SET && dir == IP_CT_DIR_ORIGINAL && |
| 958 | ct->proto.tcp.last_dir == IP_CT_DIR_ORIGINAL && |
| 959 | ct->proto.tcp.seen[dir].td_end - 1 == ntohl(th->seq)) { |
| 960 | pr_debug("nf_ct_tcp: SYN proxy client keep alive\n"); |
| 961 | spin_unlock_bh(&ct->lock); |
| 962 | return NF_ACCEPT; |
| 963 | } |
| 964 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 965 | /* Invalid packet */ |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 966 | pr_debug("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n", |
| 967 | dir, get_conntrack_index(th), old_state); |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 968 | spin_unlock_bh(&ct->lock); |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 969 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 970 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 971 | "nf_ct_tcp: invalid state "); |
| 972 | return -NF_ACCEPT; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 973 | case TCP_CONNTRACK_CLOSE: |
| 974 | if (index == TCP_RST_SET |
Jozsef Kadlecsik | bfcaa502 | 2009-05-25 17:23:15 +0200 | [diff] [blame] | 975 | && (ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_MAXACK_SET) |
| 976 | && before(ntohl(th->seq), ct->proto.tcp.seen[!dir].td_maxack)) { |
| 977 | /* Invalid RST */ |
Patrick McHardy | 334a47f | 2009-06-11 16:16:09 +0200 | [diff] [blame] | 978 | spin_unlock_bh(&ct->lock); |
Jozsef Kadlecsik | bfcaa502 | 2009-05-25 17:23:15 +0200 | [diff] [blame] | 979 | if (LOG_INVALID(net, IPPROTO_TCP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 980 | nf_log_packet(net, pf, 0, skb, NULL, NULL, |
| 981 | NULL, "nf_ct_tcp: invalid RST "); |
Jozsef Kadlecsik | bfcaa502 | 2009-05-25 17:23:15 +0200 | [diff] [blame] | 982 | return -NF_ACCEPT; |
| 983 | } |
| 984 | if (index == TCP_RST_SET |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 985 | && ((test_bit(IPS_SEEN_REPLY_BIT, &ct->status) |
| 986 | && ct->proto.tcp.last_index == TCP_SYN_SET) |
| 987 | || (!test_bit(IPS_ASSURED_BIT, &ct->status) |
| 988 | && ct->proto.tcp.last_index == TCP_ACK_SET)) |
| 989 | && ntohl(th->ack_seq) == ct->proto.tcp.last_end) { |
Adrian Bunk | 93b1fae | 2006-01-10 00:13:33 +0100 | [diff] [blame] | 990 | /* RST sent to invalid SYN or ACK we had let through |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 991 | * at a) and c) above: |
| 992 | * |
| 993 | * a) SYN was in window then |
| 994 | * c) we hold a half-open connection. |
| 995 | * |
| 996 | * Delete our connection entry. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 997 | * We skip window checking, because packet might ACK |
Jozsef Kadlecsik | 73f3060 | 2005-12-01 14:28:58 -0800 | [diff] [blame] | 998 | * segments we ignored. */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 999 | goto in_window; |
| 1000 | } |
Adrian Bunk | 93b1fae | 2006-01-10 00:13:33 +0100 | [diff] [blame] | 1001 | /* Just fall through */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1002 | default: |
| 1003 | /* Keep compilers happy. */ |
| 1004 | break; |
| 1005 | } |
| 1006 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1007 | if (!tcp_in_window(ct, &ct->proto.tcp, dir, index, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1008 | skb, dataoff, th, pf)) { |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1009 | spin_unlock_bh(&ct->lock); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1010 | return -NF_ACCEPT; |
| 1011 | } |
| 1012 | in_window: |
| 1013 | /* From now on we have got in-window packets */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1014 | ct->proto.tcp.last_index = index; |
| 1015 | ct->proto.tcp.last_dir = dir; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1016 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1017 | pr_debug("tcp_conntracks: "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 1018 | nf_ct_dump_tuple(tuple); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1019 | pr_debug("syn=%i ack=%i fin=%i rst=%i old=%i new=%i\n", |
| 1020 | (th->syn ? 1 : 0), (th->ack ? 1 : 0), |
| 1021 | (th->fin ? 1 : 0), (th->rst ? 1 : 0), |
| 1022 | old_state, new_state); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1023 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1024 | ct->proto.tcp.state = new_state; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1025 | if (old_state != new_state |
Jozsef Kadlecsik | d0c1fd7 | 2008-02-14 14:50:21 -0800 | [diff] [blame] | 1026 | && new_state == TCP_CONNTRACK_FIN_WAIT) |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1027 | ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT; |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1028 | |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1029 | if (ct->proto.tcp.retrans >= tn->tcp_max_retrans && |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1030 | timeouts[new_state] > timeouts[TCP_CONNTRACK_RETRANS]) |
| 1031 | timeout = timeouts[TCP_CONNTRACK_RETRANS]; |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1032 | else if ((ct->proto.tcp.seen[0].flags | ct->proto.tcp.seen[1].flags) & |
| 1033 | IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED && |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1034 | timeouts[new_state] > timeouts[TCP_CONNTRACK_UNACK]) |
| 1035 | timeout = timeouts[TCP_CONNTRACK_UNACK]; |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1036 | else |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1037 | timeout = timeouts[new_state]; |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1038 | spin_unlock_bh(&ct->lock); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1039 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1040 | if (new_state != old_state) |
Alexey Dobriyan | a71996f | 2008-10-08 11:35:07 +0200 | [diff] [blame] | 1041 | nf_conntrack_event_cache(IPCT_PROTOINFO, ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1042 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1043 | if (!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1044 | /* If only reply is a RST, we can consider ourselves not to |
| 1045 | have an established connection: this is a fairly common |
| 1046 | problem case, so we can delete the conntrack |
| 1047 | immediately. --RR */ |
| 1048 | if (th->rst) { |
Fabian Hugelshofer | 718d4ad | 2008-06-09 15:59:40 -0700 | [diff] [blame] | 1049 | nf_ct_kill_acct(ct, ctinfo, skb); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1050 | return NF_ACCEPT; |
| 1051 | } |
Florian Westphal | 6547a22 | 2013-06-13 17:31:28 +0200 | [diff] [blame] | 1052 | /* ESTABLISHED without SEEN_REPLY, i.e. mid-connection |
| 1053 | * pickup with loose=1. Avoid large ESTABLISHED timeout. |
| 1054 | */ |
| 1055 | if (new_state == TCP_CONNTRACK_ESTABLISHED && |
| 1056 | timeout > timeouts[TCP_CONNTRACK_UNACK]) |
| 1057 | timeout = timeouts[TCP_CONNTRACK_UNACK]; |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1058 | } else if (!test_bit(IPS_ASSURED_BIT, &ct->status) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1059 | && (old_state == TCP_CONNTRACK_SYN_RECV |
| 1060 | || old_state == TCP_CONNTRACK_ESTABLISHED) |
| 1061 | && new_state == TCP_CONNTRACK_ESTABLISHED) { |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1062 | /* Set ASSURED if we see see valid ack in ESTABLISHED |
| 1063 | after SYN_RECV or a valid answer for a picked up |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1064 | connection. */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1065 | set_bit(IPS_ASSURED_BIT, &ct->status); |
Patrick McHardy | 858b3133 | 2010-02-03 13:48:53 +0100 | [diff] [blame] | 1066 | nf_conntrack_event_cache(IPCT_ASSURED, ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1067 | } |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1068 | nf_ct_refresh_acct(ct, ctinfo, skb, timeout); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1069 | |
| 1070 | return NF_ACCEPT; |
| 1071 | } |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1072 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1073 | /* Called when a new connection for this protocol found. */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 1074 | static bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1075 | unsigned int dataoff, unsigned int *timeouts) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1076 | { |
| 1077 | enum tcp_conntrack new_state; |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 1078 | const struct tcphdr *th; |
| 1079 | struct tcphdr _tcph; |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1080 | struct net *net = nf_ct_net(ct); |
| 1081 | struct nf_tcp_net *tn = tcp_pernet(net); |
Jan Engelhardt | 82f568f | 2008-01-31 04:52:07 -0800 | [diff] [blame] | 1082 | const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0]; |
| 1083 | const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1]; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1084 | |
| 1085 | th = skb_header_pointer(skb, dataoff, sizeof(_tcph), &_tcph); |
| 1086 | BUG_ON(th == NULL); |
| 1087 | |
| 1088 | /* Don't need lock here: this conntrack not in circulation yet */ |
Changli Gao | e5fc9e7 | 2010-11-12 17:33:17 +0100 | [diff] [blame] | 1089 | new_state = tcp_conntracks[0][get_conntrack_index(th)][TCP_CONNTRACK_NONE]; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1090 | |
| 1091 | /* Invalid: delete conntrack */ |
| 1092 | if (new_state >= TCP_CONNTRACK_MAX) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1093 | pr_debug("nf_ct_tcp: invalid new deleting.\n"); |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 1094 | return false; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (new_state == TCP_CONNTRACK_SYN_SENT) { |
Changli Gao | e5fc9e7 | 2010-11-12 17:33:17 +0100 | [diff] [blame] | 1098 | memset(&ct->proto.tcp, 0, sizeof(ct->proto.tcp)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1099 | /* SYN packet */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1100 | ct->proto.tcp.seen[0].td_end = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1101 | segment_seq_plus_len(ntohl(th->seq), skb->len, |
| 1102 | dataoff, th); |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1103 | ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window); |
| 1104 | if (ct->proto.tcp.seen[0].td_maxwin == 0) |
| 1105 | ct->proto.tcp.seen[0].td_maxwin = 1; |
| 1106 | ct->proto.tcp.seen[0].td_maxend = |
| 1107 | ct->proto.tcp.seen[0].td_end; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1108 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1109 | tcp_options(skb, dataoff, th, &ct->proto.tcp.seen[0]); |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1110 | } else if (tn->tcp_loose == 0) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1111 | /* Don't try to pick up connections. */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 1112 | return false; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1113 | } else { |
Changli Gao | e5fc9e7 | 2010-11-12 17:33:17 +0100 | [diff] [blame] | 1114 | memset(&ct->proto.tcp, 0, sizeof(ct->proto.tcp)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1115 | /* |
| 1116 | * We are in the middle of a connection, |
| 1117 | * its history is lost for us. |
| 1118 | * Let's try to use the data from the packet. |
| 1119 | */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1120 | ct->proto.tcp.seen[0].td_end = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1121 | segment_seq_plus_len(ntohl(th->seq), skb->len, |
| 1122 | dataoff, th); |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1123 | ct->proto.tcp.seen[0].td_maxwin = ntohs(th->window); |
| 1124 | if (ct->proto.tcp.seen[0].td_maxwin == 0) |
| 1125 | ct->proto.tcp.seen[0].td_maxwin = 1; |
| 1126 | ct->proto.tcp.seen[0].td_maxend = |
| 1127 | ct->proto.tcp.seen[0].td_end + |
| 1128 | ct->proto.tcp.seen[0].td_maxwin; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1129 | |
Patrick McHardy | a09113c | 2007-02-07 15:05:33 -0800 | [diff] [blame] | 1130 | /* We assume SACK and liberal window checking to handle |
| 1131 | * window scaling */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1132 | ct->proto.tcp.seen[0].flags = |
| 1133 | ct->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM | |
| 1134 | IP_CT_TCP_FLAG_BE_LIBERAL; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1135 | } |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1136 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1137 | /* tcp_packet will set them */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 1138 | ct->proto.tcp.last_index = TCP_NONE_SET; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1139 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 1140 | pr_debug("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i " |
| 1141 | "receiver end=%u maxend=%u maxwin=%u scale=%i\n", |
| 1142 | sender->td_end, sender->td_maxend, sender->td_maxwin, |
| 1143 | sender->td_scale, |
| 1144 | receiver->td_end, receiver->td_maxend, receiver->td_maxwin, |
| 1145 | receiver->td_scale); |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 1146 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1147 | } |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1148 | |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 1149 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1150 | |
| 1151 | #include <linux/netfilter/nfnetlink.h> |
| 1152 | #include <linux/netfilter/nfnetlink_conntrack.h> |
| 1153 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1154 | static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla, |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1155 | struct nf_conn *ct) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1156 | { |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1157 | struct nlattr *nest_parms; |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1158 | struct nf_ct_tcp_flags tmp = {}; |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 1159 | |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1160 | spin_lock_bh(&ct->lock); |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1161 | nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED); |
| 1162 | if (!nest_parms) |
| 1163 | goto nla_put_failure; |
| 1164 | |
David S. Miller | 4925a45 | 2012-04-01 18:50:08 -0400 | [diff] [blame] | 1165 | if (nla_put_u8(skb, CTA_PROTOINFO_TCP_STATE, ct->proto.tcp.state) || |
| 1166 | nla_put_u8(skb, CTA_PROTOINFO_TCP_WSCALE_ORIGINAL, |
| 1167 | ct->proto.tcp.seen[0].td_scale) || |
| 1168 | nla_put_u8(skb, CTA_PROTOINFO_TCP_WSCALE_REPLY, |
| 1169 | ct->proto.tcp.seen[1].td_scale)) |
| 1170 | goto nla_put_failure; |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1171 | |
| 1172 | tmp.flags = ct->proto.tcp.seen[0].flags; |
David S. Miller | 4925a45 | 2012-04-01 18:50:08 -0400 | [diff] [blame] | 1173 | if (nla_put(skb, CTA_PROTOINFO_TCP_FLAGS_ORIGINAL, |
| 1174 | sizeof(struct nf_ct_tcp_flags), &tmp)) |
| 1175 | goto nla_put_failure; |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1176 | |
| 1177 | tmp.flags = ct->proto.tcp.seen[1].flags; |
David S. Miller | 4925a45 | 2012-04-01 18:50:08 -0400 | [diff] [blame] | 1178 | if (nla_put(skb, CTA_PROTOINFO_TCP_FLAGS_REPLY, |
| 1179 | sizeof(struct nf_ct_tcp_flags), &tmp)) |
| 1180 | goto nla_put_failure; |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1181 | spin_unlock_bh(&ct->lock); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1182 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1183 | nla_nest_end(skb, nest_parms); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1184 | |
| 1185 | return 0; |
| 1186 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1187 | nla_put_failure: |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1188 | spin_unlock_bh(&ct->lock); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1189 | return -1; |
| 1190 | } |
| 1191 | |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 1192 | static const struct nla_policy tcp_nla_policy[CTA_PROTOINFO_TCP_MAX+1] = { |
| 1193 | [CTA_PROTOINFO_TCP_STATE] = { .type = NLA_U8 }, |
| 1194 | [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] = { .type = NLA_U8 }, |
| 1195 | [CTA_PROTOINFO_TCP_WSCALE_REPLY] = { .type = NLA_U8 }, |
| 1196 | [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL] = { .len = sizeof(struct nf_ct_tcp_flags) }, |
| 1197 | [CTA_PROTOINFO_TCP_FLAGS_REPLY] = { .len = sizeof(struct nf_ct_tcp_flags) }, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1198 | }; |
| 1199 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1200 | static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1201 | { |
Stephen Hemminger | 2f0d2f1 | 2008-01-31 04:08:10 -0800 | [diff] [blame] | 1202 | struct nlattr *pattr = cda[CTA_PROTOINFO_TCP]; |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1203 | struct nlattr *tb[CTA_PROTOINFO_TCP_MAX+1]; |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 1204 | int err; |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1205 | |
| 1206 | /* updates could not contain anything about the private |
| 1207 | * protocol info, in that case skip the parsing */ |
Stephen Hemminger | 2f0d2f1 | 2008-01-31 04:08:10 -0800 | [diff] [blame] | 1208 | if (!pattr) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1209 | return 0; |
| 1210 | |
Stephen Hemminger | 2f0d2f1 | 2008-01-31 04:08:10 -0800 | [diff] [blame] | 1211 | err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, tcp_nla_policy); |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 1212 | if (err < 0) |
| 1213 | return err; |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1214 | |
Patrick McHardy | 5f7da4d | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1215 | if (tb[CTA_PROTOINFO_TCP_STATE] && |
| 1216 | nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]) >= TCP_CONNTRACK_MAX) |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1217 | return -EINVAL; |
| 1218 | |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1219 | spin_lock_bh(&ct->lock); |
Patrick McHardy | 5f7da4d | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 1220 | if (tb[CTA_PROTOINFO_TCP_STATE]) |
| 1221 | ct->proto.tcp.state = nla_get_u8(tb[CTA_PROTOINFO_TCP_STATE]); |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1222 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1223 | if (tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]) { |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1224 | struct nf_ct_tcp_flags *attr = |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1225 | nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]); |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1226 | ct->proto.tcp.seen[0].flags &= ~attr->mask; |
| 1227 | ct->proto.tcp.seen[0].flags |= attr->flags & attr->mask; |
| 1228 | } |
| 1229 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1230 | if (tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]) { |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1231 | struct nf_ct_tcp_flags *attr = |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1232 | nla_data(tb[CTA_PROTOINFO_TCP_FLAGS_REPLY]); |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1233 | ct->proto.tcp.seen[1].flags &= ~attr->mask; |
| 1234 | ct->proto.tcp.seen[1].flags |= attr->flags & attr->mask; |
| 1235 | } |
| 1236 | |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 1237 | if (tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL] && |
| 1238 | tb[CTA_PROTOINFO_TCP_WSCALE_REPLY] && |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1239 | ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_WINDOW_SCALE && |
| 1240 | ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_WINDOW_SCALE) { |
Patrick McHardy | 77236b6 | 2007-12-17 22:29:45 -0800 | [diff] [blame] | 1241 | ct->proto.tcp.seen[0].td_scale = |
| 1242 | nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]); |
| 1243 | ct->proto.tcp.seen[1].td_scale = |
| 1244 | nla_get_u8(tb[CTA_PROTOINFO_TCP_WSCALE_REPLY]); |
Pablo Neira Ayuso | c8e2078 | 2007-03-14 16:45:19 -0700 | [diff] [blame] | 1245 | } |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 1246 | spin_unlock_bh(&ct->lock); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 1250 | |
| 1251 | static int tcp_nlattr_size(void) |
| 1252 | { |
| 1253 | return nla_total_size(0) /* CTA_PROTOINFO_TCP */ |
| 1254 | + nla_policy_len(tcp_nla_policy, CTA_PROTOINFO_TCP_MAX + 1); |
| 1255 | } |
| 1256 | |
| 1257 | static int tcp_nlattr_tuple_size(void) |
| 1258 | { |
| 1259 | return nla_policy_len(nf_ct_port_nla_policy, CTA_PROTO_MAX + 1); |
| 1260 | } |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1261 | #endif |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1262 | |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1263 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 1264 | |
| 1265 | #include <linux/netfilter/nfnetlink.h> |
| 1266 | #include <linux/netfilter/nfnetlink_cttimeout.h> |
| 1267 | |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 1268 | static int tcp_timeout_nlattr_to_obj(struct nlattr *tb[], |
| 1269 | struct net *net, void *data) |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1270 | { |
| 1271 | unsigned int *timeouts = data; |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 1272 | struct nf_tcp_net *tn = tcp_pernet(net); |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1273 | int i; |
| 1274 | |
| 1275 | /* set default TCP timeouts. */ |
| 1276 | for (i=0; i<TCP_CONNTRACK_TIMEOUT_MAX; i++) |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 1277 | timeouts[i] = tn->timeouts[i]; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1278 | |
| 1279 | if (tb[CTA_TIMEOUT_TCP_SYN_SENT]) { |
| 1280 | timeouts[TCP_CONNTRACK_SYN_SENT] = |
| 1281 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_SENT]))*HZ; |
| 1282 | } |
| 1283 | if (tb[CTA_TIMEOUT_TCP_SYN_RECV]) { |
| 1284 | timeouts[TCP_CONNTRACK_SYN_RECV] = |
| 1285 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_RECV]))*HZ; |
| 1286 | } |
| 1287 | if (tb[CTA_TIMEOUT_TCP_ESTABLISHED]) { |
| 1288 | timeouts[TCP_CONNTRACK_ESTABLISHED] = |
| 1289 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_ESTABLISHED]))*HZ; |
| 1290 | } |
| 1291 | if (tb[CTA_TIMEOUT_TCP_FIN_WAIT]) { |
| 1292 | timeouts[TCP_CONNTRACK_FIN_WAIT] = |
| 1293 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_FIN_WAIT]))*HZ; |
| 1294 | } |
| 1295 | if (tb[CTA_TIMEOUT_TCP_CLOSE_WAIT]) { |
| 1296 | timeouts[TCP_CONNTRACK_CLOSE_WAIT] = |
| 1297 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_CLOSE_WAIT]))*HZ; |
| 1298 | } |
| 1299 | if (tb[CTA_TIMEOUT_TCP_LAST_ACK]) { |
| 1300 | timeouts[TCP_CONNTRACK_LAST_ACK] = |
| 1301 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_LAST_ACK]))*HZ; |
| 1302 | } |
| 1303 | if (tb[CTA_TIMEOUT_TCP_TIME_WAIT]) { |
| 1304 | timeouts[TCP_CONNTRACK_TIME_WAIT] = |
| 1305 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_TIME_WAIT]))*HZ; |
| 1306 | } |
| 1307 | if (tb[CTA_TIMEOUT_TCP_CLOSE]) { |
| 1308 | timeouts[TCP_CONNTRACK_CLOSE] = |
| 1309 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_CLOSE]))*HZ; |
| 1310 | } |
| 1311 | if (tb[CTA_TIMEOUT_TCP_SYN_SENT2]) { |
| 1312 | timeouts[TCP_CONNTRACK_SYN_SENT2] = |
| 1313 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_SENT2]))*HZ; |
| 1314 | } |
| 1315 | if (tb[CTA_TIMEOUT_TCP_RETRANS]) { |
| 1316 | timeouts[TCP_CONNTRACK_RETRANS] = |
| 1317 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_RETRANS]))*HZ; |
| 1318 | } |
| 1319 | if (tb[CTA_TIMEOUT_TCP_UNACK]) { |
| 1320 | timeouts[TCP_CONNTRACK_UNACK] = |
| 1321 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_UNACK]))*HZ; |
| 1322 | } |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | static int |
| 1327 | tcp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) |
| 1328 | { |
| 1329 | const unsigned int *timeouts = data; |
| 1330 | |
David S. Miller | 4925a45 | 2012-04-01 18:50:08 -0400 | [diff] [blame] | 1331 | if (nla_put_be32(skb, CTA_TIMEOUT_TCP_SYN_SENT, |
| 1332 | htonl(timeouts[TCP_CONNTRACK_SYN_SENT] / HZ)) || |
| 1333 | nla_put_be32(skb, CTA_TIMEOUT_TCP_SYN_RECV, |
| 1334 | htonl(timeouts[TCP_CONNTRACK_SYN_RECV] / HZ)) || |
| 1335 | nla_put_be32(skb, CTA_TIMEOUT_TCP_ESTABLISHED, |
| 1336 | htonl(timeouts[TCP_CONNTRACK_ESTABLISHED] / HZ)) || |
| 1337 | nla_put_be32(skb, CTA_TIMEOUT_TCP_FIN_WAIT, |
| 1338 | htonl(timeouts[TCP_CONNTRACK_FIN_WAIT] / HZ)) || |
| 1339 | nla_put_be32(skb, CTA_TIMEOUT_TCP_CLOSE_WAIT, |
| 1340 | htonl(timeouts[TCP_CONNTRACK_CLOSE_WAIT] / HZ)) || |
| 1341 | nla_put_be32(skb, CTA_TIMEOUT_TCP_LAST_ACK, |
| 1342 | htonl(timeouts[TCP_CONNTRACK_LAST_ACK] / HZ)) || |
| 1343 | nla_put_be32(skb, CTA_TIMEOUT_TCP_TIME_WAIT, |
| 1344 | htonl(timeouts[TCP_CONNTRACK_TIME_WAIT] / HZ)) || |
| 1345 | nla_put_be32(skb, CTA_TIMEOUT_TCP_CLOSE, |
| 1346 | htonl(timeouts[TCP_CONNTRACK_CLOSE] / HZ)) || |
| 1347 | nla_put_be32(skb, CTA_TIMEOUT_TCP_SYN_SENT2, |
| 1348 | htonl(timeouts[TCP_CONNTRACK_SYN_SENT2] / HZ)) || |
| 1349 | nla_put_be32(skb, CTA_TIMEOUT_TCP_RETRANS, |
| 1350 | htonl(timeouts[TCP_CONNTRACK_RETRANS] / HZ)) || |
| 1351 | nla_put_be32(skb, CTA_TIMEOUT_TCP_UNACK, |
| 1352 | htonl(timeouts[TCP_CONNTRACK_UNACK] / HZ))) |
| 1353 | goto nla_put_failure; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1354 | return 0; |
| 1355 | |
| 1356 | nla_put_failure: |
| 1357 | return -ENOSPC; |
| 1358 | } |
| 1359 | |
| 1360 | static const struct nla_policy tcp_timeout_nla_policy[CTA_TIMEOUT_TCP_MAX+1] = { |
| 1361 | [CTA_TIMEOUT_TCP_SYN_SENT] = { .type = NLA_U32 }, |
| 1362 | [CTA_TIMEOUT_TCP_SYN_RECV] = { .type = NLA_U32 }, |
| 1363 | [CTA_TIMEOUT_TCP_ESTABLISHED] = { .type = NLA_U32 }, |
| 1364 | [CTA_TIMEOUT_TCP_FIN_WAIT] = { .type = NLA_U32 }, |
| 1365 | [CTA_TIMEOUT_TCP_CLOSE_WAIT] = { .type = NLA_U32 }, |
| 1366 | [CTA_TIMEOUT_TCP_LAST_ACK] = { .type = NLA_U32 }, |
| 1367 | [CTA_TIMEOUT_TCP_TIME_WAIT] = { .type = NLA_U32 }, |
| 1368 | [CTA_TIMEOUT_TCP_CLOSE] = { .type = NLA_U32 }, |
| 1369 | [CTA_TIMEOUT_TCP_SYN_SENT2] = { .type = NLA_U32 }, |
Florian Westphal | 6d1fafc | 2012-11-22 01:32:46 +0000 | [diff] [blame] | 1370 | [CTA_TIMEOUT_TCP_RETRANS] = { .type = NLA_U32 }, |
| 1371 | [CTA_TIMEOUT_TCP_UNACK] = { .type = NLA_U32 }, |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1372 | }; |
| 1373 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
| 1374 | |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1375 | #ifdef CONFIG_SYSCTL |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1376 | static struct ctl_table tcp_sysctl_table[] = { |
| 1377 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1378 | .procname = "nf_conntrack_tcp_timeout_syn_sent", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1379 | .maxlen = sizeof(unsigned int), |
| 1380 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1381 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1382 | }, |
| 1383 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1384 | .procname = "nf_conntrack_tcp_timeout_syn_recv", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1385 | .maxlen = sizeof(unsigned int), |
| 1386 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1387 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1388 | }, |
| 1389 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1390 | .procname = "nf_conntrack_tcp_timeout_established", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1391 | .maxlen = sizeof(unsigned int), |
| 1392 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1393 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1394 | }, |
| 1395 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1396 | .procname = "nf_conntrack_tcp_timeout_fin_wait", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1397 | .maxlen = sizeof(unsigned int), |
| 1398 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1399 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1400 | }, |
| 1401 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1402 | .procname = "nf_conntrack_tcp_timeout_close_wait", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1403 | .maxlen = sizeof(unsigned int), |
| 1404 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1405 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1406 | }, |
| 1407 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1408 | .procname = "nf_conntrack_tcp_timeout_last_ack", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1409 | .maxlen = sizeof(unsigned int), |
| 1410 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1411 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1412 | }, |
| 1413 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1414 | .procname = "nf_conntrack_tcp_timeout_time_wait", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1415 | .maxlen = sizeof(unsigned int), |
| 1416 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1417 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1418 | }, |
| 1419 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1420 | .procname = "nf_conntrack_tcp_timeout_close", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1421 | .maxlen = sizeof(unsigned int), |
| 1422 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1423 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1424 | }, |
| 1425 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1426 | .procname = "nf_conntrack_tcp_timeout_max_retrans", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1427 | .maxlen = sizeof(unsigned int), |
| 1428 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1429 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1430 | }, |
| 1431 | { |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1432 | .procname = "nf_conntrack_tcp_timeout_unacknowledged", |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1433 | .maxlen = sizeof(unsigned int), |
| 1434 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1435 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | ae37504 | 2008-07-31 00:38:01 -0700 | [diff] [blame] | 1436 | }, |
| 1437 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1438 | .procname = "nf_conntrack_tcp_loose", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1439 | .maxlen = sizeof(unsigned int), |
| 1440 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1441 | .proc_handler = proc_dointvec, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1442 | }, |
| 1443 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1444 | .procname = "nf_conntrack_tcp_be_liberal", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1445 | .maxlen = sizeof(unsigned int), |
| 1446 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1447 | .proc_handler = proc_dointvec, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1448 | }, |
| 1449 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1450 | .procname = "nf_conntrack_tcp_max_retrans", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1451 | .maxlen = sizeof(unsigned int), |
| 1452 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1453 | .proc_handler = proc_dointvec, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1454 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1455 | { } |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1456 | }; |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1457 | |
| 1458 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT |
| 1459 | static struct ctl_table tcp_compat_sysctl_table[] = { |
| 1460 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1461 | .procname = "ip_conntrack_tcp_timeout_syn_sent", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1462 | .maxlen = sizeof(unsigned int), |
| 1463 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1464 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1465 | }, |
| 1466 | { |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 1467 | .procname = "ip_conntrack_tcp_timeout_syn_sent2", |
Jozsef Kadlecsik | 874ab92 | 2009-06-02 13:58:56 +0200 | [diff] [blame] | 1468 | .maxlen = sizeof(unsigned int), |
| 1469 | .mode = 0644, |
| 1470 | .proc_handler = proc_dointvec_jiffies, |
| 1471 | }, |
| 1472 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1473 | .procname = "ip_conntrack_tcp_timeout_syn_recv", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1474 | .maxlen = sizeof(unsigned int), |
| 1475 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1476 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1477 | }, |
| 1478 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1479 | .procname = "ip_conntrack_tcp_timeout_established", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1480 | .maxlen = sizeof(unsigned int), |
| 1481 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1482 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1483 | }, |
| 1484 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1485 | .procname = "ip_conntrack_tcp_timeout_fin_wait", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1486 | .maxlen = sizeof(unsigned int), |
| 1487 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1488 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1489 | }, |
| 1490 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1491 | .procname = "ip_conntrack_tcp_timeout_close_wait", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1492 | .maxlen = sizeof(unsigned int), |
| 1493 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1494 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1495 | }, |
| 1496 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1497 | .procname = "ip_conntrack_tcp_timeout_last_ack", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1498 | .maxlen = sizeof(unsigned int), |
| 1499 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1500 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1501 | }, |
| 1502 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1503 | .procname = "ip_conntrack_tcp_timeout_time_wait", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1504 | .maxlen = sizeof(unsigned int), |
| 1505 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1506 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1507 | }, |
| 1508 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1509 | .procname = "ip_conntrack_tcp_timeout_close", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1510 | .maxlen = sizeof(unsigned int), |
| 1511 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1512 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1513 | }, |
| 1514 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1515 | .procname = "ip_conntrack_tcp_timeout_max_retrans", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1516 | .maxlen = sizeof(unsigned int), |
| 1517 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1518 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1519 | }, |
| 1520 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1521 | .procname = "ip_conntrack_tcp_loose", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1522 | .maxlen = sizeof(unsigned int), |
| 1523 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1524 | .proc_handler = proc_dointvec, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1525 | }, |
| 1526 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1527 | .procname = "ip_conntrack_tcp_be_liberal", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1528 | .maxlen = sizeof(unsigned int), |
| 1529 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1530 | .proc_handler = proc_dointvec, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1531 | }, |
| 1532 | { |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1533 | .procname = "ip_conntrack_tcp_max_retrans", |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1534 | .maxlen = sizeof(unsigned int), |
| 1535 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1536 | .proc_handler = proc_dointvec, |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1537 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1538 | { } |
Patrick McHardy | a999e68 | 2006-11-29 02:35:20 +0100 | [diff] [blame] | 1539 | }; |
| 1540 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 1541 | #endif /* CONFIG_SYSCTL */ |
| 1542 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1543 | static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn, |
| 1544 | struct nf_tcp_net *tn) |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1545 | { |
| 1546 | #ifdef CONFIG_SYSCTL |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1547 | if (pn->ctl_table) |
| 1548 | return 0; |
| 1549 | |
| 1550 | pn->ctl_table = kmemdup(tcp_sysctl_table, |
| 1551 | sizeof(tcp_sysctl_table), |
| 1552 | GFP_KERNEL); |
| 1553 | if (!pn->ctl_table) |
| 1554 | return -ENOMEM; |
| 1555 | |
| 1556 | pn->ctl_table[0].data = &tn->timeouts[TCP_CONNTRACK_SYN_SENT]; |
| 1557 | pn->ctl_table[1].data = &tn->timeouts[TCP_CONNTRACK_SYN_RECV]; |
| 1558 | pn->ctl_table[2].data = &tn->timeouts[TCP_CONNTRACK_ESTABLISHED]; |
| 1559 | pn->ctl_table[3].data = &tn->timeouts[TCP_CONNTRACK_FIN_WAIT]; |
| 1560 | pn->ctl_table[4].data = &tn->timeouts[TCP_CONNTRACK_CLOSE_WAIT]; |
| 1561 | pn->ctl_table[5].data = &tn->timeouts[TCP_CONNTRACK_LAST_ACK]; |
| 1562 | pn->ctl_table[6].data = &tn->timeouts[TCP_CONNTRACK_TIME_WAIT]; |
| 1563 | pn->ctl_table[7].data = &tn->timeouts[TCP_CONNTRACK_CLOSE]; |
| 1564 | pn->ctl_table[8].data = &tn->timeouts[TCP_CONNTRACK_RETRANS]; |
| 1565 | pn->ctl_table[9].data = &tn->timeouts[TCP_CONNTRACK_UNACK]; |
| 1566 | pn->ctl_table[10].data = &tn->tcp_loose; |
| 1567 | pn->ctl_table[11].data = &tn->tcp_be_liberal; |
| 1568 | pn->ctl_table[12].data = &tn->tcp_max_retrans; |
| 1569 | #endif |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1573 | static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn, |
| 1574 | struct nf_tcp_net *tn) |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1575 | { |
| 1576 | #ifdef CONFIG_SYSCTL |
| 1577 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1578 | pn->ctl_compat_table = kmemdup(tcp_compat_sysctl_table, |
| 1579 | sizeof(tcp_compat_sysctl_table), |
| 1580 | GFP_KERNEL); |
| 1581 | if (!pn->ctl_compat_table) |
| 1582 | return -ENOMEM; |
| 1583 | |
| 1584 | pn->ctl_compat_table[0].data = &tn->timeouts[TCP_CONNTRACK_SYN_SENT]; |
| 1585 | pn->ctl_compat_table[1].data = &tn->timeouts[TCP_CONNTRACK_SYN_SENT2]; |
| 1586 | pn->ctl_compat_table[2].data = &tn->timeouts[TCP_CONNTRACK_SYN_RECV]; |
| 1587 | pn->ctl_compat_table[3].data = &tn->timeouts[TCP_CONNTRACK_ESTABLISHED]; |
| 1588 | pn->ctl_compat_table[4].data = &tn->timeouts[TCP_CONNTRACK_FIN_WAIT]; |
| 1589 | pn->ctl_compat_table[5].data = &tn->timeouts[TCP_CONNTRACK_CLOSE_WAIT]; |
| 1590 | pn->ctl_compat_table[6].data = &tn->timeouts[TCP_CONNTRACK_LAST_ACK]; |
| 1591 | pn->ctl_compat_table[7].data = &tn->timeouts[TCP_CONNTRACK_TIME_WAIT]; |
| 1592 | pn->ctl_compat_table[8].data = &tn->timeouts[TCP_CONNTRACK_CLOSE]; |
| 1593 | pn->ctl_compat_table[9].data = &tn->timeouts[TCP_CONNTRACK_RETRANS]; |
| 1594 | pn->ctl_compat_table[10].data = &tn->tcp_loose; |
| 1595 | pn->ctl_compat_table[11].data = &tn->tcp_be_liberal; |
| 1596 | pn->ctl_compat_table[12].data = &tn->tcp_max_retrans; |
| 1597 | #endif |
| 1598 | #endif |
| 1599 | return 0; |
| 1600 | } |
| 1601 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1602 | static int tcp_init_net(struct net *net, u_int16_t proto) |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1603 | { |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1604 | int ret; |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1605 | struct nf_tcp_net *tn = tcp_pernet(net); |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1606 | struct nf_proto_net *pn = &tn->pn; |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1607 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1608 | if (!pn->users) { |
| 1609 | int i; |
| 1610 | |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1611 | for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++) |
| 1612 | tn->timeouts[i] = tcp_timeouts[i]; |
| 1613 | |
| 1614 | tn->tcp_loose = nf_ct_tcp_loose; |
| 1615 | tn->tcp_be_liberal = nf_ct_tcp_be_liberal; |
| 1616 | tn->tcp_max_retrans = nf_ct_tcp_max_retrans; |
| 1617 | } |
| 1618 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1619 | if (proto == AF_INET) { |
| 1620 | ret = tcp_kmemdup_compat_sysctl_table(pn, tn); |
| 1621 | if (ret < 0) |
| 1622 | return ret; |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1623 | |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1624 | ret = tcp_kmemdup_sysctl_table(pn, tn); |
| 1625 | if (ret < 0) |
| 1626 | nf_ct_kfree_compat_sysctl_table(pn); |
| 1627 | } else |
| 1628 | ret = tcp_kmemdup_sysctl_table(pn, tn); |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1629 | |
Gao feng | d2ba1fd | 2012-05-28 21:04:12 +0000 | [diff] [blame] | 1630 | return ret; |
| 1631 | } |
| 1632 | |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 1633 | static struct nf_proto_net *tcp_get_net_proto(struct net *net) |
| 1634 | { |
| 1635 | return &net->ct.nf_ct_proto.tcp.pn; |
| 1636 | } |
| 1637 | |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 1638 | struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1639 | { |
| 1640 | .l3proto = PF_INET, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 1641 | .l4proto = IPPROTO_TCP, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1642 | .name = "tcp", |
| 1643 | .pkt_to_tuple = tcp_pkt_to_tuple, |
| 1644 | .invert_tuple = tcp_invert_tuple, |
| 1645 | .print_tuple = tcp_print_tuple, |
| 1646 | .print_conntrack = tcp_print_conntrack, |
| 1647 | .packet = tcp_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1648 | .get_timeouts = tcp_get_timeouts, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1649 | .new = tcp_new, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 1650 | .error = tcp_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 1651 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1652 | .to_nlattr = tcp_to_nlattr, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 1653 | .nlattr_size = tcp_nlattr_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1654 | .from_nlattr = nlattr_to_tcp, |
| 1655 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
| 1656 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 1657 | .nlattr_tuple_size = tcp_nlattr_tuple_size, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 1658 | .nla_policy = nf_ct_port_nla_policy, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1659 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1660 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 1661 | .ctnl_timeout = { |
| 1662 | .nlattr_to_obj = tcp_timeout_nlattr_to_obj, |
| 1663 | .obj_to_nlattr = tcp_timeout_obj_to_nlattr, |
| 1664 | .nlattr_max = CTA_TIMEOUT_TCP_MAX, |
| 1665 | .obj_size = sizeof(unsigned int) * |
| 1666 | TCP_CONNTRACK_TIMEOUT_MAX, |
| 1667 | .nla_policy = tcp_timeout_nla_policy, |
| 1668 | }, |
| 1669 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1670 | .init_net = tcp_init_net, |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 1671 | .get_net_proto = tcp_get_net_proto, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1672 | }; |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 1673 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1674 | |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 1675 | struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1676 | { |
| 1677 | .l3proto = PF_INET6, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 1678 | .l4proto = IPPROTO_TCP, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1679 | .name = "tcp", |
| 1680 | .pkt_to_tuple = tcp_pkt_to_tuple, |
| 1681 | .invert_tuple = tcp_invert_tuple, |
| 1682 | .print_tuple = tcp_print_tuple, |
| 1683 | .print_conntrack = tcp_print_conntrack, |
| 1684 | .packet = tcp_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 1685 | .get_timeouts = tcp_get_timeouts, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1686 | .new = tcp_new, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 1687 | .error = tcp_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 1688 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1689 | .to_nlattr = tcp_to_nlattr, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 1690 | .nlattr_size = tcp_nlattr_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 1691 | .from_nlattr = nlattr_to_tcp, |
| 1692 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
| 1693 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 1694 | .nlattr_tuple_size = tcp_nlattr_tuple_size, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 1695 | .nla_policy = nf_ct_port_nla_policy, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 1696 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 1697 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 1698 | .ctnl_timeout = { |
| 1699 | .nlattr_to_obj = tcp_timeout_nlattr_to_obj, |
| 1700 | .obj_to_nlattr = tcp_timeout_obj_to_nlattr, |
| 1701 | .nlattr_max = CTA_TIMEOUT_TCP_MAX, |
| 1702 | .obj_size = sizeof(unsigned int) * |
| 1703 | TCP_CONNTRACK_TIMEOUT_MAX, |
| 1704 | .nla_policy = tcp_timeout_nla_policy, |
| 1705 | }, |
| 1706 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | efa758f | 2012-06-21 04:36:43 +0000 | [diff] [blame] | 1707 | .init_net = tcp_init_net, |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 1708 | .get_net_proto = tcp_get_net_proto, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1709 | }; |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 1710 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6); |