summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/nat/lib')
-rw-r--r--src/plugins/nat/lib/alloc.c1
-rw-r--r--src/plugins/nat/lib/alloc.h25
-rw-r--r--src/plugins/nat/lib/inlines.h69
-rw-r--r--src/plugins/nat/lib/lib.h54
4 files changed, 124 insertions, 25 deletions
diff --git a/src/plugins/nat/lib/alloc.c b/src/plugins/nat/lib/alloc.c
index 33c2c071d62..ed4ba060b0b 100644
--- a/src/plugins/nat/lib/alloc.c
+++ b/src/plugins/nat/lib/alloc.c
@@ -17,6 +17,7 @@
* @brief NAT port/address allocation lib
*/
+#include <nat/lib/lib.h>
#include <nat/lib/alloc.h>
static_always_inline void
diff --git a/src/plugins/nat/lib/alloc.h b/src/plugins/nat/lib/alloc.h
index 9dba2ca94da..a9a2c15fedc 100644
--- a/src/plugins/nat/lib/alloc.h
+++ b/src/plugins/nat/lib/alloc.h
@@ -22,31 +22,6 @@
#include <vnet/ip/ip.h>
-#define foreach_nat_error \
- _(VALUE_EXIST, -1, "Value already exists") \
- _(NO_SUCH_ENTRY, -2, "No such entry") \
- _(UNKNOWN_PROTOCOL, -3, "Unknown protocol") \
- _(OUT_OF_TRANSLATIONS, -4, "Out of translations")
-
-#define foreach_nat_protocol \
- _(UDP, 0, udp, "udp") \
- _(TCP, 1, tcp, "tcp") \
- _(ICMP, 2, icmp, "icmp")
-
-typedef enum
-{
-#define _(N, i, s) NAT_ERROR_##N = i,
- foreach_nat_error
-#undef _
-} nat_error_t;
-
-typedef enum
-{
-#define _(N, i, n, s) NAT_PROTOCOL_##N = i,
- foreach_nat_protocol
-#undef _
-} nat_protocol_t;
-
typedef struct nat_ip4_pool_addr_s nat_ip4_pool_addr_t;
typedef struct nat_ip4_addr_port_s nat_ip4_addr_port_t;
typedef struct nat_ip4_pool_s nat_ip4_pool_t;
diff --git a/src/plugins/nat/lib/inlines.h b/src/plugins/nat/lib/inlines.h
new file mode 100644
index 00000000000..f2bd5e08ce6
--- /dev/null
+++ b/src/plugins/nat/lib/inlines.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @brief The NAT44 inline functions
+ */
+#ifndef included_nat_inlines_h__
+#define included_nat_inlines_h__
+
+static_always_inline u32
+ip_proto_to_nat_proto (u8 ip_proto)
+{
+ u32 nat_proto = ~0;
+
+ nat_proto = (ip_proto == IP_PROTOCOL_UDP) ? NAT_PROTOCOL_UDP : nat_proto;
+ nat_proto = (ip_proto == IP_PROTOCOL_TCP) ? NAT_PROTOCOL_TCP : nat_proto;
+ nat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? NAT_PROTOCOL_ICMP : nat_proto;
+ nat_proto = (ip_proto == IP_PROTOCOL_ICMP6) ? NAT_PROTOCOL_ICMP : nat_proto;
+
+ return nat_proto;
+}
+
+static_always_inline u8
+nat_proto_to_ip_proto (nat_protocol_t nat_proto)
+{
+ u8 ip_proto = ~0;
+
+ ip_proto = (nat_proto == NAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
+ ip_proto = (nat_proto == NAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
+ ip_proto = (nat_proto == NAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
+
+ return ip_proto;
+}
+
+static_always_inline u8
+icmp_type_is_error_message (u8 icmp_type)
+{
+ switch (icmp_type)
+ {
+ case ICMP4_destination_unreachable:
+ case ICMP4_time_exceeded:
+ case ICMP4_parameter_problem:
+ case ICMP4_source_quench:
+ case ICMP4_redirect:
+ case ICMP4_alternate_host_address:
+ return 1;
+ }
+ return 0;
+}
+
+#endif /* included_nat_inlines_h__ */
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/nat/lib/lib.h b/src/plugins/nat/lib/lib.h
new file mode 100644
index 00000000000..005db81b4a3
--- /dev/null
+++ b/src/plugins/nat/lib/lib.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file
+ * @brief NAT port/address allocation lib
+ */
+#ifndef included_nat_lib_h__
+#define included_nat_lib_h__
+
+#define foreach_nat_error \
+ _(VALUE_EXIST, -1, "Value already exists") \
+ _(NO_SUCH_ENTRY, -2, "No such entry") \
+ _(UNKNOWN_PROTOCOL, -3, "Unknown protocol") \
+ _(OUT_OF_TRANSLATIONS, -4, "Out of translations")
+
+#define foreach_nat_protocol \
+ _(UDP, 0, udp, "udp") \
+ _(TCP, 1, tcp, "tcp") \
+ _(ICMP, 2, icmp, "icmp")
+
+typedef enum
+{
+#define _(N, i, s) NAT_ERROR_##N = i,
+ foreach_nat_error
+#undef _
+} nat_error_t;
+
+typedef enum
+{
+#define _(N, i, n, s) NAT_PROTOCOL_##N = i,
+ foreach_nat_protocol
+#undef _
+} nat_protocol_t;
+
+#endif /* included_nat_lib_h__ */
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */