-----------------------------------------------------------------------------
avviaShaping
-----------------------------------------------------------------------------
#------------------NON MODIFICARE--------------------
#CREA LE CODE PRINCIPALI SULLE INTERFACCE ETH0 E ETH1 DEFAULT 10
tc qdisc add dev eth0 root handle 1: htb default 10
tc qdisc add dev eth1 root handle 1: htb default 10
#CREA LE CLASSI PRINCIPALI A 10MBIT SU ETH0 E ETH1
tc class add dev eth0 parent 1: classid 1:1 htb rate 10mbit ceil 10mbit
tc class add dev eth1 parent 1: classid 1:1 htb rate 10mbit ceil 10mbit
#CREA LE CLASSI DI DEFAULT A 10MBIT FULL RATE
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit
tc class add dev eth1 parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit
#-----------------------------------------------------
-----------------------------------------------------------------------------
insertClass
-----------------------------------------------------------------------------
#!/usr/bin/perl
$numArgs = @ARGV;
if ( $numArgs < 4) {
print ("use: insertClass device classid rate ceil \n");
exit();
}
#print "\n $numArgs \n ";
$device=$ARGV[0];
$classid=$ARGV[1];
$rate=$ARGV[2];
$ceil=$ARGV[3];
print "\n\n Vado a inserire:\n";
print "\n device= $device";
print "\n classid= $classid";
print "\n rate= $rate";
print "\n ceil= $ceil";
$comando="tc class add dev $device parent 1:1 classid $classid htb rate $rate ceil $ceil";
print "\n $comando \n\n";
system ($comando);
-----------------------------------------------------------------------------
insetFilter
-----------------------------------------------------------------------------
#!/usr/bin/perl
$numArgs = @ARGV;
if ( $numArgs < 3) {
print ("use: insertFilter device matching_rule target_class");
print "\nexample: insertFilter eth0 dport 80 1:11\n";
exit();
}
# print "\n $numArgs \n ";
$device=$ARGV[0];
$matching_rule=$ARGV[1];
$matching_rule_port=$ARGV[2];
$target_class=$ARGV[3];
# print "\n\n Vado a inserire:\n";
# print "\n device= $device";
# print "\n matching_rule= $matching_rule";
# print "\n target_class= $target_class";
$comando="tc filter add dev $device protocol ip parent 1:0 prio 1 u32 match ip $matching_rule $matching_rule_port 0xffff flowi
d $target_class";
$cmd=sprintf("/root/cgi/showFilter %s %s|",$device,$matching_rule_port);
# print "\ncomando= $cmd";
open(PS_F, $cmd);
while ( <PS_F>) {
$a=$_;
if ($a) {
($v1,$v2,$v3)=split(",",$a);
# print "\ntrovo --> $a";
# print "\nporta trovata=$v2";
# print "\nporta da inserire=$matching_rule";
#prima devo controllare se entrambi sono sport o dport
if ( ($v2 eq "destination" && $matching_rule eq "dport") ||
($v2 eq "source" && $matching_rule eq "sport") ) {
#a questo punto devo rimuovere il filtro esistente
# print "\n rimuovo il filtro esistente";
$cmd1=sprintf("/root/cgi/deleteFilter %s %s %s",$device,$matching_rule,$matching_rule_port);
# print "\neseguendo il comando $cmd1";
# print "\nRIMOZIONE FILTRO PRESENTE";
system ($cmd1);
}
#else {printf "\nil filtro ha una source/destination diversa!!";}
}
else {
# print "\nnon trovo il filtro gia presente";
#posso direttamente
}
#sotto chiudo il while
}
system ($comando);
#print "\n $comando \n\n";
#print "\n\n";
-----------------------------------------------------------------------------
showClass
-----------------------------------------------------------------------------
#!/usr/bin/perl
$numArgs = @ARGV;
if ( $numArgs < 1) {
print ("use: showClass device ");
print "\nexample: showClass eth0\n";
exit();
}
$device=$ARGV[0];
open(PS_F, "tc class show dev $device|");
while (<PS_F>) {
($class,$htb,$classid,$parent,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9) = split;
print "classid= $classid";
print "\nparent= $parent";
if (not $parent eq "root") {
($classpadre,$prio,$prioval,$rate) = split($resto);
print "\n classpadre= $v1";
print "\n rate= $v5";
print "\n ceil= $v7";
}
else {
print "\n classpadre=";
print "\n rate= $v2";
print "\n ceil= $v4";
}
print"\n-----------------\n";
}
close(PS_F);
-----------------------------------------------------------------------------
showFilter
-----------------------------------------------------------------------------
#!/usr/bin/perl
$numArgs = @ARGV;
if ( $numArgs < 1) {
print ("use: showFilter device [port]");
print "\nexample: showFilter eth0 [80]\n";
exit();
}
$device=$ARGV[0];
$port=$ARGV[1];
open(PS_F, "tc filter show dev $device|");
while (<PS_F>) {
($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19) = split;
($classpadre,$prio,$prioval,$rate) = split($resto);
if ( index($v10,"::") > 1) {
$a=<PS_F>;
($s1,$s2,$s3,$s4) = split(" ",$a);
($p1,$p2) = split("/",$s2);
$flag = "uknown";
if ($p2 eq "0000ffff" ) {
$flag="destination";
};
if ($p2 eq "ffff0000" ) {
$flag="source";
$p1 = substr($p1 , 0 , 4 );
}
$temp = "0x" . $p1;
$p1=eval($temp);
if ( $port>0 ) {
if ($port == $p1) {
print "$v19,$flag,$p1\n";
}
}
else {
print "$v19,$flag,$p1\n";
}
}
}
close(PS_F);
-----------------------------------------------------------------------------
showStats
-----------------------------------------------------------------------------
#!/usr/bin/perl
#questo file dovrebbe stampare una riga come:
# regola | parent | rate | ceil | interface
$numArgs = @ARGV;
if ( $numArgs < 1) {
print ("use: showStats device ");
print "\nexample: showStats eth0 \n";
exit();
}
$device=$ARGV[0];
#-------------------------------------------------------------------------------
#si carica i classID dei filtri esistenti in modalita DISTINCT------------------
#e mette questo array in @a-----------------------------------------------------
open(PS_F_temp, "tc filter show dev $device|");
$i=0;
while (<PS_F_temp>) {
($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19) = split;
($classpadre,$prio,$prioval,$rate) = split($resto);
@a[$i]=$v19;
@a = sort @a;
$i++;
}
close(PS_F_temp);
$old="";
#----------------------------------------------------------------------------
for ($f=0;$f<$i;$f++) {
$linea = @a[$f];
#print "\n linea:$linea old:$old";
if ( ($linea) && !($linea eq $old) ) {
#print "\n";
#print "\n*->" . $linea . "\n";
$old=$linea;
#----------------------------------------------
#a questo punto ha un classID ($linea) UNIVOCO:
#----------------------------------------------
open(PS_F, "tc filter show dev $device|");
$primaPassata=1;
while (<PS_F>) {
($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19) = split;
($classpadre,$prio,$prioval,$rate) = split($resto);
if ( $linea eq $v19) {
if ( index($v10,"::") > 1) {
$a=<PS_F>;
($s1,$s2,$s3,$s4) = split(" ",$a);
($p1,$p2) = split("/",$s2);
$flag = "uknown";
if ($p2 eq "0000ffff" ) {
$flag="destination";
};
if ($p2 eq "ffff0000" ) {
$flag="source";
$p1 = substr($p1 , 0 , 4 );
}
$temp = "0x" . $p1;
$p1=eval($temp);
#-----------inizio prima passata
if ($primaPassata) {
# print "___iniziopassata____";
if ( $port>0 ) {
if ($port == $p1) {
print "$v19,$flag,$p1";
}
}
else {
print "$v19,$flag";
}
$classID=$v19;
#stampo rate e ceil chiamando il file showrateCeil e passandogli $classID
open(PS_F2, "/root/cgi/showRateCeil $device $classID|");
while (<PS_F2>) {
($d1,$d2,$d3) = split;
print $d1;
}
$primaPassata=0;
close(PS_F2);
print ",";
#print "___finepassata____";
}
#-----------fine prima passata
print "-$p1";
}
}
}
print "\n";
close(PS_F);
}
}
-----------------------------------------------------------------------------
showrateCeil
-----------------------------------------------------------------------------
#!/usr/bin/perl
#questo scipt prnde in ingresso un classID e ritorna il rate e il ceil corrispondente
$numArgs = @ARGV;
if ( $numArgs < 2) {
print ("use: showRateCeil device classId");
print "\nexample: showRateCeil eth0 1:10\n";
exit();
}
$device=$ARGV[0];
$classID=$ARGV[1];
open(PS_F, "tc class show dev $device|");
while (<PS_F>) {
($class,$htb,$classid,$parent,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9) = split;
if ($classid eq $classID)
{
#print "$classid"; #classid
#print ",$parent"; #parent
if (not $parent eq "root") {
($classpadre,$prio,$prioval,$rate) = split($resto);
#print ",$v1"; #classpadre
print ",$v5"; #rate
print ",$v7"; #ceil
}
else {
#print ",root,"; #classpadre
print ",$v2"; #rate
print ",$v4"; #ceil
}
}
}
close(PS_F);
-----------------------------------------------------------------------------
makeStatus
-----------------------------------------------------------------------------
#!/usr/bin/perl
$numArgs = @ARGV;
if ( $numArgs < 1) {
print ("use: makeStatus device");
print "\nexample: makeStatus eth0\n";
exit();
}
$dev=$ARGV[0];
if ($dev eq "eth0") { $nf="/root/cgi/statusETH0.cfg"};
if ($dev eq "eth1") { $nf="/root/cgi/statusETH1.cfg"};
$comando=sprintf("tc filter show dev %s|",$dev);
open(PS_F, $comando);
open (STATUS,">$nf");
while (<PS_F>) {
($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19) = split;
($classpadre,$prio,$prioval,$rate) = split($resto);
# print "\n--->riga=$_";
if ( index($v10,"::") > 1) {
$a=<PS_F>;
($s1,$s2,$s3,$s4) = split(" ",$a);
($p1,$p2) = split("/",$s2);
$flag = "uknown";
if ($p2 eq "0000ffff" ) {
$flag="destination";
};
if ($p2 eq "ffff0000" ) {
$flag="source";
$p1 = $p1/10000;
}
$temp = "0x" . $p1;
$p1=eval($temp);
# print "$v19,$flag,$p1\n";
print STATUS "$v19,$flag,$p1\n";
}
}
close(PS_F);
close (STATUS);
-----------------------------------------------------------------------------
loadStatus
----------------------------------------------------------------------------
#!/usr/bin/perl
# print "\n-------\nWELCOME to loadStatus\n--------------\n";
$device="eth0";
open(STATUS0,"/root/cgi/statusETH0.cfg");
while (<STATUS0>) {
($target_class,$matching_rule,$matching_rule_port,$port)=split (",");
if ($matching_rule eq "source") {
$matching_rule="sport";
}
if ($matching_rule eq "destination") {
$matching_rule="dport";
}
$port = 0 + $matching_rule_port;
# print "Vado a inserire:";
# print "\n device= $device";
# print "\n matching_rule= $matching_rule";
# print "\n port= $port";
# print "\n target_class= $target_class\n";
$comando="tc filter add dev $device protocol ip parent 1:0 prio 1 u32 match ip $matching_rule $port 0xffff flowid $target_clas
s";
system ($comando);
# print "\n $comando \n\n";
}
$device="eth1";
open(STATUS1,"/root/cgi/statusETH1.cfg");
while (<STATUS1>) {
($target_class,$matching_rule,$matching_rule_port,$port)=split (",");
if ($matching_rule eq "source") {
$matching_rule="sport";
}
if ($matching_rule eq "destination") {
$matching_rule="dport";
}
$port = 0 + $matching_rule_port;
# print "Vado a inserire:";
# print "\n device= $device";
# print "\n matching_rule= $matching_rule";
# print "\n port= $port";
# print "\n target_class= $target_class\n";
$comando="tc filter add dev $device protocol ip parent 1:0 prio 1 u32 match ip $matching_rule $port 0xffff flowid $target_clas
s";
system ($comando);
# print "\n $comando \n\n";
}
BIBLIOGRAFIA
aspetti giuridici del filesharing http://www.cybercrime.gov/ipmanual.html
Lista aggiornata dei filesharing attualmente disponibili http://www.gnutella.com/connect
Per maggiori informazioni sul protocollo open nap http://opennap.sf.net
Gnutella:
http://www.gnutella.com
http://www9.limewire.com/developer/gnutella_protocol_0.4.pdf
http://rfc-gnutella.sf.net
Sicurezza e privacy nei p2p http://www.cs.ucr.edu/~csyiazti/cs260-2.html
Mutella: http://mutella.sf.net
Gtk-gnutella: http://gtk-gnutella.sf.net
Limewire: http://www.limewire.com
Gnucleus: http://www.gnucleus.com
Gnapster: http://jasta.gotlinux.org/gnapster
Lopster: http://lopster.sf.net
Nap client testuale: http://nap.sf.net/userguide.html
MLDonkey: http://www.freesoftware.fsf.net/mldonkey
Freenet: http://freenetproject.org/cgi-bin/twiki/view/IT/WebHome
GNUnet: http://www.gnu.org/software/GNUnet/
Wins: Windows 2000 Server guida completa - Apogeo