mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 20:57:20 +08:00
[net][sal][netdev] Add IPv6 option configuration and feature support in SAL and netdev
Signed-off-by: chenyong <1521761801@qq.com>
This commit is contained in:
@@ -25,6 +25,12 @@
|
||||
|
||||
#include <netdev.h>
|
||||
|
||||
#if (LWIP_VERSION < 0x2000000) && NETDEV_IPV6
|
||||
#error "The lwIP version is not support IPV6, please disable netdev IPV6 configuration "
|
||||
#elif (LWIP_VERSION > 0x2000000) && (NETDEV_IPV6 != LWIP_IPV6)
|
||||
#error "IPV6 configuration error, Please check and synchronize netdev and lwip IPV6 configuration."
|
||||
#endif
|
||||
|
||||
#if LWIP_VERSION < 0x2000000
|
||||
#define SELWAIT_T int
|
||||
#else
|
||||
@@ -308,7 +314,11 @@ static const struct sal_netdb_ops lwip_netdb_ops =
|
||||
static const struct sal_proto_family lwip_inet_family =
|
||||
{
|
||||
AF_INET,
|
||||
#if LWIP_VERSION > 0x2000000
|
||||
AF_INET6,
|
||||
#else
|
||||
AF_INET,
|
||||
#endif
|
||||
&lwip_socket_ops,
|
||||
&lwip_netdb_ops,
|
||||
};
|
||||
|
||||
@@ -157,6 +157,7 @@ struct sockaddr
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
#if NETDEV_IPV4
|
||||
/* members are in network byte order */
|
||||
struct sockaddr_in
|
||||
{
|
||||
@@ -167,6 +168,19 @@ struct sockaddr_in
|
||||
#define SIN_ZERO_LEN 8
|
||||
char sin_zero[SIN_ZERO_LEN];
|
||||
};
|
||||
#endif /* NETDEV_IPV4 */
|
||||
|
||||
#if NETDEV_IPV6
|
||||
struct sockaddr_in6
|
||||
{
|
||||
uint8_t sin6_len; /* length of this structure */
|
||||
sa_family_t sin6_family; /* AF_INET6 */
|
||||
in_port_t sin6_port; /* Transport layer port # */
|
||||
uint32_t sin6_flowinfo; /* IPv6 flow information */
|
||||
struct in6_addr sin6_addr; /* IPv6 address */
|
||||
uint32_t sin6_scope_id; /* Set of interfaces for scope */
|
||||
};
|
||||
#endif /* NETDEV_IPV6 */
|
||||
|
||||
struct sockaddr_storage
|
||||
{
|
||||
@@ -174,9 +188,9 @@ struct sockaddr_storage
|
||||
sa_family_t ss_family;
|
||||
char s2_data1[2];
|
||||
uint32_t s2_data2[3];
|
||||
#if SAL_IPV6
|
||||
u32_t s2_data3[3];
|
||||
#endif /* SAL_IPV6 */
|
||||
#if NETDEV_IPV6
|
||||
uint32_t s2_data3[3];
|
||||
#endif /* NETDEV_IPV6 */
|
||||
};
|
||||
|
||||
int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
@@ -549,12 +549,13 @@ static void sal_sockaddr_to_ipaddr(const struct sockaddr *name, ip_addr_t *local
|
||||
const struct sockaddr_in *svr_addr = (const struct sockaddr_in *) name;
|
||||
|
||||
#if NETDEV_IPV4 && NETDEV_IPV6
|
||||
(*local_ipaddr).u_addr.ip4.addr = svr_addr->sin_addr.s_addr;
|
||||
local_ipaddr->u_addr.ip4.addr = svr_addr->sin_addr.s_addr;
|
||||
local_ipaddr->type = IPADDR_TYPE_V4;
|
||||
#elif NETDEV_IPV4
|
||||
(*local_ipaddr).addr = svr_addr->sin_addr.s_addr;
|
||||
local_ipaddr->addr = svr_addr->sin_addr.s_addr;
|
||||
#elif NETDEV_IPV6
|
||||
LOG_E("not support IPV6");
|
||||
#endif /* SAL_IPV4 && SAL_IPV6*/
|
||||
#error "not only support IPV6"
|
||||
#endif /* NETDEV_IPV4 && NETDEV_IPV6*/
|
||||
}
|
||||
|
||||
int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
|
||||
@@ -572,7 +573,7 @@ int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
|
||||
sal_sockaddr_to_ipaddr(name, &input_ipaddr);
|
||||
|
||||
/* check input ipaddr is default netdev ipaddr */
|
||||
if (input_ipaddr.addr != INADDR_ANY)
|
||||
if (!ip_addr_isany_val(input_ipaddr))
|
||||
{
|
||||
struct sal_proto_family *input_pf = RT_NULL, *local_pf = RT_NULL;
|
||||
struct netdev *new_netdev = RT_NULL;
|
||||
|
||||
Reference in New Issue
Block a user