[NET]: Make the device list and device lookups per namespace.
[safe/jmp/linux-2.6] / net / ipv6 / ip6_tunnel.c
index 30df8e6..937625e 100644 (file)
@@ -235,7 +235,7 @@ static struct ip6_tnl *ip6_tnl_create(struct ip6_tnl_parm *p)
                int i;
                for (i = 1; i < IP6_TNL_MAX; i++) {
                        sprintf(name, "ip6tnl%d", i);
-                       if (__dev_get_by_name(name) == NULL)
+                       if (__dev_get_by_name(&init_net, name) == NULL)
                                break;
                }
                if (i == IP6_TNL_MAX)
@@ -385,7 +385,7 @@ parse_tlv_tnl_enc_lim(struct sk_buff *skb, __u8 * raw)
 
 static int
 ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
-           int *type, int *code, int *msg, __be32 *info, int offset)
+           int *type, int *code, int *msg, __u32 *info, int offset)
 {
        struct ipv6hdr *ipv6h = (struct ipv6hdr *) skb->data;
        struct ip6_tnl *t;
@@ -435,7 +435,7 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
                if ((*code) == ICMPV6_HDR_FIELD)
                        teli = parse_tlv_tnl_enc_lim(skb, skb->data);
 
-               if (teli && teli == ntohl(*info) - 2) {
+               if (teli && teli == *info - 2) {
                        tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
                        if (tel->encap_limit == 0) {
                                if (net_ratelimit())
@@ -452,7 +452,7 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
                }
                break;
        case ICMPV6_PKT_TOOBIG:
-               mtu = ntohl(*info) - offset;
+               mtu = *info - offset;
                if (mtu < IPV6_MIN_MTU)
                        mtu = IPV6_MIN_MTU;
                t->dev->mtu = mtu;
@@ -478,12 +478,12 @@ out:
 
 static int
 ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
-          int type, int code, int offset, __u32 info)
+          int type, int code, int offset, __be32 info)
 {
        int rel_msg = 0;
        int rel_type = type;
        int rel_code = code;
-       __u32 rel_info = info;
+       __u32 rel_info = ntohl(info);
        int err;
        struct sk_buff *skb2;
        struct iphdr *eiph;
@@ -526,7 +526,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
        skb2->dst = NULL;
        skb_pull(skb2, offset);
        skb_reset_network_header(skb2);
-       eiph = skb2->nh.iph;
+       eiph = ip_hdr(skb2);
 
        /* Try to guess incoming interface */
        memset(&fl, 0, sizeof(fl));
@@ -564,10 +564,9 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                        goto out;
 
                skb2->dst->ops->update_pmtu(skb2->dst, rel_info);
-               rel_info = htonl(rel_info);
        }
 
-       icmp_send(skb2, rel_type, rel_code, rel_info);
+       icmp_send(skb2, rel_type, rel_code, htonl(rel_info));
 
 out:
        kfree_skb(skb2);
@@ -576,12 +575,12 @@ out:
 
 static int
 ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
-          int type, int code, int offset, __u32 info)
+          int type, int code, int offset, __be32 info)
 {
        int rel_msg = 0;
        int rel_type = type;
        int rel_code = code;
-       __u32 rel_info = info;
+       __u32 rel_info = ntohl(info);
        int err;
 
        err = ip6_tnl_err(skb, IPPROTO_IPV6, opt, &rel_type, &rel_code,
@@ -602,7 +601,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                skb_reset_network_header(skb2);
 
                /* Try to guess incoming interface */
-               rt = rt6_lookup(&skb2->nh.ipv6h->saddr, NULL, 0, 0);
+               rt = rt6_lookup(&ipv6_hdr(skb2)->saddr, NULL, 0, 0);
 
                if (rt && rt->rt6i_dev)
                        skb2->dev = rt->rt6i_dev;
@@ -625,10 +624,10 @@ static void ip4ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
        __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
 
        if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
-               ipv4_change_dsfield(skb->nh.iph, INET_ECN_MASK, dsfield);
+               ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, dsfield);
 
        if (INET_ECN_is_ce(dsfield))
-               IP_ECN_set_ce(skb->nh.iph);
+               IP_ECN_set_ce(ip_hdr(skb));
 }
 
 static void ip6ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
@@ -636,10 +635,10 @@ static void ip6ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
                                        struct sk_buff *skb)
 {
        if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
-               ipv6_copy_dscp(ipv6h, skb->nh.ipv6h);
+               ipv6_copy_dscp(ipv6h, ipv6_hdr(skb));
 
        if (INET_ECN_is_ce(ipv6_get_dsfield(ipv6h)))
-               IP6_ECN_set_ce(skb->nh.ipv6h);
+               IP6_ECN_set_ce(ipv6_hdr(skb));
 }
 
 static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
@@ -651,7 +650,7 @@ static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
                struct net_device *ldev = NULL;
 
                if (p->link)
-                       ldev = dev_get_by_index(p->link);
+                       ldev = dev_get_by_index(&init_net, p->link);
 
                if ((ipv6_addr_is_multicast(&p->laddr) ||
                     likely(ipv6_chk_addr(&p->laddr, ldev, 0))) &&
@@ -679,10 +678,8 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
                                                    struct ipv6hdr *ipv6h,
                                                    struct sk_buff *skb))
 {
-       struct ipv6hdr *ipv6h;
        struct ip6_tnl *t;
-
-       ipv6h = skb->nh.ipv6h;
+       struct ipv6hdr *ipv6h = ipv6_hdr(skb);
 
        read_lock(&ip6_tnl_lock);
 
@@ -703,7 +700,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
                        goto discard;
                }
                secpath_reset(skb);
-               skb->mac.raw = skb->nh.raw;
+               skb->mac_header = skb->network_header;
                skb_reset_network_header(skb);
                skb->protocol = htons(protocol);
                skb->pkt_type = PACKET_HOST;
@@ -789,7 +786,7 @@ static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
                struct net_device *ldev = NULL;
 
                if (p->link)
-                       ldev = dev_get_by_index(p->link);
+                       ldev = dev_get_by_index(&init_net, p->link);
 
                if (unlikely(!ipv6_chk_addr(&p->laddr, ldev, 0)))
                        printk(KERN_WARNING
@@ -836,7 +833,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
 {
        struct ip6_tnl *t = netdev_priv(dev);
        struct net_device_stats *stats = &t->stat;
-       struct ipv6hdr *ipv6h = skb->nh.ipv6h;
+       struct ipv6hdr *ipv6h = ipv6_hdr(skb);
        struct ipv6_tel_txoption opt;
        struct dst_entry *dst;
        struct net_device *tdev;
@@ -885,8 +882,8 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
         */
        max_headroom += LL_RESERVED_SPACE(tdev);
 
-       if (skb_headroom(skb) < max_headroom ||
-           skb_cloned(skb) || skb_shared(skb)) {
+       if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
+           (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
                struct sk_buff *new_skb;
 
                if (!(new_skb = skb_realloc_headroom(skb, max_headroom)))
@@ -900,15 +897,16 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
        dst_release(skb->dst);
        skb->dst = dst_clone(dst);
 
-       skb->h.raw = skb->nh.raw;
+       skb->transport_header = skb->network_header;
 
        proto = fl->proto;
        if (encap_limit >= 0) {
                init_tel_txopt(&opt, encap_limit);
                ipv6_push_nfrag_opts(skb, &opt.ops, &proto, NULL);
        }
-       skb->nh.raw = skb_push(skb, sizeof(struct ipv6hdr));
-       ipv6h = skb->nh.ipv6h;
+       skb_push(skb, sizeof(struct ipv6hdr));
+       skb_reset_network_header(skb);
+       ipv6h = ipv6_hdr(skb);
        *(__be32*)ipv6h = fl->fl6_flowlabel | htonl(0x60000000);
        dsfield = INET_ECN_encapsulate(0, dsfield);
        ipv6_change_dsfield(ipv6h, ~INET_ECN_MASK, dsfield);
@@ -943,7 +941,7 @@ static inline int
 ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct ip6_tnl *t = netdev_priv(dev);
-       struct iphdr  *iph = skb->nh.iph;
+       struct iphdr  *iph = ip_hdr(skb);
        int encap_limit = -1;
        struct flowi fl;
        __u8 dsfield;
@@ -963,8 +961,8 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
        dsfield = ipv4_get_dsfield(iph);
 
        if ((t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS))
-               fl.fl6_flowlabel |= ntohl(((__u32)iph->tos << IPV6_TCLASS_SHIFT)
-                                         & IPV6_TCLASS_MASK);
+               fl.fl6_flowlabel |= htonl((__u32)iph->tos << IPV6_TCLASS_SHIFT)
+                                         & IPV6_TCLASS_MASK;
 
        err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
        if (err != 0) {
@@ -982,7 +980,7 @@ static inline int
 ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct ip6_tnl *t = netdev_priv(dev);
-       struct ipv6hdr *ipv6h = skb->nh.ipv6h;
+       struct ipv6hdr *ipv6h = ipv6_hdr(skb);
        int encap_limit = -1;
        __u16 offset;
        struct flowi fl;
@@ -994,9 +992,10 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
            !ip6_tnl_xmit_ctl(t) || ip6_tnl_addr_conflict(t, ipv6h))
                return -1;
 
-       if ((offset = parse_tlv_tnl_enc_lim(skb, skb->nh.raw)) > 0) {
+       offset = parse_tlv_tnl_enc_lim(skb, skb_network_header(skb));
+       if (offset > 0) {
                struct ipv6_tlv_tnl_enc_lim *tel;
-               tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->nh.raw[offset];
+               tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset];
                if (tel->encap_limit == 0) {
                        icmpv6_send(skb, ICMPV6_PARAMPROB,
                                    ICMPV6_HDR_FIELD, offset + 2, skb->dev);