2012年8月14日 星期二

ACCEL-PPP


Overview
--------
The ACCEL-PPP v1.0 is completly new implementation of PPTP/PPPoE/L2TP which was written from scratch.
Userspace daemon has its own PPP implementation, so it does not uses pppd and one process (multi-threaded) manages all connections.
ACCEL-PPP uses only kernel-mode implementations of pptp/l2tp/pppoe.


Features
--------
1.  Modular architecture
2.  High-performance multi-threaded I/O core
3.  Supported PPTP
4.  Supported PPPoE (including TR-101 extension)
5.  Supported L2TPv2 (without IPsec)
5.  Radius authentication/accounting
6.  Radius DM/CoA extention
7.  Supported authentication types: PAP, CHAP (md5), Microsoft CHAP Extentions (including version 2), not supported - EAP
8.  Supported MPPE
9.  Compression is not supported
10. Extensible logging engine with per session logging support, implemented log to file, log to remote host and log to PostgreSQL targets
11. Extensible user/password database, implemented Radius, pppd compatible chap-secrets sources
12. Extensible IP pool, implemented Radius, chap-secrets and static pools
13. Supported pppd compatible ip-up/ip-down scripts
14. Builtin tbf/htb shaper manager
15. Command line interface via telnet
16. SNMP support (master or subagent via AgentX)


Requirment
----------
1. modern linux distribution
2. kernel-2.6.25 or later
4. cmake-2.6 or later
5. libnl-2.0 or probably later (required for builtin shaper)
6. libcrypto-0.9.8 or probably later (openssl-0.9.8)
7. libpcre
8. net-snmp-5.x 


Compilation and instalation
-----------
Make sure you have configured kernel headers in /usr/src/linux,
or specify other location via KDIR.
1. cd /path/to/accel-ppp-1.3.5
2. mkdir build
3. cd build
4. cmake [-DBUILD_DRIVER=FALSE] [-DKDIR=/usr/src/linux] [-DCMAKE_INSTALL_PREFIX=/usr/local] [-DCMAKE_BUILD_TYPE=Release] [-DLOG_PGSQL=FALSE] [-DSHAPER=FALSE] [-DRADIUS=TRUE] [-DNETSNMP=FALSE] ..
   Please note that the double dot record in the end of the command is essential. You'll probably get error or misconfigured sources if you miss it.
   BUILD_DRIVER, KDIR, CMAKE_INSTALL_PREFIX, CMAKE_BUILD_TYPE, LOG_PGSQL, SHAPER, RADIUS  are optional,
   But while pptp is not present in mainline kernel you probably need BUILD_DRIVER.
   For example:
   cmake -DBUILD_DRIVER=TRUE ..
   will configure sources to build pptp driver, search kernel headers at /usr/src/linux, install to /usr/local,
   build with no debug, pgsql and shaper support, build with radius support.
5. If you want to use chap-secrets for authentication purpose then you need to disable radius support, configure as following:
   cmake -DBUILD_DRIVER=TRUE -DRADIUS=FALSE ..
   of course you can include additional options if needed.
6. make
7. make install


Configuration
-------------
read man accel-ppp.conf


Built-in shaper
--------------
accel-ppp supports tbf and htb based shaper manager.
To enable it uncomment shaper in [modules] section.
It accepts radius attributes in various formats: rate, down-rate/up-rate and cisco-like. Values have to be in kilobits except cisco-like.
For example:
Filter-Id=1000 (means 1000Kbit both up-stream and down-stream rate)
Filter-Id=2000/3000 (means 2000Kbit down-stream rate and 3000Kbit up-stream rate)
To change radius attribute which containes rate information use 'attr' option, for example:
[shaper]
attr=My-Custom-Rate-Attribute
of course this attribute have to be in radius dictionary.
To specify different attributes for down-stream and up-stream rates use 'attr-down' and 'attr-up' options, for example:
[shaper]
attr-down=PPPD-Downstream-Speed
attr-up=PPPD-Upstream-Speed

If you want to use cisco-like format configure accel-ppp as following:
[shaper]
vendor=Cisco
attr=Cisco-AVPair
and send two attributes:
Cisco-AVPair=lcp:interface-config#1=rate-limit input 2000000 8000 8000 conform-action transmit exceed-action drop (which means 2000Kbit up-stream rate and 8Kb burst)
Cisco-AVPair=lcp:interface-config#1=rate-limit output 2000000 8000 8000 conform-action transmit exceed-action drop (which means 2000Kbit down-stream rate and 8Kb burst)


