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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-09-26 15:49:45 +02:00
parent fd8826c3f1
commit cc8e31f74f
2 changed files with 20 additions and 3 deletions
@@ -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)
@@ -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"