From cc8e31f74f555a0fa1e214672dd50dddc6c30b3d Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 19 Sep 2024 06:02:42 +0200 Subject: [PATCH] board/common: adjust metric on IPv4LL and DHCP routes to match Frr Apply a distance adjustment to routes retrieved from IPv4LL/ZeroConf and DHCP to ensure that Frr (Zebra) can compare other protocol routes, e.g., static. Without this Frr will consider all routes read from the kernel to have a protocol distance of 0, meaning better than static routes that have a distance of 1. Initial proposal to fix issue #640 Signed-off-by: Joachim Wiberg --- .../common/rootfs/etc/avahi/avahi-autoipd.action | 15 ++++++++++++--- .../common/rootfs/usr/share/udhcpc/default.script | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/board/common/rootfs/etc/avahi/avahi-autoipd.action b/board/common/rootfs/etc/avahi/avahi-autoipd.action index 16df3899..239d7853 100755 --- a/board/common/rootfs/etc/avahi/avahi-autoipd.action +++ b/board/common/rootfs/etc/avahi/avahi-autoipd.action @@ -7,6 +7,10 @@ # STOP: The daemon is terminating # $2 interface name # $3 IP adddress +# +# For details on the distance adjustment below, please see the following +# section in the Frr documentation on distance + prefence => to metric. +# https://docs.frrouting.org/en/stable-8.0/zebra.html#administrative-distance PATH="$PATH:/usr/bin:/usr/sbin:/bin:/sbin" @@ -15,9 +19,14 @@ log() logger -I $$ -t zeroconf -p user.notice "$*" } -# Use a different metric for each interface, so that we can set -# identical routes to multiple interfaces. -METRIC=$((1000 + `cat "/sys/class/net/$2/ifindex" 2>/dev/null || echo 0`)) +# Use a different metric for each interface as tie breaker, to ensure we +# can set identical routes to multiple interfaces. +IFINDEX=$(cat "/sys/class/net/$2/ifindex" 2>/dev/null || echo 0) + +# Distance adjustment to ensure that static routes set by Zebra and any +# routes learned from DHCP take precedence over these interface routes. +# A distance of 255 ensures these routes are never redistributed. +METRIC=$(((255 << 24) + 1000 + IFINDEX)) case "$1" in BIND) diff --git a/board/common/rootfs/usr/share/udhcpc/default.script b/board/common/rootfs/usr/share/udhcpc/default.script index 3a59e67e..73e4c78b 100755 --- a/board/common/rootfs/usr/share/udhcpc/default.script +++ b/board/common/rootfs/usr/share/udhcpc/default.script @@ -1,5 +1,9 @@ #!/bin/sh # This script expect a system with resolvconf (openresolv) and iproute2 +# +# For details on the distance adjustment below, please see the following +# section in the Frr documentation on distance + prefence => to metric. +# https://docs.frrouting.org/en/stable-8.0/zebra.html#administrative-distance [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1 @@ -11,6 +15,10 @@ NTPFILE="/run/chrony/dhcp-sources.d/${interface}.sources" [ -n "$subnet" ] || subnet=32 [ -n "$metric" ] || metric=100 +# Distance adjustment to ensure that static routes set by Zebra +# can take precedence over routes learned from DHCP. +metric=$(((5 << 24) + metric)) + # Handle stateful DHCPv6 like DHCPv4 [ -n "$ipv6" ] && ip="$ipv6/128"