Страница 1 из 6

Ограничение скорости

Добавлено: Пн окт 20, 2008 8:36 am
ran
Поскольку уже устал отвечать в аське - попробую собрать всё до кучи

2AsmodeuS: прилепи будь ласка

1. Туннели (pptp/pppoe)

пишем скрипт

Код: Выделить всё

#!/bin/sh

TC="/sbin/tc"
TCQA="$TC qdisc add dev $IFNAME"
TCQD="$TC qdisc del dev $IFNAME"

$TCQD root &>/dev/null
$TCQD ingress &>/dev/null

$TCQA root handle 1: htb
$TCQA handle ffff: ingress

/usr/abills/libexec/linkupdown ipn up $IFNAME $PEERNAME $IPREMOTE OS=Linux
обзываем его ip-pre-up и кладём его в /etc/ppp не забыв убрать из /etc/ppp/ip-up.local все потуги связанные с шейпером (если таковые имели место быть :) )

Трафик будет шейпится согласно классам, описанным в интервалах ТП (независимо от наличия модуля Ipn) или в соответствии с / Клиенты/ Логины/ Информация/ Сервисы/ Dialup / VPN/Скорость (kb): (более высокий приоритет, независимо от ТП)

2. Чистый Ipn (без туннелей)

Для интерфейса, смотрящего на усеров (желательно перед его поднятием) выполняем скрипт, аналогичный приведённому выше, но без вызова linkupdown

В abills/libexec/config.pl пишем:

Код: Выделить всё

$conf{IPN_FW_START_RULE}="/usr/bin/sudo /usr/abills/libexec/linkupdown ipn up eth0 %LOGIN %IP".' &>/dev/null';
$conf{IPN_FW_STOP_RULE}="/usr/bin/sudo /usr/abills/libexec/linkupdown ipn down eth0 %LOGIN %IP".' &>/dev/null';

Добавлено: Вт ноя 25, 2008 8:30 am
ran
в config.pl желательно прописать

Код: Выделить всё

$conf{IPN_FW_FIRST_RULE}=1;
$conf{IPN_FW_RULE_UID}=1;

Re: Ограничение скорости

Добавлено: Пт авг 07, 2009 6:06 pm
antonmayko
ran писал(а):Поскольку уже устал отвечать в аське - попробую собрать всё до кучи

2AsmodeuS: прилепи будь ласка

1. Туннели (pptp/pppoe)

пишем скрипт

Код: Выделить всё

#!/bin/sh

TC="/sbin/tc"
TCQA="$TC qdisc add dev $IFNAME"
TCQD="$TC qdisc del dev $IFNAME"

$TCQD root &>/dev/null
$TCQD ingress &>/dev/null

$TCQA root handle 1: htb
$TCQA handle ffff: ingress

/usr/abills/libexec/linkupdown ipn up $IFNAME $PEERNAME $IPREMOTE OS=Linux
обзываем его ip-pre-up и кладём его в /etc/ppp не забыв убрать из /etc/ppp/ip-up.local все потуги связанные с шейпером (если таковые имели место быть :) )

Трафик будет шейпится согласно классам, описанным в интервалах ТП (независимо от наличия модуля Ipn) или в соответствии с / Клиенты/ Логины/ Информация/ Сервисы/ Dialup / VPN/Скорость (kb): (более высокий приоритет, независимо от ТП)
Скажите пожалуйста, а чего в Вашем скрипте не работает ограничение исходящей скорости клиента?

Re: Ограничение скорости

Добавлено: Пт авг 07, 2009 6:26 pm
NiTr0
Оно работает. А вот почему у вас не работает - смотрите в опции ядра ;)

Re: Ограничение скорости

Добавлено: Сб авг 08, 2009 7:26 pm
antonmayko
А не подскажете какие именно опции проверить?
Ну очень нужно. :cry:

Re: Ограничение скорости

Добавлено: Пн авг 10, 2009 9:39 am
ran
antonmayko писал(а):А не подскажете какие именно опции проверить?
Ну очень нужно. :cry:
ну для начала посмотреть что там ваще творится

Код: Выделить всё

tc -s -d qdisc ls dev ...
tc -s -d class ls dev ...
tc -s -d filter ls dev ... parent 1:
tc -s -d filter ls dev ... parent ffff:

Re: Ограничение скорости

Добавлено: Пн авг 10, 2009 6:30 pm
antonmayko
Вот правила шейпера (специально поставил на сервак эти, т.к. было сказано, что они работают):

Код: Выделить всё

 TC="/sbin/tc"
TCQA="$TC qdisc add dev $1"
TCQD="$TC qdisc del dev $1"

$TCQD root &>/dev/null
$TCQD ingress &>/dev/null

$TCQA root handle 1: htb
$TCQA handle ffff: ingress

/usr/abills/libexec/linkupdown ipn up $1 $PEERNAME $IPREMOTE OS=Linux
Согласно тарифа, тестовому логину скорость режется так: вх - 512 Kbit, исх - 128 Kbit. Реально на входящей скорости я получаю 58-59 килобайт и это отлично, а на исходящ. - сколько ни жалко.

Вот вывод приведенных Вами, ran, команд:

Код: Выделить всё

spez@newnet-dz:~$tc -s -d qdisc ls dev ppp1
qdisc htb 1: root r2q 10 default 0 direct_packets_stat 0 ver 3.17
 Sent 5365163 bytes 4120 pkt (dropped 138, overlimits 3403 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
qdisc ingress ffff: parent ffff:fff1 ---------------- 
 Sent 799674 bytes 3734 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 

Код: Выделить всё

spez@newnet-dz:~$ tc -s -d class ls dev ppp1
class htb 1:5b1b root prio 0 quantum 6553 rate 524288bit ceil 524288bit burst 1599b/8 mpu 0b overhead 0b cburst 1599b/8 mpu 0b overhead 0b level 0 
 Sent 5366117 bytes 4137 pkt (dropped 138, overlimits 0 requeues 0) 
 rate 208bit 0pps backlog 0b 0p requeues 0 
 lended: 4137 borrowed: 0 giants: 0
 tokens: 21815 ctokens: 21815

Код: Выделить всё

spez@newnet-dz:~$ tc -s -d filter ls dev ppp1 parent 1:
filter protocol ip pref 23323 u32 
filter protocol ip pref 23323 u32 fh 800: ht divisor 1 
filter protocol ip pref 23323 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:5b1b 
  match 00000000/00000000 at 12
  match ac1400a1/ffffffff at 16

Код: Выделить всё

spez@newnet-dz:~$ tc -s -d filter ls dev ppp1 parent ffff:
spez@newnet-dz:~$
Последняя команда ниче не показала.

Re: Ограничение скорости

Добавлено: Ср авг 12, 2009 12:03 pm
morfair
Работает вроде)) Но!! Как это работает??))) Откуда pppd и abills знают про файл /etc/ppp/ip-pre-up???

Re: Ограничение скорости

Добавлено: Ср авг 12, 2009 12:56 pm
NiTr0
morfair писал(а):Откуда pppd и abills знают про файл /etc/ppp/ip-pre-up???
Действительно, откуда pppd может знать о скрипте, который он, согласно man, обязан выполнять перед поднятием интерфейса? :lol:
Курим мануалы, перед тем, как что-то настраивать. И отвыкаем от виндовой привычки "что-то нажать, что - не прочитал".

Re: Ограничение скорости

Добавлено: Ср авг 12, 2009 2:13 pm
morfair
NiTr0 писал(а):
morfair писал(а):Откуда pppd и abills знают про файл /etc/ppp/ip-pre-up???
Действительно, откуда pppd может знать о скрипте, который он, согласно man, обязан выполнять перед поднятием интерфейса? :lol:
Курим мануалы, перед тем, как что-то настраивать. И отвыкаем от виндовой привычки "что-то нажать, что - не прочитал".
он if-up выполнять должен, а не это.... вроде как)

Re: Ограничение скорости

Добавлено: Ср авг 12, 2009 3:43 pm
NiTr0
Сначала - ip-pre-up, дожидается его выполнения, потом - поднимает интерфейс (или ip-pre-up его поднимает - по-разному встречал) и форкает ip-up.

Re: Ограничение скорости

Добавлено: Сб авг 15, 2009 7:05 pm
antonmayko
Уважаемый ran, прокомментируйте пожалуйста мой последний пост. А то меня скоро порвут на части. :cry:

Re: Ограничение скорости

Добавлено: Пн авг 17, 2009 9:16 am
ran
morfair писал(а):
NiTr0 писал(а):
morfair писал(а):Откуда pppd и abills знают про файл /etc/ppp/ip-pre-up???
Действительно, откуда pppd может знать о скрипте, который он, согласно man, обязан выполнять перед поднятием интерфейса? :lol:
Курим мануалы, перед тем, как что-то настраивать. И отвыкаем от виндовой привычки "что-то нажать, что - не прочитал".
он if-up выполнять должен, а не это.... вроде как)
man pppd писал(а):SCRIPTS
Pppd invokes scripts at various stages in its processing which can be used to perform site-specific
ancillary processing. These scripts are usually shell scripts, but could be executable code files
instead. Pppd does not wait for the scripts to finish (except for the ip-pre-up script). The
scripts are executed as root (with the real and effective user-id set to 0), so that they can do
things such as update routing tables or run privileged daemons. Be careful that the contents of
these scripts do not compromise your system's security. Pppd runs the scripts with standard input,
output and error redirected to /dev/null, and with an environment that is empty except for some
environment variables that give information about the link. The environment variables that pppd
sets are:

DEVICE The name of the serial tty device being used.

IFNAME The name of the network interface being used.

IPLOCAL
The IP address for the local end of the link. This is only set when IPCP has come up.

IPREMOTE
The IP address for the remote end of the link. This is only set when IPCP has come up.

PEERNAME
The authenticated name of the peer. This is only set if the peer authenticates itself.

SPEED The baud rate of the tty device.

ORIG_UID
The real user-id of the user who invoked pppd.

PPPLOGNAME
The username of the real user-id that invoked pppd. This is always set.

For the ip-down and auth-down scripts, pppd also sets the following variables giving statistics for
the connection:

CONNECT_TIME
The number of seconds from when the PPP negotiation started until the connection was termi‐
nated.

BYTES_SENT
The number of bytes sent (at the level of the serial port) during the connection.

BYTES_RCVD
The number of bytes received (at the level of the serial port) during the connection.

LINKNAME
The logical name of the link, set with the linkname option.

DNS1 If the peer supplies DNS server addresses, this variable is set to the first DNS server
address supplied.

DNS2 If the peer supplies DNS server addresses, this variable is set to the second DNS server
address supplied.

Pppd invokes the following scripts, if they exist. It is not an error if they don't exist.

/etc/ppp/auth-up
A program or script which is executed after the remote system successfully authenticates
itself. It is executed with the parameters

interface-name peer-name user-name tty-device speed

Note that this script is not executed if the peer doesn't authenticate itself, for example
when the noauth option is used.

/etc/ppp/auth-down
A program or script which is executed when the link goes down, if /etc/ppp/auth-up was previ‐
ously executed. It is executed in the same manner with the same parameters as
/etc/ppp/auth-up.

/etc/ppp/ip-pre-up
A program or script which is executed just before the ppp network interface is brought up.
It is executed with the same parameters as the ip-up script (below). At this point the
interface exists and has IP addresses assigned but is still down. This can be used to add
firewall rules before any IP traffic can pass through the interface. Pppd will wait for this
script to finish before bringing the interface up, so this script should run quickly.


/etc/ppp/ip-up
A program or script which is executed when the link is available for sending and receiving IP
packets (that is, IPCP has come up). It is executed with the parameters

interface-name tty-device speed local-IP-address remote-IP-address ipparam

/etc/ppp/ip-down
A program or script which is executed when the link is no longer available for sending and
receiving IP packets. This script can be used for undoing the effects of the /etc/ppp/ip-up
and /etc/ppp/ip-pre-up scripts. It is invoked in the same manner and with the same parame‐
ters as the ip-up script.

/etc/ppp/ipv6-up
Like /etc/ppp/ip-up, except that it is executed when the link is available for sending and
receiving IPv6 packets. It is executed with the parameters

interface-name tty-device speed local-link-local-address remote-link-local-address ipparam

/etc/ppp/ipv6-down
Similar to /etc/ppp/ip-down, but it is executed when IPv6 packets can no longer be transmit‐
ted on the link. It is executed with the same parameters as the ipv6-up script.

/etc/ppp/ipx-up
A program or script which is executed when the link is available for sending and receiving
IPX packets (that is, IPXCP has come up). It is executed with the parameters

interface-name tty-device speed network-number local-IPX-node-address remote-IPX-node-address
local-IPX-routing-protocol remote-IPX-routing-protocol local-IPX-router-name
remote-IPX-router-name ipparam pppd-pid

The local-IPX-routing-protocol and remote-IPX-routing-protocol field may be one of the fol‐
lowing:

NONE to indicate that there is no routing protocol
RIP to indicate that RIP/SAP should be used
NLSP to indicate that Novell NLSP should be used
RIP NLSP to indicate that both RIP/SAP and NLSP should be used

/etc/ppp/ipx-down
A program or script which is executed when the link is no longer available for sending and
receiving IPX packets. This script can be used for undoing the effects of the
/etc/ppp/ipx-up script. It is invoked in the same manner and with the same parameters as the
ipx-up script.
может ещё и вслух маны тебе почитать??? :evil:

разница между ip-pre-up и ip-up (ну и всего что из него ещё вызывается, ip-up.local например) в том, что первый пппд выполняет когда ппп ифейс уже сконфигурирован но ещё не поднят и дожидается его завершения, а второй пппд выполняет когда ппп ифейс уже поднят (по нему уже впринципе идёт ip-трафик и не дожидается его завершения (он выполняется асинхронно-параллельно с родительским пппд)

Re: Ограничение скорости

Добавлено: Пн авг 17, 2009 9:45 am
ran
antonmayko писал(а):Уважаемый ran, прокомментируйте пожалуйста мой последний пост. А то меня скоро порвут на части. :cry:
запусти руцями

Код: Выделить всё

/usr/abills/libexec/linkupdown ipn up ppp1 логин_усера 1.1.1.1 OS=Linux debug | grep /sbin/tc
и покажи что оно скажет

Re: Ограничение скорости

Добавлено: Пн авг 17, 2009 2:02 pm
antonmayko
Вот, только я не очень понял зачем именно 1.1.1.1:

Код: Выделить всё

spez@newnet-dz:~$ sudo /usr/abills/libexec/linkupdown ipn up ppp1 anton 1.1.1.1 OS=Linux debug | grep /sbin/tc
[sudo] password for spez: 
/sbin/tc filter del dev ppp1 protocol ip parent 1: prio 23003 &>/dev/null
/sbin/tc filter del dev ppp1 protocol ip parent ffff: prio 23002 &>/dev/null
/sbin/tc class del dev ppp1 parent 1: classid 1:59db &>/dev/null
/sbin/tc class add dev ppp1 parent 1: classid 1:59db htb rate 512Kibit
/sbin/tc filter add dev ppp1 protocol ip parent 1: prio 23003 u32 match ip src 0.0.0.0/0 match ip dst 1.1.1.1 flowid 1:59db
/sbin/tc filter add dev ppp1 protocol ip parent ffff: prio 23002 u32 match ip src 1.1.1.1 match ip dst 0.0.0.0/0 police rate 128Kibit burst 12k drop flowid 1:
spez@newnet-dz:~$ 
А как на счет поста №7 (Добавлено: Пн авг 10, 2009 6:30 pm ) ?? И последней команды?