Thursday, 12 July 2012

IPv6 dual-stack listeners?

As alluded to in my previous post "IPv6 and bip" when a service creates its network endpoint as an IPv6 socket it is actually able to  communicate with both IPv6 clients and IPv4 clients interchangeably.  But how does this work?

This compatibility mode is defined in one of the foundation Request For Comments (RFC) documents, specifically RFC3493 which defines how the socket() interfaces should behave with respect to IPv6 (see section 3.7 for the gory details).  This defines a reserved area of IPv6 address space which maps 1:1 to IPv4 addesses.  Essentially the IPv4 address may be translated into a unique reserved IPv6 address by concatenating the 0:0:0:0:0:FFFF prefix with the existing IPv4 address.  As this address is unique the underlying socket implementation can directly infer the correct physical protocol to use for this connection from the address alone, allowing connections to safely coexist.

The great thing about this compatibility mode is it works for any socket, server or client.  This allows an application to support only IPv6 and yet remain compatible with addresses of either type.  We no longer have to care which they are, nor does a service have to bind sockets to each protocol and handle the complexity that entails.  Magic.


No comments:

Post a Comment