Discussion:
Does IPv6 sendmsg work with IPv4-mapped addresses?
Chinh Nguyen
2008-02-20 15:19:33 UTC
Permalink
Hi,

I know that linux networking stack is dual-stack. I can send/receive to
both IPv4 and IPv6 addresses with an IPv6 socket using send, sendto,
recvfrom, etc. For IPv4 addresses, I simply convert to IPv4-mapped IPv6
address when populating sockaddr_in6.

Theoretically, I can specify the source address of the outgoing packet
on an IPv6 socket by using sendmsg with IPV6_PKTINFO option enabled and
in6_pktinfo. However, I cannot do this when the source address I specify
is IPv4-mapped. The system still chooses the IPv4 source based on the
routing table. Does linux IPv6 support IPv4-mapped addresses for
sendmsg? Note I do not have trouble with the destination IPv4-mapped
address in the destination sockaddr_in6 structure.

My own guess is no because IPv6 is not as tightly integrated as it
seems, linux dual-stack is a bit odd. Yes, I can send and receive IPv4
packets via IPv4-mapped addresses. But consider this example.

If I have enabled IPV6_PKTINFO on an IPv6 socket, I would expect to
receive both IPv6 and IPv4 local address (as IPv4-mapped address) info
in an in6_pktinfo when using recvmsg. But I only receive data for IPv6
packets. To receive IPv4 local address info from an IPv4 incoming
packet, I have to also enable IP_PKTINFO on the IPv6 socket.
Furthermore, the data will be a regular IPv4 address in an in_pktinfo
structure.

Chinh

--
http://www.certicom.com
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
YOSHIFUJI Hideaki / 吉藤英明
2008-02-20 16:14:49 UTC
Permalink
Post by Chinh Nguyen
Theoretically, I can specify the source address of the outgoing packet
on an IPv6 socket by using sendmsg with IPV6_PKTINFO option enabled and
in6_pktinfo. However, I cannot do this when the source address I specify
is IPv4-mapped. The system still chooses the IPv4 source based on the
routing table. Does linux IPv6 support IPv4-mapped addresses for
sendmsg? Note I do not have trouble with the destination IPv4-mapped
address in the destination sockaddr_in6 structure.
Sendmsg itself, yes, but IPV6_PKTINFO, no.
Semantics of ipv4-mapped address (in basic API) in that socket option
(in advanced API) is undefined.
Post by Chinh Nguyen
If I have enabled IPV6_PKTINFO on an IPv6 socket, I would expect to
receive both IPv6 and IPv4 local address (as IPv4-mapped address) info
in an in6_pktinfo when using recvmsg. But I only receive data for IPv6
packets. To receive IPv4 local address info from an IPv4 incoming
packet, I have to also enable IP_PKTINFO on the IPv6 socket.
Furthermore, the data will be a regular IPv4 address in an in_pktinfo
structure.
If you need "advanced" things, go native way.
And, well, I'd even strongly suggest not to use IPv4-mapped addresses
unless you have very very good reason.

--yoshfuji
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Chinh Nguyen
2008-02-20 17:21:46 UTC
Permalink
I am only using IPv4-mapped address because it is the "recommended" (?)=
=20
way to specify an IPv4 destination address when using an IPv6 socket. B=
y=20
recommendation, I mean this is the way unix networking books/man=20
pages/etc. describe the standard usage of a dual-stack socket (IPv6=20
socket supporting both IPv4 and IPv6 addresses).

Obviously, I am using an IPv6 socket to be efficient. Otherwise, I woul=
d=20
simply bind IPv6 and an IPv4 sockets separately.

I understand there are security concerns with IPv4-mapped addresses. If=
=20
there's a better way to send/receive IPv4 over IPv6 sockets (as well as=
=20
send/receive IPv6) in linux, I'd love to learn about it.

Regards,

Chinh
--
http://www.certicom.com
Post by YOSHIFUJI Hideaki / 吉藤英明
=20
Theoretically, I can specify the source address of the outgoing pack=
et=20
Post by YOSHIFUJI Hideaki / 吉藤英明
on an IPv6 socket by using sendmsg with IPV6_PKTINFO option enabled =
and=20
Post by YOSHIFUJI Hideaki / 吉藤英明
in6_pktinfo. However, I cannot do this when the source address I spe=
cify=20
Post by YOSHIFUJI Hideaki / 吉藤英明
is IPv4-mapped. The system still chooses the IPv4 source based on th=
e=20
Post by YOSHIFUJI Hideaki / 吉藤英明
routing table. Does linux IPv6 support IPv4-mapped addresses for=20
sendmsg? Note I do not have trouble with the destination IPv4-mapped=
=20
Post by YOSHIFUJI Hideaki / 吉藤英明
address in the destination sockaddr_in6 structure.
=20
Sendmsg itself, yes, but IPV6_PKTINFO, no.
Semantics of ipv4-mapped address (in basic API) in that socket option
(in advanced API) is undefined.
=20
If I have enabled IPV6_PKTINFO on an IPv6 socket, I would expect to=20
receive both IPv6 and IPv4 local address (as IPv4-mapped address) in=
fo=20
Post by YOSHIFUJI Hideaki / 吉藤英明
in an in6_pktinfo when using recvmsg. But I only receive data for IP=
v6=20
Post by YOSHIFUJI Hideaki / 吉藤英明
packets. To receive IPv4 local address info from an IPv4 incoming=20
packet, I have to also enable IP_PKTINFO on the IPv6 socket.=20
Furthermore, the data will be a regular IPv4 address in an in_pktinf=
o=20
Post by YOSHIFUJI Hideaki / 吉藤英明
structure.
=20
If you need "advanced" things, go native way.
And, well, I'd even strongly suggest not to use IPv4-mapped addresses
unless you have very very good reason.
=20
--yoshfuji
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...