Ignore:
Timestamp:
Nov 9, 2008, 8:05:48 PM (16 years ago)
Author:
george
Message:
  • Opraveno: Korekce systémových skriptů po aktualizaci Centrály
File:
1 edited

Legend:

Unmodified
Added
Removed
  • system/generators/traffic_shaping.php

    r111 r112  
    2323$VoipSpeedIn = 100; //$SpeedReserve;
    2424$VoipSpeedOut = 100; //$SpeedReserve;
     25$InetInterface = 'eth1';
     26$OutInterface = 'eth1';
     27$InInterface = 'ifb0';
    2528$FreeInetSpeed = 64;
    2629
     
    3639  if($Enabled)
    3740  {
    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');
    4144  }
    4245
     
    4447 
    4548  // In going traffic
    46   fputs($File, "/sbin/tc qdisc del dev imq0 root\n");
     49  fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n");
    4750  if($Enabled)
    4851  {
    49     fputs($File, "/sbin/tc qdisc add dev imq0 root handle 1:0 htb default 2\n");
     52    fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n");
    5053    fputs($FileClassInfo, "1:1 Základní\n");
    51     fputs($File, "/sbin/tc class add dev imq0 parent 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");
    5255    fputs($FileClassInfo, "1:2 Internet zdarma\n");
    53     fputs($File, "/sbin/tc class add dev imq0 parent 1:1 classid 1:".$FreeInetClass." htb rate ".$FreeInetSpeed."kbit prio 3 quantum 1500\n");
    54     fputs($File, "/sbin/tc qdisc add dev imq0 parent 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");
    5558  }
    5659  // Out going traffic
    57   fputs($File, "/sbin/tc qdisc del dev imq1 root\n");
     60  fputs($File, "/sbin/tc qdisc del dev ".$OutInterface." root\n");
    5861  if($Enabled)
    5962  {
    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");
    6469  }
    6570 
     
    7681
    7782  // VoIP in going traffic
    78   fputs($File, "/sbin/tc class add dev imq0 parent 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 imq0 parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n");
    80   fputs($File, "/sbin/tc filter add dev imq0 parent 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");
    8186  // VoIP out going traffic
    82   fputs($File, "/sbin/tc class add dev imq1 parent 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 imq1 parent 1:".$VoipClassId." handle ".$VoipClassId.": sfq perturb 10\n");
    84   fputs($File, "/sbin/tc filter add dev imq1 parent 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");
    8590  fputs($FileClassInfo, '1:'.$VoipClassId." VoIP\n");
    8691
     
    97102  $AllUsersClassId = $ClassId;
    98103  $ClassId = $ClassId + 1;
    99   fputs($File, "/sbin/tc class add dev imq0 parent 1:1 classid 1:".$AllUsersClassId." htb rate ".$UsersMaxSpeedIn."kbit prio 1 quantum 1500\n");
    100   fputs($File, "/sbin/tc class add dev imq1 parent 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é");
    102107
    103108  // Torrent sharing
     
    108113
    109114  // Torrent out going traffic
    110   fputs($File, "/sbin/tc class add dev imq1 parent 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 imq1 parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n");
    112   fputs($File, "/sbin/tc filter add dev imq1 parent 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");
    113118  fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n");
    114119  // Torrent in going traffic
    115   fputs($File, "/sbin/tc class add dev imq0 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 imq0 parent 1:".$TorrentClassId." handle ".$TorrentClassId.":0 sfq perturb 10\n");
    117   fputs($File, "/sbin/tc filter add dev imq0 parent 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");
    118123  fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n");
    119124
     
    130135
    131136    fputs($File, "# === ".$User['fullname']." ===\n");
    132     fputs($File, "/sbin/tc class add dev imq0 parent 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 imq0 parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n");
    134     //fputs($File, "/sbin/tc class add dev imq0 parent ".$UserClassId.":0 classid ".$UserClassId.":".$UserClassId." htb rate ".$UserMaxSpeedIn."bit prio 1\n");
    135     fputs($File, "/sbin/tc class add dev imq1 parent 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 imq1 parent 1:".$UserClassId." handle ".$UserClassId.":0 htb r2q 10\n");
    137     //fputs($File, "/sbin/tc class add dev imq1 parent ".$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");
    138143    fputs($FileClassInfo, '1:'.$UserClassId.' '.$User['fullname']."\n");
    139144
     
    168173        $SpeedDivider = 1;
    169174
    170               if($Host['name'] == 'CENTRALA')
     175              if($Host['name'] == 'centrala')
    171176              {
    172177                $Host['IP'] = $Host['external_ip'];
     
    180185              //if($Row['name'] == 'TERMINAL2') $Prio = 0;
    181186        //      if($Row['name'] = 'TERMINAL2') $Prio = 0;
    182         if($Host['name'] == 'VOIP-HAJDA') $Protocol = ' -p tcp';
     187        if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp';
    183188          else $Protocol = '';
    184189        //      if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;
    185         if($Host['name'] == 'GAME')
     190        /*
     191if($Host['name'] == 'GAME')
    186192        {
    187193          exec('/sbin/iptables -t mangle -F game-server');       
    188194                $TableOut = 'game-server';
    189195                $TableIn = 'game-server';
    190         }
    191         if($Host['name'] == 'TBC') continue;
     196        }*/
     197        //if($Host['name'] == 'TBC') continue;
    192198
    193199        // 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 imq0 parent 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 imq0 parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
    197             //fputs($File, "/sbin/tc filter add dev imq0 parent 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." fw flowid 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");
    199205       
    200206        // 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 imq1 parent 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 imq1 parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
    204               //fputs($File, "/sbin/tc filter add dev imq1 parent 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." fw flowid 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");
    206212               //echo($Row['id'].',');
    207213      }
     
    213219      }
    214220      // VoIP devices
     221/*
    215222      if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP'))
    216223      {
     
    260267       
    261268      }
    262      
    263      
     269*/
     270
    264271    }
    265272  }
    266273  //echo($Row['id'].',');
    267  
    268   }
    269  
     274
     275  }
     276
    270277  // In going traffic
    271278  // 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');
    274281  // 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');
    278295  fclose($File);
    279296  fclose($FileClassInfo);
Note: See TracChangeset for help on using the changeset viewer.