]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv4/udp.c
rose: improving AX25 routing frames via ROSE network
[net-next-2.6.git] / net / ipv4 / udp.c
index 1f535e315188858a4ec2f935efb431293d055dec..11eabf136144cdb0b81d506933516803ba4e52d8 100644 (file)
@@ -5,8 +5,6 @@
  *
  *             The User Datagram Protocol (UDP).
  *
- * Version:    $Id: udp.c,v 1.102 2002/02/01 22:01:04 davem Exp $
- *
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Arnt Gulbrandsen, <agulbra@nvg.unit.no>
@@ -136,7 +134,7 @@ static inline int __udp_lib_lport_inuse(struct net *net, __u16 num,
        struct sock *sk;
        struct hlist_node *node;
 
-       sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)])
+       sk_for_each(sk, node, &udptable[udp_hashfn(net, num)])
                if (net_eq(sock_net(sk), net) && sk->sk_hash == num)
                        return 1;
        return 0;
@@ -176,7 +174,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
                for (i = 0; i < UDP_HTABLE_SIZE; i++) {
                        int size = 0;
 
-                       head = &udptable[rover & (UDP_HTABLE_SIZE - 1)];
+                       head = &udptable[udp_hashfn(net, rover)];
                        if (hlist_empty(head))
                                goto gotit;
 
@@ -213,7 +211,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
 gotit:
                snum = rover;
        } else {
-               head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
+               head = &udptable[udp_hashfn(net, snum)];
 
                sk_for_each(sk2, node, head)
                        if (sk2->sk_hash == snum                             &&
@@ -229,7 +227,7 @@ gotit:
        inet_sk(sk)->num = snum;
        sk->sk_hash = snum;
        if (sk_unhashed(sk)) {
-               head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
+               head = &udptable[udp_hashfn(net, snum)];
                sk_add_node(sk, head);
                sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
        }
@@ -266,7 +264,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
        int badness = -1;
 
        read_lock(&udp_hash_lock);
-       sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
+       sk_for_each(sk, node, &udptable[udp_hashfn(net, hnum)]) {
                struct inet_sock *inet = inet_sk(sk);
 
                if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
@@ -420,7 +418,7 @@ void udp_err(struct sk_buff *skb, u32 info)
 /*
  * Throw away all pending data and cancel the corking. Socket is locked.
  */
-static void udp_flush_pending_frames(struct sock *sk)
+void udp_flush_pending_frames(struct sock *sk)
 {
        struct udp_sock *up = udp_sk(sk);
 
@@ -430,6 +428,7 @@ static void udp_flush_pending_frames(struct sock *sk)
                ip_flush_pending_frames(sk);
        }
 }
+EXPORT_SYMBOL(udp_flush_pending_frames);
 
 /**
  *     udp4_hwcsum_outgoing  -  handle outgoing HW checksumming
@@ -1060,7 +1059,7 @@ drop:
  *     Note: called only from the BH handler context,
  *     so we don't need to lock the hashes.
  */
-static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
+static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
                                    struct udphdr  *uh,
                                    __be32 saddr, __be32 daddr,
                                    struct hlist_head udptable[])
@@ -1069,7 +1068,7 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
        int dif;
 
        read_lock(&udp_hash_lock);
-       sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]);
+       sk = sk_head(&udptable[udp_hashfn(net, ntohs(uh->dest))]);
        dif = skb->dev->ifindex;
        sk = udp_v4_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
        if (sk) {
@@ -1157,6 +1156,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
        struct rtable *rt = (struct rtable*)skb->dst;
        __be32 saddr = ip_hdr(skb)->saddr;
        __be32 daddr = ip_hdr(skb)->daddr;
+       struct net *net;
 
        /*
         *  Validate the packet.
@@ -1178,10 +1178,12 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
        if (udp4_csum_init(skb, uh, proto))
                goto csum_error;
 
+       net = dev_net(skb->dev);
        if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST))
-               return __udp4_lib_mcast_deliver(skb, uh, saddr, daddr, udptable);
+               return __udp4_lib_mcast_deliver(net, skb, uh,
+                               saddr, daddr, udptable);
 
-       sk = __udp4_lib_lookup(dev_net(skb->dev), saddr, uh->source, daddr,
+       sk = __udp4_lib_lookup(net, saddr, uh->source, daddr,
                        uh->dest, inet_iif(skb), udptable);
 
        if (sk != NULL) {
@@ -1254,12 +1256,11 @@ int udp_rcv(struct sk_buff *skb)
        return __udp4_lib_rcv(skb, udp_hash, IPPROTO_UDP);
 }
 
-int udp_destroy_sock(struct sock *sk)
+void udp_destroy_sock(struct sock *sk)
 {
        lock_sock(sk);
        udp_flush_pending_frames(sk);
        release_sock(sk);
-       return 0;
 }
 
 /*
@@ -1605,10 +1606,9 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
        afinfo->seq_ops.next            = udp_seq_next;
        afinfo->seq_ops.stop            = udp_seq_stop;
 
-       p = proc_net_fops_create(net, afinfo->name, S_IRUGO, &afinfo->seq_fops);
-       if (p)
-               p->data = afinfo;
-       else
+       p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
+                            &afinfo->seq_fops, afinfo);
+       if (!p)
                rc = -ENOMEM;
        return rc;
 }