Skip to content

Commit 44f1ad0

Browse files
committed
cm4
1 parent 0a2b28a commit 44f1ad0

7 files changed

Lines changed: 42 additions & 7 deletions

File tree

lib/core-net/adopt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
834834

835835
#if defined(LWS_WITH_IPV6) && defined(IPV6_V6ONLY)
836836
if (s->dest.sa4.sin_family == AF_INET6 &&
837+
!lws_sa46_is_ipv4_mapped(&s->dest) &&
837838
(!(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
838839
(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE))) {
839840
int opt = 1;
@@ -942,8 +943,7 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
942943
#endif
943944

944945
bail:
945-
946-
/* caller must close */
946+
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "adopt udp2 fail");
947947

948948
return NULL;
949949
}
@@ -1024,6 +1024,7 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
10241024

10251025
#if defined(LWS_WITH_IPV6) && defined(IPV6_V6ONLY)
10261026
if (dest.sa4.sin_family == AF_INET6 &&
1027+
!lws_sa46_is_ipv4_mapped(&dest) &&
10271028
(!(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY) ||
10281029
(wsi->a.vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE))) {
10291030
int opt = 1;
@@ -1097,6 +1098,8 @@ lws_create_adopt_udp2(struct lws *wsi, const char *ads,
10971098
resume:
10981099
compatible_close(sock.sockfd);
10991100
bail:
1101+
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "adopt udp2 fail");
1102+
11001103
return NULL;
11011104
}
11021105
#endif

lib/core-net/client/connect2.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,12 @@ lws_client_connect_2_dnsreq_MAY_CLOSE_WSI(struct lws *wsi)
509509
}
510510
#endif
511511
n = lws_async_dns_query(wsi->a.context, wsi->tsi, adsin,
512-
LWS_ADNS_RECORD_A, lws_client_connect_3_connect,
512+
#if defined(LWS_WITH_IPV6) && !defined(LWS_WITH_IPV4)
513+
LWS_ADNS_RECORD_AAAA,
514+
#else
515+
LWS_ADNS_RECORD_A,
516+
#endif
517+
lws_client_connect_3_connect,
513518
wsi, NULL, NULL);
514519
}
515520

lib/core-net/client/sort-dns.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ lws_sort_dns(struct lws *wsi, const struct addrinfo *result)
644644
if (ai->ai_family == AF_INET6)
645645
goto next;
646646
#endif
647+
#if !defined(LWS_WITH_IPV4)
648+
if (ai->ai_family == AF_INET)
649+
goto next;
650+
#endif
647651

648652
ds = lws_zalloc(sizeof(*ds), __func__);
649653
if (!ds)

lib/core-net/network.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ lws_sa46_parse_numeric_address(const char *ads, lws_sockaddr46 *sa46)
944944
uint8_t a[16];
945945
int n;
946946

947+
memset(sa46, 0, sizeof(*sa46));
948+
947949
n = lws_parse_numeric_address(ads, a, sizeof(a));
948950
if (n < 0)
949951
return -1;

lib/roles/http/server/server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,14 @@ _lws_vhost_init_server(const struct lws_context_creation_info *info,
604604
#endif
605605
if (!vhost->iface || !LWS_IPV6_ENABLED(vhost) ||
606606
(vhost->options & LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE)) {
607+
#if defined(LWS_WITH_IPV4)
607608
const char *ads4 = vhost->iface ? vhost->iface : "0.0.0.0";
608609
if (!lws_create_adopt_udp(vhost, ads4, vhost->listen_port,
609610
LWS_CAUDP_BIND, "quic", vhost->iface, NULL,
610611
NULL, NULL, "quic_listen")) {
611612
lwsl_vhost_err(vhost, "Failed to bind QUIC IPv4 UDP listener");
612613
}
614+
#endif
613615
}
614616
}
615617
}

lib/system/async-dns/async-dns.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q)
222222
p = &pkt[LWS_PRE];
223223
memset(p, 0, DHO_SIZEOF);
224224

225-
#if defined(LWS_WITH_IPV6)
225+
#if !defined(LWS_WITH_IPV4)
226+
which = 1;
227+
q->sent[0]++;
228+
q->sent[1]++;
229+
q->asked = 2; /* AAAA response bit is 2 (1 << 1) */
230+
#elif defined(LWS_WITH_IPV6)
226231
if (q->qtype != LWS_ADNS_RECORD_A && q->qtype != LWS_ADNS_RECORD_AAAA) {
227232
which = 0;
228233
q->sent[0]++;
@@ -1330,12 +1335,20 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name,
13301335
m = lws_adns_scan_hostsfile(name, ads, sizeof(ads), qtype & 0xff);
13311336

13321337
if (m < 4 && !strcmp(name, "localhost")) {
1338+
#if defined(LWS_WITH_IPV4)
13331339
if ((qtype & 0xff) == LWS_ADNS_RECORD_A) {
13341340
ads[0] = 127; ads[1] = 0; ads[2] = 0; ads[3] = 1;
13351341
m = 4;
13361342
}
1343+
#endif
13371344
#if defined(LWS_WITH_IPV6)
1338-
else if ((qtype & 0xff) == LWS_ADNS_RECORD_AAAA) {
1345+
if (
1346+
#if defined(LWS_WITH_IPV4)
1347+
(qtype & 0xff) == LWS_ADNS_RECORD_AAAA
1348+
#else
1349+
1
1350+
#endif
1351+
) {
13391352
memset(ads, 0, 15); ads[15] = 1;
13401353
m = 16;
13411354
}

minimal-examples-lowlevel/http-client/minimal-http-client-timeout-h3/minimal-http-client-timeout-h3.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ connect_sul_cb(lws_sorted_usec_list_t *sul)
288288
return;
289289
}
290290

291+
#if defined(LWS_WITH_IPV4)
291292
if (connect_client(g_context, g_client_vh, "127.0.0.1", port))
293+
#else
294+
if (connect_client(g_context, g_client_vh, "::1", port))
295+
#endif
292296
interrupted = 1;
293297
}
294298

@@ -323,8 +327,10 @@ main(int argc, const char **argv)
323327
lws_cmdline_option_handle_builtin(argc, argv, &info);
324328

325329
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT |
326-
LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
327-
LWS_SERVER_OPTION_DISABLE_IPV6;
330+
LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
331+
#if defined(LWS_WITH_IPV4)
332+
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
333+
#endif
328334
info.protocols = server_protocols; /* used for the server vhost */
329335
/*
330336
* Client reply timeout: short and deterministic for the test. This is

0 commit comments

Comments
 (0)