blob: 648455bbecfb66c972c3ea018570e2ce151dde49 [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>
Pierre Pfister4c422f92018-12-10 11:19:08 +010022#include <vnet/fib/fib.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070023
24#include <vnet/ipsec/ipsec.h>
25
26static clib_error_t *
27set_interface_spd_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070028 unformat_input_t * input,
29 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070030{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070031 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070032 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070033 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070034 u32 spd_id;
35 int is_add = 1;
Billy McFalla9a20e72017-02-15 11:39:12 -050036 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070037
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070038 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 return 0;
40
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070041 if (unformat
42 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
43 &sw_if_index, &spd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -070044 ;
45 else if (unformat (line_input, "del"))
46 is_add = 0;
47 else
Billy McFalla9a20e72017-02-15 11:39:12 -050048 {
49 error = clib_error_return (0, "parse error: '%U'",
50 format_unformat_error, line_input);
51 goto done;
52 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070053
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070054 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
Billy McFalla9a20e72017-02-15 11:39:12 -050056done:
57 unformat_free (line_input);
58
59 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -070060}
61
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070062/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070063VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
64 .path = "set interface ipsec spd",
65 .short_help =
66 "set interface ipsec spd <int> <id>",
67 .function = set_interface_spd_command_fn,
68};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070069/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070070
71static clib_error_t *
72ipsec_sa_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070073 unformat_input_t * input,
74 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070076 unformat_input_t _line_input, *line_input = &_line_input;
Neale Ranns8d7c5022019-02-06 01:41:05 -080077 ip46_address_t tun_src = { }, tun_dst =
78 {
79 };
80 ipsec_crypto_alg_t crypto_alg;
81 ipsec_integ_alg_t integ_alg;
82 ipsec_protocol_t proto;
83 ipsec_sa_flags_t flags;
84 clib_error_t *error;
Kingwel Xied3d12052019-03-07 06:34:30 -050085 ipsec_key_t ck = { 0 };
86 ipsec_key_t ik = { 0 };
Neale Ranns8d7c5022019-02-06 01:41:05 -080087 int is_add, rv;
88 u32 id, spi;
Ed Warnickecb9cada2015-12-08 15:45:58 -070089
Neale Ranns8d7c5022019-02-06 01:41:05 -080090 error = NULL;
91 is_add = 0;
92 flags = IPSEC_SA_FLAG_NONE;
93 proto = IPSEC_PROTOCOL_ESP;
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070095 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 return 0;
97
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070098 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
99 {
Neale Ranns8d7c5022019-02-06 01:41:05 -0800100 if (unformat (line_input, "add %u", &id))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700101 is_add = 1;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800102 else if (unformat (line_input, "del %u", &id))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700103 is_add = 0;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800104 else if (unformat (line_input, "spi %u", &spi))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700105 ;
106 else if (unformat (line_input, "esp"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800107 proto = IPSEC_PROTOCOL_ESP;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700108 else if (unformat (line_input, "ah"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800109 proto = IPSEC_PROTOCOL_AH;
110 else if (unformat (line_input, "crypto-key %U",
111 unformat_ipsec_key, &ck))
112 ;
113 else if (unformat (line_input, "crypto-alg %U",
114 unformat_ipsec_crypto_alg, &crypto_alg))
115 ;
116 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
117 ;
118 else if (unformat (line_input, "integ-alg %U",
119 unformat_ipsec_integ_alg, &integ_alg))
120 ;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700121 else if (unformat (line_input, "tunnel-src %U",
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500122 unformat_ip46_address, &tun_src, IP46_TYPE_ANY))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700123 {
Neale Ranns8d7c5022019-02-06 01:41:05 -0800124 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
125 if (!ip46_address_is_ip4 (&tun_src))
126 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700127 }
128 else if (unformat (line_input, "tunnel-dst %U",
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500129 unformat_ip46_address, &tun_dst, IP46_TYPE_ANY))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800130 ;
Radu Nicolau717de092018-08-03 10:37:24 +0100131 else if (unformat (line_input, "udp-encap"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800132 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700133 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500134 {
135 error = clib_error_return (0, "parse error: '%U'",
136 format_unformat_error, line_input);
137 goto done;
138 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700139 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000141 if (is_add)
Neale Ranns8d7c5022019-02-06 01:41:05 -0800142 rv = ipsec_sa_add (id, spi, proto, crypto_alg,
143 &ck, integ_alg, &ik, flags,
144 0, &tun_src, &tun_dst, NULL);
145 else
146 rv = ipsec_sa_del (id);
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000147
Neale Ranns8d7c5022019-02-06 01:41:05 -0800148 if (rv)
149 clib_error_return (0, "failed");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150
Billy McFalla9a20e72017-02-15 11:39:12 -0500151done:
152 unformat_free (line_input);
153
154 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700155}
156
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700157/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
159 .path = "ipsec sa",
160 .short_help =
161 "ipsec sa [add|del]",
162 .function = ipsec_sa_add_del_command_fn,
163};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700164/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165
166static clib_error_t *
167ipsec_spd_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700168 unformat_input_t * input,
169 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700171 unformat_input_t _line_input, *line_input = &_line_input;
Damjan Marion3f54b182016-08-16 11:27:02 +0200172 u32 spd_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173 int is_add = ~0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500174 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700176 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177 return 0;
178
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700179 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
180 {
181 if (unformat (line_input, "add"))
182 is_add = 1;
183 else if (unformat (line_input, "del"))
184 is_add = 0;
185 else if (unformat (line_input, "%u", &spd_id))
186 ;
187 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500188 {
189 error = clib_error_return (0, "parse error: '%U'",
190 format_unformat_error, line_input);
191 goto done;
192 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700193 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194
Damjan Marion3f54b182016-08-16 11:27:02 +0200195 if (spd_id == ~0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500196 {
197 error = clib_error_return (0, "please specify SPD ID");
198 goto done;
199 }
Damjan Marion3f54b182016-08-16 11:27:02 +0200200
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700201 ipsec_add_del_spd (vm, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
Billy McFalla9a20e72017-02-15 11:39:12 -0500203done:
204 unformat_free (line_input);
205
206 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207}
208
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700209/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
211 .path = "ipsec spd",
212 .short_help =
213 "ipsec spd [add|del] <id>",
214 .function = ipsec_spd_add_del_command_fn,
215};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700216/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217
218
219static clib_error_t *
220ipsec_policy_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700221 unformat_input_t * input,
222 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700224 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225 ipsec_policy_t p;
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800226 int rv, is_add = 0;
227 u32 tmp, tmp2, stat_index;
Billy McFalla9a20e72017-02-15 11:39:12 -0500228 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229
Dave Barachb7b92992018-10-17 10:38:51 -0400230 clib_memset (&p, 0, sizeof (p));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231 p.lport.stop = p.rport.stop = ~0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700232 p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0;
233 p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0;
234 p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700236 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700237 return 0;
238
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700239 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
240 {
241 if (unformat (line_input, "add"))
242 is_add = 1;
243 else if (unformat (line_input, "del"))
244 is_add = 0;
245 else if (unformat (line_input, "spd %u", &p.id))
246 ;
247 else if (unformat (line_input, "inbound"))
248 p.is_outbound = 0;
249 else if (unformat (line_input, "outbound"))
250 p.is_outbound = 1;
251 else if (unformat (line_input, "priority %d", &p.priority))
252 ;
253 else if (unformat (line_input, "protocol %u", &tmp))
254 p.protocol = (u8) tmp;
255 else
256 if (unformat
257 (line_input, "action %U", unformat_ipsec_policy_action,
258 &p.policy))
259 {
260 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500261 {
262 error = clib_error_return (0, "unsupported action: 'resolve'");
263 goto done;
264 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700265 }
266 else if (unformat (line_input, "sa %u", &p.sa_id))
267 ;
268 else if (unformat (line_input, "local-ip-range %U - %U",
269 unformat_ip4_address, &p.laddr.start.ip4,
270 unformat_ip4_address, &p.laddr.stop.ip4))
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800271 ;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700272 else if (unformat (line_input, "remote-ip-range %U - %U",
273 unformat_ip4_address, &p.raddr.start.ip4,
274 unformat_ip4_address, &p.raddr.stop.ip4))
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800275 ;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700276 else if (unformat (line_input, "local-ip-range %U - %U",
277 unformat_ip6_address, &p.laddr.start.ip6,
278 unformat_ip6_address, &p.laddr.stop.ip6))
279 {
280 p.is_ipv6 = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700281 }
282 else if (unformat (line_input, "remote-ip-range %U - %U",
283 unformat_ip6_address, &p.raddr.start.ip6,
284 unformat_ip6_address, &p.raddr.stop.ip6))
285 {
286 p.is_ipv6 = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700287 }
288 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
289 {
290 p.lport.start = tmp;
291 p.lport.stop = tmp2;
292 }
293 else
294 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
295 {
296 p.rport.start = tmp;
297 p.rport.stop = tmp2;
298 }
299 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500300 {
301 error = clib_error_return (0, "parse error: '%U'",
302 format_unformat_error, line_input);
303 goto done;
304 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700305 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800307 /* Check if SA is for IPv6/AH which is not supported. Return error if TRUE. */
308 if (p.sa_id)
309 {
310 uword *p1;
311 ipsec_main_t *im = &ipsec_main;
312 ipsec_sa_t *sa = 0;
313 p1 = hash_get (im->sa_index_by_sa_id, p.sa_id);
Klement Sekerac2fc57e2018-06-28 14:20:12 +0200314 if (!p1)
315 {
316 error =
317 clib_error_return (0, "SA with index %u not found", p.sa_id);
318 goto done;
319 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800320 sa = pool_elt_at_index (im->sad, p1[0]);
321 if (sa && sa->protocol == IPSEC_PROTOCOL_AH && is_add && p.is_ipv6)
322 {
323 error = clib_error_return (0, "AH not supported for IPV6: '%U'",
324 format_unformat_error, line_input);
325 goto done;
326 }
327 }
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800328 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
329
330 if (!rv)
331 vlib_cli_output (vm, "policy-index:%d", stat_index);
332 else
333 vlib_cli_output (vm, "error:%d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500334
335done:
336 unformat_free (line_input);
337
338 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339}
340
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700341/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
343 .path = "ipsec policy",
344 .short_help =
345 "ipsec policy [add|del] spd <id> priority <n> ",
346 .function = ipsec_policy_add_del_command_fn,
347};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700348/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700349
350static clib_error_t *
351set_ipsec_sa_key_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700352 unformat_input_t * input,
353 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700355 unformat_input_t _line_input, *line_input = &_line_input;
Billy McFalla9a20e72017-02-15 11:39:12 -0500356 clib_error_t *error = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800357 ipsec_key_t ck, ik;
358 u32 id;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700360 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700361 return 0;
362
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700363 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
364 {
Neale Ranns8d7c5022019-02-06 01:41:05 -0800365 if (unformat (line_input, "%u", &id))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700366 ;
367 else
Neale Ranns8d7c5022019-02-06 01:41:05 -0800368 if (unformat (line_input, "crypto-key %U", unformat_ipsec_key, &ck))
369 ;
370 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
371 ;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700372 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500373 {
374 error = clib_error_return (0, "parse error: '%U'",
375 format_unformat_error, line_input);
376 goto done;
377 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700378 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379
Neale Ranns8d7c5022019-02-06 01:41:05 -0800380 ipsec_set_sa_key (id, &ck, &ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381
Billy McFalla9a20e72017-02-15 11:39:12 -0500382done:
383 unformat_free (line_input);
384
385 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386}
387
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700388/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700389VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
390 .path = "set ipsec sa",
391 .short_help =
392 "set ipsec sa <id> crypto-key <key> integ-key <key>",
393 .function = set_ipsec_sa_key_command_fn,
394};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700395/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700396
397static clib_error_t *
398show_ipsec_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700399 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700400{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700401 ipsec_main_t *im = &ipsec_main;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800402 u32 spd_id, sw_if_index, sai;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700403 vnet_hw_interface_t *hi;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800404 ipsec_tunnel_if_t *t;
Klement Sekeraea841302018-05-11 12:59:05 +0200405 u8 *protocol = NULL;
406 u8 *policy = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800407 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700409 /* *INDENT-OFF* */
Neale Ranns8d7c5022019-02-06 01:41:05 -0800410 pool_foreach_index (sai, im->sad, ({
411 vlib_cli_output(vm, "%U", format_ipsec_sa, sai);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412 }));
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800413 pool_foreach_index (i, im->spds, ({
414 vlib_cli_output(vm, "%U", format_ipsec_spd, i);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415 }));
416
Neale Ranns311124e2019-01-24 04:52:25 -0800417 vlib_cli_output (vm, "SPD Bindings:");
Neale Ranns8d7c5022019-02-06 01:41:05 -0800418
Neale Ranns311124e2019-01-24 04:52:25 -0800419 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
Neale Ranns8d7c5022019-02-06 01:41:05 -0800420 vlib_cli_output (vm, " %d -> %U", spd_id,
421 format_vnet_sw_if_index_name, im->vnet_main,
422 sw_if_index);
Neale Ranns311124e2019-01-24 04:52:25 -0800423 }));
424 /* *INDENT-ON* */
425
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700426 vlib_cli_output (vm, "tunnel interfaces");
427 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428 pool_foreach (t, im->tunnel_interfaces, ({
Matus Fabian694265d2016-08-10 01:55:36 -0700429 if (t->hw_if_index == ~0)
430 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700431 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
Pierre Pfister4c422f92018-12-10 11:19:08 +0100432
Neale Ranns8d7c5022019-02-06 01:41:05 -0800433 vlib_cli_output(vm, " %s", hi->name);
Pierre Pfister4c422f92018-12-10 11:19:08 +0100434
Neale Ranns8d7c5022019-02-06 01:41:05 -0800435 vlib_cli_output(vm, " out-bound sa");
436 vlib_cli_output(vm, " %U", format_ipsec_sa, t->output_sa_index);
437
438 vlib_cli_output(vm, " in-bound sa");
439 vlib_cli_output(vm, " %U", format_ipsec_sa, t->input_sa_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700440 }));
Klement Sekeraea841302018-05-11 12:59:05 +0200441 vec_free(policy);
442 vec_free(protocol);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700443 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700444 return 0;
445}
446
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700447/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448VLIB_CLI_COMMAND (show_ipsec_command, static) = {
449 .path = "show ipsec",
Klement Sekerab4d30532018-11-08 13:00:02 +0100450 .short_help = "show ipsec [backends]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700451 .function = show_ipsec_command_fn,
452};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700453/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454
455static clib_error_t *
Klement Sekerab4d30532018-11-08 13:00:02 +0100456ipsec_show_backends_command_fn (vlib_main_t * vm,
457 unformat_input_t * input,
458 vlib_cli_command_t * cmd)
459{
460 ipsec_main_t *im = &ipsec_main;
461 u32 verbose = 0;
462
463 (void) unformat (input, "verbose %u", &verbose);
464
465 vlib_cli_output (vm, "IPsec AH backends available:");
466 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
467 ipsec_ah_backend_t *ab;
468 /* *INDENT-OFF* */
469 pool_foreach (ab, im->ah_backends, {
470 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
471 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
472 if (verbose) {
473 vlib_node_t *n;
474 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
475 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
476 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
477 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
478 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
479 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
480 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
481 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
482 }
483 });
484 /* *INDENT-ON* */
485 vlib_cli_output (vm, "%v", s);
486 _vec_len (s) = 0;
487 vlib_cli_output (vm, "IPsec ESP backends available:");
488 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
489 ipsec_esp_backend_t *eb;
490 /* *INDENT-OFF* */
491 pool_foreach (eb, im->esp_backends, {
492 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
493 eb - im->esp_backends == im->esp_current_backend ? "yes"
494 : "no");
495 if (verbose) {
496 vlib_node_t *n;
497 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
498 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
499 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
500 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
501 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
502 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
503 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
504 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
505 }
506 });
507 /* *INDENT-ON* */
508 vlib_cli_output (vm, "%v", s);
509
510 vec_free (s);
511 return 0;
512}
513
514/* *INDENT-OFF* */
515VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
516 .path = "show ipsec backends",
517 .short_help = "show ipsec backends",
518 .function = ipsec_show_backends_command_fn,
519};
520/* *INDENT-ON* */
521
522static clib_error_t *
523ipsec_select_backend_command_fn (vlib_main_t * vm,
524 unformat_input_t * input,
525 vlib_cli_command_t * cmd)
526{
527 u32 backend_index;
528 ipsec_main_t *im = &ipsec_main;
529
530 if (pool_elts (im->sad) > 0)
531 {
532 return clib_error_return (0,
533 "Cannot change IPsec backend, while %u SA entries are configured",
534 pool_elts (im->sad));
535 }
536
537 unformat_input_t _line_input, *line_input = &_line_input;
538 /* Get a line of input. */
539 if (!unformat_user (input, unformat_line_input, line_input))
540 return 0;
541
542 if (unformat (line_input, "ah"))
543 {
544 if (unformat (line_input, "%u", &backend_index))
545 {
546 if (ipsec_select_ah_backend (im, backend_index) < 0)
547 {
548 return clib_error_return (0, "Invalid AH backend index `%u'",
549 backend_index);
550 }
551 }
552 else
553 {
554 return clib_error_return (0, "Invalid backend index `%U'",
555 format_unformat_error, line_input);
556 }
557 }
558 else if (unformat (line_input, "esp"))
559 {
560 if (unformat (line_input, "%u", &backend_index))
561 {
562 if (ipsec_select_esp_backend (im, backend_index) < 0)
563 {
564 return clib_error_return (0, "Invalid ESP backend index `%u'",
565 backend_index);
566 }
567 }
568 else
569 {
570 return clib_error_return (0, "Invalid backend index `%U'",
571 format_unformat_error, line_input);
572 }
573 }
574 else
575 {
576 return clib_error_return (0, "Unknown input `%U'",
577 format_unformat_error, line_input);
578 }
579
580 return 0;
581}
582
583/* *INDENT-OFF* */
584VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
585 .path = "ipsec select backend",
586 .short_help = "ipsec select backend <ah|esp> <backend index>",
587 .function = ipsec_select_backend_command_fn,
588};
589
590/* *INDENT-ON* */
591
592static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700593clear_ipsec_counters_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700594 unformat_input_t * input,
595 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700596{
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800597 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
Neale Rannseba31ec2019-02-17 18:04:27 +0000598 vlib_clear_combined_counters (&ipsec_sa_counters);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800600 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700601}
602
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700603/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700604VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
605 .path = "clear ipsec counters",
606 .short_help = "clear ipsec counters",
607 .function = clear_ipsec_counters_command_fn,
608};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700609/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610
611static clib_error_t *
612create_ipsec_tunnel_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700613 unformat_input_t * input,
614 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700615{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700616 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700617 ipsec_add_del_tunnel_args_t a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618 int rv;
619 u32 num_m_args = 0;
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500620 u8 ipv4_set = 0;
621 u8 ipv6_set = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500622 clib_error_t *error = NULL;
Kingwel Xied3d12052019-03-07 06:34:30 -0500623 ipsec_key_t rck = { 0 };
624 ipsec_key_t lck = { 0 };
625 ipsec_key_t lik = { 0 };
626 ipsec_key_t rik = { 0 };
Matthew Smith2838a232016-06-21 16:05:09 -0500627
Dave Barachb7b92992018-10-17 10:38:51 -0400628 clib_memset (&a, 0, sizeof (a));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700629 a.is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700630
631 /* Get a line of input. */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700632 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700633 return 0;
634
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700635 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
636 {
637 if (unformat
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500638 (line_input, "local-ip %U", unformat_ip46_address, &a.local_ip,
639 IP46_TYPE_ANY))
640 {
641 ip46_address_is_ip4 (&a.local_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
642 num_m_args++;
643 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700644 else
645 if (unformat
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500646 (line_input, "remote-ip %U", unformat_ip46_address, &a.remote_ip,
647 IP46_TYPE_ANY))
648 {
649 ip46_address_is_ip4 (&a.remote_ip) ? (ipv4_set = 1) : (ipv6_set =
650 1);
651 num_m_args++;
652 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700653 else if (unformat (line_input, "local-spi %u", &a.local_spi))
654 num_m_args++;
655 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
656 num_m_args++;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500657 else if (unformat (line_input, "instance %u", &a.show_instance))
658 a.renumber = 1;
Radu Nicolau717de092018-08-03 10:37:24 +0100659 else if (unformat (line_input, "udp-encap"))
660 a.udp_encap = 1;
Kingwel Xie2baf9422019-02-04 02:07:06 -0800661 else if (unformat (line_input, "use-esn"))
662 a.esn = 1;
663 else if (unformat (line_input, "use-anti-replay"))
664 a.anti_replay = 1;
Pierre Pfister4c422f92018-12-10 11:19:08 +0100665 else if (unformat (line_input, "tx-table %u", &a.tx_table_id))
666 ;
Neale Rannsfd060842019-03-04 13:44:42 +0000667 else
668 if (unformat
669 (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck))
670 ;
671 else
672 if (unformat
673 (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck))
674 ;
675 else if (unformat (line_input, "crypto-alg %U",
676 unformat_ipsec_crypto_alg, &a.crypto_alg))
677 ;
678 else
679 if (unformat
680 (line_input, "local-integ-key %U", unformat_ipsec_key, &lik))
681 ;
682 else
683 if (unformat
684 (line_input, "rmote-integ-key %U", unformat_ipsec_key, &rik))
685 ;
686 else if (unformat (line_input, "integ-alg %U",
687 unformat_ipsec_integ_alg, &a.integ_alg))
688 ;
Kingwel Xie2baf9422019-02-04 02:07:06 -0800689 else if (unformat (line_input, "del"))
690 a.is_add = 0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700691 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500692 {
693 error = clib_error_return (0, "unknown input `%U'",
694 format_unformat_error, line_input);
695 goto done;
696 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700697 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700698
699 if (num_m_args < 4)
Billy McFalla9a20e72017-02-15 11:39:12 -0500700 {
701 error = clib_error_return (0, "mandatory argument(s) missing");
702 goto done;
703 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700704
Kingwel Xie72b3bce2019-02-12 06:45:08 -0500705 if (ipv6_set)
706 return clib_error_return (0, "currently only IPv4 supported");
707
708 if (ipv4_set && ipv6_set)
709 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
710
Neale Rannsfd060842019-03-04 13:44:42 +0000711 clib_memcpy (a.local_crypto_key, lck.data, lck.len);
712 a.local_crypto_key_len = lck.len;
713 clib_memcpy (a.remote_crypto_key, rck.data, rck.len);
714 a.remote_crypto_key_len = rck.len;
715
Kingwel Xied3d12052019-03-07 06:34:30 -0500716 clib_memcpy (a.local_integ_key, lik.data, lik.len);
Neale Rannsfd060842019-03-04 13:44:42 +0000717 a.local_integ_key_len = lck.len;
Kingwel Xied3d12052019-03-07 06:34:30 -0500718 clib_memcpy (a.remote_integ_key, rik.data, rik.len);
Neale Rannsfd060842019-03-04 13:44:42 +0000719 a.remote_integ_key_len = rck.len;
720
Matthew Smith2838a232016-06-21 16:05:09 -0500721 rv = ipsec_add_del_tunnel_if (&a);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700722
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700723 switch (rv)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724 {
725 case 0:
726 break;
727 case VNET_API_ERROR_INVALID_VALUE:
728 if (a.is_add)
Billy McFalla9a20e72017-02-15 11:39:12 -0500729 error = clib_error_return (0,
730 "IPSec tunnel interface already exists...");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700731 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500732 error = clib_error_return (0, "IPSec tunnel interface not exists...");
733 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700734 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500735 error = clib_error_return (0, "ipsec_register_interface returned %d",
736 rv);
737 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738 }
739
Billy McFalla9a20e72017-02-15 11:39:12 -0500740done:
741 unformat_free (line_input);
742
743 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744}
745
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700746/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
748 .path = "create ipsec tunnel",
Pierre Pfister4c422f92018-12-10 11:19:08 +0100749 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> "
Kingwel Xie2baf9422019-02-04 02:07:06 -0800750 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] "
Pierre Pfister4c422f92018-12-10 11:19:08 +0100751 "[tx-table <table-id>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752 .function = create_ipsec_tunnel_command_fn,
753};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700754/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700755
756static clib_error_t *
757set_interface_key_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700758 unformat_input_t * input,
759 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700761 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762 ipsec_main_t *im = &ipsec_main;
763 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700764 u32 hw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765 u32 alg;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700766 u8 *key = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500767 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700768
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700769 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770 return 0;
771
772 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
773 {
774 if (unformat (line_input, "%U",
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700775 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
776 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700777 else
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700778 if (unformat
779 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
780 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
781 else
782 if (unformat
783 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
784 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
785 else
786 if (unformat
787 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
788 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
789 else
790 if (unformat
791 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
792 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
793 else if (unformat (line_input, "%U", unformat_hex_string, &key))
794 ;
795 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500796 {
797 error = clib_error_return (0, "parse error: '%U'",
798 format_unformat_error, line_input);
799 goto done;
800 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801 }
802
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500804 {
805 error = clib_error_return (0, "unknown key type");
806 goto done;
807 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700808
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700809 if (alg > 0 && vec_len (key) == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500810 {
811 error = clib_error_return (0, "key is not specified");
812 goto done;
813 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700814
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700815 if (hw_if_index == (u32) ~ 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500816 {
817 error = clib_error_return (0, "interface not specified");
818 goto done;
819 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700820
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700821 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700822
Billy McFalla9a20e72017-02-15 11:39:12 -0500823done:
824 vec_free (key);
825 unformat_free (line_input);
826
827 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700828}
829
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700830/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700831VLIB_CLI_COMMAND (set_interface_key_command, static) = {
832 .path = "set interface ipsec key",
833 .short_help =
834 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
835 .function = set_interface_key_command_fn,
836};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700837/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838
Ed Warnickecb9cada2015-12-08 15:45:58 -0700839clib_error_t *
840ipsec_cli_init (vlib_main_t * vm)
841{
842 return 0;
843}
844
845VLIB_INIT_FUNCTION (ipsec_cli_init);
846
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700847
848/*
849 * fd.io coding-style-patch-verification: ON
850 *
851 * Local Variables:
852 * eval: (c-set-style "gnu")
853 * End:
854 */