vrf: VRF_DEFAULT must be 0, remove useless code

Code was added in the past to support a value of VRF_DEFAULT different
from 0. This option was abandoned, the default vrf id is always 0.

Remove this code, this will simplify the code and improve performance
(use a constant value instead of a function that performs tests).

Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
This commit is contained in:
Christophe Gouault 2020-08-24 18:01:15 +02:00
parent d58b6f7568
commit 1eb92f06c4
7 changed files with 8 additions and 51 deletions

View File

@ -43,9 +43,6 @@
DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context")
DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name")
/* default NS ID value used when VRF backend is not NETNS */
#define NS_DEFAULT_INTERNAL 0
static inline int ns_compare(const struct ns *ns, const struct ns *ns2);
static struct ns *ns_lookup_name_internal(const char *name);
@ -101,9 +98,6 @@ static inline int setns(int fd, int nstype)
static int have_netns_enabled = -1;
#endif /* HAVE_NETNS */
/* default NS ID value used when VRF backend is not NETNS */
#define NS_DEFAULT_INTERNAL 0
static int have_netns(void)
{
#ifdef HAVE_NETNS
@ -612,15 +606,7 @@ ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid)
return ns->ns_id;
}
ns_id_t ns_get_default_id(void)
{
if (default_ns)
return default_ns->ns_id;
return NS_DEFAULT_INTERNAL;
}
struct ns *ns_get_default(void)
{
return default_ns;
}

View File

@ -110,13 +110,6 @@ void ns_init(void)
{
}
/* API to retrieve default NS */
ns_id_t ns_get_default_id(void)
{
return NS_UNKNOWN;
}
/* API that can be used to change from NS */
int ns_switchback_to_initial(void)
{

View File

@ -161,10 +161,7 @@ extern ns_id_t ns_map_nsid_with_external(ns_id_t ns_id, bool map);
*/
extern void ns_init(void);
/* API to retrieve default NS */
extern ns_id_t ns_get_default_id(void);
#define NS_DEFAULT ns_get_default_id()
#define NS_DEFAULT 0
/* API that can be used to change from NS */
extern int ns_switchback_to_initial(void);

View File

@ -39,8 +39,7 @@
#include "northbound.h"
#include "northbound_cli.h"
/* default VRF ID value used when VRF backend is not NETNS */
#define VRF_DEFAULT_INTERNAL 0
/* default VRF name value used when VRF backend is not NETNS */
#define VRF_DEFAULT_NAME_INTERNAL "default"
DEFINE_MTYPE_STATIC(LIB, VRF, "VRF")
@ -521,7 +520,7 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *),
strlcpy(default_vrf->data.l.netns_name,
VRF_DEFAULT_NAME, NS_NAMSIZ);
ns = ns_lookup(ns_get_default_id());
ns = ns_lookup(NS_DEFAULT);
ns->vrf_ctxt = default_vrf;
default_vrf->ns_ctxt = ns;
}
@ -949,17 +948,6 @@ const char *vrf_get_default_name(void)
return vrf_default_name;
}
vrf_id_t vrf_get_default_id(void)
{
/* backend netns is only known by zebra
* for other daemons, we return VRF_DEFAULT_INTERNAL
*/
if (vrf_is_backend_netns())
return ns_get_default_id();
else
return VRF_DEFAULT_INTERNAL;
}
int vrf_bind(vrf_id_t vrf_id, int fd, const char *name)
{
int ret = 0;

View File

@ -262,12 +262,8 @@ extern int vrf_getaddrinfo(const char *node, const char *service,
extern int vrf_ioctl(vrf_id_t vrf_id, int d, unsigned long request, char *args);
/* function called by macro VRF_DEFAULT
* to get the default VRF_ID
*/
extern vrf_id_t vrf_get_default_id(void);
/* The default VRF ID */
#define VRF_DEFAULT vrf_get_default_id()
#define VRF_DEFAULT 0
extern void vrf_set_default_name(const char *default_name, bool force);
extern const char *vrf_get_default_name(void);

View File

@ -39,9 +39,6 @@
#include "zebra/zebra_netns_id.h"
#include "zebra/zebra_errors.h"
/* default NS ID value used when VRF backend is not NETNS */
#define NS_DEFAULT_INTERNAL 0
/* in case NEWNSID not available, the NSID will be locally obtained
*/
#define NS_BASE_NSID 0
@ -362,14 +359,14 @@ ns_id_t zebra_ns_id_get_default(void)
fd = open(NS_DEFAULT_NAME, O_RDONLY);
if (fd == -1)
return NS_DEFAULT_INTERNAL;
return NS_DEFAULT;
if (!vrf_is_backend_netns()) {
close(fd);
return NS_DEFAULT_INTERNAL;
return NS_DEFAULT;
}
close(fd);
return zebra_ns_id_get((char *)NS_DEFAULT_NAME, -1);
#else /* HAVE_NETNS */
return NS_DEFAULT_INTERNAL;
return NS_DEFAULT;
#endif /* !HAVE_NETNS */
}

View File

@ -199,7 +199,7 @@ int zebra_ns_init(const char *optional_default_name)
if (ns)
ns->relative_default_ns = ns_id;
default_ns = ns_lookup(ns_get_default_id());
default_ns = ns_lookup(NS_DEFAULT);
if (!default_ns) {
flog_err(EC_ZEBRA_NS_NO_DEFAULT,
"%s: failed to find default ns", __func__);