Merged in antmerlino/nuttx/sixlowpan-route (pull request #537)
sixlowpan: Support sending to a router that is on-link and may be able to forward the packet for us if the destination is not reachable directly Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
parent
c93320ccd6
commit
827fa6796e
@ -114,15 +114,13 @@ void sixlowpan_icmpv6_send(FAR struct net_driver_s *dev,
|
|||||||
uint16_t buflen;
|
uint16_t buflen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Get the IEEE 802.15.4 MAC address of the destination. This
|
/* Get the IEEE 802.15.4 MAC address of the next hop. */
|
||||||
* assumes an encoding of the MAC address in the IPv6 address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)fwddev,
|
ret = sixlowpan_nexthopaddr((FAR struct radio_driver_s *)fwddev,
|
||||||
ipv6icmpv6->ipv6.destipaddr, &destmac);
|
ipv6icmpv6->ipv6.destipaddr, &destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to dest MAC address: %d\n", ret);
|
nerr("ERROR: Failed to get dest MAC address: %d\n", ret);
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,11 +782,11 @@ int sixlowpan_input(FAR struct radio_driver_s *radio,
|
|||||||
* address.
|
* address.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip(radio, ipv6hdr->destipaddr,
|
ret = sixlowpan_nexthopaddr(radio, ipv6hdr->destipaddr,
|
||||||
&destmac);
|
&destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to dest MAC address: %d\n", ret);
|
nerr("ERROR: Failed to get dest MAC address: %d\n", ret);
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,6 +564,22 @@ int sixlowpan_uncompresshdr_hc1(FAR struct radio_driver_s *radio,
|
|||||||
FAR uint8_t *bptr);
|
FAR uint8_t *bptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sixlowpan_nexthopaddr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* sixlowpan_nexthopaddr(): If the destination is on-link, extract the
|
||||||
|
* IEEE 802.15.14 destination address from the destination IP address. If the
|
||||||
|
* destination is not reachable directly, use the routing table (if available)
|
||||||
|
* or fall back to the default router IP address and use the router IP address
|
||||||
|
* to derive the IEEE 802.15.4 MAC address.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int sixlowpan_nexthopaddr(FAR struct radio_driver_s *radio,
|
||||||
|
FAR const net_ipv6addr_t ipaddr,
|
||||||
|
FAR struct netdev_varaddr_s *destaddr);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: sixlowpan_islinklocal, sixlowpan_destaddrfromip, and
|
* Name: sixlowpan_islinklocal, sixlowpan_destaddrfromip, and
|
||||||
* sixlowpan_ismacbased
|
* sixlowpan_ismacbased
|
||||||
|
@ -838,11 +838,9 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get the IEEE 802.15.4 MAC address of the destination. This assumes
|
/* Get the IEEE 802.15.4 MAC address of the next hop. */
|
||||||
* an encoding of the MAC address in the IPv6 address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev,
|
ret = sixlowpan_nexthopaddr((FAR struct radio_driver_s *)dev,
|
||||||
conn->u.ipv6.raddr, &destmac);
|
conn->u.ipv6.raddr, &destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -957,11 +955,9 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev,
|
|||||||
uint16_t buflen;
|
uint16_t buflen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Get the IEEE 802.15.4 MAC address of the destination. This
|
/* Get the IEEE 802.15.4 MAC address of the next hop. */
|
||||||
* assumes an encoding of the MAC address in the IPv6 address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)fwddev,
|
ret = sixlowpan_nexthopaddr((FAR struct radio_driver_s *)fwddev,
|
||||||
ipv6hdr->ipv6.destipaddr, &destmac);
|
ipv6hdr->ipv6.destipaddr, &destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -292,11 +292,9 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
|
|||||||
g_netstats.udp.sent++;
|
g_netstats.udp.sent++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get the IEEE 802.15.4 MAC address of the destination This assumes an
|
/* Get the IEEE 802.15.4 MAC address of the next hop. */
|
||||||
* encoding of the MAC address in the IPv6 address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev,
|
ret = sixlowpan_nexthopaddr((FAR struct radio_driver_s *)dev,
|
||||||
to6->sin6_addr.in6_u.u6_addr16, &destmac);
|
to6->sin6_addr.in6_u.u6_addr16, &destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -468,11 +466,9 @@ void sixlowpan_udp_send(FAR struct net_driver_s *dev,
|
|||||||
uint16_t buflen;
|
uint16_t buflen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Get the IEEE 802.15.4 MAC address of the destination. This
|
/* Get the IEEE 802.15.4 MAC address of the next hop. */
|
||||||
* assumes an encoding of the MAC address in the IPv6 address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)fwddev,
|
ret = sixlowpan_nexthopaddr((FAR struct radio_driver_s *)fwddev,
|
||||||
ipv6udp->ipv6.destipaddr, &destmac);
|
ipv6udp->ipv6.destipaddr, &destmac);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +166,63 @@ static void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *eadd
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sixlowpan_nexthopaddr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* sixlowpan_nexthopaddr(): If the destination is on-link, extract the
|
||||||
|
* IEEE 802.15.14 destination address from the destination IP address. If the
|
||||||
|
* destination is not reachable directly, use the routing table (if available)
|
||||||
|
* or fall back to the default router IP address and use the router IP address
|
||||||
|
* to derive the IEEE 802.15.4 MAC address.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int sixlowpan_nexthopaddr(FAR struct radio_driver_s *radio,
|
||||||
|
FAR const net_ipv6addr_t ipaddr,
|
||||||
|
FAR struct netdev_varaddr_s *destaddr)
|
||||||
|
{
|
||||||
|
FAR net_ipv6addr_t router;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Try to get the IEEE 802.15.4 MAC address of the destination. This
|
||||||
|
* assumes an encoding of the MAC address in the IPv6 address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = sixlowpan_destaddrfromip(radio, ipaddr, destaddr);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
/* 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(radio->r_dev, ipaddr, router);
|
||||||
|
#else
|
||||||
|
/* Use the device's default router IPv6 address instead of the
|
||||||
|
* destination address when determining the MAC address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
net_ipv6addr_copy(router, radio->r_dev.d_ipv6draddr);
|
||||||
|
#endif
|
||||||
|
/* Get the IEEE 802.15.4 MAC address of the router. This
|
||||||
|
* assumes an encoding of the MAC address in the IPv6 address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = sixlowpan_destaddrfromip(radio, router, destaddr);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: sixlowpan_destaddrfromip
|
* Name: sixlowpan_destaddrfromip
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user