Networking: Fix netdev_dev_lladdrsize. In some configurations, it could return the wrong size for the address of a packet radio.
This commit is contained in:
parent
91f9e72890
commit
efbb47999f
9 changed files with 97 additions and 62 deletions
|
@ -630,4 +630,3 @@
|
|||
typedef uint16_t net_stats_t;
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_NET_NETCONFG_H */
|
||||
|
||||
|
|
|
@ -124,6 +124,8 @@ static void devif_packet_conversion(FAR struct net_driver_s *dev,
|
|||
{
|
||||
if (dev->d_len > 0)
|
||||
{
|
||||
/* Check if this is a device served by 6LoWPAN */
|
||||
|
||||
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
||||
dev->d_lltype == NET_LL_PKTRADIO)
|
||||
{
|
||||
|
|
|
@ -74,8 +74,6 @@
|
|||
#define ICMPv6RADVERTISE \
|
||||
((struct icmpv6_router_advertise_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
|
||||
|
||||
#define DEV_LLTYPE(d) ((d)->d_lltype)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -165,7 +163,7 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
{
|
||||
/* Save the sender's address mapping in our Neighbor Table. */
|
||||
|
||||
neighbor_add(icmp->srcipaddr, DEV_LLTYPE(dev), adv->tgtlladdr);
|
||||
neighbor_add(dev, icmp->srcipaddr, adv->tgtlladdr);
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
/* Then notify any logic waiting for the Neighbor Advertisement */
|
||||
|
@ -240,7 +238,7 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
|
||||
if (sllopt->opttype == 1 && sllopt->optlen == 1)
|
||||
{
|
||||
neighbor_add(icmp->srcipaddr, DEV_LLTYPE(dev), sllopt->srclladdr);
|
||||
neighbor_add(dev, icmp->srcipaddr, sllopt->srclladdr);
|
||||
}
|
||||
|
||||
FAR struct icmpv6_prefixinfo_s *opt =
|
||||
|
|
|
@ -108,6 +108,8 @@ static void ipfwd_packet_conversion(FAR struct net_driver_s *dev, int proto)
|
|||
{
|
||||
if (dev->d_len > 0)
|
||||
{
|
||||
/* Check if this is a device served by 6LoWPAN */
|
||||
|
||||
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
||||
dev->d_lltype == NET_LL_PKTRADIO)
|
||||
{
|
||||
|
@ -141,7 +143,8 @@ static void ipfwd_packet_conversion(FAR struct net_driver_s *dev, int proto)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
nwarn("WARNING: Unsupported protocol (%u). Packet dropped\n", proto);
|
||||
nwarn("WARNING: Unsupported protocol (%u). Packet dropped\n",
|
||||
proto);
|
||||
}
|
||||
|
||||
dev->d_len = 0;
|
||||
|
|
|
@ -205,6 +205,8 @@ static int ipv6_packet_conversion(FAR struct net_driver_s *dev,
|
|||
|
||||
if (dev->d_len > 0)
|
||||
{
|
||||
/* Check if this is a device served by 6LoWPAN */
|
||||
|
||||
if (fwddev->d_lltype != NET_LL_IEEE802154 &&
|
||||
fwddev->d_lltype != NET_LL_PKTRADIO)
|
||||
{
|
||||
|
|
|
@ -113,6 +113,8 @@ extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES];
|
|||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct net_driver_s; /* Forward reference */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_initialize
|
||||
*
|
||||
|
@ -158,8 +160,8 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr);
|
|||
* already there).
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Driver instance associated with the MAC
|
||||
* ipaddr - The IPv6 address of the mapping.
|
||||
* lltype - The link layer address type
|
||||
* addr - The link layer address of the mapping
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -167,7 +169,7 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
||||
void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr,
|
||||
FAR uint8_t *addr);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
@ -67,8 +68,8 @@
|
|||
* already there).
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Driver instance associated with the MAC
|
||||
* ipaddr - The IPv6 address of the mapping.
|
||||
* lltype - The link layer address type
|
||||
* addr - The link layer address of the mapping
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -76,17 +77,21 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
||||
void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr,
|
||||
FAR uint8_t *addr)
|
||||
{
|
||||
uint8_t lltype;
|
||||
uint8_t oldest_time;
|
||||
int oldest_ndx;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(dev != NULL && addr != NULL);
|
||||
|
||||
/* Find the first unused entry or the oldest used entry. */
|
||||
|
||||
oldest_time = 0;
|
||||
oldest_ndx = 0;
|
||||
lltype = dev->d_lltype;
|
||||
|
||||
for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i)
|
||||
{
|
||||
|
@ -118,7 +123,7 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
|||
net_ipv6addr_copy(g_neighbors[oldest_ndx].ne_ipaddr, ipaddr);
|
||||
|
||||
g_neighbors[oldest_ndx].ne_addr.na_lltype = lltype;
|
||||
g_neighbors[oldest_ndx].ne_addr.na_llsize = netdev_type_lladdrsize(lltype);
|
||||
g_neighbors[oldest_ndx].ne_addr.na_llsize = netdev_dev_lladdrsize(dev);
|
||||
|
||||
memcpy(&g_neighbors[oldest_ndx].ne_addr.u, addr,
|
||||
g_neighbors[oldest_ndx].ne_addr.na_llsize);
|
||||
|
|
|
@ -403,22 +403,6 @@ void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t lipaddr,
|
|||
int netdev_count(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_type_lladdrsize
|
||||
*
|
||||
* Description:
|
||||
* Returns the size of the MAC address associated with a link layer type.
|
||||
*
|
||||
* Parameters:
|
||||
* lltype - link layer type code
|
||||
*
|
||||
* Returned Value:
|
||||
* The size of the MAC address associated with this device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netdev_type_lladdrsize(uint8_t lltype);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_dev_lladdrsize
|
||||
*
|
||||
|
@ -426,14 +410,14 @@ int netdev_type_lladdrsize(uint8_t lltype);
|
|||
* Returns the size of the MAC address associated with a network device.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - A reference to the device of interest
|
||||
* dev - A reference to the device of interest
|
||||
*
|
||||
* Returned Value:
|
||||
* The size of the MAC address associated with this device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define netdev_dev_lladdrsize(dev) netdev_type_lladdrsize((dev)->d_lltype)
|
||||
int netdev_dev_lladdrsize(FAR struct net_driver_s *dev);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
@ -50,73 +51,112 @@
|
|||
|
||||
#include "netdev/netdev.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_pktradio_addrlen
|
||||
*
|
||||
* Description:
|
||||
* Returns the size of the node address associated with a packet radio.
|
||||
* This is probably CONFIG_PKTRADIO_ADDRLEN but we cannot be sure in the
|
||||
* case that there ar mutiple packet radios. In that case, we have to
|
||||
* query the radio for its address length.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - A reference to the device of interest
|
||||
*
|
||||
* Returned Value:
|
||||
* The size of the MAC address associated with this radio
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_WIRELESS_PKTRADIO)
|
||||
static inline int netdev_pktradio_addrlen(FAR struct net_driver_s *dev)
|
||||
{
|
||||
FAR struct sixlowpan_driver_s *radio = (FAR struct sixlowpan_driver_s *)dev;
|
||||
struct sixlowpan_properties_s properties;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(radio != NULL && radio->r_properties != NULL);
|
||||
ret = radio->r_properties(radio, &properties);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return properties.sp_addrlen;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_type_lladdrsize
|
||||
* Name: netdev_dev_lladdrsize
|
||||
*
|
||||
* Description:
|
||||
* Returns the size of the MAC address associated with a link layer type.
|
||||
* Returns the size of the MAC address associated with a network device.
|
||||
*
|
||||
* Parameters:
|
||||
* lltype - link layer type code
|
||||
* dev - A reference to the device of interest
|
||||
*
|
||||
* Returned Value:
|
||||
* The size of the MAC address associated with this device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netdev_type_lladdrsize(uint8_t lltype)
|
||||
int netdev_type_lladdrsize(FAR struct net_driver_s *dev)
|
||||
{
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get the length of the address for this link layer type */
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
if (lltype == NET_LL_ETHERNET)
|
||||
switch (dev->d_lltype)
|
||||
{
|
||||
/* size of the Ethernet MAC address */
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
case NET_LL_ETHERNET:
|
||||
{
|
||||
/* Size of the Ethernet MAC address */
|
||||
|
||||
return IFHWADDRLEN;
|
||||
}
|
||||
else
|
||||
return IFHWADDRLEN;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
#ifdef CONFIG_WIRELESS_IEEE802154
|
||||
if (lltype == NET_LL_IEEE802154)
|
||||
{
|
||||
/* 6LoWPAN can be configured to use either extended or short
|
||||
* addressing.
|
||||
*/
|
||||
case NET_LL_IEEE802154:
|
||||
{
|
||||
/* 6LoWPAN can be configured to use either extended or short
|
||||
* addressing.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
return NET_6LOWPAN_EADDRSIZE;
|
||||
return NET_6LOWPAN_EADDRSIZE;
|
||||
#else
|
||||
return NET_6LOWPAN_SADDRSIZE;
|
||||
return NET_6LOWPAN_SADDRSIZE;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
#endif /* CONFIG_WIRELESS_IEEE802154 */
|
||||
|
||||
#ifdef CONFIG_WIRELESS_PKTRADIO
|
||||
if (lltype == NET_LL_PKTRADIO)
|
||||
{
|
||||
/* REVISIT: This may no be the correct size if there are multiple
|
||||
* packet radios. In that case, it will be the maxim address size
|
||||
* amongst all of the radios.
|
||||
*/
|
||||
case NET_LL_PKTRADIO:
|
||||
{
|
||||
/* Return the size of the packet radio address */
|
||||
|
||||
return CONFIG_PKTRADIO_ADDRLEN;
|
||||
}
|
||||
else
|
||||
return netdev_pktradio_addrlen(dev);
|
||||
}
|
||||
#endif /* CONFIG_WIRELESS_PKTRADIO */
|
||||
#endif /* CONFIG_NET_6LOWPAN */
|
||||
{
|
||||
/* Either the link layer type associated with lltype has no address,
|
||||
* or support for that link layer type is not enabled.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
default:
|
||||
{
|
||||
/* The link layer type associated has no address */
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue