summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-12-04 09:14:53 +0100
committerGitHub <noreply@github.com>2020-12-04 09:14:53 +0100
commitf84c971d336d5125103c3eaf772a5384af2f71da (patch)
tree4080194919921cbdd609d46d269e42c0912f1039 /python
parenta237979853a97945103291202d851de1e7bcd3f2 (diff)
parentede2972be4c49962a04b1addb9df6ce58f2d9f42 (diff)
downloadvyos-1x-f84c971d336d5125103c3eaf772a5384af2f71da.tar.gz
vyos-1x-f84c971d336d5125103c3eaf772a5384af2f71da.zip
Merge pull request #621 from jack9603301/T3089
interface: T3089: Migrate port mirroring to vyos-1x
Diffstat (limited to 'python')
-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):