unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* (web server) serving on both ipv6 and ipv4?
@ 2022-01-19  7:57 Dr. Arne Babenhauserheide
  2022-01-19  8:51 ` Maxime Devos
  2022-01-19 13:07 ` Chris Vine
  0 siblings, 2 replies; 10+ messages in thread
From: Dr. Arne Babenhauserheide @ 2022-01-19  7:57 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1219 bytes --]

Hi,


with both fibers server and (web server) there is a split between IPv4
and IPv6:


IPv4:

    (fibers:run-server handler-with-path #:family AF_INET #:port port #:addr INADDR_ANY)

    (run-server handler-with-path 'http `(#:host "localhost" #:family ,AF_INET #:addr ,INADDR_ANY #:port ,port))


IPv6:

    (define s
        (let ((s (socket AF_INET6 SOCK_STREAM 0)))
            (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
            (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
            s))
    (fibers:run-server handler-with-path #:family AF_INET6 #:port port #:addr (inet-pton AF_INET6 ip) #:socket s)

    (define s
        (let ((s (socket AF_INET6 SOCK_STREAM 0)))
            (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
            (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
            s))
    (run-server handler-with-path 'http `(#:family ,AF_INET6 #:addr (inet-pton AF_INET6 ip) #:port ,port #:socket ,s))


Is there a way to bind to both IPv6 and IPv4, so my server will react to
requests regardless of whether a client reaches my computer over IPv4 or
IPv6?


Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19  7:57 (web server) serving on both ipv6 and ipv4? Dr. Arne Babenhauserheide
@ 2022-01-19  8:51 ` Maxime Devos
  2022-01-19 18:27   ` Greg Troxel
  2022-01-19 13:07 ` Chris Vine
  1 sibling, 1 reply; 10+ messages in thread
From: Maxime Devos @ 2022-01-19  8:51 UTC (permalink / raw)
  To: Dr. Arne Babenhauserheide, guile-devel

[-- Attachment #1: Type: text/plain, Size: 1942 bytes --]

Dr. Arne Babenhauserheide schreef op wo 19-01-2022 om 08:57 [+0100]:
> Hi,
> 
> 
> with both fibers server and (web server) there is a split between IPv4
> and IPv6:
> 
> 
> IPv4:
> 
>     (fibers:run-server handler-with-path #:family AF_INET #:port port #:addr INADDR_ANY)
> 
>     (run-server handler-with-path 'http `(#:host "localhost" #:family ,AF_INET #:addr ,INADDR_ANY #:port ,port))
> 
> 
> IPv6:
> 
>     (define s
>         (let ((s (socket AF_INET6 SOCK_STREAM 0)))
>             (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
>             (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
>             s))
>     (fibers:run-server handler-with-path #:family AF_INET6 #:port port #:addr (inet-pton AF_INET6 ip) #:socket s)
> 
>     (define s
>         (let ((s (socket AF_INET6 SOCK_STREAM 0)))
>             (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
>             (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
>             s))
>     (run-server handler-with-path 'http `(#:family ,AF_INET6 #:addr (inet-pton AF_INET6 ip) #:port ,port #:socket ,s))
> 
> 
> Is there a way to bind to both IPv6 and IPv4, so my server will react to
> requests regardless of whether a client reaches my computer over IPv4 or
> IPv6?

Maybe the IPV6_V6ONLY (see the ipv6(7) man page) is relevant here.
Alternatively, you could run two servers in parallel: one bound to an
IPv4 address and another bound to an IPv6 address.

Unfortunately, the fibers HTTP server calls 'run-fibers' (even if
there's already some scheduler), so each server will be run in its own
fresh scheduler, this might cause problems..

There's some code in 'cuirass' and 'gnunet-scheme' (see
<https://git.gnunet.org/gnunet-scheme.git/tree/web/server/fiberized.scm>)
that doesn't spawn its own scheduler.

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19  7:57 (web server) serving on both ipv6 and ipv4? Dr. Arne Babenhauserheide
  2022-01-19  8:51 ` Maxime Devos
@ 2022-01-19 13:07 ` Chris Vine
  2022-01-19 13:44   ` Chris Vine
  1 sibling, 1 reply; 10+ messages in thread
From: Chris Vine @ 2022-01-19 13:07 UTC (permalink / raw)
  To: guile-devel

On Wed, 19 Jan 2022 08:57:51 +0100
"Dr. Arne Babenhauserheide" <arne_bab@web.de> wrote:
> Hi,
> 
> 
> with both fibers server and (web server) there is a split between IPv4
> and IPv6:
> 
> IPv4:
> 
>     (fibers:run-server handler-with-path #:family AF_INET #:port port #:addr INADDR_ANY)
> 
>     (run-server handler-with-path 'http `(#:host "localhost" #:family ,AF_INET #:addr ,INADDR_ANY #:port ,port))
> 
> IPv6:
> 
>     (define s
>         (let ((s (socket AF_INET6 SOCK_STREAM 0)))
>             (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
>             (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
>             s))
>     (fibers:run-server handler-with-path #:family AF_INET6 #:port port #:addr (inet-pton AF_INET6 ip) #:socket s)
> 
>     (define s
>         (let ((s (socket AF_INET6 SOCK_STREAM 0)))
>             (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
>             (bind s AF_INET6 (inet-pton AF_INET6 ip) port)
>             s))
>     (run-server handler-with-path 'http `(#:family ,AF_INET6 #:addr (inet-pton AF_INET6 ip) #:port ,port #:socket ,s))
> 
> 
> Is there a way to bind to both IPv6 and IPv4, so my server will react to
> requests regardless of whether a client reaches my computer over IPv4 or
> IPv6?

As I understand it, with linux IPv6 sockets are dual stack capable, and
in earlier kernel versions this was be enabled by default.  I believe
with current versions that is no longer the case, and that you have to
specifically enable dual stack by turning off IPV6_V6ONLY using
setsockopt before binding on the socket.

Then, if receiving a IPv4 connection from address 1.2.3.4, this would be
mapped as ::::ffff:1.2.3.4.

I do not know about other OSes.  I have half a memory that some earlier
versions of windows did not support dual stack sockets (XP?).



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19 13:07 ` Chris Vine
@ 2022-01-19 13:44   ` Chris Vine
  2022-01-19 13:53     ` Chris Vine
  2022-01-19 21:12     ` Chris Vine
  0 siblings, 2 replies; 10+ messages in thread
From: Chris Vine @ 2022-01-19 13:44 UTC (permalink / raw)
  To: guile-devel

On Wed, 19 Jan 2022 13:07:33 +0000
Chris Vine <vine35792468@gmail.com> wrote:
[snip]
> As I understand it, with linux IPv6 sockets are dual stack capable, and
> in earlier kernel versions this was be enabled by default.  I believe
> with current versions that is no longer the case, and that you have to
> specifically enable dual stack by turning off IPV6_V6ONLY using
> setsockopt before binding on the socket.
> 
> Then, if receiving a IPv4 connection from address 1.2.3.4, this would be
> mapped as ::::ffff:1.2.3.4.
> 
> I do not know about other OSes.  I have half a memory that some earlier
> versions of windows did not support dual stack sockets (XP?).

By the way I did use dual stack some years ago, and I cannot now
remember all the details, but I think I may have had to bind on
in6addr_any (which in dual stack would cover INADDR_ANY) or on ::
(which would cover 127.0.0.1) to get dual stack to work.  I suggest you
play around with it to see.

One other correction: when I said there was a mapping to ::::ffff:
1.2.3.4 I meant ::ffff:1.2.3.4.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19 13:44   ` Chris Vine
@ 2022-01-19 13:53     ` Chris Vine
  2022-01-19 21:12     ` Chris Vine
  1 sibling, 0 replies; 10+ messages in thread
From: Chris Vine @ 2022-01-19 13:53 UTC (permalink / raw)
  To: guile-devel

On Wed, 19 Jan 2022 13:44:13 +0000
Chris Vine <vine35792468@gmail.com> wrote:
> By the way I did use dual stack some years ago, and I cannot now
> remember all the details, but I think I may have had to bind on
> in6addr_any (which in dual stack would cover INADDR_ANY) or on ::
                                                                 ^^
::1 of course.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19  8:51 ` Maxime Devos
@ 2022-01-19 18:27   ` Greg Troxel
  2022-01-20  7:24     ` Dr. Arne Babenhauserheide
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Troxel @ 2022-01-19 18:27 UTC (permalink / raw)
  To: Maxime Devos; +Cc: Dr. Arne Babenhauserheide, guile-devel

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]


Maxime Devos <maximedevos@telenet.be> writes:

> Maybe the IPV6_V6ONLY (see the ipv6(7) man page) is relevant here.
> Alternatively, you could run two servers in parallel: one bound to an
> IPv4 address and another bound to an IPv6 address.

My feeling is that IPV6_ONLY is best avoided, for portability, and
because mapped addresses (an IPv6 address with the v4 address embedded)
are awkward.    So I think it's best to listen on v4 and v6 separately.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19 13:44   ` Chris Vine
  2022-01-19 13:53     ` Chris Vine
@ 2022-01-19 21:12     ` Chris Vine
  2022-01-19 21:42       ` Dr. Arne Babenhauserheide
  1 sibling, 1 reply; 10+ messages in thread
From: Chris Vine @ 2022-01-19 21:12 UTC (permalink / raw)
  To: guile-devel

On Wed, 19 Jan 2022 13:44:13 +0000
Chris Vine <vine35792468@gmail.com> wrote:
> On Wed, 19 Jan 2022 13:07:33 +0000
> Chris Vine <vine35792468@gmail.com> wrote:
> [snip]
> > As I understand it, with linux IPv6 sockets are dual stack capable, and
> > in earlier kernel versions this was be enabled by default.  I believe
> > with current versions that is no longer the case, and that you have to
> > specifically enable dual stack by turning off IPV6_V6ONLY using
> > setsockopt before binding on the socket.
> > 
> > Then, if receiving a IPv4 connection from address 1.2.3.4, this would be
> > mapped as ::::ffff:1.2.3.4.
> > 
> > I do not know about other OSes.  I have half a memory that some earlier
> > versions of windows did not support dual stack sockets (XP?).
> 
> By the way I did use dual stack some years ago, and I cannot now
> remember all the details, but I think I may have had to bind on
> in6addr_any (which in dual stack would cover INADDR_ANY) or on ::1
> (which would cover 127.0.0.1) to get dual stack to work.  I suggest you
> play around with it to see.
> 
> One other correction: when I said there was a mapping to ::::ffff:
> 1.2.3.4 I meant ::ffff:1.2.3.4.

You have stimulated my interest and this is what I have found.  First,
in C the correct call in linux to do what you want to obtain a dual
stack socket is to set the IPV6_V6ONLY option in the IPPROTO_IPV6 level
to 0 (off). However neither IPV6_V6ONLY nor IPPROTO_IPV6 is defined in
guile, so you have to enter the numeric values for your OS by hand.  In
linux this will do it in guile, but of course it is non-portable:

  (setsockopt [sock] 41 26 0)

However, this only actually seems to accept a connection from a IPv4
address if the socket binds to :: (which is in6addr_any, but
the in6addr_any symbol also appears not to be defined in guile).
Binding to ::1 (localhost) will not enable you to connect from
127.0.0.1 on my computer.  Whether binding to :: and so permitting any
interface to access the socket is OK for you depends on what your needs
are.  If not then it looks as if you are stuck with having two sockets,
one for IPv4 and one for IPv6.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19 21:12     ` Chris Vine
@ 2022-01-19 21:42       ` Dr. Arne Babenhauserheide
  0 siblings, 0 replies; 10+ messages in thread
From: Dr. Arne Babenhauserheide @ 2022-01-19 21:42 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 2643 bytes --]


Chris Vine <vine35792468@gmail.com> writes:

> On Wed, 19 Jan 2022 13:44:13 +0000
> Chris Vine <vine35792468@gmail.com> wrote:
>> On Wed, 19 Jan 2022 13:07:33 +0000
>> Chris Vine <vine35792468@gmail.com> wrote:
>> [snip]
>> > As I understand it, with linux IPv6 sockets are dual stack capable, and
>> > in earlier kernel versions this was be enabled by default.  I believe
>> > with current versions that is no longer the case, and that you have to
>> > specifically enable dual stack by turning off IPV6_V6ONLY using
>> > setsockopt before binding on the socket.
>> > 
>> > Then, if receiving a IPv4 connection from address 1.2.3.4, this would be
>> > mapped as ::::ffff:1.2.3.4.
>> > 
>> > I do not know about other OSes.  I have half a memory that some earlier
>> > versions of windows did not support dual stack sockets (XP?).
>> 
>> By the way I did use dual stack some years ago, and I cannot now
>> remember all the details, but I think I may have had to bind on
>> in6addr_any (which in dual stack would cover INADDR_ANY) or on ::1
>> (which would cover 127.0.0.1) to get dual stack to work.  I suggest you
>> play around with it to see.
>> 
>> One other correction: when I said there was a mapping to ::::ffff:
>> 1.2.3.4 I meant ::ffff:1.2.3.4.
>
> You have stimulated my interest and this is what I have found.  First,
> in C the correct call in linux to do what you want to obtain a dual
> stack socket is to set the IPV6_V6ONLY option in the IPPROTO_IPV6 level
> to 0 (off). However neither IPV6_V6ONLY nor IPPROTO_IPV6 is defined in
> guile, so you have to enter the numeric values for your OS by hand.  In
> linux this will do it in guile, but of course it is non-portable:
>
>   (setsockopt [sock] 41 26 0)
>
> However, this only actually seems to accept a connection from a IPv4
> address if the socket binds to :: (which is in6addr_any, but
> the in6addr_any symbol also appears not to be defined in guile).
> Binding to ::1 (localhost) will not enable you to connect from
> 127.0.0.1 on my computer.  Whether binding to :: and so permitting any
> interface to access the socket is OK for you depends on what your needs
> are.  If not then it looks as if you are stuck with having two sockets,
> one for IPv4 and one for IPv6.

Thank you for all your info! I seem to have working ipv4 and ipv6 access
now!

I found that IPV6_V6EONLY is off by default in my system

cat /proc/sys/net/ipv6/bindv6only

But I’m now setting it anyway, because that default might change.

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-19 18:27   ` Greg Troxel
@ 2022-01-20  7:24     ` Dr. Arne Babenhauserheide
  2022-01-20 13:38       ` Greg Troxel
  0 siblings, 1 reply; 10+ messages in thread
From: Dr. Arne Babenhauserheide @ 2022-01-20  7:24 UTC (permalink / raw)
  To: Greg Troxel; +Cc: Dr. Arne Babenhauserheide, Maxime Devos, guile-devel

[-- Attachment #1: Type: text/plain, Size: 1301 bytes --]


Greg Troxel <gdt@lexort.com> writes:

> [[PGP Signed Part:Signature made by expired key 1FDA7AE8098ED60E Gregory D. Troxel (low security, at work) <gdt@work.lexort.com>]]
>
> Maxime Devos <maximedevos@telenet.be> writes:
>
>> Maybe the IPV6_V6ONLY (see the ipv6(7) man page) is relevant here.
>> Alternatively, you could run two servers in parallel: one bound to an
>> IPv4 address and another bound to an IPv6 address.
>
> My feeling is that IPV6_ONLY is best avoided, for portability, and
> because mapped addresses (an IPv6 address with the v4 address embedded)
> are awkward.    So I think it's best to listen on v4 and v6 separately.

I see portability, but for simplicity and having the same codebase, I
think that IPV6_V6ONLY=0 is the right choice.

It is possible to listen both on v6 and v4 for the same port, but you’ll
then have more complexity — I’m mainly thinking about tutorials here:
You’ll have to explain a lot more if you have to take care of v6 vs. v4
instead of having a library that does both.

An alternative could be a server using the fiberized web server to be
able to tie efficiently into the rest of the code via a plain fibers
channel.

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: (web server) serving on both ipv6 and ipv4?
  2022-01-20  7:24     ` Dr. Arne Babenhauserheide
@ 2022-01-20 13:38       ` Greg Troxel
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Troxel @ 2022-01-20 13:38 UTC (permalink / raw)
  To: Dr. Arne Babenhauserheide; +Cc: Maxime Devos, guile-devel

[-- Attachment #1: Type: text/plain, Size: 2431 bytes --]


"Dr. Arne Babenhauserheide" <arne_bab@web.de> writes:

> Greg Troxel <gdt@lexort.com> writes:
>
>> [[PGP Signed Part:Signature made by expired key 1FDA7AE8098ED60E Gregory D. Troxel (low security, at work) <gdt@work.lexort.com>]]
>>
>> Maxime Devos <maximedevos@telenet.be> writes:
>>
>>> Maybe the IPV6_V6ONLY (see the ipv6(7) man page) is relevant here.
>>> Alternatively, you could run two servers in parallel: one bound to an
>>> IPv4 address and another bound to an IPv6 address.
>>
>> My feeling is that IPV6_ONLY is best avoided, for portability, and
>> because mapped addresses (an IPv6 address with the v4 address embedded)
>> are awkward.    So I think it's best to listen on v4 and v6 separately.
>
> I see portability, but for simplicity and having the same codebase, I
> think that IPV6_V6ONLY=0 is the right choice.

Make sure you add to your example pulling out the IPv4 address of
connections and logging it reasonably (as a v4 address).  I think it
won't be so simple.

> It is possible to listen both on v6 and v4 for the same port, but you’ll
> then have more complexity — I’m mainly thinking about tutorials here:
> You’ll have to explain a lot more if you have to take care of v6 vs. v4
> instead of having a library that does both.

It's creating two sockets instead of one.  A program that really works
as to be able to do that anyway, because the user should be able to
configure listen addresses to listen on some interfaces and not others.

I also don't follow "library that does both".  If a library has an
option to create one socket, it should be extendable to do both in some
straightforward way.

My experience is that programs that are structured to allow multiple
sockets are easy to make work, and those that don't end up awkward in
various ways,  so I'm encouraging you to address that root cause early.

> An alternative could be a server using the fiberized web server to be
> able to tie efficiently into the rest of the code via a plain fibers
> channel.

That sounds like what should really be addressed; the frameworks should
allow "add this socket, add this other socket" and that should all be
natural.   Whether it's two interface addresses v4 only, or v4/v6, or
v4, v6 and some future protocol.   (BSD kernels used to have ISO and IPX
at some point, and there's no V6ONLY type hack for those.)

Thanks for listening...
Greg

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-01-20 13:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19  7:57 (web server) serving on both ipv6 and ipv4? Dr. Arne Babenhauserheide
2022-01-19  8:51 ` Maxime Devos
2022-01-19 18:27   ` Greg Troxel
2022-01-20  7:24     ` Dr. Arne Babenhauserheide
2022-01-20 13:38       ` Greg Troxel
2022-01-19 13:07 ` Chris Vine
2022-01-19 13:44   ` Chris Vine
2022-01-19 13:53     ` Chris Vine
2022-01-19 21:12     ` Chris Vine
2022-01-19 21:42       ` Dr. Arne Babenhauserheide

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).