Line data Source code
1 : /*
2 : * Copyright (c) 2015 Cisco and/or its affiliates.
3 : * Licensed under the Apache License, Version 2.0 (the "License");
4 : * you may not use this file except in compliance with the License.
5 : * You may obtain a copy of the License at:
6 : *
7 : * http://www.apache.org/licenses/LICENSE-2.0
8 : *
9 : * Unless required by applicable law or agreed to in writing, software
10 : * distributed under the License is distributed on an "AS IS" BASIS,
11 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : * See the License for the specific language governing permissions and
13 : * limitations under the License.
14 : */
15 :
16 : #include <vat/vat.h>
17 : #include <vlibapi/api.h>
18 : #include <vlibmemory/api.h>
19 : #include <vppinfra/error.h>
20 : #include <vpp/api/types.h>
21 :
22 : #include <vnet/ip/ip_format_fns.h>
23 : #include <vnet/ethernet/ethernet_format_fns.h>
24 :
25 : /* define message IDs */
26 : #include <ip6-nd/ip6_nd.api_enum.h>
27 : #include <ip6-nd/ip6_nd.api_types.h>
28 : #include <vlibmemory/vlib.api_types.h>
29 :
30 : typedef struct
31 : {
32 : /* API message ID base */
33 : u16 msg_id_base;
34 : u32 ping_id;
35 : vat_main_t *vat_main;
36 : } ip6_nd_test_main_t;
37 :
38 : ip6_nd_test_main_t ip6_nd_test_main;
39 :
40 : #define __plugin_msg_base ip6_nd_test_main.msg_id_base
41 : #include <vlibapi/vat_helper_macros.h>
42 :
43 : static int
44 0 : api_want_ip6_ra_events (vat_main_t * vam)
45 : {
46 0 : return -1;
47 : }
48 :
49 : static int
50 0 : api_ip6nd_send_router_solicitation (vat_main_t * vam)
51 : {
52 0 : return -1;
53 : }
54 :
55 : static int
56 0 : api_ip6nd_proxy_add_del (vat_main_t * vam)
57 : {
58 0 : unformat_input_t *i = vam->input;
59 : vl_api_ip6nd_proxy_add_del_t *mp;
60 0 : u32 sw_if_index = ~0;
61 0 : u8 v6_address_set = 0;
62 : vl_api_ip6_address_t v6address;
63 0 : u8 is_add = 1;
64 : int ret;
65 :
66 : /* Parse args required to build the message */
67 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
68 : {
69 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
70 : ;
71 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index))
72 : ;
73 0 : else if (unformat (i, "%U", unformat_vl_api_ip6_address, &v6address))
74 0 : v6_address_set = 1;
75 0 : if (unformat (i, "del"))
76 0 : is_add = 0;
77 : else
78 : {
79 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
80 0 : return -99;
81 : }
82 : }
83 :
84 0 : if (sw_if_index == ~0)
85 : {
86 0 : errmsg ("missing interface name or sw_if_index");
87 0 : return -99;
88 : }
89 0 : if (!v6_address_set)
90 : {
91 0 : errmsg ("no address set");
92 0 : return -99;
93 : }
94 :
95 : /* Construct the API message */
96 0 : M (IP6ND_PROXY_ADD_DEL, mp);
97 :
98 0 : mp->is_add = is_add;
99 0 : mp->sw_if_index = ntohl (sw_if_index);
100 0 : clib_memcpy (mp->ip, v6address, sizeof (v6address));
101 :
102 : /* send it... */
103 0 : S (mp);
104 :
105 : /* Wait for a reply, return good/bad news */
106 0 : W (ret);
107 0 : return ret;
108 : }
109 :
110 : static int
111 0 : api_ip6nd_proxy_dump (vat_main_t * vam)
112 : {
113 : vl_api_ip6nd_proxy_dump_t *mp;
114 : vl_api_control_ping_t *mp_ping;
115 : int ret;
116 :
117 0 : M (IP6ND_PROXY_DUMP, mp);
118 :
119 0 : S (mp);
120 :
121 : /* Use a control ping for synchronization */
122 : /* Use a control ping for synchronization */
123 0 : mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
124 0 : mp_ping->_vl_msg_id = htons (ip6_nd_test_main.ping_id);
125 0 : mp_ping->client_index = vam->my_client_index;
126 0 : vam->result_ready = 0;
127 :
128 0 : S (mp_ping);
129 :
130 0 : W (ret);
131 0 : return ret;
132 : }
133 :
134 0 : static void vl_api_ip6nd_proxy_details_t_handler
135 : (vl_api_ip6nd_proxy_details_t * mp)
136 : {
137 0 : vat_main_t *vam = &vat_main;
138 :
139 0 : print (vam->ofp, "host %U sw_if_index %d",
140 0 : format_vl_api_ip6_address, mp->ip, ntohl (mp->sw_if_index));
141 0 : }
142 :
143 : static int
144 0 : api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
145 : {
146 0 : unformat_input_t *i = vam->input;
147 : vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
148 : u32 sw_if_index;
149 0 : u8 sw_if_index_set = 0;
150 0 : u8 v6_address_set = 0;
151 : vl_api_prefix_t pfx;
152 0 : u8 use_default = 0;
153 0 : u8 no_advertise = 0;
154 0 : u8 off_link = 0;
155 0 : u8 no_autoconfig = 0;
156 0 : u8 no_onlink = 0;
157 0 : u8 is_no = 0;
158 0 : u32 val_lifetime = 0;
159 0 : u32 pref_lifetime = 0;
160 : int ret;
161 :
162 : /* Parse args required to build the message */
163 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
164 : {
165 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
166 0 : sw_if_index_set = 1;
167 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index))
168 0 : sw_if_index_set = 1;
169 0 : else if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
170 0 : v6_address_set = 1;
171 0 : else if (unformat (i, "val_life %d", &val_lifetime))
172 : ;
173 0 : else if (unformat (i, "pref_life %d", &pref_lifetime))
174 : ;
175 0 : else if (unformat (i, "def"))
176 0 : use_default = 1;
177 0 : else if (unformat (i, "noadv"))
178 0 : no_advertise = 1;
179 0 : else if (unformat (i, "offl"))
180 0 : off_link = 1;
181 0 : else if (unformat (i, "noauto"))
182 0 : no_autoconfig = 1;
183 0 : else if (unformat (i, "nolink"))
184 0 : no_onlink = 1;
185 0 : else if (unformat (i, "isno"))
186 0 : is_no = 1;
187 : else
188 : {
189 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
190 0 : return -99;
191 : }
192 : }
193 :
194 0 : if (sw_if_index_set == 0)
195 : {
196 0 : errmsg ("missing interface name or sw_if_index");
197 0 : return -99;
198 : }
199 0 : if (!v6_address_set)
200 : {
201 0 : errmsg ("no address set");
202 0 : return -99;
203 : }
204 :
205 : /* Construct the API message */
206 0 : M (SW_INTERFACE_IP6ND_RA_PREFIX, mp);
207 :
208 0 : mp->sw_if_index = ntohl (sw_if_index);
209 0 : clib_memcpy (&mp->prefix, &pfx, sizeof (pfx));
210 0 : mp->use_default = use_default;
211 0 : mp->no_advertise = no_advertise;
212 0 : mp->off_link = off_link;
213 0 : mp->no_autoconfig = no_autoconfig;
214 0 : mp->no_onlink = no_onlink;
215 0 : mp->is_no = is_no;
216 0 : mp->val_lifetime = ntohl (val_lifetime);
217 0 : mp->pref_lifetime = ntohl (pref_lifetime);
218 :
219 : /* send it... */
220 0 : S (mp);
221 :
222 : /* Wait for a reply, return good/bad news */
223 0 : W (ret);
224 0 : return ret;
225 : }
226 :
227 : static int
228 0 : api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
229 : {
230 0 : unformat_input_t *i = vam->input;
231 : vl_api_sw_interface_ip6nd_ra_config_t *mp;
232 : u32 sw_if_index;
233 0 : u8 sw_if_index_set = 0;
234 0 : u8 suppress = 0;
235 0 : u8 managed = 0;
236 0 : u8 other = 0;
237 0 : u8 ll_option = 0;
238 0 : u8 send_unicast = 0;
239 0 : u8 cease = 0;
240 0 : u8 is_no = 0;
241 0 : u8 default_router = 0;
242 0 : u32 max_interval = 0;
243 0 : u32 min_interval = 0;
244 0 : u32 lifetime = 0;
245 0 : u32 initial_count = 0;
246 0 : u32 initial_interval = 0;
247 : int ret;
248 :
249 :
250 : /* Parse args required to build the message */
251 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
252 : {
253 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
254 0 : sw_if_index_set = 1;
255 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index))
256 0 : sw_if_index_set = 1;
257 0 : else if (unformat (i, "maxint %d", &max_interval))
258 : ;
259 0 : else if (unformat (i, "minint %d", &min_interval))
260 : ;
261 0 : else if (unformat (i, "life %d", &lifetime))
262 : ;
263 0 : else if (unformat (i, "count %d", &initial_count))
264 : ;
265 0 : else if (unformat (i, "interval %d", &initial_interval))
266 : ;
267 0 : else if (unformat (i, "suppress") || unformat (i, "surpress"))
268 0 : suppress = 1;
269 0 : else if (unformat (i, "managed"))
270 0 : managed = 1;
271 0 : else if (unformat (i, "other"))
272 0 : other = 1;
273 0 : else if (unformat (i, "ll"))
274 0 : ll_option = 1;
275 0 : else if (unformat (i, "send"))
276 0 : send_unicast = 1;
277 0 : else if (unformat (i, "cease"))
278 0 : cease = 1;
279 0 : else if (unformat (i, "isno"))
280 0 : is_no = 1;
281 0 : else if (unformat (i, "def"))
282 0 : default_router = 1;
283 : else
284 : {
285 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
286 0 : return -99;
287 : }
288 : }
289 :
290 0 : if (sw_if_index_set == 0)
291 : {
292 0 : errmsg ("missing interface name or sw_if_index");
293 0 : return -99;
294 : }
295 :
296 : /* Construct the API message */
297 0 : M (SW_INTERFACE_IP6ND_RA_CONFIG, mp);
298 :
299 0 : mp->sw_if_index = ntohl (sw_if_index);
300 0 : mp->max_interval = ntohl (max_interval);
301 0 : mp->min_interval = ntohl (min_interval);
302 0 : mp->lifetime = ntohl (lifetime);
303 0 : mp->initial_count = ntohl (initial_count);
304 0 : mp->initial_interval = ntohl (initial_interval);
305 0 : mp->suppress = suppress;
306 0 : mp->managed = managed;
307 0 : mp->other = other;
308 0 : mp->ll_option = ll_option;
309 0 : mp->send_unicast = send_unicast;
310 0 : mp->cease = cease;
311 0 : mp->is_no = is_no;
312 0 : mp->default_router = default_router;
313 :
314 : /* send it... */
315 0 : S (mp);
316 :
317 : /* Wait for a reply, return good/bad news */
318 0 : W (ret);
319 0 : return ret;
320 : }
321 : static int
322 0 : api_ip6nd_proxy_enable_disable (vat_main_t *vam)
323 : {
324 : // not yet implemented
325 0 : return -1;
326 : }
327 :
328 : static int
329 0 : api_sw_interface_ip6nd_ra_dump (vat_main_t *vam)
330 : {
331 0 : unformat_input_t *i = vam->input;
332 : vl_api_sw_interface_ip6nd_ra_dump_t *mp;
333 : vl_api_control_ping_t *mp_ping;
334 0 : u32 sw_if_index = ~0;
335 : int ret;
336 :
337 : /* Parse args required to build the message */
338 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
339 : {
340 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
341 : ;
342 0 : else if (unformat (i, "sw_if_index %u", &sw_if_index))
343 : ;
344 : else
345 : {
346 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
347 0 : return -99;
348 : }
349 : }
350 :
351 : /* Construct the API message */
352 0 : M (SW_INTERFACE_IP6ND_RA_DUMP, mp);
353 0 : mp->sw_if_index = ntohl (sw_if_index);
354 :
355 : /* Send it */
356 0 : S (mp);
357 :
358 : /* Use control ping for synchronization */
359 0 : PING (&ip6_nd_test_main, mp_ping);
360 0 : S (mp_ping);
361 :
362 : /* Wait for a reply... */
363 0 : W (ret);
364 :
365 0 : return ret;
366 : }
367 :
368 : static void
369 0 : vl_api_sw_interface_ip6nd_ra_details_t_handler (
370 : vl_api_sw_interface_ip6nd_ra_details_t *mp)
371 : {
372 0 : vat_main_t *vam = ip6_nd_test_main.vat_main;
373 : u32 sw_if_index;
374 : u8 send_radv;
375 :
376 : /* Read the message */
377 0 : sw_if_index = ntohl (mp->sw_if_index);
378 0 : send_radv = mp->send_radv;
379 :
380 : /* Print it */
381 0 : print (vam->ofp, "sw_if_index: %u, send_radv: %s", sw_if_index,
382 : (send_radv ? "on" : "off"));
383 0 : }
384 :
385 : #include <ip6-nd/ip6_nd.api_test.c>
386 :
387 : /*
388 : * fd.io coding-style-patch-verification: ON
389 : *
390 : * Local Variables:
391 : * eval: (c-set-style "gnu")
392 : * End:
393 : */
|