From 4fa93aefd1e4c525267f90b5fd7797157946c9bd Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Sun, 16 Jun 2019 20:20:09 +0200
Subject: bfd: T1183: IPv6 peers require explicit local address/interface

---
 src/conf_mode/protocols_bfd.py | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

(limited to 'src/conf_mode')

diff --git a/src/conf_mode/protocols_bfd.py b/src/conf_mode/protocols_bfd.py
index 7e137c484..51af67ff6 100755
--- a/src/conf_mode/protocols_bfd.py
+++ b/src/conf_mode/protocols_bfd.py
@@ -15,7 +15,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+import sys
 import copy
+import vyos.validate
+
+from vyos import ConfigError
 from vyos.config import Config
 
 default_config_data = {
@@ -33,7 +37,7 @@ def get_config():
     for peer in conf.list_nodes('peer'):
         conf.set_level('protocols bfd peer {0}'.format(peer))
         bfd_peer = {
-            'peer': peer,
+            'remote': peer,
             'shutdown': False,
             'local-interface': '',
             'local-address': '',
@@ -53,16 +57,36 @@ def get_config():
 
         bfd['peers'].append(bfd_peer)
 
-    print(bfd)
     return bfd
 
 def verify(bfd):
+    if bfd is None:
+        return None
+
+    for peer in bfd['peers']:
+        # Bail out early if peer is shutdown
+        if peer['shutdown']:
+            continue
+
+        # IPv6 peers require an explicit local address/interface combination
+        if vyos.validate.is_ipv6(peer['remote']):
+            if not (peer['local-interface'] and peer['local-address']):
+                raise ConfigError("BFD IPv6 peers require explicit local address/interface setting")
+
+
     return None
 
 def generate(bfd):
+    if bfd is None:
+        return None
+
     return None
 
 def apply(bfd):
+    if bfd is None:
+        return None
+
+    print(bfd)
     return None
 
 if __name__ == '__main__':
-- 
cgit v1.2.3