It took a shaper on some cheap piece of iron. The piece of iron was planned to be
DIR-320 from a famous Chinese manufacturer. But instead of the good and simple
DIR-320 , the terrible and incomprehensible
DIR-320NRU arrived and problems started.
Initially, the idea was simple: we put
OpenWRT and rule as we want. But it is not yet possible to install OpenWRT on the NRU (I will be happy if someone corrects it), the format of the bootloader is incomprehensible, I did not find a quick glance at the squashfs in the firmware. Yes, and time to look, somehow it was not. Having chosen the native firmware, it became clear that to complete the task all the necessary tools (read: tc) are in it. In general, there is something in the native dof firmware, even man-pages have a place to be.
By the method of scientific tying and some kind of mother, it was found that all changeable settings are stored in the
/ etc / default folder (which is a symlink to / tmp / etc / default, but the essence). All files in this folder are carefully packed and recorded into the nvram with the command
/ usr / sbin / saveconfig , and loaded (including when the system starts), respectively
/ usr / sbin / loadconfig , cat is present, chmod too, problems with no scripts. But there are problems with running scripts at startup.
')
Having found some more, I found the file
/etc/default/config.json and the demon
/ bin / resident , which parses the config and executes everything in the config that is written. It was written, apparently negligently and not even by the Chinese, but by the Hindus, or, more likely, by Indo-rusas, the lines from the file are immediately shoved for execution. It was then that the engineering idea was replaced by a thread on the script. The first option available was a
DMZ host - changing the contents of the config.json type:
"dmz": {
"enable": true,
"ip": "192.168.0.2"
},
on
"dmz": {
"enable": true,
"ip": "`/etc/default/shaper.sh`"
},
resident is all swallowed and instead of
-DNAT --to 192.168.0.1 , runs our script. And if the script returns the correct ip-address, then the DMZ host is also registered correctly. Voila!
Well, a little code lastly:
/etc/default/shaper.shtc qdisc del dev br0 root
tc qdisc add dev br0 root handle 1: htb default 2
tc class add dev br0 parent 1: classid 1:1 htb rate 10mbps
tc class add dev br0 parent 1:1 classid 1:2 htb rate 50kbps
for ip in `cat /etc/default/ips`;do
tc class add dev br0 parent 1:1 classid 1:${ip} htb rate 50kbps
tc filter add dev br0 parent 1: protocol ip prio 1 u32 match ip dst 192.168.0.${ip}/32 flowid 1:${ip}
done
echo cat /etc/default/DMZ.txt
led wps progress
The shaper itself, the DMZ host is taken from the DMZ.txt file,
/ etc / default / ips - the last bytes of addresses (2 3 4 5..254)
In the last line, we turn on the blinking of the internal neonka, so that it irritates and unnerves, and also informs that all of the above has been loaded and working.
Script for substitution
echo Set DMZ Host to 9.9.9.9 via WebIF and run me again!
echo Use /etc/default/DMZ.txt to set DMZ Host IP
sed -is/9.9.9.9/"\`\/etc\/default\/shaper.sh\`"/g /etc/default/config.json
saveconfig
sed for us is also left, which can not but rejoice.
And nothing more is needed. It works like this: configure everything as it should in the web-interface, set the DMZ-host in 9.9.9.9 (ibid.), Connect telnet and start
/etc/default/modify.shreboot the router by pulling out and pulling in the cable or using the reboot command.