X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fsnat%2Fsnat.h;h=39cbd3f8e0f5ebec651ae877a3da7e4190631988;hb=3b46cba8f4e909bc363403c6c92215159abb2f11;hp=fc379dfa3ed29026d894215c75f30220bdbd626a;hpb=8b275371d1487958d9469d2be8f5330ee8197d04;p=vpp.git diff --git a/src/plugins/snat/snat.h b/src/plugins/snat/snat.h index fc379dfa3ed..39cbd3f8e0f 100644 --- a/src/plugins/snat/snat.h +++ b/src/plugins/snat/snat.h @@ -66,13 +66,18 @@ typedef struct { }; u64 as_u64; }; -} snat_static_mapping_key_t; +} snat_worker_key_t; +#define foreach_snat_protocol \ + _(UDP, 0, udp, "udp") \ + _(TCP, 1, tcp, "tcp") \ + _(ICMP, 2, icmp, "icmp") + typedef enum { - SNAT_PROTOCOL_UDP = 0, - SNAT_PROTOCOL_TCP, - SNAT_PROTOCOL_ICMP, +#define _(N, i, n, s) SNAT_PROTOCOL_##N = i, + foreach_snat_protocol +#undef _ } snat_protocol_t; @@ -112,8 +117,11 @@ typedef struct { typedef struct { ip4_address_t addr; - u32 busy_ports; - uword * busy_port_bitmap; +#define _(N, i, n, s) \ + u32 busy_##n##_ports; \ + uword * busy_##n##_port_bitmap; + foreach_snat_protocol +#undef _ } snat_address_t; typedef struct { @@ -124,6 +132,7 @@ typedef struct { u8 addr_only; u32 vrf_id; u32 fib_index; + snat_protocol_t proto; } snat_static_mapping_t; typedef struct { @@ -137,6 +146,7 @@ typedef struct { u16 e_port; u32 sw_if_index; u32 vrf_id; + snat_protocol_t proto; int addr_only; int is_add; } snat_static_map_resolve_t; @@ -223,7 +233,6 @@ typedef struct { vnet_main_t * vnet_main; ip4_main_t * ip4_main; ip_lookup_main_t * ip4_lookup_main; - ethernet_main_t * ethernet_main; api_main_t * api_main; } snat_main_t; @@ -272,4 +281,28 @@ typedef struct { u16 sequence; } icmp_echo_header_t; +always_inline snat_protocol_t +ip_proto_to_snat_proto (u8 ip_proto) +{ + snat_protocol_t snat_proto = ~0; + + snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto; + snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto; + snat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto; + + return snat_proto; +} + +always_inline u8 +snat_proto_to_ip_proto (snat_protocol_t snat_proto) +{ + u8 ip_proto = ~0; + + ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto; + ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto; + ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto; + + return ip_proto; +} + #endif /* __included_snat_h__ */