summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorjack9603301 <jack9603301@163.com>2020-12-03 12:11:43 +0800
committerjack9603301 <jack9603301@163.com>2020-12-03 12:11:43 +0800
commitede2972be4c49962a04b1addb9df6ce58f2d9f42 (patch)
tree6b1d7cd1e129d8363fee51c5d202fbff412bccab /python/vyos
parent3169f1270fe8217fe57c9301e48b550539f14b77 (diff)
downloadvyos-1x-ede2972be4c49962a04b1addb9df6ce58f2d9f42.tar.gz
vyos-1x-ede2972be4c49962a04b1addb9df6ce58f2d9f42.zip
interface: T3089: Migrate port mirroring to vyos-1x
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/ifconfig/interface.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 43cd7220a..9f067b75e 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -35,6 +35,7 @@ from vyos.configdict import dict_merge
from vyos.template import render
from vyos.util import mac2eui64
from vyos.util import dict_search
+from vyos.util import cmd
from vyos.template import is_ipv4
from vyos.template import is_ipv6
from vyos.validate import is_intf_addr_assigned
@@ -929,7 +930,39 @@ class Interface(Control):
if os.path.isfile(config_file):
os.remove(config_file)
-
+
+ def get_tc_config(self,objectname):
+ # Parse configuration
+ get_tc_cmd = f'tc -j {objectname}'
+ tmp = cmd(get_tc_cmd, shell=True)
+ return json.loads(tmp)
+
+ def del_tc_qdisc(self,dev,kind,handle):
+ tc_qdisc = self.get_tc_config('qdisc')
+ for rule in tc_qdisc:
+ old_dev = rule['dev']
+ old_handle = rule['handle']
+ old_kind = rule['kind']
+ if old_dev == dev and old_handle == handle and old_kind == kind:
+ delete_tc_cmd = f'tc qdisc del dev {dev} handle {handle} {kind}'
+ self._cmd(delete_tc_cmd)
+
+
+
+ def apply_mirror(self,config):
+ ifname = config['ifname']
+
+ # Remove existing mirroring rules
+ self.del_tc_qdisc(ifname,'ingress','ffff:')
+
+ # Setting up packet mirroring
+ mirror = dict_search('mirror', config)
+ if mirror:
+ for interface in mirror:
+ mirror_cmd = f'tc qdisc add dev {ifname} handle ffff: ingress'
+ self._cmd(mirror_cmd)
+ mirror_cmd = f'tc filter add dev {ifname} parent ffff: protocol all prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress mirror dev {interface}'
+ self._cmd(mirror_cmd)
def update(self, config):
""" General helper function which works on a dictionary retrived by
@@ -1136,6 +1169,9 @@ class Interface(Control):
vif_config['ifname'] = vif_ifname
vlan = VLANIf(vif_ifname, **tmp)
vlan.update(vif_config)
+
+ self.apply_mirror(config)
+
class VLANIf(Interface):