diff options
author | Filip Varga <fivarga@cisco.com> | 2020-03-11 12:49:46 +0100 |
---|---|---|
committer | Filip Varga <fivarga@cisco.com> | 2020-03-11 17:41:40 +0100 |
commit | f2833e42c1e3721ce06b0f510447d8a6dd3e5eb4 (patch) | |
tree | b1a6711d4958b9cca4a1ded5b4b94742225e1562 /src/plugins/nat/dslite | |
parent | 92a6ac24f36dcc7e22682c0ce448cefc23d58e5e (diff) |
nat: dslite plugin separation
Type: refactor
Signed-off-by: Filip Varga <fivarga@cisco.com>
Change-Id: I81546423200cc7f8a06b527dac8ead191a9e0519
Diffstat (limited to 'src/plugins/nat/dslite')
-rw-r--r-- | src/plugins/nat/dslite/dslite.h | 29 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_ce_decap.c | 3 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_ce_encap.c | 3 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_cli.c | 22 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_dpo.c | 1 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_in2out.c | 19 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite_out2in.c | 19 |
7 files changed, 66 insertions, 30 deletions
diff --git a/src/plugins/nat/dslite/dslite.h b/src/plugins/nat/dslite/dslite.h index d512cf47c9b..8cb73d88409 100644 --- a/src/plugins/nat/dslite/dslite.h +++ b/src/plugins/nat/dslite/dslite.h @@ -15,12 +15,35 @@ #ifndef __included_dslite_h__ #define __included_dslite_h__ +#include <vppinfra/dlist.h> #include <vppinfra/bihash_8_8.h> #include <vppinfra/bihash_16_8.h> #include <vppinfra/bihash_24_8.h> + +#include <nat/lib/lib.h> #include <nat/lib/alloc.h> -#include <nat/nat.h> -#include <nat/nat_inlines.h> +#include <nat/lib/inlines.h> + +typedef struct +{ + u16 identifier; + u16 sequence; +} echo_header_t; + +/* session key (4-tuple) */ +typedef struct +{ + union + { + struct + { + ip4_address_t addr; + u16 port; + u16 protocol:3, fib_index:13; + }; + u64 as_u64; + }; +} nat_session_key_t; typedef struct { @@ -41,7 +64,7 @@ typedef struct /* *INDENT-OFF* */ typedef CLIB_PACKED (struct { - snat_session_key_t out2in; + nat_session_key_t out2in; dslite_session_key_t in2out; u32 per_b4_index; u32 per_b4_list_head_index; diff --git a/src/plugins/nat/dslite/dslite_ce_decap.c b/src/plugins/nat/dslite/dslite_ce_decap.c index 3d6ca992e45..56af25129f2 100644 --- a/src/plugins/nat/dslite/dslite_ce_decap.c +++ b/src/plugins/nat/dslite/dslite_ce_decap.c @@ -13,7 +13,6 @@ * limitations under the License. */ #include <nat/dslite/dslite.h> -#include <nat/nat_inlines.h> typedef enum { @@ -80,7 +79,7 @@ VLIB_NODE_FN (dslite_ce_decap_node) (vlib_main_t * vm, } ip40 = vlib_buffer_get_current (b0) + sizeof (ip6_header_t); - proto0 = ip_proto_to_snat_proto (ip40->protocol); + proto0 = ip_proto_to_nat_proto (ip40->protocol); if (PREDICT_FALSE (proto0 == ~0)) { diff --git a/src/plugins/nat/dslite/dslite_ce_encap.c b/src/plugins/nat/dslite/dslite_ce_encap.c index 8cec5439243..74b5bc39fbe 100644 --- a/src/plugins/nat/dslite/dslite_ce_encap.c +++ b/src/plugins/nat/dslite/dslite_ce_encap.c @@ -13,7 +13,6 @@ * limitations under the License. */ #include <nat/dslite/dslite.h> -#include <nat/nat_inlines.h> typedef enum { @@ -66,7 +65,7 @@ VLIB_NODE_FN (dslite_ce_encap_node) (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); ip40 = vlib_buffer_get_current (b0); - proto0 = ip_proto_to_snat_proto (ip40->protocol); + proto0 = ip_proto_to_nat_proto (ip40->protocol); if (PREDICT_FALSE (proto0 == ~0)) { diff --git a/src/plugins/nat/dslite/dslite_cli.c b/src/plugins/nat/dslite/dslite_cli.c index d5c0ca6498b..0819f95261a 100644 --- a/src/plugins/nat/dslite/dslite_cli.c +++ b/src/plugins/nat/dslite/dslite_cli.c @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include <nat/dslite/dslite.h> static clib_error_t * @@ -205,6 +204,25 @@ dslite_show_b4_ip6_addr_command_fn (vlib_main_t * vm, } static u8 * +format_nat_protocol (u8 * s, va_list * args) +{ + u32 i = va_arg (*args, u32); + u8 *t = 0; + + switch (i) + { +#define _(N, j, n, str) case NAT_PROTOCOL_##N: t = (u8 *) str; break; + foreach_nat_protocol +#undef _ + default: + s = format (s, "unknown"); + return s; + } + s = format (s, "%s", t); + return s; +} + +static u8 * format_dslite_session (u8 * s, va_list * args) { dslite_session_t *session = va_arg (*args, dslite_session_t *); @@ -216,7 +234,7 @@ format_dslite_session (u8 * s, va_list * args) clib_net_to_host_u16 (session->in2out.port), format_ip4_address, &session->out2in.addr, clib_net_to_host_u16 (session->out2in.port), - format_snat_protocol, session->in2out.proto); + format_nat_protocol, session->in2out.proto); s = format (s, "%Utotal pkts %d, total bytes %lld\n", format_white_space, indent + 4, session->total_pkts, session->total_bytes); diff --git a/src/plugins/nat/dslite/dslite_dpo.c b/src/plugins/nat/dslite/dslite_dpo.c index 009b5536289..120a6f0f7c7 100644 --- a/src/plugins/nat/dslite/dslite_dpo.c +++ b/src/plugins/nat/dslite/dslite_dpo.c @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include <vnet/ip/ip.h> #include <nat/dslite/dslite_dpo.h> diff --git a/src/plugins/nat/dslite/dslite_in2out.c b/src/plugins/nat/dslite/dslite_in2out.c index d1ac17509c6..1d00bb2d7fe 100644 --- a/src/plugins/nat/dslite/dslite_in2out.c +++ b/src/plugins/nat/dslite/dslite_in2out.c @@ -13,7 +13,6 @@ * limitations under the License. */ #include <nat/dslite/dslite.h> -#include <nat/nat_inlines.h> #include <nat/nat_syslog.h> typedef enum @@ -42,7 +41,7 @@ slow_path (dslite_main_t * dm, dslite_session_key_t * in2out_key, dlist_elt_t *head_elt, *oldest_elt, *elt; u32 oldest_index; dslite_session_t *s; - snat_session_key_t out2in_key; + nat_session_key_t out2in_key; nat_ip4_addr_port_t addr_port; u32 b4_index; @@ -189,7 +188,7 @@ dslite_icmp_in2out (dslite_main_t * dm, ip6_header_t * ip6, clib_bihash_kv_24_8_t kv, value; dslite_session_key_t key; u32 n = next; - icmp_echo_header_t *echo; + echo_header_t *echo; u32 new_addr, old_addr; u16 old_id, new_id; ip_csum_t sum; @@ -201,11 +200,11 @@ dslite_icmp_in2out (dslite_main_t * dm, ip6_header_t * ip6, goto done; } - echo = (icmp_echo_header_t *) (icmp + 1); + echo = (echo_header_t *) (icmp + 1); key.addr = ip4->src_address; key.port = echo->identifier; - key.proto = SNAT_PROTOCOL_ICMP; + key.proto = NAT_PROTOCOL_ICMP; key.softwire_id.as_u64[0] = ip6->src_address.as_u64[0]; key.softwire_id.as_u64[1] = ip6->src_address.as_u64[1]; key.pad = 0; @@ -237,7 +236,7 @@ dslite_icmp_in2out (dslite_main_t * dm, ip6_header_t * ip6, old_id = echo->identifier; echo->identifier = new_id = s->out2in.port; sum = icmp->checksum; - sum = ip_csum_update (sum, old_id, new_id, icmp_echo_header_t, identifier); + sum = ip_csum_update (sum, old_id, new_id, echo_header_t, identifier); icmp->checksum = ip_csum_fold (sum); done: @@ -315,7 +314,7 @@ dslite_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } ip40 = vlib_buffer_get_current (b0) + sizeof (ip6_header_t); - proto0 = ip_proto_to_snat_proto (ip40->protocol); + proto0 = ip_proto_to_nat_proto (ip40->protocol); if (PREDICT_FALSE (proto0 == ~0)) { @@ -329,7 +328,7 @@ dslite_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (is_slow_path) { - if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP)) { next0 = dslite_icmp_in2out (dm, ip60, ip40, &s0, next0, &error0, @@ -342,7 +341,7 @@ dslite_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP)) { next0 = DSLITE_IN2OUT_NEXT_SLOWPATH; goto trace0; @@ -390,7 +389,7 @@ dslite_in2out_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node, ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, src_address); ip40->checksum = ip_csum_fold (sum0); - if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP)) + if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP)) { old_port0 = tcp0->src_port; tcp0->src_port = s0->out2in.port; diff --git a/src/plugins/nat/dslite/dslite_out2in.c b/src/plugins/nat/dslite/dslite_out2in.c index ac64a589509..96cf9188cf6 100644 --- a/src/plugins/nat/dslite/dslite_out2in.c +++ b/src/plugins/nat/dslite/dslite_out2in.c @@ -13,7 +13,6 @@ * limitations under the License. */ #include <nat/dslite/dslite.h> -#include <nat/nat_inlines.h> typedef enum { @@ -37,14 +36,14 @@ dslite_icmp_out2in (dslite_main_t * dm, ip4_header_t * ip4, dslite_session_t *s = 0; icmp46_header_t *icmp = ip4_next_header (ip4); clib_bihash_kv_8_8_t kv, value; - snat_session_key_t key; + nat_session_key_t key; u32 n = next; - icmp_echo_header_t *echo; + echo_header_t *echo; u32 new_addr, old_addr; u16 old_id, new_id; ip_csum_t sum; - echo = (icmp_echo_header_t *) (icmp + 1); + echo = (echo_header_t *) (icmp + 1); if (icmp_type_is_error_message (icmp->type) || (icmp->type != ICMP4_echo_reply)) @@ -56,7 +55,7 @@ dslite_icmp_out2in (dslite_main_t * dm, ip4_header_t * ip4, key.addr = ip4->dst_address; key.port = echo->identifier; - key.protocol = SNAT_PROTOCOL_ICMP; + key.protocol = NAT_PROTOCOL_ICMP; key.fib_index = 0; kv.key = key.as_u64; @@ -77,7 +76,7 @@ dslite_icmp_out2in (dslite_main_t * dm, ip4_header_t * ip4, old_id = echo->identifier; echo->identifier = new_id = s->in2out.port; sum = icmp->checksum; - sum = ip_csum_update (sum, old_id, new_id, icmp_echo_header_t, identifier); + sum = ip_csum_update (sum, old_id, new_id, echo_header_t, identifier); icmp->checksum = ip_csum_fold (sum); old_addr = ip4->dst_address.as_u32; @@ -129,7 +128,7 @@ VLIB_NODE_FN (dslite_out2in_node) (vlib_main_t * vm, udp_header_t *udp0; tcp_header_t *tcp0; clib_bihash_kv_8_8_t kv0, value0; - snat_session_key_t key0; + nat_session_key_t key0; dslite_session_t *s0 = 0; ip_csum_t sum0; u32 new_addr0, old_addr0; @@ -145,7 +144,7 @@ VLIB_NODE_FN (dslite_out2in_node) (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); ip40 = vlib_buffer_get_current (b0); - proto0 = ip_proto_to_snat_proto (ip40->protocol); + proto0 = ip_proto_to_nat_proto (ip40->protocol); if (PREDICT_FALSE (proto0 == ~0)) { @@ -154,7 +153,7 @@ VLIB_NODE_FN (dslite_out2in_node) (vlib_main_t * vm, goto trace0; } - if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP)) { next0 = dslite_icmp_out2in (dm, ip40, &s0, next0, &error0, @@ -198,7 +197,7 @@ VLIB_NODE_FN (dslite_out2in_node) (vlib_main_t * vm, dst_address); ip40->checksum = ip_csum_fold (sum0); - if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP)) + if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP)) { old_port0 = tcp0->dst_port; tcp0->dst_port = s0->in2out.port; |