32 u32 sw_if_index = (
u32) ~ 0;
41 &sw_if_index, &spd_id))
43 else if (
unformat (line_input,
"del"))
58 .path =
"set interface ipsec spd",
60 "set interface ipsec spd <int> <id>",
75 memset (&sa, 0,
sizeof (sa));
84 else if (
unformat (line_input,
"del %u", &sa.
id))
88 else if (
unformat (line_input,
"esp"))
90 else if (
unformat (line_input,
"ah"))
101 if (sa.
crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
113 if (sa.
integ_alg < IPSEC_INTEG_ALG_NONE ||
115 if (sa.
integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
121 else if (
unformat (line_input,
"tunnel-src %U",
124 else if (
unformat (line_input,
"tunnel-dst %U",
127 else if (
unformat (line_input,
"tunnel-src %U",
131 sa.is_tunnel_ip6 = 1;
133 else if (
unformat (line_input,
"tunnel-dst %U",
137 sa.is_tunnel_ip6 = 1;
146 if (sa.
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
148 if (sa.integ_alg != IPSEC_INTEG_ALG_NONE
149 && sa.integ_alg != IPSEC_INTEG_ALG_AES_GCM_128)
150 return clib_error_return (0,
151 "unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
153 sa.integ_alg = IPSEC_INTEG_ALG_AES_GCM_128;
155 else if (sa.
integ_alg == IPSEC_INTEG_ALG_AES_GCM_128)
157 else if (sa.
integ_alg == IPSEC_INTEG_ALG_NONE)
184 "ipsec sa [add|del]",
205 else if (
unformat (line_input,
"del"))
207 else if (
unformat (line_input,
"%u", &spd_id))
228 "ipsec spd [add|del] <id>",
245 memset (&p, 0,
sizeof (p));
258 else if (
unformat (line_input,
"del"))
260 else if (
unformat (line_input,
"spd %u", &p.
id))
262 else if (
unformat (line_input,
"inbound"))
264 else if (
unformat (line_input,
"outbound"))
268 else if (
unformat (line_input,
"protocol %u", &tmp))
275 if (p.
policy == IPSEC_POLICY_ACTION_RESOLVE)
280 else if (
unformat (line_input,
"local-ip-range %U - %U",
284 else if (
unformat (line_input,
"remote-ip-range %U - %U",
288 else if (
unformat (line_input,
"local-ip-range %U - %U",
295 else if (
unformat (line_input,
"remote-ip-range %U - %U",
302 else if (
unformat (line_input,
"local-port-range %u - %u", &tmp, &tmp2))
308 if (
unformat (line_input,
"remote-port-range %u - %u", &tmp, &tmp2))
331 .path =
"ipsec policy",
333 "ipsec policy [add|del] spd <id> priority <n> ",
347 memset (&sa, 0,
sizeof (sa));
388 .path =
"set ipsec sa",
390 "set ipsec sa <id> crypto-key <key> integ-key <key>",
410 vlib_cli_output(vm,
"sa %u spi %u mode %s protocol %s", sa->id, sa->spi,
411 sa->is_tunnel ?
"tunnel" :
"transport",
412 sa->protocol ?
"esp" :
"ah");
413 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
414 vlib_cli_output(vm,
" crypto alg %U%s%U integrity alg %U%s%U",
415 format_ipsec_crypto_alg, sa->crypto_alg,
416 sa->crypto_alg ?
" key " :
"",
417 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
418 format_ipsec_integ_alg, sa->integ_alg,
419 sa->integ_alg ?
" key " :
"",
420 format_hex_bytes, sa->integ_key, sa->integ_key_len);
422 if (sa->is_tunnel && sa->is_tunnel_ip6) {
423 vlib_cli_output(vm,
" tunnel src %U dst %U",
424 format_ip6_address, &sa->tunnel_src_addr.ip6,
425 format_ip6_address, &sa->tunnel_dst_addr.ip6);
426 } else if (sa->is_tunnel) {
427 vlib_cli_output(vm,
" tunnel src %U dst %U",
428 format_ip4_address, &sa->tunnel_src_addr.ip4,
429 format_ip4_address, &sa->tunnel_dst_addr.ip4);
437 vlib_cli_output(vm,
"spd %u", spd->id);
439 vlib_cli_output(vm,
" outbound policies");
440 vec_foreach(i, spd->ipv4_outbound_policies)
442 p = pool_elt_at_index(spd->policies, *i);
443 vlib_cli_output(vm,
" priority %d action %U protocol %s%s",
445 format_ipsec_policy_action, p->policy,
447 format(0,
"%U", format_ip_protocol, p->protocol) :
449 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
450 format(0,
" sa %u", p->sa_id) :
452 vlib_cli_output(vm,
" local addr range %U - %U port range %u - %u",
453 format_ip4_address, &p->laddr.start.ip4,
454 format_ip4_address, &p->laddr.stop.ip4,
455 p->lport.start, p->lport.stop);
456 vlib_cli_output(vm,
" remte addr range %U - %U port range %u - %u",
457 format_ip4_address, &p->raddr.start.ip4,
458 format_ip4_address, &p->raddr.stop.ip4,
459 p->rport.start, p->rport.stop);
460 vlib_cli_output(vm,
" packets %u bytes %u", p->counter.packets,
465 p = pool_elt_at_index(spd->policies, *i);
466 vlib_cli_output(vm,
" priority %d action %U protocol %s%s",
468 format_ipsec_policy_action, p->policy,
470 format(0,
"%U", format_ip_protocol, p->protocol) :
472 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
473 format(0,
" sa %u", p->sa_id) :
475 vlib_cli_output(vm,
" local addr range %U - %U port range %u - %u",
476 format_ip6_address, &p->laddr.start.ip6,
477 format_ip6_address, &p->laddr.stop.ip6,
478 p->lport.start, p->lport.stop);
479 vlib_cli_output(vm,
" remote addr range %U - %U port range %u - %u",
480 format_ip6_address, &p->raddr.start.ip6,
481 format_ip6_address, &p->raddr.stop.ip6,
482 p->rport.start, p->rport.stop);
483 vlib_cli_output(vm,
" packets %u bytes %u", p->counter.packets,
487 vec_foreach(
i, spd->ipv4_inbound_protect_policy_indices)
496 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
497 format(0,
" sa %u", p->sa_id) :
502 p->lport.start, p->lport.stop);
506 p->rport.start, p->rport.stop);
510 vec_foreach(
i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
519 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
520 format(0,
" sa %u", p->sa_id) :
525 p->lport.start, p->lport.stop);
529 p->rport.start, p->rport.stop);
533 vec_foreach(
i, spd->ipv6_inbound_protect_policy_indices)
542 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
543 format(0,
" sa %u", p->sa_id) :
548 p->lport.start, p->lport.stop);
552 p->rport.start, p->rport.stop);
556 vec_foreach(
i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
565 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
566 format(0,
" sa %u", p->sa_id) :
571 p->lport.start, p->lport.stop);
575 p->rport.start, p->rport.stop);
585 if (t->hw_if_index == ~0)
587 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
588 vlib_cli_output(vm,
" %s seq", hi->name);
589 sa = pool_elt_at_index(im->sad, t->output_sa_index);
590 vlib_cli_output(vm,
" seq %u seq-hi %u esn %u anti-replay %u",
591 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay);
592 vlib_cli_output(vm,
" local-spi %u local-ip %U", sa->spi,
593 format_ip4_address, &sa->tunnel_src_addr.ip4);
594 vlib_cli_output(vm,
" local-crypto %U %U",
595 format_ipsec_crypto_alg, sa->crypto_alg,
596 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
597 vlib_cli_output(vm,
" local-integrity %U %U",
598 format_ipsec_integ_alg, sa->integ_alg,
599 format_hex_bytes, sa->integ_key, sa->integ_key_len);
600 sa = pool_elt_at_index(im->sad, t->input_sa_index);
601 vlib_cli_output(vm,
" last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
602 sa->last_seq, sa->last_seq_hi, sa->use_esn,
604 format_ipsec_replay_window, sa->replay_window);
605 vlib_cli_output(vm,
" remote-spi %u remote-ip %U", sa->spi,
606 format_ip4_address, &sa->tunnel_src_addr.ip4);
607 vlib_cli_output(vm,
" remote-crypto %U %U",
608 format_ipsec_crypto_alg, sa->crypto_alg,
609 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
610 vlib_cli_output(vm,
" remote-integrity %U %U",
611 format_ipsec_integ_alg, sa->integ_alg,
612 format_hex_bytes, sa->integ_key, sa->integ_key_len);
620 .path =
"show ipsec",
621 .short_help =
"show ipsec",
637 pool_foreach(p, spd->policies, ({
638 p->counter.packets = p->counter.bytes = 0;
648 .path =
"clear ipsec counters",
649 .short_help =
"clear ipsec counters",
664 memset (&a, 0,
sizeof (a));
684 else if (
unformat (line_input,
"del"))
701 case VNET_API_ERROR_INVALID_VALUE:
704 "IPSec tunnel interface already exists...");
717 .path =
"create ipsec tunnel",
718 .short_help =
"create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi>",
731 u32 hw_if_index = (
u32) ~ 0;
771 if (alg > 0 &&
vec_len (key) == 0)
774 if (hw_if_index == (
u32) ~ 0)
785 .path =
"set interface ipsec key",
787 "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
int ipsec_set_interface_spd(vlib_main_t *vm, u32 sw_if_index, u32 spd_id, int is_add)
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)
int ipsec_set_sa_key(vlib_main_t *vm, ipsec_sa_t *sa_update)
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
uword unformat_ipsec_integ_alg(unformat_input_t *input, va_list *args)
uword unformat_ipsec_crypto_alg(unformat_input_t *input, va_list *args)
static vlib_cli_command_t set_interface_key_command
(constructor) VLIB_CLI_COMMAND (set_interface_key_command)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static vlib_cli_command_t show_ipsec_command
(constructor) VLIB_CLI_COMMAND (show_ipsec_command)
#define VLIB_INIT_FUNCTION(x)
int ipsec_set_interface_key(vnet_main_t *vnm, u32 hw_if_index, ipsec_if_set_key_type_t type, u8 alg, u8 *key)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static vlib_cli_command_t create_ipsec_tunnel_command
(constructor) VLIB_CLI_COMMAND (create_ipsec_tunnel_command)
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)
ip46_address_range_t laddr
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add)
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)
clib_error_t * ipsec_cli_init(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
#define VLIB_CLI_COMMAND(x,...)
ip46_address_range_t raddr
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
u8 * format_ipsec_policy_action(u8 *s, va_list *args)
ipsec_protocol_t protocol
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
int ipsec_add_del_sa(vlib_main_t *vm, ipsec_sa_t *new_sa, int is_add)
int ipsec_add_del_tunnel_if(ipsec_add_del_tunnel_args_t *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
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...)
uword unformat_ipsec_policy_action(unformat_input_t *input, va_list *args)
static clib_error_t * ipsec_spd_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static vlib_cli_command_t clear_ipsec_counters_command
(constructor) VLIB_CLI_COMMAND (clear_ipsec_counters_command)