Skip to content

Commit cc4f9d6

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: move synack init code to helper
It seems more readable to use a common helper in the followup fix rather than copypaste or goto. No functional change intended. The function is only called for syn-ack or syn in repy direction in case of simultaneous open. Signed-off-by: Florian Westphal <[email protected]> Acked-by: Jozsef Kadlecsik <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a9e8503 commit cc4f9d6

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

net/netfilter/nf_conntrack_proto_tcp.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,32 @@ static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
446446
}
447447
}
448448

449+
static void tcp_init_sender(struct ip_ct_tcp_state *sender,
450+
struct ip_ct_tcp_state *receiver,
451+
const struct sk_buff *skb,
452+
unsigned int dataoff,
453+
const struct tcphdr *tcph,
454+
u32 end, u32 win)
455+
{
456+
/* SYN-ACK in reply to a SYN
457+
* or SYN from reply direction in simultaneous open.
458+
*/
459+
sender->td_end =
460+
sender->td_maxend = end;
461+
sender->td_maxwin = (win == 0 ? 1 : win);
462+
463+
tcp_options(skb, dataoff, tcph, sender);
464+
/* RFC 1323:
465+
* Both sides must send the Window Scale option
466+
* to enable window scaling in either direction.
467+
*/
468+
if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
469+
receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE)) {
470+
sender->td_scale = 0;
471+
receiver->td_scale = 0;
472+
}
473+
}
474+
449475
static bool tcp_in_window(struct nf_conn *ct,
450476
enum ip_conntrack_dir dir,
451477
unsigned int index,
@@ -499,24 +525,9 @@ static bool tcp_in_window(struct nf_conn *ct,
499525
* Initialize sender data.
500526
*/
501527
if (tcph->syn) {
502-
/*
503-
* SYN-ACK in reply to a SYN
504-
* or SYN from reply direction in simultaneous open.
505-
*/
506-
sender->td_end =
507-
sender->td_maxend = end;
508-
sender->td_maxwin = (win == 0 ? 1 : win);
509-
510-
tcp_options(skb, dataoff, tcph, sender);
511-
/*
512-
* RFC 1323:
513-
* Both sides must send the Window Scale option
514-
* to enable window scaling in either direction.
515-
*/
516-
if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
517-
&& receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
518-
sender->td_scale =
519-
receiver->td_scale = 0;
528+
tcp_init_sender(sender, receiver,
529+
skb, dataoff, tcph,
530+
end, win);
520531
if (!tcph->ack)
521532
/* Simultaneous open */
522533
return true;

0 commit comments

Comments
 (0)