diff options
author | Matus Fabian <matfabia@cisco.com> | 2017-08-15 06:59:19 -0700 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2017-11-07 21:58:31 +0000 |
commit | efcd1e9e1d7dda4e4ea3db5750925cd8f6894f4d (patch) | |
tree | 63c07cf6a94820a5fb2c3935082b6a02f6d210d3 /src/plugins/nat/nat_api.c | |
parent | 20ab0a4943f7509f6e07d6c614eee90c80c8b963 (diff) |
SNAT: IP fragmentation (VPP-890)
Translation of fragmented packets.
Change-Id: I9b1f2e9433ce273638080f32c2d3bff39c49899d
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat_api.c')
-rw-r--r-- | src/plugins/nat/nat_api.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c index 0ffa2f0e772..548a9e03bc4 100644 --- a/src/plugins/nat/nat_api.c +++ b/src/plugins/nat/nat_api.c @@ -22,6 +22,7 @@ #include <nat/nat_det.h> #include <nat/nat64.h> #include <nat/dslite.h> +#include <nat/nat_reass.h> #include <vlibapi/api.h> #include <vlibmemory/api.h> @@ -1496,6 +1497,146 @@ vl_api_nat_ipfix_enable_disable_t_print (vl_api_nat_ipfix_enable_disable_t * FINISH; } +static void +vl_api_nat_set_reass_t_handler (vl_api_nat_set_reass_t * mp) +{ + snat_main_t *sm = &snat_main; + vl_api_nat_set_reass_reply_t *rmp; + int rv = 0; + + rv = + nat_reass_set (ntohl (mp->timeout), ntohs (mp->max_reass), mp->max_frag, + mp->drop_frag, mp->is_ip6); + + REPLY_MACRO (VL_API_NAT_SET_REASS_REPLY); +} + +static void * +vl_api_nat_set_reass_t_print (vl_api_nat_set_reass_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat_set_reass "); + s = format (s, "timeout %d max_reass %d max_frag %d drop_frag %d is_ip6 %d", + clib_host_to_net_u32 (mp->timeout), + clib_host_to_net_u16 (mp->max_reass), + mp->max_frag, mp->drop_frag, mp->is_ip6); + + FINISH; +} + +static void +vl_api_nat_get_reass_t_handler (vl_api_nat_get_reass_t * mp) +{ + snat_main_t *sm = &snat_main; + vl_api_nat_get_reass_reply_t *rmp; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_NAT_GET_REASS_REPLY, + ({ + rmp->ip4_timeout = htonl (nat_reass_get_timeout(0)); + rmp->ip4_max_reass = htons (nat_reass_get_max_reass(0)); + rmp->ip4_max_frag = nat_reass_get_max_frag(0); + rmp->ip4_drop_frag = nat_reass_is_drop_frag(0); + rmp->ip6_timeout = htonl (nat_reass_get_timeout(1)); + rmp->ip6_max_reass = htons (nat_reass_get_max_reass(1)); + rmp->ip6_max_frag = nat_reass_get_max_frag(1); + rmp->ip6_drop_frag = nat_reass_is_drop_frag(1); + })) + /* *INDENT-ON* */ +} + +static void * +vl_api_nat_get_reass_t_print (vl_api_nat_get_reass_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat_get_reass"); + + FINISH; +} + +typedef struct nat_api_walk_ctx_t_ +{ + unix_shared_memory_queue_t *q; + u32 context; +} nat_api_walk_ctx_t; + +static int +nat_ip4_reass_walk_api (nat_reass_ip4_t * reass, void *arg) +{ + vl_api_nat_reass_details_t *rmp; + snat_main_t *sm = &snat_main; + nat_api_walk_ctx_t *ctx = arg; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base); + rmp->context = ctx->context; + clib_memcpy (rmp->src_addr, &(reass->key.src), 4); + clib_memcpy (rmp->dst_addr, &(reass->key.dst), 4); + rmp->proto = reass->key.proto; + rmp->frag_id = ntohl (reass->key.frag_id); + rmp->frag_n = reass->frag_n; + rmp->is_ip4 = 1; + + vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp); + + return 0; +} + +static int +nat_ip6_reass_walk_api (nat_reass_ip6_t * reass, void *arg) +{ + vl_api_nat_reass_details_t *rmp; + snat_main_t *sm = &snat_main; + nat_api_walk_ctx_t *ctx = arg; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base); + rmp->context = ctx->context; + clib_memcpy (rmp->src_addr, &(reass->key.src), 16); + clib_memcpy (rmp->dst_addr, &(reass->key.dst), 16); + rmp->proto = reass->key.proto; + rmp->frag_id = ntohl (reass->key.frag_id); + rmp->frag_n = reass->frag_n; + rmp->is_ip4 = 0; + + vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp); + + return 0; +} + +static void +vl_api_nat_reass_dump_t_handler (vl_api_nat_reass_dump_t * mp) +{ + unix_shared_memory_queue_t *q; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + return; + + nat_api_walk_ctx_t ctx = { + .q = q, + .context = mp->context, + }; + + nat_ip4_reass_walk (nat_ip4_reass_walk_api, &ctx); + nat_ip6_reass_walk (nat_ip6_reass_walk_api, &ctx); +} + +static void * +vl_api_nat_reass_dump_t_print (vl_api_nat_reass_dump_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat_reass_dump"); + + FINISH; +} + /*************/ /*** NAT44 ***/ /*************/ @@ -3406,6 +3547,9 @@ _(NAT_SHOW_CONFIG, nat_show_config) \ _(NAT_SET_WORKERS, nat_set_workers) \ _(NAT_WORKER_DUMP, nat_worker_dump) \ _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \ +_(NAT_SET_REASS, nat_set_reass) \ +_(NAT_GET_REASS, nat_get_reass) \ +_(NAT_REASS_DUMP, nat_reass_dump) \ _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \ _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \ _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \ |