struct memory_list memory_list_zebra[] =
{
{ MTYPE_RTADV_PREFIX, "Router Advertisement Prefix" },
+ { MTYPE_ZEBRA_NS, "Zebra Name Space" },
{ MTYPE_ZEBRA_VRF, "ZEBRA VRF" },
{ MTYPE_NEXTHOP, "Nexthop" },
{ MTYPE_RIB, "RIB" },
zserv.c main.c interface.c connected.c zebra_rib.c zebra_routemap.c \
redistribute.c debug.c rtadv.c zebra_snmp.c zebra_vty.c \
irdp_main.c irdp_interface.c irdp_packet.c router-id.c zebra_fpm.c \
- $(othersrc) zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c
+ $(othersrc) zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c \
+ zebra_ns.c
testzebra_SOURCES = test_main.c zebra_rib.c interface.c connected.c debug.c \
- zebra_vty.c zebra_ptm.c zebra_routemap.c \
+ zebra_vty.c zebra_ptm.c zebra_routemap.c zebra_ns.c \
kernel_null.c redistribute_null.c ioctl_null.c misc_null.c zebra_rnh_null.c \
- zebra_ptm_null.c rtadv_null.c
+ zebra_ptm_null.c rtadv_null.c if_null.c
noinst_HEADERS = \
connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
interface.h ipforward.h irdp.h router-id.h kernel_socket.h \
rt_netlink.h zebra_fpm.h zebra_fpm_private.h zebra_rnh.h \
- zebra_ptm_redistribute.h zebra_ptm.h zebra_routemap.h
+ zebra_ptm_redistribute.h zebra_ptm.h zebra_routemap.h \
+ zebra_ns.h
zebra_LDADD = $(otherobj) ../lib/libzebra.la $(LIBCAP) $(LIB_IPV6)
--- /dev/null
+/*
+ * Copyright (C) 2015 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * This file is part of Quagga.
+ *
+ * Quagga is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * Quagga is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Quagga; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <zebra.h>
+
+#include <vrf.h>
+#include <prefix.h>
+
+#include <rtadv.h>
+#include <zebra_ns.h>
+
+void interface_list (struct zebra_ns *zns)
+{ return; }
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
+#include "zebra/zebra_ns.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/irdp.h"
#include "zebra/zebra_ptm.h"
#include "zebra/rt_netlink.h"
-#include "zebra/zserv.h"
#include "zebra/interface.h"
+#include "zebra/zebra_ns.h"
#define ZEBRA_PTM_SUPPORT
static void if_down_del_nbr_connected (struct interface *ifp);
-struct zebra_ns *dzns;
-
/* Called when new interface is added. */
static int
if_zebra_new_hook (struct interface *ifp)
{
struct zebra_if *if_data;
- if_link_per_ns(dzns, ifp);
+ if_link_per_ns(zebra_ns_lookup (NS_DEFAULT), ifp);
if_data = ifp->info;
if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
#include "zebra/rtadv.h"
#include "zebra/zebra_fpm.h"
#include "zebra/zebra_ptm.h"
+#include "zebra/zebra_ns.h"
#include "zebra/redistribute.h"
#define ZEBRA_PTM_SUPPORT
/* Process ID saved for use by init system */
const char *pid_file = PATH_ZEBRA_PID;
-static int zebra_ns_disable (ns_id_t ns_id, void **info);
-
/* Help information display. */
static void
usage (char *progname, int status)
static void
sigint (void)
{
+ struct zebra_ns *zns;
+
zlog_notice ("Terminating on signal");
if (!retain_mode)
#endif
zebra_ptm_finish();
- zebra_ns_disable (0, (void **)&dzns);
+
+ zns = zebra_ns_lookup (NS_DEFAULT);
+ zebra_ns_disable (0, (void **)&zns);
systemd_send_stopping();
exit (0);
}
if (! zvrf)
{
zvrf = zebra_vrf_alloc (vrf_id, name);
- zvrf->zns = dzns; /* Point to the global (single) NS */
+ zvrf->zns = zebra_ns_lookup (NS_DEFAULT); /* Point to the global (single) NS */
*info = (void *)zvrf;
router_id_init (zvrf);
}
return 0;
}
-static int
-zebra_ns_enable (ns_id_t ns_id, void **info)
-{
- struct zebra_ns *zns = (struct zebra_ns *) (*info);
-#ifdef HAVE_NETLINK
- char nl_name[64];
-#endif
-
-#if defined (HAVE_RTADV)
- rtadv_init (zns);
-#endif
-
-#ifdef HAVE_NETLINK
- /* Initialize netlink sockets */
- snprintf (nl_name, 64, "netlink-listen (NS %u)", ns_id);
- zns->netlink.sock = -1;
- zns->netlink.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name);
-
- snprintf (nl_name, 64, "netlink-cmd (NS %u)", ns_id);
- zns->netlink_cmd.sock = -1;
- zns->netlink_cmd.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name);
-#endif
- zns->if_table = route_table_init ();
- kernel_init (zns);
- interface_list (zns);
- route_read (zns);
-
- return 0;
-}
-
/* Callback upon enabling a VRF. */
static int
zebra_vrf_enable (vrf_id_t vrf_id, const char *name, void **info)
return 0;
}
-static int
-zebra_ns_disable (ns_id_t ns_id, void **info)
-{
- struct zebra_ns *zns = (struct zebra_ns *) (*info);
-
-#if defined (HAVE_RTADV)
- rtadv_terminate (zns);
-#endif
-
- kernel_terminate (zns);
-
- return 0;
-}
-
/* Callback upon disabling a VRF. */
static int
zebra_vrf_disable (vrf_id_t vrf_id, const char *name, void **info)
}
/* Zebra VRF initialization. */
-static void
+void
zebra_vrf_init (void)
{
- struct zebra_ns *zns;
-
vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
vrf_add_hook (VRF_ENABLE_HOOK, zebra_vrf_enable);
vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable);
vrf_add_hook (VRF_DELETE_HOOK, zebra_vrf_delete);
-
- /* Default NS initialization */
-
- zns = XCALLOC (MTYPE_ZEBRA_VRF, sizeof (struct zebra_ns));
- dzns = zns; //Pending: Doing it all for the default namespace only for now.
vrf_init ();
- zebra_ns_enable (0, (void **)&zns);
}
/* Main startup routine. */
/* For debug purpose. */
/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
- /* Initialize VRF module, and make kernel routing socket. */
- zebra_vrf_init ();
+ /* Initialize NS( and implicitly the VRF module), and make kernel routing socket. */
+ zebra_ns_init ();
#ifdef HAVE_SNMP
zebra_snmp_init ();
};
#endif /* HAVE_RTADV */
-#ifdef HAVE_NETLINK
-/* Socket interface to kernel */
-struct nlsock
-{
- int sock;
- int seq;
- struct sockaddr_nl snl;
- const char *name;
-};
-#endif
-
-/* NetNS ID type. */
-typedef u_int16_t ns_id_t;
-
-struct zebra_ns
-{
- /* net-ns name. */
- char name[VRF_NAMSIZ];
-
- /* Identifier. */
- ns_id_t ns_id;
-
-#ifdef HAVE_NETLINK
- struct nlsock netlink; /* kernel messages */
- struct nlsock netlink_cmd; /* command channel */
- struct thread *t_netlink;
-#endif
-
- struct route_table *if_table;
-
-#if defined (HAVE_RTADV)
- struct rtadv rtadv;
-#endif /* HAVE_RTADV */
-};
-
/* Routing table instance. */
struct zebra_vrf
{
struct zebra_ns *zns;
};
-extern struct zebra_ns *dzns;
-
/*
* rib_table_info_t
*
struct in6_addr *ipv6,
unsigned int ifindex);
+extern void zebra_vrf_init (void);
extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id);
extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t, const char *);
extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
#include "vrf.h"
#include "zebra/zserv.h"
+#include "zebra/zebra_ns.h"
#include "zebra/rt.h"
#include "zebra/redistribute.h"
#include "zebra/interface.h"
set_ifindex(struct interface *ifp, unsigned int ifi_index)
{
struct interface *oifp;
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
- if (((oifp = if_lookup_by_index_per_ns (dzns, ifi_index)) != NULL) && (oifp != ifp))
+ if (((oifp = if_lookup_by_index_per_ns (zns, ifi_index)) != NULL) && (oifp != ifp))
{
if (ifi_index == IFINDEX_INTERNAL)
zlog_err("Netlink is setting interface %s ifindex to reserved "
memset (tb, 0, sizeof tb);
netlink_parse_rtattr (tb, IFA_MAX, IFA_RTA (ifa), len);
- ifp = if_lookup_by_index_per_ns (dzns, ifa->ifa_index);
+ ifp = if_lookup_by_index_per_ns (zebra_ns_lookup (ns_id), ifa->ifa_index);
if (ifp == NULL)
{
zlog_err ("netlink_interface_addr can't find interface by index %d vrf %u",
}
/* See if interface is present. */
- ifp = if_lookup_by_index_per_ns (dzns, ifi->ifi_index);
+ ifp = if_lookup_by_index_per_ns (zebra_ns_lookup (NS_DEFAULT), ifi->ifi_index);
if (h->nlmsg_type == RTM_NEWLINK)
{
struct sockaddr_nl snl;
int discard;
- struct zebra_ns *zns = dzns;
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
struct
{
char buf[256];
} req;
- struct zebra_ns *zns = dzns;
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
memset(&req.n, 0, sizeof(req.n));
memset(&req.ndm, 0, sizeof(req.ndm));
char buf[NL_PKT_BUF_SIZE];
} req;
- struct zebra_ns *zns = dzns;
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
struct zebra_vrf *zvrf = vrf_info_lookup (rib->vrf_id);
memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE);
char buf[NL_PKT_BUF_SIZE];
} req;
- struct zebra_ns *zns = dzns; //vrf_info_lookup (ifp->vrf_id);
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
p = ifc->address;
memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE);
#include "zebra/debug.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
+#include "zebra/zebra_ns.h"
extern struct zebra_privs_t zserv_privs;
#include <zebra.h>
#include <lib/prefix.h>
#include <rtadv.h>
+#include <zebra_ns.h>
void ipv6_nd_suppress_ra_set (struct interface *ifp, ipv6_nd_suppress_ra_status status)
{ return; }
+
+void rtadv_init (struct zebra_ns *zns)
+{ return; }
+
+void rtadv_terminate (struct zebra_ns *zns)
+{ return; }
}
/* Zebra VRF initialization. */
-static void
+void
zebra_vrf_init (void)
{
vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
--- /dev/null
+/* zebra NS Routines
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * This file is part of Quagga.
+ *
+ * Quagga is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * Quagga is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Quagga; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#include "zebra.h"
+
+#include "lib/vrf.h"
+#include "lib/prefix.h"
+#include "lib/memory.h"
+
+#include "rtadv.h"
+#include "zebra_ns.h"
+
+struct zebra_ns *dzns;
+
+struct zebra_ns *
+zebra_ns_lookup (ns_id_t ns_id)
+{
+ return dzns;
+}
+
+int
+zebra_ns_enable (ns_id_t ns_id, void **info)
+{
+ struct zebra_ns *zns = (struct zebra_ns *) (*info);
+#ifdef HAVE_NETLINK
+ char nl_name[64];
+#endif
+
+#if defined (HAVE_RTADV)
+ rtadv_init (zns);
+#endif
+
+#ifdef HAVE_NETLINK
+ /* Initialize netlink sockets */
+ snprintf (nl_name, 64, "netlink-listen (NS %u)", ns_id);
+ zns->netlink.sock = -1;
+ zns->netlink.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name);
+
+ snprintf (nl_name, 64, "netlink-cmd (NS %u)", ns_id);
+ zns->netlink_cmd.sock = -1;
+ zns->netlink_cmd.name = XSTRDUP (MTYPE_NETLINK_NAME, nl_name);
+#endif
+ zns->if_table = route_table_init ();
+ kernel_init (zns);
+ interface_list (zns);
+ route_read (zns);
+
+ return 0;
+}
+
+int
+zebra_ns_disable (ns_id_t ns_id, void **info)
+{
+ struct zebra_ns *zns = (struct zebra_ns *) (*info);
+
+#if defined (HAVE_RTADV)
+ rtadv_terminate (zns);
+#endif
+
+ kernel_terminate (zns);
+
+ return 0;
+}
+
+int
+zebra_ns_init (void)
+{
+ dzns = XCALLOC (MTYPE_ZEBRA_NS, sizeof (struct zebra_ns));
+
+ zebra_vrf_init ();
+
+ zebra_ns_enable (0, (void **)&dzns);
+
+ return 0;
+}
--- /dev/null
+/*
+ * Zebra NS header
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * This file is part of Quagga.
+ *
+ * Quagga is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * Quagga is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Quagga; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#if !defined(__ZEBRA_NS_H__)
+#define __ZEBRA_NS_H__
+
+#ifdef HAVE_NETLINK
+/* Socket interface to kernel */
+struct nlsock
+{
+ int sock;
+ int seq;
+ struct sockaddr_nl snl;
+ const char *name;
+};
+#endif
+
+/* NetNS ID type. */
+typedef u_int16_t ns_id_t;
+
+struct zebra_ns
+{
+ /* net-ns name. */
+ char name[VRF_NAMSIZ];
+
+ /* Identifier. */
+ ns_id_t ns_id;
+
+#ifdef HAVE_NETLINK
+ struct nlsock netlink; /* kernel messages */
+ struct nlsock netlink_cmd; /* command channel */
+ struct thread *t_netlink;
+#endif
+
+ struct route_table *if_table;
+
+#if defined (HAVE_RTADV)
+ struct rtadv rtadv;
+#endif /* HAVE_RTADV */
+};
+
+#define NS_DEFAULT 0
+#define NS_UNKNOWN UINT16_MAX
+
+struct zebra_ns *zebra_ns_lookup (ns_id_t ns_id);
+
+int zebra_ns_init (void);
+int zebra_ns_enable (ns_id_t ns_id, void **info);
+int zebra_ns_disable (ns_id_t ns_id, void **info);
+#endif
#include "zebra/rib.h"
#include "zebra/rt.h"
#include "zebra/zserv.h"
+#include "zebra/zebra_ns.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/zebra_rnh.h"
print_nh (struct nexthop *nexthop, struct vty *vty)
{
char buf[BUFSIZ];
+ struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT);
switch (nexthop->type)
{
case NEXTHOP_TYPE_IPV4_IFINDEX:
vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
if (nexthop->ifindex)
- vty_out (vty, ", %s", ifindex2ifname_per_ns (dzns, nexthop->ifindex));
+ vty_out (vty, ", %s", ifindex2ifname_per_ns (zns, nexthop->ifindex));
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
vty_out (vty, " %s",
inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
if (nexthop->ifindex)
- vty_out (vty, ", via %s", ifindex2ifname_per_ns (dzns, nexthop->ifindex));
+ vty_out (vty, ", via %s", ifindex2ifname_per_ns (zns, nexthop->ifindex));
break;
case NEXTHOP_TYPE_IFINDEX:
vty_out (vty, " is directly connected, %s",
- ifindex2ifname_per_ns (dzns, nexthop->ifindex));
+ ifindex2ifname_per_ns (zns, nexthop->ifindex));
break;
case NEXTHOP_TYPE_BLACKHOLE:
vty_out (vty, " is directly connected, Null0");