aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/netfilter/ip_conntrack_proto_tcp.c')
-rw-r--r--net/ipv4/netfilter/ip_conntrack_proto_tcp.c276
1 files changed, 138 insertions, 138 deletions
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
index c34f48fe547..fa35b49fe2f 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
@@ -45,8 +45,8 @@
45/* Protects conntrack->proto.tcp */ 45/* Protects conntrack->proto.tcp */
46static DEFINE_RWLOCK(tcp_lock); 46static DEFINE_RWLOCK(tcp_lock);
47 47
48/* "Be conservative in what you do, 48/* "Be conservative in what you do,
49 be liberal in what you accept from others." 49 be liberal in what you accept from others."
50 If it's non-zero, we mark only out of window RST segments as INVALID. */ 50 If it's non-zero, we mark only out of window RST segments as INVALID. */
51int ip_ct_tcp_be_liberal __read_mostly = 0; 51int ip_ct_tcp_be_liberal __read_mostly = 0;
52 52
@@ -54,8 +54,8 @@ int ip_ct_tcp_be_liberal __read_mostly = 0;
54 connections. */ 54 connections. */
55int ip_ct_tcp_loose __read_mostly = 1; 55int ip_ct_tcp_loose __read_mostly = 1;
56 56
57/* Max number of the retransmitted packets without receiving an (acceptable) 57/* Max number of the retransmitted packets without receiving an (acceptable)
58 ACK from the destination. If this number is reached, a shorter timer 58 ACK from the destination. If this number is reached, a shorter timer
59 will be started. */ 59 will be started. */
60int ip_ct_tcp_max_retrans __read_mostly = 3; 60int ip_ct_tcp_max_retrans __read_mostly = 3;
61 61
@@ -74,7 +74,7 @@ static const char *tcp_conntrack_names[] = {
74 "CLOSE", 74 "CLOSE",
75 "LISTEN" 75 "LISTEN"
76}; 76};
77 77
78#define SECS * HZ 78#define SECS * HZ
79#define MINS * 60 SECS 79#define MINS * 60 SECS
80#define HOURS * 60 MINS 80#define HOURS * 60 MINS
@@ -90,10 +90,10 @@ unsigned int ip_ct_tcp_timeout_time_wait __read_mostly = 2 MINS;
90unsigned int ip_ct_tcp_timeout_close __read_mostly = 10 SECS; 90unsigned int ip_ct_tcp_timeout_close __read_mostly = 10 SECS;
91 91
92/* RFC1122 says the R2 limit should be at least 100 seconds. 92/* RFC1122 says the R2 limit should be at least 100 seconds.
93 Linux uses 15 packets as limit, which corresponds 93 Linux uses 15 packets as limit, which corresponds
94 to ~13-30min depending on RTO. */ 94 to ~13-30min depending on RTO. */
95unsigned int ip_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS; 95unsigned int ip_ct_tcp_timeout_max_retrans __read_mostly = 5 MINS;
96 96
97static const unsigned int * tcp_timeouts[] 97static const unsigned int * tcp_timeouts[]
98= { NULL, /* TCP_CONNTRACK_NONE */ 98= { NULL, /* TCP_CONNTRACK_NONE */
99 &ip_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */ 99 &ip_ct_tcp_timeout_syn_sent, /* TCP_CONNTRACK_SYN_SENT, */
@@ -106,7 +106,7 @@ static const unsigned int * tcp_timeouts[]
106 &ip_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */ 106 &ip_ct_tcp_timeout_close, /* TCP_CONNTRACK_CLOSE, */
107 NULL, /* TCP_CONNTRACK_LISTEN */ 107 NULL, /* TCP_CONNTRACK_LISTEN */
108 }; 108 };
109 109
110#define sNO TCP_CONNTRACK_NONE 110#define sNO TCP_CONNTRACK_NONE
111#define sSS TCP_CONNTRACK_SYN_SENT 111#define sSS TCP_CONNTRACK_SYN_SENT
112#define sSR TCP_CONNTRACK_SYN_RECV 112#define sSR TCP_CONNTRACK_SYN_RECV
@@ -129,13 +129,13 @@ enum tcp_bit_set {
129 TCP_RST_SET, 129 TCP_RST_SET,
130 TCP_NONE_SET, 130 TCP_NONE_SET,
131}; 131};
132 132
133/* 133/*
134 * The TCP state transition table needs a few words... 134 * The TCP state transition table needs a few words...
135 * 135 *
136 * We are the man in the middle. All the packets go through us 136 * We are the man in the middle. All the packets go through us
137 * but might get lost in transit to the destination. 137 * but might get lost in transit to the destination.
138 * It is assumed that the destinations can't receive segments 138 * It is assumed that the destinations can't receive segments
139 * we haven't seen. 139 * we haven't seen.
140 * 140 *
141 * The checked segment is in window, but our windows are *not* 141 * The checked segment is in window, but our windows are *not*
@@ -145,11 +145,11 @@ enum tcp_bit_set {
145 * The meaning of the states are: 145 * The meaning of the states are:
146 * 146 *
147 * NONE: initial state 147 * NONE: initial state
148 * SYN_SENT: SYN-only packet seen 148 * SYN_SENT: SYN-only packet seen
149 * SYN_RECV: SYN-ACK packet seen 149 * SYN_RECV: SYN-ACK packet seen
150 * ESTABLISHED: ACK packet seen 150 * ESTABLISHED: ACK packet seen
151 * FIN_WAIT: FIN packet seen 151 * FIN_WAIT: FIN packet seen
152 * CLOSE_WAIT: ACK seen (after FIN) 152 * CLOSE_WAIT: ACK seen (after FIN)
153 * LAST_ACK: FIN seen (after FIN) 153 * LAST_ACK: FIN seen (after FIN)
154 * TIME_WAIT: last ACK seen 154 * TIME_WAIT: last ACK seen
155 * CLOSE: closed connection 155 * CLOSE: closed connection
@@ -157,8 +157,8 @@ enum tcp_bit_set {
157 * LISTEN state is not used. 157 * LISTEN state is not used.
158 * 158 *
159 * Packets marked as IGNORED (sIG): 159 * Packets marked as IGNORED (sIG):
160 * if they may be either invalid or valid 160 * if they may be either invalid or valid
161 * and the receiver may send back a connection 161 * and the receiver may send back a connection
162 * closing RST or a SYN/ACK. 162 * closing RST or a SYN/ACK.
163 * 163 *
164 * Packets marked as INVALID (sIV): 164 * Packets marked as INVALID (sIV):
@@ -175,7 +175,7 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
175 * sSS -> sSS Retransmitted SYN 175 * sSS -> sSS Retransmitted SYN
176 * sSR -> sIG Late retransmitted SYN? 176 * sSR -> sIG Late retransmitted SYN?
177 * sES -> sIG Error: SYNs in window outside the SYN_SENT state 177 * sES -> sIG Error: SYNs in window outside the SYN_SENT state
178 * are errors. Receiver will reply with RST 178 * are errors. Receiver will reply with RST
179 * and close the connection. 179 * and close the connection.
180 * Or we are not in sync and hold a dead connection. 180 * Or we are not in sync and hold a dead connection.
181 * sFW -> sIG 181 * sFW -> sIG
@@ -188,10 +188,10 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
188/*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }, 188/*synack*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV },
189/* 189/*
190 * A SYN/ACK from the client is always invalid: 190 * A SYN/ACK from the client is always invalid:
191 * - either it tries to set up a simultaneous open, which is 191 * - either it tries to set up a simultaneous open, which is
192 * not supported; 192 * not supported;
193 * - or the firewall has just been inserted between the two hosts 193 * - or the firewall has just been inserted between the two hosts
194 * during the session set-up. The SYN will be retransmitted 194 * during the session set-up. The SYN will be retransmitted
195 * by the true client (or it'll time out). 195 * by the true client (or it'll time out).
196 */ 196 */
197/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */ 197/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
@@ -201,9 +201,9 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
201 * sSS -> sIV Client migth not send FIN in this state: 201 * sSS -> sIV Client migth not send FIN in this state:
202 * we enforce waiting for a SYN/ACK reply first. 202 * we enforce waiting for a SYN/ACK reply first.
203 * sSR -> sFW Close started. 203 * sSR -> sFW Close started.
204 * sES -> sFW 204 * sES -> sFW
205 * sFW -> sLA FIN seen in both directions, waiting for 205 * sFW -> sLA FIN seen in both directions, waiting for
206 * the last ACK. 206 * the last ACK.
207 * Migth be a retransmitted FIN as well... 207 * Migth be a retransmitted FIN as well...
208 * sCW -> sLA 208 * sCW -> sLA
209 * sLA -> sLA Retransmitted FIN. Remain in the same state. 209 * sLA -> sLA Retransmitted FIN. Remain in the same state.
@@ -281,7 +281,7 @@ static const enum tcp_conntrack tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
281/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */ 281/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sLI */
282/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV }, 282/*rst*/ { sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL, sIV },
283/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV } 283/*none*/ { sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV, sIV }
284 } 284 }
285}; 285};
286 286
287static int tcp_pkt_to_tuple(const struct sk_buff *skb, 287static int tcp_pkt_to_tuple(const struct sk_buff *skb,
@@ -337,7 +337,7 @@ static int tcp_to_nfattr(struct sk_buff *skb, struct nfattr *nfa,
337 const struct ip_conntrack *ct) 337 const struct ip_conntrack *ct)
338{ 338{
339 struct nfattr *nest_parms; 339 struct nfattr *nest_parms;
340 340
341 read_lock_bh(&tcp_lock); 341 read_lock_bh(&tcp_lock);
342 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP); 342 nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP);
343 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t), 343 NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t),
@@ -367,7 +367,7 @@ static int nfattr_to_tcp(struct nfattr *cda[], struct ip_conntrack *ct)
367 if (!attr) 367 if (!attr)
368 return 0; 368 return 0;
369 369
370 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr); 370 nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr);
371 371
372 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp)) 372 if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp))
373 return -EINVAL; 373 return -EINVAL;
@@ -376,7 +376,7 @@ static int nfattr_to_tcp(struct nfattr *cda[], struct ip_conntrack *ct)
376 return -EINVAL; 376 return -EINVAL;
377 377
378 write_lock_bh(&tcp_lock); 378 write_lock_bh(&tcp_lock);
379 ct->proto.tcp.state = 379 ct->proto.tcp.state =
380 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]); 380 *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]);
381 write_unlock_bh(&tcp_lock); 381 write_unlock_bh(&tcp_lock);
382 382
@@ -395,30 +395,30 @@ static unsigned int get_conntrack_index(const struct tcphdr *tcph)
395 395
396/* TCP connection tracking based on 'Real Stateful TCP Packet Filtering 396/* TCP connection tracking based on 'Real Stateful TCP Packet Filtering
397 in IP Filter' by Guido van Rooij. 397 in IP Filter' by Guido van Rooij.
398 398
399 http://www.nluug.nl/events/sane2000/papers.html 399 http://www.nluug.nl/events/sane2000/papers.html
400 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz 400 http://www.iae.nl/users/guido/papers/tcp_filtering.ps.gz
401 401
402 The boundaries and the conditions are changed according to RFC793: 402 The boundaries and the conditions are changed according to RFC793:
403 the packet must intersect the window (i.e. segments may be 403 the packet must intersect the window (i.e. segments may be
404 after the right or before the left edge) and thus receivers may ACK 404 after the right or before the left edge) and thus receivers may ACK
405 segments after the right edge of the window. 405 segments after the right edge of the window.
406 406
407 td_maxend = max(sack + max(win,1)) seen in reply packets 407 td_maxend = max(sack + max(win,1)) seen in reply packets
408 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets 408 td_maxwin = max(max(win, 1)) + (sack - ack) seen in sent packets
409 td_maxwin += seq + len - sender.td_maxend 409 td_maxwin += seq + len - sender.td_maxend
410 if seq + len > sender.td_maxend 410 if seq + len > sender.td_maxend
411 td_end = max(seq + len) seen in sent packets 411 td_end = max(seq + len) seen in sent packets
412 412
413 I. Upper bound for valid data: seq <= sender.td_maxend 413 I. Upper bound for valid data: seq <= sender.td_maxend
414 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin 414 II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin
415 III. Upper bound for valid ack: sack <= receiver.td_end 415 III. Upper bound for valid ack: sack <= receiver.td_end
416 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW 416 IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW
417 417
418 where sack is the highest right edge of sack block found in the packet. 418 where sack is the highest right edge of sack block found in the packet.
419 419
420 The upper bound limit for a valid ack is not ignored - 420 The upper bound limit for a valid ack is not ignored -
421 we doesn't have to deal with fragments. 421 we doesn't have to deal with fragments.
422*/ 422*/
423 423
424static inline __u32 segment_seq_plus_len(__u32 seq, 424static inline __u32 segment_seq_plus_len(__u32 seq,
@@ -429,25 +429,25 @@ static inline __u32 segment_seq_plus_len(__u32 seq,
429 return (seq + len - (iph->ihl + tcph->doff)*4 429 return (seq + len - (iph->ihl + tcph->doff)*4
430 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0)); 430 + (tcph->syn ? 1 : 0) + (tcph->fin ? 1 : 0));
431} 431}
432 432
433/* Fixme: what about big packets? */ 433/* Fixme: what about big packets? */
434#define MAXACKWINCONST 66000 434#define MAXACKWINCONST 66000
435#define MAXACKWINDOW(sender) \ 435#define MAXACKWINDOW(sender) \
436 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \ 436 ((sender)->td_maxwin > MAXACKWINCONST ? (sender)->td_maxwin \
437 : MAXACKWINCONST) 437 : MAXACKWINCONST)
438 438
439/* 439/*
440 * Simplified tcp_parse_options routine from tcp_input.c 440 * Simplified tcp_parse_options routine from tcp_input.c
441 */ 441 */
442static void tcp_options(const struct sk_buff *skb, 442static void tcp_options(const struct sk_buff *skb,
443 struct iphdr *iph, 443 struct iphdr *iph,
444 struct tcphdr *tcph, 444 struct tcphdr *tcph,
445 struct ip_ct_tcp_state *state) 445 struct ip_ct_tcp_state *state)
446{ 446{
447 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)]; 447 unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
448 unsigned char *ptr; 448 unsigned char *ptr;
449 int length = (tcph->doff*4) - sizeof(struct tcphdr); 449 int length = (tcph->doff*4) - sizeof(struct tcphdr);
450 450
451 if (!length) 451 if (!length)
452 return; 452 return;
453 453
@@ -456,13 +456,13 @@ static void tcp_options(const struct sk_buff *skb,
456 length, buff); 456 length, buff);
457 BUG_ON(ptr == NULL); 457 BUG_ON(ptr == NULL);
458 458
459 state->td_scale = 459 state->td_scale =
460 state->flags = 0; 460 state->flags = 0;
461 461
462 while (length > 0) { 462 while (length > 0) {
463 int opcode=*ptr++; 463 int opcode=*ptr++;
464 int opsize; 464 int opsize;
465 465
466 switch (opcode) { 466 switch (opcode) {
467 case TCPOPT_EOL: 467 case TCPOPT_EOL:
468 return; 468 return;
@@ -476,13 +476,13 @@ static void tcp_options(const struct sk_buff *skb,
476 if (opsize > length) 476 if (opsize > length)
477 break; /* don't parse partial options */ 477 break; /* don't parse partial options */
478 478
479 if (opcode == TCPOPT_SACK_PERM 479 if (opcode == TCPOPT_SACK_PERM
480 && opsize == TCPOLEN_SACK_PERM) 480 && opsize == TCPOLEN_SACK_PERM)
481 state->flags |= IP_CT_TCP_FLAG_SACK_PERM; 481 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
482 else if (opcode == TCPOPT_WINDOW 482 else if (opcode == TCPOPT_WINDOW
483 && opsize == TCPOLEN_WINDOW) { 483 && opsize == TCPOLEN_WINDOW) {
484 state->td_scale = *(u_int8_t *)ptr; 484 state->td_scale = *(u_int8_t *)ptr;
485 485
486 if (state->td_scale > 14) { 486 if (state->td_scale > 14) {
487 /* See RFC1323 */ 487 /* See RFC1323 */
488 state->td_scale = 14; 488 state->td_scale = 14;
@@ -517,16 +517,16 @@ static void tcp_sack(const struct sk_buff *skb,
517 /* Fast path for timestamp-only option */ 517 /* Fast path for timestamp-only option */
518 if (length == TCPOLEN_TSTAMP_ALIGNED*4 518 if (length == TCPOLEN_TSTAMP_ALIGNED*4
519 && *(__be32 *)ptr == 519 && *(__be32 *)ptr ==
520 __constant_htonl((TCPOPT_NOP << 24) 520 __constant_htonl((TCPOPT_NOP << 24)
521 | (TCPOPT_NOP << 16) 521 | (TCPOPT_NOP << 16)
522 | (TCPOPT_TIMESTAMP << 8) 522 | (TCPOPT_TIMESTAMP << 8)
523 | TCPOLEN_TIMESTAMP)) 523 | TCPOLEN_TIMESTAMP))
524 return; 524 return;
525 525
526 while (length > 0) { 526 while (length > 0) {
527 int opcode=*ptr++; 527 int opcode=*ptr++;
528 int opsize, i; 528 int opsize, i;
529 529
530 switch (opcode) { 530 switch (opcode) {
531 case TCPOPT_EOL: 531 case TCPOPT_EOL:
532 return; 532 return;
@@ -540,16 +540,16 @@ static void tcp_sack(const struct sk_buff *skb,
540 if (opsize > length) 540 if (opsize > length)
541 break; /* don't parse partial options */ 541 break; /* don't parse partial options */
542 542
543 if (opcode == TCPOPT_SACK 543 if (opcode == TCPOPT_SACK
544 && opsize >= (TCPOLEN_SACK_BASE 544 && opsize >= (TCPOLEN_SACK_BASE
545 + TCPOLEN_SACK_PERBLOCK) 545 + TCPOLEN_SACK_PERBLOCK)
546 && !((opsize - TCPOLEN_SACK_BASE) 546 && !((opsize - TCPOLEN_SACK_BASE)
547 % TCPOLEN_SACK_PERBLOCK)) { 547 % TCPOLEN_SACK_PERBLOCK)) {
548 for (i = 0; 548 for (i = 0;
549 i < (opsize - TCPOLEN_SACK_BASE); 549 i < (opsize - TCPOLEN_SACK_BASE);
550 i += TCPOLEN_SACK_PERBLOCK) { 550 i += TCPOLEN_SACK_PERBLOCK) {
551 tmp = ntohl(*((__be32 *)(ptr+i)+1)); 551 tmp = ntohl(*((__be32 *)(ptr+i)+1));
552 552
553 if (after(tmp, *sack)) 553 if (after(tmp, *sack))
554 *sack = tmp; 554 *sack = tmp;
555 } 555 }
@@ -561,18 +561,18 @@ static void tcp_sack(const struct sk_buff *skb,
561 } 561 }
562} 562}
563 563
564static int tcp_in_window(struct ip_ct_tcp *state, 564static int tcp_in_window(struct ip_ct_tcp *state,
565 enum ip_conntrack_dir dir, 565 enum ip_conntrack_dir dir,
566 unsigned int index, 566 unsigned int index,
567 const struct sk_buff *skb, 567 const struct sk_buff *skb,
568 struct iphdr *iph, 568 struct iphdr *iph,
569 struct tcphdr *tcph) 569 struct tcphdr *tcph)
570{ 570{
571 struct ip_ct_tcp_state *sender = &state->seen[dir]; 571 struct ip_ct_tcp_state *sender = &state->seen[dir];
572 struct ip_ct_tcp_state *receiver = &state->seen[!dir]; 572 struct ip_ct_tcp_state *receiver = &state->seen[!dir];
573 __u32 seq, ack, sack, end, win, swin; 573 __u32 seq, ack, sack, end, win, swin;
574 int res; 574 int res;
575 575
576 /* 576 /*
577 * Get the required data from the packet. 577 * Get the required data from the packet.
578 */ 578 */
@@ -580,23 +580,23 @@ static int tcp_in_window(struct ip_ct_tcp *state,
580 ack = sack = ntohl(tcph->ack_seq); 580 ack = sack = ntohl(tcph->ack_seq);
581 win = ntohs(tcph->window); 581 win = ntohs(tcph->window);
582 end = segment_seq_plus_len(seq, skb->len, iph, tcph); 582 end = segment_seq_plus_len(seq, skb->len, iph, tcph);
583 583
584 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM) 584 if (receiver->flags & IP_CT_TCP_FLAG_SACK_PERM)
585 tcp_sack(skb, iph, tcph, &sack); 585 tcp_sack(skb, iph, tcph, &sack);
586 586
587 DEBUGP("tcp_in_window: START\n"); 587 DEBUGP("tcp_in_window: START\n");
588 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 588 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
589 "seq=%u ack=%u sack=%u win=%u end=%u\n", 589 "seq=%u ack=%u sack=%u win=%u end=%u\n",
590 NIPQUAD(iph->saddr), ntohs(tcph->source), 590 NIPQUAD(iph->saddr), ntohs(tcph->source),
591 NIPQUAD(iph->daddr), ntohs(tcph->dest), 591 NIPQUAD(iph->daddr), ntohs(tcph->dest),
592 seq, ack, sack, win, end); 592 seq, ack, sack, win, end);
593 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " 593 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
594 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 594 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
595 sender->td_end, sender->td_maxend, sender->td_maxwin, 595 sender->td_end, sender->td_maxend, sender->td_maxwin,
596 sender->td_scale, 596 sender->td_scale,
597 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 597 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
598 receiver->td_scale); 598 receiver->td_scale);
599 599
600 if (sender->td_end == 0) { 600 if (sender->td_end == 0) {
601 /* 601 /*
602 * Initialize sender data. 602 * Initialize sender data.
@@ -605,26 +605,26 @@ static int tcp_in_window(struct ip_ct_tcp *state,
605 /* 605 /*
606 * Outgoing SYN-ACK in reply to a SYN. 606 * Outgoing SYN-ACK in reply to a SYN.
607 */ 607 */
608 sender->td_end = 608 sender->td_end =
609 sender->td_maxend = end; 609 sender->td_maxend = end;
610 sender->td_maxwin = (win == 0 ? 1 : win); 610 sender->td_maxwin = (win == 0 ? 1 : win);
611 611
612 tcp_options(skb, iph, tcph, sender); 612 tcp_options(skb, iph, tcph, sender);
613 /* 613 /*
614 * RFC 1323: 614 * RFC 1323:
615 * Both sides must send the Window Scale option 615 * Both sides must send the Window Scale option
616 * to enable window scaling in either direction. 616 * to enable window scaling in either direction.
617 */ 617 */
618 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE 618 if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
619 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE)) 619 && receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
620 sender->td_scale = 620 sender->td_scale =
621 receiver->td_scale = 0; 621 receiver->td_scale = 0;
622 } else { 622 } else {
623 /* 623 /*
624 * We are in the middle of a connection, 624 * We are in the middle of a connection,
625 * its history is lost for us. 625 * its history is lost for us.
626 * Let's try to use the data from the packet. 626 * Let's try to use the data from the packet.
627 */ 627 */
628 sender->td_end = end; 628 sender->td_end = end;
629 sender->td_maxwin = (win == 0 ? 1 : win); 629 sender->td_maxwin = (win == 0 ? 1 : win);
630 sender->td_maxend = end + sender->td_maxwin; 630 sender->td_maxend = end + sender->td_maxwin;
@@ -632,11 +632,11 @@ static int tcp_in_window(struct ip_ct_tcp *state,
632 } else if (((state->state == TCP_CONNTRACK_SYN_SENT 632 } else if (((state->state == TCP_CONNTRACK_SYN_SENT
633 && dir == IP_CT_DIR_ORIGINAL) 633 && dir == IP_CT_DIR_ORIGINAL)
634 || (state->state == TCP_CONNTRACK_SYN_RECV 634 || (state->state == TCP_CONNTRACK_SYN_RECV
635 && dir == IP_CT_DIR_REPLY)) 635 && dir == IP_CT_DIR_REPLY))
636 && after(end, sender->td_end)) { 636 && after(end, sender->td_end)) {
637 /* 637 /*
638 * RFC 793: "if a TCP is reinitialized ... then it need 638 * RFC 793: "if a TCP is reinitialized ... then it need
639 * not wait at all; it must only be sure to use sequence 639 * not wait at all; it must only be sure to use sequence
640 * numbers larger than those recently used." 640 * numbers larger than those recently used."
641 */ 641 */
642 sender->td_end = 642 sender->td_end =
@@ -645,14 +645,14 @@ static int tcp_in_window(struct ip_ct_tcp *state,
645 645
646 tcp_options(skb, iph, tcph, sender); 646 tcp_options(skb, iph, tcph, sender);
647 } 647 }
648 648
649 if (!(tcph->ack)) { 649 if (!(tcph->ack)) {
650 /* 650 /*
651 * If there is no ACK, just pretend it was set and OK. 651 * If there is no ACK, just pretend it was set and OK.
652 */ 652 */
653 ack = sack = receiver->td_end; 653 ack = sack = receiver->td_end;
654 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) == 654 } else if (((tcp_flag_word(tcph) & (TCP_FLAG_ACK|TCP_FLAG_RST)) ==
655 (TCP_FLAG_ACK|TCP_FLAG_RST)) 655 (TCP_FLAG_ACK|TCP_FLAG_RST))
656 && (ack == 0)) { 656 && (ack == 0)) {
657 /* 657 /*
658 * Broken TCP stacks, that set ACK in RST packets as well 658 * Broken TCP stacks, that set ACK in RST packets as well
@@ -662,8 +662,8 @@ static int tcp_in_window(struct ip_ct_tcp *state,
662 } 662 }
663 663
664 if (seq == end 664 if (seq == end
665 && (!tcph->rst 665 && (!tcph->rst
666 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT))) 666 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
667 /* 667 /*
668 * Packets contains no data: we assume it is valid 668 * Packets contains no data: we assume it is valid
669 * and check the ack value only. 669 * and check the ack value only.
@@ -672,7 +672,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
672 * SYN. 672 * SYN.
673 */ 673 */
674 seq = end = sender->td_end; 674 seq = end = sender->td_end;
675 675
676 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 676 DEBUGP("tcp_in_window: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
677 "seq=%u ack=%u sack =%u win=%u end=%u\n", 677 "seq=%u ack=%u sack =%u win=%u end=%u\n",
678 NIPQUAD(iph->saddr), ntohs(tcph->source), 678 NIPQUAD(iph->saddr), ntohs(tcph->source),
@@ -681,26 +681,26 @@ static int tcp_in_window(struct ip_ct_tcp *state,
681 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i " 681 DEBUGP("tcp_in_window: sender end=%u maxend=%u maxwin=%u scale=%i "
682 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 682 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
683 sender->td_end, sender->td_maxend, sender->td_maxwin, 683 sender->td_end, sender->td_maxend, sender->td_maxwin,
684 sender->td_scale, 684 sender->td_scale,
685 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 685 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
686 receiver->td_scale); 686 receiver->td_scale);
687 687
688 DEBUGP("tcp_in_window: I=%i II=%i III=%i IV=%i\n", 688 DEBUGP("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
689 before(seq, sender->td_maxend + 1), 689 before(seq, sender->td_maxend + 1),
690 after(end, sender->td_end - receiver->td_maxwin - 1), 690 after(end, sender->td_end - receiver->td_maxwin - 1),
691 before(sack, receiver->td_end + 1), 691 before(sack, receiver->td_end + 1),
692 after(ack, receiver->td_end - MAXACKWINDOW(sender))); 692 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
693 693
694 if (before(seq, sender->td_maxend + 1) && 694 if (before(seq, sender->td_maxend + 1) &&
695 after(end, sender->td_end - receiver->td_maxwin - 1) && 695 after(end, sender->td_end - receiver->td_maxwin - 1) &&
696 before(sack, receiver->td_end + 1) && 696 before(sack, receiver->td_end + 1) &&
697 after(ack, receiver->td_end - MAXACKWINDOW(sender))) { 697 after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
698 /* 698 /*
699 * Take into account window scaling (RFC 1323). 699 * Take into account window scaling (RFC 1323).
700 */ 700 */
701 if (!tcph->syn) 701 if (!tcph->syn)
702 win <<= sender->td_scale; 702 win <<= sender->td_scale;
703 703
704 /* 704 /*
705 * Update sender data. 705 * Update sender data.
706 */ 706 */
@@ -720,7 +720,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
720 receiver->td_maxend++; 720 receiver->td_maxend++;
721 } 721 }
722 722
723 /* 723 /*
724 * Check retransmissions. 724 * Check retransmissions.
725 */ 725 */
726 if (index == TCP_ACK_SET) { 726 if (index == TCP_ACK_SET) {
@@ -756,11 +756,11 @@ static int tcp_in_window(struct ip_ct_tcp *state,
756 : "ACK is over the upper bound (ACKed data not seen yet)" 756 : "ACK is over the upper bound (ACKed data not seen yet)"
757 : "SEQ is under the lower bound (already ACKed data retransmitted)" 757 : "SEQ is under the lower bound (already ACKed data retransmitted)"
758 : "SEQ is over the upper bound (over the window of the receiver)"); 758 : "SEQ is over the upper bound (over the window of the receiver)");
759 } 759 }
760 760
761 DEBUGP("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u " 761 DEBUGP("tcp_in_window: res=%i sender end=%u maxend=%u maxwin=%u "
762 "receiver end=%u maxend=%u maxwin=%u\n", 762 "receiver end=%u maxend=%u maxwin=%u\n",
763 res, sender->td_end, sender->td_maxend, sender->td_maxwin, 763 res, sender->td_end, sender->td_maxend, sender->td_maxwin,
764 receiver->td_end, receiver->td_maxend, receiver->td_maxwin); 764 receiver->td_end, receiver->td_maxend, receiver->td_maxwin);
765 765
766 return res; 766 return res;
@@ -769,7 +769,7 @@ static int tcp_in_window(struct ip_ct_tcp *state,
769#ifdef CONFIG_IP_NF_NAT_NEEDED 769#ifdef CONFIG_IP_NF_NAT_NEEDED
770/* Update sender->td_end after NAT successfully mangled the packet */ 770/* Update sender->td_end after NAT successfully mangled the packet */
771void ip_conntrack_tcp_update(struct sk_buff *skb, 771void ip_conntrack_tcp_update(struct sk_buff *skb,
772 struct ip_conntrack *conntrack, 772 struct ip_conntrack *conntrack,
773 enum ip_conntrack_dir dir) 773 enum ip_conntrack_dir dir)
774{ 774{
775 struct iphdr *iph = skb->nh.iph; 775 struct iphdr *iph = skb->nh.iph;
@@ -781,7 +781,7 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,
781#endif 781#endif
782 782
783 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph); 783 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph);
784 784
785 write_lock_bh(&tcp_lock); 785 write_lock_bh(&tcp_lock);
786 /* 786 /*
787 * We have to worry for the ack in the reply packet only... 787 * We have to worry for the ack in the reply packet only...
@@ -793,11 +793,11 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,
793 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i " 793 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "
794 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 794 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
795 sender->td_end, sender->td_maxend, sender->td_maxwin, 795 sender->td_end, sender->td_maxend, sender->td_maxwin,
796 sender->td_scale, 796 sender->td_scale,
797 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 797 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
798 receiver->td_scale); 798 receiver->td_scale);
799} 799}
800 800
801#endif 801#endif
802 802
803#define TH_FIN 0x01 803#define TH_FIN 0x01
@@ -847,8 +847,8 @@ static int tcp_error(struct sk_buff *skb,
847 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 847 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
848 "ip_ct_tcp: short packet "); 848 "ip_ct_tcp: short packet ");
849 return -NF_ACCEPT; 849 return -NF_ACCEPT;
850 } 850 }
851 851
852 /* Not whole TCP header or malformed packet */ 852 /* Not whole TCP header or malformed packet */
853 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) { 853 if (th->doff*4 < sizeof(struct tcphdr) || tcplen < th->doff*4) {
854 if (LOG_INVALID(IPPROTO_TCP)) 854 if (LOG_INVALID(IPPROTO_TCP))
@@ -856,7 +856,7 @@ static int tcp_error(struct sk_buff *skb,
856 "ip_ct_tcp: truncated/malformed packet "); 856 "ip_ct_tcp: truncated/malformed packet ");
857 return -NF_ACCEPT; 857 return -NF_ACCEPT;
858 } 858 }
859 859
860 /* Checksum invalid? Ignore. 860 /* Checksum invalid? Ignore.
861 * We skip checking packets on the outgoing path 861 * We skip checking packets on the outgoing path
862 * because it is assumed to be correct. 862 * because it is assumed to be correct.
@@ -893,11 +893,11 @@ static int tcp_packet(struct ip_conntrack *conntrack,
893 struct tcphdr *th, _tcph; 893 struct tcphdr *th, _tcph;
894 unsigned long timeout; 894 unsigned long timeout;
895 unsigned int index; 895 unsigned int index;
896 896
897 th = skb_header_pointer(skb, iph->ihl * 4, 897 th = skb_header_pointer(skb, iph->ihl * 4,
898 sizeof(_tcph), &_tcph); 898 sizeof(_tcph), &_tcph);
899 BUG_ON(th == NULL); 899 BUG_ON(th == NULL);
900 900
901 write_lock_bh(&tcp_lock); 901 write_lock_bh(&tcp_lock);
902 old_state = conntrack->proto.tcp.state; 902 old_state = conntrack->proto.tcp.state;
903 dir = CTINFO2DIR(ctinfo); 903 dir = CTINFO2DIR(ctinfo);
@@ -907,7 +907,7 @@ static int tcp_packet(struct ip_conntrack *conntrack,
907 switch (new_state) { 907 switch (new_state) {
908 case TCP_CONNTRACK_IGNORE: 908 case TCP_CONNTRACK_IGNORE:
909 /* Ignored packets: 909 /* Ignored packets:
910 * 910 *
911 * a) SYN in ORIGINAL 911 * a) SYN in ORIGINAL
912 * b) SYN/ACK in REPLY 912 * b) SYN/ACK in REPLY
913 * c) ACK in reply direction after initial SYN in original. 913 * c) ACK in reply direction after initial SYN in original.
@@ -916,30 +916,30 @@ static int tcp_packet(struct ip_conntrack *conntrack,
916 && conntrack->proto.tcp.last_index == TCP_SYN_SET 916 && conntrack->proto.tcp.last_index == TCP_SYN_SET
917 && conntrack->proto.tcp.last_dir != dir 917 && conntrack->proto.tcp.last_dir != dir
918 && ntohl(th->ack_seq) == 918 && ntohl(th->ack_seq) ==
919 conntrack->proto.tcp.last_end) { 919 conntrack->proto.tcp.last_end) {
920 /* This SYN/ACK acknowledges a SYN that we earlier 920 /* This SYN/ACK acknowledges a SYN that we earlier
921 * ignored as invalid. This means that the client and 921 * ignored as invalid. This means that the client and
922 * the server are both in sync, while the firewall is 922 * the server are both in sync, while the firewall is
923 * not. We kill this session and block the SYN/ACK so 923 * not. We kill this session and block the SYN/ACK so
924 * that the client cannot but retransmit its SYN and 924 * that the client cannot but retransmit its SYN and
925 * thus initiate a clean new session. 925 * thus initiate a clean new session.
926 */ 926 */
927 write_unlock_bh(&tcp_lock); 927 write_unlock_bh(&tcp_lock);
928 if (LOG_INVALID(IPPROTO_TCP)) 928 if (LOG_INVALID(IPPROTO_TCP))
929 nf_log_packet(PF_INET, 0, skb, NULL, NULL, 929 nf_log_packet(PF_INET, 0, skb, NULL, NULL,
930 NULL, "ip_ct_tcp: " 930 NULL, "ip_ct_tcp: "
931 "killing out of sync session "); 931 "killing out of sync session ");
932 if (del_timer(&conntrack->timeout)) 932 if (del_timer(&conntrack->timeout))
933 conntrack->timeout.function((unsigned long) 933 conntrack->timeout.function((unsigned long)
934 conntrack); 934 conntrack);
935 return -NF_DROP; 935 return -NF_DROP;
936 } 936 }
937 conntrack->proto.tcp.last_index = index; 937 conntrack->proto.tcp.last_index = index;
938 conntrack->proto.tcp.last_dir = dir; 938 conntrack->proto.tcp.last_dir = dir;
939 conntrack->proto.tcp.last_seq = ntohl(th->seq); 939 conntrack->proto.tcp.last_seq = ntohl(th->seq);
940 conntrack->proto.tcp.last_end = 940 conntrack->proto.tcp.last_end =
941 segment_seq_plus_len(ntohl(th->seq), skb->len, iph, th); 941 segment_seq_plus_len(ntohl(th->seq), skb->len, iph, th);
942 942
943 write_unlock_bh(&tcp_lock); 943 write_unlock_bh(&tcp_lock);
944 if (LOG_INVALID(IPPROTO_TCP)) 944 if (LOG_INVALID(IPPROTO_TCP))
945 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, 945 nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
@@ -959,16 +959,16 @@ static int tcp_packet(struct ip_conntrack *conntrack,
959 if (old_state < TCP_CONNTRACK_TIME_WAIT) 959 if (old_state < TCP_CONNTRACK_TIME_WAIT)
960 break; 960 break;
961 if ((conntrack->proto.tcp.seen[dir].flags & 961 if ((conntrack->proto.tcp.seen[dir].flags &
962 IP_CT_TCP_FLAG_CLOSE_INIT) 962 IP_CT_TCP_FLAG_CLOSE_INIT)
963 || after(ntohl(th->seq), 963 || after(ntohl(th->seq),
964 conntrack->proto.tcp.seen[dir].td_end)) { 964 conntrack->proto.tcp.seen[dir].td_end)) {
965 /* Attempt to reopen a closed connection. 965 /* Attempt to reopen a closed connection.
966 * Delete this connection and look up again. */ 966 * Delete this connection and look up again. */
967 write_unlock_bh(&tcp_lock); 967 write_unlock_bh(&tcp_lock);
968 if (del_timer(&conntrack->timeout)) 968 if (del_timer(&conntrack->timeout))
969 conntrack->timeout.function((unsigned long) 969 conntrack->timeout.function((unsigned long)
970 conntrack); 970 conntrack);
971 return -NF_REPEAT; 971 return -NF_REPEAT;
972 } else { 972 } else {
973 write_unlock_bh(&tcp_lock); 973 write_unlock_bh(&tcp_lock);
974 if (LOG_INVALID(IPPROTO_TCP)) 974 if (LOG_INVALID(IPPROTO_TCP))
@@ -979,9 +979,9 @@ static int tcp_packet(struct ip_conntrack *conntrack,
979 case TCP_CONNTRACK_CLOSE: 979 case TCP_CONNTRACK_CLOSE:
980 if (index == TCP_RST_SET 980 if (index == TCP_RST_SET
981 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status) 981 && ((test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)
982 && conntrack->proto.tcp.last_index == TCP_SYN_SET) 982 && conntrack->proto.tcp.last_index == TCP_SYN_SET)
983 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status) 983 || (!test_bit(IPS_ASSURED_BIT, &conntrack->status)
984 && conntrack->proto.tcp.last_index == TCP_ACK_SET)) 984 && conntrack->proto.tcp.last_index == TCP_ACK_SET))
985 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) { 985 && ntohl(th->ack_seq) == conntrack->proto.tcp.last_end) {
986 /* RST sent to invalid SYN or ACK we had let through 986 /* RST sent to invalid SYN or ACK we had let through
987 * at a) and c) above: 987 * at a) and c) above:
@@ -1000,13 +1000,13 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1000 break; 1000 break;
1001 } 1001 }
1002 1002
1003 if (!tcp_in_window(&conntrack->proto.tcp, dir, index, 1003 if (!tcp_in_window(&conntrack->proto.tcp, dir, index,
1004 skb, iph, th)) { 1004 skb, iph, th)) {
1005 write_unlock_bh(&tcp_lock); 1005 write_unlock_bh(&tcp_lock);
1006 return -NF_ACCEPT; 1006 return -NF_ACCEPT;
1007 } 1007 }
1008 in_window: 1008 in_window:
1009 /* From now on we have got in-window packets */ 1009 /* From now on we have got in-window packets */
1010 conntrack->proto.tcp.last_index = index; 1010 conntrack->proto.tcp.last_index = index;
1011 1011
1012 DEBUGP("tcp_conntracks: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu " 1012 DEBUGP("tcp_conntracks: src=%u.%u.%u.%u:%hu dst=%u.%u.%u.%u:%hu "
@@ -1018,9 +1018,9 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1018 old_state, new_state); 1018 old_state, new_state);
1019 1019
1020 conntrack->proto.tcp.state = new_state; 1020 conntrack->proto.tcp.state = new_state;
1021 if (old_state != new_state 1021 if (old_state != new_state
1022 && (new_state == TCP_CONNTRACK_FIN_WAIT 1022 && (new_state == TCP_CONNTRACK_FIN_WAIT
1023 || new_state == TCP_CONNTRACK_CLOSE)) 1023 || new_state == TCP_CONNTRACK_CLOSE))
1024 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT; 1024 conntrack->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
1025 timeout = conntrack->proto.tcp.retrans >= ip_ct_tcp_max_retrans 1025 timeout = conntrack->proto.tcp.retrans >= ip_ct_tcp_max_retrans
1026 && *tcp_timeouts[new_state] > ip_ct_tcp_timeout_max_retrans 1026 && *tcp_timeouts[new_state] > ip_ct_tcp_timeout_max_retrans
@@ -1046,8 +1046,8 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1046 && (old_state == TCP_CONNTRACK_SYN_RECV 1046 && (old_state == TCP_CONNTRACK_SYN_RECV
1047 || old_state == TCP_CONNTRACK_ESTABLISHED) 1047 || old_state == TCP_CONNTRACK_ESTABLISHED)
1048 && new_state == TCP_CONNTRACK_ESTABLISHED) { 1048 && new_state == TCP_CONNTRACK_ESTABLISHED) {
1049 /* Set ASSURED if we see see valid ack in ESTABLISHED 1049 /* Set ASSURED if we see see valid ack in ESTABLISHED
1050 after SYN_RECV or a valid answer for a picked up 1050 after SYN_RECV or a valid answer for a picked up
1051 connection. */ 1051 connection. */
1052 set_bit(IPS_ASSURED_BIT, &conntrack->status); 1052 set_bit(IPS_ASSURED_BIT, &conntrack->status);
1053 ip_conntrack_event_cache(IPCT_STATUS, skb); 1053 ip_conntrack_event_cache(IPCT_STATUS, skb);
@@ -1056,7 +1056,7 @@ static int tcp_packet(struct ip_conntrack *conntrack,
1056 1056
1057 return NF_ACCEPT; 1057 return NF_ACCEPT;
1058} 1058}
1059 1059
1060/* Called when a new connection for this protocol found. */ 1060/* Called when a new connection for this protocol found. */
1061static int tcp_new(struct ip_conntrack *conntrack, 1061static int tcp_new(struct ip_conntrack *conntrack,
1062 const struct sk_buff *skb) 1062 const struct sk_buff *skb)
@@ -1072,7 +1072,7 @@ static int tcp_new(struct ip_conntrack *conntrack,
1072 th = skb_header_pointer(skb, iph->ihl * 4, 1072 th = skb_header_pointer(skb, iph->ihl * 4,
1073 sizeof(_tcph), &_tcph); 1073 sizeof(_tcph), &_tcph);
1074 BUG_ON(th == NULL); 1074 BUG_ON(th == NULL);
1075 1075
1076 /* Don't need lock here: this conntrack not in circulation yet */ 1076 /* Don't need lock here: this conntrack not in circulation yet */
1077 new_state 1077 new_state
1078 = tcp_conntracks[0][get_conntrack_index(th)] 1078 = tcp_conntracks[0][get_conntrack_index(th)]
@@ -1113,7 +1113,7 @@ static int tcp_new(struct ip_conntrack *conntrack,
1113 if (conntrack->proto.tcp.seen[0].td_maxwin == 0) 1113 if (conntrack->proto.tcp.seen[0].td_maxwin == 0)
1114 conntrack->proto.tcp.seen[0].td_maxwin = 1; 1114 conntrack->proto.tcp.seen[0].td_maxwin = 1;
1115 conntrack->proto.tcp.seen[0].td_maxend = 1115 conntrack->proto.tcp.seen[0].td_maxend =
1116 conntrack->proto.tcp.seen[0].td_end + 1116 conntrack->proto.tcp.seen[0].td_end +
1117 conntrack->proto.tcp.seen[0].td_maxwin; 1117 conntrack->proto.tcp.seen[0].td_maxwin;
1118 conntrack->proto.tcp.seen[0].td_scale = 0; 1118 conntrack->proto.tcp.seen[0].td_scale = 0;
1119 1119
@@ -1123,25 +1123,25 @@ static int tcp_new(struct ip_conntrack *conntrack,
1123 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM | 1123 conntrack->proto.tcp.seen[1].flags = IP_CT_TCP_FLAG_SACK_PERM |
1124 IP_CT_TCP_FLAG_BE_LIBERAL; 1124 IP_CT_TCP_FLAG_BE_LIBERAL;
1125 } 1125 }
1126 1126
1127 conntrack->proto.tcp.seen[1].td_end = 0; 1127 conntrack->proto.tcp.seen[1].td_end = 0;
1128 conntrack->proto.tcp.seen[1].td_maxend = 0; 1128 conntrack->proto.tcp.seen[1].td_maxend = 0;
1129 conntrack->proto.tcp.seen[1].td_maxwin = 1; 1129 conntrack->proto.tcp.seen[1].td_maxwin = 1;
1130 conntrack->proto.tcp.seen[1].td_scale = 0; 1130 conntrack->proto.tcp.seen[1].td_scale = 0;
1131 1131
1132 /* tcp_packet will set them */ 1132 /* tcp_packet will set them */
1133 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE; 1133 conntrack->proto.tcp.state = TCP_CONNTRACK_NONE;
1134 conntrack->proto.tcp.last_index = TCP_NONE_SET; 1134 conntrack->proto.tcp.last_index = TCP_NONE_SET;
1135 1135
1136 DEBUGP("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i " 1136 DEBUGP("tcp_new: sender end=%u maxend=%u maxwin=%u scale=%i "
1137 "receiver end=%u maxend=%u maxwin=%u scale=%i\n", 1137 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",
1138 sender->td_end, sender->td_maxend, sender->td_maxwin, 1138 sender->td_end, sender->td_maxend, sender->td_maxwin,
1139 sender->td_scale, 1139 sender->td_scale,
1140 receiver->td_end, receiver->td_maxend, receiver->td_maxwin, 1140 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
1141 receiver->td_scale); 1141 receiver->td_scale);
1142 return 1; 1142 return 1;
1143} 1143}
1144 1144
1145struct ip_conntrack_protocol ip_conntrack_protocol_tcp = 1145struct ip_conntrack_protocol ip_conntrack_protocol_tcp =
1146{ 1146{
1147 .proto = IPPROTO_TCP, 1147 .proto = IPPROTO_TCP,