IPv6 Input - Linux

As shown earlier, we register a specific function as a packet handler for IPv6 packets and the handler gets called when a network interface device receives a packet of type ETH_P_IPV6. This function in many ways is simpler than its equivalent for IPv4 because of the simpler IPv6 header format. The IPv6 header is simpler because, unlike IPv4, all the IPv6 options are in separate headers.The packet handling function, ipv6_rcv, is defined in file linux/net/ipv6/ip6_input.c and is called from the softirq context, or "bottom half" in the packet queuing layer.

Here we store the index of the incoming network interface device. We don’t refer to the actual network interface device, dev, once the packet is queued.

((struct inet6_skb_parm *)skb->cb)->iif = dev->ifindex;

We must check to make sure that the incoming packet is at least long enough to hold the IPv6 header.

We check to make sure that the version field is six for IPv6.

We get the payload length directly from the packet header. The payload length includes the length of the optional headers if there are any.

pkt_len = ntohs(hdr->payload_len);

It is possible that the payload length is zero if our input packet is a jumbogram.

If the next header is a hop-by-hop header, then we call ipv6_parse_hopopts to extract the hop options from the incoming packet. The hop options are stored back in the socket buffer, skb.

Now we continue processing by calling ip6_rcv_finish, which calls ip_route_input to set up the destination cache for this incoming packet by setting the dst field in the skb.

At this point, the processing is very similar to IPv4 input packet processing. Input packets may have a local destination in this machine or they may need to be forwarded. The packet destination was calculated when the ip_route_input function was called during the first stage of input packet processing. For example, if the destination is an internal destination on a machine, the input field in the dst_entry will point to the function ip6_input, which continues the processing of the input packets. Next, ip6_input calls ip_input_finish to deliver the packet to the upper layer protocols. If the destination is a locally reachable host, output will point to the function dev_queue_xmit, which queues the output packet to the network interface drivers. This process is the same as IPv4.

static inline int ip6_input_finish(struct sk_buff *skb)
. . .

Next, the rest of the processing is done by the input functions for each of the optional headers (other than the hop-by-hop header, which was processed already). The nexthdr field may contain the protocol number for an optional header or it may be UDP, TCP, IGMP, ICMP, or perhaps some other protocol.

Here is where we call the handler function for the protocol defined in the nexthdr field of the IP header.

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

Linux Topics