summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-30 12:16:54 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-30 13:13:46 -0800
commita4a2575ccf7057ad77ab02a5486a1e7145504ac8 (patch)
treedf8cf3c2cd2527b2212223a6abc770519e1f18d1
parentaa8ecb694dc85cb67e2c9f7b5fe911888d0310e4 (diff)
downloadvyatta-cfg-qos-a4a2575ccf7057ad77ab02a5486a1e7145504ac8.tar.gz
vyatta-cfg-qos-a4a2575ccf7057ad77ab02a5486a1e7145504ac8.zip
Fix QoS over ppp interfaces
Bug 3473 Add ppp startup script to apply QoS on start of related interfaces.
-rw-r--r--Makefile.am4
-rw-r--r--etc/ppp/ip-up.d/20qos3
-rwxr-xr-xscripts/vyatta-qos.pl149
3 files changed, 76 insertions, 80 deletions
diff --git a/Makefile.am b/Makefile.am
index 950d05f..f9d1d10 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,10 +12,14 @@ share_perl5_DATA += lib/Vyatta/Qos/RateLimiter.pm
share_perl5_DATA += lib/Vyatta/Qos/DropTail.pm
share_perl5_DATA += lib/Vyatta/Qos/TrafficLimiter.pm
+etcdir = /etc
+etc_SCRIPTS =
+
cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \
cpio -0pd
install-exec-hook:
mkdir -p $(DESTDIR)$(cfgdir)
+ mkdir -p $(DESTDIR)/etc/ppp/ip-up.d
cd templates; $(cpiop) $(DESTDIR)$(cfgdir)
diff --git a/etc/ppp/ip-up.d/20qos b/etc/ppp/ip-up.d/20qos
new file mode 100644
index 0000000..af5f9c4
--- /dev/null
+++ b/etc/ppp/ip-up.d/20qos
@@ -0,0 +1,3 @@
+#! /bin/sh
+
+/opt/vyatta/sbin/vyatta-qos.pl --start-interface $1
diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl
index 20c56bf..3a3d8f7 100755
--- a/scripts/vyatta-qos.pl
+++ b/scripts/vyatta-qos.pl
@@ -21,23 +21,6 @@ use strict;
use Getopt::Long;
my $debug = $ENV{'QOS_DEBUG'};
-my ($check, $update, $applyChanges);
-my @updateInterface = ();
-my @deleteInterface = ();
-
-my ($listPolicy, $deletePolicy);
-my @createPolicy = ();
-
-GetOptions(
- "check" => \$check,
- "apply-changes" => \$applyChanges,
- "update-interface=s{3}" => \@updateInterface,
- "delete-interface=s{2}" => \@deleteInterface,
-
- "list-policy=s" => \$listPolicy,
- "delete-policy=s" => \$deletePolicy,
- "create-policy=s{2}" => \@createPolicy,
-);
my %policies = (
'out' => {
@@ -118,6 +101,24 @@ sub delete_interface {
}
}
+## start_interface('ppp0')
+# reapply qos policy to interface
+sub start_interface {
+ my $ifname = shift;
+ my $interface = new Vyatta::Interface($ifname);
+
+ die "Unknown interface type: $ifname" unless $interface;
+ my $config = new Vyatta::Config;
+ $config->setLevel($interface->path() . ' qos-policy');
+
+ foreach my $direction ( $config->listNodes( ) ) {
+ my $policy = $config->returnValue($direction);
+ next unless $policy;
+
+ update_interface($ifname, $direction, $policy);
+ }
+}
+
## update_interface('eth0', 'out', 'my-shaper')
# update policy to interface
sub update_interface {
@@ -126,35 +127,34 @@ sub update_interface {
$config->setLevel('qos-policy');
foreach my $type ( $config->listNodes() ) {
- if ( $config->exists("$type $name") ) {
- my $shaper = make_policy($config, $type, $name, $direction);
+ next if (! $config->exists("$type $name"));
+ my $shaper = make_policy($config, $type, $name, $direction);
- # Remove old policy
- delete_interface($interface, $direction);
+ # Remove old policy
+ delete_interface($interface, $direction);
- # When doing debugging just echo the commands
- my $out;
- if (defined $debug) {
- open $out, '>-'
- or die "can't open stdout: $!";
- } else {
- open $out, "|-" or exec qw:sudo /sbin/tc -batch -:
- or die "Tc setup failed: $!\n";
- }
-
- $shaper->commands($out, $interface);
- if (! close $out && ! defined $debug) {
- # cleanup any partial commands
- delete_interface($interface, $direction);
+ # When doing debugging just echo the commands
+ my $out;
+ if (defined $debug) {
+ open $out, '>-'
+ or die "can't open stdout: $!";
+ } else {
+ open $out, "|-" or exec qw:sudo /sbin/tc -batch -:
+ or die "Tc setup failed: $!\n";
+ }
- # replay commands to stdout
- open $out, '>-';
- $shaper->commands($out, $interface, $direction);
- close $out;
- die "TC command failed.";
- }
- exit 0;
- }
+ $shaper->commands($out, $interface, $direction);
+ if (! close $out && ! defined $debug) {
+ # cleanup any partial commands
+ delete_interface($interface, $direction);
+
+ # replay commands to stdout
+ open $out, '>-';
+ $shaper->commands($out, $interface, $direction);
+ close $out;
+ die "TC command failed.";
+ }
+ return;
}
die "Unknown qos-policy $name\n";
@@ -340,42 +340,8 @@ sub apply_changes {
}
}
-if ($check) {
- check_conflict();
- exit 0;
-}
-
-if ( $listPolicy ) {
- list_policy($listPolicy);
- exit 0;
-}
-
-if ( $#deleteInterface == 1 ) {
- delete_interface(@deleteInterface);
- exit 0;
-}
-
-if ( $#updateInterface == 2 ) {
- update_interface(@updateInterface);
- exit 0;
-}
-
-if ( $#createPolicy == 1) {
- create_policy(@createPolicy);
- exit 0;
-}
-
-if ( $deletePolicy ) {
- delete_policy($deletePolicy);
- exit 0;
-}
-
-if ( $applyChanges ) {
- apply_changes();
- exit 0;
-}
-
-print <<EOF;
+sub usage {
+ print <<EOF;
usage: vyatta-qos.pl --check
vyatta-qos.pl --list-policy
vyatta-qos.pl --apply-changes
@@ -387,4 +353,27 @@ usage: vyatta-qos.pl --check
vyatta-qos.pl --delete-interface interface direction
EOF
-exit 1;
+ exit 1;
+}
+
+my @updateInterface = ();
+my @deleteInterface = ();
+my @createPolicy = ();
+
+GetOptions(
+ "check" => sub { check_conflict(); },
+ "apply-changes" => sub { apply_changes(); },
+ "start-interace=s" => sub { start_interface( $_[1] ); },
+ "update-interface=s{3}" => \@updateInterface,
+ "delete-interface=s{2}" => \@deleteInterface,
+
+ "list-policy=s" => sub { list_policy( $_[1] ); },
+ "delete-policy=s" => sub { delete_policy( $_[1] ); },
+ "create-policy=s{2}" => \@createPolicy,
+) or usage();
+
+delete_interface(@deleteInterface) if ( $#deleteInterface == 1 );
+update_interface(@updateInterface) if ( $#updateInterface == 2 );
+create_policy(@createPolicy) if ( $#createPolicy == 1);
+
+