2 * dns.c - skeleton vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
22 #include <vnet/ip/ip.h>
24 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
26 /* Declare message IDs */
27 #include <dns/dns.api_enum.h>
28 #include <dns/dns.api_types.h>
32 /* API message ID base */
37 dns_test_main_t dns_test_main;
39 #define __plugin_msg_base dns_test_main.msg_id_base
40 #include <vlibapi/vat_helper_macros.h>
42 static void vl_api_dns_resolve_name_reply_t_handler
43 (vl_api_dns_resolve_name_reply_t * mp)
45 vat_main_t *vam = dns_test_main.vat_main;
46 i32 retval = (i32) clib_net_to_host_u32 (mp->retval);
50 clib_warning ("resolved: %U", format_ip4_address, mp->ip4_address);
52 clib_warning ("resolved: %U", format_ip6_address, mp->ip6_address);
55 vam->async_errors += (retval < 0);
59 vam->result_ready = 1;
63 static void vl_api_dns_resolve_ip_reply_t_handler
64 (vl_api_dns_resolve_ip_reply_t * mp)
66 vat_main_t *vam = dns_test_main.vat_main;
67 i32 retval = (i32) clib_net_to_host_u32 (mp->retval);
69 clib_warning ("resolved: %s", mp->name);
71 vam->async_errors += (retval < 0);
75 vam->result_ready = 1;
80 api_dns_enable_disable (vat_main_t * vam)
82 vl_api_dns_enable_disable_t *mp;
83 unformat_input_t *i = vam->input;
87 /* Parse args required to build the message */
88 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
90 if (unformat (i, "disable"))
92 else if (unformat (i, "enable"))
98 /* Construct the API message */
99 M (DNS_ENABLE_DISABLE, mp);
105 /* Wait for a reply... */
111 api_dns_resolve_name (vat_main_t * vam)
113 unformat_input_t *line_input = vam->input;
114 vl_api_dns_resolve_name_t *mp;
118 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
120 if (unformat (line_input, "%s", &name))
128 errmsg ("missing name to resolve");
132 if (vec_len (name) > 127)
134 errmsg ("name too long");
138 /* Construct the API message */
139 M (DNS_RESOLVE_NAME, mp);
140 memcpy (mp->name, name, vec_len (name));
145 /* Wait for the reply */
151 api_dns_resolve_ip (vat_main_t * vam)
153 unformat_input_t *line_input = vam->input;
154 vl_api_dns_resolve_ip_t *mp;
160 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
162 if (unformat (line_input, "%U", unformat_ip6_address, &addr6))
164 else if (unformat (line_input, "%U", unformat_ip4_address, &addr4))
172 errmsg ("missing address");
176 /* Construct the API message */
177 M (DNS_RESOLVE_IP, mp);
180 memcpy (mp->address, &addr6, sizeof (addr6));
182 memcpy (mp->address, &addr4, sizeof (addr4));
186 /* Wait for the reply */
192 api_dns_name_server_add_del (vat_main_t * vam)
194 unformat_input_t *i = vam->input;
195 vl_api_dns_name_server_add_del_t *mp;
197 ip6_address_t ip6_server;
198 ip4_address_t ip4_server;
203 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
205 if (unformat (i, "%U", unformat_ip6_address, &ip6_server))
207 else if (unformat (i, "%U", unformat_ip4_address, &ip4_server))
209 else if (unformat (i, "del"))
213 clib_warning ("parse error '%U'", format_unformat_error, i);
218 if (ip4_set && ip6_set)
220 errmsg ("Only one server address allowed per message");
223 if ((ip4_set + ip6_set) == 0)
225 errmsg ("Server address required");
229 /* Construct the API message */
230 M (DNS_NAME_SERVER_ADD_DEL, mp);
234 memcpy (mp->server_address, &ip6_server, sizeof (ip6_address_t));
239 memcpy (mp->server_address, &ip4_server, sizeof (ip4_address_t));
248 /* Wait for a reply, return good/bad news */
253 #include <dns/dns.api_test.c>
256 * fd.io coding-style-patch-verification: ON
259 * eval: (c-set-style "gnu")