2
# ip route get 1.2.3.4
anycast 1.2.3.4 dev eth0  src 5.6.7.8

and the question is how does it know the address is an anycast ? (which apparently is true).

UPDATED:

Present as anycast route:

root@hv2 ~ # ip route get 1.2.3.4
anycast 1.2.3.4 dev eth0  src 5.6.7.8 
    cache 

but not visible in list:

root@hv2 ~ # ip route list|grep 1.2.3.4|wc -l
0

but it's possible to delete it, and than it back to normal (no anycast anymore):

root@hv2 ~ # ip route del anycast 1.2.3.4 dev eth0
root@hv2 ~ # ip route get 1.2.3.4
1.2.3.4 via 5.6.7.8 dev eth0  src 9.10.11.12 
    cache 
pawel7318
  • 213

2 Answers2

4

If you look at the iproute2 gitweb, you'll see it's showing the status of the RTN_ANYCAST bit set on the kernel routing structure. If you cross-reference that with the kernel source (rtnetlink.h) you'll see the following comment:

    RTN_ANYCAST,            /* Accept locally as broadcast,
                               but send as unicast */

If you check the manual page, you'll see the anycast status of an address is determined by configuration (in particular, adding the anycast keyword when you specify the address to be added). According to man 8 ip:

   IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ]
           [ label STRING ] [ scope SCOPE-ID ]

   ...
           anycast   -   _not  implemented_  the  destinations are anycast
           addresses assigned to this host.  They are mainly equivalent to
           local with one difference: such addresses are invalid when used
           as the source address of any packet.

From the first part of the manual, it states that when you specify the address, you can instruct the stack that it's an anycast address. Without checking the kernel source code, I imagine that when you add an anycast address, the anycast bit gets propagated to a corresponding routing table entry that would be created when the address is added.

I'm not sure if the "not implemented" part is entirely correct, because it looks like iproute2 is indeed passing the anycast flags into the system calls. So it seems like if anycast is supported by the kernel, it should work. But I haven't tested it, so I don't know about that.

mpontillo
  • 924
1

From the man page for ip-route, under the "ip route get" section:

Note that this operation is not equivalent to ip route show. show shows existing routes. get resolves them and creates new clones if necessary. Essentially, get is equivalent to sending a packet along this path

You can show anycast routes with the command ip route show type anycast.

Jed Daniels
  • 7,452
  • 2
  • 37
  • 43