Networking: Get rid of g_ipv4_allzeroaddr and g_ipv4_alloneaddr. It is more efficient and more intuitive to use INADDR_ANY and INADDR_BROADCAST

This commit is contained in:
Gregory Nutt 2015-05-29 15:16:11 -06:00
parent 34509a9ad5
commit ab50e9d04d
10 changed files with 31 additions and 34 deletions

View File

@ -219,11 +219,6 @@ extern "C"
/* Well-known IP addresses */
#ifdef CONFIG_NET_IPv4
EXTERN const in_addr_t g_ipv4_alloneaddr; /* An address of all ones */
EXTERN const in_addr_t g_ipv4_allzeroaddr; /* An address of all zeroes */
#endif
#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 */

View File

@ -232,7 +232,7 @@ int arp_send(in_addr_t ipaddr)
/* Get the device that can route this request */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv4addr(g_ipv4_allzeroaddr, ipaddr);
dev = netdev_findby_ipv4addr(INADDR_ANY, ipaddr);
#else
dev = netdev_findby_ipv4addr(ipaddr);
#endif

View File

@ -69,19 +69,11 @@ struct net_stats_s g_netstats;
uint16_t g_ipid;
#ifdef CONFIG_NET_IPv4
const in_addr_t g_ipv4_alloneaddr = 0xffffffff;
const in_addr_t g_ipv4_allzeroaddr = 0x00000000;
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_TCP_REASSEMBLY)
/* Reassembly timer (units: deci-seconds) */
#ifdef CONFIG_NET_TCP_REASSEMBLY
uint8_t g_reassembly_timer;
#endif /* CONFIG_NET_TCP_REASSEMBLY */
#endif /* CONFIG_NET_IPv4 */
#endif
#ifdef CONFIG_NET_IPv6

View File

