32 u32 sw_if_index = (
u32) ~0;
40 &sw_if_index, &spd_id))
42 else if (
unformat (line_input,
"del"))
56 .path =
"set interface ipsec spd",
58 "set interface ipsec spd <int> <id>",
72 memset(&sa, 0,
sizeof(sa));
80 else if (
unformat (line_input,
"del %u", &sa.
id))
84 else if (
unformat (line_input,
"esp"))
86 else if (
unformat (line_input,
"ah"))
94 if (sa.
crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
104 if (sa.
integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
105 sa.
integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
109 else if (
unformat (line_input,
"tunnel-src %U",
112 else if (
unformat (line_input,
"tunnel-dst %U",
115 else if (
unformat (line_input,
"tunnel-src %U",
118 else if (
unformat (line_input,
"tunnel-dst %U",
148 "ipsec sa [add|del]",
167 else if (
unformat (line_input,
"del"))
169 else if (
unformat (line_input,
"%u", &spd_id))
186 "ipsec spd [add|del] <id>",
202 memset(&p, 0,
sizeof(p));
214 else if (
unformat (line_input,
"del"))
216 else if (
unformat (line_input,
"spd %u", &p.
id))
218 else if (
unformat (line_input,
"inbound"))
220 else if (
unformat (line_input,
"outbound"))
224 else if (
unformat (line_input,
"protocol %u", &tmp))
229 if (p.
policy == IPSEC_POLICY_ACTION_RESOLVE)
234 else if (
unformat (line_input,
"local-ip-range %U - %U",
238 else if (
unformat (line_input,
"remote-ip-range %U - %U",
242 else if (
unformat (line_input,
"local-ip-range %U - %U",
249 else if (
unformat (line_input,
"remote-ip-range %U - %U",
256 else if (
unformat (line_input,
"local-port-range %u - %u", &tmp, &tmp2))
258 else if (
unformat (line_input,
"remote-port-range %u - %u", &tmp, &tmp2))
277 .path =
"ipsec policy",
279 "ipsec policy [add|del] spd <id> priority <n> ",
292 memset(&sa, 0,
sizeof(sa));
329 .path =
"set ipsec sa",
331 "set ipsec sa <id> crypto-key <key> integ-key <key>",
350 vlib_cli_output(vm,
"sa %u spi %u mode %s protocol %s", sa->id, sa->spi,
351 sa->is_tunnel ?
"tunnel" :
"transport",
352 sa->protocol ?
"esp" :
"ah");
353 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
354 vlib_cli_output(vm,
" crypto alg %U%s%U integrity alg %U%s%U",
355 format_ipsec_crypto_alg, sa->crypto_alg,
356 sa->crypto_alg ?
" key " :
"",
357 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
358 format_ipsec_integ_alg, sa->integ_alg,
359 sa->integ_alg ?
" key " :
"",
360 format_hex_bytes, sa->integ_key, sa->integ_key_len);
362 if (sa->is_tunnel && sa->is_tunnel_ip6) {
363 vlib_cli_output(vm,
" tunnel src %U dst %U",
364 format_ip6_address, &sa->tunnel_src_addr.ip6,
365 format_ip6_address, &sa->tunnel_dst_addr.ip6);
366 } else if (sa->is_tunnel) {
367 vlib_cli_output(vm,
" tunnel src %U dst %U",
368 format_ip4_address, &sa->tunnel_src_addr.ip4,
369 format_ip4_address, &sa->tunnel_dst_addr.ip4);
375 vlib_cli_output(vm,
"spd %u", spd->id);
377 vlib_cli_output(vm,
" outbound policies");
378 vec_foreach(i, spd->ipv4_outbound_policies)
380 p = pool_elt_at_index(spd->policies, *i);
381 vlib_cli_output(vm,
" priority %d action %U protocol %s%s",
383 format_ipsec_policy_action, p->policy,
385 format(0,
"%U", format_ip_protocol, p->protocol) :
387 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
388 format(0,
" sa %u", p->sa_id) :
390 vlib_cli_output(vm,
" local addr range %U - %U port range %u - %u",
391 format_ip4_address, &p->laddr.start.ip4,
392 format_ip4_address, &p->laddr.stop.ip4,
393 p->lport.start, p->lport.stop);
394 vlib_cli_output(vm,
" remte addr range %U - %U port range %u - %u",
395 format_ip4_address, &p->raddr.start.ip4,
396 format_ip4_address, &p->raddr.stop.ip4,
397 p->rport.start, p->rport.stop);
398 vlib_cli_output(vm,
" packets %u bytes %u", p->counter.packets,
403 p = pool_elt_at_index(spd->policies, *i);
404 vlib_cli_output(vm,
" priority %d action %U protocol %s%s",
406 format_ipsec_policy_action, p->policy,
408 format(0,
"%U", format_ip_protocol, p->protocol) :
410 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
411 format(0,
" sa %u", p->sa_id) :
413 vlib_cli_output(vm,
" local addr range %U - %U port range %u - %u",
414 format_ip6_address, &p->laddr.start.ip6,
415 format_ip6_address, &p->laddr.stop.ip6,
416 p->lport.start, p->lport.stop);
417 vlib_cli_output(vm,
" remote addr range %U - %U port range %u - %u",
418 format_ip6_address, &p->raddr.start.ip6,
419 format_ip6_address, &p->raddr.stop.ip6,
420 p->rport.start, p->rport.stop);
421 vlib_cli_output(vm,
" packets %u bytes %u", p->counter.packets,
425 vec_foreach(
i, spd->ipv4_inbound_protect_policy_indices)
434 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
435 format(0,
" sa %u", p->sa_id) :
440 p->lport.start, p->lport.stop);
444 p->rport.start, p->rport.stop);
448 vec_foreach(
i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
457 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
458 format(0,
" sa %u", p->sa_id) :
463 p->lport.start, p->lport.stop);
467 p->rport.start, p->rport.stop);
471 vec_foreach(
i, spd->ipv6_inbound_protect_policy_indices)
480 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
481 format(0,
" sa %u", p->sa_id) :
486 p->lport.start, p->lport.stop);
490 p->rport.start, p->rport.stop);
494 vec_foreach(
i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
503 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
504 format(0,
" sa %u", p->sa_id) :
509 p->lport.start, p->lport.stop);
513 p->rport.start, p->rport.stop);
521 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
522 vlib_cli_output(vm,
" %s seq", hi->name);
523 sa = pool_elt_at_index(im->sad, t->output_sa_index);
524 vlib_cli_output(vm,
" seq %u seq-hi %u esn %u anti-replay %u",
525 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay);
526 vlib_cli_output(vm,
" local-spi %u local-ip %U", sa->spi,
527 format_ip4_address, &sa->tunnel_src_addr.ip4);
528 vlib_cli_output(vm,
" local-crypto %U %U",
529 format_ipsec_crypto_alg, sa->crypto_alg,
530 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
531 vlib_cli_output(vm,
" local-integrity %U %U",
532 format_ipsec_integ_alg, sa->integ_alg,
533 format_hex_bytes, sa->integ_key, sa->integ_key_len);
534 sa = pool_elt_at_index(im->sad, t->input_sa_index);
535 vlib_cli_output(vm,
" last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
536 sa->last_seq, sa->last_seq_hi, sa->use_esn,
538 format_ipsec_replay_window, sa->replay_window);
539 vlib_cli_output(vm,
" remote-spi %u remote-ip %U", sa->spi,
540 format_ip4_address, &sa->tunnel_src_addr.ip4);
541 vlib_cli_output(vm,
" remote-crypto %U %U",
542 format_ipsec_crypto_alg, sa->crypto_alg,
543 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
544 vlib_cli_output(vm,
" remote-integrity %U %U",
545 format_ipsec_integ_alg, sa->integ_alg,
546 format_hex_bytes, sa->integ_key, sa->integ_key_len);
552 .path =
"show ipsec",
553 .short_help =
"show ipsec",
567 pool_foreach(p, spd->policies, ({
568 p->counter.packets = p->counter.bytes = 0;
576 .path =
"clear ipsec counters",
577 .short_help =
"clear ipsec counters",
608 else if (
unformat (line_input,
"del"))
625 case VNET_API_ERROR_INVALID_VALUE:
638 .path =
"create ipsec tunnel",
639 .short_help =
"create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi>",
651 u32 hw_if_index = (
u32) ~0;
683 if (alg > 0 &&
vec_len(key)==0)
686 if (hw_if_index == (
u32) ~0)
696 .path =
"set interface ipsec key",
698 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
unformat_function_t unformat_vnet_hw_interface
sll srl srl sll sra u16x4 i
ip46_address_t tunnel_src_addr
static clib_error_t * set_ipsec_sa_key_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
ipsec_integ_alg_t integ_alg
static clib_error_t * create_ipsec_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword unformat_ipsec_integ_alg(unformat_input_t *input, va_list *args)
static clib_error_t * set_interface_key_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
unformat_function_t unformat_vnet_sw_interface
vlib_cli_command_t set_interface_key_command
(constructor) VLIB_CLI_COMMAND (set_interface_key_command)
u32 ipsec_add_del_tunnel_if(vnet_main_t *vnm, ipsec_add_del_tunnel_args_t *args)
#define pool_foreach(VAR, POOL, BODY)
vlib_cli_command_t show_ipsec_command
(constructor) VLIB_CLI_COMMAND (show_ipsec_command)
#define VLIB_INIT_FUNCTION(x)
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
vlib_cli_command_t create_ipsec_tunnel_command
(constructor) VLIB_CLI_COMMAND (create_ipsec_tunnel_command)
uword unformat_ipsec_policy_action(unformat_input_t *input, va_list *args)
static clib_error_t * ipsec_policy_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_interface_spd_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_add_del_sa(vlib_main_t *vm, ipsec_sa_t *new_sa, int is_add)
ip46_address_range_t laddr
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
ip46_address_t tunnel_dst_addr
static clib_error_t * clear_ipsec_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_set_sa_key(vlib_main_t *vm, ipsec_sa_t *sa_update)
clib_error_t * ipsec_cli_init(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
#define VLIB_CLI_COMMAND(x,...)
ip46_address_range_t raddr
ipsec_protocol_t protocol
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_ipsec_policy_action(u8 *s, va_list *args)
static clib_error_t * ipsec_sa_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ipsec_crypto_alg_t crypto_alg
static clib_error_t * show_ipsec_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define vec_foreach(var, vec)
Vector iterator.
#define clib_error_return(e, args...)
static clib_error_t * ipsec_spd_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
int ipsec_set_interface_spd(vlib_main_t *vm, u32 sw_if_index, u32 spd_id, int is_add)
uword unformat_ipsec_crypto_alg(unformat_input_t *input, va_list *args)
int ipsec_set_interface_key(vnet_main_t *vnm, u32 hw_if_index, ipsec_if_set_key_type_t type, u8 alg, u8 *key)
vlib_cli_command_t clear_ipsec_counters_command
(constructor) VLIB_CLI_COMMAND (clear_ipsec_counters_command)