net/: Fix a sixlowpan typo bug recently introduced; Rename g_ipv6_allzeroaddre with the more meaning g_ipv6_unspecaddr since the all-zero address is the IPv6 unspecified address (sometime IN6_ADDR_ANY). Remove more inline tests for IPv6 multicast with tcommint net_is_addr_mcast() macro. Update some comments.

This commit is contained in:
Gregory Nutt
2018-06-23 12:53:27 -06:00
parent 5bb216fb90
commit a0e169ad7b
19 changed files with 85 additions and 63 deletions
+3 -3
View File
@@ -879,7 +879,7 @@ static void w25_cacheflush(struct w25_dev_s *priv)
/* Write entire erase block to FLASH */
w25_pagewrite(priv, priv->sector, (off_t)priv->esectno << W25_SECTOR_SHIFT,
W25_SECTOR_SIZE);
W25_SECTOR_SIZE);
/* The case is no long dirty and the FLASH is no longer erased */
@@ -905,8 +905,8 @@ static FAR uint8_t *w25_cacheread(struct w25_dev_s *priv, off_t sector)
* shift to the right by 3 to get the sector number in 4096 increments.
*/
shift = W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT;
esectno = sector >> shift;
shift = W25_SECTOR_SHIFT - W25_SECTOR512_SHIFT;
esectno = sector >> shift;
finfo("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift);
/* Check if the requested erase block is already in the cache */
+25 -8
View File
@@ -563,7 +563,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_loopback
*
* Description:
* Is Ithe Pv6 address a the loopback address?
* Is Ithe Pv6 address a the loopback address? See RFC 4291 (replaces
* 3513).
*
****************************************************************************/
@@ -575,7 +576,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_unspecified
*
* Description:
* Is Ithe IPv6 address the unspecified address?
* Is Ithe IPv6 address the unspecified address? See RFC 4291 (replaces
* 3513).
*
****************************************************************************/
@@ -587,7 +589,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_mcast
*
* Description:
* Is address a multicast address? See RFC 3513:
* Is address a multicast address? See RFC 4291 (replaces 3513):
*
* An IPv6 multicast address is an identifier for a group of interfaces
* (typically on different nodes). An interface may belong to any number
@@ -598,8 +600,9 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* |11111111|flgs|scop| group ID |
* +--------+----+----+---------------------------------------------+
*
* binary 11111111 at the start of the address identifies the address as
* being a multicast address.
* Bits 120-127: Prefix == 0b11111111
* Bits 116-119: Flags (3 defined)
* Bits 112-115: Scope
*
****************************************************************************/
@@ -609,7 +612,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_linklocal_allnodes_mcast
*
* Description:
* Is IPv6 address a the link local all-nodes multicast address?
* Is IPv6 address a the link local all-nodes multicast address? See RFC
* 2375
*
****************************************************************************/
@@ -621,7 +625,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_linklocal_allrouters_mcast
*
* Description:
* Is IPv6 address a the link local all-routers multicast address?
* Is IPv6 address a the link local all-routers multicast address? See RFC
* 2375
*
****************************************************************************/
@@ -633,12 +638,24 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
* Name: net_is_addr_linklocal
*
* Description:
* Checks whether the address a is link local.
* Checks whether the address 'a' is a link local unicast address. See
* RFC 4291 (replaces 3513).
*
****************************************************************************/
#define net_is_addr_linklocal(a) ((a)[0] == HTONS(0xfe80))
/****************************************************************************
* Name: net_is_addr_sitelocal
*
* Description:
* Checks whether the address 'a' is a site local unicast address. See
* RFC 4291 (replaces 3513).
*
****************************************************************************/
#define net_is_addr_sitelocal(a) ((a)[0] == HTONS(0xfec0))
#undef EXTERN
#ifdef __cplusplus
}
+4 -2
View File
@@ -324,12 +324,14 @@ int ipv6_input(FAR struct net_driver_s *dev)
return udp_ipv6_input(dev);
}
/* In other cases, the device must be assigned a non-zero IP address. */
/* In other cases, the device must be assigned a non-zero IP address
* (the all zero address is the "unspecified" address.
*/
else
#endif
#ifdef CONFIG_NET_ICMPv6
if (net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_unspecaddr))
{
/* If we are configured to use ping IP address configuration and
* hasn't been assigned an IP address yet, we accept all ICMP
+1 -1
View File
@@ -516,7 +516,7 @@ int icmpv6_autoconfig(FAR struct net_driver_s *dev)
/* No off-link communications; No router address. */
net_ipv6addr_copy(dev->d_ipv6draddr, g_ipv6_allzeroaddr);
net_ipv6addr_copy(dev->d_ipv6draddr, g_ipv6_unspecaddr);
/* Set a netmask for the local link address */
+3 -3
View File
@@ -212,8 +212,8 @@ int icmpv6_neighbor(const net_ipv6addr_t ipaddr)
* addresses=0xff (ff00::/8.)
*/
if (net_ipv6addr_cmp(ipaddr, g_ipv6_allzeroaddr) ||
(ipaddr[0] & NTOHS(0xff00)) == NTOHS(0xff00))
if (net_ipv6addr_cmp(ipaddr, g_ipv6_unspecaddr) ||
net_is_addr_mcast(ipaddr))
{
/* We don't need to send the Neighbor Solicitation */
@@ -222,7 +222,7 @@ int icmpv6_neighbor(const net_ipv6addr_t ipaddr)
/* Get the device that can route this request */
dev = netdev_findby_ipv6addr(g_ipv6_allzeroaddr, ipaddr);
dev = netdev_findby_ipv6addr(g_ipv6_unspecaddr, ipaddr);
if (!dev)
{
nerr("ERROR: Unreachable: %08lx\n", (unsigned long)ipaddr);
+2 -1
View File
@@ -388,7 +388,8 @@ ssize_t icmpv6_sendto(FAR struct socket *psock, FAR const void *buf, size_t len,
/* Get the device that will be used to route this ICMPv6 ECHO request */
dev = netdev_findby_ipv6addr(g_ipv6_allzeroaddr, inaddr->sin6_addr.s6_addr16);
dev = netdev_findby_ipv6addr(g_ipv6_unspecaddr,
inaddr->sin6_addr.s6_addr16);
if (dev == NULL)
{
nerr("ERROR: Not reachable\n");
+1 -1
View File
@@ -91,7 +91,7 @@ EXTERN uint16_t g_ipid;
/* Well-known IPv6 addresses */
#ifdef CONFIG_NET_IPv6
EXTERN const net_ipv6addr_t g_ipv6_allzeroaddr; /* An address of all zeroes */
EXTERN const net_ipv6addr_t g_ipv6_unspecaddr; /* An address of all zeroes */
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
+4 -2
View File
@@ -61,12 +61,14 @@ uint16_t g_ipid;
#ifdef CONFIG_NET_IPv6
const net_ipv6addr_t g_ipv6_allzeroaddr = /* An address of all zeroes */
/* Unspecified address (all zero). See RFC 4291 (replaces 3513) */
const net_ipv6addr_t g_ipv6_unspecaddr = /* An address of all zeroes */
{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};
/* IPv6 Multi-cast IP addresses */
/* IPv6 Multi-cast IP addresses. See RFC 2375 */
const net_ipv6addr_t g_ipv6_allnodes = /* All link local nodes */
{
+5 -6
View File
@@ -132,12 +132,12 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
return -EOPNOTSUPP;
}
/* Check if bound to local INADDR6_ANY */
/* Check if bound to the IPv6 unspecified address */
if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(lipaddr, g_ipv6_unspecaddr))
{
outaddr->sin6_family = AF_INET6;
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_allzeroaddr, 16);
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_unspecaddr, 16);
*addrlen = sizeof(struct sockaddr_in6);
return OK;
@@ -146,17 +146,16 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
net_lock();
/* Find the device matching the IPv6 address in the connection structure.
* NOTE: listening sockets have no ripaddr. Work around is to use the
* NOTE: listening sockets have no ripaddr. Work around is to use the
* lipaddr when ripaddr is not available.
*/
if (net_ipv6addr_cmp(ripaddr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(ripaddr, g_ipv6_unspecaddr))
{
ripaddr = lipaddr;
}
dev = netdev_findby_ipv6addr(*lipaddr, *ripaddr);
if (!dev)
{
net_unlock();
+3 -7
View File
@@ -43,6 +43,7 @@
#include <debug.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/netdev.h>
#include "route/route.h"
@@ -159,12 +160,7 @@ void neighbor_out(FAR struct net_driver_s *dev)
* 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
/* First check if destination is a IPv6 multicast address.
*
* REVISIT: Need to revisit IPv6 broadcast support. Broadcast
* IP addresses are not used with IPv6; multicast is used instead.
@@ -172,7 +168,7 @@ void neighbor_out(FAR struct net_driver_s *dev)
* broadcast Ethernet address?
*/
if ((ip->destipaddr[0] & HTONS(0xff00)) == HTONS(0xff00))
if (net_is_addr_mcast(ip->destipaddr))
{
memcpy(eth->dest, g_broadcast_ethaddr.ether_addr_octet,
ETHER_ADDR_LEN);
+4 -2
View File
@@ -304,9 +304,11 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr,
if (net_is_addr_mcast(ripaddr))
{
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
/* Yes.. Check the local, bound address. Is it the IPv6 unspecified
* address?
*/
if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(lipaddr, g_ipv6_unspecaddr))
{
/* Yes.. In this case, I think we are supposed to send the
* broadcast packet out ALL locally available networks. I am not
+1 -1
View File
@@ -183,7 +183,7 @@ static int ifconf_ipv6_callback(FAR struct net_driver_s *dev, FAR void *arg)
* state.
*/
if (!net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_allzeroaddr) &&
if (!net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_unspecaddr) &&
(dev->d_flags & IFF_UP) != 0)
{
/* Check if we would exceed the buffer space provided by the caller.
+1 -1
View File
@@ -220,7 +220,7 @@ static int sixlowpan_tcp_header(FAR struct tcp_conn_s *conn,
/* Copy the source and destination addresses */
net_ipv6addr_hdrcopy(ipv6tcp->ipv6.destipaddr, conn->u.ipv6.raddr);
if (!net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
if (!net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
{
net_ipv6addr_hdrcopy(ipv6tcp->ipv6.srcipaddr, conn->u.ipv6.laddr);
}
+1 -1
View File
@@ -255,7 +255,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
/* Copy the source and destination addresses */
net_ipv6addr_hdrcopy(ipv6udp.ipv6.destipaddr, to6->sin6_addr.in6_u.u6_addr16);
if (!net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
if (!net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
{
net_ipv6addr_hdrcopy(ipv6udp.ipv6.srcipaddr, conn->u.ipv6.laddr);
}
+1 -1
View File
@@ -274,7 +274,7 @@ int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio,
/* Check for a multicast address */
if (net_is_addr_mcast(ipaddr[0]))
if (net_is_addr_mcast(ipaddr))
{
DEBUGASSERT(radio->r_properties != NULL);
ret = radio->r_properties(radio, &properties);
+8 -8
View File
@@ -179,13 +179,13 @@ tcp_ipv6_listener(const net_ipv6addr_t ipaddr, uint16_t portno)
if (conn->tcpstateflags != TCP_CLOSED && conn->lport == portno)
{
/* If there are multiple interface devices, then the local IP
* address of the connection must also match. INADDR_ANY is a
* special case: There can only be instance of a port number
* with INADDR_ANY.
* address of the connection must also match. The IPv6
* unspecified address is a special case: There can only be
* one instance of a port number with the unspecified address.
*/
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, ipaddr) ||
net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
{
/* The port number is in use, return the connection */
@@ -408,8 +408,8 @@ static inline FAR struct tcp_conn_s *
* - The remote port number is checked if the connection is bound
* to a remote port.
* - Insist that the destination IP matches the bound address. If
* a socket is bound to INADDRY_ANY, then it should receive all
* packets directed to the port.
* a socket is bound to the IPv6 unspecified address, then it
* should receive all packets directed to the port.
* - Finally, if the connection is bound to a remote IP address,
* the source IP address of the packet is checked.
*
@@ -420,7 +420,7 @@ static inline FAR struct tcp_conn_s *
if (conn->tcpstateflags != TCP_CLOSED &&
tcp->destport == conn->lport &&
tcp->srcport == conn->rport &&
(net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr) ||
(net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr) ||
net_ipv6addr_cmp(*destipaddr, conn->u.ipv6.laddr)) &&
net_ipv6addr_cmp(*srcipaddr, conn->u.ipv6.raddr))
{
@@ -563,7 +563,7 @@ static inline int tcp_ipv6_bind(FAR struct tcp_conn_s *conn,
/* Back out the local address setting */
conn->lport = 0;
net_ipv6addr_copy(conn->u.ipv6.laddr, g_ipv6_allzeroaddr);
net_ipv6addr_copy(conn->u.ipv6.laddr, g_ipv6_unspecaddr);
return ret;
}
+4 -4
View File
@@ -131,12 +131,12 @@ static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn,
}
/* Return success without using device notification if the locally bound
* address is IN6ADDR_ANY. In this case, there may be multiple devices
* that can provide data so the exceptional events from any particular
* device are not important.
* address is the IPv6 unspecified address. In this case, there may be
* multiple devices* that can provide data so the exceptional events from
* any particular device are not important.
*/
if (net_ipv6addr_cmp(addr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(addr, g_ipv6_unspecaddr))
{
return OK;
}
+6 -5
View File
@@ -177,7 +177,7 @@ static FAR struct udp_conn_s *udp_find_conn(uint8_t domain,
{
if (conn->lport == portno &&
(net_ipv6addr_cmp(conn->u.ipv6.laddr, ipaddr->ipv6.laddr) ||
net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr)))
net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr)))
{
return conn;
}
@@ -463,10 +463,11 @@ static inline FAR struct udp_conn_s *
/* Check if the local port accepts any address on this port or
* that there is an exact match between the destipaddr and the
* bound local address. This catches the case of the all nodes
* multicast when the socket is bound to INADDR6_ANY.
* multicast when the socket is bound to the IPv6 unspecified
* address.
*/
(net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr) ||
(net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr) ||
net_ipv6addr_hdrcmp(ip->destipaddr, conn->u.ipv6.laddr))))
{
/* Check if the socket is connection mode. In this case, only
@@ -489,7 +490,7 @@ static inline FAR struct udp_conn_s *
* address, then accept the packet.
*/
(net_ipv6addr_cmp(conn->u.ipv6.raddr, g_ipv6_allzeroaddr) ||
(net_ipv6addr_cmp(conn->u.ipv6.raddr, g_ipv6_unspecaddr) ||
#ifdef CONFIG_NET_BROADCAST
net_ipv6addr_hdrcmp(ip->destipaddr, g_ipv6_allnodes) ||
#endif
@@ -887,7 +888,7 @@ int udp_connect(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr)
else
#endif
{
net_ipv6addr_copy(conn->u.ipv6.raddr, g_ipv6_allzeroaddr);
net_ipv6addr_copy(conn->u.ipv6.raddr, g_ipv6_unspecaddr);
}
#endif /* CONFIG_NET_IPv6 */
}
+8 -6
View File
@@ -105,11 +105,12 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn)
#endif
{
/* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
* address. The IPv6 unspecified address is used as an indication
* that the laddr is uninitialized and that the socket is, hence,
* not bound.
*/
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
{
return NULL;
}
@@ -198,11 +199,12 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
if (net_is_addr_mcast(conn->u.ipv6.raddr))
{
/* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
* address. The IPv6 unspecified address is used as an
* indication that the laddr is uninitialized and that the
* socket is, hence, not bound.
*/
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
{
return NULL;
}