Skip to content

Commit

Permalink
net/: Fix a sixlowpan typo bug recently introduced; Rename g_ipv6_all…
Browse files Browse the repository at this point in the history
…zeroaddre 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.
  • Loading branch information
gregory-nutt committed Jun 23, 2018
1 parent 5bb216f commit a0e169a
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 63 deletions.
6 changes: 3 additions & 3 deletions drivers/mtd/w25.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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 */
Expand Down
33 changes: 25 additions & 8 deletions include/nuttx/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
****************************************************************************/

Expand All @@ -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).
*
****************************************************************************/

Expand All @@ -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
Expand All @@ -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
*
****************************************************************************/

Expand All @@ -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
*
****************************************************************************/

Expand All @@ -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
*
****************************************************************************/

Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions net/devif/ipv6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion net/icmpv6/icmpv6_autoconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
6 changes: 3 additions & 3 deletions net/icmpv6/icmpv6_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion net/icmpv6/icmpv6_sendto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion net/inet/inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 4 additions & 2 deletions net/inet/inet_globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
{
Expand Down
11 changes: 5 additions & 6 deletions net/inet/ipv6_getsockname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
10 changes: 3 additions & 7 deletions net/neighbor/neighbor_ethernet_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -159,20 +160,15 @@ 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.
* Does this mean that all multicast address should go to the
* 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);
Expand Down
6 changes: 4 additions & 2 deletions net/netdev/netdev_findbyaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion net/netdev/netdev_ifconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion net/sixlowpan/sixlowpan_tcpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion net/sixlowpan/sixlowpan_udpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion net/sixlowpan/sixlowpan_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions net/tcp/tcp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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.
*
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions net/tcp/tcp_finddev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit a0e169a

Please sign in to comment.