All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: hans.schillstrom@ericsson.com
Cc: eric.dumazet@gmail.com, subramanian.vijay@gmail.com,
	dave.taht@gmail.com, netdev@vger.kernel.org,
	ncardwell@google.com, therbert@google.com, brouer@redhat.com
Subject: Re: [PATCH v2 net-next] tcp: avoid tx starvation by SYNACK packets
Date: Tue, 26 Jun 2012 00:11:24 -0700 (PDT)	[thread overview]
Message-ID: <20120626.001124.36486380031998542.davem@davemloft.net> (raw)
In-Reply-To: <201206260734.33472.hans.schillstrom@ericsson.com>

From: Hans Schillstrom <hans.schillstrom@ericsson.com>
Date: Tue, 26 Jun 2012 07:34:31 +0200

> The big cycle consumer during a syn attack is SHA sum right now, 
> so from that perspective it's better to add aes crypto (by using AES-NI) 
> to the syn cookies instead of SHA sum. Even if only newer x86_64 can use it.

I'm surprised that x86 lacks an SHA1 instruction, even shitty sparcs
have one now.

SHA1 seems overkill for what the syncookie code is trying to do, could
you give the following a try?

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 6660ffc..b280bf4 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -435,7 +435,6 @@ void tcp_finish_connect(struct sock *sk, struct sk_buff *skb);
 int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size);
 
 /* From syncookies.c */
-extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 
 				    struct ip_options *opt);
 #ifdef CONFIG_SYN_COOKIES
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index eab2a7f..60116dc 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -13,9 +13,9 @@
 #include <linux/tcp.h>
 #include <linux/slab.h>
 #include <linux/random.h>
-#include <linux/cryptohash.h>
 #include <linux/kernel.h>
 #include <linux/export.h>
+#include <linux/jhash.h>
 #include <net/tcp.h>
 #include <net/route.h>
 
@@ -25,7 +25,7 @@
 
 extern int sysctl_tcp_syncookies;
 
-__u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
+__u32 syncookie_secret[2];
 EXPORT_SYMBOL(syncookie_secret);
 
 static __init int init_syncookies(void)
@@ -38,22 +38,14 @@ __initcall(init_syncookies);
 #define COOKIEBITS 24	/* Upper bits store count */
 #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
 
-static DEFINE_PER_CPU(__u32 [16 + 5 + SHA_WORKSPACE_WORDS],
-		      ipv4_cookie_scratch);
-
 static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
 		       u32 count, int c)
 {
-	__u32 *tmp = __get_cpu_var(ipv4_cookie_scratch);
-
-	memcpy(tmp + 4, syncookie_secret[c], sizeof(syncookie_secret[c]));
-	tmp[0] = (__force u32)saddr;
-	tmp[1] = (__force u32)daddr;
-	tmp[2] = ((__force u32)sport << 16) + (__force u32)dport;
-	tmp[3] = count;
-	sha_transform(tmp + 16, (__u8 *)tmp, tmp + 16 + 5);
-
-	return tmp[17];
+	return jhash_3words((__force __u32) saddr + count,
+			    (__force __u32) daddr,
+			    (((__force __u32) sport) << 16 |
+			     (__force __u32) dport),
+			    syncookie_secret[c]);
 }
 
 

  reply	other threads:[~2012-06-26  7:11 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-31 21:56 [PATCH net-next] tcp: avoid tx starvation by SYNACK packets Eric Dumazet
2012-05-31 23:03 ` David Miller
2012-06-01  4:48   ` Eric Dumazet
2012-06-01 17:46     ` David Miller
2012-06-01  7:00 ` [PATCH] tcp: do not create inetpeer on SYNACK message Eric Dumazet
2012-06-01 18:24   ` David Miller
2012-06-01 21:34   ` Hans Schillström
2012-06-02  6:56     ` Eric Dumazet
2012-06-01  7:36 ` [PATCH net-next] tcp: avoid tx starvation by SYNACK packets Hans Schillstrom
2012-06-01  9:34   ` Eric Dumazet
2012-06-02  1:28 ` Dave Taht
2012-06-02  5:46   ` Eric Dumazet
2012-06-23  7:34     ` Vijay Subramanian
2012-06-23  8:42       ` [PATCH v2 " Eric Dumazet
2012-06-25  6:24         ` Hans Schillstrom
2012-06-25 22:43         ` David Miller
2012-06-26  4:51           ` Eric Dumazet
2012-06-26  4:55             ` David Miller
2012-06-26  5:34               ` Hans Schillstrom
2012-06-26  7:11                 ` David Miller [this message]
2012-06-26  7:27                   ` Hans Schillstrom
2012-06-26 17:02                 ` Eric Dumazet
2012-06-27  5:23                   ` Hans Schillstrom
2012-06-27  8:22                     ` David Miller
2012-06-27  8:25                       ` Jesper Dangaard Brouer
2012-06-27  8:30                       ` Hans Schillstrom
2012-06-27  8:40                       ` Eric Dumazet
2012-06-27  8:48                         ` David Miller
2012-06-27  6:32                   ` Jesper Dangaard Brouer
2012-06-27  6:54                     ` David Miller
2012-06-27  7:24                       ` Jesper Dangaard Brouer
2012-06-27  7:30                         ` Eric Dumazet
2012-06-27  7:54                           ` Jesper Dangaard Brouer
2012-06-27  8:02                             ` Eric Dumazet
2012-06-27  8:21                               ` Jesper Dangaard Brouer
2012-06-27  8:45                                 ` Eric Dumazet
2012-06-27  9:23                                   ` Jesper Dangaard Brouer
2012-06-27  8:13                           ` David Miller
2012-06-27 19:50                       ` Florian Westphal
2012-06-27 21:39                         ` Eric Dumazet
2012-06-27 22:23                           ` David Miller
2012-06-27 22:23                         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120626.001124.36486380031998542.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=brouer@redhat.com \
    --cc=dave.taht@gmail.com \
    --cc=eric.dumazet@gmail.com \
    --cc=hans.schillstrom@ericsson.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=subramanian.vijay@gmail.com \
    --cc=therbert@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.