Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 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 | typedef enum ipsec_protect_flags_t_ |
| 21 | { |
| 22 | IPSEC_PROTECT_L2 = (1 << 0), |
| 23 | IPSEC_PROTECT_ENCAPED = (1 << 1), |
| 24 | } __clib_packed ipsec_protect_flags_t; |
| 25 | |
| 26 | typedef struct ipsec_ep_t_ |
| 27 | { |
| 28 | ip46_address_t src; |
| 29 | ip46_address_t dst; |
| 30 | } ipsec_ep_t; |
| 31 | |
| 32 | typedef struct ipsec_tun_protect_t_ |
| 33 | { |
| 34 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 35 | u32 itp_out_sa; |
| 36 | |
| 37 | /* not using a vector since we want the memory inline |
| 38 | * with this struct */ |
| 39 | u32 itp_n_sa_in; |
| 40 | u32 itp_in_sas[4]; |
| 41 | |
| 42 | u32 itp_sw_if_index; |
| 43 | |
| 44 | ipsec_ep_t itp_crypto; |
| 45 | |
| 46 | ipsec_protect_flags_t itp_flags; |
| 47 | |
| 48 | ipsec_ep_t itp_tun; |
| 49 | |
| 50 | } ipsec_tun_protect_t; |
| 51 | |
| 52 | #define FOR_EACH_IPSEC_PROTECT_INPUT_SAI(_itp, _sai, body) \ |
| 53 | { \ |
| 54 | u32 __ii; \ |
| 55 | for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \ |
| 56 | _sai = itp->itp_in_sas[__ii]; \ |
| 57 | body; \ |
| 58 | } \ |
| 59 | } |
| 60 | #define FOR_EACH_IPSEC_PROTECT_INPUT_SA(_itp, _sa, body) \ |
| 61 | { \ |
| 62 | u32 __ii; \ |
| 63 | for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \ |
| 64 | _sa = ipsec_sa_get(itp->itp_in_sas[__ii]); \ |
| 65 | body; \ |
| 66 | } \ |
| 67 | } |
| 68 | |
| 69 | extern int ipsec_tun_protect_update (u32 sw_if_index, u32 sa_out, |
| 70 | u32 sa_ins[2]); |
| 71 | extern int ipsec_tun_protect_del (u32 sw_if_index); |
| 72 | |
| 73 | typedef walk_rc_t (*ipsec_tun_protect_walk_cb_t) (index_t itpi, void *arg); |
| 74 | extern void ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn, |
| 75 | void *cttx); |
| 76 | extern index_t ipsec_tun_protect_find (u32 sw_if_index); |
| 77 | |
| 78 | extern u8 *format_ipsec_tun_protect (u8 * s, va_list * args); |
| 79 | |
| 80 | // FIXME |
| 81 | extern vlib_node_registration_t ipsec4_tun_input_node; |
| 82 | extern vlib_node_registration_t ipsec6_tun_input_node; |
| 83 | |
| 84 | /* |
| 85 | * DP API |
| 86 | */ |
| 87 | extern ipsec_tun_protect_t *ipsec_protect_pool; |
| 88 | |
| 89 | typedef struct ipsec_tun_lkup_result_t_ |
| 90 | { |
| 91 | union |
| 92 | { |
| 93 | struct |
| 94 | { |
| 95 | u32 tun_index; |
| 96 | u32 sa_index; |
| 97 | }; |
| 98 | u64 as_u64; |
| 99 | }; |
| 100 | } ipsec_tun_lkup_result_t; |
| 101 | |
| 102 | always_inline ipsec_tun_protect_t * |
| 103 | ipsec_tun_protect_get (u32 index) |
| 104 | { |
| 105 | return (pool_elt_at_index (ipsec_protect_pool, index)); |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * fd.io coding-style-patch-verification: ON |
| 110 | * |
| 111 | * Local Variables: |
| 112 | * eval: (c-set-style "gnu") |
| 113 | * End: |
| 114 | */ |