Files
lcpng/lcpng_if_cli.c
Pim van Pelt ca273dc953 Remove ability to override netns
This gives a lot of operational problems later. It's definitely reasonable
to be able to create tap interfaces in other namespaces, and this is
still possible (see below for syntax).

However, changing the runtime netns makes the netlink listener much more
complicated because it will have to listen on not just one netns, but all
of them, for netlink updates.

So, for now, let's remove the ability to set the namespace in the API.
Still possible:
- set at startup.conf in lcpng { netns <x> }
- force creating in 'lcpng create ... netns <x>'

This will nudge folks to create one singular namespace (say,
'dataplane', in the startup.conf), and then handle all netlink messages
in that namespace only.
2021-08-08 20:54:43 +02:00

204 lines
5.0 KiB
C

/* Hey Emacs use -*- mode: C -*- */
/*
* Copyright 2020 Rubicon Communications, LLC.
*
* 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.
*/
#include <sys/socket.h>
#include <linux/if.h>
#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/app/version.h>
#include <vnet/format_fns.h>
#include <plugins/lcpng/lcpng_interface.h>
static clib_error_t *
lcp_itf_pair_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
vnet_main_t *vnm = vnet_get_main ();
u32 sw_if_index;
u8 *host_if_name;
lip_host_type_t host_if_type;
u8 *ns;
int r;
if (!unformat_user (input, unformat_line_input, line_input))
return 0;
sw_if_index = ~0;
host_if_name = ns = NULL;
host_if_type = LCP_ITF_HOST_TAP;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "%d", &sw_if_index))
;
else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm,
&sw_if_index))
;
else if (unformat (line_input, "host-if %s", &host_if_name))
;
else if (unformat (line_input, "netns %s", &ns))
;
else if (unformat (line_input, "tun"))
host_if_type = LCP_ITF_HOST_TUN;
else
{
unformat_free (line_input);
vec_free (host_if_name);
vec_free (ns);
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
}
}
unformat_free (line_input);
if (!host_if_name)
{
vec_free (ns);
return clib_error_return (0, "host interface name required");
}
if (sw_if_index == ~0)
{
vec_free (host_if_name);
vec_free (ns);
return clib_error_return (0, "interface name or sw_if_index required");
}
if (vec_len (ns) >= LCP_NS_LEN)
{
vec_free (host_if_name);
vec_free (ns);
return clib_error_return (
0, "Namespace name should be fewer than %d characters", LCP_NS_LEN);
}
r = lcp_itf_pair_create (sw_if_index, host_if_name, host_if_type, ns, NULL);
vec_free (host_if_name);
vec_free (ns);
if (r)
return clib_error_return (0, "lcpng pair creation failed (%d)", r);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_create_command, static) = {
.path = "lcpng create",
.short_help = "lcpng create <sw_if_index>|<if-name> host-if <host-if-name> "
"netns <namespace> [tun]",
.function = lcp_itf_pair_create_command_fn,
};
static clib_error_t *
lcp_itf_pair_delete_command_fn (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
{
vnet_main_t *vnm = vnet_get_main ();
unformat_input_t _line_input, *line_input = &_line_input;
u32 sw_if_index;
int r;
if (!unformat_user (input, unformat_line_input, line_input))
return 0;
sw_if_index = ~0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "%d", &sw_if_index))
;
else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm,
&sw_if_index))
;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
}
unformat_free (line_input);
if (sw_if_index == ~0)
return clib_error_return (0, "interface name or sw_if_index required");
r = lcp_itf_pair_delete (sw_if_index);
if (r)
return clib_error_return (0, "lcpng pair deletion failed (%d)", r);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_delete_command, static) = {
.path = "lcpng delete",
.short_help = "lcpng delete <sw_if_index>|<if-name>",
.function = lcp_itf_pair_delete_command_fn,
};
static clib_error_t *
lcp_itf_pair_show_cmd (vlib_main_t *vm, unformat_input_t *input,
vlib_cli_command_t *cmd)
{
vnet_main_t *vnm = vnet_get_main ();
u32 phy_sw_if_index;
phy_sw_if_index = ~0;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "phy %U", unformat_vnet_sw_interface, vnm,
&phy_sw_if_index))
;
else
return clib_error_return (0, "unknown input '%U'",
format_unformat_error, input);
}
lcp_itf_pair_show (phy_sw_if_index);
return 0;
}
VLIB_CLI_COMMAND (lcp_itf_pair_show_cmd_node, static) = {
.path = "show lcpng",
.function = lcp_itf_pair_show_cmd,
.short_help = "show lcpng [phy <interface>]",
.is_mp_safe = 1,
};
clib_error_t *
lcp_cli_init (vlib_main_t *vm)
{
return 0;
}
VLIB_INIT_FUNCTION (lcp_cli_init);
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/