Fossil SCM

Enhance the socket listener logic on unix so that it makes sure the IPV6_V6ONLY socket option is disabled, as we are told that this option is enabled by default on FreeBSD.

drh 2025-04-16 10:20 trunk
Commit 0eeaa6224cdbdbda632c5422d98aedd66603ec8bbbe1e11ea3f6b10f18f27e83
1 file changed +17
+17
--- src/cgi.c
+++ src/cgi.c
@@ -2498,10 +2498,26 @@
24982498
fossil_free(zToFree);
24992499
fgetc(g.httpIn); /* Read past the "," separating header from content */
25002500
cgi_init();
25012501
}
25022502
2503
+/*
2504
+** Change the listening socket, if necessary, so that it will accept both IPv4
2505
+** and IPv6
2506
+*/
2507
+static void allowBothIpV4andV6(int listener){
2508
+#if defined(IPV6_V6ONLY)
2509
+ int ipv6only = -1;
2510
+ socklen_t ipv6only_size = sizeof(ipv6only);
2511
+ getsockopt(listener, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &ipv6only_size);
2512
+ if( ipv6only ){
2513
+ ipv6only = 0;
2514
+ setsockopt(listener, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, ipv6only_size);
2515
+ }
2516
+#endif /* defined(IPV6_ONLY) */
2517
+}
2518
+
25032519
25042520
#if INTERFACE
25052521
/*
25062522
** Bitmap values for the flags parameter to cgi_http_server().
25072523
*/
@@ -2625,10 +2641,11 @@
26252641
listener = socket(AF_INET6, SOCK_STREAM, 0);
26262642
if( listener<0 ){
26272643
iPort++;
26282644
continue;
26292645
}
2646
+ allowBothIpV4andV6(listener);
26302647
}
26312648
26322649
/* if we can't terminate nicely, at least allow the socket to be reused */
26332650
setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
26342651
26352652
--- src/cgi.c
+++ src/cgi.c
@@ -2498,10 +2498,26 @@
2498 fossil_free(zToFree);
2499 fgetc(g.httpIn); /* Read past the "," separating header from content */
2500 cgi_init();
2501 }
2502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2503
2504 #if INTERFACE
2505 /*
2506 ** Bitmap values for the flags parameter to cgi_http_server().
2507 */
@@ -2625,10 +2641,11 @@
2625 listener = socket(AF_INET6, SOCK_STREAM, 0);
2626 if( listener<0 ){
2627 iPort++;
2628 continue;
2629 }
 
2630 }
2631
2632 /* if we can't terminate nicely, at least allow the socket to be reused */
2633 setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
2634
2635
--- src/cgi.c
+++ src/cgi.c
@@ -2498,10 +2498,26 @@
2498 fossil_free(zToFree);
2499 fgetc(g.httpIn); /* Read past the "," separating header from content */
2500 cgi_init();
2501 }
2502
2503 /*
2504 ** Change the listening socket, if necessary, so that it will accept both IPv4
2505 ** and IPv6
2506 */
2507 static void allowBothIpV4andV6(int listener){
2508 #if defined(IPV6_V6ONLY)
2509 int ipv6only = -1;
2510 socklen_t ipv6only_size = sizeof(ipv6only);
2511 getsockopt(listener, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &ipv6only_size);
2512 if( ipv6only ){
2513 ipv6only = 0;
2514 setsockopt(listener, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, ipv6only_size);
2515 }
2516 #endif /* defined(IPV6_ONLY) */
2517 }
2518
2519
2520 #if INTERFACE
2521 /*
2522 ** Bitmap values for the flags parameter to cgi_http_server().
2523 */
@@ -2625,10 +2641,11 @@
2641 listener = socket(AF_INET6, SOCK_STREAM, 0);
2642 if( listener<0 ){
2643 iPort++;
2644 continue;
2645 }
2646 allowBothIpV4andV6(listener);
2647 }
2648
2649 /* if we can't terminate nicely, at least allow the socket to be reused */
2650 setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
2651
2652

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button