2018-04-17 07:27:15 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2021-02-12 14:01:56 +00:00
|
|
|
# Copyright (C) 2018-2021 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
|
2018-11-27 14:21:47 +00:00
|
|
|
# Released under GPL 3. See LICENSE for the full terms.
|
2018-04-17 07:27:15 +00:00
|
|
|
|
|
|
|
START=5
|
|
|
|
|
|
|
|
USE_PROCD=1
|
|
|
|
|
2018-08-23 12:52:09 +00:00
|
|
|
omr_intf_del() {
|
2020-05-25 12:01:25 +00:00
|
|
|
[ -z "$1" ] && return
|
2018-08-23 12:52:09 +00:00
|
|
|
uci -q delete openmptcprouter.$1
|
|
|
|
}
|
2019-07-23 15:45:44 +00:00
|
|
|
|
|
|
|
omr_intf_check() {
|
|
|
|
[ "$(uci -q get network.$1)" = "" ] && omr_intf_del $1
|
|
|
|
}
|
|
|
|
|
2018-08-23 12:52:09 +00:00
|
|
|
omr_intf_set() {
|
2020-07-03 17:12:42 +00:00
|
|
|
local device
|
|
|
|
local ifname
|
2018-09-03 07:54:38 +00:00
|
|
|
config_get ifname "$1" ifname
|
2020-09-04 19:57:49 +00:00
|
|
|
config_get device "$1" device
|
2020-10-30 20:07:03 +00:00
|
|
|
config_get type "$1" type
|
2020-07-03 17:12:42 +00:00
|
|
|
|
2020-10-19 14:20:53 +00:00
|
|
|
[ -z "$ifname" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]')
|
|
|
|
|
2020-10-30 20:07:03 +00:00
|
|
|
if [ "$type" != "macvlan" ] && [ -n "$ifname" ] && [ -f /sys/class/net/${ifname}/device/uevent ]; then
|
2020-09-04 19:57:49 +00:00
|
|
|
devicepath=$(readlink -f /sys/class/net/${ifname})
|
2020-11-27 18:59:28 +00:00
|
|
|
if [ -n "$devicepath" ] && [ "$(echo ${devicepath} | grep virtual)" = "" ] && [ "$(cat /sys/class/net/${ifname}/device/uevent | grep PRODUCT)" != "" ] && [ "$(cat /sys/class/net/${ifname}/device/uevent | grep PCI_SLOT_NAME)" = "" ]; then
|
2021-01-29 13:31:44 +00:00
|
|
|
mac=""
|
|
|
|
if [ -f /sys/class/net/${ifname}/address ]; then
|
|
|
|
mac="$(cat /sys/class/net/${ifname}/address | tr -d '\n')"
|
|
|
|
fi
|
|
|
|
uci -q set network.$1.modalias="$(cat /sys/class/net/${ifname}/device/uevent | grep MODALIAS | cut -d '=' -f2 | tr -d '\n')-$mac"
|
2020-09-04 19:57:49 +00:00
|
|
|
uci -q set network.$1.product="$(cat /sys/class/net/${ifname}/device/uevent | grep PRODUCT | cut -d '=' -f2 | tr -d '\n')"
|
2020-11-27 18:59:28 +00:00
|
|
|
elif [ -n "$devicepath" ] && ([ "$(echo ${devicepath} | grep virtual)" != "" ] || [ "$(echo ${devicepath} | grep virtual)" = "" ] && [ "$(cat /sys/class/net/${ifname}/device/uevent | grep PRODUCT)" = "" ] || [ "$(cat /sys/class/net/${ifname}/device/uevent | grep PCI_SLOT_NAME)" != "" ] || [ "$(cat /sys/class/net/${ifname}tmp/device/uevent)" != "" ]); then
|
2020-09-04 19:57:49 +00:00
|
|
|
uci -q delete network.$1.device
|
|
|
|
uci -q delete network.$1.modalias
|
2020-11-27 18:59:28 +00:00
|
|
|
uci -q delete network.$1.product
|
2020-09-04 19:57:49 +00:00
|
|
|
fi
|
2020-11-27 18:59:28 +00:00
|
|
|
elif [ "$type" != "macvlan" ] && [ -n "$device" ] && [ -f /sys/bus/usb-serial/devices/${devicename}/device/uevent ] && [ "$(cat /sys/class/net/${ifname}/device/uevent | grep PRODUCT)" != "" ]; then
|
2021-01-29 13:31:44 +00:00
|
|
|
mac=""
|
|
|
|
if [ -f /sys/class/net/${ifname}/address ]; then
|
|
|
|
mac="$(cat /sys/class/net/${ifname}/address | tr -d '\n')"
|
|
|
|
fi
|
|
|
|
uci -q set network.$1.modalias="$(cat /sys/bus/usb-serial/devices/${devicename}/device/uevent | grep MODALIAS | cut -d '=' -f2 | tr -d '\n')-$mac"
|
2020-09-10 19:02:53 +00:00
|
|
|
uci -q set network.$1.product="$(cat /sys/bus/usb-serial/devices/${devicename}/device/uevent | grep PRODUCT | cut -d '=' -f2 | tr -d '\n')"
|
2021-01-08 09:46:06 +00:00
|
|
|
else
|
|
|
|
uci -q delete network.$1.modalias
|
|
|
|
uci -q delete network.$1.product
|
2020-09-04 19:57:49 +00:00
|
|
|
fi
|
2021-01-08 09:46:06 +00:00
|
|
|
}
|
2020-07-03 17:12:42 +00:00
|
|
|
|
2021-01-08 09:46:06 +00:00
|
|
|
omr_set_settings() {
|
2021-01-25 08:33:02 +00:00
|
|
|
local device
|
|
|
|
local ifname
|
|
|
|
local multipath
|
|
|
|
config_get multipath "$1" multipath
|
|
|
|
config_get ifname "$1" ifname
|
|
|
|
config_get device "$1" device
|
|
|
|
config_get proto "$1" proto
|
|
|
|
config_get type "$1" type
|
2021-02-15 14:35:04 +00:00
|
|
|
config_get ipv6 "$1" ipv6
|
2021-01-25 08:33:02 +00:00
|
|
|
config_get addlatency "$1" addlatency
|
2021-03-18 14:47:19 +00:00
|
|
|
[ -z "$multipath" ] || [ "$multipath" = "off" ] && return
|
|
|
|
[ "$1" = "omrvpn" ] || [ "$1" = "glorytun" ] && return
|
2018-10-01 18:46:24 +00:00
|
|
|
|
2018-08-23 12:52:09 +00:00
|
|
|
uci -q set openmptcprouter.$1=interface
|
2019-08-28 19:07:44 +00:00
|
|
|
uci -q set openmptcprouter.$1.multipath="$multipath"
|
2019-04-18 20:51:49 +00:00
|
|
|
config_get disable_ipv6 settings disable_ipv6 "0"
|
2021-02-15 14:35:04 +00:00
|
|
|
if [ "$disable_ipv6" = "1" ]; then
|
2019-04-18 20:51:49 +00:00
|
|
|
uci -q set network.$1.ipv6=0
|
|
|
|
fi
|
2021-01-25 08:33:02 +00:00
|
|
|
|
|
|
|
[ -z "$addlatency" ] && addlatency=0
|
|
|
|
devicename=$(echo "$device" | cut -d'/' -f3)
|
|
|
|
|
|
|
|
[ -z "$ifname" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]')
|
2021-02-15 14:35:04 +00:00
|
|
|
[ -n "$(echo $ifname | grep '@')" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["device"]')
|
2021-01-25 08:33:02 +00:00
|
|
|
|
|
|
|
if [ -n "$ifname" ]; then
|
2021-02-15 14:35:04 +00:00
|
|
|
if [ "$proto" = "dhcpv6" ] || [ "$ipv6" = "1" ]; then
|
2021-02-12 14:01:56 +00:00
|
|
|
# Change interface name for sysctl in case of VLAN (eth0.2 => eth0/2)
|
|
|
|
ifnamesys=$(echo $ifname | sed 's:\.:/:')
|
|
|
|
sysctl -qw net.ipv6.conf.${ifnamesys}.disable_ipv6=0
|
|
|
|
sysctl -qw net.ipv6.conf.${ifnamesys}.accept_ra=1
|
|
|
|
fi
|
|
|
|
|
2021-01-25 08:33:02 +00:00
|
|
|
if [ "$addlatency" = "0" ] && [ "$(tc qdisc show dev $ifname | grep delay)" != "" ]; then
|
2021-03-18 14:47:19 +00:00
|
|
|
tc qdisc del dev ${ifname} root netem 2>&1 >/dev/null
|
2021-01-25 08:33:02 +00:00
|
|
|
fi
|
|
|
|
if [ "$addlatency" != "0" ]; then
|
|
|
|
if [ "$(tc qdisc show dev $ifname | grep delay)" != "" ]; then
|
2021-03-18 14:47:19 +00:00
|
|
|
tc qdisc add dev ${ifname} root netem delay ${addlatency}ms 2>&1 >/dev/null
|
2021-01-25 08:33:02 +00:00
|
|
|
elif [ "$(tc qdisc show dev $ifname | awk '/delay/ { print $10 }' | sed 's/ms//')" != "$addlatency" ]; then
|
2021-03-18 14:47:19 +00:00
|
|
|
tc qdisc replace dev ${ifname} root netem delay ${addlatency}ms 2>&1 >/dev/null
|
2021-01-25 08:33:02 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-08-23 12:52:09 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 07:27:15 +00:00
|
|
|
start_service() {
|
2020-09-16 17:57:04 +00:00
|
|
|
local scaling_min_freq scaling_max_freq scaling_governor
|
2018-08-27 06:07:34 +00:00
|
|
|
|
2019-07-23 15:45:44 +00:00
|
|
|
config_load openmptcprouter
|
|
|
|
config_foreach omr_intf_check interface
|
2018-08-27 06:07:34 +00:00
|
|
|
config_load network
|
2021-01-08 09:46:06 +00:00
|
|
|
config_foreach omr_set_settings interface
|
2020-07-03 17:12:42 +00:00
|
|
|
uci -q commit network
|
|
|
|
uci -q commit openmptcprouter
|
2018-08-27 06:07:34 +00:00
|
|
|
|
2020-07-03 17:12:42 +00:00
|
|
|
[ -d /sys/devices/system/cpu/cpufreq/policy0 ] && {
|
|
|
|
config_load openmptcprouter
|
|
|
|
config_get scaling_min_freq settings scaling_min_freq
|
|
|
|
[ -n "$scaling_min_freq" ] && {
|
|
|
|
for c in $(ls -d /sys/devices/system/cpu/cpufreq/policy[0-9]*); do
|
|
|
|
echo $scaling_min_freq > $c/scaling_min_freq
|
|
|
|
done
|
|
|
|
}
|
|
|
|
config_get scaling_max_freq settings scaling_max_freq
|
|
|
|
[ -n "$scaling_max_freq" ] && {
|
|
|
|
for c in $(ls -d /sys/devices/system/cpu/cpufreq/policy[0-9]*); do
|
|
|
|
echo $scaling_max_freq > $c/scaling_max_freq
|
|
|
|
done
|
|
|
|
}
|
|
|
|
config_get scaling_governor settings scaling_governor
|
|
|
|
[ -n "$scaling_governor" ] && {
|
|
|
|
for c in $(ls -d /sys/devices/system/cpu/cpufreq/policy[0-9]*); do
|
|
|
|
echo $scaling_governor > $c/scaling_governor
|
|
|
|
done
|
|
|
|
}
|
2018-04-17 07:27:15 +00:00
|
|
|
}
|
2018-05-12 08:07:51 +00:00
|
|
|
# remove sysctl already defined in /etc/sysctl.d/
|
2020-09-17 12:21:48 +00:00
|
|
|
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' -e '/tcp_syn_retries/d' -e '/tcp_fastopen/d' -e '/tcp_retries2/d' -e '/tcp_retries1/d' -e '/ip_default_ttl/d' /etc/sysctl.conf
|
|
|
|
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' -e '/tcp_syn_retries/d' -e '/tcp_fastopen/d' -e '/tcp_retries2/d' -e '/tcp_retries1/d' -e '/ip_default_ttl/d' /etc/sysctl.d/10-default.conf
|
2021-01-04 09:59:07 +00:00
|
|
|
|
2021-03-29 19:28:44 +00:00
|
|
|
if [ "$(uci -q get openmptcprouter.settings.country)" = "china" ] && [ -n "$(uci -q get dhcp.@dnsmasq[0].server | grep '127.0.0.1#5353')" ]; then
|
|
|
|
uci -q batch <<-EOF > /dev/null
|
|
|
|
del_list dhcp.@dnsmasq[0].server='127.0.0.1#5353'
|
|
|
|
add_list dhcp.@dnsmasq[0].server='114.114.114.114'
|
|
|
|
set dhcp.@dnsmasq[0].dnsseccheckunsigned='0'
|
|
|
|
delete dhcp.@dnsmasq[0].dnssec='1'
|
|
|
|
commit dhcp
|
|
|
|
EOF
|
|
|
|
elif [ "$(uci -q get openmptcprouter.settings.country)" = "world" ] && [ -n "$(uci -q get dhcp.@dnsmasq[0].server | grep '114.114.114.114')" ]; then
|
|
|
|
uci -q batch <<-EOF > /dev/null
|
|
|
|
add_list dhcp.@dnsmasq[0].server='127.0.0.1#5353'
|
|
|
|
del_list dhcp.@dnsmasq[0].server='114.114.114.114'
|
|
|
|
set dhcp.@dnsmasq[0].dnsseccheckunsigned='1'
|
|
|
|
set dhcp.@dnsmasq[0].dnssec='1'
|
|
|
|
commit dhcp
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2021-01-04 09:59:07 +00:00
|
|
|
if [ "$(uci -q get rpcd.@rpcd[0].socket)" != "/var/run/ubus/ubus.sock" ]; then
|
|
|
|
uci -q batch <<-EOF >/dev/null
|
|
|
|
set rpcd.@rpcd[0].socket='/var/run/ubus/ubus.sock'
|
|
|
|
commit rpcd
|
|
|
|
EOF
|
|
|
|
/etc/init.d/rpcd restart 2>&1 >/dev/null
|
|
|
|
fi
|
2021-01-08 09:46:06 +00:00
|
|
|
}
|
2021-01-04 09:59:07 +00:00
|
|
|
|
2021-01-08 09:46:06 +00:00
|
|
|
stop_service() {
|
|
|
|
config_load network
|
|
|
|
config_foreach omr_intf_set interface
|
|
|
|
uci -q commit network
|
|
|
|
uci -q commit openmptcprouter
|
2018-04-17 07:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reload_service() {
|
|
|
|
rc_procd start_service
|
|
|
|
return 0
|
2020-02-27 21:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service_triggers() {
|
|
|
|
procd_add_reload_trigger "openmptcprouter" "network"
|
2018-04-17 07:27:15 +00:00
|
|
|
}
|