]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/main.c
lib: add new extensible memory-type handling
[mirror_frr.git] / zebra / main.c
index 0666de97846f01e60ce31b6858c9a7461663d28a..d8892f582aa986e0791e2da7763665b0bb06c326 100644 (file)
@@ -33,7 +33,6 @@
 #include "privs.h"
 #include "sigevent.h"
 #include "vrf.h"
-#include "systemd.h"
 
 #include "zebra/rib.h"
 #include "zebra/zserv.h"
@@ -43,6 +42,8 @@
 #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
 
@@ -149,7 +150,7 @@ 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 */
@@ -176,6 +177,8 @@ sighup (void)
 static void
 sigint (void)
 {
+  struct zebra_ns *zns;
+
   zlog_notice ("Terminating on signal");
 
   if (!retain_mode)
@@ -185,7 +188,9 @@ sigint (void)
 #endif
 
   zebra_ptm_finish();
-  systemd_send_stopping();
+
+  zns = zebra_ns_lookup (NS_DEFAULT);
+  zebra_ns_disable (0, (void **)&zns);
   exit (0);
 }
 
@@ -215,127 +220,6 @@ struct quagga_signal_t zebra_signals[] =
     .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);
-      *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
-
-#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);
-
-#if defined (HAVE_RTADV)
-  rtadv_init (zvrf);
-#endif
-
-  return 0;
-}
-
-/*
-static int
-zebra_ns_disable (ns_id_t ns_id, void **info)
-{
-  struct zebra_ns *zns = (struct zebra_ns *) (*info);
-
-  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)
-{
-  struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
-  struct listnode *list_node;
-  struct interface *ifp;
-
-  assert (zvrf);
-
-  rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
-  rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
-
-  for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), list_node, ifp))
-    {
-      int operative = if_is_operative (ifp);
-      UNSET_FLAG (ifp->flags, IFF_UP);
-      if (operative)
-        if_down (ifp);
-    }
-
-#if defined (HAVE_RTADV)
-  rtadv_terminate (zvrf);
-#endif
-
-  list_delete_all_node (zvrf->rid_all_sorted_list);
-  list_delete_all_node (zvrf->rid_lo_sorted_list);
-
-  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);
-  
-  /* 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
@@ -360,6 +244,10 @@ main (int argc, char **argv)
 
   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) 
     {
@@ -446,9 +334,6 @@ main (int argc, char **argv)
   /* 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);
@@ -478,8 +363,8 @@ main (int argc, char **argv)
   /* 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 ();
@@ -515,14 +400,12 @@ main (int argc, char **argv)
   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.