Thursday, September 10, 2020

Assigning the same IP address to multiple interfaces

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEdodNnxM2uiJZBxxxsoi1X/+cIsEFAl9aQn0ACgkQsoi1X/+c
IsFgMw//TsIL+PjuhRdJT+km0UHoG1itpHV/hepQ4B38Pc0TnfGZH9ls6rLKTn4B
45a6bHnV5763N+k1PZc6ZuWh70TObVspZt7o3wPdvz0yp5mjfugU0h8+sVAFWuRy
0ttQxrZM5tOD3MN3DS2TYUiF4aR9avDLgQLnaxF+LFTwHPEane4MWovETtgG3ln3
yp+cVeiko/TQUtSNWfB1jZ4DHwEoLXtnRojhaPxvOktNgXBxygD0szj6BfvOwQPn
nLYBQz72zUWs11C3B/Th4HW/rCCAxH36F6KY6e7nc7+7FNUC2vZgLpKG+vu12Pe9
SdS4HzEoSYaFVpE6l1rQKU8Au/lYCZMWGxfKcAXZije8X3Gkkvqc3nYsKQ31l7qz
EpswnB3VhAT9obW/If6JgHD9uMkhpvvjNC8LF7Vc7lvgt7jlo5CTEhk8mSQ1ULOu
9QsbAus5ZoMiSehQpVe5RNHSRg/sxgrNQyytnCnYIFvjdk6DI1UcE7ZsgR2D3Y8H
Nxuen2YwR2f+0AV7aXOLabqpsjwaV8TlaVOAUG8Y3JM6/IfR1vBphqrnugkndJ0q
2tbx7OrVHRnDVwBJfbySiQ4EeR6HmkoI7B/nRAby95WES+5cotSQZcIwZgt42H85
Xap4Xk2RGe7B2LiWOC36hLp2fefuvD4HcbH/dP+IcJYsxx0Dikw=
=d1Fu
-----END PGP SIGNATURE-----
How do I assign the same IP and MAC address to multiple interfaces?
This is easy on Linux, but I cannot figure out how to do it on
OpenBSD. The (virtual) machine is assigned a single IP address by
the hypervisor, so changing the IP not an option, and bridging is
a no-go as all the peers share a MAC address. All netmasks are /32
for IPv4 and /128 for IPv6.

Each of the interfaces is a point-to-point Ethernet link, and both
its IP and MAC address and that of its peer are statically known.
All routes are also assigned statically. In short, I need to assign
a route based purely on the name of an interface.

The -ifp keyword in route(8) seems like it should be used for this,
and the kernel sources indicate that it can be used to disambiguate
which interface should be selected. However, I was not able to get
it to work. I don't have access to the VM I was using for testing
anymore, but if I recall correctly, the C code and shell scripts I
was using did the equivalent of the following:

# ifconfig xnf0 inet 10.137.0.77 prefixlen 32
# route -n delete 10.137.0.77/32 10.137.0.77
# # this doesn't work due to a route(8) bug ― I was using C code instead
# # I submitted a bug report (with patch) to bugs@ a while back
# route -n add -inet 10.137.255.254 -link fe:ff:ff:ff:ff:ff -ifp xnf0 -ifa 10.137.0.77
# ifconfig vether0 create lladdr fe:ff:ff:ff:ff:ff
# ifconfig vether0 inet 10.137.0.77 prefixlen 32
# # this doesn't work due to a route(8) bug ― I was using C code instead
# route -n add -inet 10.139.255.254 -link fe:ff:ff:ff:ff:ff -ifp vether0 -ifa 10.137.0.77
# route -n delete 10.137.0.77/32 10.137.0.77
$ route -n show

I expect that the route would to 10.139.255.254 would go through
vether0, but it goes through xnf0 instead. If I then run:

# ifconfig xnf0 -inet
$ route -n show

the route is gone.

Should the above commands have worked? If not, is this just
unsupported in OpenBSD? If it is supported, what should I have done
differently? I did manage to create a workaround: I can assign each
interface a unique alias address from the 169.254.0.0/16 link-local
range, and use PF to NAT packets in this range to 10.137.0.77.
However, this feels like an ugly hack.

For IPv6, I can use the link-local address of each interface as the
-ifa argument, so I am much less worried.

Thank you for your time and attention.

Sincerely,

Demi M. Obenour

No comments:

Post a Comment