nat.h (12001B)
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 * DO NOT EDIT THIS FILE! 9 * This file is auto-generated. 10 * Edits to this file will be lost when it is regenerated. 11 */ 12 13 #ifndef __BCM_NAT_H__ 14 #define __BCM_NAT_H__ 15 16 #if defined(INCLUDE_L3) 17 18 #include <bcm/types.h> 19 #include <bcm/l3.h> 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_egress_t; 53 54 /* 55 * L3 Ingress NAT Structure. 56 * 57 * Contains information required for manipulating either DNAT, DNAT pool 58 * or SNAT table entries. 59 */ 60 typedef struct bcm_l3_nat_ingress_s { 61 uint32 flags; /* See BCM_L3_NAT_INGRESS_XXX flag definitions. */ 62 bcm_ip_t ip_addr; /* IP address to be translated. */ 63 bcm_vrf_t vrf; /* Virtual router instance. */ 64 uint16 l4_port; /* TCP/UDP port. */ 65 uint8 ip_proto; /* IP proto. */ 66 bcm_l3_nat_id_t nat_id; /* nat edit index to use on egress on hit. */ 67 bcm_cos_t pri; /* New priority in packet. */ 68 int class_id; /* Classification lookup class id. */ 69 bcm_if_t nexthop; /* Nexthop of ecmp_ptr depending on MULTIPATH flag 70 setting. */ 71 } bcm_l3_nat_ingress_t; 72 73 /* bcm_l3_nat_egress_traverse_cb */ 74 typedef int (*bcm_l3_nat_egress_traverse_cb)( 75 int unit, 76 int index, 77 bcm_l3_nat_egress_t *nat_info, 78 void *user_data); 79 80 /* Initialize a bcm_l3_nat_egress_t structure. */ 81 extern void bcm_l3_nat_egress_t_init( 82 bcm_l3_nat_egress_t *nat_info); 83 84 #ifndef BCM_HIDE_DISPATCHABLE 85 86 /* 87 * Add an egress NAT packet edit entry and return the index in nat_id 88 * field of nat_info structure. If REPLACE flag is specified then use 89 * nat_id field as the location to add the entry. 90 */ 91 extern int bcm_l3_nat_egress_add( 92 int unit, 93 bcm_l3_nat_egress_t *nat_info); 94 95 /* Delete an egress NAT packet edit entry at the specified index nat_id */ 96 extern int bcm_l3_nat_egress_delete( 97 int unit, 98 bcm_l3_nat_id_t nat_id); 99 100 /* 101 * Retrieve the egress NAT packet edit entry at the specified index in 102 * nat_info structure 103 */ 104 extern int bcm_l3_nat_egress_get( 105 int unit, 106 bcm_l3_nat_egress_t *nat_info); 107 108 /* 109 * Traverse through the egress NAT packet edit table and invoke a user 110 * provided callback for each valid entry. 111 */ 112 extern int bcm_l3_nat_egress_traverse( 113 int unit, 114 uint32 flags, 115 uint32 start, 116 uint32 end, 117 bcm_l3_nat_egress_traverse_cb cb, 118 void *user_data); 119 120 #endif /* BCM_HIDE_DISPATCHABLE */ 121 122 /* L3 NAT statistics maintained per l3 egress nat. */ 123 typedef enum bcm_l3_nat_egress_stat_e { 124 bcmL3NatOutPackets = 0, /* Packets that egress on the l3 Nat nat */ 125 bcmL3NatOutBytes = 1 /* Bytes that egress on the l3 Nat */ 126 } bcm_l3_nat_egress_stat_t; 127 128 #ifndef BCM_HIDE_DISPATCHABLE 129 130 /* Attach counter entries to the given l3 Egress NAT. */ 131 extern int bcm_l3_nat_egress_stat_attach( 132 int unit, 133 bcm_l3_nat_egress_t *info, 134 uint32 stat_counter_id); 135 136 /* Detach counter entries to the given l3 Egress NAT. */ 137 extern int bcm_l3_nat_egress_stat_detach( 138 int unit, 139 bcm_l3_nat_egress_t *info); 140 141 /* Get egress nat counter value for specified l3 Egress NAT */ 142 extern int bcm_l3_nat_egress_stat_counter_get( 143 int unit, 144 bcm_l3_nat_egress_t *info, 145 bcm_l3_nat_egress_stat_t stat, 146 uint32 num_entries, 147 uint32 *counter_indexes, 148 bcm_stat_value_t *counter_values); 149 150 /* Get egress nat counter value for specified l3 Egress NAT */ 151 extern int bcm_l3_nat_egress_stat_counter_sync_get( 152 int unit, 153 bcm_l3_nat_egress_t *info, 154 bcm_l3_nat_egress_stat_t stat, 155 uint32 num_entries, 156 uint32 *counter_indexes, 157 bcm_stat_value_t *counter_values); 158 159 /* Set egress nat counter value for specified l3 Egress NAT */ 160 extern int bcm_l3_nat_egress_stat_counter_set( 161 int unit, 162 bcm_l3_nat_egress_t *info, 163 bcm_l3_nat_egress_stat_t stat, 164 uint32 num_entries, 165 uint32 *counter_indexes, 166 bcm_stat_value_t *counter_values); 167 168 /* Get 64-bit counter value for multiple egress nat statistic types. */ 169 extern int bcm_l3_nat_egress_stat_multi_get( 170 int unit, 171 bcm_l3_nat_egress_t *info, 172 int nstat, 173 bcm_l3_nat_egress_stat_t *stat_arr, 174 uint64 *value_arr); 175 176 /* 177 * Get lower 32-bit counter value for multiple egress nat statistic 178 * types. 179 */ 180 extern int bcm_l3_nat_egress_stat_multi_get32( 181 int unit, 182 bcm_l3_nat_egress_t *info, 183 int nstat, 184 bcm_l3_nat_egress_stat_t *stat_arr, 185 uint32 *value_arr); 186 187 /* Set 64-bit counter value for multiple egress nat statistic types. */ 188 extern int bcm_l3_nat_egress_stat_multi_set( 189 int unit, 190 bcm_l3_nat_egress_t *info, 191 int nstat, 192 bcm_l3_nat_egress_stat_t *stat_arr, 193 uint64 *value_arr); 194 195 /* 196 * Set lower 32-bit counter value for multiple egress nat statistic 197 * types. 198 */ 199 extern int bcm_l3_nat_egress_stat_multi_set32( 200 int unit, 201 bcm_l3_nat_egress_t *info, 202 int nstat, 203 bcm_l3_nat_egress_stat_t *stat_arr, 204 uint32 *value_arr); 205 206 /* Provide stat counter ids associated with given l3 Egress NAT */ 207 extern int bcm_l3_nat_egress_stat_id_get( 208 int unit, 209 bcm_l3_nat_egress_t *info, 210 bcm_l3_nat_egress_stat_t stat, 211 uint32 *stat_counter_id); 212 213 #endif /* BCM_HIDE_DISPATCHABLE */ 214 215 /* bcm_l3_nat_ingress_traverse_cb */ 216 typedef int (*bcm_l3_nat_ingress_traverse_cb)( 217 int unit, 218 int index, 219 bcm_l3_nat_ingress_t *nat_info, 220 void *user_data); 221 222 /* Initialize a bcm_l3_nat_ingress_t structure. */ 223 extern void bcm_l3_nat_ingress_t_init( 224 bcm_l3_nat_ingress_t *nat_info); 225 226 #ifndef BCM_HIDE_DISPATCHABLE 227 228 /* 229 * Add an ingress NAT table entry. Depending on the flags settings an 230 * entry is added to either the ingress DNAT pool table, DNAT session 231 * table or SNAT session table. 232 */ 233 extern int bcm_l3_nat_ingress_add( 234 int unit, 235 bcm_l3_nat_ingress_t *nat_info); 236 237 /* 238 * Delete an ingress NAT table entry. Depending on the flags settings an 239 * entry is deleted from either the ingress DNAT pool table, DNAT session 240 * table or SNAT session table. 241 */ 242 extern int bcm_l3_nat_ingress_delete( 243 int unit, 244 bcm_l3_nat_ingress_t *nat_info); 245 246 /* 247 * Find an ingress NAT table entry. Depending on the flags settings an 248 * entry is searched for in either the ingress DNAT pool table, DNAT 249 * session table or SNAT session table. 250 */ 251 extern int bcm_l3_nat_ingress_find( 252 int unit, 253 bcm_l3_nat_ingress_t *nat_info); 254 255 /* 256 * Delete all entries in an ingress NAT table. Depending on the flags 257 * settings entries are deleted from either the ingress DNAT pool table, 258 * DNAT session table or SNAT session table. 259 */ 260 extern int bcm_l3_nat_ingress_delete_all( 261 int unit, 262 bcm_l3_nat_ingress_t *nat_info); 263 264 /* Run aging on either DNAT session or SNAT session table. */ 265 extern int bcm_l3_nat_ingress_age( 266 int unit, 267 uint32 flags, 268 bcm_l3_nat_ingress_traverse_cb age_cb, 269 void *user_data); 270 271 /* 272 * Traverse through the ingress NAT table specified by flags and invoke a 273 * user provided callback for each valid entry. 274 */ 275 extern int bcm_l3_nat_ingress_traverse( 276 int unit, 277 uint32 flags, 278 uint32 start, 279 uint32 end, 280 bcm_l3_nat_ingress_traverse_cb cb, 281 void *user_data); 282 283 #endif /* BCM_HIDE_DISPATCHABLE */ 284 285 /* L3 Large Scale NAT egress flags. */ 286 #define BCM_L3_LARGE_NAT_EGRESS_SNAT (1 << 0) /* Entry is for SNAT. */ 287 #define BCM_L3_LARGE_NAT_EGRESS_DNAT (1 << 1) /* Entry is for DNAT. */ 288 #define BCM_L3_LARGE_NAT_EGRESS_NAPT (1 << 2) /* Entry is for NAPT. */ 289 #define BCM_L3_LARGE_NAT_EGRESS_REPLACE (1 << 3) /* Replace existing 290 entry. */ 291 #define BCM_L3_LARGE_NAT_EGRESS_MULTICAST (1 << 4) /* Multicast Entry for 292 Large Scale NAT. */ 293 #define BCM_L3_LARGE_NAT_EGRESS_MACDA_UPDATE (1 << 5) /* Update MACDA on 294 Multicast NAT. */ 295 296 /* Egress Adaptation table NAT entry specification. */ 297 typedef struct bcm_l3_large_nat_egress_s { 298 uint32 flags; /* See BCM_L3_LARGE_NAT_EGRESS_XXX flag definitions. */ 299 bcm_ip_t sip_addr; /* Translated source IP. */ 300 uint16 src_port; /* Source l4 port for NAPT */ 301 bcm_ip_t dip_addr; /* Translated dest IP. */ 302 uint16 dst_port; /* Destination l4 port for NAPT */ 303 int intf_class_id; /* Overlay L3 interface class ID. Use with RIOT 304 flows only. */ 305 uint32 nat_class_id; /* NAT class ID assigned by ingress FP/EM. */ 306 int replication_id; /* Replication copy ID of multicast Egress object. */ 307 } bcm_l3_large_nat_egress_t; 308 309 /* bcm_l3_large_nat_egress_traverse_cb */ 310 typedef int (*bcm_l3_large_nat_egress_traverse_cb)( 311 int unit, 312 bcm_l3_large_nat_egress_t *nat_info, 313 void *user_data); 314 315 /* Initialize a bcm_l3_large_nat_egress_t structure. */ 316 extern void bcm_l3_large_nat_egress_t_init( 317 bcm_l3_large_nat_egress_t *nat_info); 318 319 #ifndef BCM_HIDE_DISPATCHABLE 320 321 /* 322 * Add an egress NAT entry in the Egress Adaptation Table. If REPLACE 323 * flag is specified then update the entry identified by the nat_info. 324 */ 325 extern int bcm_l3_large_nat_egress_add( 326 int unit, 327 bcm_l3_large_nat_egress_t *nat_info); 328 329 /* Delete an egress NAT entry from the Egress Adaptation table. */ 330 extern int bcm_l3_large_nat_egress_delete( 331 int unit, 332 bcm_l3_large_nat_egress_t *nat_info); 333 334 /* Retrieve the egress NAT entry specified in nat_info structure */ 335 extern int bcm_l3_large_nat_egress_get( 336 int unit, 337 bcm_l3_large_nat_egress_t *nat_info); 338 339 /* 340 * Traverse through the NAT entries in the Egress Adaptation table and 341 * invoke a user provided callback for each valid entry. 342 */ 343 extern int bcm_l3_large_nat_egress_traverse( 344 int unit, 345 bcm_l3_large_nat_egress_traverse_cb cb, 346 void *user_data); 347 348 #endif /* defined(INCLUDE_L3) */ 349 350 #endif /* BCM_HIDE_DISPATCHABLE */ 351 352 #endif /* __BCM_NAT_H__ */