NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
policy.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
96 #ifndef POLICY_H_
97 #define POLICY_H_
98 
99 #include <sys/un.h>
100 
101 #include "flow_encrypt.h"
102 #include "flow_decrypt.h"
103 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 
108 #define MAX_IP_ADDR_LEN (INET6_ADDRSTRLEN) /* Maximal IP address size */
109 #define POLICY_DIR_IN (0) /* Ingress traffic */
110 #define POLICY_DIR_OUT (1) /* Egress traffic */
111 #define POLICY_MODE_TRANSPORT (0) /* Policy transport mode */
112 #define POLICY_MODE_TUNNEL (1) /* Policy tunnel mode */
113 #define POLICY_L3_TYPE_IPV4 (4) /* Policy L3 type IPV4 */
114 #define POLICY_L3_TYPE_IPV6 (6) /* Policy L3 type IPV6 */
115 #define POLICY_L4_TYPE_UDP (IPPROTO_UDP) /* Policy L4 type UDP */
116 #define POLICY_L4_TYPE_TCP (IPPROTO_TCP) /* Policy L4 type TCP */
117 #define POLICY_KEY_TYPE_128 (0) /* Policy key type 128 */
118 #define POLICY_KEY_TYPE_256 (1) /* Policy key type 256 */
119 #define POLICY_RECORD_MIN_SIZE (224) /* Record size for Key of 16 bytes */
120 #define POLICY_RECORD_MAX_SIZE (240) /* Record size for Key of 32 bytes */
121 
122 /* Policy struct */
124  /* Protocols attributes */
125  uint16_t src_port; /* Policy inner source port */
126  uint16_t dst_port; /* Policy inner destination port */
127  uint8_t l3_protocol; /* Policy L3 proto {POLICY_L3_TYPE_IPV4, POLICY_L3_TYPE_IPV6} */
128  uint8_t l4_protocol; /* Policy L4 proto {POLICY_L4_TYPE_UDP, POLICY_L4_TYPE_TCP} */
129  uint8_t outer_l3_protocol; /* Policy outer L3 type {POLICY_L3_TYPE_IPV4, POLICY_L3_TYPE_IPV6} */
130 
131  /* Policy attributes */
132  uint8_t policy_direction; /* Policy direction {POLICY_DIR_IN, POLICY_DIR_OUT} */
133  uint8_t policy_mode; /* Policy IPSEC mode {POLICY_MODE_TRANSPORT, POLICY_MODE_TUNNEL} */
134 
135  /* Security Association attributes */
136  uint8_t esn; /* Is ESN enabled? */
137  uint8_t icv_length; /* ICV length in bytes {8, 12, 16} */
138  uint8_t key_type; /* AES key type {POLICY_KEY_TYPE_128, POLICY_KEY_TYPE_256} */
139  uint32_t spi; /* Security Parameter Index */
140  uint32_t salt; /* Cryptographic salt */
141  uint8_t enc_key_data[MAX_KEY_LEN]; /* Encryption key (binary) */
142 
143  /* Policy inner and outer addresses */
144  char src_ip_addr[MAX_IP_ADDR_LEN + 1]; /* Policy inner IP source address in string format */
145  char dst_ip_addr[MAX_IP_ADDR_LEN + 1]; /* Policy inner IP destination address in string format */
146  char outer_src_ip[MAX_IP_ADDR_LEN + 1]; /* Policy outer IP source address in string format */
147  char outer_dst_ip[MAX_IP_ADDR_LEN + 1]; /* Policy outer IP destination address in string format */
148 };
149 
150 /*
151  * Print policy attributes
152  *
153  * @policy [in]: application IPSEC policy
154  */
156 
157 /*
158  * Handle encrypt policy, function logic includes:
159  * - parsing the new policy and create encrypt rule structure
160  * - create suitable security association
161  * - add DOCA flow entry which describes the encrypt rule
162  *
163  * @app_cfg [in]: application configuration structure
164  * @ports [in]: DOCA flow ports array
165  * @policy [in]: new policy
166  * @rule [out]: encrypt rule structure
167  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
168  */
171  struct ipsec_security_gw_ipsec_policy *policy,
172  struct encrypt_rule *rule);
173 
174 /*
175  * Handle decrypt policy, function logic includes:
176  * - parsing the new policy and create decrypt rule structure
177  * - create suitable security association
178  * - add DOCA flow entry which describes the decrypt rule
179  *
180  * @app_cfg [in]: application configuration structure
181  * @secured_port [in]: DOCA flow port for secured port
182  * @policy [in]: new policy
183  * @rule [out]: encrypt rule structure
184  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
185  */
187  struct doca_flow_port *secured_port,
188  struct ipsec_security_gw_ipsec_policy *policy,
189  struct decrypt_rule *rule);
190 
191 #ifdef __cplusplus
192 } /* extern "C" */
193 #endif
194 
195 #endif /* POLICY_H_ */
static struct app_gpu_cfg app_cfg
enum doca_error doca_error_t
DOCA API return codes.
#define MAX_KEY_LEN
Definition: ipsec_ctx.h:42
doca_error_t ipsec_security_gw_handle_decrypt_policy(struct ipsec_security_gw_config *app_cfg, struct doca_flow_port *secured_port, struct ipsec_security_gw_ipsec_policy *policy, struct decrypt_rule *rule)
Definition: policy.c:269
void print_policy_attrs(struct ipsec_security_gw_ipsec_policy *policy)
Definition: policy.c:296
#define MAX_IP_ADDR_LEN
Definition: policy.h:108
doca_error_t ipsec_security_gw_handle_encrypt_policy(struct ipsec_security_gw_config *app_cfg, struct ipsec_security_gw_ports_map *ports[], struct ipsec_security_gw_ipsec_policy *policy, struct encrypt_rule *rule)
Definition: policy.c:244
char dst_ip_addr[MAX_IP_ADDR_LEN+1]
Definition: policy.h:145
uint8_t enc_key_data[MAX_KEY_LEN]
Definition: policy.h:141
char outer_dst_ip[MAX_IP_ADDR_LEN+1]
Definition: policy.h:147
char outer_src_ip[MAX_IP_ADDR_LEN+1]
Definition: policy.h:146
char src_ip_addr[MAX_IP_ADDR_LEN+1]
Definition: policy.h:144
static struct doca_flow_port * ports[FLOW_SWITCH_PORTS_MAX]
Definition: switch_core.c:42