summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorfenglei <1579628578@qq.com>2024-11-21 20:32:25 +0800
committerBeno�t Ganne <bganne@cisco.com>2024-12-18 10:10:15 +0000
commitbdb52dc044a9b034ce87233b7c6b0aa64daa350f (patch)
tree7399a4802e2756e9dc3cab86d3bacb4e9edb5d32 /src
parent098d0c594898759d3df6c0b215061f52e59905e3 (diff)
dns: cli support enable dns and config server addr
Type: improvement cli support enable dns node and config name server addr Change-Id: I4fcef28876b916bd5eac026f20afb0b0dda38fa2 Signed-off-by: fenglei <1579628578@qq.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/dns/dns.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/plugins/dns/dns.c b/src/plugins/dns/dns.c
index 3cecf942d55..de01474703b 100644
--- a/src/plugins/dns/dns.c
+++ b/src/plugins/dns/dns.c
@@ -2304,6 +2304,87 @@ VLIB_CLI_COMMAND (dns_cache_add_del_command) =
.function = dns_cache_add_del_command_fn,
};
+static clib_error_t *
+dns_enable_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ dns_main_t *dm = &dns_main;
+ u32 enable_disable;
+ int rv;
+
+ enable_disable = 0;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "enable"))
+ enable_disable = 1;
+ else if (unformat (input, "disable"))
+ enable_disable = 0;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
+
+ rv = dns_enable_disable (vm, dm, enable_disable);
+ if (rv)
+ return clib_error_return (0, "%U", format_vnet_api_errno, rv);
+
+ return 0;
+}
+
+VLIB_CLI_COMMAND (dns_enable_disable_command) = {
+ .path = "dns",
+ .short_help = "dns [enable][disable]",
+ .function = dns_enable_disable_command_fn,
+};
+
+static clib_error_t *
+dns_name_server_add_del_command_fn (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ dns_main_t *dm = &dns_main;
+ u8 is_add = 1;
+ ip6_address_t ip6_server;
+ ip4_address_t ip4_server;
+ int ip6_set = 0;
+ int ip4_set = 0;
+ int rv = 0;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "%U", unformat_ip6_address, &ip6_server))
+ ip6_set = 1;
+ else if (unformat (input, "%U", unformat_ip4_address, &ip4_server))
+ ip4_set = 1;
+ else if (unformat (input, "del"))
+ is_add = 0;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
+
+ if (ip4_set && ip6_set)
+ return clib_error_return (0, "Only one server address configed");
+ if ((ip4_set + ip6_set) == 0)
+ return clib_error_return (0, "Server address required");
+
+ if (ip6_set)
+ rv = dns6_name_server_add_del (dm, ip6_server.as_u8, is_add);
+ else
+ rv = dns4_name_server_add_del (dm, ip4_server.as_u8, is_add);
+
+ if (rv)
+ return clib_error_return (0, "%U", format_vnet_api_errno, rv);
+
+ return 0;
+}
+
+VLIB_CLI_COMMAND (dns_name_server_add_del_command) = {
+ .path = "dns name-server",
+ .short_help = "dns name-server <ip-address> [del]",
+ .function = dns_name_server_add_del_command_fn,
+};
+
#define DNS_FORMAT_TEST 1
#if DNS_FORMAT_TEST > 0