42 &sw_if_index, &spd_id))
44 else if (
unformat (line_input,
"del"))
63 .path =
"set interface ipsec spd",
65 "set interface ipsec spd <int> <id>",
82 memset (&sa, 0,
sizeof (sa));
91 else if (
unformat (line_input,
"del %u", &sa.
id))
95 else if (
unformat (line_input,
"esp"))
97 else if (
unformat (line_input,
"ah"))
124 if (sa.
integ_alg < IPSEC_INTEG_ALG_NONE ||
133 else if (
unformat (line_input,
"tunnel-src %U",
136 else if (
unformat (line_input,
"tunnel-dst %U",
139 else if (
unformat (line_input,
"tunnel-src %U",
145 else if (
unformat (line_input,
"tunnel-dst %U",
151 else if (
unformat (line_input,
"udp-encap"))
195 "ipsec sa [add|del]",
217 else if (
unformat (line_input,
"del"))
219 else if (
unformat (line_input,
"%u", &spd_id))
247 "ipsec spd [add|del] <id>",
265 memset (&p, 0,
sizeof (p));
278 else if (
unformat (line_input,
"del"))
280 else if (
unformat (line_input,
"spd %u", &p.
id))
282 else if (
unformat (line_input,
"inbound"))
284 else if (
unformat (line_input,
"outbound"))
288 else if (
unformat (line_input,
"protocol %u", &tmp))
295 if (p.
policy == IPSEC_POLICY_ACTION_RESOLVE)
303 else if (
unformat (line_input,
"local-ip-range %U - %U",
307 else if (
unformat (line_input,
"remote-ip-range %U - %U",
311 else if (
unformat (line_input,
"local-ip-range %U - %U",
318 else if (
unformat (line_input,
"remote-ip-range %U - %U",
325 else if (
unformat (line_input,
"local-port-range %u - %u", &tmp, &tmp2))
331 if (
unformat (line_input,
"remote-port-range %u - %u", &tmp, &tmp2))
380 .path =
"ipsec policy",
382 "ipsec policy [add|del] spd <id> priority <n> ",
397 memset (&sa, 0,
sizeof (sa));
442 .path =
"set ipsec sa",
444 "set ipsec sa <id> crypto-key <key> integ-key <key>",
466 vlib_cli_output(vm,
"sa %u spi %u mode %s protocol %s%s", sa->id, sa->spi,
467 sa->is_tunnel ?
"tunnel" :
"transport",
468 sa->protocol ?
"esp" :
"ah",
469 sa->udp_encap ?
" udp-encap-enabled" :
"");
470 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
471 vlib_cli_output(vm,
" crypto alg %U%s%U integrity alg %U%s%U",
472 format_ipsec_crypto_alg, sa->crypto_alg,
473 sa->crypto_alg ?
" key " :
"",
474 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
475 format_ipsec_integ_alg, sa->integ_alg,
476 sa->integ_alg ?
" key " :
"",
477 format_hex_bytes, sa->integ_key, sa->integ_key_len);
479 if (sa->is_tunnel && sa->is_tunnel_ip6) {
480 vlib_cli_output(vm,
" tunnel src %U dst %U",
481 format_ip6_address, &sa->tunnel_src_addr.ip6,
482 format_ip6_address, &sa->tunnel_dst_addr.ip6);
483 } else if (sa->is_tunnel) {
484 vlib_cli_output(vm,
" tunnel src %U dst %U",
485 format_ip4_address, &sa->tunnel_src_addr.ip4,
486 format_ip4_address, &sa->tunnel_dst_addr.ip4);
494 vlib_cli_output(vm,
"spd %u", spd->id);
496 vlib_cli_output(vm,
" outbound policies");
497 vec_foreach(i, spd->ipv4_outbound_policies)
499 p = pool_elt_at_index(spd->policies, *i);
500 vec_reset_length(protocol);
501 vec_reset_length(policy);
503 protocol = format(protocol,
"%U", format_ip_protocol, p->protocol);
505 protocol = format(protocol,
"any");
507 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
508 policy = format(policy,
" sa %u", p->sa_id);
511 vlib_cli_output(vm,
" priority %d action %U protocol %v%v",
512 p->priority, format_ipsec_policy_action, p->policy,
514 vlib_cli_output(vm,
" local addr range %U - %U port range %u - %u",
515 format_ip4_address, &p->laddr.start.ip4,
516 format_ip4_address, &p->laddr.stop.ip4,
517 p->lport.start, p->lport.stop);
518 vlib_cli_output(vm,
" remote addr range %U - %U port range %u - %u",
519 format_ip4_address, &p->raddr.start.ip4,
520 format_ip4_address, &p->raddr.stop.ip4,
521 p->rport.start, p->rport.stop);
522 vlib_cli_output(vm,
" packets %u bytes %u", p->counter.packets,
527 p = pool_elt_at_index(spd->policies, *i);
528 vec_reset_length(protocol);
529 vec_reset_length(policy);
531 protocol = format(protocol,
"%U", format_ip_protocol, p->protocol);
533 protocol = format(protocol,
"any");
535 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
536 policy = format(policy,
" sa %u", p->sa_id);
544 p->lport.start, p->lport.stop);
548 p->rport.start, p->rport.stop);
553 vec_foreach(
i, spd->ipv4_inbound_protect_policy_indices)
561 protocol =
format(protocol,
"any");
563 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
564 policy =
format(policy,
" sa %u", p->sa_id);
572 p->lport.start, p->lport.stop);
576 p->rport.start, p->rport.stop);
580 vec_foreach(
i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
588 protocol =
format(protocol,
"any");
590 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
591 policy =
format(policy,
" sa %u", p->sa_id);
599 p->lport.start, p->lport.stop);
603 p->rport.start, p->rport.stop);
607 vec_foreach(
i, spd->ipv6_inbound_protect_policy_indices)
615 protocol =
format(protocol,
"any");
617 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
618 policy =
format(policy,
" sa %u", p->sa_id);
626 p->lport.start, p->lport.stop);
630 p->rport.start, p->rport.stop);
634 vec_foreach(
i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
642 protocol =
format(protocol,
"any");
644 if (p->policy == IPSEC_POLICY_ACTION_PROTECT) {
645 policy =
format(policy,
" sa %u", p->sa_id);
653 p->lport.start, p->lport.stop);
657 p->rport.start, p->rport.stop);
667 if (t->hw_if_index == ~0)
669 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
670 vlib_cli_output(vm,
" %s seq", hi->name);
671 sa = pool_elt_at_index(im->sad, t->output_sa_index);
672 vlib_cli_output(vm,
" seq %u seq-hi %u esn %u anti-replay %u udp-encap %u",
673 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay, sa->udp_encap);
674 vlib_cli_output(vm,
" local-spi %u local-ip %U", sa->spi,
675 format_ip4_address, &sa->tunnel_src_addr.ip4);
676 vlib_cli_output(vm,
" local-crypto %U %U",
677 format_ipsec_crypto_alg, sa->crypto_alg,
678 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
679 vlib_cli_output(vm,
" local-integrity %U %U",
680 format_ipsec_integ_alg, sa->integ_alg,
681 format_hex_bytes, sa->integ_key, sa->integ_key_len);
682 sa = pool_elt_at_index(im->sad, t->input_sa_index);
683 vlib_cli_output(vm,
" last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
684 sa->last_seq, sa->last_seq_hi, sa->use_esn,
686 format_ipsec_replay_window, sa->replay_window);
687 vlib_cli_output(vm,
" remote-spi %u remote-ip %U", sa->spi,
688 format_ip4_address, &sa->tunnel_src_addr.ip4);
689 vlib_cli_output(vm,
" remote-crypto %U %U",
690 format_ipsec_crypto_alg, sa->crypto_alg,
691 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
692 vlib_cli_output(vm,
" remote-integrity %U %U",
693 format_ipsec_integ_alg, sa->integ_alg,
694 format_hex_bytes, sa->integ_key, sa->integ_key_len);
704 .path =
"show ipsec",
705 .short_help =
"show ipsec",
721 pool_foreach(p, spd->policies, ({
722 p->counter.packets = p->counter.bytes = 0;
732 .path =
"clear ipsec counters",
733 .short_help =
"clear ipsec counters",
749 memset (&a, 0,
sizeof (a));
771 else if (
unformat (line_input,
"del"))
773 else if (
unformat (line_input,
"udp-encap"))
795 case VNET_API_ERROR_INVALID_VALUE:
798 "IPSec tunnel interface already exists...");
816 .path =
"create ipsec tunnel",
817 .short_help =
"create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap]",
830 u32 hw_if_index = (
u32) ~ 0;
875 if (alg > 0 &&
vec_len (key) == 0)
881 if (hw_if_index == (
u32) ~ 0)
898 .path =
"set interface ipsec key",
900 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
unformat_function_t unformat_vnet_hw_interface
int ipsec_set_interface_key(vnet_main_t *vnm, u32 hw_if_index, ipsec_if_set_key_type_t type, u8 alg, u8 *key)
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add)
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)
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)
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
static vlib_cli_command_t set_interface_key_command
(constructor) VLIB_CLI_COMMAND (set_interface_key_command)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#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)
uword unformat_ipsec_integ_alg(unformat_input_t *input, va_list *args)
#define clib_error_return(e, args...)
ipsec_main_callbacks_t cb
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
#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)
clib_error_t *(* check_support_cb)(ipsec_sa_t *sa)
static clib_error_t * set_interface_spd_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword unformat_ipsec_crypto_alg(unformat_input_t *input, va_list *args)
ip46_address_range_t laddr
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_add_del_sa(vlib_main_t *vm, ipsec_sa_t *new_sa, int is_add)
clib_error_t * ipsec_cli_init(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
uword * sa_index_by_sa_id
int ipsec_set_sa_key(vlib_main_t *vm, ipsec_sa_t *sa_update)
#define VLIB_CLI_COMMAND(x,...)
ip46_address_range_t raddr
ipsec_protocol_t protocol
uword unformat_ipsec_policy_action(unformat_input_t *input, va_list *args)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
u8 * format_ipsec_policy_action(u8 *s, va_list *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
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.
int ipsec_add_del_tunnel_if(ipsec_add_del_tunnel_args_t *args)
static clib_error_t * ipsec_spd_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static vlib_cli_command_t clear_ipsec_counters_command
(constructor) VLIB_CLI_COMMAND (clear_ipsec_counters_command)