[NET]: cleanup extra semicolons
[powerpc.git] / net / ipv6 / ndisc.c
index 121f31c..4ee1216 100644 (file)
@@ -319,6 +319,8 @@ int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int d
        return -EINVAL;
 }
 
+EXPORT_SYMBOL(ndisc_mc_map);
+
 static u32 ndisc_hash(const void *pkey, const struct net_device *dev)
 {
        const u32 *p32 = pkey;
@@ -447,6 +449,8 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
        ifp = ipv6_get_ifaddr(solicited_addr, dev, 1);
        if (ifp) {
                src_addr = solicited_addr;
+               if (ifp->flags & IFA_F_OPTIMISTIC)
+                       override = 0;
                in6_ifa_put(ifp);
        } else {
                if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
@@ -488,8 +492,9 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
        ip6_nd_hdr(sk, skb, dev, src_addr, daddr, IPPROTO_ICMPV6, len);
 
-       msg = (struct nd_msg *)skb_put(skb, len);
-       skb->h.raw = (unsigned char*)msg;
+       skb->transport_header = skb->tail;
+       skb_put(skb, len);
+       msg = (struct nd_msg *)skb_transport_header(skb);
 
        msg->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
        msg->icmph.icmp6_code = 0;
@@ -542,7 +547,8 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
        int send_llinfo;
 
        if (saddr == NULL) {
-               if (ipv6_get_lladdr(dev, &addr_buf))
+               if (ipv6_get_lladdr(dev, &addr_buf,
+                                  (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC)))
                        return;
                saddr = &addr_buf;
        }
@@ -578,8 +584,9 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
        ip6_nd_hdr(sk, skb, dev, saddr, daddr, IPPROTO_ICMPV6, len);
 
-       msg = (struct nd_msg *)skb_put(skb, len);
-       skb->h.raw = (unsigned char*)msg;
+       skb->transport_header = skb->tail;
+       skb_put(skb, len);
+       msg = (struct nd_msg *)skb_transport_header(skb);
        msg->icmph.icmp6_type = NDISC_NEIGHBOUR_SOLICITATION;
        msg->icmph.icmp6_code = 0;
        msg->icmph.icmp6_cksum = 0;
@@ -593,7 +600,7 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
                                       dev->addr_len, dev->type);
 
        /* checksum */
-       msg->icmph.icmp6_cksum = csum_ipv6_magic(&skb->nh.ipv6h->saddr,
+       msg->icmph.icmp6_cksum = csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
                                                 daddr, len,
                                                 IPPROTO_ICMPV6,
                                                 csum_partial((__u8 *) msg,
@@ -622,9 +629,32 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr,
        struct sk_buff *skb;
        struct icmp6hdr *hdr;
        __u8 * opt;
+       int send_sllao = dev->addr_len;
        int len;
        int err;
 
+
+#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
+       /*
+        * According to section 2.2 of RFC 4429, we must not
+        * send router solicitations with a sllao from
+        * optimistic addresses, but we may send the solicitation
+        * if we don't include the sllao.  So here we check
+        * if our address is optimistic, and if so, we
+        * supress the inclusion of the sllao.
+        */
+       if (send_sllao) {
+               struct inet6_ifaddr *ifp = ipv6_get_ifaddr(saddr, dev, 1);
+               if (ifp) {
+                       if (ifp->flags & IFA_F_OPTIMISTIC)  {
+                               send_sllao = 0;
+                       }
+                       in6_ifa_put(ifp);
+               } else {
+                       send_sllao = 0;
+               }
+       }
+#endif
        ndisc_flow_init(&fl, NDISC_ROUTER_SOLICITATION, saddr, daddr,
                        dev->ifindex);
 
@@ -637,7 +667,7 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr,
                return;
 
        len = sizeof(struct icmp6hdr);
-       if (dev->addr_len)
+       if (send_sllao)
                len += ndisc_opt_addr_space(dev);
 
        skb = sock_alloc_send_skb(sk,
@@ -655,8 +685,9 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr,
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
        ip6_nd_hdr(sk, skb, dev, saddr, daddr, IPPROTO_ICMPV6, len);
 
-       hdr = (struct icmp6hdr *)skb_put(skb, len);
-       skb->h.raw = (unsigned char*)hdr;
+       skb->transport_header = skb->tail;
+       skb_put(skb, len);
+       hdr = icmp6_hdr(skb);
        hdr->icmp6_type = NDISC_ROUTER_SOLICITATION;
        hdr->icmp6_code = 0;
        hdr->icmp6_cksum = 0;
@@ -664,12 +695,12 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr,
 
        opt = (u8*) (hdr + 1);
 
-       if (dev->addr_len)
+       if (send_sllao)
                ndisc_fill_addr_option(opt, ND_OPT_SOURCE_LL_ADDR, dev->dev_addr,
                                       dev->addr_len, dev->type);
 
        /* checksum */
-       hdr->icmp6_cksum = csum_ipv6_magic(&skb->nh.ipv6h->saddr, daddr, len,
+       hdr->icmp6_cksum = csum_ipv6_magic(&ipv6_hdr(skb)->saddr, daddr, len,
                                           IPPROTO_ICMPV6,
                                           csum_partial((__u8 *) hdr, len, 0));
 
@@ -708,8 +739,8 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
        struct in6_addr *target = (struct in6_addr *)&neigh->primary_key;
        int probes = atomic_read(&neigh->probes);
 
-       if (skb && ipv6_chk_addr(&skb->nh.ipv6h->saddr, dev, 1))
-               saddr = &skb->nh.ipv6h->saddr;
+       if (skb && ipv6_chk_addr(&ipv6_hdr(skb)->saddr, dev, 1))
+               saddr = &ipv6_hdr(skb)->saddr;
 
        if ((probes -= neigh->parms->ucast_probes) < 0) {
                if (!(neigh->nud_state & NUD_VALID)) {
@@ -732,11 +763,12 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
 
 static void ndisc_recv_ns(struct sk_buff *skb)
 {
-       struct nd_msg *msg = (struct nd_msg *)skb->h.raw;
-       struct in6_addr *saddr = &skb->nh.ipv6h->saddr;
-       struct in6_addr *daddr = &skb->nh.ipv6h->daddr;
+       struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+       struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
+       struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
        u8 *lladdr = NULL;
-       u32 ndoptlen = skb->tail - msg->opt;
+       u32 ndoptlen = skb->tail - (skb->transport_header +
+                                   offsetof(struct nd_msg, opt));
        struct ndisc_options ndopts;
        struct net_device *dev = skb->dev;
        struct inet6_ifaddr *ifp;
@@ -796,28 +828,40 @@ static void ndisc_recv_ns(struct sk_buff *skb)
        inc = ipv6_addr_is_multicast(daddr);
 
        if ((ifp = ipv6_get_ifaddr(&msg->target, dev, 1)) != NULL) {
-               if (ifp->flags & IFA_F_TENTATIVE) {
-                       /* Address is tentative. If the source
-                          is unspecified address, it is someone
-                          does DAD, otherwise we ignore solicitations
-                          until DAD timer expires.
-                        */
-                       if (!dad)
+
+               if (ifp->flags & (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC)) {
+                       if (dad) {
+                               if (dev->type == ARPHRD_IEEE802_TR) {
+                                       const unsigned char *sadr;
+                                       sadr = skb_mac_header(skb);
+                                       if (((sadr[8] ^ dev->dev_addr[0]) & 0x7f) == 0 &&
+                                           sadr[9] == dev->dev_addr[1] &&
+                                           sadr[10] == dev->dev_addr[2] &&
+                                           sadr[11] == dev->dev_addr[3] &&
+                                           sadr[12] == dev->dev_addr[4] &&
+                                           sadr[13] == dev->dev_addr[5]) {
+                                               /* looped-back to us */
+                                               goto out;
+                                       }
+                               }
+
+                               /*
+                                * We are colliding with another node
+                                * who is doing DAD
+                                * so fail our DAD process
+                                */
+                               addrconf_dad_failure(ifp);
                                goto out;
-                       if (dev->type == ARPHRD_IEEE802_TR) {
-                               unsigned char *sadr = skb->mac.raw;
-                               if (((sadr[8] ^ dev->dev_addr[0]) & 0x7f) == 0 &&
-                                   sadr[9] == dev->dev_addr[1] &&
-                                   sadr[10] == dev->dev_addr[2] &&
-                                   sadr[11] == dev->dev_addr[3] &&
-                                   sadr[12] == dev->dev_addr[4] &&
-                                   sadr[13] == dev->dev_addr[5]) {
-                                       /* looped-back to us */
+                       } else {
+                               /*
+                                * This is not a dad solicitation.
+                                * If we are an optimistic node,
+                                * we should respond.
+                                * Otherwise, we should ignore it.
+                                */
+                               if (!(ifp->flags & IFA_F_OPTIMISTIC))
                                        goto out;
-                               }
                        }
-                       addrconf_dad_failure(ifp);
-                       return;
                }
 
                idev = ifp->idev;
@@ -898,11 +942,12 @@ out:
 
 static void ndisc_recv_na(struct sk_buff *skb)
 {
-       struct nd_msg *msg = (struct nd_msg *)skb->h.raw;
-       struct in6_addr *saddr = &skb->nh.ipv6h->saddr;
-       struct in6_addr *daddr = &skb->nh.ipv6h->daddr;
+       struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+       struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
+       struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
        u8 *lladdr = NULL;
-       u32 ndoptlen = skb->tail - msg->opt;
+       u32 ndoptlen = skb->tail - (skb->transport_header +
+                                   offsetof(struct nd_msg, opt));
        struct ndisc_options ndopts;
        struct net_device *dev = skb->dev;
        struct inet6_ifaddr *ifp;
@@ -1000,11 +1045,11 @@ out:
 
 static void ndisc_recv_rs(struct sk_buff *skb)
 {
-       struct rs_msg *rs_msg = (struct rs_msg *) skb->h.raw;
+       struct rs_msg *rs_msg = (struct rs_msg *)skb_transport_header(skb);
        unsigned long ndoptlen = skb->len - sizeof(*rs_msg);
        struct neighbour *neigh;
        struct inet6_dev *idev;
-       struct in6_addr *saddr = &skb->nh.ipv6h->saddr;
+       struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
        struct ndisc_options ndopts;
        u8 *lladdr = NULL;
 
@@ -1057,7 +1102,7 @@ out:
 
 static void ndisc_router_discovery(struct sk_buff *skb)
 {
-       struct ra_msg *ra_msg = (struct ra_msg *) skb->h.raw;
+       struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header(skb);
        struct neighbour *neigh = NULL;
        struct inet6_dev *in6_dev;
        struct rt6_info *rt = NULL;
@@ -1068,9 +1113,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
 
        __u8 * opt = (__u8 *)(ra_msg + 1);
 
-       optlen = (skb->tail - skb->h.raw) - sizeof(struct ra_msg);
+       optlen = (skb->tail - skb->transport_header) - sizeof(struct ra_msg);
 
-       if (!(ipv6_addr_type(&skb->nh.ipv6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
+       if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
                ND_PRINTK2(KERN_WARNING
                           "ICMPv6 RA: source address is not link-local.\n");
                return;
@@ -1136,7 +1181,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
                pref = ICMPV6_ROUTER_PREF_MEDIUM;
 #endif
 
-       rt = rt6_get_dflt_router(&skb->nh.ipv6h->saddr, skb->dev);
+       rt = rt6_get_dflt_router(&ipv6_hdr(skb)->saddr, skb->dev);
 
        if (rt)
                neigh = rt->rt6i_nexthop;
@@ -1151,7 +1196,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
                ND_PRINTK3(KERN_DEBUG
                           "ICMPv6 RA: adding default router.\n");
 
-               rt = rt6_add_dflt_router(&skb->nh.ipv6h->saddr, skb->dev, pref);
+               rt = rt6_add_dflt_router(&ipv6_hdr(skb)->saddr, skb->dev, pref);
                if (rt == NULL) {
                        ND_PRINTK0(KERN_ERR
                                   "ICMPv6 RA: %s() failed to add default route.\n",
@@ -1223,7 +1268,7 @@ skip_defrtr:
         */
 
        if (!neigh)
-               neigh = __neigh_lookup(&nd_tbl, &skb->nh.ipv6h->saddr,
+               neigh = __neigh_lookup(&nd_tbl, &ipv6_hdr(skb)->saddr,
                                       skb->dev, 1);
        if (neigh) {
                u8 *lladdr = NULL;
@@ -1252,7 +1297,7 @@ skip_defrtr:
                        if (((struct route_info *)p)->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen)
                                continue;
                        rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3,
-                                     &skb->nh.ipv6h->saddr);
+                                     &ipv6_hdr(skb)->saddr);
                }
        }
 #endif
@@ -1311,13 +1356,13 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
        int optlen;
        u8 *lladdr = NULL;
 
-       if (!(ipv6_addr_type(&skb->nh.ipv6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
+       if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
                ND_PRINTK2(KERN_WARNING
                           "ICMPv6 Redirect: source address is not link-local.\n");
                return;
        }
 
-       optlen = skb->tail - skb->h.raw;
+       optlen = skb->tail - skb->transport_header;
        optlen -= sizeof(struct icmp6hdr) + 2 * sizeof(struct in6_addr);
 
        if (optlen < 0) {
@@ -1326,7 +1371,7 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
                return;
        }
 
-       icmph = (struct icmp6hdr *) skb->h.raw;
+       icmph = icmp6_hdr(skb);
        target = (struct in6_addr *) (icmph + 1);
        dest = target + 1;
 
@@ -1376,8 +1421,8 @@ static void ndisc_redirect_rcv(struct sk_buff *skb)
 
        neigh = __neigh_lookup(&nd_tbl, target, skb->dev, 1);
        if (neigh) {
-               rt6_redirect(dest, &skb->nh.ipv6h->daddr,
-                            &skb->nh.ipv6h->saddr, neigh, lladdr,
+               rt6_redirect(dest, &ipv6_hdr(skb)->daddr,
+                            &ipv6_hdr(skb)->saddr, neigh, lladdr,
                             on_link);
                neigh_release(neigh);
        }
@@ -1406,21 +1451,21 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
 
        dev = skb->dev;
 
-       if (ipv6_get_lladdr(dev, &saddr_buf)) {
+       if (ipv6_get_lladdr(dev, &saddr_buf, IFA_F_TENTATIVE)) {
                ND_PRINTK2(KERN_WARNING
                           "ICMPv6 Redirect: no link-local address on %s\n",
                           dev->name);
                return;
        }
 
-       if (!ipv6_addr_equal(&skb->nh.ipv6h->daddr, target) &&
+       if (!ipv6_addr_equal(&ipv6_hdr(skb)->daddr, target) &&
            !(ipv6_addr_type(target) & IPV6_ADDR_LINKLOCAL)) {
                ND_PRINTK2(KERN_WARNING
                        "ICMPv6 Redirect: target address is not link-local.\n");
                return;
        }
 
-       ndisc_flow_init(&fl, NDISC_REDIRECT, &saddr_buf, &skb->nh.ipv6h->saddr,
+       ndisc_flow_init(&fl, NDISC_REDIRECT, &saddr_buf, &ipv6_hdr(skb)->saddr,
                        dev->ifindex);
 
        dst = ip6_route_output(NULL, &fl);
@@ -1475,11 +1520,12 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
        hlen = 0;
 
        skb_reserve(buff, LL_RESERVED_SPACE(dev));
-       ip6_nd_hdr(sk, buff, dev, &saddr_buf, &skb->nh.ipv6h->saddr,
+       ip6_nd_hdr(sk, buff, dev, &saddr_buf, &ipv6_hdr(skb)->saddr,
                   IPPROTO_ICMPV6, len);
 
-       icmph = (struct icmp6hdr *)skb_put(buff, len);
-       buff->h.raw = (unsigned char*)icmph;
+       skb_set_transport_header(buff, skb_tail_pointer(buff) - buff->data);
+       skb_put(buff, len);
+       icmph = icmp6_hdr(buff);
 
        memset(icmph, 0, sizeof(struct icmp6hdr));
        icmph->icmp6_type = NDISC_REDIRECT;
@@ -1491,7 +1537,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
        addrp = (struct in6_addr *)(icmph + 1);
        ipv6_addr_copy(addrp, target);
        addrp++;
-       ipv6_addr_copy(addrp, &skb->nh.ipv6h->daddr);
+       ipv6_addr_copy(addrp, &ipv6_hdr(skb)->daddr);
 
        opt = (u8*) (addrp + 1);
 
@@ -1512,9 +1558,9 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
        *(opt++) = (rd_len >> 3);
        opt += 6;
 
-       memcpy(opt, skb->nh.ipv6h, rd_len - 8);
+       memcpy(opt, ipv6_hdr(skb), rd_len - 8);
 
-       icmph->icmp6_cksum = csum_ipv6_magic(&saddr_buf, &skb->nh.ipv6h->saddr,
+       icmph->icmp6_cksum = csum_ipv6_magic(&saddr_buf, &ipv6_hdr(skb)->saddr,
                                             len, IPPROTO_ICMPV6,
                                             csum_partial((u8 *) icmph, len, 0));
 
@@ -1544,14 +1590,14 @@ int ndisc_rcv(struct sk_buff *skb)
        if (!pskb_may_pull(skb, skb->len))
                return 0;
 
-       msg = (struct nd_msg *) skb->h.raw;
+       msg = (struct nd_msg *)skb_transport_header(skb);
 
-       __skb_push(skb, skb->data-skb->h.raw);
+       __skb_push(skb, skb->data - skb_transport_header(skb));
 
-       if (skb->nh.ipv6h->hop_limit != 255) {
+       if (ipv6_hdr(skb)->hop_limit != 255) {
                ND_PRINTK2(KERN_WARNING
                           "ICMPv6 NDISC: invalid hop-limit: %d\n",
-                          skb->nh.ipv6h->hop_limit);
+                          ipv6_hdr(skb)->hop_limit);
                return 0;
        }
 
@@ -1584,7 +1630,7 @@ int ndisc_rcv(struct sk_buff *skb)
        case NDISC_REDIRECT:
                ndisc_redirect_rcv(skb);
                break;
-       };
+       }
 
        return 0;
 }