blob: 8b78939cafabfe85dbfc34df1ae000884deb8028 [file] [log] [blame]
Neale Ranns999c8ee2019-02-01 03:31:24 -08001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef __IPSEC_SPD_POLICY_H__
16#define __IPSEC_SPD_POLICY_H__
17
Piotr Bronowskid699a342022-05-10 09:08:47 +000018#include <vppinfra/bihash_40_8.h>
19#include <vppinfra/bihash_16_8.h>
Neale Ranns9f231d42019-03-19 10:06:00 +000020#include <vnet/ipsec/ipsec_spd.h>
Piotr Bronowskid699a342022-05-10 09:08:47 +000021/**
22 * calculated as max number of flows (2^10) divided by KVP_PER_PAGE (4)
23 */
24#define IPSEC_FP_HASH_LOOKUP_HASH_BUCKETS (1 << 8)
Neale Ranns999c8ee2019-02-01 03:31:24 -080025
Piotr Bronowski815c6a42022-06-09 09:09:28 +000026#define IPSEC_POLICY_PROTOCOL_ANY IP_PROTOCOL_RESERVED
27
Neale Ranns999c8ee2019-02-01 03:31:24 -080028#define foreach_ipsec_policy_action \
29 _ (0, BYPASS, "bypass") \
30 _ (1, DISCARD, "discard") \
31 _ (2, RESOLVE, "resolve") \
32 _ (3, PROTECT, "protect")
33
34typedef enum
35{
36#define _(v, f, s) IPSEC_POLICY_ACTION_##f = v,
37 foreach_ipsec_policy_action
38#undef _
39} ipsec_policy_action_t;
40
41#define IPSEC_POLICY_N_ACTION (IPSEC_POLICY_ACTION_PROTECT + 1)
42
43typedef struct
44{
45 ip46_address_t start, stop;
46} ip46_address_range_t;
47
48typedef struct
49{
50 u16 start, stop;
51} port_range_t;
52
53/**
Neale Rannsa09c1ff2019-02-04 01:10:30 -080054 * @brief
55 * Policy packet & bytes counters
56 */
57extern vlib_combined_counter_main_t ipsec_spd_policy_counters;
58
59/**
Neale Ranns999c8ee2019-02-01 03:31:24 -080060 * @brief A Secruity Policy. An entry in an SPD
61 */
62typedef struct ipsec_policy_t_
63{
64 u32 id;
65 i32 priority;
Neale Ranns9f231d42019-03-19 10:06:00 +000066
67 // the type of policy
68 ipsec_spd_policy_type_t type;
Neale Ranns999c8ee2019-02-01 03:31:24 -080069
70 // Selector
71 u8 is_ipv6;
72 ip46_address_range_t laddr;
73 ip46_address_range_t raddr;
74 u8 protocol;
75 port_range_t lport;
76 port_range_t rport;
77
78 // Policy
79 ipsec_policy_action_t policy;
80 u32 sa_id;
81 u32 sa_index;
Neale Ranns999c8ee2019-02-01 03:31:24 -080082} ipsec_policy_t;
83
84/**
85 * @brief Add/Delete a SPD
86 */
87extern int ipsec_add_del_policy (vlib_main_t * vm,
Neale Rannsa09c1ff2019-02-04 01:10:30 -080088 ipsec_policy_t * policy,
89 int is_add, u32 * stat_index);
Neale Ranns999c8ee2019-02-01 03:31:24 -080090
Neale Rannsa09c1ff2019-02-04 01:10:30 -080091extern u8 *format_ipsec_policy (u8 * s, va_list * args);
Neale Ranns999c8ee2019-02-01 03:31:24 -080092extern u8 *format_ipsec_policy_action (u8 * s, va_list * args);
93extern uword unformat_ipsec_policy_action (unformat_input_t * input,
94 va_list * args);
95
96
Neale Ranns9f231d42019-03-19 10:06:00 +000097extern int ipsec_policy_mk_type (bool is_outbound,
98 bool is_ipv6,
99 ipsec_policy_action_t action,
100 ipsec_spd_policy_type_t * type);
101
Piotr Bronowskid699a342022-05-10 09:08:47 +0000102/* A 5-tuple used to calculate the bihash entry */
103typedef union
104{
105 struct
106 {
107 union
108 {
109 struct
110 {
111 u32 l3_zero_pad[6];
112 ip4_address_t laddr;
113 ip4_address_t raddr;
114 };
115 ip6_address_t ip6_laddr;
116 ip6_address_t ip6_raddr;
117 };
118
119 u16 lport;
120 u16 rport;
121 u16 protocol;
122 u16 is_ipv6;
123 };
124 /* for ipv6 */
125 clib_bihash_kv_40_8_t kv_40_8;
126 /* for ipv4 */
127 struct
128 {
129 u64 padding_for_kv_16_8[3];
130 clib_bihash_kv_16_8_t kv_16_8;
131 };
132} ipsec_fp_5tuple_t;
133
134/*
135 * An element describing a particular policy mask,
136 * and refcount of policies with same mask.
137 */
138typedef struct
139{
140 /** Required for pool_get_aligned */
141 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
142 ipsec_fp_5tuple_t mask;
143 u32 refcount; /* counts how many policies use this mask */
144} ipsec_fp_mask_type_entry_t;
145
146/*
147 * Bihash lookup value,
148 * contains an unordered vector of policies indices in policy pool.
149 */
150typedef union
151{
152 u64 as_u64;
153 struct
154 {
155 u32 *fp_policies_ids;
156 };
157} ipsec_fp_lookup_value_t;
158
Neale Ranns999c8ee2019-02-01 03:31:24 -0800159#endif /* __IPSEC_SPD_POLICY_H__ */
160
161/*
162 * fd.io coding-style-patch-verification: ON
163 *
164 * Local Variables:
165 * eval: (c-set-style "gnu")
166 * End:
167 */