]> err.no Git - linux-2.6/blobdiff - net/ipv6/ip6_tunnel.c
Merge ../linus
[linux-2.6] / net / ipv6 / ip6_tunnel.c
index fdf1a2fa3a3d4a4663046260642ba1f59844774c..8d918348f5bb62b4b61d8dbb82bc7670c1c98542 100644 (file)
@@ -424,12 +424,9 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                }
                break;
        case ICMPV6_PARAMPROB:
-               /* ignore if parameter problem not caused by a tunnel
-                  encapsulation limit sub-option */
-               if (code != ICMPV6_HDR_FIELD) {
-                       break;
-               }
-               teli = parse_tlv_tnl_enc_lim(skb, skb->data);
+               teli = 0;
+               if (code == ICMPV6_HDR_FIELD)
+                       teli = parse_tlv_tnl_enc_lim(skb, skb->data);
 
                if (teli && teli == ntohl(info) - 2) {
                        tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
@@ -441,6 +438,10 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                                               "tunnel!\n", t->parms.name);
                                rel_msg = 1;
                        }
+               } else if (net_ratelimit()) {
+                       printk(KERN_WARNING
+                              "%s: Recipient unable to parse tunneled "
+                              "packet!\n ", t->parms.name);
                }
                break;
        case ICMPV6_PKT_TOOBIG:
