From 520b72b8d60e4c78486eaf7078983d3343c57c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jake=20Buchholz=20G=C3=B6kt=C3=BCrk?= Date: Thu, 23 Mar 2023 10:33:52 -0700 Subject: [PATCH] Fix imds-net-sync with multiple interfaces * all IPv4s of non-eth0 interfaces should be associated with route table * also add "to" rules for non-eth0 interfaces (symmetry with the "from" rules) --- sbin/imds-net-sync | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sbin/imds-net-sync b/sbin/imds-net-sync index a341705..897a779 100755 --- a/sbin/imds-net-sync +++ b/sbin/imds-net-sync @@ -49,15 +49,14 @@ iface_ip6s() { } imds_ip4s() { - local ip4=$(imds "@nic:$IFACE,@ipv4") - local ip4s=$(echo "$ip4" | tail +2) # secondary IPv4s + local ip4s=$(imds "@nic:$IFACE,@ipv4") local ip4p ip4_cidr ip4_gw # non-eth0 interfaces need custom route tables # if [ "$IFACE" != eth0 ] && [ -n "$ip4s" ] && [ -z $(ip +F -4 route show table "$RTABLE" 2>/dev/null) ]; then - ip4p=$(echo "$ip4" | head -1) # primary IPv4 + ip4p=$(echo "$ip4s" | head -1) # primary IPv4 ip4_cidr=$(imds "@nic:$IFACE,@ipv4-net") # TODO: get from iface instead? # TODO: this may not hold true for non-AWS clouds ip4_gw=$(echo "$ip4_cidr" | cut -d/ -f1 | @@ -91,6 +90,7 @@ imds_ip6s() { sleep 0.5 done ip -6 route add default via "$gw" dev "$IFACE" table "$RTABLE" + # TODO? match ipds_ip4s() with ip -6 route add "ip6_cidr" dev "$IFACE" ... fi echo "$ip6s" } @@ -110,6 +110,7 @@ ip_addr() { # non-eth0 interfaces get rules associating IPs with route tables ip -"$1" rule "$2" from "$3" lookup "$RTABLE" + ip -"$1" rule "$2" to "$3" lookup "$RTABLE" } # sync_ips {4|6} "" ""