Changeset 112 for system/generators/traffic_shaping.php
- Timestamp:
- Nov 9, 2008, 8:05:48 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
system/generators/traffic_shaping.php
r111 r112 23 23 $VoipSpeedIn = 100; //$SpeedReserve; 24 24 $VoipSpeedOut = 100; //$SpeedReserve; 25 $InetInterface = 'eth1'; 26 $OutInterface = 'eth1'; 27 $InInterface = 'ifb0'; 25 28 $FreeInetSpeed = 64; 26 29 … … 36 39 if($Enabled) 37 40 { 38 exec('/sbin/iptables -t mangle -A FORWARD -j MARK --set-mark 0');39 exec('/sbin/iptables -t mangle -i eth1 -A FORWARD -j MARK --set-mark 1');40 exec('/sbin/iptables -t mangle -o eth1 -A FORWARD -j MARK --set-mark 1');41 //exec('/sbin/iptables -t mangle -A FORWARD -j MARK --set-mark 0'); 42 //exec('/sbin/iptables -t mangle -i eth1 -A FORWARD -j MARK --set-mark 1'); 43 //exec('/sbin/iptables -t mangle -o eth1 -A FORWARD -j MARK --set-mark 1'); 41 44 } 42 45 … … 44 47 45 48 // In going traffic 46 fputs($File, "/sbin/tc qdisc del dev imq0root\n");49 fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n"); 47 50 if($Enabled) 48 51 { 49 fputs($File, "/sbin/tc qdisc add dev imq0root handle 1:0 htb default 2\n");52 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n"); 50 53 fputs($FileClassInfo, "1:1 Základní\n"); 51 fputs($File, "/sbin/tc class add dev imq0parent 1:0 classid 1:1 htb rate ".$TotalMaxSpeedIn."kbit quantum 1500\n");54 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:0 classid 1:1 htb rate ".$TotalMaxSpeedIn."kbit quantum 1500\n"); 52 55 fputs($FileClassInfo, "1:2 Internet zdarma\n"); 53 fputs($File, "/sbin/tc class add dev imq0parent 1:1 classid 1:".$FreeInetClass." htb rate ".$FreeInetSpeed."kbit prio 3 quantum 1500\n");54 fputs($File, "/sbin/tc qdisc add dev imq0parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n");56 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:1 classid 1:".$FreeInetClass." htb rate ".$FreeInetSpeed."kbit prio 3 quantum 1500\n"); 57 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n"); 55 58 } 56 59 // Out going traffic 57 fputs($File, "/sbin/tc qdisc del dev imq1root\n");60 fputs($File, "/sbin/tc qdisc del dev ".$OutInterface." root\n"); 58 61 if($Enabled) 59 62 { 60 fputs($File, "/sbin/tc qdisc add dev imq1 root handle 1:0 htb default 2\n"); 61 fputs($File, "/sbin/tc class add dev imq1 parent 1:0 classid 1:1 htb rate ".$TotalMaxSpeedOut."kbit quantum 1500\n"); 62 fputs($File, "/sbin/tc class add dev imq1 parent 1:1 classid 1:".$FreeInetClass." htb rate ".$FreeInetSpeed."kbit prio 3 quantum 1500\n"); 63 fputs($File, "/sbin/tc qdisc add dev imq1 parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n"); 63 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." root handle 1:0 htb default 2\n"); 64 fputs($FileClassInfo, "1:1 Základní\n"); 65 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:0 classid 1:1 htb rate ".$TotalMaxSpeedOut."kbit quantum 1500\n"); 66 fputs($FileClassInfo, "1:2 Internet zdarma\n"); 67 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:1 classid 1:".$FreeInetClass." htb rate ".$FreeInetSpeed."kbit prio 3 quantum 1500\n"); 68 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n"); 64 69 } 65 70 … … 76 81 77 82 // VoIP in going traffic 78 fputs($File, "/sbin/tc class add dev imq0parent 1:1 classid 1:".$VoipClassId." htb rate ".$VoipSpeedIn."kbit ceil ".$VoipMaxSpeedIn."kbit quantum 12000 burst 6k cburst 3k prio ".$Prio."\n");79 fputs($File, "/sbin/tc qdisc add dev imq0parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n");80 fputs($File, "/sbin/tc filter add dev imq0parent 1:0 protocol ip handle ".$VoipClassId." fw flowid 1:".$VoipClassId."\n");83 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:1 classid 1:".$VoipClassId." htb rate ".$VoipSpeedIn."kbit ceil ".$VoipMaxSpeedIn."kbit quantum 12000 burst 6k cburst 3k prio ".$Prio."\n"); 84 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n"); 85 fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip handle ".$VoipClassId." fw flowid 1:".$VoipClassId."\n"); 81 86 // VoIP out going traffic 82 fputs($File, "/sbin/tc class add dev imq1parent 1:1 classid 1:".$VoipClassId." htb rate ".$VoipSpeedOut."kbit ceil ".$VoipMaxSpeedOut."kbit quantum 12000 burst 6k cburst 3k prio ".$Prio."\n");83 fputs($File, "/sbin/tc qdisc add dev imq1parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n");84 fputs($File, "/sbin/tc filter add dev imq1parent 1:0 protocol ip handle ".$VoipClassId." fw flowid 1:".$VoipClassId."\n");87 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:1 classid 1:".$VoipClassId." htb rate ".$VoipSpeedOut."kbit ceil ".$VoipMaxSpeedOut."kbit quantum 12000 burst 6k cburst 3k prio ".$Prio."\n"); 88 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n"); 89 fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip handle ".$VoipClassId." fw flowid 1:".$VoipClassId."\n"); 85 90 fputs($FileClassInfo, '1:'.$VoipClassId." VoIP\n"); 86 91 … … 97 102 $AllUsersClassId = $ClassId; 98 103 $ClassId = $ClassId + 1; 99 fputs($File, "/sbin/tc class add dev imq0parent 1:1 classid 1:".$AllUsersClassId." htb rate ".$UsersMaxSpeedIn."kbit prio 1 quantum 1500\n");100 fputs($File, "/sbin/tc class add dev imq1parent 1:1 classid 1:".$AllUsersClassId." htb rate ".$UsersMaxSpeedOut."kbit prio 1 quantum 1500\n");101 fputs($FileClassInfo, '1:'.$AllUsersClassId." Všichni u živatelé\n");104 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:1 classid 1:".$AllUsersClassId." htb rate ".$UsersMaxSpeedIn."kbit prio 1 quantum 1500\n"); 105 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:1 classid 1:".$AllUsersClassId." htb rate ".$UsersMaxSpeedOut."kbit prio 1 quantum 1500\n"); 106 fputs($FileClassInfo, '1:'.$AllUsersClassId." Všichni uivatelé"); 102 107 103 108 // Torrent sharing … … 108 113 109 114 // Torrent out going traffic 110 fputs($File, "/sbin/tc class add dev imq1parent 1:".$AllUsersClassId." classid 1:".$TorrentClassId." htb rate ".$TorrentSpeedOut."kbit ceil ".$UsersMaxSpeedOut."kbit prio ".$Prio." quantum 1500\n");111 fputs($File, "/sbin/tc qdisc add dev imq1parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n");112 fputs($File, "/sbin/tc filter add dev imq1parent 1:0 protocol ip handle ".$TorrentClassId." fw flowid 1:".$TorrentClassId."\n");115 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:".$AllUsersClassId." classid 1:".$TorrentClassId." htb rate ".$TorrentSpeedOut."kbit ceil ".$UsersMaxSpeedOut."kbit prio ".$Prio." quantum 1500\n"); 116 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n"); 117 fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip handle ".$TorrentClassId." fw flowid 1:".$TorrentClassId."\n"); 113 118 fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n"); 114 119 // Torrent in going traffic 115 fputs($File, "/sbin/tc class add dev imq0parent 1:".$AllUsersClassId." classid 1:".$TorrentClassId." htb rate ".$TorrentSpeedOut."kbit ceil ".$UsersMaxSpeedOut."kbit prio ".$Prio." quantum 1500\n");116 fputs($File, "/sbin/tc qdisc add dev imq0parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n");117 fputs($File, "/sbin/tc filter add dev imq0parent 1:0 protocol ip handle ".$TorrentClassId." fw flowid 1:".$TorrentClassId."\n");120 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:".$AllUsersClassId." classid 1:".$TorrentClassId." htb rate ".$TorrentSpeedOut."kbit ceil ".$UsersMaxSpeedOut."kbit prio ".$Prio." quantum 1500\n"); 121 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n"); 122 fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip handle ".$TorrentClassId." fw flowid 1:".$TorrentClassId."\n"); 118 123 fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n"); 119 124 … … 130 135 131 136 fputs($File, "# === ".$User['fullname']." ===\n"); 132 fputs($File, "/sbin/tc class add dev imq0parent 1:".$AllUsersClassId." classid 1:".$UserClassId." htb rate ".$SpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio 1 quantum ".$Quantum."\n");133 //fputs($File, "/sbin/tc qdisc add dev imq0parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n");134 //fputs($File, "/sbin/tc class add dev imq0parent ".$UserClassId.":0 classid ".$UserClassId.":".$UserClassId." htb rate ".$UserMaxSpeedIn."bit prio 1\n");135 fputs($File, "/sbin/tc class add dev imq1parent 1:".$AllUsersClassId." classid 1:".$UserClassId." htb rate ".$SpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio 1 quantum ".$Quantum."\n");136 //fputs($File, "/sbin/tc qdisc add dev imq1parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n");137 //fputs($File, "/sbin/tc class add dev imq1parent ".$UserClassId.":0 classid ".$UserClassId.":".$UserClassId." htb rate ".$UserMaxSpeedOut."bit prio 1\n");137 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:".$AllUsersClassId." classid 1:".$UserClassId." htb rate ".$SpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio 1 quantum ".$Quantum."\n"); 138 //fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n"); 139 //fputs($File, "/sbin/tc class add dev ".$InInterface." parent ".$UserClassId.":0 classid ".$UserClassId.":".$UserClassId." htb rate ".$UserMaxSpeedIn."bit prio 1\n"); 140 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:".$AllUsersClassId." classid 1:".$UserClassId." htb rate ".$SpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio 1 quantum ".$Quantum."\n"); 141 //fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n"); 142 //fputs($File, "/sbin/tc class add dev ".$OutInterface." parent ".$UserClassId.":0 classid ".$UserClassId.":".$UserClassId." htb rate ".$UserMaxSpeedOut."bit prio 1\n"); 138 143 fputs($FileClassInfo, '1:'.$UserClassId.' '.$User['fullname']."\n"); 139 144 … … 168 173 $SpeedDivider = 1; 169 174 170 if($Host['name'] == ' CENTRALA')175 if($Host['name'] == 'centrala') 171 176 { 172 177 $Host['IP'] = $Host['external_ip']; … … 180 185 //if($Row['name'] == 'TERMINAL2') $Prio = 0; 181 186 // if($Row['name'] = 'TERMINAL2') $Prio = 0; 182 if($Host['name'] == ' VOIP-HAJDA') $Protocol = ' -p tcp';187 if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp'; 183 188 else $Protocol = ''; 184 189 // if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000; 185 if($Host['name'] == 'GAME') 190 /* 191 if($Host['name'] == 'GAME') 186 192 { 187 193 exec('/sbin/iptables -t mangle -F game-server'); 188 194 $TableOut = 'game-server'; 189 195 $TableIn = 'game-server'; 190 } 191 if($Host['name'] == 'TBC') continue;196 }*/ 197 //if($Host['name'] == 'TBC') continue; 192 198 193 199 // In going traffic 194 exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId);195 fputs($File, "/sbin/tc class add dev imq0parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio ".$Prio." quantum ".$Quantum."\n");196 fputs($File, "/sbin/tc qdisc add dev imq0parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");197 //fputs($File, "/sbin/tc filter add dev imq0parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");198 fputs($File, "/sbin/tc filter add dev imq0 parent 1:0 protocol ip handle ".$HostClassId." fwflowid 1:".$HostClassId."\n");200 //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId); 201 fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio ".$Prio." quantum ".$Quantum."\n"); 202 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n"); 203 //fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n"); 204 fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip prio 1 u32 match ip dst ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n"); 199 205 200 206 // Out going traffic 201 exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId);202 fputs($File, "/sbin/tc class add dev imq1parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio ".$Prio." quantum ".$Quantum."\n");203 fputs($File, "/sbin/tc qdisc add dev imq1parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");204 //fputs($File, "/sbin/tc filter add dev imq1parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");205 fputs($File, "/sbin/tc filter add dev imq1 parent 1:0 protocol ip handle ".$HostClassId." fwflowid 1:".$HostClassId."\n");207 //exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId); 208 fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio ".$Prio." quantum ".$Quantum."\n"); 209 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n"); 210 //fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n"); 211 fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip prio 1 u32 match ip src ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n"); 206 212 //echo($Row['id'].','); 207 213 } … … 213 219 } 214 220 // VoIP devices 221 /* 215 222 if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP')) 216 223 { … … 260 267 261 268 } 262 263 269 */ 270 264 271 } 265 272 } 266 273 //echo($Row['id'].','); 267 268 } 269 274 275 } 276 270 277 // In going traffic 271 278 // exec('/sbin/iptables -t mangle -A FORWARD -m mark --mark 1 -j LOG --log-prefix "TRAFFIC " --log-level info'); 272 exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -j IMQ --todev 0');273 exec('/sbin/iptables -t mangle -A INPUT -i eth1 -j IMQ --todev 0');279 //exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -j IMQ --todev 0'); 280 //exec('/sbin/iptables -t mangle -A INPUT -i eth1 -j IMQ --todev 0'); 274 281 // Out going traffic 275 exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -j IMQ --todev 1'); 276 exec('/sbin/iptables -t mangle -A OUTPUT -o eth1 -j IMQ --todev 1'); 277 exec('/sbin/iptables-save >/etc/sysconfig/iptables'); 282 //exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -j IMQ --todev 1'); 283 //exec('/sbin/iptables -t mangle -A OUTPUT -o eth1 -j IMQ --todev 1'); 284 285 fputs($File, "\n# Interface redirection\n"); 286 fputs($File, "/sbin/tc qdisc del dev ".$InetInterface." ingress\n"); 287 fputs($File, "/sbin/tc qdisc add dev ".$InetInterface." ingress\n"); 288 fputs($File, "/sbin/tc filter add dev ".$InetInterface." parent ffff: protocol ip prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0\n"); 289 290 //fputs($File, "/sbin/tc qdisc del dev ".$InetInterface." root handle 1: htb default 10\n"); 291 //fputs($File, "/sbin/tc qdisc add dev ".$InetInterface." root handle 1: htb default 10\n"); 292 //fputs($File, "/sbin/tc filter add dev ".$InetInterface." parent 1: protocol ip prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb1\n"); 293 294 //exec('/sbin/iptables-save >/etc/sysconfig//sbin/iptables'); 278 295 fclose($File); 279 296 fclose($FileClassInfo);
Note:
See TracChangeset
for help on using the changeset viewer.