summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Qos/Match.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Vyatta/Qos/Match.pm')
-rw-r--r--lib/Vyatta/Qos/Match.pm145
1 files changed, 74 insertions, 71 deletions
diff --git a/lib/Vyatta/Qos/Match.pm b/lib/Vyatta/Qos/Match.pm
index a3842f6..4406b98 100644
--- a/lib/Vyatta/Qos/Match.pm
+++ b/lib/Vyatta/Qos/Match.pm
@@ -21,17 +21,17 @@ use strict;
use warnings;
sub getPort {
- my ($str, $proto) = @_;
+ my ( $str, $proto ) = @_;
return unless defined($str);
if ( $str =~ /^([0-9]+)|(0x[0-9a-fA-F]+)$/ ) {
- die "$str is not a valid port number\n"
- if ( $str <= 0 || $str > 65535 );
+ die "$str is not a valid port number\n"
+ if ( $str <= 0 || $str > 65535 );
return $str;
}
-
+
$proto = "tcp" unless $proto;
- my $port = getservbyname($str, $proto);
+ my $port = getservbyname( $str, $proto );
die "$str unknown $proto port name\n" unless $port;
return $port;
@@ -52,24 +52,25 @@ sub new {
if ( $af eq 'ether' ) {
$fields{protocol} = $config->returnValue("ether protocol");
- $fields{src} = $config->returnValue("ether source");
- $fields{dst} = $config->returnValue("ether destination");
+ $fields{src} = $config->returnValue("ether source");
+ $fields{dst} = $config->returnValue("ether destination");
} else {
- $fields{dsfield} =
- getDsfield( $config->returnValue("$af dscp") );
- my $ipprot = $config->returnValue("$af protocol");
+ $fields{dsfield} = getDsfield( $config->returnValue("$af dscp") );
+ my $ipprot = $config->returnValue("$af protocol");
$fields{protocol} = getProtocol($ipprot);
- $fields{src} = $config->returnValue("$af source address");
- $fields{dst} = $config->returnValue("$af destination address");
- $fields{sport} = getPort($config->returnValue("$af source port"), $ipprot);
- $fields{dport} = getPort($config->returnValue("$af destination port"), $ipprot);
+ $fields{src} = $config->returnValue("$af source address");
+ $fields{dst} = $config->returnValue("$af destination address");
+ $fields{sport} =
+ getPort( $config->returnValue("$af source port"), $ipprot );
+ $fields{dport} =
+ getPort( $config->returnValue("$af destination port"), $ipprot );
}
$self->{$af} = \%fields;
- die "Can not match on both $af and $lastaf protocol in same match\n"
- if $lastaf;
- $lastaf = $af;
+ die "Can not match on both $af and $lastaf protocol in same match\n"
+ if $lastaf;
+ $lastaf = $af;
}
my $vif = $config->returnValue("vif");
@@ -82,10 +83,10 @@ sub new {
$self->{_fwmark} = $fwmark;
if ($lastaf) {
- die "Can not combine protocol and vlan tag match\n"
- if ($vif);
- die "Can not combine protocol and interface match\n"
- if ($iif);
+ die "Can not combine protocol and vlan tag match\n"
+ if ($vif);
+ die "Can not combine protocol and interface match\n"
+ if ($iif);
}
return $self;
@@ -105,12 +106,12 @@ sub filter {
next unless $ip && $$ip{dsfield};
printf "filter add dev %s parent %x: protocol %s prio $prio",
- $dev, $parent, $ipver;
+ $dev, $parent, $ipver;
printf " handle %s tcindex classid %x:%x\n",
- $$ip{dsfield}, $parent, $classid;
+ $$ip{dsfield}, $parent, $classid;
- $prio += 1;
- }
+ $prio += 1;
+ }
return;
}
@@ -119,43 +120,44 @@ sub filter {
my $p = $self->{$proto};
next unless $p;
- printf "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
- if ($proto eq 'ether') {
- my $type = $$p{protocol};
- $type = 'all' unless $type;
-
- if (defined($$p{src}) || defined($$p{dest})) {
- print " protocol $type u32";
- print " match ether src $$p{src}" if $$p{src};
- print " match ether dst $$p{dst}" if $$p{dst};
- } else {
- # u32 requires some options to work but basic works
- print " protocol $type basic";
- }
- } else {
- print " protocol all u32";
-
- # workaround inconsistent usage in tc u32 match
- my $sel = $proto;
- if ($proto eq 'ipv6') {
- $sel = 'ip6';
- printf " match u16 0x%x 0x0ff0 at 0", hex($$p{dsfield}) << 4,
- if $$p{dsfield};
- } else {
- print " match $sel dsfield $$p{dsfield} 0xff" if $$p{dsfield};
- }
- print " match $sel protocol $$p{protocol} 0xff" if $$p{protocol};
-
- print " match $sel src $$p{src}" if $$p{src};
- print " match $sel sport $$p{sport} 0xffff" if $$p{sport};
- print " match $sel dst $$p{dst}" if $$p{dst};
- print " match $sel dport $$p{dport} 0xffff" if $$p{dport};
- }
-
- print " match mark $fwmark 0xff" if $fwmark;
- print " $police" if $police;
- printf " flowid %x:%x\n", $parent, $classid;
- return;
+ printf "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
+ if ( $proto eq 'ether' ) {
+ my $type = $$p{protocol};
+ $type = 'all' unless $type;
+
+ if ( defined( $$p{src} ) || defined( $$p{dest} ) ) {
+ print " protocol $type u32";
+ print " match ether src $$p{src}" if $$p{src};
+ print " match ether dst $$p{dst}" if $$p{dst};
+ } else {
+
+ # u32 requires some options to work but basic works
+ print " protocol $type basic";
+ }
+ } else {
+ print " protocol all u32";
+
+ # workaround inconsistent usage in tc u32 match
+ my $sel = $proto;
+ if ( $proto eq 'ipv6' ) {
+ $sel = 'ip6';
+ printf " match u16 0x%x 0x0ff0 at 0", hex( $$p{dsfield} ) << 4,
+ if $$p{dsfield};
+ } else {
+ print " match $sel dsfield $$p{dsfield} 0xff" if $$p{dsfield};
+ }
+ print " match $sel protocol $$p{protocol} 0xff" if $$p{protocol};
+
+ print " match $sel src $$p{src}" if $$p{src};
+ print " match $sel sport $$p{sport} 0xffff" if $$p{sport};
+ print " match $sel dst $$p{dst}" if $$p{dst};
+ print " match $sel dport $$p{dport} 0xffff" if $$p{dport};
+ }
+
+ print " match mark $fwmark 0xff" if $fwmark;
+ print " $police" if $police;
+ printf " flowid %x:%x\n", $parent, $classid;
+ return;
}
my $indev = $self->{_indev};
@@ -165,15 +167,16 @@ sub filter {
print " protocol all basic";
print " match meta\(rt_iif eq $indev\)" if $indev;
print " match meta\(vlan mask 0xfff eq $vif\)" if $vif;
- print " match meta\(fwmark eq $fwmark\)" if $fwmark;
-
- print " $police" if $police;
- printf " flowid %x:%x\n", $parent, $classid;
- } elsif ( $fwmark ) {
- printf "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
- printf " protocol all handle %d fw", $fwmark;
- print " $police" if $police;
- printf " flowid %x:%x\n", $parent, $classid;
+ print " match meta\(fwmark eq $fwmark\)" if $fwmark;
+
+ print " $police" if $police;
+ printf " flowid %x:%x\n", $parent, $classid;
+ }
+ elsif ($fwmark) {
+ printf "filter add dev %s parent %x: prio %d", $dev, $parent, $prio;
+ printf " protocol all handle %d fw", $fwmark;
+ print " $police" if $police;
+ printf " flowid %x:%x\n", $parent, $classid;
}
}