> Вроде как начинаю понимать в чём проблема, но решить пока что не
> могу.
> Дело в том что адрес в локальной сети которому я хочу обрезать
> канал по порту 80, находится под NAT и чтоб TC его
> видел, пакеты нужно промаркировать.
> Уже по всякому пробовал, чуть ли не в каждую цепочку сунул маркировку
> пакетов на 80й порт, но эффекта нет.
> Применял вот такие правила: ...
> В таблицах mangel, nat и filter.
> Ничего не помогает. Видно что пакеты маркируются iptables, но TC их не
> видит.
Вот пример вроде рабочий с одного дачного шлюза:
>>BEGIN RC.SHAPER.CONF
# Devices & params
SH1_IMQ_IN="imq0"
SH1_IMQ_OUT="imq1"
SH1_IFS_IN="eth0"
SH1_IFS_OUT="eth0"
SH2_IMQ_IN="imq2"
SH2_IMQ_OUT="imq3"
SH2_IFS_IN="eth1"
SH2_IFS_OUT="eth1"
SH1_CTRL="22 53 54322"
SH1_COMM="110 995 3373 5190"
SH1_SURF="25 80 443 465 3128 8000 8080"
SH1_OUT_DISCIPLINE="esfq limit 64 depth 256 hash dst perturb 16"
SH1_IN_DISCIPLINE="esfq limit 64 depth 256 hash dst perturb 16"
SH2_CTRL="22 53 54322"
SH2_COMM="110 995 3373 5190"
SH2_SURF="25 80 443 465 3128 8000 8080"
##SH2_OUT_DISCIPLINE="esfq limit 64 depth 256 hash dst perturb 16"
SH2_OUT_DISCIPLINE="esfq limit 64 depth 256 hash src perturb 16"
SH2_IN_DISCIPLINE="esfq limit 64 depth 256 hash dst perturb 16"
# Rate to quantum
# req.: MTU < quantum < 60000
# com.: quantum = RATE / R2Q
# quantum is small if: RATE / R2Q < MTU, try --R2Q or ++RATE
# quantum is big if: RATE / R2Q > 60000, try ++R2Q or --RATE
SH1_R2Q="r2q 24"
SH1_RATEUP="24576"
SH1_RATEDN="24576"
SH1_RATE_OUT0=256
SH1_RATE_OUT1=256
SH1_RATE_OUT2=5120
SH1_RATE_OUT3=1024
SH1_RATE_OUT4=$[$SH1_RATEUP - $SH1_RATE_OUT0 - $SH1_RATE_OUT1 - $SH1_RATE_OUT2 - $SH1_RATE_OUT3]
SH1_RATE_IN0=256
SH1_RATE_IN1=256
SH1_RATE_IN2=5120
SH1_RATE_IN3=1024
SH1_RATE_IN4=$[$SH1_RATEDN - $SH1_RATE_IN0 - $SH1_RATE_IN1 - $SH1_RATE_IN2 - $SH1_RATE_IN3]
SH2_R2Q="r2q 3"
SH2_RATEUP="4096"
SH2_RATEDN="4096"
SH2_RATE_OUT0=256
SH2_RATE_OUT1=512
SH2_RATE_OUT2=1024
SH2_RATE_OUT3=1024
SH2_RATE_OUT4=$[$SH2_RATEUP - $SH2_RATE_OUT0 - $SH2_RATE_OUT1 - $SH2_RATE_OUT2 - $SH2_RATE_OUT3]
SH2_RATE_IN0=256
SH2_RATE_IN1=512
SH2_RATE_IN2=1024
SH2_RATE_IN3=1024
SH2_RATE_IN4=$[$SH2_RATEDN - $SH2_RATE_IN0 - $SH2_RATE_IN1 - $SH2_RATE_IN2 - $SH2_RATE_IN3]
>>END RC.SHAPER.CONF
отрывок из RC.SHAPER
#!/bin/bash
. /etc/rc.d/rc.fw.conf
. /etc/rc.d/rc.shaper.conf
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
export PATH
IPT=/usr/sbin/iptables
LBL_VIP=10
LBL_CTL=20
LBL_STD=30
LBL_AVG=40
LBL_DEF=70
shaper_status() {
echo "======================================[QDISC]======================================"
echo "qdisc show dev $SH1_IMQ_IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s qdisc show dev $SH1_IMQ_IN
echo "qdisc show dev $SH1_IMQ_OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s qdisc show dev $SH1_IMQ_OUT
echo "qdisc show dev $SH2_IMQ_IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s qdisc show dev $SH2_IMQ_IN
echo "qdisc show dev $SH2_IMQ_OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s qdisc show dev $SH2_IMQ_OUT
echo "======================================[CLASS]======================================"
echo "SHAPER >>>> 1 >>>> IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s class show dev $SH1_IMQ_IN
echo "SHAPER >>>> 1 >>>> OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s class show dev $SH1_IMQ_OUT
echo "SHAPER >>>> 2 >>>> IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s class show dev $SH2_IMQ_IN
echo "SHAPER >>>> 2 >>>> OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s class show dev $SH2_IMQ_OUT
echo "=====================================[FILTER]====================================="
echo "SHAPER 1 IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s filter show dev $SH1_IMQ_IN
echo "SHAPER 1 OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s filter show dev $SH1_IMQ_OUT
echo "SHAPER 2 IN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s filter show dev $SH2_IMQ_IN
echo "SHAPER 2 OUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
tc -s filter show dev $SH2_IMQ_OUT
echo "======================================[RULES]======================================"
$IPT -t mangle -L SHAPER1-IN -v -x -n 2> /dev/null
$IPT -t mangle -L SHAPER1-OUT -v -x -n 2> /dev/null
$IPT -t mangle -L SHAPER2-IN -v -x -n 2> /dev/null
$IPT -t mangle -L SHAPER2-OUT -v -x -n 2> /dev/null
}
...
shaper2_outstart() {
ip link set $SH2_IMQ_OUT up
tc qdisc add dev $SH2_IMQ_OUT handle 1: root htb default $LBL_DEF $SH2_R2Q
tc class add dev $SH2_IMQ_OUT parent 1: classid 1:1 htb rate ${SH2_RATEUP}kbit ceil ${SH2_RATEUP}kbit
tc class add dev $SH2_IMQ_OUT parent 1:1 classid 1:$LBL_VIP htb rate ${SH2_RATE_OUT0}kbit ceil ${SH2_RATEUP}kbit prio 0
tc class add dev $SH2_IMQ_OUT parent 1:1 classid 1:$LBL_CTL htb rate ${SH2_RATE_OUT1}kbit ceil ${SH2_RATEUP}kbit prio 1
tc class add dev $SH2_IMQ_OUT parent 1:1 classid 1:$LBL_STD htb rate ${SH2_RATE_OUT2}kbit ceil ${SH2_RATEUP}kbit prio 2
tc class add dev $SH2_IMQ_OUT parent 1:1 classid 1:$LBL_AVG htb rate ${SH2_RATE_OUT3}kbit ceil ${SH2_RATEUP}kbit prio 3
tc class add dev $SH2_IMQ_OUT parent 1:1 classid 1:$LBL_DEF htb rate ${SH2_RATE_OUT4}kbit ceil ${SH2_RATEUP}kbit prio 6
tc qdisc add dev $SH2_IMQ_OUT parent 1:$LBL_VIP handle $LBL_VIP: $SH2_OUT_DISCIPLINE
tc qdisc add dev $SH2_IMQ_OUT parent 1:$LBL_CTL handle $LBL_CTL: $SH2_OUT_DISCIPLINE
tc qdisc add dev $SH2_IMQ_OUT parent 1:$LBL_STD handle $LBL_STD: $SH2_OUT_DISCIPLINE
tc qdisc add dev $SH2_IMQ_OUT parent 1:$LBL_AVG handle $LBL_AVG: $SH2_OUT_DISCIPLINE
tc qdisc add dev $SH2_IMQ_OUT parent 1:$LBL_DEF handle $LBL_DEF: $SH2_OUT_DISCIPLINE
tc filter add dev $SH2_IMQ_OUT parent 1:0 protocol ip prio 0 handle $LBL_VIP fw flowid 1:$LBL_VIP
tc filter add dev $SH2_IMQ_OUT parent 1:0 protocol ip prio 1 handle $LBL_CTL fw flowid 1:$LBL_CTL
tc filter add dev $SH2_IMQ_OUT parent 1:0 protocol ip prio 2 handle $LBL_STD fw flowid 1:$LBL_STD
tc filter add dev $SH2_IMQ_OUT parent 1:0 protocol ip prio 3 handle $LBL_AVG fw flowid 1:$LBL_AVG
tc filter add dev $SH2_IMQ_OUT parent 1:0 protocol ip prio 6 handle $LBL_DEF fw flowid 1:$LBL_DEF
$IPT -t mangle -N SHAPER2-OUT
$IPT -t mangle -A POSTROUTING -o $SH2_IFS_OUT -j SHAPER2-OUT
#$IPT -t mangle -A SHAPER2-OUT -p icmp -j MARK --set-mark $LBL_VIP
$IPT -t mangle -A SHAPER2-OUT -p all -m length --length :128 -j MARK --set-mark $LBL_VIP
for ctrl_out in $SH2_CTRL
do
$IPT -t mangle -A SHAPER2-OUT -p tcp --dport $ctrl_out -j MARK --set-mark $LBL_CTL
$IPT -t mangle -A SHAPER2-OUT -p tcp --sport $ctrl_out -j MARK --set-mark $LBL_CTL
done
for comm_out in $SH2_COMM
do
$IPT -t mangle -A SHAPER2-OUT -p tcp --dport $comm_out -j MARK --set-mark $LBL_STD
$IPT -t mangle -A SHAPER2-OUT -p tcp --sport $comm_out -j MARK --set-mark $LBL_STD
done
$IPT -t mangle -A SHAPER2-OUT -p sctp -j MARK --set-mark $LBL_STD
for surf_out in $SH2_SURF
do
$IPT -t mangle -A SHAPER2-OUT -p tcp --dport $surf_out -j MARK --set-mark $LBL_AVG
$IPT -t mangle -A SHAPER2-OUT -p tcp --sport $surf_out -j MARK --set-mark $LBL_AVG
done
$IPT -t mangle -A SHAPER2-OUT -m mark --mark 0 -j MARK --set-mark $LBL_DEF
$IPT -t mangle -A SHAPER2-OUT -j IMQ --todev 3
####################################################
echo "Outbound shaping added($SH2_IMQ_OUT), rate: ${SH2_RATEUP}Kbit/sec."
echo "Default rate: ${SH2_RATE_OUT4}Kbit/sec."
}