mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
IPv6: Remove comparisons to the address with all ones set. IPv6 does not support broadcast addresses and certainly not in that form. Replace with multicast addresses beginning with 0xff02.
This commit is contained in:
@@ -227,20 +227,6 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Well-known IP addresses */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
EXTERN const net_ipv6addr_t g_ipv6_alloneaddr; /* An address of all ones */
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allzeroaddr; /* An address of all zeroes */
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link address */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
|
||||
@@ -76,70 +75,6 @@ uint16_t g_ipid;
|
||||
uint8_t g_reassembly_timer;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
const net_ipv6addr_t g_ipv6_alloneaddr = /* An address of all ones */
|
||||
{
|
||||
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
|
||||
};
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allzeroaddr = /* An address of all zeroes */
|
||||
{
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
|
||||
/* IPv6 Multi-cast IP addresses */
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allnodes = /* All link local nodes */
|
||||
{
|
||||
HTONS(0xff02),
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
HTONS(0x0001)
|
||||
};
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allrouters = /* All link local routers */
|
||||
{
|
||||
HTONS(0xff02),
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
HTONS(0x0002)
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Link-Local Address: Link-local addresses have "1111 1110 10" for the
|
||||
* first ten bits followed by 54 zeroes and then the 64 bit interface
|
||||
* identifier (typically derived from the data link layer address).
|
||||
*/
|
||||
|
||||
const net_ipv6addr_t g_ipv6_llnetmask = /* Netmask for local link address */
|
||||
{
|
||||
0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
|
||||
/* IPv6 Multi-cast Ethernet addresses. Formed from the 16-bit prefix:
|
||||
*
|
||||
* 0x33:0x33:xx:xx:xx:xx:
|
||||
*
|
||||
* and the last 32-bits of the IPv6 IP address
|
||||
*/
|
||||
|
||||
const struct ether_addr g_ipv6_ethallnodes = /* All link local nodes */
|
||||
{
|
||||
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x01 }
|
||||
};
|
||||
|
||||
const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */
|
||||
{
|
||||
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x02 }
|
||||
};
|
||||
|
||||
#endif /* CONFIG_NET_ETHERNET */
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER */
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
@@ -319,15 +319,17 @@ int ipv6_input(FAR struct net_driver_s *dev)
|
||||
goto drop;
|
||||
}
|
||||
|
||||
/* If IP broadcast support is configured, we check for a broadcast
|
||||
/* If UDP broadcast support is configured, we check for a multicast
|
||||
* UDP packet, which may be destined to us (even if there is no IP
|
||||
* address yet assigned to the device as is the case when we are
|
||||
* negotiating over DHCP for an address).
|
||||
* address yet assigned to the device). We should actually pick off
|
||||
* certain multicast address (all hosts multicast address, and the
|
||||
* solicited-node multicast address). We will cheat here and accept
|
||||
* all multicast packets that are sent to the ff02::/16 addresses.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_BROADCAST) && defined(NET_UDP_HAVE_STACK)
|
||||
if (ipv6->proto == IP_PROTO_UDP &&
|
||||
net_ipv6addr_cmp(ipv6->destipaddr, g_ipv6_alloneaddr))
|
||||
ipv6->destipaddr[0] == HTONS(0xff02))
|
||||
{
|
||||
#ifdef CONFIG_NET_IPFORWARD_BROADCAST
|
||||
/* Forward broadcast packets */
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "neighbor/neighbor.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "utils/utils.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include <nuttx/net/icmpv6.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "utils/utils.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "utils/utils.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ SOCK_CSRCS += ipv4_getsockname.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_IPv6),y)
|
||||
SOCK_CSRCS += ipv6_getsockname.c
|
||||
SOCK_CSRCS += ipv6_getsockname.c inet_globals.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_SENDFILE),y)
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -81,6 +82,21 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Well-known IP addresses */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allzeroaddr; /* An address of all zeroes */
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link address */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* PF_INET/PF_INET6 socket address family interface */
|
||||
|
||||
#ifdef HAVE_INET_SOCKETS
|
||||
EXTERN const struct sock_intf_s g_inet_sockif;
|
||||
#endif
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "route/route.h"
|
||||
#include "netdev/netdev.h"
|
||||
|
||||
@@ -326,9 +327,13 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t ripaddr)
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* First, check if this is the broadcast IP address */
|
||||
/* First, check if this is the multicast IP address We should actually
|
||||
* pick off certain multicast address (all hosts multicast address, and
|
||||
* the solicited-node multicast address). We will cheat here and accept
|
||||
* all multicast packets that are destined for the ff02::/16 addresses.
|
||||
*/
|
||||
|
||||
if (net_ipv6addr_cmp(ripaddr, g_ipv6_alloneaddr))
|
||||
if (ripaddr[0] == HTONS(0xff02))
|
||||
{
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
|
||||
|
||||
@@ -235,9 +235,9 @@ int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router)
|
||||
struct route_ipv6_match_s match;
|
||||
int ret;
|
||||
|
||||
/* Do not route the special broadcast IP address */
|
||||
/* Do not route to any the special IPv6 multicast addresses */
|
||||
|
||||
if (net_ipv6addr_cmp(target, g_ipv6_alloneaddr))
|
||||
if (target[0] == HTONS(0xff02))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "socket/socket.h"
|
||||
#include "inet/inet.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "udp/udp.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <nuttx/net/tcp.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "tcp/tcp.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "tcp/tcp.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
+23
-8
@@ -62,6 +62,7 @@
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "udp/udp.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -301,6 +302,15 @@ static inline FAR struct udp_conn_s *
|
||||
*
|
||||
* If all of the above are true then the newly received UDP packet
|
||||
* is destined for this UDP connection.
|
||||
*
|
||||
* To send and receive broadcast packets, the application should:
|
||||
*
|
||||
* - Bind socket to INADDR_ANY
|
||||
* - setsockopt to SO_BROADCAST
|
||||
* - call sendto with sendaddr.sin_addr.s_addr = <broadcast-address>
|
||||
* - call recvfrom.
|
||||
*
|
||||
* REVIST: SO_BROADCAST flag is currently ignored.
|
||||
*/
|
||||
|
||||
if (conn->lport != 0 && udp->destport == conn->lport &&
|
||||
@@ -359,27 +369,32 @@ static inline FAR struct udp_conn_s *
|
||||
* to a remote port.
|
||||
* - If multiple network interfaces are supported, then the local
|
||||
* IP address is available and we will insist that the
|
||||
* destination IP matches the bound address (or the destination
|
||||
* IP address is a broadcast address). If a socket is bound to
|
||||
* INADDRY_ANY (laddr), then it should receive all packets
|
||||
* directed to the port.
|
||||
* destination IP matches the bound address. If a socket is bound to
|
||||
* INADDRY_ANY (laddr), then it should receive all packets directed
|
||||
* to the port. REVISIT: Should also depend on SO_BROADCAST.
|
||||
* - Finally, if the connection is bound to a remote IP address,
|
||||
* the source IP address of the packet is checked. Broadcast
|
||||
* addresses are also accepted.
|
||||
* the source IP address of the packet is checked.
|
||||
*
|
||||
* If all of the above are true then the newly received UDP packet
|
||||
* is destined for this UDP connection.
|
||||
*
|
||||
* To send and receive broadcast packets, the application should:
|
||||
*
|
||||
* - Bind socket to INADDR6_ANY
|
||||
* - setsockopt to SO_BROADCAST
|
||||
* - call sendto with sendaddr.sin_addr.s_addr = <broadcast-address>
|
||||
* - call recvfrom.
|
||||
*
|
||||
* REVIST: SO_BROADCAST flag is currently ignored.
|
||||
*/
|
||||
|
||||
if (conn->lport != 0 && udp->destport == conn->lport &&
|
||||
(conn->rport == 0 || udp->srcport == conn->rport) &&
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
(net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr) ||
|
||||
net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_alloneaddr) ||
|
||||
net_ipv6addr_hdrcmp(ip->destipaddr, conn->u.ipv6.laddr)) &&
|
||||
#endif
|
||||
(net_ipv6addr_cmp(conn->u.ipv6.raddr, g_ipv6_allzeroaddr) ||
|
||||
net_ipv6addr_cmp(conn->u.ipv6.raddr, g_ipv6_alloneaddr) ||
|
||||
net_ipv6addr_hdrcmp(ip->srcipaddr, conn->u.ipv6.raddr)))
|
||||
{
|
||||
/* Matching connection found.. return a reference to it */
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "inet/inet.h"
|
||||
#include "udp/udp.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user