Advanced shaper using
---------------------
1. Burst configuration.
If you not using cisco-like format then burst calculates from rate and specified burst factors.
To specify burst factors use 'down-burst-factor' and 'up-burst-factor' options, for example:
[shaper]
down-burst-factor=1.0
up-burst-factor=10.0
which means that burst for tbf/htb qdisc will be calculated as down-stream rate multiply to 1.0 and burst for policer/htb will be calculated as up-stream rate multiply to 10.0.

2. Time ranges.
You can specify time ranges to authomatic rate reconfiguration.
To specify time ranges use following sample configuration:
[shaper]
time-range=1,1:00-3:00
time-range=2,3:00-5:00
time-range=3,5:00-7:00
first number is time range identifier.
To specify time range specific rates use following format of radius attributes: range-id,rate, range-id,down-rate/up-rate or cisco-like, for example:
Filter-Id=1000
Filter-Id=1,2000
Filter-Id=2,3000
Filter-Id=3,4000
which means: set 1000Kbit by default, set 2000Kbit in time range 1, set 3000Kbit in time range 2, set 4000Kbit in time range 3.
You have to pass multiple Filter-Id attributes to utilize this functionality.
Or cisco-like:
Cisco-AVPair=lcp:interface-config#1=rate-limit output access-group 1 1000000 8000 8000 conform-action transmit exceed-action drop
Cisco-AVPair=lcp:interface-config#1=rate-limit input access-group 1 1000000 8000 8000 conform-action transmit exceed-action drop
and so on...

3. chap-secrets.
If you use chap-secrets instead of radius then there is way to utilize built-in shaper too.
The optional fifth column in chap-secrets file is used to pass rate information to shaper.
Its format is same as for radius attributes, except you cann't utilize time ranges functionality.


