blob: 5ca37029a76c21a4196b1acff5b6b510b284b736 [file] [log] [blame]
Neale Rannscbe25aa2019-09-30 10:53:31 +00001/*
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 <vpp/api/vpe.api_types.h>
29
30typedef 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
38ip6_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
43static int
44api_want_ip6_ra_events (vat_main_t * vam)
45{
46 return -1;
47}
48
49static int
50api_ip6nd_send_router_solicitation (vat_main_t * vam)
51{
52 return -1;
53}
54
55static int
56api_ip6nd_proxy_add_del (vat_main_t * vam)
57{
58 unformat_input_t *i = vam->input;
59 vl_api_ip6nd_proxy_add_del_t *mp;
60 u32 sw_if_index = ~0;
61 u8 v6_address_set = 0;
62 vl_api_ip6_address_t v6address;
63 u8 is_add = 1;
64 int ret;
65
66 /* Parse args required to build the message */
67 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
68 {
69 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
70 ;
71 else if (unformat (i, "sw_if_index %d", &sw_if_index))
72 ;
73 else if (unformat (i, "%U", unformat_vl_api_ip6_address, &v6address))
74 v6_address_set = 1;
75 if (unformat (i, "del"))
76 is_add = 0;
77 else
78 {
79 clib_warning ("parse error '%U'", format_unformat_error, i);
80 return -99;
81 }
82 }
83
84 if (sw_if_index == ~0)
85 {
86 errmsg ("missing interface name or sw_if_index");
87 return -99;
88 }
89 if (!v6_address_set)
90 {
91 errmsg ("no address set");
92 return -99;
93 }
94
95 /* Construct the API message */
96 M (IP6ND_PROXY_ADD_DEL, mp);
97
98 mp->is_add = is_add;
99 mp->sw_if_index = ntohl (sw_if_index);
100 clib_memcpy (mp->ip, v6address, sizeof (v6address));
101
102 /* send it... */
103 S (mp);
104
105 /* Wait for a reply, return good/bad news */
106 W (ret);
107 return ret;
108}
109
110static int
111api_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 M (IP6ND_PROXY_DUMP, mp);
118
119 S (mp);
120
121 /* Use a control ping for synchronization */
122 /* Use a control ping for synchronization */
123 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
124 mp_ping->_vl_msg_id = htons (ip6_nd_test_main.ping_id);
125 mp_ping->client_index = vam->my_client_index;
126 vam->result_ready = 0;
127
128 S (mp_ping);
129
130 W (ret);
131 return ret;
132}
133
134static void vl_api_ip6nd_proxy_details_t_handler
135 (vl_api_ip6nd_proxy_details_t * mp)
136{
137 vat_main_t *vam = &vat_main;
138
139 print (vam->ofp, "host %U sw_if_index %d",
140 format_vl_api_ip6_address, mp->ip, ntohl (mp->sw_if_index));
141}
142
143static int
144api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
145{
146 unformat_input_t *i = vam->input;
147 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
148 u32 sw_if_index;
149 u8 sw_if_index_set = 0;
150 u8 v6_address_set = 0;
151 vl_api_prefix_t pfx;
152 u8 use_default = 0;
153 u8 no_advertise = 0;
154 u8 off_link = 0;
155 u8 no_autoconfig = 0;
156 u8 no_onlink = 0;
157 u8 is_no = 0;
158 u32 val_lifetime = 0;
159 u32 pref_lifetime = 0;
160 int ret;
161
162 /* Parse args required to build the message */
163 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
164 {
165 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
166 sw_if_index_set = 1;
167 else if (unformat (i, "sw_if_index %d", &sw_if_index))
168 sw_if_index_set = 1;
169 else if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
170 v6_address_set = 1;
171 else if (unformat (i, "val_life %d", &val_lifetime))
172 ;
173 else if (unformat (i, "pref_life %d", &pref_lifetime))
174 ;
175 else if (unformat (i, "def"))
176 use_default = 1;
177 else if (unformat (i, "noadv"))
178 no_advertise = 1;
179 else if (unformat (i, "offl"))
180 off_link = 1;
181 else if (unformat (i, "noauto"))
182 no_autoconfig = 1;
183 else if (unformat (i, "nolink"))
184 no_onlink = 1;
185 else if (unformat (i, "isno"))
186 is_no = 1;
187 else
188 {
189 clib_warning ("parse error '%U'", format_unformat_error, i);
190 return -99;
191 }
192 }
193
194 if (sw_if_index_set == 0)
195 {
196 errmsg ("missing interface name or sw_if_index");
197 return -99;
198 }
199 if (!v6_address_set)
200 {
201 errmsg ("no address set");
202 return -99;
203 }
204
205 /* Construct the API message */
206 M (SW_INTERFACE_IP6ND_RA_PREFIX, mp);
207
208 mp->sw_if_index = ntohl (sw_if_index);
209 clib_memcpy (&mp->prefix, &pfx, sizeof (pfx));
210 mp->use_default = use_default;
211 mp->no_advertise = no_advertise;
212 mp->off_link = off_link;
213 mp->no_autoconfig = no_autoconfig;
214 mp->no_onlink = no_onlink;
215 mp->is_no = is_no;
216 mp->val_lifetime = ntohl (val_lifetime);
217 mp->pref_lifetime = ntohl (pref_lifetime);
218
219 /* send it... */
220 S (mp);
221
222 /* Wait for a reply, return good/bad news */
223 W (ret);
224 return ret;
225}
226
227static int
228api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
229{
230 unformat_input_t *i = vam->input;
231 vl_api_sw_interface_ip6nd_ra_config_t *mp;
232 u32 sw_if_index;
233 u8 sw_if_index_set = 0;
234 u8 suppress = 0;
235 u8 managed = 0;
236 u8 other = 0;
237 u8 ll_option = 0;
238 u8 send_unicast = 0;
239 u8 cease = 0;
240 u8 is_no = 0;
241 u8 default_router = 0;
242 u32 max_interval = 0;
243 u32 min_interval = 0;
244 u32 lifetime = 0;
245 u32 initial_count = 0;
246 u32 initial_interval = 0;
247 int ret;
248
249
250 /* Parse args required to build the message */
251 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
252 {
253 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
254 sw_if_index_set = 1;
255 else if (unformat (i, "sw_if_index %d", &sw_if_index))
256 sw_if_index_set = 1;
257 else if (unformat (i, "maxint %d", &max_interval))
258 ;
259 else if (unformat (i, "minint %d", &min_interval))
260 ;
261 else if (unformat (i, "life %d", &lifetime))
262 ;
263 else if (unformat (i, "count %d", &initial_count))
264 ;
265 else if (unformat (i, "interval %d", &initial_interval))
266 ;
267 else if (unformat (i, "suppress") || unformat (i, "surpress"))
268 suppress = 1;
269 else if (unformat (i, "managed"))
270 managed = 1;
271 else if (unformat (i, "other"))
272 other = 1;
273 else if (unformat (i, "ll"))
274 ll_option = 1;
275 else if (unformat (i, "send"))
276 send_unicast = 1;
277 else if (unformat (i, "cease"))
278 cease = 1;
279 else if (unformat (i, "isno"))
280 is_no = 1;
281 else if (unformat (i, "def"))
282 default_router = 1;
283 else
284 {
285 clib_warning ("parse error '%U'", format_unformat_error, i);
286 return -99;
287 }
288 }
289
290 if (sw_if_index_set == 0)
291 {
292 errmsg ("missing interface name or sw_if_index");
293 return -99;
294 }
295
296 /* Construct the API message */
297 M (SW_INTERFACE_IP6ND_RA_CONFIG, mp);
298
299 mp->sw_if_index = ntohl (sw_if_index);
300 mp->max_interval = ntohl (max_interval);
301 mp->min_interval = ntohl (min_interval);
302 mp->lifetime = ntohl (lifetime);
303 mp->initial_count = ntohl (initial_count);
304 mp->initial_interval = ntohl (initial_interval);
305 mp->suppress = suppress;
306 mp->managed = managed;
307 mp->other = other;
308 mp->ll_option = ll_option;
309 mp->send_unicast = send_unicast;
310 mp->cease = cease;
311 mp->is_no = is_no;
312 mp->default_router = default_router;
313
314 /* send it... */
315 S (mp);
316
317 /* Wait for a reply, return good/bad news */
318 W (ret);
319 return ret;
320}
321
322#include <ip6-nd/ip6_nd.api_test.c>
323
324/*
325 * fd.io coding-style-patch-verification: ON
326 *
327 * Local Variables:
328 * eval: (c-set-style "gnu")
329 * End:
330 */