]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv6/reassembly.c
ipv6: almost identical frag hashing funcs combined
[linux-2.6-omap-h63xx.git] / net / ipv6 / reassembly.c
index a60d7d1297137880de4294999966f3cb487ec16c..2eeadfa039cbb0e84e81efe33eaca668b93d26a7 100644 (file)
@@ -5,8 +5,6 @@
  *     Authors:
  *     Pedro Roque             <roque@di.fc.ul.pt>
  *
- *     $Id: reassembly.c,v 1.26 2001/03/07 22:00:57 davem Exp $
- *
  *     Based on: net/ipv4/ip_fragment.c
  *
  *     This program is free software; you can redistribute it and/or
@@ -101,8 +99,8 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
  * callers should be careful not to use the hash value outside the ipfrag_lock
  * as doing so could race with ipfrag_hash_rnd being recalculated.
  */
-static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr,
-                              struct in6_addr *daddr)
+unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
+                            const struct in6_addr *daddr, u32 rnd)
 {
        u32 a, b, c;
 
@@ -112,7 +110,7 @@ static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr,
 
        a += JHASH_GOLDEN_RATIO;
        b += JHASH_GOLDEN_RATIO;
-       c += ip6_frags.rnd;
+       c += rnd;
        __jhash_mix(a, b, c);
 
        a += (__force u32)saddr->s6_addr32[3];
@@ -127,13 +125,14 @@ static unsigned int ip6qhashfn(__be32 id, struct in6_addr *saddr,
 
        return c & (INETFRAGS_HASHSZ - 1);
 }
+EXPORT_SYMBOL_GPL(inet6_hash_frag);
 
 static unsigned int ip6_hashfn(struct inet_frag_queue *q)
 {
        struct frag_queue *fq;
 
        fq = container_of(q, struct frag_queue, q);
-       return ip6qhashfn(fq->id, &fq->saddr, &fq->daddr);
+       return inet6_hash_frag(fq->id, &fq->saddr, &fq->daddr, ip6_frags.rnd);
 }
 
 int ip6_frag_match(struct inet_frag_queue *q, void *a)
@@ -249,7 +248,7 @@ fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst,
        arg.dst = dst;
 
        read_lock(&ip6_frags.lock);
-       hash = ip6qhashfn(id, src, dst);
+       hash = inet6_hash_frag(id, src, dst, ip6_frags.rnd);
 
        q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
        if (q == NULL)
@@ -475,8 +474,8 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
                fq->q.fragments = head;
        }
 
-       BUG_TRAP(head != NULL);
-       BUG_TRAP(FRAG6_CB(head)->offset == 0);
+       WARN_ON(head == NULL);
+       WARN_ON(FRAG6_CB(head)->offset != 0);
 
        /* Unfragmented part is taken from the first segment. */
        payload_len = ((head->data - skb_network_header(head)) -
@@ -634,7 +633,7 @@ static struct inet6_protocol frag_protocol =
 };
 
 #ifdef CONFIG_SYSCTL
-static struct ctl_table ip6_frags_ctl_table[] = {
+static struct ctl_table ip6_frags_ns_ctl_table[] = {
        {
                .ctl_name       = NET_IPV6_IP6FRAG_HIGH_THRESH,
                .procname       = "ip6frag_high_thresh",
@@ -660,6 +659,10 @@ static struct ctl_table ip6_frags_ctl_table[] = {
                .proc_handler   = &proc_dointvec_jiffies,
                .strategy       = &sysctl_jiffies,
        },
+       { }
+};
+
+static struct ctl_table ip6_frags_ctl_table[] = {
        {
                .ctl_name       = NET_IPV6_IP6FRAG_SECRET_INTERVAL,
                .procname       = "ip6frag_secret_interval",
@@ -672,21 +675,20 @@ static struct ctl_table ip6_frags_ctl_table[] = {
        { }
 };
 
-static int ip6_frags_sysctl_register(struct net *net)
+static int ip6_frags_ns_sysctl_register(struct net *net)
 {
        struct ctl_table *table;
        struct ctl_table_header *hdr;
 
-       table = ip6_frags_ctl_table;
+       table = ip6_frags_ns_ctl_table;
        if (net != &init_net) {
-               table = kmemdup(table, sizeof(ip6_frags_ctl_table), GFP_KERNEL);
+               table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
                if (table == NULL)
                        goto err_alloc;
 
                table[0].data = &net->ipv6.frags.high_thresh;
                table[1].data = &net->ipv6.frags.low_thresh;
                table[2].data = &net->ipv6.frags.timeout;
-               table[3].mode &= ~0222;
        }
 
        hdr = register_net_sysctl_table(net, net_ipv6_ctl_path, table);
@@ -703,7 +705,7 @@ err_alloc:
        return -ENOMEM;
 }
 
-static void ip6_frags_sysctl_unregister(struct net *net)
+static void ip6_frags_ns_sysctl_unregister(struct net *net)
 {
        struct ctl_table *table;
 
@@ -711,13 +713,36 @@ static void ip6_frags_sysctl_unregister(struct net *net)
        unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
        kfree(table);
 }
+
+static struct ctl_table_header *ip6_ctl_header;
+
+static int ip6_frags_sysctl_register(void)
+{
+       ip6_ctl_header = register_net_sysctl_rotable(net_ipv6_ctl_path,
+                       ip6_frags_ctl_table);
+       return ip6_ctl_header == NULL ? -ENOMEM : 0;
+}
+
+static void ip6_frags_sysctl_unregister(void)
+{
+       unregister_net_sysctl_table(ip6_ctl_header);
+}
 #else
-static inline int ip6_frags_sysctl_register(struct net *net)
+static inline int ip6_frags_ns_sysctl_register(struct net *net)
 {
        return 0;
 }
 
-static inline void ip6_frags_sysctl_unregister(struct net *net)
+static inline void ip6_frags_ns_sysctl_unregister(struct net *net)
+{
+}
+
+static inline int ip6_frags_sysctl_register(void)
+{
+       return 0;
+}
+
+static inline void ip6_frags_sysctl_unregister(void)
 {
 }
 #endif
@@ -730,12 +755,12 @@ static int ipv6_frags_init_net(struct net *net)
 
        inet_frags_init_net(&net->ipv6.frags);
 
-       return ip6_frags_sysctl_register(net);
+       return ip6_frags_ns_sysctl_register(net);
 }
 
 static void ipv6_frags_exit_net(struct net *net)
 {
-       ip6_frags_sysctl_unregister(net);
+       ip6_frags_ns_sysctl_unregister(net);
        inet_frags_exit_net(&net->ipv6.frags, &ip6_frags);
 }
 
@@ -752,7 +777,13 @@ int __init ipv6_frag_init(void)
        if (ret)
                goto out;
 
-       register_pernet_subsys(&ip6_frags_ops);
+       ret = ip6_frags_sysctl_register();
+       if (ret)
+               goto err_sysctl;
+
+       ret = register_pernet_subsys(&ip6_frags_ops);
+       if (ret)
+               goto err_pernet;
 
        ip6_frags.hashfn = ip6_hashfn;
        ip6_frags.constructor = ip6_frag_init;
@@ -765,11 +796,18 @@ int __init ipv6_frag_init(void)
        inet_frags_init(&ip6_frags);
 out:
        return ret;
+
+err_pernet:
+       ip6_frags_sysctl_unregister();
+err_sysctl:
+       inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
+       goto out;
 }
 
 void ipv6_frag_exit(void)
 {
        inet_frags_fini(&ip6_frags);
+       ip6_frags_sysctl_unregister();
        unregister_pernet_subsys(&ip6_frags_ops);
        inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
 }