- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigLinux/Generators/TrafficShaping.php
r548 r738 10 10 // Generate traffic shaping rules 11 11 //$TotalMaxSpeedIn = 4048; //$RealMaxSpeed; //1536; 12 //TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536; 12 //TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536; 13 13 //$UsersMaxSpeedIn = 1900; //$MaxSpeed; 14 14 //$UsersMaxSpeedOut = 1900; //$MaxSpeed; … … 45 45 46 46 $FreeInetClass = 2; 47 47 48 48 // In going traffic 49 49 fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n"); 50 50 if($Enabled) 51 { 51 { 52 52 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n"); 53 53 fputs($FileClassInfo, "1:1 Základní\n"); … … 68 68 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n"); 69 69 } 70 70 71 71 if(!$Enabled) die("Traffic shaping disabled\n"); 72 72 73 if($ClassesEnabled) 73 if($ClassesEnabled) 74 74 { 75 75 $ClassId = 3; … … 98 98 //$SpeedOut = round($UsersMaxSpeedOut / $InetUserCount); 99 99 $Prio = 1; 100 101 100 101 102 102 $AllUsersClassId = $ClassId; 103 103 $ClassId = $ClassId + 1; … … 123 123 fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n"); 124 124 125 $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)'); 125 $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)'); 126 126 while($User = $DbResult->fetch_array()) 127 127 { … … 144 144 145 145 //echo('User class id: '.$UserClassId."\n"); 146 146 147 147 $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$User['id']); 148 148 $Row = $DbResult2->fetch_array(); … … 150 150 $HostSpeedIn = round($SpeedIn / $HostCount); 151 151 $HostSpeedOut = round($SpeedOut / $HostCount); 152 152 153 153 $DbResult2 = $Database->select('hosts','*',"block=0 AND MAC!='' AND user=".$User['id']); 154 154 while($Host = $DbResult2->fetch_array()) … … 164 164 $Prio = 1; 165 165 if($Host['vpn'] == 1) 166 167 168 169 170 171 172 //else 166 { 167 if($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip']; 168 else $Host['IP'] = ToVpnIp($Host); 169 } 170 171 //if($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5; 172 //else 173 173 $SpeedDivider = 1; 174 174 175 176 177 178 179 180 175 if($Host['name'] == 'centrala') 176 { 177 $Host['IP'] = $Host['external_ip']; 178 $TableOut = 'OUTPUT'; 179 $TableIn = 'INPUT'; 180 } else 181 181 { 182 183 184 185 //if($Row['name'] == 'TERMINAL2') $Prio = 0; 186 // 187 if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp'; 188 189 // 182 $TableOut = 'FORWARD'; 183 $TableIn = 'FORWARD'; 184 } 185 //if($Row['name'] == 'TERMINAL2') $Prio = 0; 186 // if($Row['name'] = 'TERMINAL2') $Prio = 0; 187 if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp'; 188 else $Protocol = ''; 189 // if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000; 190 190 /* 191 if($Host['name'] == 'GAME') 192 193 exec('/sbin/iptables -t mangle -F game-server'); 194 195 196 191 if($Host['name'] == 'GAME') 192 { 193 exec('/sbin/iptables -t mangle -F game-server'); 194 $TableOut = 'game-server'; 195 $TableIn = 'game-server'; 196 }*/ 197 197 //if($Host['name'] == 'TBC') continue; 198 198 199 199 // In going traffic 200 //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId); 201 202 203 204 205 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"); 205 206 206 // Out going traffic 207 207 //exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId); 208 209 210 211 212 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"); 212 //echo($Row['id'].','); 213 213 } 214 214 // Free inet 215 215 if($Tarify[$User['inet_tarif_now']]['group_id'] == 3) 216 216 { 217 //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass); 217 //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass); 218 218 //exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass); 219 219 } 220 220 // VoIP devices 221 221 /* 222 if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP')) 222 if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP')) 223 223 { 224 224 exec('/sbin/iptables -t mangle -A '.$TableIn." -i eth1 -d ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId); 225 225 exec('/sbin/iptables -t mangle -A '.$TableOut." -o eth1 -s ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId); 226 } else 226 } else 227 227 if($Host['name'] == 'GAME') 228 228 { 229 exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server"); 230 exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -d '.$Host['IP']." -j game-server"); 231 229 exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server"); 230 exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -d '.$Host['IP']." -j game-server"); 231 232 232 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -j MARK --set-mark ".$TorrentClassId); 233 233 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -j MARK --set-mark ".$TorrentClassId); … … 237 237 238 238 // Local services 239 239 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p icmp -j MARK --set-mark ".$HostClassId); // ICMP 240 240 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p icmp -j MARK --set-mark ".$HostClassId); 241 241 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 6969 -j MARK --set-mark ".$HostClassId); // web torrent 242 242 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 6969 -j MARK --set-mark ".$HostClassId); 243 243 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 80 -j MARK --set-mark ".$HostClassId); // web 244 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId); 244 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId); 245 245 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 21 -j MARK --set-mark ".$HostClassId); // FTP 246 246 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 21 -j MARK --set-mark ".$HostClassId); … … 252 252 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 22 -j MARK --set-mark ".$HostClassId); 253 253 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 443 -j MARK --set-mark ".$HostClassId); // https 254 254 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 443 -j MARK --set-mark ".$HostClassId); 255 255 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 27015 -j MARK --set-mark ".$HostClassId); // Counter Strike 256 256 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 27015 -j MARK --set-mark ".$HostClassId); … … 259 259 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 5906 -j MARK --set-mark ".$HostClassId); // VNC 260 260 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 5906 -j MARK --set-mark ".$HostClassId); 261 262 261 262 // Remote services 263 263 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --dport 443 -j MARK --set-mark ".$HostClassId); // https 264 264 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 443 -j MARK --set-mark ".$HostClassId); 265 265 exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId); // http 266 267 266 exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 80 -j MARK --set-mark ".$HostClassId); 267 268 268 } 269 269 */
Note:
See TracChangeset
for help on using the changeset viewer.