IPv6 TCP - Linux

IPv6 also has its own version of the TCP protocol, which can be found in file linux/net/ipv6/tcp_ipv6.c. The initialization procedure for TCP is the same as UDP. Its handler functions are defined as follows.

static struct inet6_protocol tcpv6_protocol = {

Tcp_v6_rcv is the handler function for incoming TCP segments.

As with UDP, we allow security policy checks of incoming packets using the XFRM mechanism.

.flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, } ;

The proto structure for TCP is defined below. Most of the fields are mapped to the very same functions used with IPv4, but we have noted a few exceptions here.

The connect function is different for IPv6. This is to handle mapped IPv4 addresses.

Socket initialization and destruction functions also are unique for IPv6. This is because there are a few fields in the sock structure that are initialized differently from IPv4.

Finally, the backlog receive function is different. All the socket lookup and socket hash functions are different, too. Both the address and port are used to look up a socket, so all these functions must be implemented specially for the longer address format in IPv6.

In general, TCP is implemented separately to support IPv6 addressing and the ability to specify IPv4 destinations over IPv6 sockets. We will look at a few code snippets from some of the TCP functions to see how IPv6 handles things differently. For example, let’s look at the TCP connect function for IPv6, tcp_v6_connect.

Here we check to see if the application has requested any specific flow labeling for this socket. We recall from the earlier discussion that flow labeling is the IPv6 method of QoS. The variable np points to the IPv6 protocol-specific info in the sock structure.

If the application wants to connect to INADDR_ANY, that means that we really want to connect to the loopback addresses. Therefore, we explicitly set the bit to define the loopback address type.

Here we check to see if the address type is link-local.

The field sin6_scope_id field is the scope of the link-local address. It is used to specify the network interface device index. If the socket is bound to an interface, we check to see if the socket is bound to the same interface through which the application is requesting the connection. If not, the request is invalid.

Here we check to see if our socket is bound to an interface. This is because, by definition, a linklocal destination requires that an interface be known.

Now, we handle TCP over IPv4. If the address to which we are trying to connect is an IPv4 mapped address, we want the TCP from IPv4 to handle packets for this socket.

We set the backlog receive function to the correct one for IPv4 TCP and then call the IPv4 TCP connect function with the IPv4 portion of the destination address.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Linux Topics