diff options
author | Christian Breunig <christian@breunig.cc> | 2023-08-23 07:35:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 07:35:28 +0200 |
commit | 8c7fbec24f8bfe064d8ad804951f5ae59b54748f (patch) | |
tree | 6bbf7902d77f0761fe95719f2492efad3a486ede /python | |
parent | a090dd71231167cda95baaf7284e031230b5ee7a (diff) | |
parent | 007942130b3e9b86391fd08c3e372002afc6025e (diff) | |
download | vyos-1x-8c7fbec24f8bfe064d8ad804951f5ae59b54748f.tar.gz vyos-1x-8c7fbec24f8bfe064d8ad804951f5ae59b54748f.zip |
Merge pull request #2156 from giga1699/T5447
T5447: Initial support for MACsec static keys
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig/macsec.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/python/vyos/ifconfig/macsec.py b/python/vyos/ifconfig/macsec.py index 1a78d18d8..9329c5ee7 100644 --- a/python/vyos/ifconfig/macsec.py +++ b/python/vyos/ifconfig/macsec.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 VyOS maintainers and contributors <maintainers@vyos.io> +# Copyright 2020-2023 VyOS maintainers and contributors <maintainers@vyos.io> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -41,10 +41,30 @@ class MACsecIf(Interface): Create MACsec interface in OS kernel. Interface is administrative down by default. """ + # 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) + # 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"]["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["key"]}' + self._cmd(cmd) + # interface is always A/D down. It needs to be enabled explicitly self.set_admin_state('down') |