mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Networking: Replace all references to the macros net_ipaddr_copy, net_ipaddr_hdrcopy, net_ipaddr_cmp, net_ipaddr_hdrcmp, and net_ipaddr_maskcmp with the appropriate IPv4 or IPv6 version of the macro (such as net_ipv4addr_copy). The goal is to support both IPv4 and IPv6 simultaneously. This requires that the macros be distinct and not conditionally defined to one on or the other.
This commit is contained in:
@@ -251,7 +251,7 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev,
|
||||
{
|
||||
/* Initialize the non-zero elements of the group structure */
|
||||
|
||||
net_ipaddr_copy(group->grpaddr, *addr);
|
||||
net_ipv4addr_copy(group->grpaddr, *addr);
|
||||
sem_init(&group->sem, 0, 0);
|
||||
|
||||
/* Initialize the group timer (but don't start it yet) */
|
||||
@@ -301,7 +301,7 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev,
|
||||
group = group->next)
|
||||
{
|
||||
grplldbg("Compare: %08x vs. %08x\n", group->grpaddr, *addr);
|
||||
if (net_ipaddr_cmp(group->grpaddr, *addr))
|
||||
if (net_ipv4addr_cmp(group->grpaddr, *addr))
|
||||
{
|
||||
grplldbg("Match!\n");
|
||||
break;
|
||||
|
||||
@@ -165,7 +165,7 @@ void igmp_input(struct net_driver_s *dev)
|
||||
|
||||
/* Check if the query was sent to all systems */
|
||||
|
||||
if (net_ipaddr_cmp(destipaddr, g_ipv4_allsystems))
|
||||
if (net_ipv4addr_cmp(destipaddr, g_ipv4_allsystems))
|
||||
{
|
||||
/* Yes... Now check the if this this is a general or a group
|
||||
* specific query.
|
||||
@@ -206,7 +206,7 @@ void igmp_input(struct net_driver_s *dev)
|
||||
{
|
||||
/* Skip over the all systems group entry */
|
||||
|
||||
if (!net_ipaddr_cmp(member->grpaddr, g_ipv4_allsystems))
|
||||
if (!net_ipv4addr_cmp(member->grpaddr, g_ipv4_allsystems))
|
||||
{
|
||||
ticks = net_dsec2tick((int)IGMPBUF->maxresp);
|
||||
if (IS_IDLEMEMBER(member->flags) ||
|
||||
|
||||
@@ -155,8 +155,8 @@ void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
||||
IGMPBUF->ttl = IGMP_TTL;
|
||||
IGMPBUF->proto = IP_PROTO_IGMP;
|
||||
|
||||
net_ipaddr_hdrcopy(IGMPBUF->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipaddr_hdrcopy(IGMPBUF->destipaddr, destipaddr);
|
||||
net_ipv4addr_hdrcopy(IGMPBUF->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipv4addr_hdrcopy(IGMPBUF->destipaddr, destipaddr);
|
||||
|
||||
/* Calculate IP checksum. */
|
||||
|
||||
@@ -167,7 +167,7 @@ void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
||||
|
||||
IGMPBUF->type = group->msgid;
|
||||
IGMPBUF->maxresp = 0;
|
||||
net_ipaddr_hdrcopy(IGMPBUF->grpaddr, &group->grpaddr);
|
||||
net_ipv4addr_hdrcopy(IGMPBUF->grpaddr, &group->grpaddr);
|
||||
|
||||
/* Calculate the IGMP checksum. */
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/netdev/netdev_findbyaddr.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -107,7 +107,8 @@ static FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr)
|
||||
{
|
||||
/* Yes.. check for an address match (under the netmask) */
|
||||
|
||||
if (net_ipaddr_maskcmp(dev->d_ipaddr, ripaddr, dev->d_netmask))
|
||||
if (net_ipv4addr_maskcmp(dev->d_ipaddr, ripaddr,
|
||||
dev->d_netmask))
|
||||
{
|
||||
/* Its a match */
|
||||
|
||||
@@ -160,7 +161,8 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr)
|
||||
{
|
||||
/* Yes.. check for an address match (under the netmask) */
|
||||
|
||||
if (net_ipaddr_maskcmp(dev->d_ipv6addr, ripaddr, dev->d_ipv6netmask))
|
||||
if (net_ipv6addr_maskcmp(dev->d_ipv6addr, ripaddr,
|
||||
dev->d_ipv6netmask))
|
||||
{
|
||||
/* Its a match */
|
||||
|
||||
|
||||
@@ -94,9 +94,9 @@ int net_addroute(in_addr_t target, in_addr_t netmask, in_addr_t router)
|
||||
|
||||
/* Format the new route table entry */
|
||||
|
||||
net_ipaddr_copy(route->target, target);
|
||||
net_ipaddr_copy(route->netmask, netmask);
|
||||
net_ipaddr_copy(route->router, router);
|
||||
net_ipv4addr_copy(route->target, target);
|
||||
net_ipv4addr_copy(route->netmask, netmask);
|
||||
net_ipv4addr_copy(route->router, router);
|
||||
|
||||
/* Get exclusive address to the networking data structures */
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
* must be the same.
|
||||
*/
|
||||
|
||||
if (net_ipaddr_maskcmp(route->target, match->target, match->netmask) &&
|
||||
net_ipaddr_cmp(route->netmask, match->netmask))
|
||||
if (net_ipv4addr_maskcmp(route->target, match->target, match->netmask) &&
|
||||
net_ipv4addr_cmp(route->netmask, match->netmask))
|
||||
{
|
||||
/* They match.. Remove the entry from the routing table */
|
||||
|
||||
@@ -141,8 +141,8 @@ int net_delroute(in_addr_t target, in_addr_t netmask)
|
||||
/* Set up the comparison structure */
|
||||
|
||||
match.prev = NULL;
|
||||
net_ipaddr_copy(match.target, target);
|
||||
net_ipaddr_copy(match.netmask, netmask);
|
||||
net_ipv4addr_copy(match.target, target);
|
||||
net_ipv4addr_copy(match.netmask, netmask);
|
||||
|
||||
/* Then remove the entry from the routing table */
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ static int net_ipv4_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
net_ipaddr_copy(match->router, route->router);
|
||||
net_ipv4addr_copy(match->router, route->router);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ static int net_ipv6_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
net_ipaddr_copy(match->router, route->router);
|
||||
net_ipv6addr_copy(match->router, route->router);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -181,7 +181,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
|
||||
|
||||
/* Do not route the special broadcast IP address */
|
||||
|
||||
if (net_ipaddr_cmp(target, g_ipv4_alloneaddr))
|
||||
if (net_ipv4addr_cmp(target, g_ipv4_alloneaddr))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv4_match_s));
|
||||
net_ipaddr_copy(match.target, target);
|
||||
net_ipv4addr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address
|
||||
@@ -239,7 +239,7 @@ int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router)
|
||||
|
||||
/* Do not route the special broadcast IP address */
|
||||
|
||||
if (net_ipaddr_cmp(target, g_ipv6_alloneaddr))
|
||||
if (net_ipv6addr_cmp(target, g_ipv6_alloneaddr))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -247,7 +247,7 @@ int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router)
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv6_match_s));
|
||||
net_ipaddr_copy(match.target, target);
|
||||
net_ipv6addr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address
|
||||
|
||||
@@ -190,7 +190,7 @@ void netdev_ipv4_router(FAR struct net_driver_s *dev, in_addr_t target,
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv4_devmatch_s));
|
||||
match.dev = dev;
|
||||
net_ipaddr_copy(match.target, target);
|
||||
net_ipv4addr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address using this device.
|
||||
@@ -247,7 +247,7 @@ void netdev_ipv6_router(FAR struct net_driver_s *dev,
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv6_devmatch_s));
|
||||
match.dev = dev;
|
||||
net_ipaddr_copy(match.target, target);
|
||||
net_ipv6addr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address using this device.
|
||||
|
||||
+14
-14
@@ -104,18 +104,7 @@ struct accept_s
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_TCP
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
static inline void accept_tcpsender(FAR struct tcp_conn_s *conn,
|
||||
FAR struct sockaddr_in6 *addr)
|
||||
{
|
||||
if (addr)
|
||||
{
|
||||
addr->sin_family = AF_INET6;
|
||||
addr->sin_port = conn->rport;
|
||||
net_ipaddr_copy(addr->sin6_addr.s6_addr, conn->u.ipv4.raddr);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
static inline void accept_tcpsender(FAR struct tcp_conn_s *conn,
|
||||
FAR struct sockaddr_in *addr)
|
||||
{
|
||||
@@ -123,10 +112,21 @@ static inline void accept_tcpsender(FAR struct tcp_conn_s *conn,
|
||||
{
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = conn->rport;
|
||||
net_ipaddr_copy(addr->sin_addr.s_addr, conn->u.ipv4.raddr);
|
||||
net_ipv4addr_copy(addr->sin_addr.s_addr, conn->u.ipv4.raddr);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
#else
|
||||
static inline void accept_tcpsender(FAR struct tcp_conn_s *conn,
|
||||
FAR struct sockaddr_in6 *addr)
|
||||
{
|
||||
if (addr)
|
||||
{
|
||||
addr->sin_family = AF_INET6;
|
||||
addr->sin_port = conn->rport;
|
||||
net_ipv6addr_copy(addr->sin6_addr.s6_addr, conn->u.ipv4.raddr);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
#endif /* CONFIG_NET_TCP */
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -584,10 +584,10 @@ static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev,
|
||||
infrom->sin_port = TCPBUF->srcport;
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_copy(infrom->sin6_addr.s6_addr, TCPBUF->srcipaddr);
|
||||
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, TCPBUF->srcipaddr);
|
||||
#else
|
||||
net_ipaddr_copy(infrom->sin_addr.s_addr,
|
||||
net_ip4addr_conv32(TCPBUF->srcipaddr));
|
||||
net_ipv4addr_copy(infrom->sin_addr.s_addr,
|
||||
net_ip4addr_conv32(TCPBUF->srcipaddr));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -831,10 +831,10 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_
|
||||
infrom->sin_port = UDPBUF->srcport;
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_copy(infrom->sin6_addr.s6_addr, UDPBUF->srcipaddr);
|
||||
net_ipv6addr_copy(infrom->sin6_addr.s6_addr, UDPBUF->srcipaddr);
|
||||
#else
|
||||
net_ipaddr_copy(infrom->sin_addr.s_addr,
|
||||
net_ip4addr_conv32(UDPBUF->srcipaddr));
|
||||
net_ipv4addr_copy(infrom->sin_addr.s_addr,
|
||||
net_ip4addr_conv32(UDPBUF->srcipaddr));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -524,10 +524,10 @@ FAR struct tcp_conn_s *tcp_active(FAR struct net_driver_s *dev,
|
||||
tcp->destport == conn->lport &&
|
||||
tcp->srcport == conn->rport &&
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
(net_ipaddr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
|
||||
net_ipaddr_cmp(destipaddr, conn->u.ipv4.laddr)) &&
|
||||
(net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
|
||||
net_ipv4addr_cmp(destipaddr, conn->u.ipv4.laddr)) &&
|
||||
#endif
|
||||
net_ipaddr_cmp(srcipaddr, conn->u.ipv4.raddr))
|
||||
net_ipv4addr_cmp(srcipaddr, conn->u.ipv4.raddr))
|
||||
{
|
||||
/* Matching connection found.. break out of the loop and return a
|
||||
* reference to it.
|
||||
@@ -600,9 +600,9 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
|
||||
conn->lport = tcp->destport;
|
||||
conn->rport = tcp->srcport;
|
||||
conn->mss = TCP_INITIAL_MSS(dev);
|
||||
net_ipaddr_copy(conn->u.ipv4.raddr, net_ip4addr_conv32(ip->srcipaddr));
|
||||
net_ipv4addr_copy(conn->u.ipv4.raddr, net_ip4addr_conv32(ip->srcipaddr));
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
net_ipaddr_copy(conn->u.ipv4.laddr, net_ip4addr_conv32(ip->destipaddr));
|
||||
net_ipv4addr_copy(conn->u.ipv4.laddr, net_ip4addr_conv32(ip->destipaddr));
|
||||
#endif
|
||||
conn->tcpstateflags = TCP_SYN_RCVD;
|
||||
|
||||
@@ -706,7 +706,7 @@ int tcp_bind(FAR struct tcp_conn_s *conn,
|
||||
conn->lport = addr->sin_port;
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
net_ipaddr_copy(conn->u.ipv4.laddr, ipaddr);
|
||||
net_ipv4addr_copy(conn->u.ipv4.laddr, ipaddr);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
@@ -800,7 +800,7 @@ int tcp_connect(FAR struct tcp_conn_s *conn,
|
||||
|
||||
/* The sockaddr address is 32-bits in network order. */
|
||||
|
||||
net_ipaddr_copy(conn->u.ipv4.raddr, addr->sin_addr.s_addr);
|
||||
net_ipv4addr_copy(conn->u.ipv4.raddr, addr->sin_addr.s_addr);
|
||||
|
||||
#ifdef CONFIG_NET_TCP_READAHEAD
|
||||
/* Initialize the list of TCP read-ahead buffers */
|
||||
|
||||
+4
-4
@@ -187,8 +187,8 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev,
|
||||
pbuf->srcport = conn->lport;
|
||||
pbuf->destport = conn->rport;
|
||||
|
||||
net_ipaddr_hdrcopy(pbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipaddr_hdrcopy(pbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
net_ipv4addr_hdrcopy(pbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipv4addr_hdrcopy(pbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
|
||||
if (conn->tcpstateflags & TCP_STOPPED)
|
||||
{
|
||||
@@ -320,8 +320,8 @@ void tcp_reset(FAR struct net_driver_s *dev)
|
||||
|
||||
/* Swap IP addresses. */
|
||||
|
||||
net_ipaddr_hdrcopy(pbuf->destipaddr, pbuf->srcipaddr);
|
||||
net_ipaddr_hdrcopy(pbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipv4addr_hdrcopy(pbuf->destipaddr, pbuf->srcipaddr);
|
||||
net_ipv4addr_hdrcopy(pbuf->srcipaddr, &dev->d_ipaddr);
|
||||
|
||||
/* And send out the RST packet */
|
||||
|
||||
|
||||
+2
-2
@@ -466,7 +466,7 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr)
|
||||
* for receiving (Sending will use the default port).
|
||||
*/
|
||||
|
||||
net_ipaddr_copy(conn->u.ipv4.laddr, ipaddr);
|
||||
net_ipv4addr_copy(conn->u.ipv4.laddr, ipaddr);
|
||||
#endif
|
||||
|
||||
/* Is the user requesting to bind to any port? */
|
||||
@@ -563,7 +563,7 @@ int udp_connect(FAR struct udp_conn_s *conn,
|
||||
if (addr)
|
||||
{
|
||||
conn->rport = addr->sin_port;
|
||||
net_ipaddr_copy(conn->u.ipv4.raddr, addr->sin_addr.s_addr);
|
||||
net_ipv4addr_copy(conn->u.ipv4.raddr, addr->sin_addr.s_addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+4
-4
@@ -125,8 +125,8 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
|
||||
pudpbuf->proto = IP_PROTO_UDP;
|
||||
pudpbuf->ttl = conn->ttl;
|
||||
|
||||
net_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipaddr_copy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
net_ipv6addr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipav6ddr_copy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
@@ -142,8 +142,8 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
|
||||
pudpbuf->ttl = conn->ttl;
|
||||
pudpbuf->proto = IP_PROTO_UDP;
|
||||
|
||||
net_ipaddr_hdrcopy(pudpbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipaddr_hdrcopy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
net_ipv4addr_hdrcopy(pudpbuf->srcipaddr, &dev->d_ipaddr);
|
||||
net_ipv4addr_hdrcopy(pudpbuf->destipaddr, &conn->u.ipv4.raddr);
|
||||
|
||||
/* Calculate IP checksum. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user