blob: 863afdbba5acdd90f8d4d76c6dcccc5f94dd0958 [file] [log] [blame]
Neale Rannsc87b66c2019-02-07 07:26:12 -08001/*
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
Neale Ranns12989b52019-09-26 16:20:19 +000020/* *INDENT-OFF* */
21typedef 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* */
37typedef 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
47extern u8 *format_ipsec4_tunnel_key (u8 * s, va_list * args);
48extern u8 *format_ipsec6_tunnel_key (u8 * s, va_list * args);
49
Neale Rannsc87b66c2019-02-07 07:26:12 -080050typedef enum ipsec_protect_flags_t_
51{
52 IPSEC_PROTECT_L2 = (1 << 0),
53 IPSEC_PROTECT_ENCAPED = (1 << 1),
54} __clib_packed ipsec_protect_flags_t;
55
56typedef struct ipsec_ep_t_
57{
58 ip46_address_t src;
59 ip46_address_t dst;
60} ipsec_ep_t;
61
62typedef struct ipsec_tun_protect_t_
63{
64 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Neale Ranns495d7ff2019-07-12 09:15:26 +000065 index_t itp_out_sa;
Neale Rannsc87b66c2019-02-07 07:26:12 -080066
67 /* not using a vector since we want the memory inline
68 * with this struct */
69 u32 itp_n_sa_in;
Neale Ranns495d7ff2019-07-12 09:15:26 +000070 index_t itp_in_sas[4];
Neale Rannsc87b66c2019-02-07 07:26:12 -080071
72 u32 itp_sw_if_index;
73
74 ipsec_ep_t itp_crypto;
75
76 ipsec_protect_flags_t itp_flags;
77
78 ipsec_ep_t itp_tun;
79
Neale Ranns28287212019-12-16 00:53:11 +000080 ip_address_t *itp_key;
81
Neale Rannsc87b66c2019-02-07 07:26:12 -080082} ipsec_tun_protect_t;
83
84#define FOR_EACH_IPSEC_PROTECT_INPUT_SAI(_itp, _sai, body) \
85{ \
86 u32 __ii; \
87 for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
88 _sai = itp->itp_in_sas[__ii]; \
89 body; \
90 } \
91}
92#define FOR_EACH_IPSEC_PROTECT_INPUT_SA(_itp, _sa, body) \
93{ \
94 u32 __ii; \
95 for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
96 _sa = ipsec_sa_get(itp->itp_in_sas[__ii]); \
97 body; \
98 } \
99}
100
Neale Ranns28287212019-12-16 00:53:11 +0000101extern int ipsec_tun_protect_update_one (u32 sw_if_index,
102 const ip_address_t * nh,
103 u32 sa_out, u32 sa_in);
104extern int ipsec_tun_protect_update (u32 sw_if_index,
105 const ip_address_t * nh,
106 u32 sa_out, u32 * sa_ins);
107extern int ipsec_tun_protect_update_in (u32 sw_if_index,
108 const ip_address_t * nh, u32 sa_in);
109extern int ipsec_tun_protect_update_out (u32 sw_if_index,
110 const ip_address_t * nh, u32 sa_out);
Neale Ranns12989b52019-09-26 16:20:19 +0000111
Neale Ranns28287212019-12-16 00:53:11 +0000112extern int ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800113
114typedef walk_rc_t (*ipsec_tun_protect_walk_cb_t) (index_t itpi, void *arg);
115extern void ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn,
116 void *cttx);
Neale Ranns28287212019-12-16 00:53:11 +0000117extern void ipsec_tun_protect_walk_itf (u32 sw_if_index,
118 ipsec_tun_protect_walk_cb_t fn,
119 void *cttx);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800120
121extern u8 *format_ipsec_tun_protect (u8 * s, va_list * args);
Neale Ranns28287212019-12-16 00:53:11 +0000122extern u8 *format_ipsec_tun_protect_index (u8 * s, va_list * args);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800123
Neale Ranns8d6d74c2020-02-20 09:45:16 +0000124extern void ipsec_tun_register_nodes (ip_address_family_t af);
125extern void ipsec_tun_unregister_nodes (ip_address_family_t af);
126
Neale Rannsc87b66c2019-02-07 07:26:12 -0800127// FIXME
128extern vlib_node_registration_t ipsec4_tun_input_node;
129extern vlib_node_registration_t ipsec6_tun_input_node;
130
131/*
132 * DP API
133 */
Neale Ranns28287212019-12-16 00:53:11 +0000134extern ipsec_tun_protect_t *ipsec_tun_protect_pool;
Neale Rannsc87b66c2019-02-07 07:26:12 -0800135
136typedef struct ipsec_tun_lkup_result_t_
137{
138 union
139 {
140 struct
141 {
142 u32 tun_index;
143 u32 sa_index;
144 };
145 u64 as_u64;
146 };
147} ipsec_tun_lkup_result_t;
148
149always_inline ipsec_tun_protect_t *
150ipsec_tun_protect_get (u32 index)
151{
Neale Ranns28287212019-12-16 00:53:11 +0000152 return (pool_elt_at_index (ipsec_tun_protect_pool, index));
153}
154
155extern index_t *ipsec_tun_protect_sa_by_adj_index;
156always_inline index_t
157ipsec_tun_protect_get_sa_out (adj_index_t ai)
158{
159 ASSERT (vec_len (ipsec_tun_protect_sa_by_adj_index) > ai);
160 ASSERT (INDEX_INVALID != ipsec_tun_protect_sa_by_adj_index[ai]);
161
162 return (ipsec_tun_protect_sa_by_adj_index[ai]);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800163}
164
165/*
166 * fd.io coding-style-patch-verification: ON
167 *
168 * Local Variables:
169 * eval: (c-set-style "gnu")
170 * End:
171 */