SNMP
----
SNMP is implemented using net-snmp libraries. By default accel-ppp starts in subagent mode,
so make sure that net-snmp configured with subagent control turned on (read net-snmp's README.agentx for more details).
Also you can start accel-ppp as master agent using following configuration:
[snmp]
master=1

Usage:
Place accel-pppd/extra/net-snmp/ACCEL-PPP-MIB.txt to your mibs directory.
Also you can find used numerical oids in this file.
1. Requesting statistics:
snmpwalk -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::accelPPPStat
2. Requesting sessions:
snmptable -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::sessionsTable
3. Terminate session by session identifier (Acct-Session-ID):
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termBySID.0 = 0000000000000001
4. Terminate session by interface name:
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByIfName.0 = ppp2
5. Terminaten session by IP address (Framed-IP-Address):
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByIP.0 = 192.168.10.10
6. Terminate session by username:
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByUsername.0 = user1
7. Execute cli command:
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::cli.0 = "shaper change all 1024 temp"



Warning !!!
-----------
1. The pptp driver conflicts with ip_gre driver (in kernel), so make sure that ip_gre is not built-in or loaded at run time
   (don't matter if you have 2.6.37 or later kernel).
2. Don't mix connections of accel-ppp and poptop's pptpd, before starting accel-ppp make sure that no connections
   of pptpd exists.


Contacts
--------
http://accel-ppp.sourceforge.net/
mail: xeb@mail.ru
ICQ: 337258064
Jabber: xeb@xeb.homelinux.net

Using pppoe kernel-mode, HOW-TO

Ref:http://norean.freecontrib.org/nakooki/SVN/snapshot/nakooki/0.3/docs/pppoe-HOW-TO.html

2012年8月7日 星期二

Linux 無線網路 WEP/WPA 手動設定(iwpriv


個人用的無線網路的加密大概可分以下幾種:
OPEN/NONE 完全無加密,人人皆可用
OPEN/WEP 使用WEP靜態加密,防君子不防小人
SHARE/WEP 使用WEP靜態加密,防君子不防小人
WPA/TKIP, AES, or TKIP/AES 使用WPA加密,算是比較安全的方式
WPA2/TKIP, AES, or TKIP/AES WPA的升級版
WPAWPA2/TKIP, AES, or TKIP/AES 混合WPA/WPA2的相容模式

以下按設定的分為三種:無加密,WEP靜態加密跟WPA動態加密
無加密(OPEN/NONE)
ifconfig ra0 up
iwpriv ra0 set NetworkType=Infra
iwpriv ra0 set AuthMode=OPEN
iwpriv ra0 set EncrypType=NONE
iwpriv ra0 set SSID="dht"
dhclient ra0

WEP靜態加密
OPEN/WEP
ifconfig ra0 up
iwconfig ra0 essid "dht"
iwconfig ra0 key open
iwconfig ra0 key aabbccddee *注1
iwconfig ra0 mode managed 

SHARE/WEP
killall wpa_supplicant
ifconfig ra0 up
iwconfig ra0 essid "dht"
iwconfig ra0 key restricted
iwconfig ra0 key aabbccddee *注1
iwconfig ra0 mode managed 

*注:加密金鑰的寫法可以是
十六進位表示法(10或者26個十六進位數字):31323334353637383930
ASCII字元表示法(5或13個英文字母):s:1234567890

WPA/WPA2
killall wpa_supplicant
ifconfig ra0 up
wpa_passphrase dht 123456789 > /tmp/wpa.conf *註2
wpa_supplicant -BDwext -ira0 -c/tmp/wpa.conf
dhclient ra0

*註2:WPA的共享金鑰長度是8~32bytes

應用上述幾種方法,大概就可以解決所有個人無線網路設定的問題

延伸閱讀:
Ubuntu Linux 設定 Wirelss(WiFi) WPA
How To: Manual Network Configuration without the need for Network Manager.

2012年7月24日 星期二

VirtualBox 複製vdi 及 修改 uuid

如果要複製一份 vdi檔,最好是複製的同時可以對新的印象檔重新產生新的 uuid。 
 
VBoxManage clonevdi Orig.vdi New.vdi 
 
例如:C:\Program Files\Oracle\VirtualBox>VBoxManage clonevdi e:\VirtualBox\XP-DEMO.vdi XP-DEMO2.vdi 
 
 
 
如果不幸複製完後才發現,還是有指令可以補救。 
 
VirutalBox 4.0 之後版本: 
 
VBoxManage internalcommands sethduuid New.vdi 
 
VirutalBox 3.2 之前版本: 
VBoxManage internalcommands setvdiuuid New.vdi 
 
如此就可以針對 New.vdi 亂數再產生新的 uuid。

2012年7月6日 星期五

TC (traffic control)


一、TC原理介紹
Linux操作系統中的流量控制器TC(Traffic Control)用於Linux內核的流量控制,主要是通過在輸出端口處建立一個隊列來實現流量控制。
Linux流量控制的基本原理如下圖所示。
Linux下TC使用說明_^_^開心^

接收包從輸入接口(Input Interface)進來後,經過流量限制(Ingress Policing)丟棄不符合規定的數據包,由輸入多路分配器(Input De-Multiplexing)進行判斷選擇:如果接收包的目的是本主機,那麼將該包送給上層處理;否則需要進行轉發,將接收包交到轉發塊(Forwarding Block)處理。轉發塊同時也接收本主機上層(TCP、UDP等)產生的包。轉發塊通過查看路由表,決定所處理包的下一跳。然後,對包進行排列以便將它們傳送到輸出接口(Output Interface)。一般我們只能限制網卡發送的數據包,不能限制網卡接收的數據包,所以我們可以通過改變發送次序來控制傳輸速率。Linux流量控制主要是在輸出接口排列時進行處理和實現的。
二、TC規則
1、流量控制方式
流量控制包括以下幾種方式:
SHAPING(限制)
     當流量被限制,它的傳輸速率就被控制在某個值以下。限制值可以大大小於有效帶寬,這樣可以平滑突發數據流量,使網絡更爲穩定。shaping(限制)只適用於向外的流量。
SCHEDULING(調度)
     通過調度數據包的傳輸,可以在帶寬範圍內,按照優先級分配帶寬。SCHEDULING(調度)也只適於向外的流量。
POLICING(策略)
     SHAPING用於處理向外的流量,而POLICIING(策略)用於處理接收到的數據。
DROPPING(丟棄)
     如果流量超過某個設定的帶寬,就丟棄數據包,不管是向內還是向外。
2、流量控制處理對象
流量的處理由三種對象控制,它們是:qdisc(排隊規則)、class(類別)和filter(過濾器)。
QDISC(排隊規則)
     QDisc(排隊規則)是queueing discipline的簡寫,它是理解流量控制(traffic control)的基礎。無論何時,內核如果需要通過某個網絡接口發送數據包,它都需要按照爲這個接口配置的qdisc(排隊規則)把數據包加入隊列。然後,內核會儘可能多地從qdisc裏面取出數據包,把它們交給網絡適配器驅動模塊。最簡單的QDisc是pfifo它不對進入的數據包做任何的處理,數據包採用先入先出的方式通過隊列。不過,它會保存網絡接口一時無法處理的數據包。
QDISC的類別如下:
(1)、CLASSLESS QDisc(不可分類QDisc)
1>無類別QDISC包括:
[p|b]fifo
使用最簡單的qdisc,純粹的先進先出。只有一個參數:limit,用來設置隊列的長度,pfifo是以數據包的個數爲單位;bfifo是以字節數爲單位。
pfifo_fast
在編譯內核時,如果打開了高級路由器(Advanced Router)編譯選項,pfifo_fast就是系統的標準QDISC。它的隊列包括三個波段(band)。在每個波段裏面,使用先進先出規則。而三個波段(band)的優先級也不相同,band 0的優先級最高,band 2的最低。如果band裏面有數據包,系統就不會處理band 1裏面的數據包,band 1和band 2之間也是一樣。數據包是按照服務類型(Type of Service,TOS)被分配多三個波段(band)裏面的。
red是Random Early Detection(隨機早期探測)的簡寫。如果使用這種QDISC,當帶寬的佔用接近於規定的帶寬時,系統會隨機地丟棄一些數據包。它非常適合高帶寬應用。
sfq是Stochastic Fairness Queueing的簡寫。它按照會話(session--對應於每個TCP連接或者UDP流)爲流量進行排序,然後循環發送每個會話的數據包。
tbf是Token Bucket Filter的簡寫,適合於把流速降低到某個值。
2>不可分類QDisc的配置
如果沒有可分類QDisc,不可分類QDisc只能附屬於設備的根。它們的用法如下:
    tc qdisc add dev DEV root QDISC QDISC-PARAMETERS
要刪除一個不可分類QDisc,需要使用如下命令:
    tc qdisc del dev DEV root
一個網絡接口上如果沒有設置QDisc,pfifo_fast就作爲缺省的QDisc。
(2)、CLASSFUL QDISC(分類QDisc)
可分類的QDisc包括:
CBQ是Class Based Queueing(基於類別排隊)的縮寫。它實現了一個豐富的連接共享類別結構,既有限制(shaping)帶寬的能力,也具有帶寬優先級管理的能力。帶寬限制是通過計算連接的空閒時間完成的。空閒時間的計算標準是數據包離隊事件的頻率和下層連接(數據鏈路層)的帶寬。
HTB是Hierarchy Token Bucket的縮寫。通過在實踐基礎上的改進,它實現了一個豐富的連接共享類別體系。使用HTB可以很容易地保證每個類別的帶寬,雖然它也允許特定的類可以突破帶寬上限,佔用別的類的帶寬。HTB可以通過TBF(Token Bucket Filter)實現帶寬限制,也能夠劃分類別的優先級。
PRIO
PRIO QDisc不能限制帶寬,因爲屬於不同類別的數據包是順序離隊的。使用PRIO QDisc可以很容易對流量進行優先級管理,只有屬於高優先級類別的數據包全部發送完畢,纔會發送屬於低優先級類別的數據包。爲了方便管理,需要使用iptables或者ipchains處理數據包的服務類型(Type Of Service,ToS)。
CLASS(類)
      某些QDisc(排隊規則)可以包含一些類別,不同的類別中可以包含更深入的QDisc(排隊規則),通過這些細分的QDisc還可以爲進入的隊列的數據包排隊。通過設置各種類別數據包的離隊次序,QDisc可以爲設置網絡數據流量的優先級。
FILTER(過濾器)
     Filter(過濾器)用於爲數據包分類,決定它們按照何種QDisc進入隊列。無論何時數據包進入一個劃分子類的類別中,都需要進行分類。分類的方法可以有多種,使用fileter(過濾器)就是其中之一。使用filter(過濾器)分類時,內核會調用附屬於這個類(class)的所有過濾器,直到返回一個判決。如果沒有判決返回,就作進一步的處理,而處理方式和QDISC有關。需要注意的是,filter(過濾器)是在QDisc內部,它們不能作爲主體。
3、操作原理
類(Class)組成一個樹,每個類都只有一個父類,而一個類可以有多個子類。某些QDisc(例如:CBQ和HTB)允許在運行時動態添加類,而其它的QDisc(例如:PRIO)不允許動態建立類。允許動態添加類的QDisc可以有零個或者多個子類,由它們爲數據包排隊。此外,每個類都有一個葉子QDisc,默認情況下,這個葉子QDisc使用pfifo的方式排隊,我們也可以使用其它類型的QDisc代替這個默認的QDisc。而且,這個葉子葉子QDisc有可以分類,不過每個子類只能有一個葉子QDisc。
當一個數據包進入一個分類QDisc,它會被歸入某個子類。我們可以使用以下三種方式爲數據包歸類,不過不是所有的QDisc都能夠使用這三種方式。
tc過濾器(tc filter)
如果過濾器附屬於一個類,相關的指令就會對它們進行查詢。過濾器能夠匹配數據包頭所有的域,也可以匹配由ipchains或者iptables做的標記。
服務類型(Type of Service)
某些QDisc有基於服務類型(Type of Service,ToS)的內置的規則爲數據包分類。
skb->priority
用戶空間的應用程序可以使用SO_PRIORITY選項在skb->priority域設置一個類的ID。
樹的每個節點都可以有自己的過濾器,但是高層的過濾器也可以直接用於其子類。
如果數據包沒有被成功歸類,就會被排到這個類的葉子QDisc的隊中。相關細節在各個QDisc的手冊頁中。
4、命名規則
所有的QDisc、類和過濾器都有ID。ID可以手工設置,也可以有內核自動分配。ID由一個主序列號和一個從序列號組成,兩個數字用一個冒號分開。
QDISC
一個QDisc會被分配一個主序列號,叫做句柄(handle),然後把從序列號作爲類的命名空間。句柄採用象10:一樣的表達方式。習慣上,需要爲有子類的QDisc顯式地分配一個句柄。
類(CLASS)
在同一個QDisc裏面的類分享這個QDisc的主序列號,但是每個類都有自己的從序列號,叫做類識別符(classid)。類識別符只與父QDisc有關,和父類無關。類的命名習慣和QDisc的相同。
過濾器(FILTER)
過濾器的ID有三部分,只有在對過濾器進行散列組織纔會用到。詳情請參考tc-filters手冊頁。
5、單位
tc命令的所有參數都可以使用浮點數,可能會涉及到以下計數單位。
1》帶寬或者流速單位:
kbps                            千字節/秒
mbps                           兆字節/秒
kbit                             KBits/秒
mbit                            MBits/秒
bps或者一個無單位數字      字節數/秒
2》數據的數量單位:
kb或者k                      千字節
mb或者m                    兆字節
mbit                          兆bit
kbit                           千bit
b或者一個無單位數字       字節數
3》時間的計量單位:
s、sec或者secs                              秒
ms、msec或者msecs                       分鐘
us、usec、usecs或者一個無單位數字    微秒
三、TC命令
tc可以使用以下命令對QDisc、類和過濾器進行操作:
在一個節點里加入一個QDisc、類或者過濾器。添加時,需要傳遞一個祖先作爲參數,傳遞參數時既可以使用ID也可以直接傳遞設備的根。如果要建立一個QDisc或者過濾器,可以使用句柄(handle)來命名;如果要建立一個類,可以使用類識別符(classid)來命名。
remove
刪除有某個句柄(handle)指定的QDisc,根QDisc(root)也可以刪除。被刪除QDisc上的所有子類以及附屬於各個類的過濾器都會被自動刪除。
change
以替代的方式修改某些條目。除了句柄(handle)和祖先不能修改以外,change命令的語法和add命令相同。換句話說,change命令不能一定節點的位置。
replace
對一個現有節點進行近於原子操作的刪除/添加。如果節點不存在,這個命令就會建立節點。
link
只適用於DQisc,替代一個現有的節點。
例:
tc qdisc [ add | change | replace | link ] dev DEV [ parent qdisc-id | root ] [ handle qdisc-id ] qdisc [ qdisc specific parameters ]
tc class [ add | change | replace ] dev DEV parent qdisc-id [ classid class-id ] qdisc [ qdisc specific parameters ]
tc filter [ add | change | replace ] dev DEV [ parent qdisc-id | root ] protocol protocol prio priority filtertype [ filtertype specific parameters ] flowid flow-id
tc [-s | -d ] qdisc show [ dev DEV ]
tc [-s | -d ] class show dev DEV tc filter show dev DEV
四、具體操作
Linux流量控制主要分爲建立隊列、建立分類和建立過濾器三個方面。
1、基本實現步驟爲:
(1) 針對網絡物理設備(如以太網卡eth0)綁定一個隊列QDisc;
(2) 在該隊列上建立分類class;
(3) 爲每一分類建立一個基於路由的過濾器filter;
(4) 最後與過濾器相配合,建立特定的路由表。
2、環境模擬實例:
流量控制器上的以太網卡(eth0) 的IP地址爲192.168.1.66,在其上建立一個CBQ隊列。假設包的平均大小爲1000字節,包間隔發送單元的大小爲8字節,可接收衝突的發送最長包數目爲20字節。
假如有三種類型的流量需要控制:
      1) 是發往主機1的,其IP地址爲192.168.1.24。其流量帶寬控制在8Mbit,優先級爲2;
      2) 是發往主機2的,其IP地址爲192.168.1.30。其流量帶寬控制在1Mbit,優先級爲1;
      3) 是發往子網1的,其子網號爲192.168.1.0,子網掩碼爲255.255.255.0。流量帶寬控制在1Mbit,優先級爲6。
1. 建立隊列
一般情況下,針對一個網卡只需建立一個隊列。
將一個cbq隊列綁定到網絡物理設備eth0上,其編號爲1:0;網絡物理設備eth0的實際帶寬爲10 Mbit,包的平均大小爲1000字節;包間隔發送單元的大小爲8字節,最小傳輸包大小爲64字節。
・tc qdisc add dev eth0 root handle 1: cbq bandwidth 10Mbit avpkt 1000 cell 8 mpu 64
2. 建立分類
分類建立在隊列之上。
一般情況下,針對一個隊列需建立一個根分類,然後再在其上建立子分類。對於分類,按其分類的編號順序起作用,編號小的優先;一旦符合某個分類匹配規則,通過該分類發送數據包,則其後的分類不再起作用。
1) 創建根分類1:1;分配帶寬爲10Mbit,優先級別爲8。
・tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 10Mbit rate 10Mbit maxburst 20 allot 1514 prio 8 avpkt 1000 cell 8 weight 1Mbit
該隊列的最大可用帶寬爲10Mbit,實際分配的帶寬爲10Mbit,可接收衝突的發送最長包數目爲20字節;最大傳輸單元加MAC頭的大小爲1514字節,優先級別爲8,包的平均大小爲1000字節,包間隔發送單元的大小爲8字節,相應於實際帶寬的加權速率爲1Mbit。
2)創建分類1:2,其父分類爲1:1,分配帶寬爲8Mbit,優先級別爲2。
・tc class add dev eth0 parent 1:1 classid 1:2 cbq bandwidth 10Mbit rate 8Mbit maxburst 20 allot 1514 prio 2 avpkt 1000 cell 8 weight 800Kbit split 1:0 bounded
該隊列的最大可用帶寬爲10Mbit,實際分配的帶寬爲 8Mbit,可接收衝突的發送最長包數目爲20字節;最大傳輸單元加MAC頭的大小爲1514字節,優先級別爲1,包的平均大小爲1000字節,包間隔發送單元的大小爲8字節,相應於實際帶寬的加權速率爲800Kbit,分類的分離點爲1:0,且不可借用未使用帶寬。
3)創建分類1:3,其父分類爲1:1,分配帶寬爲1Mbit,優先級別爲1。
・tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 10Mbit rate 1Mbit maxburst 20 allot 1514 prio 1 avpkt 1000 cell 8 weight 100Kbit split 1:0
該隊列的最大可用帶寬爲10Mbit,實際分配的帶寬爲 1Mbit,可接收衝突的發送最長包數目爲20字節;最大傳輸單元加MAC頭的大小爲1514字節,優先級別爲2,包的平均大小爲1000字節,包間隔發送單元的大小爲8字節,相應於實際帶寬的加權速率爲100Kbit,分類的分離點爲1:0。
4)創建分類1:4,其父分類爲1:1,分配帶寬爲1Mbit,優先級別爲6。
・tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 10Mbit rate 1Mbit maxburst 20 allot 1514 prio 6 avpkt 1000 cell 8 weight 100Kbit split 1:0
該隊列的最大可用帶寬爲10Mbit,實際分配的帶寬爲1Mbit,可接收衝突的發送最長包數目爲20字節;最大傳輸單元加MAC頭的大小爲1514字節,優先級別爲6,包的平均大小爲1000字節,包間隔發送單元的大小爲8字節,相應於實際帶寬的加權速率爲100Kbit,分類的分離點爲1:0。
3. 建立過濾器
過濾器主要服務於分類。
一般只需針對根分類提供一個過濾器,然後爲每個子分類提供路由映射。
1) 應用路由分類器到cbq隊列的根,父分類編號爲1:0;過濾協議爲ip,優先級別爲100,過濾器爲基於路由表。
・tc filter add dev eth0 parent 1:0 protocol ip prio 100 route
2) 建立路由映射分類1:2, 1:3, 1:4
・tc filter add dev eth0 parent 1:0 protocol ip prio 100 route to 2 flowid 1:2
・tc filter add dev eth0 parent 1:0 protocol ip prio 100 route to 3 flowid 1:3
・tc filter add dev eth0 parent 1:0 protocol ip prio 100 route to 4 flowid 1:4
4.建立路由
該路由是與前面所建立的路由映射一一對應。
1) 發往主機192.168.1.24的數據包通過分類2轉發(分類2的速率8Mbit)
・ip route add 192.168.1.24 dev eth0 via 192.168.1.66 realm 2
2) 發往主機192.168.1.30的數據包通過分類3轉發(分類3的速率1Mbit)
・ip route add 192.168.1.30 dev eth0 via 192.168.1.66 realm 3
3)發往子網192.168.1.0/24的數據包通過分類4轉發(分類4的速率1Mbit)
・ip route add 192.168.1.0/24 dev eth0 via 192.168.1.66 realm 4
注:一般對於流量控制器所直接連接的網段建議使用IP主機地址流量控制限制,不要使用子網流量控制限制。如一定需要對直連子網使用子網流量控制限制,則在建立該子網的路由映射前,需將原先由系統建立的路由刪除,纔可完成相應步驟。
5. 監視
主要包括對現有隊列、分類、過濾器和路由的狀況進行監視。
1)顯示隊列的狀況
簡單顯示指定設備(這裏爲eth0)的隊列狀況
・tc qdisc ls dev eth0
qdisc cbq 1: rate 10Mbit (bounded,isolated) prio no-transmit
詳細顯示指定設備(這裏爲eth0)的隊列狀況
・tc -s qdisc ls dev eth0
qdisc cbq 1: rate 10Mbit (bounded,isolated) prio no-transmit
     Sent 7646731 bytes 13232 pkts (dropped 0, overlimits 0)
     borrowed 0 overactions 0 avgidle 31 undertime 0
這裏主要顯示了通過該隊列發送了13232個數據包,數據流量爲7646731個字節,丟棄的包數目爲0,超過速率限制的包數目爲0。
2)顯示分類的狀況
簡單顯示指定設備(這裏爲eth0)的分類狀況
・tc class ls dev eth0
class cbq 1: root rate 10Mbit (bounded,isolated) prio no-transmit
      class cbq 1:1 parent 1: rate 10Mbit prio no-transmit #no-transmit表示優先級爲8
     class cbq 1:2 parent 1:1 rate 8Mbit prio 2
     class cbq 1:3 parent 1:1 rate 1Mbit prio 1
     class cbq 1:4 parent 1:1 rate 1Mbit prio 6
詳細顯示指定設備(這裏爲eth0)的分類狀況
・tc -s class ls dev eth0
class cbq 1: root rate 10Mbit (bounded,isolated) prio no-transmit
     Sent 17725304 bytes 32088 pkts (dropped 0, overlimits 0)
     borrowed 0 overactions 0 avgidle 31 undertime 0
     class cbq 1:1 parent 1: rate 10Mbit prio no-transmit
     Sent 16627774 bytes 28884 pkts (dropped 0, overlimits 0)
     borrowed 16163 overactions 0 avgidle 587 undertime 0
     class cbq 1:2 parent 1:1 rate 8Mbit prio 2
     Sent 628829 bytes 3130 pkts (dropped 0, overlimits 0)
     borrowed 0 overactions 0 avgidle 4137 undertime 0
     class cbq 1:3 parent 1:1 rate 1Mbit prio 1
     Sent 0 bytes 0 pkts (dropped 0, overlimits 0)
     borrowed 0 overactions 0 avgidle 159654 undertime 0
     class cbq 1:4 parent 1:1 rate 1Mbit prio 6
     Sent 5552879 bytes 8076 pkts (dropped 0, overlimits 0)
     borrowed 3797 overactions 0 avgidle 159557 undertime 0
這裏主要顯示了通過不同分類發送的數據包,數據流量,丟棄的包數目,超過速率限制的包數目等等。其中根分類(class cbq 1:0)的狀況應與隊列的狀況類似。
例如,分類class cbq 1:4發送了8076個數據包,數據流量爲5552879個字節,丟棄的包數目爲0,超過速率限制的包數目爲0。
顯示過濾器的狀況
・tc -s filter ls dev eth0
filter parent 1: protocol ip pref 100 route
     filter parent 1: protocol ip pref 100 route fh 0xffff0002 flowid 1:2 to 2
     filter parent 1: protocol ip pref 100 route fh 0xffff0003 flowid 1:3 to 3
     filter parent 1: protocol ip pref 100 route fh 0xffff0004 flowid 1:4 to 4
這裏flowid 1:2代表分類class cbq 1:2,to 2代表通過路由2發送。
顯示現有路由的狀況
・ip route
192.168.1.66 dev eth0 scope link
     192.168.1.24 via 192.168.1.66 dev eth0 realm 2
     202.102.24.216 dev ppp0 proto kernel scope link src 202.102.76.5
     192.168.1.30 via 192.168.1.66 dev eth0 realm 3
     192.168.1.0/24 via 192.168.1.66 dev eth0 realm 4
     192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.66
     172.16.1.0/24 via 192.168.1.66 dev eth0 scope link
     127.0.0.0/8 dev lo scope link
     default via 202.102.24.216 dev ppp0
     default via 192.168.1.254 dev eth0
