FD.io VPP  v20.05.1-5-g09f167997
Vector Packet Processing
ipsec_tun.h
Go to the documentation of this file.
1 /*
2  * ipsec_tun.h : IPSEC tunnel protection
3  *
4  * Copyright (c) 2015 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/ipsec/ipsec.h>
19 
20 /* *INDENT-OFF* */
21 typedef CLIB_PACKED(struct {
22  /*
23  * Key fields: remote ip and spi on incoming packet
24  * all fields in NET byte order
25  */
26  union {
27  struct {
28  ip4_address_t remote_ip;
29  u32 spi;
30  };
31  u64 as_u64;
32  };
33 }) ipsec4_tunnel_key_t;
34 /* *INDENT-ON* */
35 
36 /* *INDENT-OFF* */
37 typedef CLIB_PACKED(struct {
38  /*
39  * Key fields: remote ip and spi on incoming packet
40  * all fields in NET byte order
41  */
42  ip6_address_t remote_ip;
43  u32 spi;
44 }) ipsec6_tunnel_key_t;
45 /* *INDENT-ON* */
46 
47 extern u8 *format_ipsec4_tunnel_key (u8 * s, va_list * args);
48 extern u8 *format_ipsec6_tunnel_key (u8 * s, va_list * args);
49 
51 {
52  IPSEC_PROTECT_L2 = (1 << 0),
54 } __clib_packed ipsec_protect_flags_t;
55 
56 typedef struct ipsec_ep_t_
57 {
58  ip46_address_t src;
59  ip46_address_t dst;
60 } ipsec_ep_t;
61 
62 #define ITP_MAX_N_SA_IN 4
63 
64 typedef struct ipsec_tun_protect_t_
65 {
66  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
68 
69  /* not using a vector since we want the memory inline
70  * with this struct */
72  index_t itp_in_sas[ITP_MAX_N_SA_IN];
73 
75 
77 
78  ipsec_protect_flags_t itp_flags;
79 
81 
83 
85 
86 #define FOR_EACH_IPSEC_PROTECT_INPUT_SAI(_itp, _sai, body) \
87 { \
88  u32 __ii; \
89  for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
90  _sai = itp->itp_in_sas[__ii]; \
91  body; \
92  } \
93 }
94 #define FOR_EACH_IPSEC_PROTECT_INPUT_SA(_itp, _sa, body) \
95 { \
96  u32 __ii; \
97  for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
98  _sa = ipsec_sa_get(itp->itp_in_sas[__ii]); \
99  body; \
100  } \
101 }
102 
104  const ip_address_t * nh,
105  u32 sa_out, u32 sa_in);
107  const ip_address_t * nh,
108  u32 sa_out, u32 * sa_ins);
110  const ip_address_t * nh, u32 sa_in);
112  const ip_address_t * nh, u32 sa_out);
113 
114 extern int ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh);
115 
116 typedef walk_rc_t (*ipsec_tun_protect_walk_cb_t) (index_t itpi, void *arg);
118  void *cttx);
121  void *cttx);
122 
123 extern u8 *format_ipsec_tun_protect (u8 * s, va_list * args);
124 extern u8 *format_ipsec_tun_protect_index (u8 * s, va_list * args);
125 
128 
129 // FIXME
132 
133 /*
134  * DP API
135  */
137 
139 {
140  union
141  {
142  struct
143  {
146  };
148  };
150 
153 {
154  return (pool_elt_at_index (ipsec_tun_protect_pool, index));
155 }
156 
160 {
161  ASSERT (vec_len (ipsec_tun_protect_sa_by_adj_index) > ai);
162  ASSERT (INDEX_INVALID != ipsec_tun_protect_sa_by_adj_index[ai]);
163 
164  return (ipsec_tun_protect_sa_by_adj_index[ai]);
165 }
166 
167 /*
168  * fd.io coding-style-patch-verification: ON
169  *
170  * Local Variables:
171  * eval: (c-set-style "gnu")
172  * End:
173  */
u32 spi
walk_rc_t(* ipsec_tun_protect_walk_cb_t)(index_t itpi, void *arg)
Definition: ipsec_tun.h:116
struct ipsec_tun_lkup_result_t_ ipsec_tun_lkup_result_t
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vlib_node_registration_t ipsec6_tun_input_node
(constructor) VLIB_REGISTER_NODE (ipsec6_tun_input_node)
Definition: ipsec_tun_in.c:390
int ipsec_tun_protect_del(u32 sw_if_index, const ip_address_t *nh)
Definition: ipsec_tun.c:733
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
u64 as_u64
Definition: bihash_doc.h:63
unsigned long u64
Definition: types.h:89
struct ipsec_tun_protect_t_ ipsec_tun_protect_t
int ipsec_tun_protect_update_one(u32 sw_if_index, const ip_address_t *nh, u32 sa_out, u32 sa_in)
Definition: ipsec_tun.c:477
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
unsigned char u8
Definition: types.h:56
enum walk_rc_t_ walk_rc_t
Walk return code.
typedef CLIB_PACKED(struct { union { struct { ip4_address_t remote_ip;u32 spi;};u64 as_u64;};}) ipsec4_tunnel_key_t
ip46_address_t src
Definition: ipsec_tun.h:58
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
u8 * format_ipsec_tun_protect_index(u8 *s, va_list *args)
Definition: ipsec_format.c:343
ipsec_protect_flags_t_
Definition: ipsec_tun.h:50
ipsec_ep_t itp_tun
Definition: ipsec_tun.h:80
unsigned int u32
Definition: types.h:88
u32 sa_in[n_sa_in]
Definition: ipsec.api:252
int ipsec_tun_protect_update_out(u32 sw_if_index, const ip_address_t *nh, u32 sa_out)
Definition: ipsec_tun.c:490
vlib_node_registration_t ipsec4_tun_input_node
(constructor) VLIB_REGISTER_NODE (ipsec4_tun_input_node)
Definition: ipsec_tun_in.c:367
u32 sa_out
Definition: ipsec.api:250
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
static index_t ipsec_tun_protect_get_sa_out(adj_index_t ai)
Definition: ipsec_tun.h:159
int ipsec_tun_protect_update_in(u32 sw_if_index, const ip_address_t *nh, u32 sa_in)
Definition: ipsec_tun.c:539
#define always_inline
Definition: ipsec.h:28
void ipsec_tun_unregister_nodes(ip_address_family_t af)
Definition: ipsec_tun.c:105
u8 * format_ipsec_tun_protect(u8 *s, va_list *args)
Definition: ipsec_format.c:358
u8 * format_ipsec6_tunnel_key(u8 *s, va_list *args)
Definition: ipsec_format.c:396
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
#define ITP_MAX_N_SA_IN
Definition: ipsec_tun.h:62
ipsec_tun_protect_t * ipsec_tun_protect_pool
Pool of tunnel protection objects.
Definition: ipsec_tun.c:33
ip46_address_t dst
Definition: ipsec_tun.h:59
#define ASSERT(truth)
static ipsec_tun_protect_t * ipsec_tun_protect_get(u32 index)
Definition: ipsec_tun.h:152
struct ipsec_ep_t_ ipsec_ep_t
void ipsec_tun_protect_walk(ipsec_tun_protect_walk_cb_t fn, void *cttx)
Definition: ipsec_tun.c:762
void ipsec_tun_register_nodes(ip_address_family_t af)
Definition: ipsec_tun.c:88
u8 * format_ipsec4_tunnel_key(u8 *s, va_list *args)
Definition: ipsec_format.c:383
enum ip_address_family_t_ ip_address_family_t
struct _vlib_node_registration vlib_node_registration_t
void ipsec_tun_protect_walk_itf(u32 sw_if_index, ipsec_tun_protect_walk_cb_t fn, void *cttx)
Definition: ipsec_tun.c:775
ipsec_ep_t itp_crypto
Definition: ipsec_tun.h:76
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
ipsec_protect_flags_t itp_flags
Definition: ipsec_tun.h:78
ip_address_t * itp_key
Definition: ipsec_tun.h:82
index_t * ipsec_tun_protect_sa_by_adj_index
Adj index to TX SA mapping.
Definition: ipsec_tun.c:43
enum ipsec_protect_flags_t_ ipsec_protect_flags_t
int ipsec_tun_protect_update(u32 sw_if_index, const ip_address_t *nh, u32 sa_out, u32 *sa_ins)
Definition: ipsec_tun.c:598