Cześć,
zrobiłem własny skrypt do tablic mieszających bo muszę przebadać sieć i tu zaczynają się schody, ponieważ na innym komputerze (nowszym) działał ten skrypt natomiast na innym nie chce. W konsoli wykonuje się skrypt natomiast nie obcina ruchu dla żadnego z adresów 192.168.0.2-192.168.3.254 (pętla).
Test tablic wykonuje ściągając duże pliki na komputer podłączonego do kompa-serwer z Ubuntu.
Proszę o pomoc!
#!/usr/bin/perl -s
$option = @ARGV[0];
if( $option eq "help") {
print_info();
exit;
} elsif ($option eq "start") {
stop_tc();
start_tc();
exit;
} elsif ($option eq "stop") {
stop_tc();
exit;
} else {
print_info();
exit;
}
sub print_info{
print "Usage:\n\tstart - Start tc.\n\tstop = Stop tc.\n\thelp - Display ts text.\n";
}
sub stop_tc{
print "Stop tc.\n";
system "tc qdisc del dev eth1 root handle 1:0 htb";
system "tc qdisc del dev eth0 root handle 1:0 htb";
}
sub start_tc{
print "-----[TABLICE MIESZAJĄCE]-----\n";
system "tc qdisc add dev eth1 root handle 1:0 htb";
system "tc class add dev eth1 parent 1:0 classid 1:1 htb rate 31kbps ceil 40kbps quantum 80000";
system "tc filter add dev eth1 parent 1:0 prio 1 handle 100: protocol ip u32 divisor 256";
system "tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 ht 800:: match ip dst 192.168.0.0/22 hashkey mask 0x0000ff00 at 16 link 100:";
#filtry hashujące
# 192.168.0.0/24
system "tc filter add dev eth1 protocol ip parent 1:0 handle 201: u32 divisor 256";
system "tc filter add dev eth1 protocol ip parent 1:0 u32 ht 100:: match ip dst 192.168.0.0/22 hashkey mask 0x000000ff at 16 link 201:";
# 192.168.1.0/24
system "tc filter add dev eth1 protocol ip parent 1:0 handle 202: u32 divisor 256";
system "tc filter add dev eth1 protocol ip parent 1:0 u32 ht 100:: match ip dst 192.168.1.0/22 hashkey mask 0x000000ff at 16 link 202:";
# 192.168.2.0/24
system "tc filter add dev eth1 protocol ip parent 1:0 handle 203: u32 divisor 256";
system "tc filter add dev eth1 protocol ip parent 1:0 u32 ht 100:: match ip dst 192.168.2.0/22 hashkey mask 0x000000ff at 16 link 203:";
# 192.168.3.0/24
system "tc filter add dev eth1 protocol ip parent 1:0 handle 204: u32 divisor 256";
system "tc filter add dev eth1 protocol ip parent 1:0 u32 ht 100:: match ip dst 192.168.3.0/22 hashkey mask 0x000000ff at 16 link 204:";
for(my $i = 1; $i < 255; $i++) {
$hex = sprintf("%x", $i);
# Hosts in 192.168.0.0/32
system "tc class add dev eth1 parent 1:1 classid 1:$hex htb rate 31kbps ceil 40kbps quantum 1500" ;
system "tc filter add dev eth1 protocol ip parent 1:1 u32 ht 201:$hex: match ip dst 192.168.0.$i/32 flowid 1:$hex";
# Hosts in 192.168.1.0/32
system "tc class add dev eth1 parent 1:1 classid 1:$hex htb rate 31kbps ceil 40kbps quantum 1500" ;
system "tc filter add dev eth1 protocol ip parent 1:1 u32 ht 202:$hex: match ip dst 192.168.1.$i/32 flowid 1:$hex";
# Hosts in 192.168.2.0/32
system "tc class add dev eth1 parent 1:1 classid 1:$hex htb rate 31kbps ceil 40kbps quantum 1500" ;
system "tc filter add dev eth1 protocol ip parent 1:1 u32 ht 203:$hex: match ip dst 192.168.2.$i/32 flowid 1:$hex";
# Hosts in 192.168.3.0/32
system "tc class add dev eth1 parent 1:1 classid 1:$hex htb rate 31kbps ceil 40kbps quantum 1500" ;
system "tc filter add dev eth1 protocol ip parent 1:1 u32 ht 204:$hex: match ip dst 192.168.3.$i/32 flowid 1:$hex";
}
}