Created
December 26, 2020 09:24
-
-
Save grifferz/d17e68ba4625479f1409d655fe7f40ac to your computer and use it in GitHub Desktop.
Hacky script to use an ifb interface to shape traffic both ways on another interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# shaper.sh eth1 clear # removes traffic shaping | |
# shaper.sh eth1 1000 # shapes eth1 to 1Mbit/s in both directions | |
# Andy Smith <[email protected]> | |
intf="$1" | |
bw="$2" | |
ifb="ifb0" | |
if ! grep -q ^ifb /proc/modules; then | |
modprobe ifb numifbs=1 | |
fi | |
if [ "$bw" = "clear" ] || [ "$bw" = "delete" ]; then | |
tc qdisc del dev "$intf" handle ffff: ingress 2>/dev/null || true | |
tc qdisc del dev "$intf" root 2>/dev/null || true | |
tc qdisc del dev "$ifb" root 2>/dev/null || true | |
ip link set dev "$ifb" down >/dev/null 2>&1 || true | |
else | |
ip link set dev "$ifb" up >/dev/null 2>&1 || true | |
tc qdisc del dev "$intf" handle ffff: ingress 2>/dev/null || true | |
tc qdisc del dev "$intf" root 2>/dev/null || true | |
tc qdisc del dev "$ifb" root 2>/dev/null || true | |
tc qdisc add dev "$intf" handle ffff: ingress | |
tc filter add dev "$intf" parent ffff: protocol all prio 50 \ | |
u32 match u32 0 0 action mirred egress redirect dev "$ifb" | |
tc qdisc add dev "$intf" root tbf \ | |
rate "$bw"kbit latency 25ms burst 10k | |
tc qdisc add dev "$ifb" root tbf \ | |
rate "$bw"kbit latency 25ms burst 10k | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment