segfault/router/tc.sh

46 lines
1.3 KiB
Bash
Raw Normal View History

2022-07-27 21:50:51 +00:00
#! /bin/bash
tc_set()
{
local dev
local rate
dev="$1"
rate="$2"
# Installs a class based queue
2022-07-28 13:33:08 +00:00
tc qdisc add dev "${dev}" root handle 1: cbq avpkt 1000 bandwidth 1000mbit
2022-07-27 21:50:51 +00:00
# Create a shaped class
2022-07-28 13:33:08 +00:00
tc class add dev "${dev}" parent 1: classid 1:1 cbq rate "${rate:-1000Mbit}" \
2022-07-27 21:50:51 +00:00
allot 1500 prio 5 bounded isolated
# Send all traffic through the shaped class
2022-09-17 18:39:19 +00:00
# Amazon Linux 2 does not come with cls_matchall module
2022-09-18 11:42:52 +00:00
tc filter add dev "${dev}" parent 1: matchall flowid 1:1 || { echo -e >&2 "cls_matchall.ko not available? NO TRAFFIC LIMIT."; sleep 5; return 0; }
2022-07-27 21:50:51 +00:00
}
2022-09-18 11:42:52 +00:00
unset SF_MAXOUT
unset SF_MAXIN
eval "$(grep ^SF_MAX /config/host/etc/sf/sf.conf)"
[[ -z $SF_MAXOUT ]] && [[ -z $SF_MAXIN ]] && { echo -e >&2 "WARNING: NO TRAFFIC LIMIT configured."; exit 0; }
2022-07-27 21:50:51 +00:00
2022-08-09 06:28:47 +00:00
# User's INCOMING traffic to his shell. Normally not limited.
DEV_SHELL=${1:-eth1}
# All outgoing interfaces
DEV_GW=${2:-eth3} # Traffic via VPN (User's shell)
DEV_I22=${3:-eth0} # SSHD return traffic to User
2022-07-27 21:50:51 +00:00
# Delete all. This might set $? to false
2022-08-09 06:28:47 +00:00
tc qdisc del dev "${DEV_GW}" root 2>/dev/null
tc qdisc del dev "${DEV_I22}" root 2>/dev/null
true # force $? to be true
2022-09-18 11:42:52 +00:00
[[ -n $SF_MAXOUT ]] && { tc_set "${DEV_GW}" "${SF_MAXOUT}" || exit 255; }
[[ -n $SF_MAXOUT ]] && { tc_set "${DEV_I22}" "${SF_MAXOUT}" || exit 255; }
2022-07-27 21:50:51 +00:00
2022-09-18 11:42:52 +00:00
[[ -n $SF_MAXIN ]] && { tc_set "${DEV_SHELL}" "${SF_MAXIN}" || exit 255; }
2022-07-27 21:50:51 +00:00
exit 0