@@ -460,6 +461,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
        if (rel_msg &&  pskb_may_pull(skb, offset + sizeof (*ipv6h))) {
                struct rt6_info *rt;
                struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
+
                if (!skb2)
                        goto out;
 
@@ -494,6 +496,27 @@ static inline void ip6ip6_ecn_decapsulate(struct ipv6hdr *outer_iph,
        if (INET_ECN_is_ce(ipv6_get_dsfield(outer_iph)))
                IP6_ECN_set_ce(inner_iph);
 }
+static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
+{
+       struct ip6_tnl_parm *p = &t->parms;
+       int ret = 0;
+
+       if (p->flags & IP6_TNL_F_CAP_RCV) {
+               struct net_device *ldev = NULL;
+
+               if (p->link)
+                       ldev = dev_get_by_index(p->link);
+
+               if ((ipv6_addr_is_multicast(&p->laddr) ||
+                    likely(ipv6_chk_addr(&p->laddr, ldev, 0))) &&
+                   likely(!ipv6_chk_addr(&p->raddr, NULL, 0)))
+                       ret = 1;
+
+               if (ldev)
+                       dev_put(ldev);
+       }
+       return ret;
+}
 
 /**
  * ip6ip6_rcv - decapsulate IPv6 packet and retransmit it locally
@@ -518,7 +541,7 @@ ip6ip6_rcv(struct sk_buff *skb)
                        goto discard;
                }
 
-               if (!(t->parms.flags & IP6_TNL_F_CAP_RCV)) {
+               if (!ip6_tnl_rcv_ctl(t)) {
                        t->stat.rx_dropped++;
                        read_unlock(&ip6ip6_lock);
                        goto discard;
@@ -550,31 +573,23 @@ discard:
        return 0;
 }
 
-static inline struct ipv6_txoptions *create_tel(__u8 encap_limit)
-{
-       struct ipv6_tlv_tnl_enc_lim *tel;
-       struct ipv6_txoptions *opt;
-       __u8 *raw;
-
-       int opt_len = sizeof(*opt) + 8;
-
-       if (!(opt = kzalloc(opt_len, GFP_ATOMIC))) {
-               return NULL;
-       }
-       opt->tot_len = opt_len;
-       opt->dst0opt = (struct ipv6_opt_hdr *) (opt + 1);
-       opt->opt_nflen = 8;
+struct ipv6_tel_txoption {
+       struct ipv6_txoptions ops;
+       __u8 dst_opt[8];
+};
 
-       tel = (struct ipv6_tlv_tnl_enc_lim *) (opt->dst0opt + 1);
-       tel->type = IPV6_TLV_TNL_ENCAP_LIMIT;
-       tel->length = 1;
-       tel->encap_limit = encap_limit;
+static void init_tel_txopt(struct ipv6_tel_txoption *opt, __u8 encap_limit)
+{
+       memset(opt, 0, sizeof(struct ipv6_tel_txoption));
 
-       raw = (__u8 *) opt->dst0opt;
-       raw[5] = IPV6_TLV_PADN;
-       raw[6] = 1;
+       opt->dst_opt[2] = IPV6_TLV_TNL_ENCAP_LIMIT;
+       opt->dst_opt[3] = 1;
+       opt->dst_opt[4] = encap_limit;
+       opt->dst_opt[5] = IPV6_TLV_PADN;
+       opt->dst_opt[6] = 1;
 
-       return opt;
+       opt->ops.dst0opt = (struct ipv6_opt_hdr *) opt->dst_opt;
+       opt->ops.opt_nflen = 8;
 }
 
 /**
@@ -597,6 +612,34 @@ ip6ip6_tnl_addr_conflict(struct ip6_tnl *t, struct ipv6hdr *hdr)
        return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
 }
 
+static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
+{
+       struct ip6_tnl_parm *p = &t->parms;
+       int ret = 0;
+
+       if (p->flags & IP6_TNL_F_CAP_XMIT) {
+               struct net_device *ldev = NULL;
+
+               if (p->link)
+                       ldev = dev_get_by_index(p->link);
+
+               if (unlikely(!ipv6_chk_addr(&p->laddr, ldev, 0)))
+                       printk(KERN_WARNING
+                              "%s xmit: Local address not yet configured!\n",
+                              p->name);
+               else if (!ipv6_addr_is_multicast(&p->raddr) &&
+                        unlikely(ipv6_chk_addr(&p->raddr, NULL, 0)))
+                       printk(KERN_WARNING
+                              "%s xmit: Routing loop! "
+                              "Remote address found on this node!\n",
+                              p->name);
+               else
+                       ret = 1;
+               if (ldev)
+                       dev_put(ldev);
+       }
+       return ret;
+}
 /**
  * ip6ip6_tnl_xmit - encapsulate packet and send 
  *   @skb: the outgoing socket buffer
@@ -616,8 +659,8 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
        struct ip6_tnl *t = netdev_priv(dev);
        struct net_device_stats *stats = &t->stat;
        struct ipv6hdr *ipv6h = skb->nh.ipv6h;
-       struct ipv6_txoptions *opt = NULL;
        int encap_limit = -1;
+       struct ipv6_tel_txoption opt;
        __u16 offset;
        struct flowi fl;
        struct dst_entry *dst;
@@ -634,10 +677,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
                goto tx_err;
        }
        if (skb->protocol != htons(ETH_P_IPV6) ||
-           !(t->parms.flags & IP6_TNL_F_CAP_XMIT) ||
-           ip6ip6_tnl_addr_conflict(t, ipv6h)) {
+           !ip6_tnl_xmit_ctl(t) || ip6ip6_tnl_addr_conflict(t, ipv6h))
                goto tx_err;
-       }
+
        if ((offset = parse_tlv_tnl_enc_lim(skb, skb->nh.raw)) > 0) {
                struct ipv6_tlv_tnl_enc_lim *tel;
                tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->nh.raw[offset];
@@ -647,9 +689,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
                        goto tx_err;
                }
                encap_limit = tel->encap_limit - 1;
-       } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) {
+       } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
                encap_limit = t->parms.encap_limit;
-       }
+
        memcpy(&fl, &t->fl, sizeof (fl));
        proto = fl.proto;
 
@@ -659,9 +701,6 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
        if ((t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL))
                fl.fl6_flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
 
-       if (encap_limit >= 0 && (opt = create_tel(encap_limit)) == NULL)
-               goto tx_err;
-
        if ((dst = ip6_tnl_dst_check(t)) != NULL)
                dst_hold(dst);
        else {
@@ -682,7 +721,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
                goto tx_err_dst_release;
        }
        mtu = dst_mtu(dst) - sizeof (*ipv6h);
-       if (opt) {
+       if (encap_limit >= 0) {
                max_headroom += 8;
                mtu -= 8;
        }
@@ -720,9 +759,10 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
 
        skb->h.raw = skb->nh.raw;
 
-       if (opt)
-               ipv6_push_nfrag_opts(skb, opt, &proto, NULL);
-
+       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;
        *(__be32*)ipv6h = fl.fl6_flowlabel | htonl(0x60000000);
@@ -746,9 +786,6 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
                stats->tx_aborted_errors++;
        }
        ip6_tnl_dst_store(t, dst);
-
-       kfree(opt);
-
        t->recursion--;
        return 0;
 tx_err_link_failure:
@@ -756,7 +793,6 @@ tx_err_link_failure:
        dst_link_failure(skb);
 tx_err_dst_release:
        dst_release(dst);
-       kfree(opt);
 tx_err:
        stats->tx_errors++;
        stats->tx_dropped++;
@@ -768,39 +804,19 @@ tx_err:
 static void ip6_tnl_set_cap(struct ip6_tnl *t)
 {
        struct ip6_tnl_parm *p = &t->parms;
-       struct in6_addr *laddr = &p->laddr;
-       struct in6_addr *raddr = &p->raddr;
-       int ltype = ipv6_addr_type(laddr);
-       int rtype = ipv6_addr_type(raddr);
+       int ltype = ipv6_addr_type(&p->laddr);
+       int rtype = ipv6_addr_type(&p->raddr);
 
        p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV);
 
-       if (ltype != IPV6_ADDR_ANY && rtype != IPV6_ADDR_ANY &&
-           ((ltype|rtype) &
-            (IPV6_ADDR_UNICAST|
-             IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL|
-             IPV6_ADDR_MAPPED|IPV6_ADDR_RESERVED)) == IPV6_ADDR_UNICAST) {
-               struct net_device *ldev = NULL;
-               int l_ok = 1;
-               int r_ok = 1;
-
-               if (p->link)
-                       ldev = dev_get_by_index(p->link);
-               
-               if (ltype&IPV6_ADDR_UNICAST && !ipv6_chk_addr(laddr, ldev, 0))
-                       l_ok = 0;
-               
-               if (rtype&IPV6_ADDR_UNICAST && ipv6_chk_addr(raddr, NULL, 0))
-                       r_ok = 0;
-               
-               if (l_ok && r_ok) {
-                       if (ltype&IPV6_ADDR_UNICAST)
-                               p->flags |= IP6_TNL_F_CAP_XMIT;
-                       if (rtype&IPV6_ADDR_UNICAST)
-                               p->flags |= IP6_TNL_F_CAP_RCV;
-               }
-               if (ldev)
-                       dev_put(ldev);
+       if (ltype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
+           rtype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
+           !((ltype|rtype) & IPV6_ADDR_LOOPBACK) &&
+           (!((ltype|rtype) & IPV6_ADDR_LINKLOCAL) || p->link)) {
+               if (ltype&IPV6_ADDR_UNICAST)
+                       p->flags |= IP6_TNL_F_CAP_XMIT;
+               if (rtype&IPV6_ADDR_UNICAST)
+                       p->flags |= IP6_TNL_F_CAP_RCV;
        }
 }
 
@@ -834,8 +850,11 @@ static void ip6ip6_tnl_link_config(struct ip6_tnl *t)
        dev->iflink = p->link;
 
        if (p->flags & IP6_TNL_F_CAP_XMIT) {
+               int strict = (ipv6_addr_type(&p->raddr) &
+                             (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
+
                struct rt6_info *rt = rt6_lookup(&p->raddr, &p->laddr,
-                                                p->link, 0);
+                                                p->link, strict);
 
                if (rt == NULL)
                        return;