From 131c27414545dc6e8f324453d3f458c1bf817021 Mon Sep 17 00:00:00 2001 From: Jingyuan Liang Date: Thu, 19 Jan 2023 08:45:07 +0000 Subject: [PATCH] Remove the use of `route` from install-cni.sh --- scripts/build-toybox.sh | 2 +- scripts/install-cni.sh | 15 +++++++++------ scripts/shell-test.sh | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/build-toybox.sh b/scripts/build-toybox.sh index cb5154520..388c4bb88 100755 --- a/scripts/build-toybox.sh +++ b/scripts/build-toybox.sh @@ -5,7 +5,7 @@ set -exu # Toybox route is "pending" but the TODOs are in add/del; # we're using it for display only so we should be good. # Toybox sh has more TODOs in multiple areas so don't use it. -toys="base64 mktemp mv route timeout" +toys="base64 mktemp mv timeout" cd /toybox-*/ diff --git a/scripts/install-cni.sh b/scripts/install-cni.sh index fac378cb7..dfac699fa 100755 --- a/scripts/install-cni.sh +++ b/scripts/install-cni.sh @@ -212,16 +212,19 @@ else cni_spec=${cni_spec//@ipv6RouteOptional/} fi -# Format of `route` output: -# Destination Gateway Genmask Flags Metric Ref Use Iface -# 0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 ens4 -# 192.168.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens4 +# Format of /proc/net/route: +# Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT +# ens4 00000000 0100A8C0 0003 0 0 100 00000000 0 0 0 +# ens4 0100A8C0 00000000 0005 0 0 100 FFFFFFFF 0 0 0 + +# Note that Destination and Mask are IP represented in hexadecimal in +# little-endian. Regardless of endianness, 00000000 is always 0.0.0.0. # The first grep extracts the default line, and the second grep extracts the -# last field, which is the interface name. We stick to using grep to avoid +# first field, which is the interface name. We stick to using grep to avoid # introducing too many new dependencies. -default_nic=$(route -n | grep -E '^0\.0\.0\.0\s+\S+\s+0\.0\.0\.0' | grep -oE '\S+$') +default_nic=$(grep -E '^\S+\s+00000000\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+00000000\s+' /proc/net/route | grep -oE '^\S+') # Set mtu if [ -f "/sys/class/net/$default_nic/mtu" ]; then diff --git a/scripts/shell-test.sh b/scripts/shell-test.sh index 148f48249..41e814135 100755 --- a/scripts/shell-test.sh +++ b/scripts/shell-test.sh @@ -59,7 +59,7 @@ run_test inotify_cmd inotify / '' /bin/cat /dev/null >/dev/null && pass || fail run_test default_nic_mtu -[[ -f "/sys/class/net/$(route -n | grep -E '^0\.0\.0\.0\s+\S+\s+0\.0\.0\.0' | grep -oE '\S+$')/mtu" ]] && pass || fail +[[ -f "/sys/class/net/$(grep -E '^\S+\s+00000000\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+00000000\s+' /proc/net/route | grep -oE '^\S+')/mtu" ]] && pass || fail run_test mktemp_cmd [[ -f "$(mktemp /tmp.XXXXXX)" ]] && pass || fail