Routing IPv6 packets towards oneself with routing sockets?
Hiroki Sato
hrs at FreeBSD.org
Tue Aug 19 08:30:30 UTC 2014
Fernando Gont <fernando at gont.com.ar> wrote
in <53E5B71D.2030500 at gont.com.ar>:
fe> > Although your code assumes RTA_GATEWAY eventually returns the
fe> > outgoing interface, it is not always true. RTA_IFP should be used if
fe> > you want to look up it instead of looking up gateways until AF_LINK
fe> > is obtained. Certainly RTA_GATEWAY returns AF_LINK and you can check
fe> > sdl_index in it, but the index number is not always the same as the
fe> > actual outgoing interface (one of the examples is a host route).
fe>
fe> Just curious: what's the meaning of the AF_LINK I was reading?
Sorry for the delay. AF_LINK with (sdl_nlen == sdl_alen == sdl_slen
== 0) in RTA_GATEWAY was used to create a clone route. Let's
consider a situation that there are a IPv4 node (node A) with
192.168.0.1/24 on its em0 and another node (node B) with
192.168.0.2/24 on the same link. If node A is running FreeBSD 8.0 or
later, an output of "netstat -nrf inet" on node A will be something
like this:
Destination Gateway Flags Netif Expire
192.168.0.0/24 link#2 U em0
192.168.0.1 link#2 UHS lo0
but it was the following on an older FreeBSD (and other
4.3BSD-derived implementations to which UNPv1 refers):
Destination Gateway Flags Refs Use Netif Expire
192.168.0.0/24 link#2 UC 2 0 em0
192.168.0.1 xx:xx:xx:xx:xx:xx UHLW 0 0 lo0
192.168.0.2 yy:yy:yy:yy:yy:yy UHLW 0 0 em0
A primary difference is that FreeBSD 8.0 and later do not directly
have L2 address information in the routing table. Instead, FreeBSD
now has L2 address translation table and routing table separately.
In the old routing table, a host route on the same net
(e.g. 192.168.0.2) was dynamically created and its MAC address was
added to the routing table by issuing ARP request. More
specifically, when node A attempts to look up a route for
192.168.0.3, for example, an AF_LINK route with empty L2 address in
RTA_GATEWAY matches first via the entry 192.168.0.0/24 bacause it is
the most specific at the moment. Then the sdl_index in RTA_GATEWAY
is used for ARP request, and a host route is added eventually. NDP
works in the same way for IPv6.
In the new implementation, a route with empty L2 address means which
L2 address table (separated in per-interface and per-AF basis) should
be referred. A host route is usually used only as loopback route,
and in its RTA_GATEWAY it just has empty L2 address with if_index
where the address is configured.
So, in both cases checking AF_LINK in RTA_GATEWAY is not reliable to
know the actual outgoing interface.
-- Hiroki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-net/attachments/20140819/a0aaf989/attachment.sig>
More information about the freebsd-net
mailing list