small-package/luci-app-easymesh/root/etc/init.d/easymesh

262 lines
7.5 KiB
Plaintext
Raw Normal View History

2021-09-05 16:50:22 +08:00
#!/bin/sh /etc/rc.common
START=99
2021-12-10 09:04:39 +08:00
STOP=70
2021-09-05 16:50:22 +08:00
2021-12-21 09:08:01 +08:00
load_easymesh_config() {
enable=$(uci -q get easymesh.config.enabled)
mesh_bat0=$(uci -q get network.bat0)
ap_mode=$(uci -q get easymesh.config.ap_mode)
lan=$(uci -q get network.lan.ifname)
ipaddr=$(uci -q get easymesh.config.ipaddr)
netmask=$(uci -q get easymesh.config.netmask)
gateway=$(uci -q get easymesh.config.gateway)
dns=$(uci -q get easymesh.config.dns)
ap_ipaddr=$(uci -q get network.lan.ipaddr)
ap_ipaddr1=$(sed -n '1p' /etc/easymesh 2>/dev/null)
apRadio=$(uci -q get easymesh.config.apRadio)
kvr=$(uci -q get easymesh.config.kvr)
2022-02-11 20:29:45 +08:00
iapp=$(uci -q get easymesh.config.iapp)
2021-12-21 09:08:01 +08:00
brlan=$(uci -q get network.@device[0].name)
role=$(uci -q get easymesh.config.role)
}
2021-12-14 20:31:53 +08:00
ap_mode_stop() {
ap_ipaddr=$(uci -q get network.lan.ipaddr)
ap_ipaddr1=$(sed -n '1p' /etc/easymesh 2>/dev/null)
dns1=$(sed -n '2p' /etc/easymesh 2>/dev/null)
2021-10-24 20:29:43 +08:00
if [ "$ap_ipaddr" = "$ap_ipaddr1" ]; then
2021-12-14 20:31:53 +08:00
uci -q delete network.lan.gateway
uci -q del_list network.lan.dns=$dns1
2021-09-05 16:50:22 +08:00
uci commit network
2021-12-14 20:31:53 +08:00
echo "" >/etc/easymesh
2021-09-05 16:50:22 +08:00
2021-12-14 20:31:53 +08:00
uci -q delete dhcp.lan.dynamicdhcp
uci -q delete dhcp.lan.ignore
2021-09-05 16:50:22 +08:00
uci commit dhcp
/etc/init.d/odhcpd enable && /etc/init.d/odhcpd start
/etc/init.d/firewall enable && /etc/init.d/firewall start >/dev/null 2>&1
fi
}
2021-12-14 20:31:53 +08:00
add_wifi_mesh() {
mesh_nwi_mesh=$(uci -q get network.nwi_mesh_${apall})
mesh_apRadio=$(uci -q get wireless.mesh_${apall}.device)
mesh_mesh=$(uci -q get wireless.mesh_${apall})
mesh_id=$(uci -q get easymesh.config.mesh_id)
mobility_domain=$(uci -q get easymesh.config.mobility_domain)
key=$(uci -q get easymesh.config.key)
encryption=$(uci -q get easymesh.config.encryption)
2021-10-24 20:29:43 +08:00
if [ "$mesh_nwi_mesh" != "interface" ]; then
uci set network.nwi_mesh_$apall=interface
uci set network.nwi_mesh_$apall.proto='batadv_hardif'
uci set network.nwi_mesh_$apall.master='bat0'
2021-12-10 09:04:39 +08:00
uci set network.nwi_mesh_$apall.mtu='1536'
2021-10-24 20:29:43 +08:00
uci commit network
fi
2021-10-25 09:03:50 +08:00
if [ "$mesh_mesh" != "wifi-iface" ]; then
2021-10-23 20:29:42 +08:00
uci set wireless.mesh_$apall=wifi-iface
uci set wireless.mesh_$apall.device=$apall
uci set wireless.mesh_$apall.ifname=mesh_${apall}
2021-10-24 20:29:43 +08:00
uci set wireless.mesh_$apall.network=nwi_mesh_${apall}
2021-10-23 20:29:42 +08:00
uci set wireless.mesh_$apall.mode='mesh'
uci set wireless.mesh_$apall.mesh_id=$mesh_id
2021-12-10 09:04:39 +08:00
uci set wireless.mesh_$apall.mesh_fwding='0'
uci set wireless.mesh_$apall.mesh_ttl='1'
uci set wireless.mesh_$apall.mcast_rate='24000'
uci set wireless.mesh_$apall.disabled='0'
2021-10-23 20:29:42 +08:00
uci commit wireless
fi
if [ "$mesh_mesh" = "wifi-iface" ]; then
if [ "$mesh_apRadio" != "$apall" ]; then
uci set wireless.mesh_$apall.device=$apall
uci commit wireless
fi
fi
2021-12-14 20:31:53 +08:00
2021-10-23 20:29:42 +08:00
if [ "$encryption" != 1 ]; then
uci set wireless.mesh_$apall.encryption='none'
uci commit wireless
else
uci set wireless.mesh_$apall.encryption='sae'
uci set wireless.mesh_$apall.key=$key
uci commit wireless
fi
}
2021-10-15 20:30:31 +08:00
2021-12-14 20:31:53 +08:00
add_kvr() {
kvr=$(uci -q get easymesh.config.kvr)
mobility_domain=$(uci -q get easymesh.config.mobility_domain)
2022-02-11 20:29:45 +08:00
iapp=$(uci -q get easymesh.config.iapp)
2021-10-25 09:03:50 +08:00
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
2021-10-24 09:02:41 +08:00
if [ "$kvr" = 1 ]; then
2021-10-25 09:03:50 +08:00
uci set wireless.default_$apall.ieee80211k='1'
uci set wireless.default_$apall.rrm_neighbor_report='1'
uci set wireless.default_$apall.rrm_beacon_report='1'
uci set wireless.default_$apall.ieee80211v='1'
uci set wireless.default_$apall.bss_transition='1'
uci set wireless.default_$apall.ieee80211r='1'
2021-10-26 19:14:12 +08:00
uci set wireless.default_$apall.encryption='psk2+ccmp'
2021-10-25 09:03:50 +08:00
uci set wireless.default_$apall.mobility_domain=$mobility_domain
uci set wireless.default_$apall.ft_over_ds='1'
uci set wireless.default_$apall.ft_psk_generate_local='1'
uci commit wireless
2021-10-23 20:29:42 +08:00
else
2021-12-14 20:31:53 +08:00
uci -q delete wireless.default_$apall.ieee80211k
uci -q delete wireless.default_$apall.ieee80211v
uci -q delete wireless.default_$apall.ieee80211r
2021-10-25 09:03:50 +08:00
uci commit wireless
2021-10-23 20:29:42 +08:00
fi
2022-02-11 20:29:45 +08:00
if [ "$iapp" = 1 ]; then
uci set wireless.default_$apall.iapp_interface='br-lan'
uci commit wireless
else
uci -q delete wireless.default_$apall.iapp_interface
uci commit wireless
fi
2021-10-23 20:29:42 +08:00
done
}
2021-12-14 20:31:53 +08:00
add_dawn() {
kvr=$(uci -q get easymesh.config.kvr)
rssi_val=$(uci -q get easymesh.config.rssi_val)
low_rssi_val=$(uci -q get easymesh.config.low_rssi_val)
2021-10-23 20:29:42 +08:00
if [ "$kvr" = 1 ]; then
uci set dawn.@metric[0].rssi_val=$rssi_val
uci set dawn.@metric[0].low_rssi_val=$low_rssi_val
2021-12-14 20:31:53 +08:00
uci commit dawn
2021-10-23 20:29:42 +08:00
/etc/init.d/dawn enable && /etc/init.d/dawn start
else
/etc/init.d/dawn stop && /etc/init.d/dawn disable
fi
2021-10-15 20:30:31 +08:00
}
2021-10-15 09:05:13 +08:00
2021-12-21 09:08:01 +08:00
set_easymesh() {
load_easymesh_config
2021-12-14 20:31:53 +08:00
if [ "$enable" = 1 ]; then
2021-09-05 16:50:22 +08:00
if [ "$mesh_bat0" != "interface" ]; then
uci set network.bat0=interface
uci set network.bat0.proto='batadv'
uci set network.bat0.routing_algo='BATMAN_IV'
uci set network.bat0.aggregated_ogms='1'
uci set network.bat0.ap_isolation='0'
uci set network.bat0.bonding='0'
2021-12-10 09:04:39 +08:00
uci set network.bat0.bridge_loop_avoidance='1'
uci set network.bat0.distributed_arp_table='1'
2021-09-05 16:50:22 +08:00
uci set network.bat0.fragmentation='1'
2021-12-14 20:31:53 +08:00
# uci set network.bat0.gw_bandwidth='10000/2000'
# uci set network.bat0.gw_sel_class='20'
2021-12-10 09:04:39 +08:00
uci set network.bat0.hop_penalty='30'
uci set network.bat0.isolation_mark='0x00000000/0x00000000'
2021-09-05 16:50:22 +08:00
uci set network.bat0.log_level='0'
2021-12-10 09:04:39 +08:00
uci set network.bat0.multicast_fanout='16'
2021-09-05 16:50:22 +08:00
uci set network.bat0.multicast_mode='1'
uci set network.bat0.network_coding='0'
2021-12-10 09:04:39 +08:00
uci set network.bat0.orig_interval='1000'
2021-09-05 16:50:22 +08:00
2021-12-10 09:04:39 +08:00
if [ "$role" = "server" ]; then
uci set network.bat0.gw_mode='server'
elif [ "$role" = "client" ]; then
uci set network.bat0.gw_mode='client'
else
uci set network.bat0.gw_mode='off'
fi
2021-12-14 20:31:53 +08:00
2021-10-24 09:02:41 +08:00
if [ "$brlan" = "br-lan" ]; then
uci add_list network.@device[0].ports='bat0'
else
uci set network.lan.ifname="${lan} bat0"
fi
2021-09-05 16:50:22 +08:00
uci commit network
fi
2021-10-23 20:29:42 +08:00
if [ "$apRadio" = "all" ]; then
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
add_wifi_mesh
2021-10-15 09:05:13 +08:00
done
else
2021-10-23 20:29:42 +08:00
apall=$apRadio
add_wifi_mesh
2021-10-15 09:05:13 +08:00
fi
2021-10-25 09:03:50 +08:00
add_kvr
2021-10-24 09:02:41 +08:00
add_dawn
2021-09-05 16:50:22 +08:00
2021-12-14 20:31:53 +08:00
if [ "$ap_mode" = 1 ]; then
2021-10-24 20:29:43 +08:00
if [ "$ap_ipaddr" != "$ipaddr" ]; then
2021-09-05 16:50:22 +08:00
uci set network.lan.ipaddr=$ipaddr
uci set network.lan.netmask=$netmask
uci set network.lan.gateway=$gateway
uci add_list network.lan.dns=$dns
uci commit network
2021-12-14 20:31:53 +08:00
echo "" >/etc/easymesh
echo "$ipaddr" >/etc/easymesh
echo "$dns" >>/etc/easymesh
2021-09-05 16:50:22 +08:00
uci set dhcp.lan.dynamicdhcp='0'
2021-10-04 23:13:07 +08:00
uci set dhcp.lan.ignore='1'
2021-12-14 20:31:53 +08:00
uci -q delete dhcp.lan.ra
uci -q delete dhcp.lan.dhcpv6
uci -q delete dhcp.lan.ra_management
2021-09-05 16:50:22 +08:00
uci commit dhcp
/etc/init.d/odhcpd stop && /etc/init.d/odhcpd disable
/etc/init.d/firewall stop && /etc/init.d/firewall disable >/dev/null 2>&1
fi
else
ap_mode_stop
fi
else
if [ "$mesh_bat0" = "interface" ]; then
2021-12-14 20:31:53 +08:00
uci -q delete network.bat0
2021-10-24 09:02:41 +08:00
if [ "$brlan" = "br-lan" ]; then
2021-12-14 20:31:53 +08:00
uci -q del_list network.@device[0].ports='bat0'
2021-10-24 09:02:41 +08:00
else
sed -i 's/ bat0//' /etc/config/network
fi
2021-09-05 16:50:22 +08:00
uci commit network
fi
2021-10-23 20:29:42 +08:00
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
2021-12-14 20:31:53 +08:00
mesh_nwi_mesh=$(uci -q get network.nwi_mesh_${apall})
mesh_mesh=$(uci -q get wireless.mesh_${apall})
2021-10-24 20:29:43 +08:00
if [ "$mesh_nwi_mesh" = "interface" ]; then
2021-12-14 20:31:53 +08:00
uci -q delete network.nwi_mesh_$apall
2021-10-24 20:29:43 +08:00
uci commit network
fi
2021-10-23 20:29:42 +08:00
if [ "$mesh_mesh" = "wifi-iface" ]; then
2021-12-14 20:31:53 +08:00
uci -q delete wireless.mesh_$apall
2021-10-23 20:29:42 +08:00
uci commit wireless
fi
done
2021-10-15 09:05:13 +08:00
2021-10-23 20:29:42 +08:00
add_kvr
add_dawn
2021-09-05 16:50:22 +08:00
2021-12-14 20:31:53 +08:00
if [ "$ap_mode" = 1 ]; then
2021-09-05 16:50:22 +08:00
ap_mode_stop
fi
fi
2021-12-19 09:09:08 +08:00
/etc/init.d/network restart
2021-09-05 16:50:22 +08:00
}
2021-12-21 09:08:01 +08:00
start() {
return 0
}
stop() {
return 0
}
restart() {
set_easymesh
}