Skip to content

Commit 1442be6

Browse files
committed
fix: destroy stale netd network before creating to avoid ndc conflict
1 parent 94a9e6e commit 1442be6

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

os-image/android/network.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ if [ -z "$GW" ]; then
9292
log -t cocoon-network "WARN: no gateway found; skip ndc setup"
9393
else
9494
# Register network with netd so it owns the routes and policy tables.
95+
# Destroy first in case a previous run left a stale network registration.
96+
ndc network destroy "$NETID" 2>/dev/null
9597
ndc network create "$NETID" 2>/dev/null
9698
ndc network interface add "$NETID" "$IFACE" 2>/dev/null
99+
SUBNET="$(ip -4 route show table main 2>/dev/null | sed -n "s#^\([0-9.][0-9./]*\) dev ${IFACE} .*#\1#p" | head -1)"
100+
[ -n "$SUBNET" ] && ndc network route add "$NETID" "$IFACE" "$SUBNET" 2>/dev/null
97101
ndc network route add "$NETID" "$IFACE" 0.0.0.0/0 "$GW" 2>/dev/null
98-
SRC="$(iface_src)"
99-
if [ -n "$SRC" ]; then
100-
# Add subnet route so netd can resolve L2 for local destinations.
101-
SUBNET="$(ip -4 route show table main 2>/dev/null | sed -n "s#^\([0-9.][0-9./]*\) dev ${IFACE} .*#\1#p" | head -1)"
102-
[ -n "$SUBNET" ] && ndc network route add "$NETID" "$IFACE" "$SUBNET" 2>/dev/null
103-
fi
104102
ndc network default set "$NETID" 2>/dev/null
105103
ndc network permission user set NETWORK "$NETID" 2>/dev/null
106104
fi

0 commit comments

Comments
 (0)