]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv4/ip_sockglue.c
[IPV4]: Add 'rtable' field in struct sk_buff to alias 'dst' and avoid casts
[net-next-2.6.git] / net / ipv4 / ip_sockglue.c
index 6b420aedcdcf55a5578eed3a07c4f54f4ffdb7fd..e7c9e4e72327e7649f6ffe9b567eaa4bc69dff5c 100644 (file)
@@ -57,7 +57,7 @@
 static void ip_cmsg_recv_pktinfo(struct msghdr *msg, struct sk_buff *skb)
 {
        struct in_pktinfo info;
-       struct rtable *rt = (struct rtable *)skb->dst;
+       struct rtable *rt = skb->rtable;
 
        info.ipi_addr.s_addr = ip_hdr(skb)->daddr;
        if (rt) {
@@ -437,10 +437,8 @@ static int do_ip_setsockopt(struct sock *sk, int level,
 
        /* If optlen==0, it is equivalent to val == 0 */
 
-#ifdef CONFIG_IP_MROUTE
-       if (optname >= MRT_BASE && optname <= (MRT_BASE + 10))
+       if (ip_mroute_opt(optname))
                return ip_mroute_setsockopt(sk,optname,optval,optlen);
-#endif
 
        err = 0;
        lock_sock(sk);
@@ -516,11 +514,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,
                        val &= ~3;
                        val |= inet->tos & 3;
                }
-               if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP &&
-                   !capable(CAP_NET_ADMIN)) {
-                       err = -EPERM;
-                       break;
-               }
                if (inet->tos != val) {
                        inet->tos = val;
                        sk->sk_priority = rt_tos2priority(val);
@@ -596,13 +589,13 @@ static int do_ip_setsockopt(struct sock *sk, int level,
                                err = 0;
                                break;
                        }
-                       dev = ip_dev_find(mreq.imr_address.s_addr);
+                       dev = ip_dev_find(&init_net, mreq.imr_address.s_addr);
                        if (dev) {
                                mreq.imr_ifindex = dev->ifindex;
                                dev_put(dev);
                        }
                } else
-                       dev = __dev_get_by_index(mreq.imr_ifindex);
+                       dev = __dev_get_by_index(&init_net, mreq.imr_ifindex);
 
 
                err = -EADDRNOTAVAIL;
@@ -659,7 +652,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
                        break;
                }
                msf = kmalloc(optlen, GFP_KERNEL);
-               if (msf == 0) {
+               if (!msf) {
                        err = -ENOBUFS;
                        break;
                }
@@ -816,7 +809,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
                        break;
                }
                gsf = kmalloc(optlen,GFP_KERNEL);
-               if (gsf == 0) {
+               if (!gsf) {
                        err = -ENOBUFS;
                        break;
                }
@@ -836,7 +829,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
                }
                msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
                msf = kmalloc(msize,GFP_KERNEL);
-               if (msf == 0) {
+               if (!msf) {
                        err = -ENOBUFS;
                        goto mc_msf_out;
                }
@@ -909,11 +902,9 @@ int ip_setsockopt(struct sock *sk, int level,
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default case */
        if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
-               optname != IP_IPSEC_POLICY && optname != IP_XFRM_POLICY
-#ifdef CONFIG_IP_MROUTE
-               && (optname < MRT_BASE || optname > (MRT_BASE + 10))
-#endif
-          ) {
+                       optname != IP_IPSEC_POLICY &&
+                       optname != IP_XFRM_POLICY &&
+                       !ip_mroute_opt(optname)) {
                lock_sock(sk);
                err = nf_setsockopt(sk, PF_INET, optname, optval, optlen);
                release_sock(sk);
@@ -935,11 +926,9 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default case */
        if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
-           optname != IP_IPSEC_POLICY && optname != IP_XFRM_POLICY
-#ifdef CONFIG_IP_MROUTE
-           && (optname < MRT_BASE || optname > (MRT_BASE + 10))
-#endif
-          ) {
+                       optname != IP_IPSEC_POLICY &&
+                       optname != IP_XFRM_POLICY &&
+                       !ip_mroute_opt(optname)) {
                lock_sock(sk);
                err = compat_nf_setsockopt(sk, PF_INET, optname,
                                           optval, optlen);
@@ -967,11 +956,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
        if (level != SOL_IP)
                return -EOPNOTSUPP;
 
-#ifdef CONFIG_IP_MROUTE
-       if (optname >= MRT_BASE && optname <= MRT_BASE+10) {
+       if (ip_mroute_opt(optname))
                return ip_mroute_getsockopt(sk,optname,optval,optlen);
-       }
-#endif
 
        if (get_user(len,optlen))
                return -EFAULT;
@@ -1171,11 +1157,8 @@ int ip_getsockopt(struct sock *sk, int level,
        err = do_ip_getsockopt(sk, level, optname, optval, optlen);
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default case */
-       if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS
-#ifdef CONFIG_IP_MROUTE
-               && (optname < MRT_BASE || optname > MRT_BASE+10)
-#endif
-          ) {
+       if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS &&
+                       !ip_mroute_opt(optname)) {
                int len;
 
                if (get_user(len,optlen))
@@ -1200,11 +1183,8 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname,
        int err = do_ip_getsockopt(sk, level, optname, optval, optlen);
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default case */
-       if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS
-#ifdef CONFIG_IP_MROUTE
-           && (optname < MRT_BASE || optname > MRT_BASE+10)
-#endif
-          ) {
+       if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS &&
+                       !ip_mroute_opt(optname)) {
                int len;
 
                if (get_user(len, optlen))