예제 #1
0
/**
   If this neighbor is unknown, use node to connect to neighbor.
   @return neighbor from bucket.  NULL if given self id.
*/
KDA_Neighbor*
check_neighbor(MPIRPC_Node node, KDA_Neighbor* neighbor)
{
  NOTE_FX(neighbor->id);
  KDA_Neighbor* result;

  if (neighbor_add(neighbor))
    KDA_Join(node, neighbor);

  result = neighbor_lookup(neighbor);
  return result;
}
예제 #2
0
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]);
}