Merge git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-drm-fsl-dcu.git] / net / ipv6 / af_inet6.c
index 858cae29581c8e129289ce09cf644fd5d70c9184..a006d242be765390f8e239b1297a528283be3d39 100644 (file)
@@ -1,9 +1,9 @@
 /*
  *     PF_INET6 socket protocol family
- *     Linux INET6 implementation 
+ *     Linux INET6 implementation
  *
  *     Authors:
- *     Pedro Roque             <roque@di.fc.ul.pt>     
+ *     Pedro Roque             <roque@di.fc.ul.pt>
  *
  *     Adapted from linux/net/ipv4/af_inet.c
  *
@@ -49,6 +49,7 @@
 #include <net/ip.h>
 #include <net/ipv6.h>
 #include <net/udp.h>
+#include <net/udplite.h>
 #include <net/tcp.h>
 #include <net/ipip.h>
 #include <net/protocol.h>
@@ -170,7 +171,7 @@ lookup_protocol:
                sk->sk_reuse = 1;
 
        inet = inet_sk(sk);
-       inet->is_icsk = INET_PROTOSW_ICSK & answer_flags;
+       inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
 
        if (SOCK_RAW == sock->type) {
                inet->num = protocol;
@@ -190,7 +191,7 @@ lookup_protocol:
        np->mc_loop     = 1;
        np->pmtudisc    = IPV6_PMTUDISC_WANT;
        np->ipv6only    = sysctl_ipv6_bindv6only;
-       
+
        /* Init the ipv4 part of the socket since we can have sockets
         * using v6 API for ipv4.
         */
@@ -205,7 +206,7 @@ lookup_protocol:
                inet->pmtudisc = IP_PMTUDISC_DONT;
        else
                inet->pmtudisc = IP_PMTUDISC_WANT;
-       /* 
+       /*
         * Increment only the relevant sk_prot->socks debug field, this changes
         * the previous behaviour of incrementing both the equivalent to
         * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
@@ -221,7 +222,7 @@ lookup_protocol:
                 * the user to assign a number at socket
                 * creation time automatically shares.
                 */
-               inet->sport = ntohs(inet->num);
+               inet->sport = htons(inet->num);
                sk->sk_prot->hash(sk);
        }
        if (sk->sk_prot->init) {
@@ -292,7 +293,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                                         */
                                        sk->sk_bound_dev_if = addr->sin6_scope_id;
                                }
