Skip to content

Commit c43a0d6

Browse files
committed
ipv6: special-case fe80::1
It's expected for binding that fe80::1 maps to lo, but in fact there is no such address typically bound to any interface explicitly. This patch handles it as a special case on ipv6 enabled builds forcibly mapping it to lo as expected. #3028
1 parent 9575034 commit c43a0d6

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ doc
6464
/destdir/
6565
/bb1/
6666
/bb3/
67+
/bin/

lib/roles/http/server/server.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
8686
{
8787
struct lws_context *cx = a->vhost->context;
8888
struct lws_context_per_thread *pt;
89-
int n, opt = 1, limit = 1;
89+
int n, opt = 1, limit = 1, san = 2;
90+
const char *_iface = a->vhost->iface;
9091
lws_sockfd_type sockfd;
9192
struct lws *wsi;
9293
int m = 0, is;
@@ -97,21 +98,32 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
9798
(void)method_names;
9899
(void)opt;
99100

101+
#ifdef LWS_WITH_IPV6
102+
if (LWS_IPV6_ENABLED(a->vhost)) {
103+
if (_iface && !strcmp(_iface, "fe80::1"))
104+
_iface = "lo";
105+
}
106+
#endif
107+
100108
lwsl_info("%s: af %d\n", __func__, (int)a->af);
101109

102110
if (lws_vhost_foreach_listen_wsi(a->vhost->context, a, check_extant))
103111
return 0;
104112

105113
deal:
106114

107-
if (a->vhost->iface) {
115+
if (!san--) {
116+
return -1;
117+
}
118+
119+
if (_iface) {
108120

109121
/*
110122
* let's check before we do anything else about the disposition
111123
* of the interface he wants to bind to...
112124
*/
113125
is = lws_socket_bind(a->vhost, NULL, LWS_SOCK_INVALID,
114-
a->vhost->listen_port, a->vhost->iface,
126+
a->vhost->listen_port, _iface,
115127
a->af);
116128
lwsl_debug("initial if check says %d\n", is);
117129

@@ -158,7 +170,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
158170

159171
/* first time */
160172
lwsl_err("%s: VH %s: iface %s port %d DOESN'T EXIST\n",
161-
__func__, a->vhost->name, a->vhost->iface,
173+
__func__, a->vhost->name, _iface,
162174
a->vhost->listen_port);
163175

164176
return (a->info->options &
@@ -172,7 +184,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
172184
return -1;
173185

174186
lwsl_err("%s: VH %s: iface %s port %d NOT USABLE\n",
175-
__func__, a->vhost->name, a->vhost->iface,
187+
__func__, a->vhost->name, _iface,
176188
a->vhost->listen_port);
177189

178190
return (a->info->options &
@@ -273,7 +285,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
273285

274286
is = lws_socket_bind(a->vhost, NULL, sockfd,
275287
a->vhost->listen_port,
276-
a->vhost->iface, a->af);
288+
_iface, a->af);
277289

278290
if (is == LWS_ITOSA_BUSY) {
279291
/* treat as fatal */
@@ -288,9 +300,9 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
288300
* here despite we earlier confirmed it.
289301
*/
290302
if (is < 0) {
291-
lwsl_info("%s: lws_socket_bind says %d\n", __func__, is);
303+
lwsl_info("%s: A lws_socket_bind says %d\n", __func__, is);
292304
compatible_close(sockfd);
293-
if (a->vhost->iface)
305+
if (_iface)
294306
goto deal;
295307
return -1;
296308
}
@@ -316,7 +328,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
316328
wsi->unix_skt = 1;
317329
a->vhost->listen_port = is;
318330

319-
lwsl_debug("%s: lws_socket_bind says %d\n", __func__, is);
331+
lwsl_debug("%s: B lws_socket_bind says %d\n", __func__, is);
320332
}
321333

322334
wsi->desc.sockfd = sockfd;
@@ -375,19 +387,19 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
375387
&a->vhost->context->lcg[LWSLCG_WSI],
376388
&wsi->lc, "listen|%s|%s|%d",
377389
a->vhost->name,
378-
a->vhost->iface ? a->vhost->iface : "",
390+
_iface ? _iface : "",
379391
(int)a->vhost->listen_port);
380392

381393
} /* for each thread able to independently listen */
382394

383395
if (!lws_check_opt(cx->options, LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) {
384396
#ifdef LWS_WITH_UNIX_SOCK
385397
if (a->af == AF_UNIX)
386-
lwsl_info(" Listening on \"%s\"\n", a->vhost->iface);
398+
lwsl_info(" Listening on \"%s\"\n", _iface);
387399
else
388400
#endif
389401
lwsl_info(" Listening on %s:%d\n",
390-
a->vhost->iface,
402+
_iface,
391403
a->vhost->listen_port);
392404
}
393405

0 commit comments

Comments
 (0)