diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index 35177965171..70f7ff82599 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -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 */ diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index bae0091b8c1..88a95dae993 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -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 } diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 328ce73c188..d905c416258 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -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 diff --git a/net/icmpv6/icmpv6_autoconfig.c b/net/icmpv6/icmpv6_autoconfig.c index 0b8939e2540..b5074b77e42 100644 --- a/net/icmpv6/icmpv6_autoconfig.c +++ b/net/icmpv6/icmpv6_autoconfig.c @@ -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 */ diff --git a/net/icmpv6/icmpv6_neighbor.c b/net/icmpv6/icmpv6_neighbor.c index db05e46b32a..f73d702e88d 100644 --- a/net/icmpv6/icmpv6_neighbor.c +++ b/net/icmpv6/icmpv6_neighbor.c @@ -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); diff --git a/net/icmpv6/icmpv6_sendto.c b/net/icmpv6/icmpv6_sendto.c index e179e3d434b..8e5ad48837b 100644 --- a/net/icmpv6/icmpv6_sendto.c +++ b/net/icmpv6/icmpv6_sendto.c @@ -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"); diff --git a/net/inet/inet.h b/net/inet/inet.h index d48e3f39bd3..9e81bda98f8 100644 --- a/net/inet/inet.h +++ b/net/inet/inet.h @@ -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 */ diff --git a/net/inet/inet_globals.c b/net/inet/inet_globals.c index 23b1d65c092..d6f4087be48 100644 --- a/net/inet/inet_globals.c +++ b/net/inet/inet_globals.c @@ -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 */ { diff --git a/net/inet/ipv6_getsockname.c b/net/inet/ipv6_getsockname.c index 1606f568377..8de7c5b7d38 100644 --- a/net/inet/ipv6_getsockname.c +++ b/net/inet/ipv6_getsockname.c @@ -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(); diff --git a/net/neighbor/neighbor_ethernet_out.c b/net/neighbor/neighbor_ethernet_out.c index 4da54e42fc2..60aad3e750e 100644 --- a/net/neighbor/neighbor_ethernet_out.c +++ b/net/neighbor/neighbor_ethernet_out.c @@ -43,6 +43,7 @@ #include #include +#include #include #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); diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index 32e634792a1..5328d04db7d 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -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 diff --git a/net/netdev/netdev_ifconf.c b/net/netdev/netdev_ifconf.c index f3f850c48f1..469974256c5 100644 --- a/net/netdev/netdev_ifconf.c +++ b/net/netdev/netdev_ifconf.c @@ -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. diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 45d1b52b171..66ce10eb357 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -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); } diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 6f99f31b7c6..1b7a591b058 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -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); } diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index 35394134181..8cf4481badc 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -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); diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 9ce5d60e2d6..94b36813061 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -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; } diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index 411e5c9c3d0..feccc8400bb 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -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; } diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index ac45e1173bc..bd8304a5325 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -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 */ } diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index b3ddb60c3d0..d47cb0b783b 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -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; }