Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Mfw 4007 on network device down, static routes are dropped, but not registered back on device up" #207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sync-settings/files/interface-watcher.init
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ start_service() {
}

stop_service() {
ps | grep "/usr/bin/interface_watcher.sh" | awk '{print $1}' | xargs kill -9 "$1" 2>&1
kill -9 "$(pgrep interface_watcher.sh)"
}
35 changes: 7 additions & 28 deletions sync-settings/files/interface_watcher.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
#!/bin/sh

grab_intf_name() {
interfaces=$(uci show network | grep "$1" | cut -d"." -f2)
interfaces=$(uci show network | grep $1 | cut -d"." -f2)
}

# Monitor ip link status for interfaces.
ip -o monitor link | while read -r index interface status remaining; do
iface=$(printf '%s\n' "$interface" | sed -E 's/(@.*)?:$//')
operstate=$(printf '%s\n' "$remaining" | grep -Eo ' state [^ ]+' | sed 's/^ state //')

# | tr '[:upper:]' '[:lower:]' does not work on busybox atm
grab_intf_name "$iface"
# If iface goes to UP
if [ "$operstate" = "UP" ]; then
action="up"
elif [ "$operstate" = "DOWN" ]; then
action="down"
else
logger -p Error -t "Interface Watch" "Unknown operating state: $operstate"
continue
fi

[ "$operstate" = "UP" ] && ubus call network reload

# For both ipv6 and ipv4
echo "$interfaces" | while read -r intfc; do
# if interface empty string
if [ -z "$intfc" ]; then
continue
fi
# For both ipv6 and ipv4
grab_intf_name "$iface"
echo "$interfaces" | while read -r line; do ifup "$line"; done

# Check intfc actually exists
ubus -S list "network.interface.$intfc" >/dev/null || {
logger -p Debug -t "Interface Watch" "Interface $intfc not found in UBUS networks"
continue
}

ubus call network.interface $action "{ \"interface\" : \"$intfc\" }"
logger -p Info -t "Interface Watch" "Interface $intfc of device $interface changed state to $operstate"
done
fi

logger -t "Interface Watch" "Interface $iface changed state to $operstate"
done

exit 1