static uint16_t icmpv6_neighbor_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, FAR void *priv, uint16_t flags) { FAR struct icmpv6_neighbor_s *state = (FAR struct icmpv6_neighbor_s *)priv; nllvdbg("flags: %04x sent: %d\n", flags, state->snd_sent); if (state) { #ifdef CONFIG_NETDEV_MULTINIC /* Is this the device that we need to route this request? */ if (strncmp((FAR const char *)dev->d_ifname, (FAR const char *)state->snd_ifname, IFNAMSIZ) != 0) { /* No... pass on this one and wait for the device that we want */ return flags; } #endif /* Check if the outgoing packet is available. It may have been claimed * by a send interrupt serving a different thread -OR- if the output * buffer currently contains unprocessed incoming data. In these cases * we will just have to wait for the next polling cycle. */ if (dev->d_sndlen > 0 || (flags & ICMPv6_NEWDATA) != 0) { /* Another thread has beat us sending data or the buffer is busy, * Check for a timeout. If not timed out, wait for the next * polling cycle and check again. */ /* REVISIT: No timeout. Just wait for the next polling cycle */ return flags; } /* It looks like we are good to send the data */ /* Copy the packet data into the device packet buffer and send it */ icmpv6_solicit(dev, state->snd_ipaddr); /* Make sure no additional Neighbor Solicitation overwrites this one. * This flag will be cleared in icmpv6_out(). */ IFF_SET_NOARP(dev->d_flags); /* Don't allow any further call backs. */ state->snd_sent = true; state->snd_cb->flags = 0; state->snd_cb->priv = NULL; state->snd_cb->event = NULL; /* Wake up the waiting thread */ sem_post(&state->snd_sem); } return flags; }
void neighbor_out(FAR struct net_driver_s *dev) { FAR const struct neighbor_addr_s *naddr; FAR struct eth_hdr_s *eth = ETHBUF; FAR struct ipv6_hdr_s *ip = IPv6BUF; net_ipv6addr_t ipaddr; /* Skip sending Neighbor Solicitations when the frame to be transmitted was * written into a packet socket or if we are sending certain Neighbor * messages (solicitation, advertisement, echo request). */ if (IFF_IS_NOARP(dev->d_flags)) { /* Clear the indication and let the packet continue on its way. */ IFF_CLR_NOARP(dev->d_flags); return; } /* Find the destination IPv6 address in the Neighbor Table and construct * the Ethernet header. If the destination IPv6 address isn't on the local * network, we use the default router's IPv6 address instead. * * If no Neighbor Table entry is found, we overwrite the original IPv6 * packet with an Neighbor Solicitation Request for the IPv6 address. */ /* First check if destination is a IPv6 multicast address. IPv6 * multicast addresses in IPv6 have the prefix ff00::/8 * * Bits 120-127: Prefix * Bits 116-119: Flags (1, 2, or 3 defined) * Bits 112-115: Scope * * REVISIT: Need to revisit IPv6 broadcast support. Broadcast * IP addresses are not used with IPv6; multicast is used instead. * Does this mean that all multicast address should go to the * broadcast Ethernet address? */ if ((ip->destipaddr[0] & HTONS(0xff00)) == HTONS(0xff00)) { memcpy(eth->dest, g_broadcast_ethaddr.ether_addr_octet, ETHER_ADDR_LEN); } #ifdef CONFIG_NET_IGMP /* Check if the destination address is a multicast address * * IPv6 multicast addresses are have the high-order octet of the * addresses=0xff (ff00::/8.) * * REVISIT: See comments above. How do we distinguish broadcast * from IGMP multicast? */ #warning Missing logic #endif else { /* Check if the destination address is on the local network. */ if (!net_ipv6addr_maskcmp(ip->destipaddr, dev->d_ipv6addr, dev->d_ipv6netmask)) { /* Destination address is not on the local network */ #ifdef CONFIG_NET_ROUTE /* We have a routing table.. find the correct router to use in * this case (or, as a fall-back, use the device's default router * address). We will use the router IPv6 address instead of the * destination address when determining the MAC address. */ netdev_ipv6_router(dev, ip->destipaddr, ipaddr); #else /* Use the device's default router IPv6 address instead of the * destination address when determining the MAC address. */ net_ipv6addr_copy(ipaddr, dev->d_ipv6draddr); #endif } else { /* Else, we use the destination IPv6 address. */ net_ipv6addr_copy(ipaddr, ip->destipaddr); } /* Check if we already have this destination address in the Neighbor Table */ naddr = neighbor_lookup(ipaddr); if (!naddr) { nllvdbg("IPv6 Neighbor solicitation for IPv6\n"); /* The destination address was not in our Neighbor Table, so we * overwrite the IPv6 packet with an ICMDv6 Neighbor Solicitation * message. */ icmpv6_solicit(dev, ipaddr); return; } /* Build an Ethernet header. */ memcpy(eth->dest, naddr->na_addr.ether_addr_octet, ETHER_ADDR_LEN); } /* Finish populating the Ethernet header */ memcpy(eth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); eth->type = HTONS(ETHTYPE_IP6); /* Add the size of the layer layer header to the total size of the * outgoing packet. */ dev->d_len += netdev_ipv6_hdrlen(dev); nllvdbg("Outgoing IPv6 Packet length: %d (%d)\n", dev->d_len, (ip->len[0] << 8) | ip->len[1]); }