如上所示,結尾包含有realm的顯示行是起作用的路由過濾器。
6. 維護
主要包括對隊列、分類、過濾器和路由的增添、修改和刪除。
增添動作一般依照"隊列->分類->過濾器->路由"的順序進行;修改動作則沒有什麼要求;刪除則依照"路由->過濾器->分類->隊列"的順序進行。
1)隊列的維護
一般對於一臺流量控制器來說,出廠時針對每個以太網卡均已配置好一個隊列了,通常情況下對隊列無需進行增添、修改和刪除動作了。
2)分類的維護
增添
增添動作通過tc class add命令實現,如前面所示。
修改
修改動作通過tc class change命令實現,如下所示:
・tc class change dev eth0 parent 1:1 classid 1:2 cbq bandwidth 10Mbit rate 7Mbit maxburst 20 allot 1514 prio 2 avpkt 1000 cell 8 weight 700Kbit split 1:0 bounded
對於bounded命令應慎用,一旦添加後就進行修改,只可通過刪除後再添加來實現。
刪除
刪除動作只在該分類沒有工作前纔可進行,一旦通過該分類發送過數據,則無法刪除它了。因此,需要通過shell文件方式來修改,通過重新啓動來完成刪除動作。
3)過濾器的維護
增添
增添動作通過tc filter add命令實現,如前面所示。
修改
修改動作通過tc filter change命令實現,如下所示:
・tc filter change dev eth0 parent 1:0 protocol ip prio 100 route to 10 flowid 1:8
刪除
刪除動作通過tc filter del命令實現,如下所示:
・tc filter del dev eth0 parent 1:0 protocol ip prio 100 route to 10
4)與過濾器一一映射路由的維護
增添
增添動作通過ip route add命令實現,如前面所示。
修改
修改動作通過ip route change命令實現,如下所示:
・ip route change 192.168.1.30 dev eth0 via 192.168.1.66 realm 8
刪除
刪除動作通過ip route del命令實現,如下所示:
・ip route del 192.168.1.30 dev eth0 via 192.168.1.66 realm 8
・ip route del 192.168.1.0/24 dev eth0 via 192.168.1.66 realm 4
注:部分內容來自互聯網,版權歸原作者所有。

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...