summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-02-05 16:53:46 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-02-05 16:53:46 -0800
commit24b46144a00f1346b0c983884e3f11b91b0c4379 (patch)
tree5643fcf4e33a70e4d7f510a3e0e85b5022808e9d
parentcbea4bffaf8ee64229db7624d63e47427c43d664 (diff)
downloadvyatta-cfg-qos-24b46144a00f1346b0c983884e3f11b91b0c4379.tar.gz
vyatta-cfg-qos-24b46144a00f1346b0c983884e3f11b91b0c4379.zip
add validation for policy names, and policy update/delete
Check names of policys for syntax and uniqueness. Add hooks for update that does refresh of interface (should fix bug). Block deletion of policy that is in use.
-rwxr-xr-xscripts/vyatta-qos.pl118
-rw-r--r--templates/interfaces/ethernet/node.tag/qos-policy/out/node.def4
-rw-r--r--templates/qos-policy/fair-queue/node.def6
-rw-r--r--templates/qos-policy/traffic-shaper/node.def4
4 files changed, 104 insertions, 28 deletions
diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl
index 4ca96b8..ea9d60d 100755
--- a/scripts/vyatta-qos.pl
+++ b/scripts/vyatta-qos.pl
@@ -9,23 +9,29 @@ use Getopt::Long;
my $qosNode = 'qos-policy';
my $debug = $ENV{'QOS_DEBUG'};
-my @update = ();
-my @delete = ();
-my $list = undef;
+my @updateInterface = ();
+my @deleteInterface = ();
+my @updatePolicy = ();
+my $deletePolicy = undef;
+my $listName = undef;
+my $validateName = undef;
GetOptions(
- "list" => \$list,
- "update=s{3}" => \@update,
- "delete=s{2}" => \@delete,
+ "list-policy" => \$listName,
+ "validate-name=s" => \$validateName,
+ "update-interface=s{3}" => \@updateInterface,
+ "delete-interface=s{2}" => \@deleteInterface,
+ "update-policy=s{2}" => \@updatePolicy,
+ "delete-policy=s" => \$deletePolicy,
);
-## list available qos policy names
-sub list_available {
+## list defined qos policy names
+sub list_inuse {
my $config = new VyattaConfig;
my @nodes = ();
- foreach my $policy ( $config->listNodes($qosNode) ) {
- foreach my $name ( $config->listNodes("$qosNode $policy") ) {
+ foreach my $policy ($config->listNodes($qosNode) ) {
+ foreach my $name ($config->listNodes("$qosNode $policy") ) {
push @nodes, $name;
}
}
@@ -33,12 +39,29 @@ sub list_available {
print join( ' ', @nodes ), "\n";
}
+## check if name is okay
+sub validate_name {
+ my $name = shift;
+ my $config = new VyattaConfig;
+
+ ($name =~ '^\w[\w_-]*$') or die "Invalid policy name $name\n";
+
+ foreach my $policy ($config->listNodes($qosNode) ) {
+ foreach my $node ($config->listNodes("$qosNode $policy") ) {
+ if ($name eq $node) {
+ die "Name $name is already in use by $policy\n";
+ }
+ }
+ }
+}
+
+
## delete_interface('eth0', 'out')
# remove all filters and qdisc's
sub delete_interface {
- my ( $interface, $direction ) = @_;
+ my ($interface, $direction ) = @_;
- if ( $direction =~ /^out/ ) {
+ if ($direction eq "out" ) {
# delete old qdisc - will give error if no policy in place
system("tc qdisc del dev $interface root 2>/dev/null");
@@ -52,11 +75,12 @@ sub delete_interface {
## update_interface('eth0', 'out', 'my-shaper')
# update policy to interface
sub update_interface {
- my ( $interface, $direction, $name ) = @_;
+ my ($interface, $direction, $name ) = @_;
my $config = new VyattaConfig;
+ print "update_interface $interface $direction $name\n";
# TODO: add support for ingress
- ( $direction =~ /^out/ ) or die "Only out direction supported";
+ ( $direction eq "out" ) or die "Only out direction supported";
foreach my $policy ( $config->listNodes($qosNode) ) {
if ( $config->exists("$qosNode $policy $name") ) {
@@ -87,24 +111,72 @@ sub update_interface {
die "Unknown $qosNode $name\n";
}
-if ( defined $list ) {
- list_available();
+sub delete_policy {
+ my ( $name ) = @_;
+ my $config = new VyattaConfig;
+
+ $config->setLevel("interfaces ethernet");
+ foreach my $interface ( $config->listNodes() ) {
+ foreach my $direction ($config->listNodes("$interface qos-policy")) {
+ if ($config->returnValue("$interface qos-policy $direction") eq $name) {
+ # can't delete active policy
+ die "Qos policy $name still in use on ethernet $interface $direction\n";
+ }
+ }
+ }
+}
+
+sub update_policy {
+ my ($shaper, $name) = @_;
+ my $config = new VyattaConfig;
+
+ $config->setLevel("interfaces ethernet");
+ foreach my $interface ( $config->listNodes()) {
+ foreach my $direction ($config->listNodes("$interface qos-policy")) {
+ if ($config->returnValue("$interface qos-policy $direction") eq $name) {
+ delete_interface($interface, $direction);
+ update_interface($interface, $direction, $name);
+ }
+ }
+ }
+}
+
+if ( defined $listName ) {
+ list_inuse();
+ exit 0;
+}
+
+if ( defined $validateName ) {
+ validate_name($validateName);
+ exit 0;
+}
+
+if ( $#deleteInterface == 1 ) {
+ delete_interface(@deleteInterface);
+ exit 0;
+}
+
+if ( $#updateInterface == 2 ) {
+ update_interface(@updateInterface);
exit 0;
}
-if ( $#delete == 1 ) {
- delete_interface(@delete);
+if ( defined $deletePolicy ) {
+ delete_policy($deletePolicy);
exit 0;
}
-if ( $#update == 2 ) {
- update_interface(@update);
+if ( $#updatePolicy == 1) {
+ update_policy(@updatePolicy);
exit 0;
}
print <<EOF;
-usage: vyatta-qos.pl --list
- vyatta-qos.pl --update interface direction policy
- vyatta-qos.pl --delete interface direction
+usage: vyatta-qos.pl --list-policy
+ vyatta-qos.pl --validate-name policy-name
+ vyatta-qos.pl --update-interface interface direction policy-name
+ vyatta-qos.pl --delete-interface interface direction
+ vyatta-qos.pl --update-policy policy-type policy-name
+ vyatta-qos.pl --delete-policy policy-type policy-name
EOF
exit 1;
diff --git a/templates/interfaces/ethernet/node.tag/qos-policy/out/node.def b/templates/interfaces/ethernet/node.tag/qos-policy/out/node.def
index 20ecd5e..c8f875f 100644
--- a/templates/interfaces/ethernet/node.tag/qos-policy/out/node.def
+++ b/templates/interfaces/ethernet/node.tag/qos-policy/out/node.def
@@ -1,4 +1,4 @@
type: txt
help: Set outbound QOS policy
-update:expression: "/opt/vyatta/sbin/vyatta-qos.pl --update $VAR(../../@) out $VAR(@)"
-delete:expression: "/opt/vyatta/sbin/vyatta-qos.pl --delete $VAR(../../@) out"
+update:expression: "/opt/vyatta/sbin/vyatta-qos.pl --update-interface $VAR(../../@) $VAR(../@) $VAR(@)"
+delete:expression: "/opt/vyatta/sbin/vyatta-qos.pl --delete-interface $VAR(../../@) $VAR(../@)"
diff --git a/templates/qos-policy/fair-queue/node.def b/templates/qos-policy/fair-queue/node.def
index 304e0d4..3ec844e 100644
--- a/templates/qos-policy/fair-queue/node.def
+++ b/templates/qos-policy/fair-queue/node.def
@@ -1,4 +1,6 @@
tag:
type: txt
-syntax:expression: pattern $VAR(@) "^[^-]" ; "Qos queue name cannot start with \"-\""
-help: Configure fair queueing based policy
+help: Configure fair queueing policy
+syntax:expression: exec " /opt/vyatta/sbin/vyatta-qos.pl --validate-name $VAR(@)"
+update:expression: "/opt/vyatta/sbin/vyatta-qos.pl --update-policy $VAR(../@) $VAR(@)"
+delete:expression: "/opt/vyatta/sbin/vyatta-qos.pl --delete-policy $VAR(@)"
diff --git a/templates/qos-policy/traffic-shaper/node.def b/templates/qos-policy/traffic-shaper/node.def
index 38d72d2..afb77bd 100644
--- a/templates/qos-policy/traffic-shaper/node.def
+++ b/templates/qos-policy/traffic-shaper/node.def
@@ -1,4 +1,6 @@
tag:
type: txt
-syntax:expression: pattern $VAR(@) "^[^-]" ; "Qos queue name cannot start with \"-\""
help: Configure traffic shaping based policy
+syntax:expression: exec " /opt/vyatta/sbin/vyatta-qos.pl --validate-name $VAR(@)"
+update:expression: "/opt/vyatta/sbin/vyatta-qos.pl --update-policy $VAR(../@) $VAR(@)"
+delete:expression: "/opt/vyatta/sbin/vyatta-qos.pl --delete-policy $VAR(@)"