summaryrefslogtreecommitdiffstats
path: root/src/plugins/snat/snat.h
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2017-02-02 01:43:00 -0800
committerMatus Fabian <matfabia@cisco.com>2017-02-03 01:09:45 -0800
commit09d96f4a611fa989bfbbfb7e683d668dbe73ac1a (patch)
treec3e99fad08357a2c1b9660de49cf01b2e7d20aee /src/plugins/snat/snat.h
parent85bb9172894870f0c6c72e1555a0decf4d37213f (diff)
SNAT: Port allocation per protocol
Ports are allocated per protocol (UDP, TCP, ICMP) 1:1 NAT with port is configured for specific protocol Change-Id: I37ae5eed3715b223d0620d4fdaed7a482bb7a834 Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/plugins/snat/snat.h')
-rw-r--r--src/plugins/snat/snat.h46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/plugins/snat/snat.h b/src/plugins/snat/snat.h
index fc379dfa3ed..32dc9f9e0a6 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;
@@ -272,4 +282,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__ */