summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-03-17 10:38:08 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-03-17 10:38:08 -0700
commitc667c9b128af7a9d8344459c8c65ee9ee8703f02 (patch)
tree7d81e69553460d081b899016bcc6b0c9e395baa5
parent426d6086ebecea13fe29721130f071284ebca899 (diff)
downloadvyatta-cfg-qos-c667c9b128af7a9d8344459c8c65ee9ee8703f02.tar.gz
vyatta-cfg-qos-c667c9b128af7a9d8344459c8c65ee9ee8703f02.zip
Use select to avoid passing output path around
Easier to just use 'select' in perl to avoid passing file descriptor everywhere.
-rw-r--r--lib/Vyatta/Qos/DropTail.pm4
-rw-r--r--lib/Vyatta/Qos/FairQueue.pm8
-rw-r--r--lib/Vyatta/Qos/Match.pm26
-rw-r--r--lib/Vyatta/Qos/NetworkEmulator.pm20
-rw-r--r--lib/Vyatta/Qos/RateLimiter.pm5
-rw-r--r--lib/Vyatta/Qos/ShaperClass.pm42
-rw-r--r--lib/Vyatta/Qos/TrafficLimiter.pm8
-rw-r--r--lib/Vyatta/Qos/TrafficShaper.pm20
-rwxr-xr-xscripts/vyatta-qos.pl18
9 files changed, 74 insertions, 77 deletions
diff --git a/lib/Vyatta/Qos/DropTail.pm b/lib/Vyatta/Qos/DropTail.pm
index 09508a8..1b14a81 100644
--- a/lib/Vyatta/Qos/DropTail.pm
+++ b/lib/Vyatta/Qos/DropTail.pm
@@ -39,12 +39,12 @@ sub new {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
+ my ( $self, $dev ) = @_;
my $limit = $self->{_limit};
my $cmd = "qdisc add dev $dev root pfifo";
$cmd .= " limit $limit" if defined $limit;
- printf {$out} "%s\n", $cmd;
+ printf "%s\n", $cmd;
}
sub isChanged {
diff --git a/lib/Vyatta/Qos/FairQueue.pm b/lib/Vyatta/Qos/FairQueue.pm
index 327a32b..bc3a872 100644
--- a/lib/Vyatta/Qos/FairQueue.pm
+++ b/lib/Vyatta/Qos/FairQueue.pm
@@ -44,11 +44,11 @@ sub new {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
+ my ( $self, $dev ) = @_;
- print {$out} "qdisc add dev $dev root sfq";
- print {$out} " perturb $self->{_perturb}" if ( defined $self->{_perturb} );
- print {$out} " limit $self->{_limit}" if ( defined $self->{_limit} );
+ print "qdisc add dev $dev root sfq";
+ print " perturb $self->{_perturb}" if ( $self->{_perturb} );
+ print " limit $self->{_limit}" if ( $self->{_limit} );
print "\n";
}
diff --git a/lib/Vyatta/Qos/Match.pm b/lib/Vyatta/Qos/Match.pm
index 751473e..ecfa09d 100644
--- a/lib/Vyatta/Qos/Match.pm
+++ b/lib/Vyatta/Qos/Match.pm
@@ -58,7 +58,7 @@ sub _define {
}
sub filter {
- my ( $self, $out, $dev, $parent, $prio, $dsmark ) = @_;
+ my ( $self, $dev, $parent, $prio, $dsmark ) = @_;
my $ip = $self->{_ip};
my $indev = $self->{_dev};
my $vif = $self->{_vif};
@@ -71,32 +71,32 @@ sub filter {
# Special case for when dsmarking is used with ds matching
# original dscp is saved in tc_index
if (defined $dsmark && defined $ip && defined $$ip{dsfield}) {
- printf {$out} "filter add dev %s parent %x: protocol ip prio 1",
+ printf "filter add dev %s parent %x: protocol ip prio 1",
$dev, $parent;
printf ${out} " handle %d tcindex", $$ip{dsfield};
return;
}
- printf {$out} "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
+ printf "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
if (defined $ip) {
- print {$out} " protocol ip u32";
- print {$out} " match ip dsfield $$ip{dsfield} 0xff"
+ print " protocol ip u32";
+ print " match ip dsfield $$ip{dsfield} 0xff"
if defined $$ip{dsfield};
- print {$out} " match ip protocol $$ip{protocol} 0xff"
+ print " match ip protocol $$ip{protocol} 0xff"
if defined $$ip{protocol};
- print {$out} " match ip src $$ip{src}"
+ print " match ip src $$ip{src}"
if defined $$ip{src};
- print {$out} " match ip sport $$ip{sport} 0xffff"
+ print " match ip sport $$ip{sport} 0xffff"
if defined $$ip{sport};
- print {$out} " match ip dst $$ip{dst}"
+ print " match ip dst $$ip{dst}"
if defined $$ip{dst};
- print {$out} " match ip dport $$ip{dport} 0xffff"
+ print " match ip dport $$ip{dport} 0xffff"
if defined $$ip{dport};
} else {
- print {$out} " protocol all basic";
- print {$out} " match meta\(rt_iif eq $indev\)"
+ print " protocol all basic";
+ print " match meta\(rt_iif eq $indev\)"
if (defined $indev);
- print {$out} " match meta\(vlan mask 0xfff eq $vif\)"
+ print " match meta\(vlan mask 0xfff eq $vif\)"
if (defined $vif);
}
}
diff --git a/lib/Vyatta/Qos/NetworkEmulator.pm b/lib/Vyatta/Qos/NetworkEmulator.pm
index 47b0174..1458dd4 100644
--- a/lib/Vyatta/Qos/NetworkEmulator.pm
+++ b/lib/Vyatta/Qos/NetworkEmulator.pm
@@ -52,37 +52,37 @@ sub new {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
+ my ( $self, $dev ) = @_;
my $rate = $self->{_rate};
if ($rate) {
my $burst = $self->{_burst};
$burst or $burst = "15K";
- printf {$out} "qdisc add dev %s root handle 1:0 tbf rate %s burst %s\n",
+ printf "qdisc add dev %s root handle 1:0 tbf rate %s burst %s\n",
$dev, $rate, $burst;
- printf {$out} "qdisc add dev %s parent 1:1 handle 10: netem";
+ printf "qdisc add dev %s parent 1:1 handle 10: netem";
}
else {
- printf {$out} "qdisc add dev %s root netem";
+ printf "qdisc add dev %s root netem";
}
my $delay = $self->{_delay};
- print {$out} " delay $delay" if ($delay);
+ print " delay $delay" if ($delay);
my $limit = $self->{_limit};
- print {$out} " limit $limit" if ($limit);
+ print " limit $limit" if ($limit);
my $drop = $self->{_drop};
- print {$out} " drop $drop" if ($drop);
+ print " drop $drop" if ($drop);
my $corrupt = $self->{_corrupt};
- print {$out} " corrupt $corrupt" if ($corrupt);
+ print " corrupt $corrupt" if ($corrupt);
my $reorder = $self->{_reorder};
- print {$out} " reorder $reorder" if ($reorder);
+ print " reorder $reorder" if ($reorder);
- print {$out} "\n";
+ print "\n";
}
sub isChanged {
diff --git a/lib/Vyatta/Qos/RateLimiter.pm b/lib/Vyatta/Qos/RateLimiter.pm
index f7585e6..c20646e 100644
--- a/lib/Vyatta/Qos/RateLimiter.pm
+++ b/lib/Vyatta/Qos/RateLimiter.pm
@@ -49,10 +49,9 @@ sub new {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
-
+ my ( $self, $dev ) = @_;
- printf {$out} "qdisc add dev %s root tbf rate %s latency %s burst %s\n",
+ printf "qdisc add dev %s root tbf rate %s latency %s burst %s\n",
$dev, $self->{_rate}, $self->{_latency}, $self->{_burst};
}
diff --git a/lib/Vyatta/Qos/ShaperClass.pm b/lib/Vyatta/Qos/ShaperClass.pm
index 43095a4..4caaddc 100644
--- a/lib/Vyatta/Qos/ShaperClass.pm
+++ b/lib/Vyatta/Qos/ShaperClass.pm
@@ -127,30 +127,30 @@ sub rateCheck {
}
sub prioQdisc {
- my ( $self, $out, $dev, $rate ) = @_;
+ my ( $self, $dev, $rate ) = @_;
my $prio_id = 0x4000 + $self->{id};
my $limit = $self->{_limit};
- printf {$out} "handle %x: prio\n", $prio_id;
+ printf "handle %x: prio\n", $prio_id;
if ($limit) {
foreach my $i (qw/1 2 3/) {
- printf {$out} "qdisc add dev %s parent %x:%d pfifo limit %d\n",
+ printf "qdisc add dev %s parent %x:%d pfifo limit %d\n",
$dev, $prio_id, $i, $limit;
}
}
}
sub sfqQdisc {
- my ( $self, $out, $dev, $rate ) = @_;
+ my ( $self, $dev, $rate ) = @_;
- print ${out} "sfq";
- print ${out} " limit $self->{_limit}" if ( $self->{_limit} );
- print ${out} "\n";
+ print "sfq";
+ print " limit $self->{_limit}" if ( $self->{_limit} );
+ print "\n";
}
sub fifoQdisc {
- my ( $self, $out, $dev, $rate ) = @_;
+ my ( $self, $dev, $rate ) = @_;
print ${out} "pfifo";
print ${out} " limit $self->{_limit}" if ( $self->{_limit} );
@@ -165,7 +165,7 @@ sub fifoQdisc {
# min := max / 3
# burst := (2 * min + max) / (3 * average)
sub redQdisc {
- my ( $self, $out, $dev, $rate ) = @_;
+ my ( $self, $dev, $rate ) = @_;
my $limit = $self->{_limit};
my $avg = 1000;
my $qlimit;
@@ -195,24 +195,24 @@ my %qdiscOptions = (
);
sub htbClass {
- my ( $self, $out, $dev, $parent, $speed ) = @_;
+ my ( $self, $dev, $parent, $speed ) = @_;
my $rate = _getPercentRate( $self->{_rate}, $speed );
my $ceil = _getPercentRate( $self->{_ceiling}, $speed );
- printf ${out} "class add dev %s parent %x:1 classid %x:%x htb rate %s",
+ printf "class add dev %s parent %x:1 classid %x:%x htb rate %s",
$dev, $parent, $parent, $self->{id}, $rate;
- print ${out} " ceil $ceil" if ($ceil);
- print ${out} " burst $self->{_burst}" if ( defined $self->{_burst} );
- print ${out} " prio $self->{_priority}" if ( defined $self->{_priority} );
- print {$out} "\n";
+ print " ceil $ceil" if ($ceil);
+ print " burst $self->{_burst}" if ( defined $self->{_burst} );
+ print " prio $self->{_priority}" if ( defined $self->{_priority} );
+ print "\n";
# create leaf qdisc
my $q = $qdiscOptions{ $self->{_qdisc} };
if ( defined $q ) {
- printf {$out} "qdisc add dev %s parent %x:%x ",
+ printf "qdisc add dev %s parent %x:%x ",
$dev, $parent, $self->{id};
- $q->( $self, $out, $dev, $rate );
+ $q->( $self, $dev, $rate );
}
else {
die "Unknown queue type $self->{_qdisc}\n";
@@ -220,16 +220,16 @@ sub htbClass {
}
sub dsmarkClass {
- my ( $self, $out, $parent, $dev ) = @_;
+ my ( $self, $parent, $dev ) = @_;
- printf ${out} "class change dev %s classid %x:%x dsmark",
+ printf "class change dev %s classid %x:%x dsmark",
$dev, $parent, $self->{id};
if ( $self->{dsmark} ) {
- print ${out} " mask 0 value $self->{dsmark}\n";
+ print " mask 0 value $self->{dsmark}\n";
}
else {
- print ${out} " mask 0xff value 0\n";
+ print " mask 0xff value 0\n";
}
}
diff --git a/lib/Vyatta/Qos/TrafficLimiter.pm b/lib/Vyatta/Qos/TrafficLimiter.pm
index 5aea0f9..fd3460c 100644
--- a/lib/Vyatta/Qos/TrafficLimiter.pm
+++ b/lib/Vyatta/Qos/TrafficLimiter.pm
@@ -76,15 +76,15 @@ sub _define {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
+ my ( $self, $dev ) = @_;
my $classes = $self->{_classes};
my $parent = 0xffff;
- printf {$out} "qdisc add dev %s handle %x: ingress\n", $dev, $parent;
+ printf "qdisc add dev %s handle %x: ingress\n", $dev, $parent;
foreach my $class (@$classes) {
foreach my $match ( $class->matchRules() ) {
- $match->filter( $out, $dev, $parent, $class->{priority} );
- printf {$out} " police rate %s burst %s drop flowid :%x\n",
+ $match->filter( $dev, $parent, $class->{priority} );
+ printf " police rate %s burst %s drop flowid :%x\n",
$class->{rate}, $class->{burst}, $class->{id};
}
}
diff --git a/lib/Vyatta/Qos/TrafficShaper.pm b/lib/Vyatta/Qos/TrafficShaper.pm
index dbc3d31..8295764 100644
--- a/lib/Vyatta/Qos/TrafficShaper.pm
+++ b/lib/Vyatta/Qos/TrafficShaper.pm
@@ -127,7 +127,7 @@ sub _define {
}
sub commands {
- my ( $self, $out, $dev ) = @_;
+ my ( $self, $dev ) = @_;
my $rate = _getAutoRate( $self->{_rate}, $dev );
my $classes = $self->{_classes};
my %dsmark = ();
@@ -170,14 +170,14 @@ sub commands {
++$indices;
}
- print {$out} "qdisc add dev $dev handle 1:0 root dsmark"
+ print "qdisc add dev $dev handle 1:0 root dsmark"
. " indices $indices default_index $default->{id} set_tc_index\n";
foreach my $class (@$classes) {
- $class->dsmarkClass( $out, 1, $dev );
+ $class->dsmarkClass( 1, $dev );
foreach my $match ( $class->matchRules() ) {
- $match->filter( $out, $dev, 1, 1 );
- printf {$out} " classid %x:%x\n", $parent, $class->{id};
+ $match->filter( $dev, 1, 1 );
+ printf " classid %x:%x\n", $parent, $class->{id};
}
}
@@ -185,17 +185,17 @@ sub commands {
$root = "parent 1:1";
}
- printf {$out} "qdisc add dev %s %s handle %x: htb default %x\n",
+ printf "qdisc add dev %s %s handle %x: htb default %x\n",
$dev, $root, $parent, $default->{id};
- printf {$out} "class add dev %s parent %x: classid %x:1 htb rate %s\n",
+ printf "class add dev %s parent %x: classid %x:1 htb rate %s\n",
$dev, $parent, $parent, $rate;
foreach my $class (@$classes) {
- $class->htbClass( $out, $dev, $parent, $rate );
+ $class->htbClass( $dev, $parent, $rate );
foreach my $match ( $class->matchRules() ) {
- $match->filter( $out, $dev, $parent, 1, $class->{dsmark} );
- printf {$out} " classid %x:%x\n", $parent, $class->{id};
+ $match->filter( $dev, $parent, 1, $class->{dsmark} );
+ printf " classid %x:%x\n", $parent, $class->{id};
}
}
}
diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl
index 8b8b978..328e8d7 100755
--- a/scripts/vyatta-qos.pl
+++ b/scripts/vyatta-qos.pl
@@ -157,26 +157,24 @@ sub update_interface {
# When doing debugging just echo the commands
my $out;
- if ( defined $debug ) {
- open $out, '>-'
- or die "can't open stdout: $!";
- }
- else {
+ unless ($debug) {
open $out, "|-"
or exec qw:sudo /sbin/tc -batch -:
or die "Tc setup failed: $!\n";
+
+ select $out;
}
- $shaper->commands( $out, $device, $direction );
- if ( !close $out && !defined $debug ) {
+ $shaper->commands( $device, $direction );
+ return if ($debug);
+ select STDOUT;
+ unless (close $out) {
# cleanup any partial commands
delete_interface( $device, $direction );
# replay commands to stdout
- open $out, '>-';
- $shaper->commands( $out, $device, $direction );
- close $out;
+ $shaper->commands($device, $direction );
die "TC command failed.";
}
}