#!/bin/sh
# interfaces to apply the bandwidth control
IFACES="eno1 eno2"
# ASN28573
ASN28573="177.32.0.0/16 177.32.0.0/19 177.32.32.0/19 177.32.64.0/19 177.32.96.0/19 177.32.128.0/19 177.32.160.0/19 177.32.192.0/19 177.32.224.0/19 177.33.0.0/19 177.33.0.0/16 177.33.32.0/19 177.33.64.0/19 177.33.96.0/19 177.33.128.0/19 177.33.136.0/22 177.33.140.0/22 177.33.160.0/19 177.33.192.0/19 177.33.224.0/19 177.34.0.0/20 177.34.16.0/21 177.34.24.0/21 177.34.32.0/20 177.34.48.0/20 177.34.64.0/20 177.34.80.0/20 177.34.96.0/20 177.34.112.0/21 177.34.120.0/21 177.34.128.0/20 177.34.144.0/20 177.34.160.0/20 177.34.176.0/20 177.34.192.0/19 177.34.224.0/20 177.34.240.0/21 177.34.248.0/21 177.35.0.0/20 177.35.16.0/20 177.35.32.0/21 177.35.40.0/21 177.35.48.0/21 177.35.56.0/21 177.35.58.0/24 177.35.60.0/23 177.35.62.0/23 177.35.64.0/20 177.35.80.0/21 177.35.88.0/21 177.35.96.0/20 177.35.112.0/20 177.35.128.0/19 177.35.160.0/19 177.35.192.0/20 177.35.208.0/20 177.35.224.0/21 177.35.232.0/21 177.35.240.0/21 177.35.248.0/21 177.64.0.0/18 177.64.64.0/19 177.64.96.0/20 177.64.112.0/21 177.64.128.0/19 177.64.160.0/19 177.64.192.0/21 177.64.200.0/21 177.64.208.0/21 177.64.216.0/21 177.64.224.0/19 177.65.0.0/18 177.65.96.0/24 177.65.96.0/20 177.65.97.0/24 177.65.98.0/24 177.65.99.0/24 177.65.102.0/24 177.65.103.0/24 177.65.110.0/24 177.65.111.0/24 177.65.128.0/20 177.65.144.0/20 177.65.160.0/19 177.65.192.0/21 177.65.200.0/21 177.65.208.0/21 177.65.216.0/21 177.65.224.0/20 177.65.240.0/20 177.80.0.0/16 177.81.0.0/19 177.81.0.0/16 177.81.32.0/19 177.81.64.0/19 177.81.72.0/22 177.81.76.0/22 177.81.96.0/19 177.81.128.0/19 177.81.160.0/19 177.81.192.0/19 177.81.224.0/19 177.82.0.0/20 177.82.16.0/21 177.82.24.0/21 177.82.32.0/21 177.82.40.0/21 177.82.48.0/20 177.82.64.0/18 177.82.128.0/21 177.82.136.0/21 177.82.144.0/20 177.82.160.0/20 177.82.176.0/20 177.82.192.0/19 177.82.224.0/20 177.82.240.0/20 177.83.0.0/19 177.83.32.0/21 177.83.40.0/22 177.83.44.0/22 177.83.48.0/20 177.83.64.0/18 177.83.128.0/19 177.83.160.0/19 177.83.192.0/20 177.83.208.0/20 177.83.224.0/21 177.83.232.0/21 177.83.240.0/21 177.83.248.0/21 177.100.0.0/20 177.100.16.0/23 177.100.20.0/22 177.100.24.0/21 177.100.48.0/20 177.100.64.0/20 177.100.80.0/21 177.100.88.0/21 177.100.104.0/22 177.100.108.0/22 177.100.112.0/21 177.100.120.0/21 177.100.128.0/21 177.100.136.0/21 177.100.144.0/21 177.100.152.0/21 177.100.160.0/22 177.100.164.0/23 177.100.168.0/21 177.100.176.0/21 177.100.184.0/21 177.100.192.0/19 177.100.224.0/21 177.100.232.0/22 177.100.236.0/22 177.127.0.0/20 177.127.16.0/21 177.127.24.0/21 177.127.36.0/22 177.127.40.0/22 177.127.48.0/20 177.127.64.0/21 177.127.72.0/21 177.127.80.0/21 177.127.88.0/21 177.127.96.0/21 177.127.104.0/21 177.127.112.0/21 177.127.120.0/21 177.127.128.0/20 177.127.144.0/21 177.127.152.0/21 177.127.160.0/20 177.127.176.0/21 177.127.184.0/21 177.127.192.0/20 177.127.208.0/21 177.127.216.0/21 177.127.224.0/20 177.127.240.0/21 177.127.248.0/21 177.140.0.0/19 177.140.0.0/16 177.140.32.0/19 177.140.64.0/19 177.140.96.0/19 177.140.104.0/22 177.140.128.0/19 177.140.160.0/19 177.140.192.0/19 177.140.224.0/19 177.141.0.0/16 177.141.0.0/19 177.141.32.0/19 177.141.64.0/19 177.141.96.0/19 177.141.128.0/19 177.141.160.0/19 177.141.192.0/19 177.141.224.0/19 177.142.0.0/16 177.143.0.0/17 177.143.128.0/19 177.143.136.0/23 177.143.160.0/20 177.143.176.0/21 177.143.184.0/22 177.143.192.0/21 177.143.200.0/21 177.143.208.0/21 177.143.216.0/21 177.143.224.0/21 177.143.232.0/21 177.143.240.0/20 177.180.0.0/19 177.180.48.0/20 177.180.64.0/19 177.180.96.0/20 177.180.112.0/21 177.180.120.0/21 177.180.128.0/19 177.180.160.0/19 177.180.192.0/19 177.180.224.0/19 177.181.0.0/19 177.181.32.0/19 177.181.64.0/19 177.181.96.0/19 177.181.160.0/21 177.181.168.0/21 177.181.176.0/21 177.181.184.0/21 177.181.192.0/19 177.181.224.0/19 177.182.0.0/17 177.182.128.0/19 177.182.160.0/19 177.182.192.0/19 177.182.224.0/19 177.183.0.0/19 177.183.10.0/23 177.183.32.0/21 177.183.40.0/21 177.183.48.0/21 177.183.56.0/21 177.183.64.0/18 177.183.128.0/19 177.183.160.0/20 177.183.176.0/20 177.183.192.0/20 177.183.208.0/21 177.183.216.0/21 177.183.224.0/21 177.183.232.0/21 177.183.240.0/21 177.183.248.0/21 177.192.0.0/16 177.193.0.0/20 177.193.16.0/20 177.193.32.0/19 177.193.64.0/19 177.193.96.0/20 177.193.112.0/20 177.193.128.0/18 177.193.192.0/19 177.193.224.0/20 177.193.240.0/21 177.193.248.0/21 177.194.0.0/17 177.194.128.0/18 177.194.192.0/19 177.194.224.0/19 177.195.0.0/20 177.195.16.0/20 177.195.32.0/19 177.195.64.0/18 177.195.128.0/18 177.195.208.0/20 177.195.224.0/20 177.195.240.0/20 177.235.0.0/16 179.105.0.0/20 179.105.16.0/20 179.105.32.0/20"
add_flow_control() {
for iface in $IFACES; do
tc qdisc add dev $iface root handle 1: htb default 20
tc class add dev $iface parent 1: classid 1:10 htb rate 1000mbit ceil 1000mbit
for ip in $ASN28573; do
tc filter add dev $iface protocol ip parent 1: prio 1 u32 match ip src $ip flowid 1:10
tc filter add dev $iface protocol ip parent 1: prio 1 u32 match ip dst $ip flowid 1:10
done
done
}
del_flow_control() {
for iface in $IFACES; do
tc qdisc del dev $iface root
done
}
case $1 in
add)
add_flow_control
;;
del)
del_flow_control
;;
*)
echo "Usage: $0 {add|del}"
exit 1
;;
esac