Neighbor Discovery - Linux

The Neighbor Discovery (ND) protocol is used by hosts and routers for mutual discovery on locally connected nets [RFC 2461]. This protocol replaces two protocols in IPv4. One of these protocols, no longer needed in IPv6, is ARP. In IPv4, ARP was used to map an IP address to a link layer address. As we saw, this is no longer necessary because IPv6 addresses include a link-local address type in which the link-layer addresses are built in to the IPv6 address itself. Another facility that sometimes used IPv4 was router discovery [RFC 1256]. Router discovery was a protocol in which routers would send out periodic advertisements with advertised addresses and preferences. Hosts could choose a default gateway from among the advertisements.

We covered the generic neighbor system. we discussed how the neighbor system was designed for the ND protocol, even though it is used for an ARP cache in IPv4. We create a local instance of the generic neighbor table. In the ndisc.c, the neighbor table nd_tbl is initialized.

struct neigh_table nd_tbl = { . . .

The constructor and proxy constructor member functions are set as follows.

We also initialize a neighbor operations structure for the generic operations, the hardware header operations, and the direct operations. In each case, most of the member functions use the generic functions defined for the neighbor system, but the family field is initialized to AF_INET6. For example, this is how the ndisc_generic_ops structure is initialized for the IPv6 ND protocol.

The following four functions are the same ones that are used for the IPv4 neighbor cache.

In the hardware header operations, the only local function is the solicit member function.

.solicit = ndisc_solicit,

ND messages are defined as part of the ICMPv6 protocol. Therefore, there is no packet handler registered specifically for ND. The protocol includes four different message types, defined in file linux/include/net/ndisc.h..

Neighbor Discovery Messages

Neighbor Discovery Messages

When an ND message is received by ICMP, it calls the function ndisc_rcv implemented in file linux/net/ipv6/ndisc.c.

As of this writing, there isn’t support for the router solicitation message NDISC_ROUTER_SOLICITATION.

The neighbor solicitation message is sent for two reasons. The first is to discover the link-layer address for a connected neighbor. The other is to determine the reachability status of a neighbor. The function ndisc_recv_ns in file ndisc.c processes the neighbor solicitation messages.

static void ndisc_recv_ns(struct sk_buff *skb);

The first thing we do is some validity checks. If the source address is the unspecified address, IPV6_ADDR_ANY, the destination address must be the solicited node multicast address. Next, we parse the neighbor discovery options in the packet. We update the neighbor cache and the unreachability state depending on the message contents. Of course, we also send a neighbor advertisement message in response if the validity checks pass. The neighbor advertisement message is received in response to a neighbor solicitation.

static void ndisc_recv_na(struct sk_buff *skb) . . .

The main thing this function does is look up the advertised neighbor in the neighbor cache. This is done by calling the generic neighbor cache function, neigh_lookup. Msg points to the neighbor advertisement message contents. Target is the advertised address.

If the neighbor cache entry is listed as a router, we must change that entry back to host and try to get the actual default router.

Here we are checking the flag bit in the ICMP header of the incoming packet to see if it is coming from a router. If so, we update the neighbor cache entry.

Here we update the neighbor cache entry by calling neigh_update. will update the reachability state and attach the hardware header, so packets can be transmitted using this neighbor entry.

The Router Advertisement (RA) message serves several functions. Primarily, it is simply an RA message. When a node receives an RA message, it can determine which machine is the default or preferred router. In addition, the RA message is used for interface autoconfiguration because it may contain an address to be added to the interface’s list of local addresses. The function ndisc_router_discovery processes an incoming router advertisement message.

static void ndisc_router_discovery(struct sk_buff *skb);

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

Linux Topics