mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 05:33:42 +00:00
Merge pull request #9466 from idryzhov/vrf-netns
lib, zebra: move vrf netns commands from lib to zebra
This commit is contained in:
commit
3e324ff419
63
lib/vrf.c
63
lib/vrf.c
@ -58,7 +58,6 @@ struct vrf_name_head vrfs_by_name = RB_INITIALIZER(&vrfs_by_name);
|
|||||||
|
|
||||||
static int vrf_backend;
|
static int vrf_backend;
|
||||||
static int vrf_backend_configured;
|
static int vrf_backend_configured;
|
||||||
static struct zebra_privs_t *vrf_daemon_privs;
|
|
||||||
static char vrf_default_name[VRF_NAMSIZ] = VRF_DEFAULT_NAME_INTERNAL;
|
static char vrf_default_name[VRF_NAMSIZ] = VRF_DEFAULT_NAME_INTERNAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -856,62 +855,6 @@ static struct cmd_node vrf_node = {
|
|||||||
.prompt = "%s(config-vrf)# ",
|
.prompt = "%s(config-vrf)# ",
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFUN_NOSH (vrf_netns,
|
|
||||||
vrf_netns_cmd,
|
|
||||||
"netns NAME",
|
|
||||||
"Attach VRF to a Namespace\n"
|
|
||||||
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
|
||||||
{
|
|
||||||
int idx_name = 1, ret;
|
|
||||||
char *pathname = ns_netns_pathname(vty, argv[idx_name]->arg);
|
|
||||||
|
|
||||||
VTY_DECLVAR_CONTEXT(vrf, vrf);
|
|
||||||
|
|
||||||
if (!pathname)
|
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
|
||||||
|
|
||||||
frr_with_privs(vrf_daemon_privs) {
|
|
||||||
ret = vrf_netns_handler_create(vty, vrf, pathname,
|
|
||||||
NS_UNKNOWN,
|
|
||||||
NS_UNKNOWN,
|
|
||||||
NS_UNKNOWN);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN_NOSH (no_vrf_netns,
|
|
||||||
no_vrf_netns_cmd,
|
|
||||||
"no netns [NAME]",
|
|
||||||
NO_STR
|
|
||||||
"Detach VRF from a Namespace\n"
|
|
||||||
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
|
||||||
{
|
|
||||||
struct ns *ns = NULL;
|
|
||||||
|
|
||||||
VTY_DECLVAR_CONTEXT(vrf, vrf);
|
|
||||||
|
|
||||||
if (!vrf_is_backend_netns()) {
|
|
||||||
vty_out(vty, "VRF backend is not Netns. Aborting\n");
|
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
|
||||||
}
|
|
||||||
if (!vrf->ns_ctxt) {
|
|
||||||
vty_out(vty, "VRF %s(%u) is not configured with NetNS\n",
|
|
||||||
vrf->name, vrf->vrf_id);
|
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ns = (struct ns *)vrf->ns_ctxt;
|
|
||||||
|
|
||||||
ns->vrf_ctxt = NULL;
|
|
||||||
vrf_disable(vrf);
|
|
||||||
/* vrf ID from VRF is necessary for Zebra
|
|
||||||
* so that propagate to other clients is done
|
|
||||||
*/
|
|
||||||
ns_delete(ns);
|
|
||||||
vrf->ns_ctxt = NULL;
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Debug CLI for vrf's
|
* Debug CLI for vrf's
|
||||||
*/
|
*/
|
||||||
@ -973,12 +916,6 @@ void vrf_cmd_init(int (*writefunc)(struct vty *vty),
|
|||||||
install_node(&vrf_node);
|
install_node(&vrf_node);
|
||||||
install_default(VRF_NODE);
|
install_default(VRF_NODE);
|
||||||
install_element(VRF_NODE, &vrf_exit_cmd);
|
install_element(VRF_NODE, &vrf_exit_cmd);
|
||||||
if (vrf_is_backend_netns() && ns_have_netns()) {
|
|
||||||
/* Install NS commands. */
|
|
||||||
vrf_daemon_privs = daemon_privs;
|
|
||||||
install_element(VRF_NODE, &vrf_netns_cmd);
|
|
||||||
install_element(VRF_NODE, &no_vrf_netns_cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vrf_set_default_name(const char *default_name, bool force)
|
void vrf_set_default_name(const char *default_name, bool force)
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include "vtysh/vtysh.h"
|
#include "vtysh/vtysh.h"
|
||||||
#include "vtysh/vtysh_daemons.h"
|
#include "vtysh/vtysh_daemons.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "ns.h"
|
|
||||||
#include "vrf.h"
|
#include "vrf.h"
|
||||||
#include "libfrr.h"
|
#include "libfrr.h"
|
||||||
#include "command_graph.h"
|
#include "command_graph.h"
|
||||||
@ -2744,17 +2743,6 @@ DEFUNSH(VTYSH_VRF, vtysh_vrf, vtysh_vrf_cmd, "vrf NAME",
|
|||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFSH(VTYSH_ZEBRA, vtysh_vrf_netns_cmd,
|
|
||||||
"netns NAME",
|
|
||||||
"Attach VRF to a Namespace\n"
|
|
||||||
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
|
||||||
|
|
||||||
DEFSH(VTYSH_ZEBRA, vtysh_no_vrf_netns_cmd,
|
|
||||||
"no netns [NAME]",
|
|
||||||
NO_STR
|
|
||||||
"Detach VRF from a Namespace\n"
|
|
||||||
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
|
||||||
|
|
||||||
DEFUNSH(VTYSH_VRF, vtysh_exit_vrf, vtysh_exit_vrf_cmd, "exit",
|
DEFUNSH(VTYSH_VRF, vtysh_exit_vrf, vtysh_exit_vrf_cmd, "exit",
|
||||||
"Exit current mode and down to previous mode\n")
|
"Exit current mode and down to previous mode\n")
|
||||||
{
|
{
|
||||||
@ -4472,8 +4460,6 @@ void vtysh_init_vty(void)
|
|||||||
|
|
||||||
install_node(&vrf_node);
|
install_node(&vrf_node);
|
||||||
install_element(CONFIG_NODE, &vtysh_vrf_cmd);
|
install_element(CONFIG_NODE, &vtysh_vrf_cmd);
|
||||||
install_element(VRF_NODE, &vtysh_vrf_netns_cmd);
|
|
||||||
install_element(VRF_NODE, &vtysh_no_vrf_netns_cmd);
|
|
||||||
install_element(VRF_NODE, &exit_vrf_config_cmd);
|
install_element(VRF_NODE, &exit_vrf_config_cmd);
|
||||||
install_element(VRF_NODE, &vtysh_end_all_cmd);
|
install_element(VRF_NODE, &vtysh_end_all_cmd);
|
||||||
install_element(VRF_NODE, &vtysh_exit_vrf_cmd);
|
install_element(VRF_NODE, &vtysh_exit_vrf_cmd);
|
||||||
|
@ -19,6 +19,7 @@ vtysh_scan += \
|
|||||||
zebra/zebra_routemap.c \
|
zebra/zebra_routemap.c \
|
||||||
zebra/zebra_vty.c \
|
zebra/zebra_vty.c \
|
||||||
zebra/zserv.c \
|
zebra/zserv.c \
|
||||||
|
zebra/zebra_vrf.c \
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# can be loaded as DSO - always include for vtysh
|
# can be loaded as DSO - always include for vtysh
|
||||||
@ -132,6 +133,7 @@ clippy_scan += \
|
|||||||
zebra/zebra_routemap.c \
|
zebra/zebra_routemap.c \
|
||||||
zebra/zebra_vty.c \
|
zebra/zebra_vty.c \
|
||||||
zebra/zebra_srv6_vty.c \
|
zebra/zebra_srv6_vty.c \
|
||||||
|
zebra/zebra_vrf.c \
|
||||||
# end
|
# end
|
||||||
|
|
||||||
noinst_HEADERS += \
|
noinst_HEADERS += \
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
#include "zebra/zebra_vxlan.h"
|
#include "zebra/zebra_vxlan.h"
|
||||||
#include "zebra/zebra_netns_notify.h"
|
#include "zebra/zebra_netns_notify.h"
|
||||||
#include "zebra/zebra_routemap.h"
|
#include "zebra/zebra_routemap.h"
|
||||||
|
#ifndef VTYSH_EXTRACT_PL
|
||||||
|
#include "zebra/zebra_vrf_clippy.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void zebra_vrf_table_create(struct zebra_vrf *zvrf, afi_t afi,
|
static void zebra_vrf_table_create(struct zebra_vrf *zvrf, afi_t afi,
|
||||||
safi_t safi);
|
safi_t safi);
|
||||||
@ -528,6 +531,63 @@ static int vrf_config_write(struct vty *vty)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFPY (vrf_netns,
|
||||||
|
vrf_netns_cmd,
|
||||||
|
"netns NAME$netns_name",
|
||||||
|
"Attach VRF to a Namespace\n"
|
||||||
|
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
||||||
|
{
|
||||||
|
char *pathname = ns_netns_pathname(vty, netns_name);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
VTY_DECLVAR_CONTEXT(vrf, vrf);
|
||||||
|
|
||||||
|
if (!pathname)
|
||||||
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
|
||||||
|
frr_with_privs(&zserv_privs) {
|
||||||
|
ret = vrf_netns_handler_create(vty, vrf, pathname,
|
||||||
|
NS_UNKNOWN,
|
||||||
|
NS_UNKNOWN,
|
||||||
|
NS_UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFUN (no_vrf_netns,
|
||||||
|
no_vrf_netns_cmd,
|
||||||
|
"no netns [NAME]",
|
||||||
|
NO_STR
|
||||||
|
"Detach VRF from a Namespace\n"
|
||||||
|
"The file name in " NS_RUN_DIR ", or a full pathname\n")
|
||||||
|
{
|
||||||
|
struct ns *ns = NULL;
|
||||||
|
|
||||||
|
VTY_DECLVAR_CONTEXT(vrf, vrf);
|
||||||
|
|
||||||
|
if (!vrf_is_backend_netns()) {
|
||||||
|
vty_out(vty, "VRF backend is not Netns. Aborting\n");
|
||||||
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
}
|
||||||
|
if (!vrf->ns_ctxt) {
|
||||||
|
vty_out(vty, "VRF %s(%u) is not configured with NetNS\n",
|
||||||
|
vrf->name, vrf->vrf_id);
|
||||||
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
ns = (struct ns *)vrf->ns_ctxt;
|
||||||
|
|
||||||
|
ns->vrf_ctxt = NULL;
|
||||||
|
vrf_disable(vrf);
|
||||||
|
/* vrf ID from VRF is necessary for Zebra
|
||||||
|
* so that propagate to other clients is done
|
||||||
|
*/
|
||||||
|
ns_delete(ns);
|
||||||
|
vrf->ns_ctxt = NULL;
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* Zebra VRF initialization. */
|
/* Zebra VRF initialization. */
|
||||||
void zebra_vrf_init(void)
|
void zebra_vrf_init(void)
|
||||||
{
|
{
|
||||||
@ -535,4 +595,10 @@ void zebra_vrf_init(void)
|
|||||||
zebra_vrf_delete, zebra_vrf_update);
|
zebra_vrf_delete, zebra_vrf_update);
|
||||||
|
|
||||||
vrf_cmd_init(vrf_config_write, &zserv_privs);
|
vrf_cmd_init(vrf_config_write, &zserv_privs);
|
||||||
|
|
||||||
|
if (vrf_is_backend_netns() && ns_have_netns()) {
|
||||||
|
/* Install NS commands. */
|
||||||
|
install_element(VRF_NODE, &vrf_netns_cmd);
|
||||||
|
install_element(VRF_NODE, &no_vrf_netns_cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user