forked from Mirror/frr
zebra/lib: move some code around
* move netlink code from zebra_nc.c to kernel_netlink.c; * move vrf CLI commands from if.c/interface.c to vrf.c/zebra_vrf.c; * move declaration of the 'ns' structure to a header file. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
1fbe3e585d
commit
f30c50b992
54
lib/if.c
54
lib/if.c
|
@ -840,60 +840,6 @@ ALIAS (no_interface,
|
||||||
"Interface's name\n"
|
"Interface's name\n"
|
||||||
VRF_CMD_HELP_STR)
|
VRF_CMD_HELP_STR)
|
||||||
|
|
||||||
DEFUN (vrf,
|
|
||||||
vrf_cmd,
|
|
||||||
"vrf NAME",
|
|
||||||
"Select a VRF to configure\n"
|
|
||||||
"VRF's name\n")
|
|
||||||
{
|
|
||||||
struct vrf *vrfp;
|
|
||||||
size_t sl;
|
|
||||||
|
|
||||||
if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
|
|
||||||
{
|
|
||||||
vty_out (vty, "%% VRF name %s is invalid: length exceeds "
|
|
||||||
"%d characters%s",
|
|
||||||
argv[0], VRF_NAMSIZ, VTY_NEWLINE);
|
|
||||||
return CMD_WARNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
vrfp = vrf_get (VRF_UNKNOWN, argv[0]);
|
|
||||||
|
|
||||||
VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN_NOSH (no_vrf,
|
|
||||||
no_vrf_cmd,
|
|
||||||
"no vrf NAME",
|
|
||||||
NO_STR
|
|
||||||
"Delete a pseudo VRF's configuration\n"
|
|
||||||
"VRF's name\n")
|
|
||||||
{
|
|
||||||
struct vrf *vrfp;
|
|
||||||
|
|
||||||
vrfp = vrf_list_lookup_by_name (argv[0]);
|
|
||||||
|
|
||||||
if (vrfp == NULL)
|
|
||||||
{
|
|
||||||
vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
|
|
||||||
return CMD_WARNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CHECK_FLAG (vrfp->status, VRF_ACTIVE))
|
|
||||||
{
|
|
||||||
vty_out (vty, "%% Only inactive VRFs can be deleted%s",
|
|
||||||
VTY_NEWLINE);
|
|
||||||
return CMD_WARNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
vrf_delete(vrfp);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* For debug purpose. */
|
/* For debug purpose. */
|
||||||
DEFUN (show_address,
|
DEFUN (show_address,
|
||||||
show_address_cmd,
|
show_address_cmd,
|
||||||
|
|
16
lib/ns.c
16
lib/ns.c
|
@ -91,22 +91,6 @@ static int have_netns(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ns
|
|
||||||
{
|
|
||||||
/* Identifier, same as the vector index */
|
|
||||||
ns_id_t ns_id;
|
|
||||||
/* Name */
|
|
||||||
char *name;
|
|
||||||
/* File descriptor */
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Master list of interfaces belonging to this NS */
|
|
||||||
struct list *iflist;
|
|
||||||
|
|
||||||
/* User data */
|
|
||||||
void *info;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Holding NS hooks */
|
/* Holding NS hooks */
|
||||||
struct ns_master
|
struct ns_master
|
||||||
{
|
{
|
||||||
|
|
16
lib/ns.h
16
lib/ns.h
|
@ -33,6 +33,22 @@ typedef u_int16_t ns_id_t;
|
||||||
/* Default netns directory (Linux) */
|
/* Default netns directory (Linux) */
|
||||||
#define NS_RUN_DIR "/var/run/netns"
|
#define NS_RUN_DIR "/var/run/netns"
|
||||||
|
|
||||||
|
struct ns
|
||||||
|
{
|
||||||
|
/* Identifier, same as the vector index */
|
||||||
|
ns_id_t ns_id;
|
||||||
|
/* Name */
|
||||||
|
char *name;
|
||||||
|
/* File descriptor */
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
/* Master list of interfaces belonging to this NS */
|
||||||
|
struct list *iflist;
|
||||||
|
|
||||||
|
/* User data */
|
||||||
|
void *info;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NS hooks
|
* NS hooks
|
||||||
*/
|
*/
|
||||||
|
|
54
lib/vrf.c
54
lib/vrf.c
|
@ -740,6 +740,60 @@ vrf_socket (int domain, int type, int protocol, vrf_id_t vrf_id)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vrf CLI commands */
|
||||||
|
DEFUN (vrf,
|
||||||
|
vrf_cmd,
|
||||||
|
"vrf NAME",
|
||||||
|
"Select a VRF to configure\n"
|
||||||
|
"VRF's name\n")
|
||||||
|
{
|
||||||
|
struct vrf *vrfp;
|
||||||
|
size_t sl;
|
||||||
|
|
||||||
|
if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
|
||||||
|
{
|
||||||
|
vty_out (vty, "%% VRF name %s is invalid: length exceeds "
|
||||||
|
"%d characters%s",
|
||||||
|
argv[0], VRF_NAMSIZ, VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
vrfp = vrf_get (VRF_UNKNOWN, argv[0]);
|
||||||
|
|
||||||
|
VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp);
|
||||||
|
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFUN_NOSH (no_vrf,
|
||||||
|
no_vrf_cmd,
|
||||||
|
"no vrf NAME",
|
||||||
|
NO_STR
|
||||||
|
"Delete a pseudo VRF's configuration\n"
|
||||||
|
"VRF's name\n")
|
||||||
|
{
|
||||||
|
struct vrf *vrfp;
|
||||||
|
|
||||||
|
vrfp = vrf_list_lookup_by_name (argv[0]);
|
||||||
|
|
||||||
|
if (vrfp == NULL)
|
||||||
|
{
|
||||||
|
vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CHECK_FLAG (vrfp->status, VRF_ACTIVE))
|
||||||
|
{
|
||||||
|
vty_out (vty, "%% Only inactive VRFs can be deleted%s",
|
||||||
|
VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
vrf_delete(vrfp);
|
||||||
|
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Debug CLI for vrf's
|
* Debug CLI for vrf's
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1289,33 +1289,6 @@ struct cmd_node interface_node =
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Wrapper hook point for zebra daemon so that ifindex can be set
|
|
||||||
* DEFUN macro not used as extract.pl HAS to ignore this
|
|
||||||
* See also interface_cmd in lib/if.c
|
|
||||||
*/
|
|
||||||
DEFUN_NOSH (zebra_vrf,
|
|
||||||
zebra_vrf_cmd,
|
|
||||||
"vrf NAME",
|
|
||||||
"Select a VRF to configure\n"
|
|
||||||
"VRF's name\n")
|
|
||||||
{
|
|
||||||
// VTY_DECLVAR_CONTEXT (vrf, vrfp);
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Call lib vrf() */
|
|
||||||
if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cmd_node vrf_node =
|
|
||||||
{
|
|
||||||
VRF_NODE,
|
|
||||||
"%s(config-vrf)# ",
|
|
||||||
1
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Show all interfaces to vty. */
|
/* Show all interfaces to vty. */
|
||||||
DEFUN (show_interface, show_interface_cmd,
|
DEFUN (show_interface, show_interface_cmd,
|
||||||
"show interface",
|
"show interface",
|
||||||
|
@ -2929,23 +2902,6 @@ if_config_write (struct vty *vty)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
vrf_config_write (struct vty *vty)
|
|
||||||
{
|
|
||||||
struct listnode *node;
|
|
||||||
struct zebra_vrf *zvrf;
|
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
|
|
||||||
{
|
|
||||||
if (strcmp(zvrf->name, VRF_DEFAULT_NAME))
|
|
||||||
{
|
|
||||||
vty_out (vty, "vrf %s%s", zvrf->name, VTY_NEWLINE);
|
|
||||||
vty_out (vty, "!%s", VTY_NEWLINE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate and initialize interface vector. */
|
/* Allocate and initialize interface vector. */
|
||||||
void
|
void
|
||||||
zebra_if_init (void)
|
zebra_if_init (void)
|
||||||
|
@ -2957,7 +2913,6 @@ zebra_if_init (void)
|
||||||
/* Install configuration write function. */
|
/* Install configuration write function. */
|
||||||
install_node (&interface_node, if_config_write);
|
install_node (&interface_node, if_config_write);
|
||||||
install_node (&link_params_node, NULL);
|
install_node (&link_params_node, NULL);
|
||||||
install_node (&vrf_node, vrf_config_write);
|
|
||||||
|
|
||||||
install_element (VIEW_NODE, &show_interface_cmd);
|
install_element (VIEW_NODE, &show_interface_cmd);
|
||||||
install_element (VIEW_NODE, &show_interface_vrf_cmd);
|
install_element (VIEW_NODE, &show_interface_vrf_cmd);
|
||||||
|
@ -3020,8 +2975,4 @@ zebra_if_init (void)
|
||||||
install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
|
install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
|
||||||
install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
|
install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
|
||||||
install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
|
install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
|
||||||
|
|
||||||
install_element (CONFIG_NODE, &zebra_vrf_cmd);
|
|
||||||
install_element (CONFIG_NODE, &no_vrf_cmd);
|
|
||||||
install_default (VRF_NODE);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,11 +716,18 @@ kernel_init (struct zebra_ns *zns)
|
||||||
{
|
{
|
||||||
unsigned long groups;
|
unsigned long groups;
|
||||||
|
|
||||||
groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR;
|
/* Initialize netlink sockets */
|
||||||
#ifdef HAVE_IPV6
|
groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR |
|
||||||
groups |= RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR;
|
RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR;
|
||||||
#endif /* HAVE_IPV6 */
|
|
||||||
|
snprintf (zns->netlink.name, sizeof (zns->netlink.name),
|
||||||
|
"netlink-listen (NS %u)", zns->ns_id);
|
||||||
|
zns->netlink.sock = -1;
|
||||||
netlink_socket (&zns->netlink, groups, zns->ns_id);
|
netlink_socket (&zns->netlink, groups, zns->ns_id);
|
||||||
|
|
||||||
|
snprintf (zns->netlink_cmd.name, sizeof (zns->netlink_cmd.name),
|
||||||
|
"netlink-cmd (NS %u)", zns->ns_id);
|
||||||
|
zns->netlink_cmd.sock = -1;
|
||||||
netlink_socket (&zns->netlink_cmd, 0, zns->ns_id);
|
netlink_socket (&zns->netlink_cmd, 0, zns->ns_id);
|
||||||
|
|
||||||
/* Register kernel socket. */
|
/* Register kernel socket. */
|
||||||
|
|
|
@ -50,16 +50,6 @@ zebra_ns_enable (ns_id_t ns_id, void **info)
|
||||||
rtadv_init (zns);
|
rtadv_init (zns);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NETLINK
|
|
||||||
/* Initialize netlink sockets */
|
|
||||||
snprintf (zns->netlink.name, sizeof (zns->netlink.name),
|
|
||||||
"netlink-listen (NS %u)", ns_id);
|
|
||||||
zns->netlink.sock = -1;
|
|
||||||
|
|
||||||
snprintf (zns->netlink_cmd.name, sizeof (zns->netlink_cmd.name),
|
|
||||||
"netlink-cmd (NS %u)", ns_id);
|
|
||||||
zns->netlink_cmd.sock = -1;
|
|
||||||
#endif
|
|
||||||
zns->if_table = route_table_init ();
|
zns->if_table = route_table_init ();
|
||||||
kernel_init (zns);
|
kernel_init (zns);
|
||||||
interface_list (zns);
|
interface_list (zns);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "linklist.h"
|
#include "linklist.h"
|
||||||
|
#include "command.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
#include "zebra/debug.h"
|
#include "zebra/debug.h"
|
||||||
|
@ -427,6 +428,50 @@ zebra_vrf_other_route_table (afi_t afi, u_int32_t table_id, vrf_id_t vrf_id)
|
||||||
return zvrf->table[afi][SAFI_UNICAST];
|
return zvrf->table[afi][SAFI_UNICAST];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wrapper hook point for zebra daemon so that ifindex can be set
|
||||||
|
* DEFUN macro not used as extract.pl HAS to ignore this
|
||||||
|
* See also interface_cmd in lib/if.c
|
||||||
|
*/
|
||||||
|
DEFUN_NOSH (zebra_vrf,
|
||||||
|
zebra_vrf_cmd,
|
||||||
|
"vrf NAME",
|
||||||
|
"Select a VRF to configure\n"
|
||||||
|
"VRF's name\n")
|
||||||
|
{
|
||||||
|
// VTY_DECLVAR_CONTEXT (vrf, vrfp);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Call lib vrf() */
|
||||||
|
if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vrf_config_write (struct vty *vty)
|
||||||
|
{
|
||||||
|
struct listnode *node;
|
||||||
|
struct zebra_vrf *zvrf;
|
||||||
|
|
||||||
|
for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
|
||||||
|
{
|
||||||
|
if (strcmp(zvrf->name, VRF_DEFAULT_NAME))
|
||||||
|
{
|
||||||
|
vty_out (vty, "vrf %s%s", zvrf->name, VTY_NEWLINE);
|
||||||
|
vty_out (vty, "!%s", VTY_NEWLINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cmd_node vrf_node =
|
||||||
|
{
|
||||||
|
VRF_NODE,
|
||||||
|
"%s(config-vrf)# ",
|
||||||
|
1
|
||||||
|
};
|
||||||
|
|
||||||
/* Zebra VRF initialization. */
|
/* Zebra VRF initialization. */
|
||||||
void
|
void
|
||||||
zebra_vrf_init (void)
|
zebra_vrf_init (void)
|
||||||
|
@ -439,4 +484,9 @@ zebra_vrf_init (void)
|
||||||
zvrf_list = list_new ();
|
zvrf_list = list_new ();
|
||||||
|
|
||||||
vrf_init ();
|
vrf_init ();
|
||||||
|
|
||||||
|
install_node (&vrf_node, vrf_config_write);
|
||||||
|
install_default (VRF_NODE);
|
||||||
|
install_element (CONFIG_NODE, &zebra_vrf_cmd);
|
||||||
|
install_element (CONFIG_NODE, &no_vrf_cmd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue