diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-05-13 20:13:24 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-05-18 08:40:55 +0000 |
commit | 64ad908eb80c9b494454f0e4ac06e691a89fdb22 (patch) | |
tree | ea090c079936d8f709064d3de3897dcb3dc8d4a7 /pkgs/os-specific/linux/spectrum/vm/net/default.nix | |
parent | 5ebae3db48bfb2157bbbd36cad8b4dc6db96f148 (diff) | |
download | nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar.gz nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar.bz2 nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar.lz nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar.xz nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.tar.zst nixpkgs-64ad908eb80c9b494454f0e4ac06e691a89fdb22.zip |
spectrumPackages: use link-local router addresses
There's no need for every interface on a router to have it's own unique IP. Using link-local addresses, we can assign every interface on a single router the same IP, and save the effort of adding/subtracting one all the time to infer the address of one side of a link from the other. This means that routers and clients are both only interested in what the IP of the client should be, since that's the only thing that is different between different links. So we change our MAC format to communicate the client IP to both sides. If we just made the whole NIC portion of the MAC the last three octets of an IP address like we did before, then both ends of the link would have the same MAC, so we still need to set a bit to encode whether a MAC is at the router side of the link or the client side. I've decided to simplify the implementation by using the most significant bit of the NIC part for that, and just declaring the rest of that octet to be reserved. This way, no calculation is required in the guests -- they just need to look at the last two octets. And we can still identify 65536 links in this scheme, which should be enough for anybody, right? Message-Id: <20210513201323.2087344-1-hi@alyssa.is> Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
Diffstat (limited to 'pkgs/os-specific/linux/spectrum/vm/net/default.nix')
-rw-r--r-- | pkgs/os-specific/linux/spectrum/vm/net/default.nix | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pkgs/os-specific/linux/spectrum/vm/net/default.nix b/pkgs/os-specific/linux/spectrum/vm/net/default.nix index 1deb7031caf..5921b62fcf7 100644 --- a/pkgs/os-specific/linux/spectrum/vm/net/default.nix +++ b/pkgs/os-specific/linux/spectrum/vm/net/default.nix @@ -54,15 +54,16 @@ runCommand "vm-net" rec { # Our IP is encoded in the NIC-specific portion of the # interface's MAC address. - backtick -i LOCAL_IP { + backtick -i CLIENT_IP { pipeline { ip -j link show $INTERFACE } - pipeline { jq -r ".[0].address | split(\":\") | .[3:6] | \"0x\" + .[]" } - xargs printf "100.%d.%d.%d" + pipeline { jq -r ".[0].address | split(\":\") | .[4:6] | \"0x\" + .[]" } + xargs printf "100.64.%d.%d" } - importas -iu LOCAL_IP LOCAL_IP + importas -iu CLIENT_IP CLIENT_IP - if { ip address add ''${LOCAL_IP}/31 dev $INTERFACE } - ip link set $INTERFACE up + if { ip address add 169.254.0.1/32 dev $INTERFACE } + if { ip link set $INTERFACE up } + ip route add $CLIENT_IP dev $INTERFACE } { |