blob: 09134e3901bd9b252cdd836f854554c9680b85ee [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * decap.c : IPSec tunnel support
3 *
4 * Copyright (c) 2015 Cisco and/or its affiliates.
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:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18#include <vnet/vnet.h>
19#include <vnet/api_errno.h>
20#include <vnet/ip/ip.h>
21#include <vnet/interface.h>
22
23#include <vnet/ipsec/ipsec.h>
24
25static clib_error_t *
26set_interface_spd_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070027 unformat_input_t * input,
28 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070029{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070030 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070031 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070032 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070033 u32 spd_id;
34 int is_add = 1;
Billy McFalla9a20e72017-02-15 11:39:12 -050035 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070036
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070037 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -070038 return 0;
39
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070040 if (unformat
41 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
42 &sw_if_index, &spd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -070043 ;
44 else if (unformat (line_input, "del"))
45 is_add = 0;
46 else
Billy McFalla9a20e72017-02-15 11:39:12 -050047 {
48 error = clib_error_return (0, "parse error: '%U'",
49 format_unformat_error, line_input);
50 goto done;
51 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070053 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -070054
Billy McFalla9a20e72017-02-15 11:39:12 -050055done:
56 unformat_free (line_input);
57
58 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -070059}
60
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070061/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070062VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
63 .path = "set interface ipsec spd",
64 .short_help =
65 "set interface ipsec spd <int> <id>",
66 .function = set_interface_spd_command_fn,
67};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070068/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070069
70static clib_error_t *
71ipsec_sa_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070072 unformat_input_t * input,
73 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070074{
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000075 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070076 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 ipsec_sa_t sa;
78 int is_add = ~0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070079 u8 *ck = 0, *ik = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -050080 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070082 memset (&sa, 0, sizeof (sa));
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070084 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 return 0;
86
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070087 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
88 {
89 if (unformat (line_input, "add %u", &sa.id))
90 is_add = 1;
91 else if (unformat (line_input, "del %u", &sa.id))
92 is_add = 0;
93 else if (unformat (line_input, "spi %u", &sa.spi))
94 ;
95 else if (unformat (line_input, "esp"))
96 sa.protocol = IPSEC_PROTOCOL_ESP;
97 else if (unformat (line_input, "ah"))
Billy McFalla9a20e72017-02-15 11:39:12 -050098 {
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080099 sa.protocol = IPSEC_PROTOCOL_AH;
Billy McFalla9a20e72017-02-15 11:39:12 -0500100 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700101 else
102 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
103 sa.crypto_key_len = vec_len (ck);
104 else
105 if (unformat
106 (line_input, "crypto-alg %U", unformat_ipsec_crypto_alg,
107 &sa.crypto_alg))
108 {
109 if (sa.crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +0000110 sa.crypto_alg >= IPSEC_CRYPTO_N_ALG)
Billy McFalla9a20e72017-02-15 11:39:12 -0500111 {
112 error = clib_error_return (0, "unsupported crypto-alg: '%U'",
113 format_ipsec_crypto_alg,
114 sa.crypto_alg);
115 goto done;
116 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700117 }
118 else
119 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
120 sa.integ_key_len = vec_len (ik);
121 else if (unformat (line_input, "integ-alg %U", unformat_ipsec_integ_alg,
122 &sa.integ_alg))
123 {
124 if (sa.integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +0000125 sa.integ_alg >= IPSEC_INTEG_N_ALG)
Billy McFalla9a20e72017-02-15 11:39:12 -0500126 {
127 error = clib_error_return (0, "unsupported integ-alg: '%U'",
128 format_ipsec_integ_alg,
129 sa.integ_alg);
130 goto done;
131 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700132 }
133 else if (unformat (line_input, "tunnel-src %U",
134 unformat_ip4_address, &sa.tunnel_src_addr.ip4))
135 sa.is_tunnel = 1;
136 else if (unformat (line_input, "tunnel-dst %U",
137 unformat_ip4_address, &sa.tunnel_dst_addr.ip4))
138 sa.is_tunnel = 1;
139 else if (unformat (line_input, "tunnel-src %U",
140 unformat_ip6_address, &sa.tunnel_src_addr.ip6))
141 {
142 sa.is_tunnel = 1;
143 sa.is_tunnel_ip6 = 1;
144 }
145 else if (unformat (line_input, "tunnel-dst %U",
146 unformat_ip6_address, &sa.tunnel_dst_addr.ip6))
147 {
148 sa.is_tunnel = 1;
149 sa.is_tunnel_ip6 = 1;
150 }
151 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500152 {
153 error = clib_error_return (0, "parse error: '%U'",
154 format_unformat_error, line_input);
155 goto done;
156 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700157 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700159 if (sa.crypto_key_len > sizeof (sa.crypto_key))
160 sa.crypto_key_len = sizeof (sa.crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700162 if (sa.integ_key_len > sizeof (sa.integ_key))
163 sa.integ_key_len = sizeof (sa.integ_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
165 if (ck)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700166 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167
168 if (ik)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700169 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000171 if (is_add)
172 {
173 ASSERT (im->cb.check_support_cb);
Billy McFalla9a20e72017-02-15 11:39:12 -0500174 error = im->cb.check_support_cb (&sa);
175 if (error)
176 goto done;
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000177 }
178
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700179 ipsec_add_del_sa (vm, &sa, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180
Billy McFalla9a20e72017-02-15 11:39:12 -0500181done:
182 unformat_free (line_input);
183
184 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185}
186
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700187/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
189 .path = "ipsec sa",
190 .short_help =
191 "ipsec sa [add|del]",
192 .function = ipsec_sa_add_del_command_fn,
193};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700194/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195
196static clib_error_t *
197ipsec_spd_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700198 unformat_input_t * input,
199 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700201 unformat_input_t _line_input, *line_input = &_line_input;
Damjan Marion3f54b182016-08-16 11:27:02 +0200202 u32 spd_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700203 int is_add = ~0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500204 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700206 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207 return 0;
208
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
210 {
211 if (unformat (line_input, "add"))
212 is_add = 1;
213 else if (unformat (line_input, "del"))
214 is_add = 0;
215 else if (unformat (line_input, "%u", &spd_id))
216 ;
217 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500218 {
219 error = clib_error_return (0, "parse error: '%U'",
220 format_unformat_error, line_input);
221 goto done;
222 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700223 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224
Damjan Marion3f54b182016-08-16 11:27:02 +0200225 if (spd_id == ~0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500226 {
227 error = clib_error_return (0, "please specify SPD ID");
228 goto done;
229 }
Damjan Marion3f54b182016-08-16 11:27:02 +0200230
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700231 ipsec_add_del_spd (vm, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232
Billy McFalla9a20e72017-02-15 11:39:12 -0500233done:
234 unformat_free (line_input);
235
236 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700237}
238
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700239/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
241 .path = "ipsec spd",
242 .short_help =
243 "ipsec spd [add|del] <id>",
244 .function = ipsec_spd_add_del_command_fn,
245};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700246/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700247
248
249static clib_error_t *
250ipsec_policy_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700251 unformat_input_t * input,
252 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700254 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255 ipsec_policy_t p;
256 int is_add = 0;
257 int is_ip_any = 1;
258 u32 tmp, tmp2;
Billy McFalla9a20e72017-02-15 11:39:12 -0500259 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700261 memset (&p, 0, sizeof (p));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262 p.lport.stop = p.rport.stop = ~0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700263 p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0;
264 p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0;
265 p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700266
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700267 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268 return 0;
269
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700270 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
271 {
272 if (unformat (line_input, "add"))
273 is_add = 1;
274 else if (unformat (line_input, "del"))
275 is_add = 0;
276 else if (unformat (line_input, "spd %u", &p.id))
277 ;
278 else if (unformat (line_input, "inbound"))
279 p.is_outbound = 0;
280 else if (unformat (line_input, "outbound"))
281 p.is_outbound = 1;
282 else if (unformat (line_input, "priority %d", &p.priority))
283 ;
284 else if (unformat (line_input, "protocol %u", &tmp))
285 p.protocol = (u8) tmp;
286 else
287 if (unformat
288 (line_input, "action %U", unformat_ipsec_policy_action,
289 &p.policy))
290 {
291 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500292 {
293 error = clib_error_return (0, "unsupported action: 'resolve'");
294 goto done;
295 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700296 }
297 else if (unformat (line_input, "sa %u", &p.sa_id))
298 ;
299 else if (unformat (line_input, "local-ip-range %U - %U",
300 unformat_ip4_address, &p.laddr.start.ip4,
301 unformat_ip4_address, &p.laddr.stop.ip4))
302 is_ip_any = 0;
303 else if (unformat (line_input, "remote-ip-range %U - %U",
304 unformat_ip4_address, &p.raddr.start.ip4,
305 unformat_ip4_address, &p.raddr.stop.ip4))
306 is_ip_any = 0;
307 else if (unformat (line_input, "local-ip-range %U - %U",
308 unformat_ip6_address, &p.laddr.start.ip6,
309 unformat_ip6_address, &p.laddr.stop.ip6))
310 {
311 p.is_ipv6 = 1;
312 is_ip_any = 0;
313 }
314 else if (unformat (line_input, "remote-ip-range %U - %U",
315 unformat_ip6_address, &p.raddr.start.ip6,
316 unformat_ip6_address, &p.raddr.stop.ip6))
317 {
318 p.is_ipv6 = 1;
319 is_ip_any = 0;
320 }
321 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
322 {
323 p.lport.start = tmp;
324 p.lport.stop = tmp2;
325 }
326 else
327 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
328 {
329 p.rport.start = tmp;
330 p.rport.stop = tmp2;
331 }
332 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500333 {
334 error = clib_error_return (0, "parse error: '%U'",
335 format_unformat_error, line_input);
336 goto done;
337 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700338 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800340 /* Check if SA is for IPv6/AH which is not supported. Return error if TRUE. */
341 if (p.sa_id)
342 {
343 uword *p1;
344 ipsec_main_t *im = &ipsec_main;
345 ipsec_sa_t *sa = 0;
346 p1 = hash_get (im->sa_index_by_sa_id, p.sa_id);
347 sa = pool_elt_at_index (im->sad, p1[0]);
348 if (sa && sa->protocol == IPSEC_PROTOCOL_AH && is_add && p.is_ipv6)
349 {
350 error = clib_error_return (0, "AH not supported for IPV6: '%U'",
351 format_unformat_error, line_input);
352 goto done;
353 }
354 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700355 ipsec_add_del_policy (vm, &p, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356 if (is_ip_any)
357 {
358 p.is_ipv6 = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700359 ipsec_add_del_policy (vm, &p, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360 }
Billy McFalla9a20e72017-02-15 11:39:12 -0500361
362done:
363 unformat_free (line_input);
364
365 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700366}
367
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700368/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700369VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
370 .path = "ipsec policy",
371 .short_help =
372 "ipsec policy [add|del] spd <id> priority <n> ",
373 .function = ipsec_policy_add_del_command_fn,
374};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700375/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376
377static clib_error_t *
378set_ipsec_sa_key_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700379 unformat_input_t * input,
380 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700382 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383 ipsec_sa_t sa;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700384 u8 *ck = 0, *ik = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500385 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700387 memset (&sa, 0, sizeof (sa));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700388
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700389 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 return 0;
391
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700392 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
393 {
394 if (unformat (line_input, "%u", &sa.id))
395 ;
396 else
397 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
398 sa.crypto_key_len = vec_len (ck);
399 else
400 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
401 sa.integ_key_len = vec_len (ik);
402 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500403 {
404 error = clib_error_return (0, "parse error: '%U'",
405 format_unformat_error, line_input);
406 goto done;
407 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700408 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700409
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700410 if (sa.crypto_key_len > sizeof (sa.crypto_key))
411 sa.crypto_key_len = sizeof (sa.crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700413 if (sa.integ_key_len > sizeof (sa.integ_key))
414 sa.integ_key_len = sizeof (sa.integ_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415
416 if (ck)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700417 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700418
419 if (ik)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700420 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700422 ipsec_set_sa_key (vm, &sa);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700423
Billy McFalla9a20e72017-02-15 11:39:12 -0500424done:
425 unformat_free (line_input);
426
427 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428}
429
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700430/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700431VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
432 .path = "set ipsec sa",
433 .short_help =
434 "set ipsec sa <id> crypto-key <key> integ-key <key>",
435 .function = set_ipsec_sa_key_command_fn,
436};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700437/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438
439static clib_error_t *
440show_ipsec_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700441 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700443 ipsec_spd_t *spd;
444 ipsec_sa_t *sa;
445 ipsec_policy_t *p;
446 ipsec_main_t *im = &ipsec_main;
447 u32 *i;
448 ipsec_tunnel_if_t *t;
449 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700451 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700452 pool_foreach (sa, im->sad, ({
453 if (sa->id) {
454 vlib_cli_output(vm, "sa %u spi %u mode %s protocol %s", sa->id, sa->spi,
455 sa->is_tunnel ? "tunnel" : "transport",
456 sa->protocol ? "esp" : "ah");
457 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
458 vlib_cli_output(vm, " crypto alg %U%s%U integrity alg %U%s%U",
459 format_ipsec_crypto_alg, sa->crypto_alg,
460 sa->crypto_alg ? " key " : "",
461 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
462 format_ipsec_integ_alg, sa->integ_alg,
463 sa->integ_alg ? " key " : "",
464 format_hex_bytes, sa->integ_key, sa->integ_key_len);
465 }
466 if (sa->is_tunnel && sa->is_tunnel_ip6) {
467 vlib_cli_output(vm, " tunnel src %U dst %U",
468 format_ip6_address, &sa->tunnel_src_addr.ip6,
469 format_ip6_address, &sa->tunnel_dst_addr.ip6);
470 } else if (sa->is_tunnel) {
471 vlib_cli_output(vm, " tunnel src %U dst %U",
472 format_ip4_address, &sa->tunnel_src_addr.ip4,
473 format_ip4_address, &sa->tunnel_dst_addr.ip4);
474 }
475 }
476 }));
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700477 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700479 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480 pool_foreach (spd, im->spds, ({
481 vlib_cli_output(vm, "spd %u", spd->id);
482
483 vlib_cli_output(vm, " outbound policies");
484 vec_foreach(i, spd->ipv4_outbound_policies)
485 {
486 p = pool_elt_at_index(spd->policies, *i);
487 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
488 p->priority,
489 format_ipsec_policy_action, p->policy,
490 p->protocol ?
491 format(0, "%U", format_ip_protocol, p->protocol) :
492 (u8 *) "any",
493 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
494 format(0, " sa %u", p->sa_id) :
495 (u8 *) "");
496 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
497 format_ip4_address, &p->laddr.start.ip4,
498 format_ip4_address, &p->laddr.stop.ip4,
499 p->lport.start, p->lport.stop);
500 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
501 format_ip4_address, &p->raddr.start.ip4,
502 format_ip4_address, &p->raddr.stop.ip4,
503 p->rport.start, p->rport.stop);
504 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
505 p->counter.bytes);
506 };
507 vec_foreach(i, spd->ipv6_outbound_policies)
508 {
509 p = pool_elt_at_index(spd->policies, *i);
510 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
511 p->priority,
512 format_ipsec_policy_action, p->policy,
513 p->protocol ?
514 format(0, "%U", format_ip_protocol, p->protocol) :
515 (u8 *) "any",
516 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
517 format(0, " sa %u", p->sa_id) :
518 (u8 *) "");
519 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
520 format_ip6_address, &p->laddr.start.ip6,
521 format_ip6_address, &p->laddr.stop.ip6,
522 p->lport.start, p->lport.stop);
523 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
524 format_ip6_address, &p->raddr.start.ip6,
525 format_ip6_address, &p->raddr.stop.ip6,
526 p->rport.start, p->rport.stop);
527 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
528 p->counter.bytes);
529 };
530 vlib_cli_output(vm, " inbound policies");
531 vec_foreach(i, spd->ipv4_inbound_protect_policy_indices)
532 {
533 p = pool_elt_at_index(spd->policies, *i);
534 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
535 p->priority,
536 format_ipsec_policy_action, p->policy,
537 p->protocol ?
538 format(0, "%U", format_ip_protocol, p->protocol) :
539 (u8 *) "any",
540 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
541 format(0, " sa %u", p->sa_id) :
542 (u8 *) "");
543 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
544 format_ip4_address, &p->laddr.start.ip4,
545 format_ip4_address, &p->laddr.stop.ip4,
546 p->lport.start, p->lport.stop);
547 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
548 format_ip4_address, &p->raddr.start.ip4,
549 format_ip4_address, &p->raddr.stop.ip4,
550 p->rport.start, p->rport.stop);
551 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
552 p->counter.bytes);
553 };
554 vec_foreach(i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
555 {
556 p = pool_elt_at_index(spd->policies, *i);
557 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
558 p->priority,
559 format_ipsec_policy_action, p->policy,
560 p->protocol ?
561 format(0, "%U", format_ip_protocol, p->protocol) :
562 (u8 *) "any",
563 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
564 format(0, " sa %u", p->sa_id) :
565 (u8 *) "");
566 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
567 format_ip4_address, &p->laddr.start.ip4,
568 format_ip4_address, &p->laddr.stop.ip4,
569 p->lport.start, p->lport.stop);
570 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
571 format_ip4_address, &p->raddr.start.ip4,
572 format_ip4_address, &p->raddr.stop.ip4,
573 p->rport.start, p->rport.stop);
574 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
575 p->counter.bytes);
576 };
577 vec_foreach(i, spd->ipv6_inbound_protect_policy_indices)
578 {
579 p = pool_elt_at_index(spd->policies, *i);
580 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
581 p->priority,
582 format_ipsec_policy_action, p->policy,
583 p->protocol ?
584 format(0, "%U", format_ip_protocol, p->protocol) :
585 (u8 *) "any",
586 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
587 format(0, " sa %u", p->sa_id) :
588 (u8 *) "");
589 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
590 format_ip6_address, &p->laddr.start.ip6,
591 format_ip6_address, &p->laddr.stop.ip6,
592 p->lport.start, p->lport.stop);
593 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
594 format_ip6_address, &p->raddr.start.ip6,
595 format_ip6_address, &p->raddr.stop.ip6,
596 p->rport.start, p->rport.stop);
597 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
598 p->counter.bytes);
599 };
600 vec_foreach(i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
601 {
602 p = pool_elt_at_index(spd->policies, *i);
603 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
604 p->priority,
605 format_ipsec_policy_action, p->policy,
606 p->protocol ?
607 format(0, "%U", format_ip_protocol, p->protocol) :
608 (u8 *) "any",
609 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
610 format(0, " sa %u", p->sa_id) :
611 (u8 *) "");
612 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
613 format_ip6_address, &p->laddr.start.ip6,
614 format_ip6_address, &p->laddr.stop.ip6,
615 p->lport.start, p->lport.stop);
616 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
617 format_ip6_address, &p->raddr.start.ip6,
618 format_ip6_address, &p->raddr.stop.ip6,
619 p->rport.start, p->rport.stop);
620 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
621 p->counter.bytes);
622 };
623 }));
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700624 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700625
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700626 vlib_cli_output (vm, "tunnel interfaces");
627 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700628 pool_foreach (t, im->tunnel_interfaces, ({
Matus Fabian694265d2016-08-10 01:55:36 -0700629 if (t->hw_if_index == ~0)
630 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700631 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
632 vlib_cli_output(vm, " %s seq", hi->name);
633 sa = pool_elt_at_index(im->sad, t->output_sa_index);
634 vlib_cli_output(vm, " seq %u seq-hi %u esn %u anti-replay %u",
635 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay);
636 vlib_cli_output(vm, " local-spi %u local-ip %U", sa->spi,
637 format_ip4_address, &sa->tunnel_src_addr.ip4);
638 vlib_cli_output(vm, " local-crypto %U %U",
639 format_ipsec_crypto_alg, sa->crypto_alg,
640 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
641 vlib_cli_output(vm, " local-integrity %U %U",
642 format_ipsec_integ_alg, sa->integ_alg,
643 format_hex_bytes, sa->integ_key, sa->integ_key_len);
644 sa = pool_elt_at_index(im->sad, t->input_sa_index);
645 vlib_cli_output(vm, " last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
646 sa->last_seq, sa->last_seq_hi, sa->use_esn,
647 sa->use_anti_replay,
648 format_ipsec_replay_window, sa->replay_window);
649 vlib_cli_output(vm, " remote-spi %u remote-ip %U", sa->spi,
650 format_ip4_address, &sa->tunnel_src_addr.ip4);
651 vlib_cli_output(vm, " remote-crypto %U %U",
652 format_ipsec_crypto_alg, sa->crypto_alg,
653 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
654 vlib_cli_output(vm, " remote-integrity %U %U",
655 format_ipsec_integ_alg, sa->integ_alg,
656 format_hex_bytes, sa->integ_key, sa->integ_key_len);
657 }));
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700658 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659 return 0;
660}
661
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700662/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663VLIB_CLI_COMMAND (show_ipsec_command, static) = {
664 .path = "show ipsec",
665 .short_help = "show ipsec",
666 .function = show_ipsec_command_fn,
667};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700668/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700669
670static clib_error_t *
671clear_ipsec_counters_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700672 unformat_input_t * input,
673 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700675 ipsec_main_t *im = &ipsec_main;
676 ipsec_spd_t *spd;
677 ipsec_policy_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700678
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700679 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700680 pool_foreach (spd, im->spds, ({
681 pool_foreach(p, spd->policies, ({
682 p->counter.packets = p->counter.bytes = 0;
683 }));
684 }));
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700685 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700686
687 return 0;
688}
689
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700690/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700691VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
692 .path = "clear ipsec counters",
693 .short_help = "clear ipsec counters",
694 .function = clear_ipsec_counters_command_fn,
695};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700696/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700697
698static clib_error_t *
699create_ipsec_tunnel_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700700 unformat_input_t * input,
701 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700702{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700703 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700704 ipsec_add_del_tunnel_args_t a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700705 int rv;
706 u32 num_m_args = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500707 clib_error_t *error = NULL;
Matthew Smith2838a232016-06-21 16:05:09 -0500708
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700709 memset (&a, 0, sizeof (a));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710 a.is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711
712 /* Get a line of input. */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700713 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714 return 0;
715
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700716 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
717 {
718 if (unformat
719 (line_input, "local-ip %U", unformat_ip4_address, &a.local_ip))
720 num_m_args++;
721 else
722 if (unformat
723 (line_input, "remote-ip %U", unformat_ip4_address, &a.remote_ip))
724 num_m_args++;
725 else if (unformat (line_input, "local-spi %u", &a.local_spi))
726 num_m_args++;
727 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
728 num_m_args++;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500729 else if (unformat (line_input, "instance %u", &a.show_instance))
730 a.renumber = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700731 else if (unformat (line_input, "del"))
732 a.is_add = 0;
733 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500734 {
735 error = clib_error_return (0, "unknown input `%U'",
736 format_unformat_error, line_input);
737 goto done;
738 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700739 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700740
741 if (num_m_args < 4)
Billy McFalla9a20e72017-02-15 11:39:12 -0500742 {
743 error = clib_error_return (0, "mandatory argument(s) missing");
744 goto done;
745 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700746
Matthew Smith2838a232016-06-21 16:05:09 -0500747 rv = ipsec_add_del_tunnel_if (&a);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700748
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700749 switch (rv)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700750 {
751 case 0:
752 break;
753 case VNET_API_ERROR_INVALID_VALUE:
754 if (a.is_add)
Billy McFalla9a20e72017-02-15 11:39:12 -0500755 error = clib_error_return (0,
756 "IPSec tunnel interface already exists...");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700757 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500758 error = clib_error_return (0, "IPSec tunnel interface not exists...");
759 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500761 error = clib_error_return (0, "ipsec_register_interface returned %d",
762 rv);
763 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700764 }
765
Billy McFalla9a20e72017-02-15 11:39:12 -0500766done:
767 unformat_free (line_input);
768
769 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770}
771
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700772/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700773VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
774 .path = "create ipsec tunnel",
Matthew Smith8e1039a2018-04-12 07:32:56 -0500775 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi> [instance <inst_num>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700776 .function = create_ipsec_tunnel_command_fn,
777};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700778/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700779
780static clib_error_t *
781set_interface_key_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700782 unformat_input_t * input,
783 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700784{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700785 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786 ipsec_main_t *im = &ipsec_main;
787 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700788 u32 hw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700789 u32 alg;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700790 u8 *key = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500791 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700792
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700793 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794 return 0;
795
796 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
797 {
798 if (unformat (line_input, "%U",
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700799 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
800 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801 else
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700802 if (unformat
803 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
804 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
805 else
806 if (unformat
807 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
808 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
809 else
810 if (unformat
811 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
812 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
813 else
814 if (unformat
815 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
816 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
817 else if (unformat (line_input, "%U", unformat_hex_string, &key))
818 ;
819 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500820 {
821 error = clib_error_return (0, "parse error: '%U'",
822 format_unformat_error, line_input);
823 goto done;
824 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700825 }
826
Ed Warnickecb9cada2015-12-08 15:45:58 -0700827 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500828 {
829 error = clib_error_return (0, "unknown key type");
830 goto done;
831 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700832
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700833 if (alg > 0 && vec_len (key) == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500834 {
835 error = clib_error_return (0, "key is not specified");
836 goto done;
837 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700839 if (hw_if_index == (u32) ~ 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500840 {
841 error = clib_error_return (0, "interface not specified");
842 goto done;
843 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700845 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700846
Billy McFalla9a20e72017-02-15 11:39:12 -0500847done:
848 vec_free (key);
849 unformat_free (line_input);
850
851 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700852}
853
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700854/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700855VLIB_CLI_COMMAND (set_interface_key_command, static) = {
856 .path = "set interface ipsec key",
857 .short_help =
858 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
859 .function = set_interface_key_command_fn,
860};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700861/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700862
Ed Warnickecb9cada2015-12-08 15:45:58 -0700863clib_error_t *
864ipsec_cli_init (vlib_main_t * vm)
865{
866 return 0;
867}
868
869VLIB_INIT_FUNCTION (ipsec_cli_init);
870
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700871
872/*
873 * fd.io coding-style-patch-verification: ON
874 *
875 * Local Variables:
876 * eval: (c-set-style "gnu")
877 * End:
878 */