nat.h (11856B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 * 8 */ 9 10 #ifndef __BCM_NAT_H__ 11 #define __BCM_NAT_H__ 12 13 #if defined(INCLUDE_L3) 14 15 #include <bcm/types.h> 16 #include <bcm/l3.h> 17 18 /* L3 NAT definitions. */ 19 #define BCM_L3_NAT_REALM_ID_INVALID -1 /* Invalid NAT realm ID. */ 20 21 /* L3 NAT ingress. */ 22 #define BCM_L3_NAT_INGRESS_DNAT (1 << 0) /* 1: DNAT entry, 0: SNAT 23 entry. */ 24 #define BCM_L3_NAT_INGRESS_DNAT_POOL (1 << 1) /* Indicates DNAT pool entry. */ 25 #define BCM_L3_NAT_INGRESS_TYPE_NAPT (1 << 2) /* 0: Indicates NAT entry. 1: 26 Indicates NAPT entry. */ 27 #define BCM_L3_NAT_INGRESS_RPE (1 << 3) /* Assign internal priority 28 from DNAT entry. */ 29 #define BCM_L3_NAT_INGRESS_DST_DISCARD (1 << 4) /* Discard the packet on DIP 30 match. */ 31 #define BCM_L3_NAT_INGRESS_MULTIPATH (1 << 5) /* Entry is for ECMP. */ 32 #define BCM_L3_NAT_INGRESS_HIT (1 << 6) /* SNAT/DNAT entry match. */ 33 #define BCM_L3_NAT_INGRESS_REPLACE (1 << 7) /* Replace existing entry. */ 34 35 /* L3 NAT egress packet edit flags. */ 36 #define BCM_L3_NAT_EGRESS_SNAT (1 << 0) /* Entry is for SNAT. */ 37 #define BCM_L3_NAT_EGRESS_DNAT (1 << 1) /* Entry is for DNAT. */ 38 #define BCM_L3_NAT_EGRESS_NAPT (1 << 2) /* Entry is for NAPT. */ 39 #define BCM_L3_NAT_EGRESS_REPLACE (1 << 3) /* Replace existing entry. */ 40 #define BCM_L3_NAT_EGRESS_WITH_ID (1 << 4) /* ID is provided. */ 41 42 /* Egress nat table entry specification. */ 43 typedef struct bcm_l3_nat_egress_s { 44 uint32 flags; /* See BCM_L3_NAT_EGRESS_XXX flag definitions. */ 45 bcm_l3_nat_id_t nat_id; /* Index into packet edit table. */ 46 bcm_ip_t sip_addr; /* Translated source IP. */ 47 bcm_ip_t sip_addr_mask; /* Bits of source IP prefix to translate. */ 48 uint16 src_port; /* Source l4 port for NAPT */ 49 bcm_ip_t dip_addr; /* Translated dest IP. */ 50 bcm_ip_t dip_addr_mask; /* Bits of dest IP prefix to translate. */ 51 uint16 dst_port; /* Destination l4 port for NAPT */ 52 bcm_l3_nat_id_t snat_id; /* Key for source and twice NAT/NAPT hash edit 53 table. */ 54 bcm_l3_nat_id_t dnat_id; /* Key for destination and twice NAT/NAPT hash 55 edit table. */ 56 } bcm_l3_nat_egress_t; 57 58 /* 59 * L3 Ingress NAT Structure. 60 * 61 * Contains information required for manipulating either DNAT, DNAT pool 62 * or SNAT table entries. 63 */ 64 typedef struct bcm_l3_nat_ingress_s { 65 uint32 flags; /* See BCM_L3_NAT_INGRESS_XXX flag definitions. */ 66 bcm_ip_t ip_addr; /* IP address to be translated. */ 67 bcm_vrf_t vrf; /* Virtual router instance. */ 68 uint16 l4_port; /* TCP/UDP port. */ 69 uint8 ip_proto; /* IP proto. */ 70 bcm_l3_nat_id_t nat_id; /* nat edit index to use on egress on hit. */ 71 bcm_cos_t pri; /* New priority in packet. */ 72 int class_id; /* Classification lookup class id. */ 73 bcm_if_t nexthop; /* Nexthop of ecmp_ptr depending on MULTIPATH flag 74 setting. */ 75 int realm_id; /* Realm ID for NAT. */ 76 } bcm_l3_nat_ingress_t; 77 78 /* bcm_l3_nat_egress_traverse_cb */ 79 typedef int (*bcm_l3_nat_egress_traverse_cb)( 80 int unit, 81 int index, 82 bcm_l3_nat_egress_t *nat_info, 83 void *user_data); 84 85 /* Initialize a bcm_l3_nat_egress_t structure. */ 86 extern void bcm_l3_nat_egress_t_init( 87 bcm_l3_nat_egress_t *nat_info); 88 89 #ifndef BCM_HIDE_DISPATCHABLE 90 91 /* 92 * Add an egress NAT packet edit entry and return the index in nat_id 93 * field of nat_info structure. If REPLACE flag is specified then use 94 * nat_id field as the location to add the entry. 95 */ 96 extern int bcm_l3_nat_egress_add( 97 int unit, 98 bcm_l3_nat_egress_t *nat_info); 99 100 /* Delete an egress NAT packet edit entry at the specified index nat_id */ 101 extern int bcm_l3_nat_egress_delete( 102 int unit, 103 bcm_l3_nat_id_t nat_id); 104 105 /* 106 * Delete an egress NAT hash entry. BCM_L3_NAT_EGRESS_XXX flags and 107 * corresponding snat_id or dnat_id as hash key must be specified. 108 */ 109 extern int bcm_l3_nat_egress_destroy( 110 int unit, 111 bcm_l3_nat_egress_t *nat_info); 112 113 /* 114 * Retrieve the egress NAT packet edit entry at the specified index in 115 * nat_info structure 116 */ 117 extern int bcm_l3_nat_egress_get( 118 int unit, 119 bcm_l3_nat_egress_t *nat_info); 120 121 /* 122 * Traverse through the egress NAT packet edit table and invoke a user 123 * provided callback for each valid entry. 124 */ 125 extern int bcm_l3_nat_egress_traverse( 126 int unit, 127 uint32 flags, 128 uint32 start, 129 uint32 end, 130 bcm_l3_nat_egress_traverse_cb cb, 131 void *user_data); 132 133 #endif /* BCM_HIDE_DISPATCHABLE */ 134 135 /* L3 NAT statistics maintained per l3 egress nat. */ 136 typedef enum bcm_l3_nat_egress_stat_e { 137 bcmL3NatOutPackets = 0, /* Packets that egress on the l3 Nat nat */ 138 bcmL3NatOutBytes = 1 /* Bytes that egress on the l3 Nat */ 139 } bcm_l3_nat_egress_stat_t; 140 141 #ifndef BCM_HIDE_DISPATCHABLE 142 143 /* Attach counter entries to the given l3 Egress NAT. */ 144 extern int bcm_l3_nat_egress_stat_attach( 145 int unit, 146 bcm_l3_nat_egress_t *info, 147 uint32 stat_counter_id); 148 149 /* Detach counter entries to the given l3 Egress NAT. */ 150 extern int bcm_l3_nat_egress_stat_detach( 151 int unit, 152 bcm_l3_nat_egress_t *info); 153 154 /* Get egress nat counter value for specified l3 Egress NAT */ 155 extern int bcm_l3_nat_egress_stat_counter_get( 156 int unit, 157 bcm_l3_nat_egress_t *info, 158 bcm_l3_nat_egress_stat_t stat, 159 uint32 num_entries, 160 uint32 *counter_indexes, 161 bcm_stat_value_t *counter_values); 162 163 /* Get egress nat counter value for specified l3 Egress NAT */ 164 extern int bcm_l3_nat_egress_stat_counter_sync_get( 165 int unit, 166 bcm_l3_nat_egress_t *info, 167 bcm_l3_nat_egress_stat_t stat, 168 uint32 num_entries, 169 uint32 *counter_indexes, 170 bcm_stat_value_t *counter_values); 171 172 /* Set egress nat counter value for specified l3 Egress NAT */ 173 extern int bcm_l3_nat_egress_stat_counter_set( 174 int unit, 175 bcm_l3_nat_egress_t *info, 176 bcm_l3_nat_egress_stat_t stat, 177 uint32 num_entries, 178 uint32 *counter_indexes, 179 bcm_stat_value_t *counter_values); 180 181 /* Get 64-bit counter value for multiple egress nat statistic types. */ 182 extern int bcm_l3_nat_egress_stat_multi_get( 183 int unit, 184 bcm_l3_nat_egress_t *info, 185 int nstat, 186 bcm_l3_nat_egress_stat_t *stat_arr, 187 uint64 *value_arr); 188 189 /* 190 * Get lower 32-bit counter value for multiple egress nat statistic 191 * types. 192 */ 193 extern int bcm_l3_nat_egress_stat_multi_get32( 194 int unit, 195 bcm_l3_nat_egress_t *info, 196 int nstat, 197 bcm_l3_nat_egress_stat_t *stat_arr, 198 uint32 *value_arr); 199 200 /* Set 64-bit counter value for multiple egress nat statistic types. */ 201 extern int bcm_l3_nat_egress_stat_multi_set( 202 int unit, 203 bcm_l3_nat_egress_t *info, 204 int nstat, 205 bcm_l3_nat_egress_stat_t *stat_arr, 206 uint64 *value_arr); 207 208 /* 209 * Set lower 32-bit counter value for multiple egress nat statistic 210 * types. 211 */ 212 extern int bcm_l3_nat_egress_stat_multi_set32( 213 int unit, 214 bcm_l3_nat_egress_t *info, 215 int nstat, 216 bcm_l3_nat_egress_stat_t *stat_arr, 217 uint32 *value_arr); 218 219 /* Provide stat counter ids associated with given l3 Egress NAT */ 220 extern int bcm_l3_nat_egress_stat_id_get( 221 int unit, 222 bcm_l3_nat_egress_t *info, 223 bcm_l3_nat_egress_stat_t stat, 224 uint32 *stat_counter_id); 225 226 #endif /* BCM_HIDE_DISPATCHABLE */ 227 228 /* bcm_l3_nat_ingress_traverse_cb */ 229 typedef int (*bcm_l3_nat_ingress_traverse_cb)( 230 int unit, 231 int index, 232 bcm_l3_nat_ingress_t *nat_info, 233 void *user_data); 234 235 /* Initialize a bcm_l3_nat_ingress_t structure. */ 236 extern void bcm_l3_nat_ingress_t_init( 237 bcm_l3_nat_ingress_t *nat_info); 238 239 #ifndef BCM_HIDE_DISPATCHABLE 240 241 /* 242 * Add an ingress NAT table entry. Depending on the flags settings an 243 * entry is added to either the ingress DNAT pool table, DNAT session 244 * table or SNAT session table. 245 */ 246 extern int bcm_l3_nat_ingress_add( 247 int unit, 248 bcm_l3_nat_ingress_t *nat_info); 249 250 /* 251 * Delete an ingress NAT table entry. Depending on the flags settings an 252 * entry is deleted from either the ingress DNAT pool table, DNAT session 253 * table or SNAT session table. 254 */ 255 extern int bcm_l3_nat_ingress_delete( 256 int unit, 257 bcm_l3_nat_ingress_t *nat_info); 258 259 /* 260 * Find an ingress NAT table entry. Depending on the flags settings an 261 * entry is searched for in either the ingress DNAT pool table, DNAT 262 * session table or SNAT session table. 263 */ 264 extern int bcm_l3_nat_ingress_find( 265 int unit, 266 bcm_l3_nat_ingress_t *nat_info); 267 268 /* 269 * Delete all entries in an ingress NAT table. Depending on the flags 270 * settings entries are deleted from either the ingress DNAT pool table, 271 * DNAT session table or SNAT session table. 272 */ 273 extern int bcm_l3_nat_ingress_delete_all( 274 int unit, 275 bcm_l3_nat_ingress_t *nat_info); 276 277 /* Run aging on either DNAT session or SNAT session table. */ 278 extern int bcm_l3_nat_ingress_age( 279 int unit, 280 uint32 flags, 281 bcm_l3_nat_ingress_traverse_cb age_cb, 282 void *user_data); 283 284 /* 285 * Traverse through the ingress NAT table specified by flags and invoke a 286 * user provided callback for each valid entry. 287 */ 288 extern int bcm_l3_nat_ingress_traverse( 289 int unit, 290 uint32 flags, 291 uint32 start, 292 uint32 end, 293 bcm_l3_nat_ingress_traverse_cb cb, 294 void *user_data); 295 296 #endif /* BCM_HIDE_DISPATCHABLE */ 297 298 /* Requires BROADCOM_PREMIUM license */ 299 #define BCM_L3_LARGE_NAT_EGRESS_SNAT (1 << 0) /* Entry is for SNAT. */ 300 #define BCM_L3_LARGE_NAT_EGRESS_DNAT (1 << 1) /* Entry is for DNAT. */ 301 #define BCM_L3_LARGE_NAT_EGRESS_NAPT (1 << 2) /* Entry is for NAPT. */ 302 #define BCM_L3_LARGE_NAT_EGRESS_REPLACE (1 << 3) /* Replace existing 303 entry. */ 304 #define BCM_L3_LARGE_NAT_EGRESS_MULTICAST (1 << 4) /* Multicast Entry for 305 Large Scale NAT. */ 306 #define BCM_L3_LARGE_NAT_EGRESS_MACDA_UPDATE (1 << 5) /* Update MACDA on 307 Multicast NAT. */ 308 309 /* Requires BROADCOM_PREMIUM license */ 310 typedef struct bcm_l3_large_nat_egress_s { 311 uint32 flags; 312 bcm_ip_t sip_addr; 313 uint16 src_port; 314 bcm_ip_t dip_addr; 315 uint16 dst_port; 316 int intf_class_id; 317 uint32 nat_class_id; 318 int replication_id; 319 } bcm_l3_large_nat_egress_t; 320 321 /* Requires BROADCOM_PREMIUM license */ 322 typedef int (*bcm_l3_large_nat_egress_traverse_cb)( 323 int unit, 324 bcm_l3_large_nat_egress_t *nat_info, 325 void *user_data); 326 327 /* Requires BROADCOM_PREMIUM license */ 328 extern void bcm_l3_large_nat_egress_t_init( 329 bcm_l3_large_nat_egress_t *nat_info); 330 331 #ifndef BCM_HIDE_DISPATCHABLE 332 333 /* Requires BROADCOM_PREMIUM license */ 334 extern int bcm_l3_large_nat_egress_add( 335 int unit, 336 bcm_l3_large_nat_egress_t *nat_info); 337 338 /* Requires BROADCOM_PREMIUM license */ 339 extern int bcm_l3_large_nat_egress_delete( 340 int unit, 341 bcm_l3_large_nat_egress_t *nat_info); 342 343 /* Requires BROADCOM_PREMIUM license */ 344 extern int bcm_l3_large_nat_egress_get( 345 int unit, 346 bcm_l3_large_nat_egress_t *nat_info); 347 348 /* Requires BROADCOM_PREMIUM license */ 349 extern int bcm_l3_large_nat_egress_traverse( 350 int unit, 351 bcm_l3_large_nat_egress_traverse_cb cb, 352 void *user_data); 353 354 #endif /* defined(INCLUDE_L3) */ 355 356 #endif /* BCM_HIDE_DISPATCHABLE */ 357 358 #endif /* __BCM_NAT_H__ */