ipv6 move disable to vhost option

Server ipv6 support disable is now controlled by vhost->options rather
than context->options, allowing it to be set per-vhost.



Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2016-06-03 21:19:40 +08:00
parent 1dca916bec
commit 2dc7ddecfd
5 changed files with 27 additions and 20 deletions

View file

@ -206,6 +206,7 @@ Other vhost options
- "`ecdh-curve`": "<curve name>" The default ecdh curve is "prime256v1", but you can override it here, per-vhost
- "`noipv6`": "on" Disable ipv6 for this vhost
Mounts
------

View file

@ -74,6 +74,7 @@ static const char * const paths_vhosts[] = {
"vhosts[].enable-client-ssl",
"vhosts[].ciphers",
"vhosts[].ecdh-curve",
"vhosts[].noipv6",
};
enum lejp_vhost_paths {
@ -105,6 +106,7 @@ enum lejp_vhost_paths {
LEJPVP_ENABLE_CLIENT_SSL,
LEJPVP_CIPHERS,
LEJPVP_ECDH_CURVE,
LEJPVP_NOIPV6,
};
#define MAX_PLUGIN_DIRS 10
@ -474,6 +476,13 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason)
a->enable_client_ssl = arg_to_bool(ctx->buf);
return 0;
case LEJPVP_NOIPV6:
if (arg_to_bool(ctx->buf))
a->info->options |= LWS_SERVER_OPTION_DISABLE_IPV6;
else
a->info->options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6);
return 0;
default:
return 0;
}

View file

@ -587,20 +587,20 @@ lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len)
#if LWS_POSIX
LWS_VISIBLE int
interface_to_sa(struct lws_context *context, const char *ifname, struct sockaddr_in *addr, size_t addrlen)
interface_to_sa(struct lws_vhost *vh, const char *ifname, struct sockaddr_in *addr, size_t addrlen)
{
int ipv6 = 0;
#ifdef LWS_USE_IPV6
ipv6 = LWS_IPV6_ENABLED(context);
ipv6 = LWS_IPV6_ENABLED(vh);
#endif
(void)context;
(void)vh;
return lws_interface_to_sa(ipv6, ifname, addr, addrlen);
}
#endif
LWS_VISIBLE int
lws_get_addresses(struct lws_context *context, void *ads, char *name,
static int
lws_get_addresses(struct lws_vhost *vh, void *ads, char *name,
int name_len, char *rip, int rip_len)
{
#if LWS_POSIX
@ -613,7 +613,7 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
addr4.sin_family = AF_UNSPEC;
#ifdef LWS_USE_IPV6
if (LWS_IPV6_ENABLED(context)) {
if (LWS_IPV6_ENABLED(vh)) {
if (!lws_plat_inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ads)->sin6_addr, rip, rip_len)) {
lwsl_err("inet_ntop", strerror(LWS_ERRNO));
return -1;
@ -671,7 +671,7 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
return 0;
#else
(void)context;
(void)vh;
(void)ads;
(void)name;
(void)name_len;
@ -705,7 +705,7 @@ lws_get_peer_simple(struct lws *wsi, char *name, int namelen)
void *p, *q;
#ifdef LWS_USE_IPV6
if (LWS_IPV6_ENABLED(wsi->context)) {
if (LWS_IPV6_ENABLED(wsi->vhost)) {
len = sizeof(sin6);
p = &sin6;
af = AF_INET6;
@ -765,7 +765,7 @@ lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
lws_latency_pre(context, wsi);
#ifdef LWS_USE_IPV6
if (LWS_IPV6_ENABLED(context)) {
if (LWS_IPV6_ENABLED(wsi->vhost)) {
len = sizeof(sin6);
p = &sin6;
} else
@ -780,7 +780,7 @@ lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
goto bail;
}
ret = lws_get_addresses(context, p, name, name_len, rip, rip_len);
ret = lws_get_addresses(wsi->vhost, p, name, name_len, rip, rip_len);
bail:
lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1);
@ -1624,7 +1624,7 @@ lws_socket_bind(struct lws_vhost *vhost, int sockfd, int port,
} else
#endif
#ifdef LWS_USE_IPV6
if (LWS_IPV6_ENABLED(vhost->context)) {
if (LWS_IPV6_ENABLED(vhost)) {
v = (struct sockaddr *)&serv_addr6;
n = sizeof(struct sockaddr_in6);
bzero((char *) &serv_addr6, sizeof(serv_addr6));
@ -1641,7 +1641,7 @@ lws_socket_bind(struct lws_vhost *vhost, int sockfd, int port,
serv_addr4.sin_family = AF_INET;
if (iface &&
interface_to_sa(vhost->context, iface,
interface_to_sa(vhost, iface,
(struct sockaddr_in *)v, n) < 0) {
lwsl_err("Unable to find interface %s\n", iface);
return -1;

View file

@ -845,8 +845,9 @@ LWS_EXTERN void lws_feature_status_libuv(struct lws_context_creation_info *info)
#ifdef LWS_USE_IPV6
#define LWS_IPV6_ENABLED(context) \
(!lws_check_opt(context->options, LWS_SERVER_OPTION_DISABLE_IPV6))
#define LWS_IPV6_ENABLED(vh) \
(!lws_check_opt(vh->context->options, LWS_SERVER_OPTION_DISABLE_IPV6) &&
!lws_check_opt(vh->options, LWS_SERVER_OPTION_DISABLE_IPV6))
#else
#define LWS_IPV6_ENABLED(context) (0)
#endif
@ -1538,7 +1539,7 @@ LWS_EXTERN int get_daemonize_pid();
#if !defined(MBED_OPERATORS)
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
interface_to_sa(struct lws_context *context, const char *ifname,
interface_to_sa(struct lws_vhost *vh, const char *ifname,
struct sockaddr_in *addr, size_t addrlen);
#endif
LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
@ -1718,10 +1719,6 @@ _lws_server_listen_accept_flow_control(struct lws *twsi, int on);
#define _lws_server_listen_accept_flow_control(a, b) (0)
#endif
LWS_EXTERN int
lws_get_addresses(struct lws_context *context, void *ads, char *name,
int name_len, char *rip, int rip_len);
#ifdef LWS_WITH_ACCESS_LOG
LWS_EXTERN int
lws_access_log(struct lws *wsi);

View file

@ -67,7 +67,7 @@ lws_context_init_server(struct lws_context_creation_info *info,
else
#endif
#ifdef LWS_USE_IPV6
if (LWS_IPV6_ENABLED(vhost->context))
if (LWS_IPV6_ENABLED(vhost))
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
else
#endif