DanielG / dhcp-policy-routing

Policy routing or multihoming with DHCP for additional public IP addresses from consumer Cable modems
3 stars 1 forks source link

Routing table identifier is 32-bit #1

Closed SpareSimian closed 1 year ago

SpareSimian commented 1 year ago

The value used in rt_tables can be in the range 1-(2^32-1). See: https://man7.org/linux/man-pages/man8/ip-route.8.html

(I'm setting up a router and planning to use a table value of 5000 plus the interface index for each WAN interface.)

DanielG commented 1 year ago

Indeed it is. A fact I exploit in my latest (unpublished) generalized iteration of this dhcp multihoming script. Really this example is quite outdated, if you're implementing this on modern systems I would recommend trying source-specific routing[1] ala ip route add default from $WAN_IP dev $WAN_IFACE. No need to fiddle with multiple routing tables then. I haven't tested it with IPv4 yet but from reading the kernel source it should work for /32 addresses. Let me know if you test it out.

[1]: See https://arxiv.org/pdf/1403.0445.pdf for motivation etc.

DanielG commented 1 year ago

Ok, turns out SSR isn't supported on the IPv4 side after all. Instead I've updated the entire thing for the latest iteration of this setup using just plain'ol dhclient since I found dhcpcd too finicky and unpredictable.

The route table IDs are now derrived from the DHCP assigned IP addresses so there's no need for manual table configuration anymore.

This iteration also fixes LAN address reachability and use with stuff that only supports fwmarks not source IP binding (cough wireguard cough).

SpareSimian commented 1 year ago

Thanks so much! I'd read through the paper and was googling for examples and all I could find were 10-year-old articles about how it didn't work with IPv4, so I parked the project temporarily. Now I feel motivated to go back to it!

DanielG commented 1 year ago

Sorry about that. I've been working a lot with IPv6 lately. It's easy to forget how stuck in time IPv4 is feature wise on linux :)

Let me know how your deployment turns out.

SpareSimian commented 1 year ago

I installed it and it seems to work, using dhcpcd. I made one change to the suggested procedure and put multihomed in /usr/local/sbin instead of /etc to reduce clutter in /etc. I symlink that to /etc/dhcpcd.exit-hook. System is 2023-02-21-raspios-bullseye-arm64. (I started to investigate switching to dhclient only to find that ISC has stopped development on that while dhcpcd is still under active development. I'm already using Kea for the server side on my home system.)