make ipv6 support optional

This commit is contained in:
Dima Pulkinen 2024-02-26 12:48:12 +02:00
parent 98be8d9fc1
commit fa0ad4def4
5 changed files with 54 additions and 2 deletions

View File

@ -348,10 +348,12 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
\*-------------------------------------------------------------------------*/
const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
const char *err = socket_strerror(socket_create(ps, family, type, protocol));
#ifdef IPV6_V6ONLY
if (err == NULL && family == AF_INET6) {
int yes = 1;
setsockopt(*ps, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes));
}
#endif
return err;
}

View File

@ -12,7 +12,9 @@
* Internal functions prototypes
\*=========================================================================*/
static int opt_setmembership(lua_State *L, p_socket ps, int level, int name);
#if defined(IPV6_ADD_MEMBERSHIP) || defined(IPV6_DROP_MEMBERSHIP)
static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name);
#endif
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name);
static int opt_getboolean(lua_State *L, p_socket ps, int level, int name);
static int opt_setint(lua_State *L, p_socket ps, int level, int name);
@ -243,6 +245,7 @@ int opt_set_tcp_defer_accept(lua_State *L, p_socket ps)
#endif
/*------------------------------------------------------*/
#ifdef IPV6_UNICAST_HOPS
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
{
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
@ -252,8 +255,10 @@ int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)
{
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
}
#endif
/*------------------------------------------------------*/
#ifdef IPV6_MULTICAST_HOPS
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)
{
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
@ -263,6 +268,7 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)
{
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
}
#endif
/*------------------------------------------------------*/
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
@ -276,6 +282,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
}
/*------------------------------------------------------*/
#ifdef IPV6_MULTICAST_LOOP
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
@ -285,6 +292,7 @@ int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)
{
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
}
#endif
/*------------------------------------------------------*/
int opt_set_linger(lua_State *L, p_socket ps)
@ -362,17 +370,22 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
}
/*------------------------------------------------------*/
#ifdef IPV6_ADD_MEMBERSHIP
int opt_set_ip6_add_membership(lua_State *L, p_socket ps)
{
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);
}
#endif
#ifdef IPV6_DROP_MEMBERSHIP
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)
{
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);
}
#endif
/*------------------------------------------------------*/
#ifdef IPV6_V6ONLY
int opt_get_ip6_v6only(lua_State *L, p_socket ps)
{
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
@ -382,6 +395,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
}
#endif
/*------------------------------------------------------*/
int opt_get_error(lua_State *L, p_socket ps)
@ -421,6 +435,7 @@ static int opt_setmembership(lua_State *L, p_socket ps, int level, int name)
return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
#if defined(IPV6_ADD_MEMBERSHIP) || defined(IPV6_DROP_MEMBERSHIP)
static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
{
struct ipv6_mreq val; /* obj, opt-name, table */
@ -446,6 +461,7 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
}
return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
#endif
static
int opt_get(lua_State *L, p_socket ps, int level, int name, void *val, int* len)

View File

@ -78,17 +78,23 @@ int opt_set_tcp_fastopen(lua_State *L, p_socket ps);
int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_UNICAST_HOPS
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps);
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_MULTICAST_HOPS
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps);
int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);
#endif
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
int opt_get_ip_multicast_loop(lua_State *L, p_socket ps);
#ifdef IPV6_MULTICAST_LOOP
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);
int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps);
#endif
int opt_set_linger(lua_State *L, p_socket ps);
int opt_get_linger(lua_State *L, p_socket ps);
@ -101,11 +107,17 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps);
int opt_set_ip_add_membership(lua_State *L, p_socket ps);
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
#ifdef IPV6_ADD_MEMBERSHIP
int opt_set_ip6_add_membership(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_DROP_MEMBERSHIP
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_V6ONLY
int opt_set_ip6_v6only(lua_State *L, p_socket ps);
int opt_get_ip6_v6only(lua_State *L, p_socket ps);
#endif
int opt_get_error(lua_State *L, p_socket ps);

View File

@ -107,7 +107,9 @@ static t_opt optset[] = {
#ifdef TCP_KEEPINTVL
{"tcp-keepintvl", opt_set_tcp_keepintvl},
#endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_set_ip6_v6only},
#endif
{"linger", opt_set_linger},
{"recv-buffer-size", opt_set_recv_buf_size},
{"send-buffer-size", opt_set_send_buf_size},

View File

@ -80,12 +80,24 @@ static t_opt optset[] = {
{"ip-multicast-loop", opt_set_ip_multicast_loop},
{"ip-add-membership", opt_set_ip_add_membership},
{"ip-drop-membership", opt_set_ip_drop_membersip},
#ifdef IPV6_UNICAST_HOPS
{"ipv6-unicast-hops", opt_set_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_HOPS
{"ipv6-multicast-hops", opt_set_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_LOOP
{"ipv6-multicast-loop", opt_set_ip6_multicast_loop},
#endif
#ifdef IPV6_ADD_MEMBERSHIP
{"ipv6-add-membership", opt_set_ip6_add_membership},
#endif
#ifdef IPV6_DROP_MEMBERSHIP
{"ipv6-drop-membership", opt_set_ip6_drop_membersip},
#endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_set_ip6_v6only},
#endif
{"recv-buffer-size", opt_set_recv_buf_size},
{"send-buffer-size", opt_set_send_buf_size},
{NULL, NULL}
@ -100,10 +112,18 @@ static t_opt optget[] = {
{"ip-multicast-if", opt_get_ip_multicast_if},
{"ip-multicast-loop", opt_get_ip_multicast_loop},
{"error", opt_get_error},
#ifdef IPV6_UNICAST_HOPS
{"ipv6-unicast-hops", opt_get_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_HOPS
{"ipv6-multicast-hops", opt_get_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_LOOP
{"ipv6-multicast-loop", opt_get_ip6_multicast_loop},
#endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_get_ip6_v6only},
#endif
{"recv-buffer-size", opt_get_recv_buf_size},
{"send-buffer-size", opt_get_send_buf_size},
{NULL, NULL}