]> err.no Git - linux-2.6/blobdiff - net/ipv4/syncookies.c
the scheduled ieee80211 softmac removal
[linux-2.6] / net / ipv4 / syncookies.c
index 33016cc90f0b8a7add18555666a010f87bc550ab..4704f27f6c0b4f16d929668a9f043a96a57fd7ac 100644 (file)
@@ -10,8 +10,6 @@
  *      2 of the License, or (at your option) any later version.
  *
  *  $Id: syncookies.c,v 1.18 2002/02/01 22:01:04 davem Exp $
- *
- *  Missing: IPv6 support.
  */
 
 #include <linux/tcp.h>
 
 extern int sysctl_tcp_syncookies;
 
-static __u32 syncookie_secret[2][16-3+SHA_DIGEST_WORDS];
+__u32 syncookie_secret[2][16-3+SHA_DIGEST_WORDS];
+EXPORT_SYMBOL(syncookie_secret);
 
 static __init int init_syncookies(void)
 {
        get_random_bytes(syncookie_secret, sizeof(syncookie_secret));
        return 0;
 }
-module_init(init_syncookies);
+__initcall(init_syncookies);
 
 #define COOKIEBITS 24  /* Upper bits store count */
 #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
 
+static DEFINE_PER_CPU(__u32, cookie_scratch)[16 + 5 + SHA_WORKSPACE_WORDS];
+
 static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
                       u32 count, int c)
 {
-       __u32 tmp[16 + 5 + SHA_WORKSPACE_WORDS];
+       __u32 *tmp = __get_cpu_var(cookie_scratch);
 
        memcpy(tmp + 3, syncookie_secret[c], sizeof(syncookie_secret[c]));
        tmp[0] = (__force u32)saddr;
@@ -125,10 +126,11 @@ static __u16 const msstab[] = {
 __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
 {
        struct tcp_sock *tp = tcp_sk(sk);
+       const struct iphdr *iph = ip_hdr(skb);
+       const struct tcphdr *th = tcp_hdr(skb);
        int mssind;
        const __u16 mss = *mssp;
 
-
        tp->last_synq_overflow = jiffies;
 
        /* XXX sort msstab[] by probability?  Binary search? */
@@ -138,9 +140,8 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
 
        NET_INC_STATS_BH(LINUX_MIB_SYNCOOKIESSENT);
 
-       return secure_tcp_syn_cookie(skb->nh.iph->saddr, skb->nh.iph->daddr,
-                                    skb->h.th->source, skb->h.th->dest,
-                                    ntohl(skb->h.th->seq),
+       return secure_tcp_syn_cookie(iph->saddr, iph->daddr,
+                                    th->source, th->dest, ntohl(th->seq),
                                     jiffies / (HZ * 60), mssind);
 }
 
@@ -157,14 +158,13 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
  */
 static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
 {
-       __u32 seq;
-       __u32 mssind;
-
-       seq = ntohl(skb->h.th->seq)-1;
-       mssind = check_tcp_syn_cookie(cookie,
-                                     skb->nh.iph->saddr, skb->nh.iph->daddr,
-                                     skb->h.th->source, skb->h.th->dest,
-                                     seq, jiffies / (HZ * 60), COUNTER_TRIES);
+       const struct iphdr *iph = ip_hdr(skb);
+       const struct tcphdr *th = tcp_hdr(skb);
+       __u32 seq = ntohl(th->seq) - 1;
+       __u32 mssind = check_tcp_syn_cookie(cookie, iph->saddr, iph->daddr,
+                                           th->source, th->dest, seq,
+                                           jiffies / (HZ * 60),
+                                           COUNTER_TRIES);
 
        return mssind < NUM_MSS ? msstab[mssind] + 1 : 0;
 }
@@ -191,14 +191,15 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
        struct inet_request_sock *ireq;
        struct tcp_request_sock *treq;
        struct tcp_sock *tp = tcp_sk(sk);
-       __u32 cookie = ntohl(skb->h.th->ack_seq) - 1;
+       const struct tcphdr *th = tcp_hdr(skb);
+       __u32 cookie = ntohl(th->ack_seq) - 1;
        struct sock *ret = sk;
        struct request_sock *req;
        int mss;
        struct rtable *rt;
        __u8 rcv_wscale;
 
-       if (!sysctl_tcp_syncookies || !skb->h.th->ack)
+       if (!sysctl_tcp_syncookies || !th->ack)
                goto out;
 
        if (time_after(jiffies, tp->last_synq_overflow + TCP_TIMEOUT_INIT) ||
@@ -220,12 +221,12 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
        }
        ireq = inet_rsk(req);
        treq = tcp_rsk(req);
-       treq->rcv_isn           = ntohl(skb->h.th->seq) - 1;
+       treq->rcv_isn           = ntohl(th->seq) - 1;
        treq->snt_isn           = cookie;
        req->mss                = mss;
-       ireq->rmt_port          = skb->h.th->source;
-       ireq->loc_addr          = skb->nh.iph->daddr;
-       ireq->rmt_addr          = skb->nh.iph->saddr;
+       ireq->rmt_port          = th->source;
+       ireq->loc_addr          = ip_hdr(skb)->daddr;
+       ireq->rmt_addr          = ip_hdr(skb)->saddr;
        ireq->opt               = NULL;
 
        /* We throwed the options of the initial SYN away, so we hope
@@ -261,10 +262,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
                                                .tos = RT_CONN_FLAGS(sk) } },
                                    .proto = IPPROTO_TCP,
                                    .uli_u = { .ports =
-                                              { .sport = skb->h.th->dest,
-                                                .dport = skb->h.th->source } } };
+                                              { .sport = th->dest,
+                                                .dport = th->source } } };
                security_req_classify_flow(req, &fl);
-               if (ip_route_output_key(&rt, &fl)) {
+               if (ip_route_output_key(&init_net, &rt, &fl)) {
                        reqsk_free(req);
                        goto out;
                }