#include "privs.h"
#include "sigevent.h"
#include "vrf.h"
-#include "systemd.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#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)
"-r, --retain When program terminates, retain added route "\
"by zebra.\n"\
"-u, --user User to run as\n"\
- "-g, --group Group to run as\n", progname);
+ "-g, --group Group to run as\n", progname);
#ifdef HAVE_NETLINK
printf ("-s, --nl-bufsize Set netlink receive buffer size\n");
#endif /* HAVE_NETLINK */
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);
- systemd_send_stopping();
+
+ zns = zebra_ns_lookup (NS_DEFAULT);
+ zebra_ns_disable (0, (void **)&zns);
exit (0);
}
.handler = &sigint,
},
};
-
-/* Callback upon creating a new VRF. */
-static int
-zebra_vrf_new (vrf_id_t vrf_id, const char *name, void **info)
-{
- struct zebra_vrf *zvrf = *info;
-
- zlog_info ("ZVRF %s with id %u", name, vrf_id);
-
- if (! zvrf)
- {
- zvrf = zebra_vrf_alloc (vrf_id, name);
- zvrf->zns = dzns; /* 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)
-{
- struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
-
- assert (zvrf);
-
- 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)
-{
- return 0;
-}
-
-static int
-zebra_vrf_delete (vrf_id_t vrf_id, const char *name, void **info)
-{
- struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
-
- assert (zvrf);
-
- rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
- rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
-
- list_delete_all_node (zvrf->rid_all_sorted_list);
- list_delete_all_node (zvrf->rid_lo_sorted_list);
-
- XFREE (MTYPE_ZEBRA_VRF, zvrf);
-
- return 0;
-}
-
-/* Zebra VRF initialization. */
-static 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. */
int
zlog_default = openzlog (progname, ZLOG_ZEBRA, 0,
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
+ zprivs_init (&zserv_privs);
+#if defined(HAVE_CUMULUS)
+ zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
+#endif
while (1)
{
/* Make master thread emulator. */
zebrad.master = thread_master_create ();
- /* privs initialise */
- zprivs_init (&zserv_privs);
-
/* Vty related initialize. */
signal_init (zebrad.master, array_size(zebra_signals), zebra_signals);
cmd_init (1);
/* 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 ();
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("Zebra daemon failed: %s", strerror(errno));
- systemd_send_stopping ();
exit (1);
}
/* Output pid of zebra. */
pid_output (pid_file);
- systemd_send_started (zebrad.master);
/* After we have successfully acquired the pidfile, we can be sure
* about being the only copy of zebra process, which is submitting
* changes to the FIB.