Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6.git] / net / ipv6 / ipv6_sockglue.c
index 030c0c9..2aa294b 100644 (file)
@@ -59,7 +59,7 @@ DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly;
 struct ip6_ra_chain *ip6_ra_chain;
 DEFINE_RWLOCK(ip6_ra_lock);
 
-int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
+int ip6_ra_control(struct sock *sk, int sel)
 {
        struct ip6_ra_chain *ra, *new_ra, **rap;
 
@@ -81,8 +81,6 @@ int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
                        *rap = ra->next;
                        write_unlock_bh(&ip6_ra_lock);
 
-                       if (ra->destructor)
-                               ra->destructor(sk);
                        sock_put(sk);
                        kfree(ra);
                        return 0;
@@ -94,7 +92,6 @@ int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
        }
        new_ra->sk = sk;
        new_ra->sel = sel;
-       new_ra->destructor = destructor;
        new_ra->next = ra;
        *rap = new_ra;
        sock_hold(sk);
@@ -349,6 +346,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
                 */
                if (optlen == 0)
                        optval = NULL;
+               else if (optval == NULL)
+                       goto e_inval;
                else if (optlen < sizeof(struct ipv6_opt_hdr) ||
                         optlen & 0x7 || optlen > 8 * 255)
                        goto e_inval;
@@ -367,11 +366,16 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
                }
 
                /* routing header option needs extra check */
+               retv = -EINVAL;
                if (optname == IPV6_RTHDR && opt && opt->srcrt) {
                        struct ipv6_rt_hdr *rthdr = opt->srcrt;
                        switch (rthdr->type) {
 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
                        case IPV6_SRCRT_TYPE_2:
+                               if (rthdr->hdrlen != 2 ||
+                                   rthdr->segments_left != 1)
+                                       goto sticky_done;
+
                                break;
 #endif
                        default:
@@ -632,7 +636,7 @@ done:
        case IPV6_ROUTER_ALERT:
                if (optlen < sizeof(int))
                        goto e_inval;
-               retv = ip6_ra_control(sk, val, NULL);
+               retv = ip6_ra_control(sk, val);
                break;
        case IPV6_MTU_DISCOVER:
                if (optlen < sizeof(int))
@@ -912,7 +916,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
                } else {
                        if (np->rxopt.bits.rxinfo) {
                                struct in6_pktinfo src_info;
-                               src_info.ipi6_ifindex = np->mcast_oif;
+                               src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : sk->sk_bound_dev_if;
                                ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
                                put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
                        }
@@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
                        }
                        if (np->rxopt.bits.rxoinfo) {
                                struct in6_pktinfo src_info;
-                               src_info.ipi6_ifindex = np->mcast_oif;
+                               src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif : sk->sk_bound_dev_if;
                                ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
                                put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
                        }
@@ -1041,7 +1045,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
                        dst_release(dst);
                }
                if (val < 0)
-                       val = ipv6_devconf.hop_limit;
+                       val = sock_net(sk)->ipv6.devconf_all->hop_limit;
                break;
        }