Use common macro(s) for calculating link layer header length. From Brennan Ashton.

This commit is contained in:
Gregory Nutt 2015-04-13 13:53:13 -06:00
parent 3d6161a7aa
commit 7a745c3fa4
6 changed files with 50 additions and 33 deletions

View file

@ -481,4 +481,47 @@ uint16_t ipv4_chksum(FAR struct net_driver_s *dev);
#ifdef CONFIG_NET_IPv6
uint16_t ipv6_chksum(FAR struct net_driver_s *dev);
#endif
/****************************************************************************
* Function: netdev_ipv4_hdrlen
*
* Description:
* Provide header length for interface based on device
*
* Input Parameters:
* dev Device structure pointer
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
#if defined(CONFIG_NET_MULTILINK)
# define netdev_ipv4_hdrlen(dev) (dev->d_llhdrlen)
#elif defined(CONFIG_NET_ETHERNET)
# define netdev_ipv4_hdrlen(dev) ETH_HDRLEN
#else /* if defined(CONFIG_NET_SLIP) */
# define netdev_ipv4_hdrlen(dev) 0
#endif
#endif /* CONFIG_NET_IPv4 */
/****************************************************************************
* Function: netdev_ipv6_hdrlen
*
* Description:
* Provide header lenght for interface based on device
*
* Input Parameters:
* dev Device structure pointer
*
****************************************************************************/
#ifdef CONFIG_NET_IPv6
#if defined(CONFIG_NET_MULTILINK)
# define netdev_ipv6_hdrlen(dev) dev->d_llhdrlen
#elif defined(CONFIG_NET_ETHERNET)
# define netdev_ipv6_hdrlen(dev) ETH_HDRLEN
#else /* if defined(CONFIG_NET_SLIP) */
# define netdev_ipv6_hdrlen(dev) 0
#endif
#endif /* CONFIG_NET_IPv6 */
#endif /* __INCLUDE_NUTTX_NET_NETDEV_H */

View file

@ -274,6 +274,8 @@ config LIBC_LOCALTIME
timezone file is required for any another time zone and the environment
variable TZ must be set to the name of that file.
See https://www.iana.org/time-zones
if LIBC_LOCALTIME
config LIBC_TZ_MAX_TIMES

View file

@ -178,13 +178,8 @@ int ipv6_input(FAR struct net_driver_s *dev)
* headers.
*/
#if defined(CONFIG_NET_MULTILINK)
pktlen = (ipv6->len[0] << 8) + ipv6->len[1] + IPv6_HDRLEN + dev->d_llhdrlen;
#elif defined(CONFIG_NET_ETHERNET)
pktlen = (ipv6->len[0] << 8) + ipv6->len[1] + IPv6_HDRLEN + ETH_HDRLEN;
#else /* if defined(CONFIG_NET_SLIP) */
pktlen = (ipv6->len[0] << 8) + ipv6->len[1] + IPv6_HDRLEN;
#endif
pktlen = (ipv6->len[0] << 8) + ipv6->len[1] + IPv6_HDRLEN + netdev_ip +
netdev_ipv6_hdrlen(dev);
if (pktlen <= dev->d_len)
{

View file

@ -182,15 +182,7 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
/* Add the size of the layer layer header to the total size of the
* outgoing packet.
*/
#if defined(CONFIG_NET_MULTILINK)
dev->d_len += dev->d_llhdrlen;
#elif defined(CONFIG_NET_ETHERNET)
dev->d_len += ETH_HDRLEN;
#else /* if defined(CONFIG_NET_SLIP) */
/* SLIP has no link layer header */
#endif
dev->d_len += netdev_ipv6_hdrlen(dev);
nllvdbg("Outgoing ICMPv6 Router Solicitation length: %d (%d)\n",
dev->d_len, (icmp->len[0] << 8) | icmp->len[1]);

View file

@ -210,15 +210,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev,
/* Add the size of the layer layer header to the total size of the
* outgoing packet.
*/
#if defined(CONFIG_NET_MULTILINK)
dev->d_len += dev->d_llhdrlen;
#elif defined(CONFIG_NET_ETHERNET)
dev->d_len += ETH_HDRLEN;
#else /* if defined(CONFIG_NET_SLIP) */
/* SLIP has no link layer header */
#endif
dev->d_len += netdev_ipv6_hdrlen(dev);
nllvdbg("Outgoing ICMPv6 Neighbor Solicitation length: %d (%d)\n",
dev->d_len, (icmp->len[0] << 8) | icmp->len[1]);

View file

@ -245,14 +245,7 @@ void neighbor_out(FAR struct net_driver_s *dev)
* outgoing packet.
*/
#if defined(CONFIG_NET_MULTILINK)
dev->d_len += dev->d_llhdrlen;
#elif defined(CONFIG_NET_ETHERNET)
dev->d_len += ETH_HDRLEN;
#else /* if defined(CONFIG_NET_SLIP) */
/* SLIP has no link layer header */
#endif
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]);
}