summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
authorGiga Murphy <giga1699@gmail.com>2023-08-18 00:26:51 +0000
committerGiga Murphy <giga1699@gmail.com>2023-08-18 00:26:51 +0000
commit33b9bc55f9e3d7ce6a5ff447a6b545a96915daf3 (patch)
treee1f8072a5f86d3ad2f69cc819b1f5afb05832cee /python/vyos/ifconfig
parent65ea7cef9fe922581e286bc539c4dc1e223c9d32 (diff)
downloadvyos-1x-33b9bc55f9e3d7ce6a5ff447a6b545a96915daf3.tar.gz
vyos-1x-33b9bc55f9e3d7ce6a5ff447a6b545a96915daf3.zip
T5447: Initial support for MACsec static keys
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r--python/vyos/ifconfig/macsec.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/python/vyos/ifconfig/macsec.py b/python/vyos/ifconfig/macsec.py
index 1a78d18d8..6318a1688 100644
--- a/python/vyos/ifconfig/macsec.py
+++ b/python/vyos/ifconfig/macsec.py
@@ -39,12 +39,36 @@ class MACsecIf(Interface):
def _create(self):
"""
Create MACsec interface in OS kernel. Interface is administrative
- down by default.
+ down by default when not using static keys.
"""
+
# create tunnel interface
cmd = 'ip link add link {source_interface} {ifname} type {type}'.format(**self.config)
cmd += f' cipher {self.config["security"]["cipher"]}'
self._cmd(cmd)
- # interface is always A/D down. It needs to be enabled explicitly
- self.set_admin_state('down')
+ # Check if using static keys
+ if 'static' in self.config["security"]:
+ # Set static TX key
+ cmd = 'ip macsec add {ifname} tx sa 0 pn 1 on key 00'.format(**self.config)
+ cmd += f' {self.config["security"]["static"]["tx_key"]}'
+ self._cmd(cmd)
+
+ for peer, peer_config in self.config["security"]["static"]["peer"].items():
+ if 'disable' in peer_config:
+ continue
+
+ # Create the address
+ cmd = 'ip macsec add {ifname} rx port 1 address'.format(**self.config)
+ cmd += f' {peer_config["mac"]}'
+ self._cmd(cmd)
+ # Add the rx-key to the address
+ cmd += f' sa 0 pn 1 on key 01 {peer_config["rx_key"]}'
+ self._cmd(cmd)
+
+ # Set admin state to up
+ self.set_admin_state('up')
+
+ else:
+ # interface is always A/D down. It needs to be enabled explicitly
+ self.set_admin_state('down')