-                               
+
                                /* Binding to link-local address requires an interface */
                                if (!sk->sk_bound_dev_if) {
                                        err = -EINVAL;
@@ -326,7 +327,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
        inet->saddr = v4addr;
 
        ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
-               
+
        if (!(addr_type & IPV6_ADDR_MULTICAST))
                ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
 
@@ -341,7 +342,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
        if (snum)
                sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
-       inet->sport = ntohs(inet->num);
+       inet->sport = htons(inet->num);
        inet->dport = 0;
        inet->daddr = 0;
 out:
@@ -392,7 +393,7 @@ EXPORT_SYMBOL_GPL(inet6_destroy_sock);
 /*
  *     This does both peername and sockname.
  */
+
 int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
                 int *uaddr_len, int peer)
 {
@@ -400,7 +401,7 @@ int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
        struct sock *sk = sock->sk;
        struct inet_sock *inet = inet_sk(sk);
        struct ipv6_pinfo *np = inet6_sk(sk);
-  
+
        sin->sin6_family = AF_INET6;
        sin->sin6_flowinfo = 0;
        sin->sin6_scope_id = 0;
@@ -432,14 +433,14 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 {
        struct sock *sk = sock->sk;
 
-       switch(cmd) 
+       switch(cmd)
        {
        case SIOCGSTAMP:
                return sock_get_timestamp(sk, (struct timeval __user *)arg);
 
        case SIOCADDRT:
        case SIOCDELRT:
-         
+
                return(ipv6_route_ioctl(cmd,(void __user *)arg));
 
        case SIOCSIFADDR:
@@ -583,7 +584,7 @@ inet6_register_protosw(struct inet_protosw *p)
        /* Add the new entry after the last permanent entry if any, so that
         * the new entry does not override a permanent entry when matched with
         * a wild-card protocol. But it is allowed to override any existing
-        * non-permanent entry.  This means that when we remove this entry, the 
+        * non-permanent entry.  This means that when we remove this entry, the
         * system automatically returns to the old behavior.
         */
        list_add_rcu(&p->list, last_perm);
@@ -678,7 +679,7 @@ int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb)
        if (np->rxopt.all) {
                if ((opt->hop && (np->rxopt.bits.hopopts ||
                                  np->rxopt.bits.ohopopts)) ||
-                   ((IPV6_FLOWINFO_MASK & *(u32*)skb->nh.raw) &&
+                   ((IPV6_FLOWINFO_MASK & *(__be32*)skb->nh.raw) &&
                     np->rxopt.bits.rxflow) ||
                    (opt->srcrt && (np->rxopt.bits.srcrt ||
                     np->rxopt.bits.osrcrt)) ||
@@ -719,10 +720,8 @@ snmp6_mib_free(void *ptr[2])
 {
        if (ptr == NULL)
                return;
-       if (ptr[0])
-               free_percpu(ptr[0]);
-       if (ptr[1])
-               free_percpu(ptr[1]);
+       free_percpu(ptr[0]);
+       free_percpu(ptr[1]);
        ptr[0] = ptr[1] = NULL;
 }
 
@@ -737,15 +736,20 @@ static int __init init_ipv6_mibs(void)
        if (snmp6_mib_init((void **)udp_stats_in6, sizeof (struct udp_mib),
                           __alignof__(struct udp_mib)) < 0)
                goto err_udp_mib;
+       if (snmp6_mib_init((void **)udplite_stats_in6, sizeof (struct udp_mib),
+                          __alignof__(struct udp_mib)) < 0)
+               goto err_udplite_mib;
        return 0;
 
+err_udplite_mib:
+       snmp6_mib_free((void **)udp_stats_in6);
 err_udp_mib:
        snmp6_mib_free((void **)icmpv6_statistics);
 err_icmp_mib:
        snmp6_mib_free((void **)ipv6_statistics);
 err_ip_mib:
        return -ENOMEM;
-       
+
 }
 
 static void cleanup_ipv6_mibs(void)
@@ -753,12 +757,13 @@ static void cleanup_ipv6_mibs(void)
        snmp6_mib_free((void **)ipv6_statistics);
        snmp6_mib_free((void **)icmpv6_statistics);
        snmp6_mib_free((void **)udp_stats_in6);
+       snmp6_mib_free((void **)udplite_stats_in6);
 }
 
 static int __init inet6_init(void)
 {
        struct sk_buff *dummy_skb;
-        struct list_head *r;
+       struct list_head *r;
        int err;
 
        BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb));
@@ -780,10 +785,14 @@ static int __init inet6_init(void)
        if (err)
                goto out_unregister_tcp_proto;
 
-       err = proto_register(&rawv6_prot, 1);
+       err = proto_register(&udplitev6_prot, 1);
        if (err)
                goto out_unregister_udp_proto;
 
+       err = proto_register(&rawv6_prot, 1);
+       if (err)
+               goto out_unregister_udplite_proto;
+
 
        /* Register the socket-side information for inet6_create.  */
        for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
@@ -805,7 +814,7 @@ static int __init inet6_init(void)
        err = init_ipv6_mibs();
        if (err)
                goto out_unregister_sock;
-       
+
        /*
         *      ipngwg API draft makes clear that the correct semantics
         *      for TCP and UDP is to consider one TCP and UDP instance
@@ -837,6 +846,8 @@ static int __init inet6_init(void)
                goto proc_tcp6_fail;
        if (udp6_proc_init())
                goto proc_udp6_fail;
+       if (udplite6_proc_init())
+               goto proc_udplite6_fail;
        if (ipv6_misc_proc_init())
                goto proc_misc6_fail;
 
@@ -862,6 +873,7 @@ static int __init inet6_init(void)
 
        /* Init v6 transport protocols. */
        udpv6_init();
+       udplitev6_init();
        tcpv6_init();
 
        ipv6_packet_init();
@@ -879,6 +891,8 @@ proc_if6_fail:
 proc_anycast6_fail:
        ipv6_misc_proc_exit();
 proc_misc6_fail:
+       udplite6_proc_exit();
+proc_udplite6_fail:
        udp6_proc_exit();
 proc_udp6_fail:
        tcp6_proc_exit();
@@ -902,6 +916,8 @@ out_unregister_sock:
        sock_unregister(PF_INET6);
 out_unregister_raw_proto:
        proto_unregister(&rawv6_prot);
+out_unregister_udplite_proto:
+       proto_unregister(&udplitev6_prot);
 out_unregister_udp_proto:
        proto_unregister(&udpv6_prot);
 out_unregister_tcp_proto:
@@ -917,10 +933,11 @@ static void __exit inet6_exit(void)
 #ifdef CONFIG_PROC_FS
        if6_proc_exit();
        ac6_proc_exit();
-       ipv6_misc_proc_exit();
-       udp6_proc_exit();
-       tcp6_proc_exit();
-       raw6_proc_exit();
+       ipv6_misc_proc_exit();
+       udp6_proc_exit();
+       udplite6_proc_exit();
+       tcp6_proc_exit();
+       raw6_proc_exit();
 #endif
 #ifdef CONFIG_IPV6_MIP6
        mip6_fini();
@@ -935,7 +952,7 @@ static void __exit inet6_exit(void)
        ndisc_cleanup();
        icmpv6_cleanup();
 #ifdef CONFIG_SYSCTL
-       ipv6_sysctl_unregister();       
+       ipv6_sysctl_unregister();
 #endif
        cleanup_ipv6_mibs();
        proto_unregister(&rawv6_prot);