diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 6fd6bbd1125c..69635053245b 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -66,8 +66,9 @@ Table of Contents * [LOGGER](#logger) * [WRED_PROFILE](#wred_profile) * [PASSWORD_HARDENING](#password_hardening) - * [SYSTEM_DEFAULTS table](#systemdefaults-table) - * [RADIUS](#radius) + * [SYSTEM_DEFAULTS table](#systemdefaults-table) + * [RADIUS](#radius) + * [Static DNS](#static-dns) * [For Developers](#for-developers) * [Generating Application Config by Jinja2 Template](#generating-application-config-by-jinja2-template) * [Incremental Configuration by Subscribing to ConfigDB](#incremental-configuration-by-subscribing-to-configdb) @@ -2096,6 +2097,19 @@ The RADIUS and RADIUS_SERVER tables define RADIUS configuration parameters. RADI } ``` +### Static DNS + +The DNS_NAMESERVER table introduces static DNS nameservers configuration. + +```json +{ + "DNS_NAMESERVER": { + "1.1.1.1": {}, + "fe80:1000:2000:3000::1": {} + }, +} +``` + #### 5.2.3 Update value directly in db memory For Developers diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 2afc3c85f0ac..16e962f0b0b8 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -107,6 +107,7 @@ def run(self): './yang-models/sonic-device_neighbor_metadata.yang', './yang-models/sonic-dhcp-server.yang', './yang-models/sonic-dhcpv6-relay.yang', + './yang-models/sonic-dns.yang', './yang-models/sonic-events-bgp.yang', './yang-models/sonic-events-common.yang', './yang-models/sonic-events-dhcp-relay.yang', diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index f9945175cf48..23bcf94d8fa7 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -8,6 +8,10 @@ "192.0.0.8": {}, "192.0.0.8": {} }, + "DNS_NAMESERVER": { + "1.1.1.1": {}, + "fe80:1000:2000:3000::1": {} + }, "BUFFER_POOL": { "ingress_lossy_pool": { "mode": "static", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/dns.json b/src/sonic-yang-models/tests/yang_model_tests/tests/dns.json new file mode 100644 index 000000000000..538eee4de72c --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/dns.json @@ -0,0 +1,13 @@ +{ + "DNS_NAMESERVER_TEST" : { + "desc": "DNS nameserver configuration in DNS_NAMESERVER table." + }, + "DNS_NAMESERVER_TEST_INVALID_IP" : { + "desc": "DNS nameserver configuration with invalid IP value in DNS_NAMESERVER table.", + "eStr": "Invalid value" + }, + "DNS_NAMESERVER_TEST_MAX_IP_NUMBER" : { + "desc": "DNS nameserver configuration exceeds the maximum IPs in DNS_NAMESERVER table.", + "eStr": "Too many elements." + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/dns.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/dns.json new file mode 100644 index 000000000000..da14e8566c45 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/dns.json @@ -0,0 +1,47 @@ +{ + "DNS_NAMESERVER_TEST": { + "sonic-dns:sonic-dns": { + "sonic-dns:DNS_NAMESERVER": { + "DNS_NAMESERVER_LIST": [ + { + "ip": "192.168.1.1" + }, + { + "ip": "fe80:1000:2000:3000::1" + } + ] + } + } + }, + "DNS_NAMESERVER_TEST_INVALID_IP": { + "sonic-dns:sonic-dns": { + "sonic-dns:DNS_NAMESERVER": { + "DNS_NAMESERVER_LIST": [ + { + "ip": "1.x.2.x" + } + ] + } + } + }, + "DNS_NAMESERVER_TEST_MAX_IP_NUMBER": { + "sonic-dns:sonic-dns": { + "sonic-dns:DNS_NAMESERVER": { + "DNS_NAMESERVER_LIST": [ + { + "ip": "192.168.1.1" + }, + { + "ip": "fe80:1000:2000:3000::2" + }, + { + "ip": "192.168.1.3" + }, + { + "ip": "fe80:1000:2000:3000::4" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-dns.yang b/src/sonic-yang-models/yang-models/sonic-dns.yang new file mode 100644 index 000000000000..87366d60e82a --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-dns.yang @@ -0,0 +1,45 @@ +module sonic-dns { + + namespace "http://github.com/sonic-net/sonic-dns"; + yang-version 1.1; + prefix dns; + + import ietf-inet-types { + prefix inet; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description "DNS YANG module for SONiC OS"; + + revision 2023-02-14 { + description "Initial version"; + } + + container sonic-dns { + + container DNS_NAMESERVER { + + description "DNS_NAMESERVER part of config_db.json"; + + list DNS_NAMESERVER_LIST { + max-elements 3; + description "List of nameservers IPs"; + + key "ip"; + + leaf ip { + description "IP as DHCP_SERVER"; + type inet:ip-address; + } + } /* end of list DNS_NAMESERVER_LIST */ + + } /* end of container DNS_NAMESERVER */ + + } /* end of container sonic-dns */ + +} /* end of module sonic-dns */