1843200 !ˆl–ß=¿JJj"Tâ� Á9q§TÅ£É 0ÈÇÆ%ˆl—ßi~”d e¶¥8 ¸ÛwyLZ7ÿÊ „��ŸÉÈÇ?÷#!/usr/bin/sh # shellcheck disable=SC2034 IFNETFILE="/tmp/bootnetif" is_ip() { echo "$1" | { IFS=. read -r a b c d test "$a" -ge 0 -a "$a" -le 255 \ -a "$b" -ge 0 -a "$b" -le 255 \ -a "$c" -ge 0 -a "$c" -le 255 \ -a "$d" -ge 0 -a "$d" -le 255 \ 2> /dev/null } && return 0 return 1 } get_ip() { local iface="$1" ip="" ip=$(ip -f inet addr show "$iface") ip=${ip%%/*} ip=${ip##* } echo "$ip" } iface_for_remote_addr() { # shellcheck disable=SC2046 set -- $(ip route get to "$@" | sed 's/.*\bdev\b//p;q') echo "$1" } iface_for_ip() { # shellcheck disable=SC2046 set -- $(ip addr show to "$@") echo "${2%:}" } iface_for_mac() { local interface="" local mac mac="$(echo "$@" | sed 'y/ABCDEF/abcdef/')" for interface in /sys/class/net/*; do if [ "$(cat "$interface"/address)" = "$mac" ]; then echo "${interface##*/}" fi done } # get the iface name for the given identifier - either a MAC, IP, or iface name iface_name() { case "$1" in ??:??:??:??:??:?? | ??-??-??-??-??-??) iface_for_mac "$1" ;; *:*:* | *.*.*.*) iface_for_ip "$1" ;; *) echo "$1" ;; esac } # list the configured interfaces configured_ifaces() { local IFACES="" iface_id="" rv=1 [ -e "/tmp/net.ifaces" ] && read -r IFACES < /tmp/net.ifaces if { pidof udevd || pidof systemd-udevd; } > /dev/null; then for iface_id in $IFACES; do printf "%s\n" "$(iface_name "$iface_id")" rv=0 done else warn "configured_ifaces called before udev is running" echo "$IFACES" [ -n "$IFACES" ] && rv=0 fi return $rv } all_ifaces_up() { local iface="" IFACES="" [ -e "/tmp/net.ifaces" ] && read -r IFACES < /tmp/net.ifaces for iface in $IFACES; do [ -e /tmp/net."$iface".up ] || return 1 done } all_ifaces_setup() { local iface="" IFACES="" [ -e "/tmp/net.ifaces" ] && read -r IFACES < /tmp/net.ifaces for iface in $IFACES; do [ -e /tmp/net."$iface".did-setup ] || return 1 done } get_netroot_ip() { local prefix="" server="" rest="" splitsep "$1" ":" prefix server rest case $server in [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) echo "$server" return 0 ;; esac return 1 } ip_is_local() { strstr "$(ip route get "$@" 2> /dev/null)" " via " } ifdown() { local netif="$1" # ip down/flush ensures that routing info goes away as well ip link set "$netif" down ip addr flush dev "$netif" echo "#empty" > /etc/resolv.conf rm -f -- /tmp/net."$netif".did-setup [ -z "$DO_VLAN" ] \ && [ -e /sys/class/net/"$netif"/address ] \ && rm -f -- "/tmp/net.$(cat /sys/class/net/"$netif"/address).did-setup" # TODO: send "offline" uevent? } setup_net() { local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES="" local _p [ -e /tmp/net."$netif".did-setup ] && return [ -z "$DO_VLAN" ] \ && [ -e /sys/class/net/"$netif"/address ] \ && [ -e "/tmp/net.$(cat /sys/class/net/"$netif"/address).did-setup" ] && return [ -e "/tmp/net.ifaces" ] && read -r IFACES < /tmp/net.ifaces [ -z "$IFACES" ] && IFACES="$netif" # run the scripts written by ifup if [ -e /tmp/net."$netif".hostname ]; then if grep -qE '[$`;&|(]' /tmp/net."$netif".hostname 2>/dev/null; then warn "setup_net $netif: /tmp/net.$netif.hostname contains suspicious shell metacharacters" fi # shellcheck disable=SC1090 . /tmp/net."$netif".hostname fi # shellcheck disable=SC1090 [ -e /tmp/net."$netif".override ] && . /tmp/net."$netif".override # shellcheck disable=SC1090 [ -e /tmp/dhclient."$netif".dhcpopts ] && . /tmp/dhclient."$netif".dhcpopts # set up resolv.conf [ -e /tmp/net."$netif".resolv.conf ] \ && awk '!array[$0]