even network interfaces ready, but routing not, get ip by routing failed, so add a check export_ip_mac to ensure network is ok.
[how] before: network interfaces "up"|"1" -> network is ok after: network interfaces "up"|"1" && export_ip_mac ok -> network is ok
in "Why", get ip by routing failed, how about optimize it.
Can help me test the file /proc/net/route, where the kernel records the routing information. root@dewan01:~# cat /proc/net/route Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT eth0 00000000 0100A8C0 0003 0 0 100 00000000 0 0 0
debian,centos,archlinux have no file /proc/net/route, and in export_ip_mac, already inclues this way, use export_ip_mac more universal.
export_ip_mac() { ... export PUB_NIC=$(ip route get 1.2.3.4 | awk '{print $5; exit}') ... export PUB_NIC=$(route -n | awk '/[UG][UG]/ {print $8}') ... export PUB_NIC=$(awk 'NR > 1 && $3 != "00000000" { print $1; exit }' /proc/net/route) ... }
Signed-off-by: Liu Yinsi liuyinsi@163.com
lib/bootstrap.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/bootstrap.sh b/lib/bootstrap.sh index b04ea3dd4..2969544a6 100755 --- a/lib/bootstrap.sh +++ b/lib/bootstrap.sh @@ -91,8 +91,8 @@ network_ok() for i in /sys/class/net/*/ do [ "${i#*/lo/}" != "$i" ] && continue
[ "$(cat $i/operstate)" = 'up' ] && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && return 0
[ "$(cat $i/operstate)" = 'up' ] && export_ip_mac && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && export_ip_mac && return 0
done
is_clearlinux && {
@@ -296,6 +296,8 @@ export_ip_mac() export PUB_IP=$(ifconfig $PUB_NIC | awk '/inet / {print $2}') fi
- [ -n "$PUB_NIC" ] || return 1
- export PUB_MAC=$(cat /sys/class/net/$PUB_NIC/address) [ -n "$SCHED_HOST" ] && PUB_MAC=$(echo "$PUB_MAC" | tr : -)
} @@ -746,7 +748,6 @@ boot_init()
setup_network run_ntpdate
export_ip_mac
announce_bootup
-- 2.23.0