summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Qos/IngressMirror.pm
blob: d3e52c076b038a2c4dfbd6a9bc7fb684c6dba2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Ingress Mirror
#   Duplicate all packets to another interface
#   This is useful for some forms of IDS or capture
#
# **** License ****
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc.
# All Rights Reserved.
# **** End License ****

package Vyatta::Qos::IngressMirror;
use strict;
use warnings;

require Vyatta::Config;

sub new {
    my ( $that, $config, $name ) = @_;
    my $self = {};
    my $class = ref($that) || $that;

    bless $self, $class;
    $self->_define($config);

    return $self;
}

# Setup new instance.
sub _define {
    my ( $self, $config ) = @_;
    # config is at level: interfaces ethernet $dev input-policy redirect
    $self->{_target} = $config->returnValue();
}

sub commands {
    my ( $self, $dev, $parent ) = @_;
    my $target = $self->{_target};

    # Apply filter to ingress qdisc
    # NB: action is egress because we are in ingress (upside down)
    printf "filter add dev %s parent %x: ", $dev, $parent;
    print  " protocol all prio 10 u32"; 
    print  " match u32 0 0 flowid 1:1";
    print  " action mirred egress mirror dev $target\n";
}

1;