45 &sw_if_index, &spd_id))
47 else if (
unformat (line_input,
"del"))
66 .path =
"set interface ipsec spd",
68 "set interface ipsec spd <int> <id>",
79 ip46_address_t tun_src = { }, tun_dst =
95 flags = IPSEC_SA_FLAG_NONE;
97 integ_alg = IPSEC_INTEG_ALG_NONE;
98 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
105 if (
unformat (line_input,
"add %u", &
id))
107 else if (
unformat (line_input,
"del %u", &
id))
109 else if (
unformat (line_input,
"spi %u", &spi))
111 else if (
unformat (line_input,
"salt 0x%x", &salt))
113 else if (
unformat (line_input,
"esp"))
115 else if (
unformat (line_input,
"ah"))
117 else if (
unformat (line_input,
"crypto-key %U",
120 else if (
unformat (line_input,
"crypto-alg %U",
125 else if (
unformat (line_input,
"integ-alg %U",
128 else if (
unformat (line_input,
"tunnel-src %U",
131 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
133 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
135 else if (
unformat (line_input,
"tunnel-dst %U",
138 else if (
unformat (line_input,
"udp-encap"))
139 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
150 &ck, integ_alg, &ik, flags,
151 0, clib_host_to_net_u32 (salt),
152 &tun_src, &tun_dst,
NULL);
169 "ipsec sa [add|del]",
191 else if (
unformat (line_input,
"del"))
193 else if (
unformat (line_input,
"%u", &spd_id))
221 "ipsec spd [add|del] <id>",
235 u32 tmp, tmp2, stat_index;
250 else if (
unformat (line_input,
"del"))
252 else if (
unformat (line_input,
"spd %u", &p.
id))
254 else if (
unformat (line_input,
"inbound"))
256 else if (
unformat (line_input,
"outbound"))
260 else if (
unformat (line_input,
"protocol %u", &tmp))
267 if (p.
policy == IPSEC_POLICY_ACTION_RESOLVE)
275 else if (
unformat (line_input,
"local-ip-range %U - %U",
279 else if (
unformat (line_input,
"remote-ip-range %U - %U",
283 else if (
unformat (line_input,
"local-ip-range %U - %U",
289 else if (
unformat (line_input,
"remote-ip-range %U - %U",
295 else if (
unformat (line_input,
"local-port-range %u - %u", &tmp, &tmp2))
301 if (
unformat (line_input,
"remote-port-range %u - %u", &tmp, &tmp2))
319 " outboud:%s %s action:%U",
320 (is_outbound ?
"yes" :
"no"),
341 .path =
"ipsec policy",
343 "ipsec policy [add|del] spd <id> priority <n> ",
355 vlib_cli_output(vm,
"%U", format_ipsec_sa, sai,
356 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
368 vlib_cli_output(vm,
"%U", format_ipsec_spd, spdi);
383 spd = pool_elt_at_index (im->spds, spd_id);
384 vlib_cli_output (vm,
" %d -> %U", spd->id,
385 format_vnet_sw_if_index_name, im->vnet_main,
421 .path =
"show ipsec all",
422 .short_help =
"show ipsec all",
490 .path =
"show ipsec sa",
491 .short_help =
"show ipsec sa [index]",
496 .path =
"clear ipsec sa",
497 .short_help =
"clear ipsec sa [index]",
507 u8 show_bindings = 0;
514 else if (
unformat (input,
"bindings"))
532 .path =
"show ipsec spd",
533 .short_help =
"show ipsec spd [index]",
550 .path =
"show ipsec tunnel",
551 .short_help =
"show ipsec tunnel",
564 (void)
unformat (input,
"verbose %u", &verbose);
567 u8 *s =
format (
NULL,
"%=25s %=25s %=10s\n",
"Name",
"Index",
"Active");
571 s = format (s,
"%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
572 ab - im->ah_backends == im->ah_current_backend ?
"yes" :
"no");
575 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
576 s = format (s,
" enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
577 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
578 s = format (s,
" dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
579 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
580 s = format (s,
" enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
581 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
582 s = format (s,
" dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
589 s =
format (s,
"%=25s %=25s %=10s\n",
"Name",
"Index",
"Active");
593 s = format (s,
"%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
594 eb - im->esp_backends == im->esp_current_backend ?
"yes" 598 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
599 s = format (s,
" enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
600 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
601 s = format (s,
" dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
602 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
603 s = format (s,
" enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
604 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
605 s = format (s,
" dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
617 .path =
"show ipsec backends",
618 .short_help =
"show ipsec backends",
644 if (
unformat (line_input,
"%u", &backend_index))
658 else if (
unformat (line_input,
"esp"))
660 if (
unformat (line_input,
"%u", &backend_index))
685 .path =
"ipsec select backend",
686 .short_help =
"ipsec select backend <ah|esp> <backend index>",
705 .path =
"clear ipsec counters",
706 .short_help =
"clear ipsec counters",
714 return (0x80000000 | ti);
720 return (0xc0000000 | ti);
748 flags = IPSEC_SA_FLAG_NONE;
771 else if (
unformat (line_input,
"local-spi %u", &local_spi))
773 else if (
unformat (line_input,
"remote-spi %u", &remote_spi))
775 else if (
unformat (line_input,
"salt 0x%x", &salt))
777 else if (
unformat (line_input,
"udp-encap"))
778 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
779 else if (
unformat (line_input,
"use-esn"))
780 flags |= IPSEC_SA_FLAG_USE_ESN;
781 else if (
unformat (line_input,
"use-anti-replay"))
782 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
783 else if (
unformat (line_input,
"instance %u", &instance))
785 else if (
unformat (line_input,
"tx-table %u", &table_id))
795 else if (
unformat (line_input,
"crypto-alg %U",
806 else if (
unformat (line_input,
"integ-alg %U",
809 else if (
unformat (line_input,
"del"))
825 if (ipv4_set && ipv6_set)
832 rv = VNET_API_ERROR_NO_SUCH_FIB;
844 instance, &local_ip, &remote_ip, fib_index,
845 IPIP_TUNNEL_FLAG_NONE, IP_DSCP_CS0, &sw_if_index);
849 &lck, integ_alg, &lik, flags, table_id,
850 clib_host_to_net_u32 (salt), &local_ip,
855 &rck, integ_alg, &rik,
856 (flags | IPSEC_SA_FLAG_IS_INBOUND), table_id,
857 clib_host_to_net_u32 (salt), &remote_ip,
872 case VNET_API_ERROR_INVALID_VALUE:
874 "IPSec tunnel interface already exists...");
890 .path =
"create ipsec tunnel",
891 .short_help =
"create ipsec tunnel local-ip <addr> local-spi <spi> " 892 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] " 893 "[tx-table <table-id>]",
917 else if (
unformat (line_input,
"add"))
919 else if (
unformat (line_input,
"sa-in %d", &sa_in))
921 else if (
unformat (line_input,
"sa-out %d", &sa_out))
923 else if (
unformat (line_input,
"%U",
944 .path =
"ipsec tunnel protect",
946 .short_help =
"ipsec tunnel protect <interface> input-sa <SA> output-sa <SA>",
967 .path =
"show ipsec protect",
969 .short_help =
"show ipsec protect",
982 ipsec4_tunnel_key_t
key;
989 vlib_cli_output (vm,
" %U", format_ipsec4_tunnel_key, &key);
990 vlib_cli_output (vm,
" tun:%d sa:%d", value.tun_index, value.sa_index);
997 ipsec6_tunnel_key_t *
key;
1004 vlib_cli_output (vm,
" %U", format_ipsec6_tunnel_key, key);
1005 vlib_cli_output (vm,
" tun:%d sa:%d", value.tun_index, value.sa_index);
1019 .path =
"show ipsec protect-hash",
1021 .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)
uword * tun6_protect_by_key
static u32 ipsec_tun_mk_local_sa_id(u32 ti)
vnet_main_t * vnet_get_main(void)
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, ipip_tunnel_flags_t flags, ip_dscp_t dscp, u32 *sw_if_indexp)
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).
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.
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
void ipsec_tun_protect_walk(ipsec_tun_protect_walk_cb_t fn, void *ctx)
static void ipsec_tunnel_show_all(vlib_main_t *vm)
uword * spd_index_by_sw_if_index
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)
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
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)
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.
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 fib_protocol_t fib_ip_proto(bool is_ip6)
Convert from boolean is_ip6 to FIB protocol.
static u32 ipsec_tun_mk_remote_sa_id(u32 ti)
static clib_error_t * show_ipsec_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ipsec_tun_protect_update_one(u32 sw_if_index, u32 sa_out, u32 sa_in)
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,...)
#define ip46_address_initializer
uword * tun4_protect_by_key