23.3 IPv6 Implementation

   


The implementation of IPv6 in the Linux kernel is in the net/ipv6 directory and in the header file <include/net/ipv6.h>. The code of IPv4 formed the basis for the IPv6 implementation, so that most things are similar. As in IPv4, packets can reach the IPv6 layer in either of three possible ways. Figure 23-3 shows how a packet travels across the Linux kernel. Packets received by the network card are passed by the function ipv6_rcv(sbk, dev, pt) to the data-link layer, and ip6_xmit(skb) sends packets created by higher layers or protocols (e.g., UDP or TCP). Finally, special commands, such as icmpv6_send(), can be used to create IPv6 packets in the IP layer.

Figure 23-3. IPv6 implementation in the Linux kernel.

graphics/23fig03.gif


23.3.1 Incoming Packets

ipv6_rcv()

include/net/ipv6.h


ip6_rcv_finish()

net/ipv6/ip6_input.c


The ipv6_rcv() function accepts IPv6 packets incoming from the lower layer. If an incoming packet is addressed to a different computer, it is dropped immediately by ipv6_rcv(). If an IPv6 packet is addressed to the local computer, then the first things to do are to check the IPv6 packet header and the packet length and to use the skb_trim() function to correct things, if necessary. If a packet-header extension of the type Hop-by-Hop Options follows next, this extension is processed by the function ipv6_parse_hopopts(). Subsequently, the NETFILTER call NF_IP6_PRE_ROUTING passes the IPv6 packet to the ip6_rcv_finish() function, which invokes one of these three functions: ip6_input(), ip6_mc_input(), ip6_forward().

23.3.2 Forwarding Packets

ip6_forward()

include/net/ipv6.h


ip6_forward_finish()

net/ipv6/ip6_output.c


The ip6_rcv_finish() function invokes ip6_forward() when an IPv6 packet has to be forwarded. The latter checks first to see whether forwarding is enabled; otherwise, the packet could simply get dropped. Subsequently, the packet's lifetime is checked, and, if the value in the Hop Limit field is smaller than or equal to one, the packet is actually dropped, and an ICMPv6 message is sent to the corresponding node. If the IPv6 packet is not explicitly sent over this computer on its way to the destination, (which means that the address of the local node is in the Routing packet-header extension), and if the packet would leave the computer over the same interface on which it arrived in the local node, then an ICMPv6 message of the type Redirect is returned to the sender. IPv6 packets with a Link-Local, Multicast or Loopback source address will also be dropped. The final check is to see whether the length of the new MTU is exceeded and, if so, to send an ICMPV6_PKT_TOOBIG message to the sender. Finally, the NETFILTER call NF_IP6_FORWARD passes the IPv6 packet to the ip6_forward_finish() function, which, in turn, invokes ip6_output().

23.3.3 Packets Delivered Locally

ip6_xmit()

include/net/ipv6.h


ip6_output()

include/net/ipv6.h


ip6_output_finish()

net/ipv6/ip6_output.c


Packets that have to be delivered locally are taken by the ip6_rcv_finish() function and passed either to ip6_mc_input() or directly to ip6_input(). However, ip6_mc_input() merely checks to find out whether the multicast packet is addressed to this computer and, if so, passes it to ip6_input(). In turn, ip6_input() invokes the ip6_input_finish() function over a NF_IP6_LOCAL_IN netfilter call and assumes further processing. Initially, ip6_input_finish() checks to see whether the next packet-header extension is of the type Hop-by-Hop Options; if this is true, this extension will be skipped. If the next header extension is either a TCP header or a UDP header, then all further packet-header extensions are processed by the ip6_parse_extheaders() function. Figure 23-3 shows this process in the Extensions box. If the IPv6 packet is not for a RAW IPv6 socket, then the next step determines the transport protocol. Similarly to IPv4, the IPv6 implementation uses a hash function over the maximum number of protocols (MAX_INET_PROTOS - 1). Subsequently, the IPv6 packet is passed to the function in charge, which processes the payload. If no transport protocol was identified, the IPv6 packet is passed to the matching RAW IPv6 socket (if present); otherwise, the packet will be dropped and an ICMPV6_UNK_NEXTHDR message returned to the sender.

23.3.4 Transport-Layer Packets

ip6_xmit()

include/net/ipv6.h


ip6_output()

include/net/ipv6.h


ip6_output_finish()

net/ipv6/ip6_output.c


Packets created by the transport layer can be sent via several different functions; one example is the function ip6_xmit(). This function accepts a packet for example, from the TCPv6 implementation and then uses the function skb_realloc_headroom() to first create free storage before the packet arrives, if the available storage is too small. Subsequently, the individual parameters for the IPv6 packet header are set, and the packet is passed to the function ip6_maybe_reroute() via the NETFILTER call NF_IP6_LOCAL_OUT, if it does not exceed the MTU. The function ip6_maybe_reroute(), in turn, ensures that an alternative route is found, if an entry in the routing table is no longer up to date. Next, ip6_maybe_reroute() passes the packet to the function ip6_output(), which filters multicast packets again before it sends the packet. Via the NETFILTER call NF_IP6_POST_ROUTING, the IPv6 packet eventually reaches ip6_output_finish(). This latter function uses Neighbour Discovery to figure out the further route for the IPv6 packet and then passes the packet to the transmit functions of the lower layer, from which the IPv6 packet leaves the local computer.


       


    Linux Network Architecture
    Linux Network Architecture
    ISBN: 131777203
    EAN: N/A
    Year: 2004
    Pages: 187

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net