44 &sw_if_index, &spd_id))
46 else if (
unformat (line_input,
"del"))
65 .path =
"set interface ipsec spd",
67 "set interface ipsec spd <int> <id>",
78 ip46_address_t tun_src = { }, tun_dst =
94 flags = IPSEC_SA_FLAG_NONE;
96 integ_alg = IPSEC_INTEG_ALG_NONE;
97 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
104 if (
unformat (line_input,
"add %u", &
id))
106 else if (
unformat (line_input,
"del %u", &
id))
108 else if (
unformat (line_input,
"spi %u", &spi))
110 else if (
unformat (line_input,
"salt 0x%x", &salt))
112 else if (
unformat (line_input,
"esp"))
114 else if (
unformat (line_input,
"ah"))
116 else if (
unformat (line_input,
"crypto-key %U",
119 else if (
unformat (line_input,
"crypto-alg %U",
124 else if (
unformat (line_input,
"integ-alg %U",
127 else if (
unformat (line_input,
"tunnel-src %U",
130 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
132 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
134 else if (
unformat (line_input,
"tunnel-dst %U",
137 else if (
unformat (line_input,
"udp-encap"))
138 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
149 &ck, integ_alg, &ik, flags,
150 0, clib_host_to_net_u32 (salt),
151 &tun_src, &tun_dst, NULL);
168 "ipsec sa [add|del]",
190 else if (
unformat (line_input,
"del"))
192 else if (
unformat (line_input,
"%u", &spd_id))
220 "ipsec spd [add|del] <id>",
234 u32 tmp, tmp2, stat_index;
249 else if (
unformat (line_input,
"del"))
251 else if (
unformat (line_input,
"spd %u", &p.
id))
253 else if (
unformat (line_input,
"inbound"))
255 else if (
unformat (line_input,
"outbound"))
259 else if (
unformat (line_input,
"protocol %u", &tmp))
266 if (p.
policy == IPSEC_POLICY_ACTION_RESOLVE)
274 else if (
unformat (line_input,
"local-ip-range %U - %U",
278 else if (
unformat (line_input,
"remote-ip-range %U - %U",
282 else if (
unformat (line_input,
"local-ip-range %U - %U",
288 else if (
unformat (line_input,
"remote-ip-range %U - %U",
294 else if (
unformat (line_input,
"local-port-range %u - %u", &tmp, &tmp2))
300 if (
unformat (line_input,
"remote-port-range %u - %u", &tmp, &tmp2))
318 " outboud:%s %s action:%U",
319 (is_outbound ?
"yes" :
"no"),
340 .path =
"ipsec policy",
342 "ipsec policy [add|del] spd <id> priority <n> ",
354 vlib_cli_output(vm,
"%U", format_ipsec_sa, sai,
355 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
367 vlib_cli_output(vm,
"%U", format_ipsec_spd, spdi);
382 spd = pool_elt_at_index (im->spds, spd_id);
383 vlib_cli_output (vm,
" %d -> %U", spd->id,
384 format_vnet_sw_if_index_name, im->vnet_main,
398 vlib_cli_output(vm,
" %U", format_ipsec_tunnel, ti);
419 .path =
"show ipsec all",
420 .short_help =
"show ipsec all",
488 .path =
"show ipsec sa",
489 .short_help =
"show ipsec sa [index]",
494 .path =
"clear ipsec sa",
495 .short_help =
"clear ipsec sa [index]",
505 u8 show_bindings = 0;
512 else if (
unformat (input,
"bindings"))
530 .path =
"show ipsec spd",
531 .short_help =
"show ipsec spd [index]",
562 .path =
"show ipsec tunnel",
563 .short_help =
"show ipsec tunnel [index]",
576 (void)
unformat (input,
"verbose %u", &verbose);
579 u8 *s =
format (NULL,
"%=25s %=25s %=10s\n",
"Name",
"Index",
"Active");
583 s = format (s,
"%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
584 ab - im->ah_backends == im->ah_current_backend ?
"yes" :
"no");
587 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
588 s = format (s,
" enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
589 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
590 s = format (s,
" dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
591 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
592 s = format (s,
" enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
593 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
594 s = format (s,
" dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
601 s =
format (s,
"%=25s %=25s %=10s\n",
"Name",
"Index",
"Active");
605 s = format (s,
"%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
606 eb - im->esp_backends == im->esp_current_backend ?
"yes" 610 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
611 s = format (s,
" enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
612 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
613 s = format (s,
" dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
614 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
615 s = format (s,
" enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
616 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
617 s = format (s,
" dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
629 .path =
"show ipsec backends",
630 .short_help =
"show ipsec backends",
656 if (
unformat (line_input,
"%u", &backend_index))
670 else if (
unformat (line_input,
"esp"))
672 if (
unformat (line_input,
"%u", &backend_index))
697 .path =
"ipsec select backend",
698 .short_help =
"ipsec select backend <ah|esp> <backend index>",
717 .path =
"clear ipsec counters",
718 .short_help =
"clear ipsec counters",
773 else if (
unformat (line_input,
"udp-encap"))
775 else if (
unformat (line_input,
"use-esn"))
777 else if (
unformat (line_input,
"use-anti-replay"))
789 else if (
unformat (line_input,
"crypto-alg %U",
800 else if (
unformat (line_input,
"integ-alg %U",
803 else if (
unformat (line_input,
"del"))
819 if (ipv4_set && ipv6_set)
825 a.local_crypto_key_len = lck.len;
827 a.remote_crypto_key_len = rck.len;
830 a.local_integ_key_len = lck.len;
832 a.remote_integ_key_len = rck.len;
840 case VNET_API_ERROR_INVALID_VALUE:
843 "IPSec tunnel interface already exists...");
861 .path =
"create ipsec tunnel",
862 .short_help =
"create ipsec tunnel local-ip <addr> local-spi <spi> " 863 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] " 864 "[tx-table <table-id>]",
888 else if (
unformat (line_input,
"add"))
890 else if (
unformat (line_input,
"sa-in %d", &sa_in))
892 else if (
unformat (line_input,
"sa-out %d", &sa_out))
894 else if (
unformat (line_input,
"%U",
915 .path =
"ipsec tunnel protect",
917 .short_help =
"ipsec tunnel protect <interface> input-sa <SA> output-sa <SA>",
945 .path =
"show ipsec protect",
947 .short_help =
"show ipsec protect",
960 ipsec4_tunnel_key_t
key;
967 vlib_cli_output (vm,
" %U", format_ipsec4_tunnel_key, &key);
968 vlib_cli_output (vm,
" tun:%d sa:%d", value.tun_index, value.sa_index);
975 ipsec6_tunnel_key_t *
key;
982 vlib_cli_output (vm,
" %U", format_ipsec6_tunnel_key, key);
983 vlib_cli_output (vm,
" tun:%d sa:%d", value.tun_index, value.sa_index);
997 .path =
"show ipsec protect-hash",
999 .short_help =
"show ipsec protect-hash",
static clib_error_t * ipsec_select_backend_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ipsec_tunnel_if_t * tunnel_interfaces
uword * tun6_protect_by_key
vnet_main_t * vnet_get_main(void)
ip46_address_range_t laddr
static clib_error_t * show_ipsec_spd_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
int ipsec_policy_mk_type(bool is_outbound, bool is_ipv6, ipsec_policy_action_t action, ipsec_spd_policy_type_t *type)
static clib_error_t * create_ipsec_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int ipsec_add_del_tunnel_if(ipsec_add_del_tunnel_args_t *args)
void ipsec_sa_clear(index_t sai)
int ipsec_select_ah_backend(ipsec_main_t *im, u32 backend_idx)
unformat_function_t unformat_vnet_sw_interface
A Secruity Policy Database.
void ipsec_tun_protect_walk(ipsec_tun_protect_walk_cb_t fn, void *ctx)
uword * spd_index_by_sw_if_index
#define clib_memcpy(d, s, n)
enum walk_rc_t_ walk_rc_t
Walk return code.
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
int ipsec_select_esp_backend(ipsec_main_t *im, u32 backend_idx)
#define hash_foreach(key_var, value_var, h, body)
#define clib_error_return(e, args...)
int ipsec_sa_unlock_id(u32 id)
static void ipsec_tunnel_show_all(vlib_main_t *vm, ipsec_main_t *im)
static clib_error_t * ipsec_tun_protect_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_combined_counter_main_t ipsec_spd_policy_counters
Policy packet & bytes counters.
static clib_error_t * ipsec_policy_add_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add, u32 *stat_index)
Add/Delete a SPD.
static clib_error_t * set_interface_spd_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
clib_error_t * ipsec_rsc_in_use(ipsec_main_t *im)
static clib_error_t * ipsec_show_backends_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ipsec_spd_policy_type_t type
#define hash_foreach_mem(key_var, value_var, h, body)
static void ipsec_spd_bindings_show_all(vlib_main_t *vm, ipsec_main_t *im)
static clib_error_t * clear_ipsec_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define ip46_address_is_ip4(ip46)
ipsec_crypto_alg_t crypto_alg
static void ipsec_sa_show_all(vlib_main_t *vm, ipsec_main_t *im, u8 detail)
int ipsec_tun_protect_update(u32 sw_if_index, u32 sa_out, u32 *sas_in)
ipsec_ah_backend_t * ah_backends
clib_error_t * ipsec_cli_init(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * clear_ipsec_sa_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ipsec_policy_action_t policy
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#define VLIB_CLI_COMMAND(x,...)
static void ipsec_spd_show_all(vlib_main_t *vm, ipsec_main_t *im)
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
ipsec_integ_alg_t integ_alg
static clib_error_t * show_ipsec_sa_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * ipsec_tun_protect_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_sa_add_and_lock(u32 id, u32 spi, ipsec_protocol_t proto, ipsec_crypto_alg_t crypto_alg, const ipsec_key_t *ck, ipsec_integ_alg_t integ_alg, const ipsec_key_t *ik, ipsec_sa_flags_t flags, u32 tx_table_id, u32 salt, const ip46_address_t *tun_src, const ip46_address_t *tun_dst, u32 *sa_out_index)
ip46_address_range_t raddr
static clib_error_t * show_ipsec_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * ipsec_sa_add_del_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)
Bind/attach a SPD to an interface.
static clib_error_t * ipsec_tun_protect_hash_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
Add/Delete a SPD.
static clib_error_t * show_ipsec_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static walk_rc_t ipsec_tun_protect_show_one(index_t itpi, void *ctx)
#define pool_foreach_index(i, v, body)
Iterate pool by index.
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,...)
vl_api_fib_path_nh_proto_t proto
uword * tun4_protect_by_key