Skip to content

Commit

Permalink
Fix device name parsing for MTU discovery when using link scoped devi…
Browse files Browse the repository at this point in the history
…ces (earthly#4233)

This fix is relevant for tun devices, which are common in VPN
implementations. For example, while a "normal" default route may look
like:

default via 192.168.1.1 dev enp1s0 proto dhcp src 192.168.1.123 metric
100

A tun device for a VPN may instead look like:

	default dev tun0 scope link

In the current entrypoint, the device name would be incorrectly parsed
as "link" instead of "tun0". By using sed to find the word after "dev",
the result is more likely to be correct. Sed is used elsewhere in the
entrypoint, so it is already an expected utility.

When the device name is incorrectly parsed, the earthly-buildkitd
container fails with the error:

	cat: can't open '/sys/class/net/link/mtu': No such file or directory
  • Loading branch information
ben-krieger authored Jun 27, 2024
1 parent 43f76e6 commit c7a6f9c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions buildkitd/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ echo "$EARTHLY_GIT_CONFIG" | base64 -d >/root/.gitconfig

#Set up CNI
if [ -z "$CNI_MTU" ]; then
device=$(ip route show | grep default | cut -d' ' -f5 | head -n 1)
device=$(ip route show | grep ^default | head -n 1 | sed 's|.* dev \(\w*\)\s.*|\1|')
CNI_MTU=$(cat /sys/class/net/"$device"/mtu)
export CNI_MTU
fi
Expand Down Expand Up @@ -324,7 +324,7 @@ do
if [ "$OOM_SCORE_ADJ" -ne "0" ]; then
! "$BUILDKIT_DEBUG" || echo "$(date) | $PID($(cat /proc/"$PID"/cmdline)) killed with OOM_SCORE_ADJ=$OOM_SCORE_ADJ" >> /var/log/oom_adj
kill -9 "$PID"
else
else
! "$BUILDKIT_DEBUG" || echo "$(date) | $PID($(cat /proc/"$PID"/cmdline)) was not killed because OOM_SCORE_ADJ was default or not set" >> /var/log/oom_adj
fi
fi
Expand Down

0 comments on commit c7a6f9c

Please sign in to comment.