mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
Networking: Some fixes for compilation when both IPv4 and IPv6 are enabled
This commit is contained in:
+5
-8
@@ -183,23 +183,20 @@ endmenu # Data link support
|
|||||||
|
|
||||||
source "net/netdev/Kconfig"
|
source "net/netdev/Kconfig"
|
||||||
|
|
||||||
# Currently cannot select both IPv4 and IPv6
|
menu "Internet Protocol Selection"
|
||||||
|
|
||||||
config NET_IPv4
|
config NET_IPv4
|
||||||
bool
|
bool "IPv4"
|
||||||
default y if !NET_IPv6
|
default y
|
||||||
default n if NET_IPv6
|
|
||||||
---help---
|
---help---
|
||||||
Build in support for IPv4.
|
Build in support for IPv4.
|
||||||
|
|
||||||
menu "Internet Protocol Selection"
|
|
||||||
depends on EXPERIMENTAL
|
|
||||||
|
|
||||||
config NET_IPv6
|
config NET_IPv6
|
||||||
bool "IPv6"
|
bool "IPv6"
|
||||||
default n
|
default n
|
||||||
|
depends on EXPERIMENTAL
|
||||||
---help---
|
---help---
|
||||||
Build in support for IPv6. Not fully implemented.
|
Build in support for IPv6.
|
||||||
|
|
||||||
source "net/neighbor/Kconfig"
|
source "net/neighbor/Kconfig"
|
||||||
endmenu # Internet Protocol Selection
|
endmenu # Internet Protocol Selection
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
case SIOCGIFNETMASK: /* Get network mask */
|
case SIOCGLIFNETMASK: /* Get network mask */
|
||||||
{
|
{
|
||||||
dev = netdev_ifrdev(req);
|
dev = netdev_ifrdev(req);
|
||||||
if (dev)
|
if (dev)
|
||||||
|
|||||||
+1
-1
@@ -341,7 +341,7 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
|
|||||||
#endif /* CONFIG_NET_IPv4 */
|
#endif /* CONFIG_NET_IPv4 */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
case PF_INET:
|
case PF_INET6:
|
||||||
{
|
{
|
||||||
if (*addrlen < sizeof(struct sockaddr_in6))
|
if (*addrlen < sizeof(struct sockaddr_in6))
|
||||||
{
|
{
|
||||||
|
|||||||
+49
-57
@@ -98,11 +98,7 @@ struct recvfrom_s
|
|||||||
sem_t rf_sem; /* Semaphore signals recv completion */
|
sem_t rf_sem; /* Semaphore signals recv completion */
|
||||||
size_t rf_buflen; /* Length of receive buffer */
|
size_t rf_buflen; /* Length of receive buffer */
|
||||||
uint8_t *rf_buffer; /* Pointer to receive buffer */
|
uint8_t *rf_buffer; /* Pointer to receive buffer */
|
||||||
#ifdef CONFIG_NET_IPv6
|
FAR struct sockaddr *rf_from; /* Address of sender */
|
||||||
FAR struct sockaddr_in6 *rf_from; /* Address of sender */
|
|
||||||
#else
|
|
||||||
FAR struct sockaddr_in *rf_from; /* Address of sender */
|
|
||||||
#endif
|
|
||||||
size_t rf_recvlen; /* The received length */
|
size_t rf_recvlen; /* The received length */
|
||||||
int rf_result; /* Success:OK, failure:negated errno */
|
int rf_result; /* Success:OK, failure:negated errno */
|
||||||
};
|
};
|
||||||
@@ -582,7 +578,8 @@ static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev,
|
|||||||
if (IFF_IS_IPv6(dev->d_flags))
|
if (IFF_IS_IPv6(dev->d_flags))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
FAR struct sockaddr_in6 *infrom = pstate->rf_from;
|
FAR struct sockaddr_in6 *infrom =
|
||||||
|
(FAR struct sockaddr_in6 *)pstate->rf_from;
|
||||||
|
|
||||||
if (infrom)
|
if (infrom)
|
||||||
{
|
{
|
||||||
@@ -602,7 +599,8 @@ static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev,
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
FAR struct sockaddr_in *infrom = pstate->rf_from;
|
FAR struct sockaddr_in *infrom =
|
||||||
|
(FAR struct sockaddr_in *)pstate->rf_from;
|
||||||
|
|
||||||
if (infrom)
|
if (infrom)
|
||||||
{
|
{
|
||||||
@@ -855,7 +853,8 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_
|
|||||||
if (IFF_IS_IPv6(dev->d_flags))
|
if (IFF_IS_IPv6(dev->d_flags))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
FAR struct sockaddr_in6 *infrom = pstate->rf_from;
|
FAR struct sockaddr_in6 *infrom =
|
||||||
|
(FAR struct sockaddr_in6 *)pstate->rf_from;
|
||||||
|
|
||||||
if (infrom)
|
if (infrom)
|
||||||
{
|
{
|
||||||
@@ -875,7 +874,8 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
FAR struct sockaddr_in *infrom = pstate->rf_from;
|
FAR struct sockaddr_in *infrom =
|
||||||
|
(FAR struct sockaddr_in *)pstate->rf_from;
|
||||||
|
|
||||||
if (infrom)
|
if (infrom)
|
||||||
{
|
{
|
||||||
@@ -1012,13 +1012,9 @@ static uint16_t recvfrom_udpinterrupt(struct net_driver_s *dev, void *pvconn,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
|
||||||
static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len,
|
static void recvfrom_init(FAR struct socket *psock, FAR void *buf,
|
||||||
#ifdef CONFIG_NET_IPv6
|
size_t len, FAR struct sockaddr *infrom,
|
||||||
FAR struct sockaddr_in6 *infrom,
|
FAR struct recvfrom_s *pstate)
|
||||||
#else
|
|
||||||
FAR struct sockaddr_in *infrom,
|
|
||||||
#endif
|
|
||||||
struct recvfrom_s *pstate)
|
|
||||||
{
|
{
|
||||||
/* Initialize the state structure. */
|
/* Initialize the state structure. */
|
||||||
|
|
||||||
@@ -1187,7 +1183,7 @@ static inline void recvfrom_udp_rxnotify(FAR struct socket *psock,
|
|||||||
|
|
||||||
#ifdef CONFIG_NET_PKT
|
#ifdef CONFIG_NET_PKT
|
||||||
static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||||
FAR struct sockaddr_ll *from)
|
FAR struct sockaddr *from)
|
||||||
{
|
{
|
||||||
FAR struct pkt_conn_s *conn = (FAR struct pkt_conn_s *)psock->s_conn;
|
FAR struct pkt_conn_s *conn = (FAR struct pkt_conn_s *)psock->s_conn;
|
||||||
struct recvfrom_s state;
|
struct recvfrom_s state;
|
||||||
@@ -1202,7 +1198,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
save = net_lock();
|
save = net_lock();
|
||||||
recvfrom_init(psock, buf, len, (struct sockaddr_in *)from, &state);
|
recvfrom_init(psock, buf, len, from, &state);
|
||||||
|
|
||||||
/* TODO recvfrom_init() expects from to be of type sockaddr_in, but
|
/* TODO recvfrom_init() expects from to be of type sockaddr_in, but
|
||||||
* in our case is sockaddr_ll
|
* in our case is sockaddr_ll
|
||||||
@@ -1265,10 +1261,10 @@ errout_with_state:
|
|||||||
* Perform the recvfrom operation for a UDP SOCK_DGRAM
|
* Perform the recvfrom operation for a UDP SOCK_DGRAM
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
||||||
* buf Buffer to receive data
|
* buf Buffer to receive data
|
||||||
* len Length of buffer
|
* len Length of buffer
|
||||||
* infrom INET address of source (may be NULL)
|
* from INET address of source (may be NULL)
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, returns the number of characters sent. On error,
|
* On success, returns the number of characters sent. On error,
|
||||||
@@ -1279,13 +1275,8 @@ errout_with_state:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP
|
#ifdef CONFIG_NET_UDP
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||||
FAR struct sockaddr_in6 *infrom)
|
FAR struct sockaddr *from)
|
||||||
#else
|
|
||||||
static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|
||||||
FAR struct sockaddr_in *infrom)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)psock->s_conn;
|
FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)psock->s_conn;
|
||||||
struct recvfrom_s state;
|
struct recvfrom_s state;
|
||||||
@@ -1300,7 +1291,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
save = net_lock();
|
save = net_lock();
|
||||||
recvfrom_init(psock, buf, len, infrom, &state);
|
recvfrom_init(psock, buf, len, from, &state);
|
||||||
|
|
||||||
/* Setup the UDP remote connection */
|
/* Setup the UDP remote connection */
|
||||||
|
|
||||||
@@ -1357,10 +1348,10 @@ errout_with_state:
|
|||||||
* Perform the recvfrom operation for a TCP/IP SOCK_STREAM
|
* Perform the recvfrom operation for a TCP/IP SOCK_STREAM
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
||||||
* buf Buffer to receive data
|
* buf Buffer to receive data
|
||||||
* len Length of buffer
|
* len Length of buffer
|
||||||
* infrom INET address of source (may be NULL)
|
* from INET address of source (may be NULL)
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, returns the number of characters sent. On error,
|
* On success, returns the number of characters sent. On error,
|
||||||
@@ -1371,13 +1362,8 @@ errout_with_state:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_TCP
|
#ifdef CONFIG_NET_TCP
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||||
FAR struct sockaddr_in6 *infrom )
|
FAR struct sockaddr *from)
|
||||||
#else
|
|
||||||
static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|
||||||
FAR struct sockaddr_in *infrom )
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
struct recvfrom_s state;
|
struct recvfrom_s state;
|
||||||
net_lock_t save;
|
net_lock_t save;
|
||||||
@@ -1389,7 +1375,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
save = net_lock();
|
save = net_lock();
|
||||||
recvfrom_init(psock, buf, len, infrom, &state);
|
recvfrom_init(psock, buf, len, from, &state);
|
||||||
|
|
||||||
/* Handle any any TCP data already buffered in a read-ahead buffer. NOTE
|
/* Handle any any TCP data already buffered in a read-ahead buffer. NOTE
|
||||||
* that there may be read-ahead data to be retrieved even after the
|
* that there may be read-ahead data to be retrieved even after the
|
||||||
@@ -1597,17 +1583,6 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
int flags,FAR struct sockaddr *from,
|
int flags,FAR struct sockaddr *from,
|
||||||
FAR socklen_t *fromlen)
|
FAR socklen_t *fromlen)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_NET_PKT)
|
|
||||||
FAR struct sockaddr_ll *llfrom = (struct sockaddr_ll *)from;
|
|
||||||
#endif
|
|
||||||
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
FAR struct sockaddr_in6 *infrom = (struct sockaddr_in6 *)from;
|
|
||||||
#else
|
|
||||||
FAR struct sockaddr_in *infrom = (struct sockaddr_in *)from;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -1635,11 +1610,28 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
|
|
||||||
if (from)
|
if (from)
|
||||||
{
|
{
|
||||||
|
socklen_t minlen;
|
||||||
|
|
||||||
|
/* Get the minimum socket length */
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv4
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (*fromlen < sizeof(struct sockaddr_in6))
|
if (psock->s_domain == PF_INET)
|
||||||
#else
|
|
||||||
if (*fromlen < sizeof(struct sockaddr_in))
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
minlen = sizeof(struct sockaddr_in);
|
||||||
|
}
|
||||||
|
#endif /*CONFIG_NET_IPv4 */
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
#ifdef CONFIG_NET_IPv4
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
minlen = sizeof(struct sockaddr_in6);
|
||||||
|
}
|
||||||
|
#endif /*CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
|
if (*fromlen < minlen)
|
||||||
{
|
{
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
goto errout;
|
goto errout;
|
||||||
@@ -1656,21 +1648,21 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
#if defined(CONFIG_NET_PKT)
|
#if defined(CONFIG_NET_PKT)
|
||||||
if (psock->s_type == SOCK_RAW)
|
if (psock->s_type == SOCK_RAW)
|
||||||
{
|
{
|
||||||
ret = pkt_recvfrom(psock, buf, len, llfrom);
|
ret = pkt_recvfrom(psock, buf, len, from);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_TCP)
|
||||||
if (psock->s_type == SOCK_STREAM)
|
if (psock->s_type == SOCK_STREAM)
|
||||||
{
|
{
|
||||||
ret = tcp_recvfrom(psock, buf, len, infrom);
|
ret = tcp_recvfrom(psock, buf, len, from);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_NET_UDP)
|
#if defined(CONFIG_NET_UDP)
|
||||||
if (psock->s_type == SOCK_DGRAM)
|
if (psock->s_type == SOCK_DGRAM)
|
||||||
{
|
{
|
||||||
ret = udp_recvfrom(psock, buf, len, infrom);
|
ret = udp_recvfrom(psock, buf, len, from);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -72,11 +72,9 @@
|
|||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
void tcp_ipv4_select(FAR struct net_driver_s *dev)
|
void tcp_ipv4_select(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
/* Clear a bit in the d_flags to distinguish this from an IPv6 packet */
|
/* Clear a bit in the d_flags to distinguish this from an IPv6 packet */
|
||||||
|
|
||||||
IFF_SET_IPv4(dev->dflags);
|
IFF_SET_IPv4(dev->d_flags);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the offset to the beginning of the TCP data payload */
|
/* Set the offset to the beginning of the TCP data payload */
|
||||||
|
|
||||||
@@ -95,11 +93,9 @@ void tcp_ipv4_select(FAR struct net_driver_s *dev)
|
|||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
void tcp_ipv6_select(FAR struct net_driver_s *dev)
|
void tcp_ipv6_select(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
/* Set a bit in the d_flags to distinguish this from an IPv6 packet */
|
/* Set a bit in the d_flags to distinguish this from an IPv6 packet */
|
||||||
|
|
||||||
IFF_SET_IPv6(dev->dflags);
|
IFF_SET_IPv6(dev->d_flags);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the offset to the beginning of the TCP data payload */
|
/* Set the offset to the beginning of the TCP data payload */
|
||||||
|
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (conn->domain == PF_INET))
|
if (conn->domain == PF_INET)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
|
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (conn->domain == PF_INET))
|
if (conn->domain == PF_INET)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
|
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
|
||||||
|
|||||||
@@ -73,11 +73,9 @@
|
|||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
void udp_ipv4_select(FAR struct net_driver_s *dev)
|
void udp_ipv4_select(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
/* Clear a bit in the d_flags to distinguish this from an IPv6 packet */
|
/* Clear a bit in the d_flags to distinguish this from an IPv6 packet */
|
||||||
|
|
||||||
IFF_SET_IPv4(dev->dflags);
|
IFF_SET_IPv4(dev->d_flags);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the offset to the beginning of the UDP data payload */
|
/* Set the offset to the beginning of the UDP data payload */
|
||||||
|
|
||||||
@@ -96,11 +94,9 @@ void udp_ipv4_select(FAR struct net_driver_s *dev)
|
|||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
void udp_ipv6_select(FAR struct net_driver_s *dev)
|
void udp_ipv6_select(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
/* Set a bit in the d_flags to distinguish this from an IPv6 packet */
|
/* Set a bit in the d_flags to distinguish this from an IPv6 packet */
|
||||||
|
|
||||||
IFF_SET_IPv6(dev->dflags);
|
IFF_SET_IPv6(dev->d_flags);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the offset to the beginning of the UDP data payload */
|
/* Set the offset to the beginning of the UDP data payload */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user