IPv6 UDP - Linux

IPv6 has its own implementation of the UDP protocol, in the file linux/net/ipv6/udp.c. Although the source code for IPv6 is mostly separate from IPv4, all the socket structures are shared, including the dynamic state information. There are no duplicate sockets or data structures outside of the protocol families. As with IPv4, UDP has an initialization function that is called from the IP initialization function as shown earlier. The initialization function for UDP is udpv6_init.

void __init udpv6_init(void) {

As is the case with the IPv4 function, inet_add_protocol registers the packet handlers.

The udpv6_protocol structure is shown here. The handler for incoming UDP packets is udpv6_rcv.

The flags field is initialized to allow XFRM transformations to be used with incoming UDP packets. This will allow packet security checks with the SDB.

The inet_protosw structure for registration is also defined in file ipv6/udp.c.

The prot and the ops structures for IPv6 UDP are shown here.

.prot = &udpv6_prot, .ops = &inet6_dgram_ops,

Capability has to do with permissions. As is the case with IPv4 UDP, anybody has permission to send UDP datagrams.

The UDP proto functions for IPv6 are defined as follows. This structure maps the socket calls to the protocol-specific functions.

The following two functions are the only ones shared with IPv4. It is interesting to note that although the socket level ioctl is different for SOCK_DGRAM type sockets, the protocol level ioctl is the same as UDP for IPv4.

We noted earlier how IPv6 has its own implementation of UDP. The separate sources are required for a couple of reasons. One is that the different address format requires different address comparison logic. Address comparisons are required when doing a lookup to find the destination socket for an incoming packet. A second reason is we need the ability to send and receive messages with AF_INET type destination addresses through IPv6 sockets, and this requires some special handling.

The function, udp6_sendmsg is called when the application wants to transmit a message of any type from a SOCK_DGRAM type socket of the AF_INET6 protocol family. Another reason why IPv6 requires a separate set of functions for UDP is to support flow labeling, which is a fundamental feature of IPv6 for supporting QoS. Although some data structures for IPv4 such as flowi are updated for version 2.6, the standard Linux framework does not support flow labeling. We should look at a small section of code in udp6_sendmsg to see how it decides to send packet via the IPv4 protocol.

The variable sin6 points to the "name" part of the msghdr structure, which is in the form of a sockaddr_in6 structure.

Here we check for the address families showing that it is legal to receive a message sent to an AF_INET type address family destination through an AF_INET6 socket.

We call udp_sendmsg, which is the ordinary IPv4 UDP send message function when we are sending datagrams to AF_INET type destinations.

return udp_sendmsg(iocb, sk, msg, len);

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

Linux Topics