diff --git a/net/Kconfig b/net/Kconfig index bb039d30f1..0e3039cfff 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -183,23 +183,20 @@ endmenu # Data link support source "net/netdev/Kconfig" -# Currently cannot select both IPv4 and IPv6 +menu "Internet Protocol Selection" config NET_IPv4 - bool - default y if !NET_IPv6 - default n if NET_IPv6 + bool "IPv4" + default y ---help--- Build in support for IPv4. -menu "Internet Protocol Selection" - depends on EXPERIMENTAL - config NET_IPv6 bool "IPv6" default n + depends on EXPERIMENTAL ---help--- - Build in support for IPv6. Not fully implemented. + Build in support for IPv6. source "net/neighbor/Kconfig" endmenu # Internet Protocol Selection diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 0f5ffa7028..50300abad9 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -581,7 +581,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, #endif #ifdef CONFIG_NET_IPv6 - case SIOCGIFNETMASK: /* Get network mask */ + case SIOCGLIFNETMASK: /* Get network mask */ { dev = netdev_ifrdev(req); if (dev) diff --git a/net/socket/accept.c b/net/socket/accept.c index 9ba43a4b50..71a7812ead 100644 --- a/net/socket/accept.c +++ b/net/socket/accept.c @@ -341,7 +341,7 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen) #endif /* CONFIG_NET_IPv4 */ #ifdef CONFIG_NET_IPv6 - case PF_INET: + case PF_INET6: { if (*addrlen < sizeof(struct sockaddr_in6)) { diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 9421539d47..05aca3fd5e 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -98,11 +98,7 @@ struct recvfrom_s sem_t rf_sem; /* Semaphore signals recv completion */ size_t rf_buflen; /* Length of receive buffer */ uint8_t *rf_buffer; /* Pointer to receive buffer */ -#ifdef CONFIG_NET_IPv6 - FAR struct sockaddr_in6 *rf_from; /* Address of sender */ -#else - FAR struct sockaddr_in *rf_from; /* Address of sender */ -#endif + FAR struct sockaddr *rf_from; /* Address of sender */ size_t rf_recvlen; /* The received length */ 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)) #endif { - FAR struct sockaddr_in6 *infrom = pstate->rf_from; + FAR struct sockaddr_in6 *infrom = + (FAR struct sockaddr_in6 *)pstate->rf_from; if (infrom) { @@ -602,7 +599,8 @@ static inline void recvfrom_tcpsender(FAR struct net_driver_s *dev, else #endif { - FAR struct sockaddr_in *infrom = pstate->rf_from; + FAR struct sockaddr_in *infrom = + (FAR struct sockaddr_in *)pstate->rf_from; 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)) #endif { - FAR struct sockaddr_in6 *infrom = pstate->rf_from; + FAR struct sockaddr_in6 *infrom = + (FAR struct sockaddr_in6 *)pstate->rf_from; if (infrom) { @@ -875,7 +874,8 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ else #endif { - FAR struct sockaddr_in *infrom = pstate->rf_from; + FAR struct sockaddr_in *infrom = + (FAR struct sockaddr_in *)pstate->rf_from; 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) -static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len, -#ifdef CONFIG_NET_IPv6 - FAR struct sockaddr_in6 *infrom, -#else - FAR struct sockaddr_in *infrom, -#endif - struct recvfrom_s *pstate) +static void recvfrom_init(FAR struct socket *psock, FAR void *buf, + size_t len, FAR struct sockaddr *infrom, + FAR struct recvfrom_s *pstate) { /* Initialize the state structure. */ @@ -1187,7 +1183,7 @@ static inline void recvfrom_udp_rxnotify(FAR struct socket *psock, #ifdef CONFIG_NET_PKT 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; 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(); - 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 * in our case is sockaddr_ll @@ -1265,10 +1261,10 @@ errout_with_state: * Perform the recvfrom operation for a UDP SOCK_DGRAM * * Parameters: - * psock Pointer to the socket structure for the SOCK_DRAM socket - * buf Buffer to receive data - * len Length of buffer - * infrom INET address of source (may be NULL) + * psock Pointer to the socket structure for the SOCK_DRAM socket + * buf Buffer to receive data + * len Length of buffer + * from INET address of source (may be NULL) * * Returned Value: * On success, returns the number of characters sent. On error, @@ -1279,13 +1275,8 @@ errout_with_state: ****************************************************************************/ #ifdef CONFIG_NET_UDP -#ifdef CONFIG_NET_IPv6 static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, - FAR struct sockaddr_in6 *infrom) -#else -static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, - FAR struct sockaddr_in *infrom) -#endif + FAR struct sockaddr *from) { FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)psock->s_conn; 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(); - recvfrom_init(psock, buf, len, infrom, &state); + recvfrom_init(psock, buf, len, from, &state); /* Setup the UDP remote connection */ @@ -1357,10 +1348,10 @@ errout_with_state: * Perform the recvfrom operation for a TCP/IP SOCK_STREAM * * Parameters: - * psock Pointer to the socket structure for the SOCK_DRAM socket - * buf Buffer to receive data - * len Length of buffer - * infrom INET address of source (may be NULL) + * psock Pointer to the socket structure for the SOCK_DRAM socket + * buf Buffer to receive data + * len Length of buffer + * from INET address of source (may be NULL) * * Returned Value: * On success, returns the number of characters sent. On error, @@ -1371,13 +1362,8 @@ errout_with_state: ****************************************************************************/ #ifdef CONFIG_NET_TCP -#ifdef CONFIG_NET_IPv6 static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, - FAR struct sockaddr_in6 *infrom ) -#else -static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, - FAR struct sockaddr_in *infrom ) -#endif + FAR struct sockaddr *from) { struct recvfrom_s state; 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(); - 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 * 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, 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; int err; @@ -1635,11 +1610,28 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (from) { + socklen_t minlen; + + /* Get the minimum socket length */ + +#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (*fromlen < sizeof(struct sockaddr_in6)) -#else - if (*fromlen < sizeof(struct sockaddr_in)) + if (psock->s_domain == PF_INET) #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; 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 (psock->s_type == SOCK_RAW) { - ret = pkt_recvfrom(psock, buf, len, llfrom); + ret = pkt_recvfrom(psock, buf, len, from); } else #endif #if defined(CONFIG_NET_TCP) if (psock->s_type == SOCK_STREAM) { - ret = tcp_recvfrom(psock, buf, len, infrom); + ret = tcp_recvfrom(psock, buf, len, from); } else #endif #if defined(CONFIG_NET_UDP) if (psock->s_type == SOCK_DGRAM) { - ret = udp_recvfrom(psock, buf, len, infrom); + ret = udp_recvfrom(psock, buf, len, from); } else #endif diff --git a/net/tcp/tcp_ipselect.c b/net/tcp/tcp_ipselect.c index 9fa9070526..9463fe4b30 100644 --- a/net/tcp/tcp_ipselect.c +++ b/net/tcp/tcp_ipselect.c @@ -72,11 +72,9 @@ #ifdef CONFIG_NET_IPv4 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 */ - IFF_SET_IPv4(dev->dflags); -#endif + IFF_SET_IPv4(dev->d_flags); /* 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 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 */ - IFF_SET_IPv6(dev->dflags); -#endif + IFF_SET_IPv6(dev->d_flags); /* Set the offset to the beginning of the TCP data payload */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index d7d495e7b8..7a69c261a2 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -291,7 +291,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET)) + if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 6e7fe32315..e93dbc8304 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -245,7 +245,7 @@ static uint16_t tcpsend_interrupt(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET)) + if (conn->domain == PF_INET) #endif { DEBUGASSERT(IFF_IS_IPv4(dev->d_flags)); diff --git a/net/udp/udp_ipselect.c b/net/udp/udp_ipselect.c index 835e814ebb..7c5227ba25 100644 --- a/net/udp/udp_ipselect.c +++ b/net/udp/udp_ipselect.c @@ -73,11 +73,9 @@ #ifdef CONFIG_NET_IPv4 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 */ - IFF_SET_IPv4(dev->dflags); -#endif + IFF_SET_IPv4(dev->d_flags); /* 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 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 */ - IFF_SET_IPv6(dev->dflags); -#endif + IFF_SET_IPv6(dev->d_flags); /* Set the offset to the beginning of the UDP data payload */