Blob Blame History Raw
From e4bfd9436500aa26dcc82d346039e8b1b886d64c Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Wed, 25 Mar 2020 11:27:55 +0800
Subject: [PATCH] dns: Enable support of 3+ unmixed DNS name server

Support 3 or more IPv4/IPv6 only DNS name servers.
Still not supported 3+ IPv4 and IPv6 mixed name servers.

A warning will be emitted when 4 or more DNS name severs defined.

Integration test cases added.

Signed-off-by: Gris Ge <fge@redhat.com>
---
 libnmstate/validator.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libnmstate/validator.py b/libnmstate/validator.py
index a817930..0e61858 100644
--- a/libnmstate/validator.py
+++ b/libnmstate/validator.py
@@ -166,9 +166,18 @@ def validate_dns(state):
     dns_servers = (
         state.get(DNS.KEY, {}).get(DNS.CONFIG, {}).get(DNS.SERVER, [])
     )
-    if len(dns_servers) > 2:
+    if len(dns_servers) > 3:
+        logging.warning(
+            "The libc resolver may not support more than 3 nameservers."
+        )
+    if (
+        len(dns_servers) > 2
+        and any(is_ipv6_address(n) for n in dns_servers)
+        and any(not is_ipv6_address(n) for n in dns_servers)
+    ):
         raise NmstateNotImplementedError(
-            "Nmstate only support at most 2 DNS name servers"
+            "Three or more nameservers are only supported when using "
+            "either IPv4 or IPv6 nameservers but not both."
         )
 
 
-- 
2.18.2