syncookies: only increment SYNCOOKIESFAILED on validation error
authorFlorian Westphal <fw@strlen.de>
Thu, 30 Oct 2014 01:55:38 +0000 (02:55 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 30 Oct 2014 20:53:39 +0000 (16:53 -0400)
Only count packets that failed cookie-authentication.
We can get SYNCOOKIESFAILED > 0 while we never even sent a single cookie.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/syncookies.c
net/ipv6/syncookies.c

index 32b98d0207b48b07472f0954e327483900be08e6..4ac7bcaf2f46ea6dd6976f6596d3469f5e4f4271 100644 (file)
@@ -275,8 +275,11 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
        if (!sysctl_tcp_syncookies || !th->ack || th->rst)
                goto out;
 
-       if (tcp_synq_no_recent_overflow(sk) ||
-           (mss = __cookie_v4_check(ip_hdr(skb), th, cookie)) == 0) {
+       if (tcp_synq_no_recent_overflow(sk))
+               goto out;
+
+       mss = __cookie_v4_check(ip_hdr(skb), th, cookie);
+       if (mss == 0) {
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED);
                goto out;
        }
index 0e26e795b703cee7ca2367b397966444c1403b05..be291baa2ec2e181b7aefd7b006ef401804d67c0 100644 (file)
@@ -171,8 +171,11 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
        if (!sysctl_tcp_syncookies || !th->ack || th->rst)
                goto out;
 
-       if (tcp_synq_no_recent_overflow(sk) ||
-               (mss = __cookie_v6_check(ipv6_hdr(skb), th, cookie)) == 0) {
+       if (tcp_synq_no_recent_overflow(sk))
+               goto out;
+
+       mss = __cookie_v6_check(ipv6_hdr(skb), th, cookie);
+       if (mss == 0) {
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED);
                goto out;
        }