@ -85,6 +85,7 @@
#include <debug.h>
#include <string.h>
#include <netinet/in.h>
#include <net/if.h>
#include <nuttx/net/netconfig.h>
@ -377,16 +378,16 @@ int ipv4_input(FAR struct net_driver_s *dev)
#endif /* CONFIG_NET_TCP_REASSEMBLY */
}
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
/* If IP broadcast support is configured, we check for a broadcast
* 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).
*/
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
if (pbuf->proto == IP_PROTO_UDP &&
net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr),
g_ipv4_alloneaddr))
INADDR_BROADCAST))
{
return udp_ipv4_input(dev);
}
@ -399,14 +400,14 @@ int ipv4_input(FAR struct net_driver_s *dev)
else
#endif
#ifdef CONFIG_NET_ICMP
if (net_ipv4addr_cmp(dev->d_ipaddr, g_ipv4_allzeroaddr))
if (net_ipv4addr_cmp(dev->d_ipaddr, INADDR_ANY))
{
#ifdef CONFIG_NET_PINGADDRCONF
/* If we are configured to use ping IP address configuration and
* hasn't been assigned an IP address yet, we accept all ICMP
* packets.
*/
#ifdef CONFIG_NET_PINGADDRCONF
if (pbuf->proto == IP_PROTO_ICMP)
{
nlldbg("Possible ping config packet received\n");
@ -476,17 +477,17 @@ int ipv4_input(FAR struct net_driver_s *dev)
break;
#endif
#ifdef CONFIG_NET_ICMP
/* Check for ICMP input */
#ifdef CONFIG_NET_ICMP
case IP_PROTO_ICMP: /* ICMP input */
icmp_input(dev);
break;
#endif
#ifdef CONFIG_NET_IGMP
/* Check for IGMP input */
#ifdef CONFIG_NET_IGMP
case IP_PROTO_IGMP: /* IGMP input */
igmp_input(dev);
break;

View File

@ -47,6 +47,7 @@
#include <semaphore.h>
#include <debug.h>
#include <netinet/in.h>
#include <net/if.h>
#include <nuttx/clock.h>
@ -350,7 +351,7 @@ int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen,
/* Get the device that will be used to route this ICMP ECHO request */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv4addr(g_ipv4_allzeroaddr, addr);
dev = netdev_findby_ipv4addr(INADDR_ANY, addr);
#else
dev = netdev_findby_ipv4addr(addr);
#endif

View File

@ -45,6 +45,8 @@
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/ip.h>
@ -219,12 +221,12 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t ripaddr)
/* First, check if this is the broadcast IP address */
if (net_ipv4addr_cmp(ripaddr, g_ipv4_alloneaddr))
if (net_ipv4addr_cmp(ripaddr, INADDR_BROADCAST))
{
#ifdef CONFIG_NETDEV_MULTINIC
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
if (net_ipv4addr_cmp(lipaddr, g_ipv4_allzeroaddr))
if (net_ipv4addr_cmp(lipaddr, INADDR_ANY))
{
/* Yes.. In this case, I think we are supposed to send the
* broadcast packet out ALL local networks. I am not sure

View File

@ -43,6 +43,8 @@
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <nuttx/net/ip.h>
#include "devif/devif.h"
@ -177,7 +179,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
/* Do not route the special broadcast IP address */
if (net_ipv4addr_cmp(target, g_ipv4_alloneaddr))
if (net_ipv4addr_cmp(target, INADDR_BROADCAST))
{
return -ENOENT;
}

View File

@ -49,6 +49,8 @@
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <arch/irq.h>
#include <nuttx/net/netconfig.h>
@ -395,7 +397,7 @@ static inline FAR struct tcp_conn_s *
tcp->destport == conn->lport &&
tcp->srcport == conn->rport &&
#ifdef CONFIG_NETDEV_MULTINIC
(net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
(net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY) ||
net_ipv4addr_cmp(destipaddr, conn->u.ipv4.laddr)) &&
#endif
net_ipv4addr_cmp(srcipaddr, conn->u.ipv4.raddr))

View File

@ -50,6 +50,8 @@
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <arch/irq.h>
#include <nuttx/net/netconfig.h>
@ -305,12 +307,12 @@ static inline FAR struct udp_conn_s *
if (conn->lport != 0 && udp->destport == conn->lport &&
(conn->rport == 0 || udp->srcport == conn->rport) &&
#ifdef CONFIG_NETDEV_MULTINIC
(net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_alloneaddr) ||
(net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY) ||
net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_BROADCAST) ||
net_ipv4addr_hdrcmp(ip->destipaddr, &conn->u.ipv4.laddr)) &&
#endif
(net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_allzeroaddr) ||
net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_alloneaddr) ||
(net_ipv4addr_cmp(conn->u.ipv4.raddr, INADDR_ANY) ||
net_ipv4addr_cmp(conn->u.ipv4.raddr, INADDR_BROADCAST) ||
net_ipv4addr_hdrcmp(ip->srcipaddr, &conn->u.ipv4.raddr)))
{
/* Matching connection found.. return a reference to it */
@ -746,7 +748,7 @@ int udp_connect(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr)
if (conn->domain == PF_INET)
#endif
{
net_ipv4addr_copy(conn->u.ipv4.raddr, g_ipv4_allzeroaddr);
net_ipv4addr_copy(conn->u.ipv4.raddr, INADDR_ANY);
}
#endif /* CONFIG_NET_IPv4 */

View File

@ -87,7 +87,7 @@ FAR struct net_driver_s *udp_find_ipv4_device(FAR struct udp_conn_s *conn,
* sendto().
*/
if (ipv4addr == INADDR_ANY)
if ((net_ipv4addr_cmp(ipv4addr, INADDR_ANY))
{
return NULL;
}
@ -139,7 +139,7 @@ FAR struct net_driver_s *udp_find_ipv6_device(FAR struct udp_conn_s *conn,
* sendto().
*/
if (net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr))
if (net_ipv6addr_cmp(ipv6addr, g_ipv6_allzeroaddr))
{
return NULL;
}