Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Sep 2020 13:48:33 -0700
From:      Doug Hardie <bc979@lafn.org>
To:        freebsd-net@freebsd.org
Subject:   Address Differences between UDP and SCTP
Message-ID:  <6A9D0A4B-F35C-4012-A868-5450D60EC13B@mail.sermon-archive.info>

next in thread | raw e-mail | index | archive | help
I was quite surprised to discover that the sockaddr structure returned =
from recv_fd and recvfrom handle IPv4 addresses differently when using =
an INET6 socket.  I don't know if this was intended, or a side effect.  =
I started using SCTP because of the need for accessing multi-homed =
servers.  Some would be on IPv6 and others on IPv4.  SCTP handles that =
nicely if you use an INET6 socket.  When a transaction is received, if =
it is to an IPv4 address, then the returned sockaddr will have a =
inet_family of IPv4 and the IPv4 structure.  If it was sent to an IPv6 =
address, then the inet6_family is used.  A simple test of the family =
tells you which address format was provided and the address is in IPv4 =
or IPv6 format accordingly.

However, A new site needed to be added and it is behind a NAT router.  =
The problem with SCTP is that most (possibly all) NAT routers only work =
with TCP and UDP.  They will not port forward SCTP.  So I have no way to =
get through to the machine.  So I added code to check for that situation =
and use UDP instead.  This will work because I don't thing it is at all =
likely that a machine behind NAT can be multi-homed.

However, the code to obtain the remote IP address failed miserably.  It =
turns out that if you have v6only set to 1, you will never see the IPv4 =
packets.  If you set it to 0, then you get the packets, but the sockaddr =
format with UDP is different than that for SCTP.  If it is an IPv6 =
address, everything is the same.  However, if it is an IPv4 address, =
then the family remains IPv6, and the address is in sin6_addr and it is =
in the format ::ffff:n.n.n.n.  This makes it interesting as I need to =
obtain the IPv4 address as part of the verification process that the =
transaction is authorized.

Was this difference intended, or is it likely to change in the future?

-- Doug




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6A9D0A4B-F35C-4012-A868-5450D60EC13B>