Skip to content

Commit 72efe52

Browse files
committed
win:quic-minimal-workaround
1 parent 1a749fc commit 72efe52

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

  • lib/core-net
  • minimal-examples-lowlevel/quic/minimal-quic-client-server

lib/core-net/adopt.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,27 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
833833
}
834834

835835
#if defined(LWS_WITH_IPV6) && defined(IPV6_V6ONLY)
836+
/*
837+
* For IPv6 UDP sockets we own the IPV6_V6ONLY state rather
838+
* than inheriting the OS default (which is 0 = dual-stack on
839+
* Linux/macOS but 1 = v6-only on Windows):
840+
*
841+
* - by default (!MODIFY) we force v6-only, matching the TCP
842+
* listen path. Callers that want both families bind two
843+
* sockets (:: and 0.0.0.0) and rely on this -- e.g. dht,
844+
* auth_dns, extip.
845+
* - MODIFY && !VALUE explicitly requests dual-stack, so a
846+
* lone :: listener also receives IPv4-mapped packets
847+
* (the QUIC adoption path). Force V6ONLY=0 here, since
848+
* the OS default cannot be relied on (Windows = 1).
849+
* - MODIFY | VALUE explicitly requests v6-only.
850+
*/
836851
if (s->dest.sa4.sin_family == AF_INET6 &&
837-
!lws_sa46_is_ipv4_mapped(&s->dest) &&
838-
(!(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
839-
(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE))) {
840-
int opt = 1;
852+
!lws_sa46_is_ipv4_mapped(&s->dest)) {
853+
int opt = !(wsi->a.vhost->options &
854+
LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
855+
!!(wsi->a.vhost->options &
856+
LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE);
841857
if (setsockopt(sock.sockfd, IPPROTO_IPV6, IPV6_V6ONLY,
842858
(const void *)&opt, sizeof(opt)) < 0) {
843859
lwsl_vhost_notice(wsi->a.vhost, "set IPV6_V6ONLY fail");
@@ -1024,10 +1040,11 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
10241040

10251041
#if defined(LWS_WITH_IPV6) && defined(IPV6_V6ONLY)
10261042
if (dest.sa4.sin_family == AF_INET6 &&
1027-
!lws_sa46_is_ipv4_mapped(&dest) &&
1028-
(!(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
1029-
(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE))) {
1030-
int opt = 1;
1043+
!lws_sa46_is_ipv4_mapped(&dest)) {
1044+
int opt = !(wsi->a.vhost->options &
1045+
LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
1046+
!!(wsi->a.vhost->options &
1047+
LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE);
10311048
if (setsockopt(sock.sockfd, IPPROTO_IPV6, IPV6_V6ONLY,
10321049
(const void *)&opt, sizeof(opt)) < 0) {
10331050
lwsl_vhost_notice(wsi->a.vhost, "set IPV6_V6ONLY fail");

minimal-examples-lowlevel/quic/minimal-quic-client-server/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ int main(int argc, const char **argv)
381381
info.protocols = protocols;
382382
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT |
383383
LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
384-
#if !defined(WIN32)
385384
LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY |
386-
#endif
387385
0;
388386

389387
context = lws_create_context(&info);
@@ -422,9 +420,9 @@ int main(int argc, const char **argv)
422420

423421
if (!p) {
424422
/* Explicitly instantiate a UDP listener socket and bind it to QUIC! */
425-
if (!lws_create_adopt_udp(vh, NULL, port, LWS_CAUDP_BIND,
426-
"quic-test-protocol", NULL, NULL, NULL,
427-
NULL, "quic_listen")) {
423+
if (!lws_create_adopt_udp(vh, NULL, port, LWS_CAUDP_BIND,
424+
"quic-test-protocol", NULL, NULL, NULL,
425+
NULL, "quic_listen")) {
428426
lwsl_err("Failed to bind QUIC UDP listener\n");
429427
goto bail;
430428
}

0 commit comments

Comments
 (0)