2016-12-06 12:50:08 +01:00
|
|
|
/*
|
|
|
|
|
*------------------------------------------------------------------
|
|
|
|
|
* map_api.c - vnet map api
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2016 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.
|
|
|
|
|
*------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2019-09-04 09:12:29 +02:00
|
|
|
#include <vnet/ip/ip_types_api.h>
|
2018-06-22 11:32:12 +02:00
|
|
|
#include <map/map.h>
|
2019-09-19 01:08:30 +02:00
|
|
|
#include <map/map.api_enum.h>
|
|
|
|
|
#include <map/map.api_types.h>
|
2016-12-06 12:50:08 +01:00
|
|
|
#include <vnet/ip/ip.h>
|
2019-08-21 10:53:14 +00:00
|
|
|
#include <vnet/ip/reass/ip4_sv_reass.h>
|
|
|
|
|
#include <vnet/ip/reass/ip6_sv_reass.h>
|
2019-10-01 13:00:22 +00:00
|
|
|
#include <vnet/ip/reass/ip6_full_reass.h>
|
2016-12-06 12:50:08 +01:00
|
|
|
#include <vnet/fib/fib_table.h>
|
2018-06-22 11:32:12 +02:00
|
|
|
#include <vlibmemory/api.h>
|
2016-12-06 12:50:08 +01:00
|
|
|
|
2018-06-22 11:32:12 +02:00
|
|
|
#define REPLY_MSG_ID_BASE mm->msg_id_base
|
|
|
|
|
#include <vlibapi/api_helper_macros.h>
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
|
|
|
|
|
{
|
2018-06-22 11:32:12 +02:00
|
|
|
map_main_t *mm = &map_main;
|
2016-12-06 12:50:08 +01:00
|
|
|
vl_api_map_add_domain_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
u32 index;
|
2017-11-08 11:10:54 +01:00
|
|
|
u8 flags = 0;
|
2019-08-23 22:55:18 +02:00
|
|
|
|
2020-01-21 18:24:44 +01:00
|
|
|
mp->tag[ARRAY_LEN (mp->tag) - 1] = '\0';
|
2016-12-06 12:50:08 +01:00
|
|
|
rv =
|
2019-06-06 14:07:55 -04:00
|
|
|
map_create_domain ((ip4_address_t *) & mp->ip4_prefix.address,
|
2018-11-22 12:53:00 +01:00
|
|
|
mp->ip4_prefix.len,
|
2019-06-06 14:07:55 -04:00
|
|
|
(ip6_address_t *) & mp->ip6_prefix.address,
|
2018-11-22 12:53:00 +01:00
|
|
|
mp->ip6_prefix.len,
|
2019-06-06 14:07:55 -04:00
|
|
|
(ip6_address_t *) & mp->ip6_src.address,
|
2018-11-22 12:53:00 +01:00
|
|
|
mp->ip6_src.len, mp->ea_bits_len, mp->psid_offset,
|
2020-05-18 11:14:05 +02:00
|
|
|
mp->psid_length, &index, mp->mtu, flags, mp->tag);
|
2020-01-21 18:24:44 +01:00
|
|
|
|
2016-12-06 12:50:08 +01:00
|
|
|
/* *INDENT-OFF* */
|
2020-05-18 11:14:05 +02:00
|
|
|
REPLY_MACRO2_END(VL_API_MAP_ADD_DOMAIN_REPLY,
|
2016-12-06 12:50:08 +01:00
|
|
|
({
|
2020-05-18 11:14:05 +02:00
|
|
|
rmp->index = index;
|
2016-12-06 12:50:08 +01:00
|
|
|
}));
|
2020-05-18 11:14:05 +02:00
|
|
|
|
2016-12-06 12:50:08 +01:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
|
|
|
|
|
{
|
2018-06-22 11:32:12 +02:00
|
|
|
map_main_t *mm = &map_main;
|
2016-12-06 12:50:08 +01:00
|
|
|
vl_api_map_del_domain_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
rv = map_delete_domain (ntohl (mp->index));
|
|
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
|
|
|
|
|
{
|
2018-06-22 11:32:12 +02:00
|
|
|
map_main_t *mm = &map_main;
|
2016-12-06 12:50:08 +01:00
|
|
|
vl_api_map_del_domain_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
rv =
|
|
|
|
|
map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
|
2018-11-22 12:53:00 +01:00
|
|
|
(ip6_address_t *) & mp->ip6_dst, mp->is_add);
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-05-20 15:47:06 +02:00
|
|
|
send_domain_details (u32 map_domain_index, vl_api_registration_t * rp,
|
|
|
|
|
u32 context)
|
2016-12-06 12:50:08 +01:00
|
|
|
{
|
2020-05-20 15:47:06 +02:00
|
|
|
map_main_t *mm = &map_main;
|
2016-12-06 12:50:08 +01:00
|
|
|
vl_api_map_domain_details_t *rmp;
|
2020-05-20 15:47:06 +02:00
|
|
|
map_domain_t *d = pool_elt_at_index (mm->domains, map_domain_index);
|
|
|
|
|
|
|
|
|
|
/* Make sure every field is initiated (or don't skip the clib_memset()) */
|
|
|
|
|
map_domain_extra_t *de =
|
|
|
|
|
vec_elt_at_index (mm->domain_extras, map_domain_index);
|
|
|
|
|
int tag_len = clib_min (ARRAY_LEN (rmp->tag), vec_len (de->tag) + 1);
|
|
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
|
REPLY_MACRO_DETAILS4(VL_API_MAP_DOMAIN_DETAILS, rp, context,
|
|
|
|
|
({
|
|
|
|
|
rmp->domain_index = htonl (map_domain_index);
|
|
|
|
|
clib_memcpy (&rmp->ip6_prefix.address, &d->ip6_prefix,
|
|
|
|
|
sizeof (rmp->ip6_prefix.address));
|
|
|
|
|
clib_memcpy (&rmp->ip4_prefix.address, &d->ip4_prefix,
|
|
|
|
|
sizeof (rmp->ip4_prefix.address));
|
|
|
|
|
clib_memcpy (&rmp->ip6_src.address, &d->ip6_src,
|
|
|
|
|
sizeof (rmp->ip6_src.address));
|
|
|
|
|
rmp->ip6_prefix.len = d->ip6_prefix_len;
|
|
|
|
|
rmp->ip4_prefix.len = d->ip4_prefix_len;
|
|
|
|
|
rmp->ip6_src.len = d->ip6_src_len;
|
|
|
|
|
rmp->ea_bits_len = d->ea_bits_len;
|
|
|
|
|
rmp->psid_offset = d->psid_offset;
|
|
|
|
|
rmp->psid_length = d->psid_length;
|
|
|
|
|
rmp->flags = d->flags;
|
|
|
|
|
rmp->mtu = htons (d->mtu);
|
|
|
|
|
memcpy (rmp->tag, de->tag, tag_len - 1);
|
|
|
|
|
rmp->tag[tag_len - 1] = '\0';
|
|
|
|
|
}));
|
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
|
|
|
|
|
{
|
2016-12-06 12:50:08 +01:00
|
|
|
map_main_t *mm = &map_main;
|
2020-05-20 15:47:06 +02:00
|
|
|
int i;
|
2018-01-09 06:39:23 -08:00
|
|
|
vl_api_registration_t *reg;
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
if (pool_elts (mm->domains) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-01-09 06:39:23 -08:00
|
|
|
reg = vl_api_client_index_to_registration (mp->client_index);
|
|
|
|
|
if (!reg)
|
|
|
|
|
return;
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
2020-12-13 21:47:40 +01:00
|
|
|
pool_foreach_index (i, mm->domains)
|
|
|
|
|
{
|
2020-05-20 15:47:06 +02:00
|
|
|
send_domain_details(i, reg, mp->context);
|
2020-12-13 21:47:40 +01:00
|
|
|
}
|
2020-05-20 15:47:06 +02:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
}
|
2019-03-12 13:09:08 -05:00
|
|
|
|
2020-05-20 15:47:06 +02:00
|
|
|
static void
|
|
|
|
|
vl_api_map_domains_get_t_handler (vl_api_map_domains_get_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_domains_get_reply_t *rmp;
|
|
|
|
|
|
|
|
|
|
i32 rv = 0;
|
|
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
|
REPLY_AND_DETAILS_MACRO (VL_API_MAP_DOMAINS_GET_REPLY, mm->domains,
|
|
|
|
|
({
|
|
|
|
|
send_domain_details (cursor, rp, mp->context);
|
2016-12-06 12:50:08 +01:00
|
|
|
}));
|
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
|
|
|
|
|
{
|
2018-01-09 06:39:23 -08:00
|
|
|
vl_api_registration_t *reg;
|
2016-12-06 12:50:08 +01:00
|
|
|
u16 i;
|
|
|
|
|
ip6_address_t dst;
|
|
|
|
|
vl_api_map_rule_details_t *rmp;
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
u32 domain_index = ntohl (mp->domain_index);
|
|
|
|
|
map_domain_t *d;
|
|
|
|
|
|
|
|
|
|
if (pool_elts (mm->domains) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
d = pool_elt_at_index (mm->domains, domain_index);
|
|
|
|
|
if (!d || !d->rules)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 06:39:23 -08:00
|
|
|
reg = vl_api_client_index_to_registration (mp->client_index);
|
|
|
|
|
if (!reg)
|
|
|
|
|
return;
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < (0x1 << d->psid_length); i++)
|
|
|
|
|
{
|
|
|
|
|
dst = d->rules[i];
|
|
|
|
|
if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
rmp = vl_msg_api_alloc (sizeof (*rmp));
|
2018-10-17 10:38:51 -04:00
|
|
|
clib_memset (rmp, 0, sizeof (*rmp));
|
2018-06-22 11:32:12 +02:00
|
|
|
rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS + mm->msg_id_base);
|
2016-12-06 12:50:08 +01:00
|
|
|
rmp->psid = htons (i);
|
make build failure.
[84/597] Building C object vnet/CMakeFiles/vnet.dir/ip/ip_types_api.c.o
FAILED: ccache /usr/lib/ccache/cc -DWITH_LIBSSL=1 -Dvnet_EXPORTS -I/vpp/src -I. -Iinclude -march=corei7 -mtune=corei7-avx -g -O2 -DFORTIFY_SOURCE=2 -fstack-protector -fPIC -Werror -fPIC -Wno-address-of-packed-member -Wall -MMD -MT vnet/CMakeFiles/vnet.dir/ip/ip_types_api.c.o -MF vnet/CMakeFiles/vnet.dir/ip/ip_types_api.c.o.d -o vnet/CMakeFiles/vnet.dir/ip/ip_types_api.c.o -c /vpp/src/vnet/ip/ip_types_api.c
/vpp/src/vnet/ip/ip_types_api.c: In function 'ip_address_union_encode':
/vpp/src/vnet/ip/ip_types_api.c:70:13: error: incompatible type for argument 1 of 'memcpy'
memcpy (out->ip6, &in->ip6, sizeof (out->ip6));
^
In file included from /usr/include/string.h:635:0,
from /vpp/src/vppinfra/string.h:55,
from /vpp/src/vppinfra/mem.h:55,
from /vpp/src/vppinfra/vec.h:42,
from /vpp/src/vppinfra/error.h:53,
from /vpp/src/vppinfra/hash.h:41,
from /vpp/src/vnet/ip/ip.h:43,
from /vpp/src/vnet/ip/ip_types_api.h:23,
from /vpp/src/vnet/ip/ip_types_api.c:16:
/usr/include/x86_64-linux-gnu/bits/string3.h:50:42: note: expected 'void * restrict' but argument is of type 'vl_api_ip6_address_t {aka struct _vl_api_ip6_address}'
__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
^
/vpp/src/vnet/ip/ip_types_api.c:72:13: error: incompatible type for argument 1 of 'memcpy'
memcpy (out->ip4, &in->ip4, sizeof (out->ip4));
^
In file included from /usr/include/string.h:635:0,
from /vpp/src/vppinfra/string.h:55,
from /vpp/src/vppinfra/mem.h:55,
from /vpp/src/vppinfra/vec.h:42,
from /vpp/src/vppinfra/error.h:53,
from /vpp/src/vppinfra/hash.h:41,
from /vpp/src/vnet/ip/ip.h:43,
from /vpp/src/vnet/ip/ip_types_api.h:23,
from /vpp/src/vnet/ip/ip_types_api.c:16:
/usr/include/x86_64-linux-gnu/bits/string3.h:50:42: note: expected 'void * restrict' but argument is of type 'vl_api_ip4_address_t {aka struct _vl_api_ip4_address}'
__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
^
/vpp/src/vnet/ip/ip_types_api.c: At top level:
cc1: error: unrecognized command line option '-Wno-address-of-packed-member' [-Werror]
cc1: all warnings being treated as errors
[84/597] Building C object vnet/CMakeFiles/vnet.dir/ip/ip4_forward.c.o
ninja: build stopped: subcommand failed.
Makefile:691: recipe for target 'vpp-build' failed
make[1]: *** [vpp-build] Error 1
make[1]: Leaving directory '/vpp/build-root'
Makefile:394: recipe for target 'test' failed
make: *** [test] Error 2
DBGvpp# show cpu
Model name: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Microarchitecture: Haswell (Crystalwell)
Flags: sse3 ssse3 sse41 sse42 avx avx2 aes invariant_tsc
Base frequency: 2.49 GHz
DBGvpp# show version verbose
Version: v19.01-rc0~447-g3be662f
Compiled by: vagrant
Compile host: vpp
Compile date: Mon Dec 10 14:55:24 PST 2018
Compile location: /vpp
Compiler: GCC 5.4.0 20160609
Current PID: 14104
Change-Id: I6ff03bc5ad1c3517256e244b6986e9a1507a3349
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-12-10 14:50:13 -08:00
|
|
|
clib_memcpy (&rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
|
2016-12-06 12:50:08 +01:00
|
|
|
rmp->context = mp->context;
|
2018-01-09 06:39:23 -08:00
|
|
|
vl_api_send_msg (reg, (u8 *) rmp);
|
2016-12-06 12:50:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
|
|
|
|
|
{
|
|
|
|
|
vl_api_map_summary_stats_reply_t *rmp;
|
|
|
|
|
vlib_combined_counter_main_t *cm;
|
|
|
|
|
vlib_counter_t v;
|
|
|
|
|
int i, which;
|
|
|
|
|
u64 total_pkts[VLIB_N_RX_TX];
|
|
|
|
|
u64 total_bytes[VLIB_N_RX_TX];
|
|
|
|
|
map_main_t *mm = &map_main;
|
2018-01-09 06:39:23 -08:00
|
|
|
vl_api_registration_t *reg;
|
2016-12-06 12:50:08 +01:00
|
|
|
|
2018-01-09 06:39:23 -08:00
|
|
|
reg = vl_api_client_index_to_registration (mp->client_index);
|
|
|
|
|
if (!reg)
|
2016-12-06 12:50:08 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rmp = vl_msg_api_alloc (sizeof (*rmp));
|
2018-06-22 11:32:12 +02:00
|
|
|
rmp->_vl_msg_id = htons (VL_API_MAP_SUMMARY_STATS_REPLY + mm->msg_id_base);
|
2016-12-06 12:50:08 +01:00
|
|
|
rmp->context = mp->context;
|
|
|
|
|
rmp->retval = 0;
|
|
|
|
|
|
2017-06-26 18:12:37 +02:00
|
|
|
if (pool_elts (mm->domains) == 0)
|
|
|
|
|
{
|
|
|
|
|
rmp->retval = -1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 10:38:51 -04:00
|
|
|
clib_memset (total_pkts, 0, sizeof (total_pkts));
|
|
|
|
|
clib_memset (total_bytes, 0, sizeof (total_bytes));
|
2016-12-06 12:50:08 +01:00
|
|
|
|
|
|
|
|
map_domain_counter_lock (mm);
|
|
|
|
|
vec_foreach (cm, mm->domain_counters)
|
|
|
|
|
{
|
|
|
|
|
which = cm - mm->domain_counters;
|
|
|
|
|
|
2017-03-15 15:41:17 -04:00
|
|
|
for (i = 0; i < vlib_combined_counter_n_counters (cm); i++)
|
2016-12-06 12:50:08 +01:00
|
|
|
{
|
|
|
|
|
vlib_get_combined_counter (cm, i, &v);
|
|
|
|
|
total_pkts[which] += v.packets;
|
|
|
|
|
total_bytes[which] += v.bytes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map_domain_counter_unlock (mm);
|
|
|
|
|
|
|
|
|
|
/* Note: in network byte order! */
|
|
|
|
|
rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
|
|
|
|
|
clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
|
|
|
|
|
rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
|
|
|
|
|
clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
|
|
|
|
|
rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
|
|
|
|
|
clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
|
|
|
|
|
rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
|
|
|
|
|
clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
|
|
|
|
|
rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
|
|
|
|
|
rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
|
|
|
|
|
rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
|
|
|
|
|
clib_host_to_net_u64 (map_error_counter_get
|
|
|
|
|
(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
|
|
|
|
|
rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
|
|
|
|
|
clib_host_to_net_u64 (map_error_counter_get
|
|
|
|
|
(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
|
|
|
|
|
|
2017-06-26 18:12:37 +02:00
|
|
|
out:
|
2018-01-09 06:39:23 -08:00
|
|
|
vl_api_send_msg (reg, (u8 *) rmp);
|
2016-12-06 12:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-06 11:49:17 -06:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
map_param_set_fragmentation (bool inner, bool ignore_df)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
mm->frag_inner = ! !inner;
|
|
|
|
|
mm->frag_ignore_df = ! !ignore_df;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_fragmentation_t_handler
|
|
|
|
|
(vl_api_map_param_set_fragmentation_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_fragmentation_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
rv = map_param_set_fragmentation (mp->inner, mp->ignore_df);
|
|
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_FRAGMENTATION_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
map_param_set_icmp (ip4_address_t * icmp_src_address)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
if (icmp_src_address == 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
mm->icmp4_src_address = *icmp_src_address;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_icmp_t_handler (vl_api_map_param_set_icmp_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_icmp_reply_t *rmp;
|
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
rv = map_param_set_icmp ((ip4_address_t *) & mp->ip4_err_relay_src);
|
|
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_ICMP_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
map_param_set_icmp6 (u8 enable_unreachable)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
mm->icmp6_enabled = ! !enable_unreachable;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_icmp6_t_handler (vl_api_map_param_set_icmp6_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_icmp6_reply_t *rmp;
|
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
rv = map_param_set_icmp6 (mp->enable_unreachable);
|
|
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_ICMP6_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_add_del_pre_resolve_t_handler
|
|
|
|
|
(vl_api_map_param_add_del_pre_resolve_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_add_del_pre_resolve_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
map_pre_resolve ((ip4_address_t *) & mp->ip4_nh_address,
|
2018-12-13 17:48:21 -06:00
|
|
|
(ip6_address_t *) & mp->ip6_nh_address, !mp->is_add);
|
2018-12-06 11:49:17 -06:00
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_ADD_DEL_PRE_RESOLVE_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
map_param_set_security_check (bool enable, bool fragments)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
mm->sec_check = ! !enable;
|
|
|
|
|
mm->sec_check_frag = ! !fragments;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_security_check_t_handler
|
|
|
|
|
(vl_api_map_param_set_security_check_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_security_check_reply_t *rmp;
|
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
rv = map_param_set_security_check (mp->enable, mp->fragments);
|
|
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_SECURITY_CHECK_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
map_param_set_traffic_class (bool copy, u8 tc)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
mm->tc_copy = ! !copy;
|
|
|
|
|
mm->tc = tc;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_traffic_class_t_handler
|
|
|
|
|
(vl_api_map_param_set_traffic_class_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_traffic_class_reply_t *rmp;
|
|
|
|
|
int rv;
|
|
|
|
|
|
2019-08-06 19:58:24 -04:00
|
|
|
rv = map_param_set_traffic_class (mp->copy, mp->tc_class);
|
2018-12-06 11:49:17 -06:00
|
|
|
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_TRAFFIC_CLASS_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-12-17 13:43:52 -06:00
|
|
|
int
|
|
|
|
|
map_param_set_tcp (u16 tcp_mss)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
mm->tcp_mss = tcp_mss;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_param_set_tcp_t_handler (vl_api_map_param_set_tcp_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_set_tcp_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
map_param_set_tcp (ntohs (mp->tcp_mss));
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_PARAM_SET_TCP_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-12-06 11:49:17 -06:00
|
|
|
static void
|
|
|
|
|
vl_api_map_param_get_t_handler (vl_api_map_param_get_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_param_get_reply_t *rmp;
|
|
|
|
|
vl_api_registration_t *reg;
|
|
|
|
|
|
|
|
|
|
reg = vl_api_client_index_to_registration (mp->client_index);
|
|
|
|
|
if (!reg)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rmp = vl_msg_api_alloc (sizeof (*rmp));
|
|
|
|
|
rmp->_vl_msg_id = htons (VL_API_MAP_PARAM_GET_REPLY + mm->msg_id_base);
|
|
|
|
|
rmp->context = mp->context;
|
|
|
|
|
rmp->retval = 0;
|
|
|
|
|
|
|
|
|
|
rmp->frag_inner = mm->frag_inner;
|
|
|
|
|
rmp->frag_ignore_df = mm->frag_ignore_df;
|
|
|
|
|
|
|
|
|
|
clib_memcpy (&rmp->icmp_ip4_err_relay_src,
|
|
|
|
|
&mm->icmp4_src_address, sizeof (rmp->icmp_ip4_err_relay_src));
|
|
|
|
|
|
|
|
|
|
rmp->icmp6_enable_unreachable = mm->icmp6_enabled;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: How are these addresses re-extracted from the FIB?
|
|
|
|
|
* Or should a local map_main copy be kept?
|
|
|
|
|
*/
|
|
|
|
|
clib_memset (&rmp->ip4_nh_address, 0, sizeof (rmp->ip4_nh_address));
|
|
|
|
|
clib_memset (&rmp->ip6_nh_address, 0, sizeof (rmp->ip6_nh_address));
|
|
|
|
|
|
|
|
|
|
rmp->sec_check_enable = mm->sec_check;
|
|
|
|
|
rmp->sec_check_fragments = mm->sec_check_frag;
|
|
|
|
|
|
|
|
|
|
rmp->tc_copy = mm->tc_copy;
|
|
|
|
|
rmp->tc_class = mm->tc;
|
|
|
|
|
|
|
|
|
|
vl_api_send_msg (reg, (u8 *) rmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-12-17 13:43:52 -06:00
|
|
|
int
|
|
|
|
|
map_if_enable_disable (bool is_enable, u32 sw_if_index, bool is_translation)
|
|
|
|
|
{
|
2019-01-03 17:12:59 -06:00
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
|
|
|
|
|
if (pool_is_free_index (mm->vnet_main->interface_main.sw_interfaces,
|
|
|
|
|
sw_if_index))
|
|
|
|
|
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
|
|
|
|
|
|
|
|
|
|
is_enable = ! !is_enable;
|
|
|
|
|
|
|
|
|
|
if (is_translation)
|
|
|
|
|
{
|
|
|
|
|
if (clib_bitmap_get (mm->bm_trans_enabled_by_sw_if, sw_if_index)
|
|
|
|
|
== is_enable)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (clib_bitmap_get (mm->bm_encap_enabled_by_sw_if, sw_if_index)
|
|
|
|
|
== is_enable)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 13:43:52 -06:00
|
|
|
if (is_translation == false)
|
|
|
|
|
{
|
2019-08-21 10:53:14 +00:00
|
|
|
ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable);
|
2019-10-01 13:00:22 +00:00
|
|
|
ip6_full_reass_enable_disable_with_refcnt (sw_if_index, is_enable);
|
2018-12-17 13:43:52 -06:00
|
|
|
vnet_feature_enable_disable ("ip4-unicast", "ip4-map", sw_if_index,
|
|
|
|
|
is_enable ? 1 : 0, 0, 0);
|
|
|
|
|
vnet_feature_enable_disable ("ip6-unicast", "ip6-map", sw_if_index,
|
|
|
|
|
is_enable ? 1 : 0, 0, 0);
|
2019-01-03 17:12:59 -06:00
|
|
|
mm->bm_encap_enabled_by_sw_if =
|
|
|
|
|
clib_bitmap_set (mm->bm_encap_enabled_by_sw_if, sw_if_index,
|
|
|
|
|
is_enable);
|
2018-12-17 13:43:52 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-23 09:00:30 +00:00
|
|
|
ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable);
|
|
|
|
|
ip6_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable);
|
2018-12-17 13:43:52 -06:00
|
|
|
vnet_feature_enable_disable ("ip4-unicast", "ip4-map-t", sw_if_index,
|
|
|
|
|
is_enable ? 1 : 0, 0, 0);
|
|
|
|
|
vnet_feature_enable_disable ("ip6-unicast", "ip6-map-t", sw_if_index,
|
|
|
|
|
is_enable ? 1 : 0, 0, 0);
|
2019-01-03 17:12:59 -06:00
|
|
|
mm->bm_trans_enabled_by_sw_if =
|
|
|
|
|
clib_bitmap_set (mm->bm_trans_enabled_by_sw_if, sw_if_index,
|
|
|
|
|
is_enable);
|
2018-12-17 13:43:52 -06:00
|
|
|
}
|
2019-01-03 17:12:59 -06:00
|
|
|
|
2018-12-17 13:43:52 -06:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vl_api_map_if_enable_disable_t_handler (vl_api_map_if_enable_disable_t * mp)
|
|
|
|
|
{
|
|
|
|
|
map_main_t *mm = &map_main;
|
|
|
|
|
vl_api_map_if_enable_disable_reply_t *rmp;
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
VALIDATE_SW_IF_INDEX (mp);
|
|
|
|
|
|
|
|
|
|
rv =
|
|
|
|
|
map_if_enable_disable (mp->is_enable, htonl (mp->sw_if_index),
|
|
|
|
|
mp->is_translation);
|
|
|
|
|
|
|
|
|
|
BAD_SW_IF_INDEX_LABEL;
|
|
|
|
|
REPLY_MACRO (VL_API_MAP_IF_ENABLE_DISABLE_REPLY);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 01:08:30 +02:00
|
|
|
/* API definitions */
|
|
|
|
|
#include <vnet/format_fns.h>
|
|
|
|
|
#include <map/map.api.c>
|
2016-12-06 12:50:08 +01:00
|
|
|
|
2018-06-22 11:32:12 +02:00
|
|
|
/* Set up the API message handling tables */
|
|
|
|
|
clib_error_t *
|
|
|
|
|
map_plugin_api_hookup (vlib_main_t * vm)
|
2016-12-06 12:50:08 +01:00
|
|
|
{
|
2018-06-22 11:32:12 +02:00
|
|
|
map_main_t *mm = &map_main;
|
2016-12-06 12:50:08 +01:00
|
|
|
|
2019-09-19 01:08:30 +02:00
|
|
|
mm->msg_id_base = setup_message_id_table ();
|
2020-05-18 11:14:05 +02:00
|
|
|
|
2016-12-06 12:50:08 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* fd.io coding-style-patch-verification: ON
|
|
|
|
|
*
|
|
|
|
|
* Local Variables:
|
|
|
|
|
* eval: (c-set-style "gnu")
|
|
|
|
|
* End:
|
|
|
|
|
*/
|