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