Skip to content

Commit 3ff09e0

Browse files
committed
Re-done ingress shaping to fix errors, added "auto" option to hostapd wait time
1 parent 70bbe16 commit 3ff09e0

File tree

1 file changed

+90
-125
lines changed

1 file changed

+90
-125
lines changed

routertools

Lines changed: 90 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trap 'trap_ctl' SIGINT SIGTERM
4141

4242
# Initialize variables and language setting for compatibility
4343
LANG=C
44-
version="2.0.0"
44+
version="2.0.1"
4545
error_count=0
4646
crit_count=0
4747
crit_add=0
@@ -476,9 +476,8 @@ initfs(){
476476
echo "# WIRELESS INTERFACE OPTIONS #" >> $f
477477
echo "# Check https://wiki.dd-wrt.com/wiki/index.php/Atheros/ath_wireless_settings for explanations." >> $f
478478
echo "" >> $f
479-
echo "# hostapd_wait_for_secs -> seconds to wait for hostapd to ready interfaces" >> $f
480-
echo "# 15 seconds is a reasonable number. increase this if you use ACS or a lot of virtual interfaces." >> $f
481-
echo "hostapd_wait_for_secs=15 " >> $f
479+
echo "# hostapd_wait_for_secs -> seconds to wait for hostapd to be done. 'auto' tries to automatically detect." >> $f
480+
echo "hostapd_wait_for_secs=auto" >> $f
482481
echo "" >> $f
483482
echo "# wifi_txpower -> transmission power for this interface" >> $f
484483
echo "# can be 'auto' or a number in dBm for fixed power. Auto is usually best." >> $f
@@ -546,7 +545,7 @@ initfs(){
546545
echo "" >> $f
547546
echo "# enable_ipv6 -> a boolean. true only enables ipv6 forwarding on this interface." >> $f
548547
echo "# if you actually want it to work you need radvd or a configured dnsmasq." >> $f
549-
echo "# unless something else in your network does this for you." >> $f
548+
echo "# and manual address addition/routing via scripting." >> $f
550549
echo "enable_ipv6=true" >> $f
551550
echo "" >> $f
552551
echo "# enable_pptp -> a boolean. true inserts the module needed for PPTP. if you are not sure you need it say false here, as the Point to Point Tunneling Protocol is known to be insecure." >> $f
@@ -586,7 +585,7 @@ initfs_daemon_cfg(){
586585
echo "# these options are only valid for the --daemon command" >> $f
587586
echo "" >> $f
588587
echo "# daemon_manage_inet_every -> a number in seconds. the internet watchdog will be executed every this amount of time." >> $f
589-
echo "daemon_manage_inet_every=60" >> $f
588+
echo "daemon_manage_inet_every=50" >> $f
590589
echo "" >> $f
591590
echo "# daemon_manage_wifi_every -> a number in seconds. the wifi watchdog will be executed every this amount of time." >> $f
592591
echo "daemon_manage_wifi_every=40" >> $f
@@ -599,7 +598,7 @@ initfs_daemon_cfg(){
599598
echo "# daemon_ath9k_recalibrate_every -> a number in seconds." >> $f
600599
echo "# if running the wifi daemon and wifi_driver for that interface includes ath9k, ath9k-recalibrate will be run every X seconds." >> $f
601600
echo "# recommended is hourly (3600). Set to 0 to disable." >> $f
602-
echo "daemon_ath9k_recalibrate_every=0" >> $f
601+
echo "daemon_ath9k_recalibrate_every=3600" >> $f
603602
echo "" >> $f
604603

605604
unset f
@@ -1129,6 +1128,7 @@ sqm_disable(){
11291128

11301129
for i in $ifaces; do
11311130
tc qdisc del dev $i root 2>/dev/null
1131+
tc qdisc del dev $i handle ffff: ingress 2>/dev/null
11321132
# FQ-CoDel is a safe alternative
11331133
# if this fails system default (probably none) will stay
11341134
tc qdisc add dev $i root fq_codel 2>/dev/null
@@ -1197,42 +1197,51 @@ sqm_enable(){
11971197

11981198
# Apply qdisc in categories
11991199
for i in $ppp_ifaces; do
1200+
ifnq echo "Applying queue discipline to $i (ethernet interface)"
12001201

12011202
restore_extra_arg=${extra_arg}
12021203

12031204
if [[ $ack_filter_no_ppp == "true" ]]; then
12041205
extra_arg=""
12051206
fi
12061207

1207-
ifb_check=$(echo "$ifb_ifaces" | grep -i "$i")
1208+
ifb_check=$(tc qdisc | grep "ingress" | grep "$i");
12081209

12091210
if [[ "$ifb_check" = "" ]]; then
12101211

12111212
tc qdisc del dev $i root 2>/dev/null
12121213

12131214
if [[ "$sqm_inet_upload" != "" ]]; then
12141215
tc qdisc add dev $i root cake ${diffserv}nat ${overhead}bandwidth "$sqm_inet_upload"mbit $extra_arg
1216+
ifnq echo "Applying queue discipline to $i (ppp interface)"
12151217
else
12161218
tc qdisc add dev $i root cake ${diffserv}nat ${overhead}$extra_arg
1219+
ifnq echo "Applying queue discipline to $i (ppp interface)"
12171220
fi
1218-
1219-
ip link add name ifb$i type ifb
1220-
tc qdisc del dev $i ingress
1221-
tc qdisc add dev $i handle ffff: ingress
1222-
tc qdisc del dev ifb$i root
1221+
1222+
ip link add name ifb$i type ifb 2>/dev/null
1223+
tc qdisc del dev $i ingress 2>/dev/null
1224+
tc qdisc add dev $i handle ffff: ingress 2>/dev/null
1225+
tc qdisc del dev ifb$i root 2>/dev/null
12231226

12241227
if [[ "$sqm_use_overheads" == "true" ]]; then
12251228
overhead="overhead 35 "
12261229
else
12271230
overhead=""
12281231
fi
12291232

1233+
if [[ "$sqm_wash_markings" == "true" ]]; then
1234+
wash="wash"
1235+
else
1236+
wash=""
1237+
fi
1238+
12301239
if [[ "$sqm_inet_download" != "" ]]; then
1231-
tc qdisc add dev ifb$i root cake ${diffserv}nat bandwidth "$sqm_inet_download"mbit ${overhead}split-gso $extra_arg
1232-
ifnq echo "Applying queue discipline to $i (ifb interface)"
1240+
tc qdisc add dev ifb$i root cake ${diffserv}nat $wash bandwidth "$sqm_inet_download"mbit ${overhead}split-gso $extra_arg
1241+
ifnq echo "Applying queue discipline to ifb$i (ifb interface)"
12331242
else
1234-
tc qdisc add dev ifb$i root cake ${diffserv}nat ${overhead}split-gso $extra_arg
1235-
ifnq echo "Applying queue discipline to $i (ifb interface)"
1243+
tc qdisc add dev ifb$i root cake ${diffserv}nat $wash ${overhead}split-gso $extra_arg
1244+
ifnq echo "Applying queue discipline to ifb$i (ifb interface)"
12361245
fi
12371246

12381247
ip link set ifb$i up
@@ -1241,78 +1250,7 @@ sqm_enable(){
12411250
fi
12421251

12431252
extra_arg=${restore_extra_arg}
1244-
done
1245-
1246-
pppe_ifaces=$(tc qdisc | grep -E 'ppp' | grep -v 'ifb' | grep -v 'cake' | grep -v 'ingress' | awk '{printf $5}' )
1247-
ifbe_ifaces=$(tc qdisc | grep -E 'ppp' | grep -i 'ifb' | grep -v 'cake' | awk '{printf $5}')
1248-
1249-
if [[ "$sqm_use_overheads" == "true" ]]; then
1250-
overhead="overhead 35 "
1251-
else
1252-
overhead=""
1253-
fi
1254-
1255-
for i in $ifbe_ifaces; do
1256-
if ! chk_qdisc $i; then
1257-
1258-
for a in $(echo $i | grep -i "$ifb_ifaces"); do
1259-
ifnq echo "Applying queue discipline to $i (ifb interface)"
1260-
# Fix qdisc sometimes disappearing on network changes
1261-
tc qdisc del dev $a root 2>/dev/null
1262-
1263-
if [[ "$sqm_wash_markings" != "true" ]]; then
1264-
if [[ "$sqm_inet_download" != "" ]]; then
1265-
tc qdisc add dev $a root cake ${diffserv}nat ${overhead}bandwidth "$sqm_inet_download"mbit split-gso 2>/dev/null
1266-
else
1267-
tc qdisc add dev $a root cake ${diffserv}nat ${overhead}split-gso 2>/dev/null
1268-
fi
1269-
1270-
elif [[ "$sqm_wash_markings" == "true" ]]; then
1271-
if [[ "$sqm_inet_download" != "" ]]; then
1272-
tc qdisc add dev $a root cake nat bandwidth "$sqm_inet_download"mbit ${overhead}besteffort wash split-gso 2>/dev/null
1273-
1274-
else
1275-
tc qdisc add dev $a root cake nat besteffort ${overhead}wash split-gso 2>/dev/null
1276-
fi
1277-
1278-
fi
1279-
1280-
done
1281-
1282-
fi
1283-
done
1284-
1285-
if [[ "$sqm_use_overheads" == "true" ]]; then
1286-
overhead="overhead 35 "
1287-
else
1288-
overhead=""
1289-
fi
1290-
1291-
for i in $pppe_ifaces; do
1292-
1293-
restore_extra_arg=${extra_arg}
1294-
if [[ $ack_filter_no_ppp == "true" ]]; then
1295-
extra_arg=""
1296-
fi
1297-
1298-
if ! chk_qdisc $i; then
1299-
1300-
for a in $(echo $i | grep -i "$ppp_ifaces"); do
1301-
1302-
# Fix qdisc sometimes disappearing on network changes
1303-
ifnq echo "Applying queue discipline to $i (ppp interface)"
1304-
tc qdisc del dev $a root 2>/dev/null
13051253

1306-
if [[ "$sqm_inet_upload" != "" ]]; then
1307-
tc qdisc add dev $a root cake ${diffserv}nat bandwidth "$sqm_inet_upload"mbit ${overhead}split-gso $extra_arg 2>/dev/null
1308-
else
1309-
tc qdisc add dev $a root cake ${diffserv}nat ${overhead}split-gso $extra_arg 2>/dev/null
1310-
fi
1311-
1312-
done
1313-
fi
1314-
1315-
extra_arg=${restore_extra_arg}
13161254
done
13171255

13181256
if [[ "$sqm_use_overheads" == "true" ]]; then
@@ -1325,48 +1263,52 @@ sqm_enable(){
13251263

13261264
if ! chk_qdisc $i ; then
13271265

1328-
ifnq echo "Applying queue discipline to $i (ethernet interface)"
1266+
if [[ "$sqm_enable_ifb_on_ethernet" == "true" ]]; then
13291267

1330-
if [[ "$sqm_enable_ifb_on_ethernet" == "true" ]]; then
1268+
restore_extra_arg=${extra_arg}
13311269

1332-
ifb_check=$(echo "$ifb_ifaces" | grep -i "$i")
1333-
if [[ "$ifb_check" = "" ]]; then
1334-
tc qdisc del dev $i root 2>/dev/null
1270+
ifb_check=$(tc qdisc | grep "ingress" | grep "$i");
13351271

1336-
if [[ "$sqm_inet_upload" != "" ]]; then
1337-
tc qdisc add dev $i root cake ${diffserv}nat bandwidth "$sqm_inet_upload"mbit ${overhead}split-gso $extra_arg
1338-
else
1339-
tc qdisc add dev $i root cake ${diffserv}nat split-gso ${overhead}$extra_arg
1340-
fi
1341-
1342-
ip link add name ifb$i type ifb
1343-
tc qdisc del dev $i ingress
1344-
tc qdisc add dev $i handle ffff: ingress
1345-
tc qdisc del dev ifb$i root
1272+
if [[ "$ifb_check" = "" ]]; then
13461273

1347-
if [[ "$sqm_wash_markings" != "true" ]]; then
1274+
tc qdisc del dev $i root 2>/dev/null
13481275

1349-
if [[ "$sqm_inet_download" != "" ]]; then
1350-
tc qdisc add dev ifb$i root cake ${diffserv}nat bandwidth "$sqm_inet_download"mbit ${overhead}split-gso
1351-
else
1352-
tc qdisc add dev ifb$i root cake ${diffserv}nat split-gso ${overhead}dual-dsthost
1353-
fi
1276+
if [[ "$sqm_inet_upload" != "" ]]; then
1277+
tc qdisc add dev $i root cake ${diffserv}nat ${overhead}bandwidth "$sqm_inet_upload"mbit $extra_arg
1278+
ifnq echo "Applying queue discipline to $i (ethernet interface)"
1279+
else
1280+
tc qdisc add dev $i root cake ${diffserv}nat ${overhead}$extra_arg
1281+
ifnq echo "Applying queue discipline to $i (ethernet interface)"
1282+
fi
1283+
1284+
ip link add name ifb$i type ifb 2>/dev/null
1285+
tc qdisc del dev $i ingress 2>/dev/null
1286+
tc qdisc add dev $i handle ffff: ingress 2>/dev/null
1287+
tc qdisc del dev ifb$i root 2>/dev/null
1288+
1289+
if [[ "$sqm_wash_markings" == "true" ]]; then
1290+
wash="wash"
1291+
else
1292+
wash=""
1293+
fi
13541294

1355-
elif [[ "$sqm_wash_markings" == "true" ]]; then
1295+
if [[ "$sqm_inet_download" != "" ]]; then
1296+
tc qdisc add dev ifb$i root cake ${diffserv}nat $wash bandwidth "$sqm_inet_download"mbit ${overhead}split-gso $extra_arg
1297+
ifnq echo "Applying queue discipline to ifb$i (ifb interface)"
1298+
else
1299+
tc qdisc add dev ifb$i root cake ${diffserv}nat $wash ${overhead}split-gso $extra_arg
1300+
ifnq echo "Applying queue discipline to ifb$i (ifb interface)"
1301+
fi
13561302

1357-
if [[ "$sqm_inet_download" != "" ]]; then
1358-
tc qdisc add dev ifb$i root cake nat bandwidth "$sqm_inet_download"mbit split-gso ${overhead}besteffort wash
1359-
else
1360-
tc qdisc add dev ifb$i root cake nat split-gso besteffort wash ${overhead}dual-dsthost
1361-
fi
1303+
ip link set ifb$i up
1304+
tc filter add dev $i parent ffff: protocol all prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb$i
13621305

1363-
fi
1306+
fi
13641307

1365-
ip link set ifb$i up
1366-
tc filter add dev $i parent ffff: protocol all prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb$i
1367-
fi
1308+
extra_arg=${restore_extra_arg}
1309+
13681310
else
1369-
1311+
ifnq echo "Applying queue discipline to $i (ethernet interface)"
13701312
tc qdisc del dev $i root 2>/dev/null
13711313
tc qdisc add dev $i root cake ${diffserv}nat ${overhead}split-gso $extra_arg
13721314

@@ -1473,6 +1415,10 @@ sqm_enable(){
14731415
ifv echo "Your kernel does not support either BBRv1 or BBRv2, or the modules aren't loaded. Keeping default congestion control."
14741416
fi
14751417
fi
1418+
else
1419+
if [[ $(sysctl net.ipv4.tcp_congestion_control | grep -i bbr | wc -l) -gt 0 ]]; then
1420+
sysctl net.ipv4.tcp_congestion_control=cubic
1421+
fi
14761422
fi
14771423

14781424

@@ -1663,7 +1609,8 @@ ap_start(){
16631609
getphy $i || crit_error "Couldn't get a phy number for interface $i even after trying twice, this usually means your network card isn't initialized by the driver yet."
16641610

16651611
# Execute hostapd
1666-
hostapd /etc/routertools.d/wifi-access-points/${i}_hostapd.conf &
1612+
rm /var/log/hostapd_$i.log
1613+
hostapd /etc/routertools.d/wifi-access-points/${i}_hostapd.conf > /var/log/hostapd_$i.log &
16671614
hostapd_pid=$!
16681615

16691616
echo "$hostapd_pid" > /dev/shm/hostapd_pid_$i
@@ -1673,10 +1620,29 @@ ap_start(){
16731620
ifv echo "storing hostapd pid in /dev/shm/hostapd_pid_$i"
16741621
ifv echo "hostapd pid for $i -> $hostapd_pid"
16751622

1676-
echo "Waiting $hostapd_wait_for_secs seconds for hostapd to be ready."
1677-
sleep $hostapd_wait_for_secs
1623+
if [[ "$hostapd_wait_for_secs" == "auto" ]]; then
1624+
# timeouts in a minute
1625+
half_seconds=0
1626+
1627+
while [[ $half_seconds -lt 120 ]]; do
1628+
1629+
check_done=$(cat /var/log/hostapd_$i.log | grep -c "AP-ENABLED")
1630+
1631+
if [[ $check_done -gt 0 ]]; then
1632+
echo "hostapd is ready, waited $((half_seconds / 2)) seconds."
1633+
break
1634+
fi
1635+
1636+
sleep 0.5
1637+
half_seconds=$((half_seconds + 1))
1638+
done
1639+
1640+
else
1641+
echo "Waiting $hostapd_wait_for_secs seconds for hostapd to be ready (noauto)."
1642+
sleep $hostapd_wait_for_secs
1643+
fi
16781644

1679-
setup_ap_networking $i || error "An error occourred trying to set up network sharing."
1645+
setup_ap_networking $i || error "An error occourred trying to set up AP networking."
16801646
setup_ap_helpers $i
16811647

16821648
if [[ "$wifi_disable_cck" == "true" ]]; then
@@ -2361,7 +2327,6 @@ import_addresses(){
23612327

23622328
}
23632329

2364-
# Shorter, faster and less precise internet check with hardcoded values and returns 1 or 0
23652330
check_inet_short(){
23662331

23672332
local bad_dns_1=0

0 commit comments

Comments
 (0)