-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFreshJR_QOS.sh
2396 lines (2218 loc) · 103 KB
/
FreshJR_QOS.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
##FreshJR_QOS
version=8.8
release=03/07/2019
#Copyright (C) 2017-2019 FreshJR - All Rights Reserved
#Tested with ASUS AC-68U, FW384.9, using Adaptive QOS with Manual Bandwidth Settings
# Script Changes Unidentified traffic destination away from "Defaults" into "Others"
# Script Changes HTTPS traffic destination away from "Net Control" into "Web Surfing"
# Script Changes Guaranteed Bandwidth per QOS category into logical percentages of upload and download.
# Script Repurposes "Defaults" to contain "Game Downloads"
# "Game Downloads" moved into 6th position
# "Lowest Defined" moved into 7th position
#Script includes misc hardcoded rules
# (Wifi Calling) - UDP traffic on remote ports 500 & 4500 moved into VOIP
# (Facetime) - UDP traffic on local ports 16384 - 16415 moved into VOIP
# (Usenet) - TCP traffic on remote ports 119 & 563 moved into Downloads
# (Gaming) - Gaming TCP traffic from remote ports 80 & 443 moved into Game Downloads.
# (Snapchat) - Moved into Others
# (Speedtest.net) - Moved into Downloads
# (Google Play) - Moved into Downloads
# (Apple AppStore)- Moved into Downloads
# (Advertisement) - Moved into Downloads
# (VPN Fix) - Router VPN Client upload traffic moved into Downloads instead of whitelisted
# (VPN Fix) - Router VPN Client download traffic moved into Downloads instead of showing up in Uploads
# (Gaming Manual) - Unidentified traffic for specified devices, not originating from ports 80/443, moved into "Gaming"
#
# Gaming traffic originating from ports 80 & 443 is primarily downloads & patches (some lobby/login protocols mixed within)
# Manually configurable rule will take untracked traffic, not originating from 80/443, for specified devices and place it into Gaming
# Use of this gaming rule REQUIRES devices to have a continuous static ip assignment && this range needs to be defined in the script
#
# Custom rules can be created within the WebUI OR by running the -rules command:
# (custom rules): /jffs/scripts/FreshJR_QOS -rules
#
# Default bandwidth allocation per category can be adjusted via WebUI OR -rates command:
# (custom rates): /jffs/scripts/FreshJR_QOS -rates
#
##For discussion visit this thread:
## https://www.snbforums.com/threads/release-freshjr-adaptive-qos-improvements-custom-rules-and-inner-workings.36836/
## https://github.com/FreshJR07/FreshJR_QOS (Source Code + Backup Link)
#
##License
## FreshJR_QOS is free to use under the GNU General Public License, version 3 (GPL-3.0).
## https://opensource.org/licenses/GPL-3.0
#################### MODIFY BELOW WITH CAUTION #####################
#################### MODIFY BELOW WITH CAUTION #####################
#
### IF YOU MANUALLY ADD RULES TO AREA BELOW THEN KEEP IN MIND THAT YOUR CHANGES WILL TAKE EFFECT BUT WILL NOT BE REFLECTED UNDER THE TRACKED CONNECTIONS SECTION OF THE WEBUI.
### FOR HARDCODED CHANGES TO BE REFLECTED IN TRACKED CONNECTIONS SECTION OF THE WEBUI THEN YOU ALSO HAVE TO MODIFY THE CORRESPONDING JAVASCRIPT CODE IN /jffs/scripts/FreshJR_QoS_Stats.asp
### INSTEAD OF HARDCODED CHANGES (legacy method) YOU CAN USE THE SCRIPTS -RULES COMMAND OR ENTER THE WEBUI PAGE FOR CREATING RULES AND THOSE CHANGES WILL BE REFLECTED IN THE TRACKED CONNECTIONS TABLE.
#
#################### MODIFY BELOW WITH CAUTION #####################
#################### MODIFY BELOW WITH CAUTION #####################
iptable_down_rules() {
echo "Applying - Iptable Down Rules"
##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES START HERE -- legacy method
iptables -D POSTROUTING -t mangle -o br0 -p udp -m multiport --sports 500,4500 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Wifi Calling - (All incoming traffic from WAN source ports 500 & 4500 --> VOIP )
iptables -A POSTROUTING -t mangle -o br0 -p udp -m multiport --sports 500,4500 -j MARK --set-mark ${VOIP_mark_down}
iptables -D POSTROUTING -t mangle -o br0 -p udp --dport 16384:16415 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Facetime - (All incoming traffic to LAN destination ports 16384-16415 --> VOIP )
iptables -A POSTROUTING -t mangle -o br0 -p udp --dport 16384:16415 -j MARK --set-mark ${VOIP_mark_down}
iptables -D POSTROUTING -t mangle -o br0 -p tcp -m multiport --sports 119,563 -j MARK --set-mark ${Downloads_mark_down} &> /dev/null #Usenet - (All incoming traffic from WAN source ports 119 & 563 --> Downloads )
iptables -A POSTROUTING -t mangle -o br0 -p tcp -m multiport --sports 119,563 -j MARK --set-mark ${Downloads_mark_down}
iptables -D POSTROUTING -t mangle -o br0 -m mark --mark 0x40000000/0xc0000000 -j MARK --set-xmark 0x80000000/0xC0000000 &> /dev/null #VPN Fix - (Fixes download traffic showing up in upload section when router is acting as a VPN Client)
iptables -A POSTROUTING -t mangle -o br0 -m mark --mark 0x40000000/0xc0000000 -j MARK --set-xmark 0x80000000/0xC0000000
iptables -D POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp -m multiport --sports 80,443 -j MARK --set-mark ${Default_mark_down} &> /dev/null #Gaming - (Incoming "Gaming" traffic from WAN source ports 80 & 443 --> Defaults//GameDownloads)
iptables -A POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp -m multiport --sports 80,443 -j MARK --set-mark ${Default_mark_down}
##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES END HERE -- legacy method
if [ "$( echo $gameCIDR | tr -cd '.' | wc -c )" -eq "3" ] ; then
iptables -D POSTROUTING -t mangle -o br0 -d $gameCIDR -m mark --mark 0x80000000/0x8000ffff -p tcp -m multiport ! --sports 80,443 -j MARK --set-mark ${Gaming_mark_down} &> /dev/null #Gaming - (Incoming "Unidentified" TCP traffic, for devices specified, not from WAN source ports 80 & 443 --> Gaming)
iptables -A POSTROUTING -t mangle -o br0 -d $gameCIDR -m mark --mark 0x80000000/0x8000ffff -p tcp -m multiport ! --sports 80,433 -j MARK --set-mark ${Gaming_mark_down}
iptables -D POSTROUTING -t mangle -o br0 -d $gameCIDR -m mark --mark 0x80000000/0x8000ffff -p udp -m multiport ! --sports 80,443 -j MARK --set-mark ${Gaming_mark_down} &> /dev/null #Gaming - (Incoming "Unidentified" UDP traffic, for devices specified, not from WAN source ports 80 & 443 --> Gaming)
iptables -A POSTROUTING -t mangle -o br0 -d $gameCIDR -m mark --mark 0x80000000/0x8000ffff -p udp -m multiport ! --sports 80,443 -j MARK --set-mark ${Gaming_mark_down}
fi
if ! [ -z "$ip1_down" ] ; then #Script Interactively Defined Rule 1
if [ "$(echo ${ip1_down} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o br0 ${ip1_down//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip1_down//both/tcp}
iptables -D POSTROUTING -t mangle -o br0 ${ip1_down//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip1_down//both/udp}
else
iptables -D POSTROUTING -t mangle -o br0 ${ip1_down} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip1_down}
fi
fi
if ! [ -z "$ip2_down" ] ; then #Script Interactively Defined Rule 2
if [ "$(echo ${ip2_down} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o br0 ${ip2_down//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip2_down//both/tcp}
iptables -D POSTROUTING -t mangle -o br0 ${ip2_down//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip2_down//both/udp}
else
iptables -D POSTROUTING -t mangle -o br0 ${ip2_down} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip2_down}
fi
fi
if ! [ -z "$ip3_down" ] ; then #Script Interactively Defined Rule 3
if [ "$(echo ${ip3_down} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o br0 ${ip3_down//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip3_down//both/tcp}
iptables -D POSTROUTING -t mangle -o br0 ${ip3_down//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip3_down//both/udp}
else
iptables -D POSTROUTING -t mangle -o br0 ${ip3_down} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip3_down}
fi
fi
if ! [ -z "$ip4_down" ] ; then #Script Interactively Defined Rule 4
if [ "$(echo ${ip4_down} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o br0 ${ip4_down//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip4_down//both/tcp}
iptables -D POSTROUTING -t mangle -o br0 ${ip4_down//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip4_down//both/udp}
else
iptables -D POSTROUTING -t mangle -o br0 ${ip4_down} &> /dev/null
iptables -A POSTROUTING -t mangle -o br0 ${ip4_down}
fi
fi
}
iptable_up_rules(){
#wan="ppp0" ## WAN interface over-ride for upload traffic if automatic detection is not working properly
echo "Applying - Iptable Up Rules ($wan)"
##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES START HERE -- legacy method
iptables -D POSTROUTING -t mangle -o $wan -p udp -m multiport --dports 500,4500 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Wifi Calling - (All outgoing traffic to WAN destination ports 500 & 4500 --> VOIP )
iptables -A POSTROUTING -t mangle -o $wan -p udp -m multiport --dports 500,4500 -j MARK --set-mark ${VOIP_mark_up}
iptables -D POSTROUTING -t mangle -o $wan -p udp --sport 16384:16415 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Facetime - (All outgoing traffic from LAN source ports 16384-16415 --> VOIP )
iptables -A POSTROUTING -t mangle -o $wan -p udp --sport 16384:16415 -j MARK --set-mark ${VOIP_mark_up}
iptables -D POSTROUTING -t mangle -o $wan -p tcp -m multiport --dports 119,563 -j MARK --set-mark ${Downloads_mark_up} &> /dev/null #Usenet - (All outgoing traffic to WAN destination ports 119 & 563 --> Downloads )
iptables -A POSTROUTING -t mangle -o $wan -p tcp -m multiport --dports 119,563 -j MARK --set-mark ${Downloads_mark_up}
iptables -D OUTPUT -t mangle -o $wan -p udp -m multiport ! --dports 53,123 -j MARK --set-mark ${Downloads_mark_up} &> /dev/null #VPN Fix - (Fixes upload traffic not detected when the router is acting as a VPN Client)
iptables -A OUTPUT -t mangle -o $wan -p udp -m multiport ! --dports 53,123 -j MARK --set-mark ${Downloads_mark_up}
iptables -D OUTPUT -t mangle -o $wan -p tcp -m multiport ! --dports 53,123 -j MARK --set-mark ${Downloads_mark_up} &> /dev/null #VPN Fix - (Fixes upload traffic not detected when the router is acting as a VPN Client)
iptables -A OUTPUT -t mangle -o $wan -p tcp -m multiport ! --dports 53,123 -j MARK --set-mark ${Downloads_mark_up}
iptables -D POSTROUTING -t mangle -o $wan -m mark --mark 0x40080000/0xc03f0000 -p tcp -m multiport --sports 80,443 -j MARK --set-mark ${Default_mark_up} &> /dev/null #Gaming - (Outgoing "Gaming" traffic to WAN destinations ports 80 & 443 --> Defaults//GameDownloads)
iptables -A POSTROUTING -t mangle -o $wan -m mark --mark 0x40080000/0xc03f0000 -p tcp -m multiport --sports 80,443 -j MARK --set-mark ${Default_mark_up}
##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES END HERE -- legacy method
if [ "$( echo $gameCIDR | tr -cd '.' | wc -c )" -eq "3" ] ; then
iptables -D POSTROUTING -t mangle -o $wan -s $gameCIDR -m mark --mark 0x40000000/0x4000ffff -p tcp -m multiport ! --dports 80,443 -j MARK --set-mark ${Gaming_mark_up} &> /dev/null #Gaming - (Outgoing "Unidentified" TCP traffic, for devices specified, not to WAN destination ports 80 & 443 --> Gaming)
iptables -A POSTROUTING -t mangle -o $wan -s $gameCIDR -m mark --mark 0x40000000/0x4000ffff -p tcp -m multiport ! --dports 80,443 -j MARK --set-mark ${Gaming_mark_up}
iptables -D POSTROUTING -t mangle -o $wan -s $gameCIDR -m mark --mark 0x40000000/0x4000ffff -p udp -m multiport ! --dports 80,443 -j MARK --set-mark ${Gaming_mark_up} &> /dev/null #Gaming - (Outgoing "Unidentified" UDP traffic, for devices specified, not to WAN destination ports 80 & 443 --> Gaming)
iptables -A POSTROUTING -t mangle -o $wan -s $gameCIDR -m mark --mark 0x40000000/0x4000ffff -p udp -m multiport ! --dports 80,443 -j MARK --set-mark ${Gaming_mark_up}
fi
if ! [ -z "$ip1_up" ] ; then #Script Interactively Defined Rule 1
if [ "$(echo ${ip1_up} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o $wan ${ip1_up//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip1_up//both/tcp}
iptables -D POSTROUTING -t mangle -o $wan ${ip1_up//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip1_up//both/udp}
else
iptables -D POSTROUTING -t mangle -o $wan ${ip1_up} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip1_up}
fi
fi
if ! [ -z "$ip2_up" ] ; then #Script Interactively Defined Rule 2
if [ "$(echo ${ip2_up} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o $wan ${ip2_up//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip2_up//both/tcp}
iptables -D POSTROUTING -t mangle -o $wan ${ip2_up//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip2_up//both/udp}
else
iptables -D POSTROUTING -t mangle -o $wan ${ip2_up} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip2_up}
fi
fi
if ! [ -z "$ip3_up" ] ; then #Script Interactively Defined Rule 3
if [ "$(echo ${ip3_up} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o $wan ${ip3_up//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip3_up//both/tcp}
iptables -D POSTROUTING -t mangle -o $wan ${ip3_up//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip3_up//both/udp}
else
iptables -D POSTROUTING -t mangle -o $wan ${ip3_up} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip3_up}
fi
fi
if ! [ -z "$ip4_up" ] ; then #Script Interactively Defined Rule 4
if [ "$(echo ${ip4_up} | grep -c "both")" -ge "1" ] ; then
iptables -D POSTROUTING -t mangle -o $wan ${ip4_up//both/tcp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip4_up//both/tcp}
iptables -D POSTROUTING -t mangle -o $wan ${ip4_up//both/udp} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip4_up//both/udp}
else
iptables -D POSTROUTING -t mangle -o $wan ${ip4_up} &> /dev/null
iptables -A POSTROUTING -t mangle -o $wan ${ip4_up}
fi
fi
}
tc_redirection_down_rules() {
echo "Applying TC Down Rules"
${tc} filter del dev br0 parent 1: prio $1 #remove original unidentified traffic rule
${tc} filter del dev br0 parent 1: prio 22 &> /dev/null #remove original HTTPS rule
${tc} filter del dev br0 parent 1: prio 23 &> /dev/null #remove original HTTPS rule
! [ -z "$tc4_down" ] && ${tc} filter add dev br0 protocol all ${tc4_down} #Script Interactively Defined Rule 4
! [ -z "$tc3_down" ] && ${tc} filter add dev br0 protocol all ${tc3_down} #Script Interactively Defined Rule 3
! [ -z "$tc2_down" ] && ${tc} filter add dev br0 protocol all ${tc2_down} #Script Interactively Defined Rule 2
! [ -z "$tc1_down" ] && ${tc} filter add dev br0 protocol all ${tc1_down} #Script Interactively Defined Rule 1
${tc} filter add dev br0 protocol all prio 20 u32 match mark 0x8012003F 0xc03fffff flowid ${Web} # HTTP rule with different destination
${tc} filter add dev br0 protocol all prio 22 u32 match mark 0x80130000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
${tc} filter add dev br0 protocol all prio 23 u32 match mark 0x80140000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
##DOWNLOAD APP_DB TRAFFIC REDIRECTION RULES START HERE -- legacy method
${tc} filter add dev br0 protocol all prio 2 u32 match mark 0x8000006B 0xc03fffff flowid ${Others} #Snapchat
${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D0007 0xc03fffff flowid ${Downloads} #Speedtest.net
${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D0086 0xc03fffff flowid ${Downloads} #Google Play
${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D00A0 0xc03fffff flowid ${Downloads} #Apple AppStore
${tc} filter add dev br0 protocol all prio 50 u32 match mark 0x801A0000 0xc03f0000 flowid ${Downloads} #Advertisement
##DOWNLOAD APP_DB TRAFFIC REDIRECTION RULES END HERE -- legacy method
${tc} filter add dev br0 protocol all prio $1 u32 match mark 0x80000000 0x8000ffff flowid ${Others} #recreate unidentified traffic rule with different destination - Routes Unidentified Traffic into webUI adjustable "Others" traffic container instead of "Defaults"
${tc} filter add dev br0 protocol all prio 10 u32 match mark 0x803f0001 0xc03fffff flowid ${Defaults} #Used for iptables Default_mark_down functionality
}
tc_redirection_up_rules() {
echo "Applying TC Up Rules"
${tc} filter del dev eth0 parent 1: prio $1 #remove original unidentified traffic rule
${tc} filter del dev eth0 parent 1: prio 22 &> /dev/null #remove original HTTPS rule
${tc} filter del dev eth0 parent 1: prio 23 &> /dev/null #remove original HTTPS rule
! [ -z "$tc4_up" ] && ${tc} filter add dev eth0 protocol all ${tc4_up} #Script Interactively Defined Rule 4
! [ -z "$tc3_up" ] && ${tc} filter add dev eth0 protocol all ${tc3_up} #Script Interactively Defined Rule 3
! [ -z "$tc2_up" ] && ${tc} filter add dev eth0 protocol all ${tc2_up} #Script Interactively Defined Rule 2
! [ -z "$tc1_up" ] && ${tc} filter add dev eth0 protocol all ${tc1_up} #Script Interactively Defined Rule 1
${tc} filter add dev eth0 protocol all prio 20 u32 match mark 0x4012003F 0xc03fffff flowid ${Web} # HTTP rule with different destination
${tc} filter add dev eth0 protocol all prio 22 u32 match mark 0x40130000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
${tc} filter add dev eth0 protocol all prio 23 u32 match mark 0x40140000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
##UPLOAD APP_DB TRAFFIC REDIRECTION RULES START HERE -- legacy method
${tc} filter add dev eth0 protocol all prio 2 u32 match mark 0x4000006B 0xc03fffff flowid ${Others} #Snapchat
${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D0007 0xc03fffff flowid ${Downloads} #Speedtest.net
${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D0086 0xc03fffff flowid ${Downloads} #Google Play
${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D00A0 0xc03fffff flowid ${Downloads} #Apple AppStore
${tc} filter add dev eth0 protocol all prio 50 u32 match mark 0x401A0000 0xc03f0000 flowid ${Downloads} #Advertisement
##UPLOAD APP_DB TRAFFIC REDIRECTION RULES END HERE -- legacy method
${tc} filter add dev eth0 protocol all prio $1 u32 match mark 0x40000000 0x4000ffff flowid ${Others} #recreate unidentified traffic rule with different destination - Routes Unidentified Traffic into webUI adjustable "Others" traffic container, instead of "Default" traffic container
${tc} filter add dev eth0 protocol all prio 10 u32 match mark 0x403f0001 0xc03fffff flowid ${Defaults} #Used for iptables Default_mark_up functionality
}
custom_rates() {
echo "Modifying TC Class Rates"
${tc} class change dev br0 parent 1:1 classid 1:10 htb ${PARMS}prio 0 rate ${DownRate0}Kbit ceil ${DownCeil0}Kbit burst ${DownBurst0} cburst ${DownCburst0}
${tc} class change dev br0 parent 1:1 classid 1:11 htb ${PARMS}prio 1 rate ${DownRate1}Kbit ceil ${DownCeil1}Kbit burst ${DownBurst1} cburst ${DownCburst1}
${tc} class change dev br0 parent 1:1 classid 1:12 htb ${PARMS}prio 2 rate ${DownRate2}Kbit ceil ${DownCeil2}Kbit burst ${DownBurst2} cburst ${DownCburst2}
${tc} class change dev br0 parent 1:1 classid 1:13 htb ${PARMS}prio 3 rate ${DownRate3}Kbit ceil ${DownCeil3}Kbit burst ${DownBurst3} cburst ${DownCburst3}
${tc} class change dev br0 parent 1:1 classid 1:14 htb ${PARMS}prio 4 rate ${DownRate4}Kbit ceil ${DownCeil4}Kbit burst ${DownBurst4} cburst ${DownCburst4}
${tc} class change dev br0 parent 1:1 classid 1:15 htb ${PARMS}prio 5 rate ${DownRate5}Kbit ceil ${DownCeil5}Kbit burst ${DownBurst5} cburst ${DownCburst5}
${tc} class change dev br0 parent 1:1 classid 1:16 htb ${PARMS}prio 7 rate ${DownRate6}Kbit ceil ${DownCeil6}Kbit burst ${DownBurst6} cburst ${DownCburst6}
${tc} class change dev br0 parent 1:1 classid 1:17 htb ${PARMS}prio 6 rate ${DownRate7}Kbit ceil ${DownCeil7}Kbit burst ${DownBurst7} cburst ${DownCburst7}
${tc} class change dev eth0 parent 1:1 classid 1:10 htb ${PARMS}prio 0 rate ${UpRate0}Kbit ceil ${UpCeil0}Kbit burst ${UpBurst0} cburst ${UpCburst0}
${tc} class change dev eth0 parent 1:1 classid 1:11 htb ${PARMS}prio 1 rate ${UpRate1}Kbit ceil ${UpCeil1}Kbit burst ${UpBurst1} cburst ${UpCburst1}
${tc} class change dev eth0 parent 1:1 classid 1:12 htb ${PARMS}prio 2 rate ${UpRate2}Kbit ceil ${UpCeil2}Kbit burst ${UpBurst2} cburst ${UpCburst2}
${tc} class change dev eth0 parent 1:1 classid 1:13 htb ${PARMS}prio 3 rate ${UpRate3}Kbit ceil ${UpCeil3}Kbit burst ${UpBurst3} cburst ${UpCburst3}
${tc} class change dev eth0 parent 1:1 classid 1:14 htb ${PARMS}prio 4 rate ${UpRate4}Kbit ceil ${UpCeil4}Kbit burst ${UpBurst4} cburst ${UpCburst4}
${tc} class change dev eth0 parent 1:1 classid 1:15 htb ${PARMS}prio 5 rate ${UpRate5}Kbit ceil ${UpCeil5}Kbit burst ${UpBurst5} cburst ${UpCburst5}
${tc} class change dev eth0 parent 1:1 classid 1:16 htb ${PARMS}prio 7 rate ${UpRate6}Kbit ceil ${UpCeil6}Kbit burst ${UpBurst6} cburst ${UpCburst6}
${tc} class change dev eth0 parent 1:1 classid 1:17 htb ${PARMS}prio 6 rate ${UpRate7}Kbit ceil ${UpCeil7}Kbit burst ${UpBurst7} cburst ${UpCburst7}
}
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
#################### DO NOT MODIFY BELOW #####################
webpath='/jffs/scripts/www_FreshJR_QoS_Stats.asp' #path of FreshJR_QoS_Stats.asp
#marks for iptable rules
Net_mark_down="0x80090001"
VOIP_mark_down="0x80060001" # Marks for iptables variant of download rules
Gaming_mark_down="0x80080001" # Note these marks are same as filter match/mask combo but have a 1 at the end. That trailing 1 prevents them from being caught by unidentified mask
Others_mark_down="0x800a0001"
Web_mark_down="0x800d0001"
Streaming_mark_down="0x80040001"
Downloads_mark_down="0x80030001"
Default_mark_down="0x803f0001"
Net_mark_up="0x40090001"
VOIP_mark_up="0x40060001" # Marks for iptables variant of upload rules
Gaming_mark_up="0x40080001" # Note these marks are same as filter match/mask combo but have a 1 at the end. That trailing 1 prevents them from being caught by unidentified mask
Others_mark_up="0x400a0001"
Web_mark_up="0x400d0001"
Streaming_mark_up="0x40040001"
Downloads_mark_up="0x40030001"
Default_mark_up="0x403f0001"
set_tc_variables(){
if [ -e "/usr/sbin/realtc" ] ; then
tc="realtc"
else
tc="tc"
fi
#read order of QOS categories
Defaults="1:17"
Net="1:10"
flowid=0
while read -r line; # reads users order of QOS categories
do
#logger -s "${line} ${flowid}"
case ${line} in
'0')
VOIP="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp1}"
eval "Cat${flowid}UpBandPercent=${urp1}"
eval "Cat${flowid}DownCeilPercent=${dcp1}"
eval "Cat${flowid}UpCeilPercent=${ucp1}"
;;
'1')
Downloads="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp7}"
eval "Cat${flowid}UpBandPercent=${urp7}"
eval "Cat${flowid}DownCeilPercent=${dcp7}"
eval "Cat${flowid}UpCeilPercent=${ucp7}"
;;
'4')
Streaming="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp5}"
eval "Cat${flowid}UpBandPercent=${urp5}"
eval "Cat${flowid}DownCeilPercent=${dcp5}"
eval "Cat${flowid}UpCeilPercent=${ucp5}"
;;
'7')
Others="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp3}"
eval "Cat${flowid}UpBandPercent=${urp3}"
eval "Cat${flowid}DownCeilPercent=${dcp3}"
eval "Cat${flowid}UpCeilPercent=${ucp3}"
;;
'8')
Gaming="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp2}"
eval "Cat${flowid}UpBandPercent=${urp2}"
eval "Cat${flowid}DownCeilPercent=${dcp2}"
eval "Cat${flowid}UpCeilPercent=${ucp2}"
;;
'9')
#net control
flowid=0
;;
'13')
Web="1:1${flowid}"
eval "Cat${flowid}DownBandPercent=${drp4}"
eval "Cat${flowid}UpBandPercent=${urp4}"
eval "Cat${flowid}DownCeilPercent=${dcp4}"
eval "Cat${flowid}UpCeilPercent=${ucp4}"
;;
esac
firstchar="${line%%[0-9]*}"
if [ "${firstchar}" == "[" ] ; then
flowid=$((flowid + 1))
#logger -s "flowid = ${flowid} ==========="
fi
done <<EOF
$(cat /tmp/bwdpi/qosd.conf | sed 's/rule=//g' | sed '/na/q')
EOF
#calculate up/down rates
DownCeil="$(printf "%.0f" $(nvram get qos_ibw))"
UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
DownRate0="$(expr ${DownCeil} \* ${drp0} / 100)" #Minimum guaranteed Up/Down rates per QOS category corresponding to user defined percentages
DownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"
DownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"
DownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"
DownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"
DownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"
DownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"
DownRate7="$(expr ${DownCeil} \* ${drp6} / 100)"
UpRate0="$(expr ${UpCeil} \* ${urp0} / 100)"
UpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"
UpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"
UpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"
UpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"
UpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"
UpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"
UpRate7="$(expr ${UpCeil} \* ${urp6} / 100)"
DownCeil0="$(expr ${DownCeil} \* ${dcp0} / 100)" #Minimum guaranteed Up/Down rates per QOS category corresponding to user defined percentages
DownCeil1="$(expr ${DownCeil} \* ${Cat1DownCeilPercent} / 100)"
DownCeil2="$(expr ${DownCeil} \* ${Cat2DownCeilPercent} / 100)"
DownCeil3="$(expr ${DownCeil} \* ${Cat3DownCeilPercent} / 100)"
DownCeil4="$(expr ${DownCeil} \* ${Cat4DownCeilPercent} / 100)"
DownCeil5="$(expr ${DownCeil} \* ${Cat5DownCeilPercent} / 100)"
DownCeil6="$(expr ${DownCeil} \* ${Cat6DownCeilPercent} / 100)"
DownCeil7="$(expr ${DownCeil} \* ${dcp6} / 100)"
UpCeil0="$(expr ${UpCeil} \* ${ucp0} / 100)"
UpCeil1="$(expr ${UpCeil} \* ${Cat1UpCeilPercent} / 100)"
UpCeil2="$(expr ${UpCeil} \* ${Cat2UpCeilPercent} / 100)"
UpCeil3="$(expr ${UpCeil} \* ${Cat3UpCeilPercent} / 100)"
UpCeil4="$(expr ${UpCeil} \* ${Cat4UpCeilPercent} / 100)"
UpCeil5="$(expr ${UpCeil} \* ${Cat5UpCeilPercent} / 100)"
UpCeil6="$(expr ${UpCeil} \* ${Cat6UpCeilPercent} / 100)"
UpCeil7="$(expr ${UpCeil} \* ${ucp6} / 100)"
ClassesPresent=0
#read existing burst/cburst per download class
while read -r line;
do
ClassesPresent=$(($ClassesPresent+1))
if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
DownBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
DownBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
DownBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
DownBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
DownBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
DownBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
DownBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
DownBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
DownCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
done <<EOF
$( tc class show dev br0 | grep "parent 1:1 " )
EOF
#read existing burst/cburst per upload class
while read -r line;
do
if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
UpBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
UpBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
UpBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
UpBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
UpBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
UpBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
UpBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
UpBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
UpCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
fi
done <<EOF
$( tc class show dev eth0 | grep "parent 1:1 " )
EOF
#read parameters for fakeTC
PARMS=""
OVERHEAD=$(nvram get qos_overhead)
if [ ! -z "$OVERHEAD" ] && [ "$OVERHEAD" -gt "0" ] ; then
ATM=$(nvram get qos_atm)
if [ "$ATM" == "1" ] ; then
PARMS="overhead $OVERHEAD linklayer atm "
else
PARMS="overhead $OVERHEAD linklayer ethernet "
fi
fi
}
## Main Menu -appdb function
appdb(){
if [ "$( grep -i "${1}" /tmp/bwdpi/bwdpi.app.db | wc -l )" -lt "25" ] ; then
grep -i "${1}" /tmp/bwdpi/bwdpi.app.db | while read -r line ; do
echo $line | cut -f 4 -d ","
cat_decimal=$(echo $line | cut -f 1 -d "," )
cat_hex=$( printf "%02x" $cat_decimal )
case "$cat_decimal" in
'9'|'20')
echo " Originally: Net Control"
;;
'0'|'5'|'6'|'15'|'17')
echo " Originally: VoIP"
;;
'8')
echo " Originally: Gaming"
;;
'7'|'10'|'11'|'21'|'23')
echo " Originally: Others"
;;
'13'|'24'|'18'|'19')
echo " Originally: Web"
;;
'4'|'12')
echo " Originally: Streaming"
;;
'1'|'3'|'14')
echo " Originally: Downloads"
;;
esac
echo -n " Mark: ${cat_hex}"
echo $line | cut -f 2 -d "," | awk '{printf("%04x \n",$1)}'
#parameters required for manually creating TC rules
#echo " TC Prio : $(expr $(tc filter show dev br0 | grep "${cat_hex}0000" -B1 | tail -2 | cut -d " " -f7 | head -1) - 1)"
#printf " Down Mark : 0x80${cat_hex}"
#echo $line | cut -f 2 -d "," | awk '{printf("%04x 0xc03fffff\n",$1)}'
#printf " UP Mark : 0x40${cat_hex}"
#echo $line | cut -f 2 -d "," | awk '{printf("%04x 0xc03fffff\n",$1)}'
echo ""
done
else
echo "AppDB search parameter has to be more specfic"
fi
}
## Main Menu -debug function
debug(){
echo -en "\033c\e[3J" #clear screen
echo -en '\033[?7l' #disable line wrap
echo -e "\033[1;32mFreshJR QOS v${version}\033[0m"
echo "Debug:"
echo ""
read_nvram
set_tc_variables
current_undf_rule="$(tc filter show dev br0 | grep -v "/" | grep "000ffff" -B1)"
undf_flowid=$(echo $current_undf_rule | grep -o "flowid.*" | cut -d" " -f2 | head -1)
undf_prio=$(echo $current_undf_rule | grep -o "pref.*" | cut -d" " -f2 | head -1)
logger -t "adaptive QOS" -s "Undf Prio: $undf_prio"
logger -t "adaptive QOS" -s "Undf FlowID: $undf_flowid"
logger -t "adaptive QOS" -s "Classes Present: $ClassesPresent"
logger -t "adaptive QOS" -s "Down Band: $DownCeil"
logger -t "adaptive QOS" -s "Up Band : $UpCeil"
logger -t "adaptive QOS" -s "***********"
logger -t "adaptive QOS" -s "Net = ${Net}"
logger -t "adaptive QOS" -s "VOIP = ${VOIP}"
logger -t "adaptive QOS" -s "Gaming = ${Gaming}"
logger -t "adaptive QOS" -s "Others = ${Others}"
logger -t "adaptive QOS" -s "Web = ${Web}"
logger -t "adaptive QOS" -s "Streaming = ${Streaming}"
logger -t "adaptive QOS" -s "Downloads = ${Downloads}"
logger -t "adaptive QOS" -s "Defaults = ${Defaults}"
logger -t "adaptive QOS" -s "***********"
logger -t "adaptive QOS" -s "Downrates -- $DownRate0, $DownRate1, $DownRate2, $DownRate3, $DownRate4, $DownRate5, $DownRate6, $DownRate7"
logger -t "adaptive QOS" -s "Downceils -- $DownCeil0, $DownCeil1, $DownCeil2, $DownCeil3, $DownCeil4, $DownCeil5, $DownCeil6, $DownCeil7"
logger -t "adaptive QOS" -s "Downbursts -- $DownBurst0, $DownBurst1, $DownBurst2, $DownBurst3, $DownBurst4, $DownBurst5, $DownBurst6, $DownBurst7"
logger -t "adaptive QOS" -s "DownCbursts -- $DownCburst0, $DownCburst1, $DownCburst2, $DownCburst3, $DownCburst4, $DownCburst5, $DownCburst6, $DownCburst7"
logger -t "adaptive QOS" -s "***********"
logger -t "adaptive QOS" -s "Uprates -- $UpRate0, $UpRate1, $UpRate2, $UpRate3, $UpRate4, $UpRate5, $UpRate6, $UpRate7"
logger -t "adaptive QOS" -s "Upciels -- $UpCeil0, $UpCeil1, $UpCeil2, $UpCeil3, $UpCeil4, $UpCeil5, $UpCeil6, $UpCeil7"
logger -t "adaptive QOS" -s "Upbursts -- $UpBurst0, $UpBurst1, $UpBurst2, $UpBurst3, $UpBurst4, $UpBurst5, $UpBurst6, $UpBurst7"
logger -t "adaptive QOS" -s "UpCbursts -- $UpCburst0, $UpCburst1, $UpCburst2, $UpCburst3, $UpCburst4, $UpCburst5, $UpCburst6, $UpCburst7"
echo -en '\033[?7h' #enable line wrap
}
debug2(){
echo -en "\033c\e[3J" #clear screen
echo -en '\033[?7l' #disable line wrap
echo -e "\033[1;32mFreshJR QOS v${version}\033[0m"
echo "Debug2:"
echo ""
read_nvram
set_tc_variables
parse_iptablerule "${e1}" "${e2}" "${e3}" "${e4}" "${e5}" "${e6}" "${e7}" ip1_down ip1_up
parse_iptablerule "${f1}" "${f2}" "${f3}" "${f4}" "${f5}" "${f6}" "${f7}" ip2_down ip2_up
parse_iptablerule "${g1}" "${g2}" "${g3}" "${g4}" "${g5}" "${g6}" "${g7}" ip3_down ip3_up
parse_iptablerule "${h1}" "${h2}" "${h3}" "${h4}" "${h5}" "${h6}" "${h7}" ip4_down ip4_up
parse_tcrule "${r1}" "${d1}" tc1_down tc1_up
parse_tcrule "${r2}" "${d2}" tc2_down tc2_up
parse_tcrule "${r3}" "${d3}" tc3_down tc3_up
parse_tcrule "${r4}" "${d4}" tc4_down tc4_up
echo -en '\033[?7l' #disable line wrap
echo "Game CIDR: ${gameCIDR}"
echo ""
if [ "$(echo ${ip1_down} | grep -c "both")" -ge "1" ] ; then
echo "Rule1 Down: ${ip1_down//both/tcp}"
echo " : ${ip1_down//both/udp}"
echo "Rule1 Up : ${ip1_up//both/tcp}"
echo " : ${ip1_up//both/udp}"
else
echo "Rule1 Down: ${ip1_down}"
echo "Rule1 Up : ${ip1_up}"
fi
echo ""
if [ "$(echo ${ip2_down} | grep -c "both")" -ge "1" ] ; then
echo "Rule2 Down: ${ip2_down//both/tcp}"
echo " ${ip2_down//both/udp}"
echo "Rule2 Up : ${ip2_up//both/tcp}"
echo " ${ip2_up//both/udp}"
else
echo "Rule2 Down: ${ip2_down}"
echo "Rule2 Up : ${ip2_up}"
fi
echo ""
if [ "$(echo ${ip3_down} | grep -c "both")" -ge "1" ] ; then
echo "Rule3 Down: ${ip3_down//both/tcp}"
echo " : ${ip3_down//both/udp}"
echo "Rule3 Up : ${ip3_up//both/tcp}"
echo " : ${ip3_up//both/udp}"
else
echo "Rule3 Down: ${ip3_down}"
echo "Rule3 Up : ${ip3_up}"
fi
echo ""
if [ "$(echo ${ip4_down} | grep -c "both")" -ge "1" ] ; then
echo "Rule4 Down: ${ip4_down//both/tcp}"
echo " ${ip4_down//both/udp}"
echo "Rule4 Up : ${ip4_up//both/tcp}"
echo " ${ip4_up//both/udp}"
else
echo "Rule4 Down: ${ip4_down}"
echo "Rule4 Up : ${ip4_up}"
fi
echo ""
echo "AppDB1 Down: ${tc1_down}"
echo "AppDB1 Up : ${tc1_up}"
echo ""
echo "AppDB2 Down: ${tc2_down}"
echo "AppDB2 Up : ${tc2_up}"
echo ""
echo "AppDB3 Down: ${tc3_down}"
echo "AppDB3 Up : ${tc3_up}"
echo ""
echo "AppDB4 Down: ${tc4_down}"
echo "AppDB4 Up : ${tc4_up}"
echo -en '\033[?7h' #enable line wrap
}
## Main Menu -gameip function
gameip(){
if [ "$( echo $1 | tr -cd '.' | wc -c )" -eq "3" ] ; then
gameCIDR=${input}
else
gameCIDR=''
fi
save_nvram
}
## helper function to parse csv nvram variables
read_nvram(){
OLDIFS=$IFS
IFS=";"
if [ $(nvram get fb_comment | sed 's/>/;/g' | tr -cd ';' | wc -c) -ne 20 ] ; then
$(nvram set fb_comment=";;;;;;>;;;;;;>;;;;;;")
fi
if [ $(nvram get fb_email_dbg | sed 's/>/;/g' | tr -cd ';' | wc -c) -ne 48 ] ; then
$(nvram set fb_email_dbg=";;;;;;>;>;>;>;>>>5;20;15;10;10;30;5;5>100;100;100;100;100;100;100;100>5;20;15;30;10;10;5;5>100;100;100;100;100;100;100;100")
fi
read \
e1 e2 e3 e4 e5 e6 e7 \
f1 f2 f3 f4 f5 f6 f7 \
g1 g2 g3 g4 g5 g6 g7 \
<<EOF
$(nvram get fb_comment | sed 's/>/;/g' )
EOF
read \
h1 h2 h3 h4 h5 h6 h7 \
r1 d1 \
r2 d2 \
r3 d3 \
r4 d4 \
gameCIDR \
ruleFLAG \
drp0 drp1 drp2 drp3 drp4 drp5 drp6 drp7 \
dcp0 dcp1 dcp2 dcp3 dcp4 dcp5 dcp6 dcp7 \
urp0 urp1 urp2 urp3 urp4 urp5 urp6 urp7 \
ucp0 ucp1 ucp2 ucp3 ucp4 ucp5 ucp6 ucp7 \
<<EOF
$(nvram get fb_email_dbg | sed 's/>/;/g' )
EOF
IFS=$OLDIFS
#Verify each read nvram rate is between 5-100 (disabled unless needed in future)
# [ "${drp0//[^0-9]}" -ge "5" ] && [ "${drp0//[^0-9]}" -le "100" ] && drp0="5"
# [ "${drp1//[^0-9]}" -ge "5" ] && [ "${drp1//[^0-9]}" -le "100" ] && drp1="20"
# [ "${drp2//[^0-9]}" -ge "5" ] && [ "${drp2//[^0-9]}" -le "100" ] && drp2="15"
# [ "${drp3//[^0-9]}" -ge "5" ] && [ "${drp3//[^0-9]}" -le "100" ] && drp3="10"
# [ "${drp4//[^0-9]}" -ge "5" ] && [ "${drp4//[^0-9]}" -le "100" ] && drp4="10"
# [ "${drp5//[^0-9]}" -ge "5" ] && [ "${drp5//[^0-9]}" -le "100" ] && drp5="30"
# [ "${drp6//[^0-9]}" -ge "5" ] && [ "${drp6//[^0-9]}" -le "100" ] && drp6="5"
# [ "${drp7//[^0-9]}" -ge "5" ] && [ "${drp7//[^0-9]}" -le "100" ] && drp7="5"
# [ "${dcp0//[^0-9]}" -ge "5" ] && [ "${dcp0//[^0-9]}" -le "100" ] && dcp0="100"
# [ "${dcp1//[^0-9]}" -ge "5" ] && [ "${dcp1//[^0-9]}" -le "100" ] && dcp1="100"
# [ "${dcp2//[^0-9]}" -ge "5" ] && [ "${dcp2//[^0-9]}" -le "100" ] && dcp2="100"
# [ "${dcp3//[^0-9]}" -ge "5" ] && [ "${dcp3//[^0-9]}" -le "100" ] && dcp3="100"
# [ "${dcp4//[^0-9]}" -ge "5" ] && [ "${dcp4//[^0-9]}" -le "100" ] && dcp4="100"
# [ "${dcp5//[^0-9]}" -ge "5" ] && [ "${dcp5//[^0-9]}" -le "100" ] && dcp5="100"
# [ "${dcp6//[^0-9]}" -ge "5" ] && [ "${dcp6//[^0-9]}" -le "100" ] && dcp6="100"
# [ "${dcp7//[^0-9]}" -ge "5" ] && [ "${dcp7//[^0-9]}" -le "100" ] && dcp7="100"
# [ "${urp0//[^0-9]}" -ge "5" ] && [ "${urp0//[^0-9]}" -le "100" ] && urp0="5"
# [ "${urp1//[^0-9]}" -ge "5" ] && [ "${urp1//[^0-9]}" -le "100" ] && urp1="20"
# [ "${urp2//[^0-9]}" -ge "5" ] && [ "${urp2//[^0-9]}" -le "100" ] && urp2="15"
# [ "${urp3//[^0-9]}" -ge "5" ] && [ "${urp3//[^0-9]}" -le "100" ] && urp3="30"
# [ "${urp4//[^0-9]}" -ge "5" ] && [ "${urp4//[^0-9]}" -le "100" ] && urp4="10"
# [ "${urp5//[^0-9]}" -ge "5" ] && [ "${urp5//[^0-9]}" -le "100" ] && urp5="10"
# [ "${urp6//[^0-9]}" -ge "5" ] && [ "${urp6//[^0-9]}" -le "100" ] && urp6="5"
# [ "${urp7//[^0-9]}" -ge "5" ] && [ "${urp7//[^0-9]}" -le "100" ] && urp7="5"
# [ "${ucp0//[^0-9]}" -ge "5" ] && [ "${ucp0//[^0-9]}" -le "100" ] && ucp0="100"
# [ "${ucp1//[^0-9]}" -ge "5" ] && [ "${ucp1//[^0-9]}" -le "100" ] && ucp1="100"
# [ "${ucp2//[^0-9]}" -ge "5" ] && [ "${ucp2//[^0-9]}" -le "100" ] && ucp2="100"
# [ "${ucp3//[^0-9]}" -ge "5" ] && [ "${ucp3//[^0-9]}" -le "100" ] && ucp3="100"
# [ "${ucp4//[^0-9]}" -ge "5" ] && [ "${ucp4//[^0-9]}" -le "100" ] && ucp4="100"
# [ "${ucp5//[^0-9]}" -ge "5" ] && [ "${ucp5//[^0-9]}" -le "100" ] && ucp5="100"
# [ "${ucp6//[^0-9]}" -ge "5" ] && [ "${ucp6//[^0-9]}" -le "100" ] && ucp6="100"
# [ "${ucp7//[^0-9]}" -ge "5" ] && [ "${ucp7//[^0-9]}" -le "100" ] && ucp7="100"
#takes protocol saved in nvram and makes it lower case
e3=$(echo ${e3} | tr '[A-Z]' '[a-z]')
f3=$(echo ${f3} | tr '[A-Z]' '[a-z]')
g3=$(echo ${g3} | tr '[A-Z]' '[a-z]')
h3=$(echo ${h3} | tr '[A-Z]' '[a-z]')
}
## helper function to save nvram variables in csv format
save_nvram(){
$(nvram set fb_comment="${e1};${e2};${e3};${e4};${e5};${e6};${e7}>${f1};${f2};${f3};${f4};${f5};${f6};${f7}>${g1};${g2};${g3};${g4};${g5};${g6};${g7}")
$(nvram set fb_email_dbg="${h1};${h2};${h3};${h4};${h5};${h6};${h7}>${r1};${d1}>${r2};${d2}>${r3};${d3}>${r4};${d4}>${gameCIDR}>${ruleFLAG}>${drp0};${drp1};${drp2};${drp3};${drp4};${drp5};${drp6};${drp7}>${dcp0};${dcp1};${dcp2};${dcp3};${dcp4};${dcp5};${dcp6};${dcp7}>${urp0};${urp1};${urp2};${urp3};${urp4};${urp5};${urp6};${urp7}>${ucp0};${ucp1};${ucp2};${ucp3};${ucp4};${ucp5};${ucp6};${ucp7}")
$(nvram commit)
}
## helper function for interactive menu mode
dst_2_name()
{
case "$1" in
0) echo "Net Control" ;;
1) echo "Gaming" ;;
2) echo "Streaming" ;;
3) echo "VoIP" ;;
4) echo "Web Surfing" ;;
5) echo "Downloads" ;;
6) echo "Others" ;;
7) echo "Game Downloads" ;;
*) echo "" ;;
esac
}
## helper function for interactive menu mode
mark_2_name()
{
return #function disabled since grep is kinda slow
[ -z "$1" ] && return
cat="$( echo ${1} | head -c2 )"
id="$( echo ${1} | tail -c -5 )"
cat="$(printf "%d" 0x${cat})"
id="$(printf "%d" 0x${id})"
cat /tmp/bwdpi/bwdpi.app.db | grep "^${cat},${id}" | head -n1 | cut -d',' -f4
}
## INTERACTIVE mode - rate main page (overview)
rates(){
echo -en "\033c\e[3J" #clear screen
echo -en '\033[?7l' #disable line wrap
printf '\e[8;30;120t' #set height/width of terminal
echo -e "\033[1;32mFreshJR QOS v${version}\033[0m"
echo "QoS Rates: -------Download------- --------Upload--------"
echo " Minimum Maximum Minimum Maximum"
echo " Reserved Reserved Allowed Allowed"
echo " Bandwidth Bandwidth Bandwidth Bandwidth"
echo " (%) (%) (%) (%) "
echo " ----------------------- -----------------------"
format="%-15s %-13s %-18s %-13s %-4s\n"
printf "${format}" "Net Control" "${drp0}" "${dcp0}" "${urp0}" "${ucp0}"
printf "${format}" "VoIP" "${drp1}" "${dcp1}" "${urp1}" "${ucp1}"
printf "${format}" "Gaming" "${drp2}" "${dcp2}" "${urp2}" "${ucp2}"
printf "${format}" "Others" "${drp3}" "${dcp3}" "${urp3}" "${ucp3}"
printf "${format}" "Web Surfing" "${drp4}" "${dcp4}" "${urp4}" "${ucp4}"
printf "${format}" "Streaming" "${drp5}" "${dcp5}" "${urp5}" "${ucp5}"
printf "${format}" "Game Downloads" "${drp6}" "${dcp6}" "${urp6}" "${ucp6}"
printf "${format}" "File Downloads" "${drp7}" "${dcp7}" "${urp7}" "${ucp7}"
echo ""
echo "Available actions:"
echo ""
echo "1) Minimum Reserved Bandwidth -- Download"
echo "2) Minimum Reserved Bandwidth -- Upload"
echo ""
echo "3) Maximum Allowed Bandwidth -- Download"
echo "4) Maximum Allowed Bandwidth -- Upload"
echo ""
echo "r) Reset Values to Defaults"
echo "s) Save & Exit"
echo "e) Exit"
echo -en '\033[?7h' #enable line wrap
echo ""
echo -n "What would you like to do (Enter 1-10): "
read input
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
echo -en "\033[1A\r\033[0K"
case $input in
1)
echo "Minimum Reserved Bandwidth"
read -p " Net Control : " in0
read -p " Voip : " in1
read -p " Gaming : " in2
read -p " Others : " in3
read -p " Web Surfing : " in4
read -p " Streaming : " in5
read -p " Game Downloads : " in6
read -p " File Downloads : " in7
[ "${in0//[^0-9]}" -ge "5" ] && [ "${in0//[^0-9]}" -le "100" ] && drp0="${in0//[^0-9]}"
[ "${in1//[^0-9]}" -ge "5" ] && [ "${in1//[^0-9]}" -le "100" ] && drp1="${in1//[^0-9]}"
[ "${in2//[^0-9]}" -ge "5" ] && [ "${in2//[^0-9]}" -le "100" ] && drp2="${in2//[^0-9]}"
[ "${in3//[^0-9]}" -ge "5" ] && [ "${in3//[^0-9]}" -le "100" ] && drp3="${in3//[^0-9]}"
[ "${in4//[^0-9]}" -ge "5" ] && [ "${in4//[^0-9]}" -le "100" ] && drp4="${in4//[^0-9]}"
[ "${in5//[^0-9]}" -ge "5" ] && [ "${in5//[^0-9]}" -le "100" ] && drp5="${in5//[^0-9]}"
[ "${in6//[^0-9]}" -ge "5" ] && [ "${in6//[^0-9]}" -le "100" ] && drp6="${in6//[^0-9]}"
[ "${in7//[^0-9]}" -ge "5" ] && [ "${in7//[^0-9]}" -le "100" ] && drp7="${in7//[^0-9]}"
rates
;;
2)
echo "Minimum Reserved Bandwidth"
read -p " Net Control : " in0
read -p " Voip : " in1
read -p " Gaming : " in2
read -p " Others : " in3
read -p " Web Surfing : " in4
read -p " Streaming : " in5
read -p " Game Downloads : " in6
read -p " File Downloads : " in7
[ "${in0//[^0-9]}" -ge "5" ] && [ "${in0//[^0-9]}" -le "100" ] && urp0="${in0//[^0-9]}"
[ "${in1//[^0-9]}" -ge "5" ] && [ "${in1//[^0-9]}" -le "100" ] && urp1="${in1//[^0-9]}"
[ "${in2//[^0-9]}" -ge "5" ] && [ "${in2//[^0-9]}" -le "100" ] && urp2="${in2//[^0-9]}"
[ "${in3//[^0-9]}" -ge "5" ] && [ "${in3//[^0-9]}" -le "100" ] && urp3="${in3//[^0-9]}"
[ "${in4//[^0-9]}" -ge "5" ] && [ "${in4//[^0-9]}" -le "100" ] && urp4="${in4//[^0-9]}"
[ "${in5//[^0-9]}" -ge "5" ] && [ "${in5//[^0-9]}" -le "100" ] && urp5="${in5//[^0-9]}"
[ "${in6//[^0-9]}" -ge "5" ] && [ "${in6//[^0-9]}" -le "100" ] && urp6="${in6//[^0-9]}"
[ "${in7//[^0-9]}" -ge "5" ] && [ "${in7//[^0-9]}" -le "100" ] && urp7="${in7//[^0-9]}"
rates
;;
3)
echo "Minimum Reserved Bandwidth"
read -p " Net Control : " in0
read -p " Voip : " in1
read -p " Gaming : " in2
read -p " Others : " in3
read -p " Web Surfing : " in4
read -p " Streaming : " in5
read -p " Game Downloads : " in6
read -p " File Downloads : " in7
[ "${in0//[^0-9]}" -ge "5" ] && [ "${in0//[^0-9]}" -le "100" ] && dcp0="${in0//[^0-9]}"
[ "${in1//[^0-9]}" -ge "5" ] && [ "${in1//[^0-9]}" -le "100" ] && dcp1="${in1//[^0-9]}"
[ "${in2//[^0-9]}" -ge "5" ] && [ "${in2//[^0-9]}" -le "100" ] && dcp2="${in2//[^0-9]}"
[ "${in3//[^0-9]}" -ge "5" ] && [ "${in3//[^0-9]}" -le "100" ] && dcp3="${in3//[^0-9]}"
[ "${in4//[^0-9]}" -ge "5" ] && [ "${in4//[^0-9]}" -le "100" ] && dcp4="${in4//[^0-9]}"
[ "${in5//[^0-9]}" -ge "5" ] && [ "${in5//[^0-9]}" -le "100" ] && dcp5="${in5//[^0-9]}"
[ "${in6//[^0-9]}" -ge "5" ] && [ "${in6//[^0-9]}" -le "100" ] && dcp6="${in6//[^0-9]}"
[ "${in7//[^0-9]}" -ge "5" ] && [ "${in7//[^0-9]}" -le "100" ] && dcp7="${in7//[^0-9]}"
rates
;;
4)
echo "Minimum Reserved Bandwidth"
read -p " Net Control : " in0
read -p " Voip : " in1
read -p " Gaming : " in2
read -p " Others : " in3
read -p " Web Surfing : " in4
read -p " Streaming : " in5
read -p " Game Downloads : " in6
read -p " File Downloads : " in7
[ "${in0//[^0-9]}" -ge "5" ] && [ "${in0//[^0-9]}" -le "100" ] && ucp0="${in0//[^0-9]}"
[ "${in1//[^0-9]}" -ge "5" ] && [ "${in1//[^0-9]}" -le "100" ] && ucp1="${in1//[^0-9]}"
[ "${in2//[^0-9]}" -ge "5" ] && [ "${in2//[^0-9]}" -le "100" ] && ucp2="${in2//[^0-9]}"
[ "${in3//[^0-9]}" -ge "5" ] && [ "${in3//[^0-9]}" -le "100" ] && ucp3="${in3//[^0-9]}"
[ "${in4//[^0-9]}" -ge "5" ] && [ "${in4//[^0-9]}" -le "100" ] && ucp4="${in4//[^0-9]}"
[ "${in5//[^0-9]}" -ge "5" ] && [ "${in5//[^0-9]}" -le "100" ] && ucp5="${in5//[^0-9]}"
[ "${in6//[^0-9]}" -ge "5" ] && [ "${in6//[^0-9]}" -le "100" ] && ucp6="${in6//[^0-9]}"
[ "${in7//[^0-9]}" -ge "5" ] && [ "${in7//[^0-9]}" -le "100" ] && ucp7="${in7//[^0-9]}"
rates
;;
'r'|'R')
drp0="5"
drp1="20"
drp2="15"
drp3="10"
drp4="10"
drp5="30"
drp6="5"
drp7="5"
dcp0="100"
dcp1="100"
dcp2="100"
dcp3="100"
dcp4="100"
dcp5="100"
dcp6="100"
dcp7="100"
urp0="5"
urp1="20"
urp2="15"
urp3="30"
urp4="10"
urp5="10"
urp6="5"
urp7="5"
ucp0="100"
ucp1="100"
ucp2="100"
ucp3="100"