]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/test_main.c
*: use an ifindex_t type, defined in lib/if.h, for ifindex values
[mirror_frr.git] / zebra / test_main.c
index 46f73bbe17e9fab04fab645d62a1ee563050a0fc..95c56bb0464c0a29fa427ce12d31c8f7bdac8bbb 100644 (file)
 #include "log.h"
 #include "privs.h"
 #include "sigevent.h"
+#include "vrf.h"
 
 #include "zebra/rib.h"
+#include "zebra/zebra_ns.h"
 #include "zebra/zserv.h"
+#include "zebra/zebra_vrf.h"
 #include "zebra/debug.h"
 #include "zebra/router-id.h"
 #include "zebra/interface.h"
@@ -45,6 +48,9 @@ struct zebra_t zebrad =
 /* process id. */
 pid_t pid;
 
+/* Allow non-quagga entities to delete quagga routes */
+int allow_delete = 0;
+
 /* zebra_rib's workqueue hold time. Private export for use by test code only */
 extern int rib_process_hold_time;
 
@@ -54,15 +60,15 @@ struct thread_master *master;
 /* Command line options. */
 struct option longopts[] = 
 {
-  { "batch",       no_argument,       NULL, 'b'},
-  { "daemon",      no_argument,       NULL, 'd'},
-  { "log_mode",    no_argument,       NULL, 'l'},
-  { "config_file", required_argument, NULL, 'f'},
-  { "help",        no_argument,       NULL, 'h'},
-  { "vty_addr",    required_argument, NULL, 'A'},
-  { "vty_port",    required_argument, NULL, 'P'},
-  { "version",     no_argument,       NULL, 'v'},
-  { "rib_hold",           required_argument, NULL, 'r'},
+  { "batch",        no_argument,       NULL, 'b'},
+  { "daemon",       no_argument,       NULL, 'd'},
+  { "allow_delete", no_argument,       NULL, 'a'},
+  { "config_file",  required_argument, NULL, 'f'},
+  { "help",         no_argument,       NULL, 'h'},
+  { "vty_addr",     required_argument, NULL, 'A'},
+  { "vty_port",     required_argument, NULL, 'P'},
+  { "version",      no_argument,       NULL, 'v'},
+  { "rib_hold",     required_argument, NULL, 'r'},
   { 0 }
 };
 
@@ -92,8 +98,8 @@ usage (char *progname, int status)
              "redistribution between different routing protocols.\n\n"\
              "-b, --batch        Runs in batch mode\n"\
              "-d, --daemon       Runs in daemon mode\n"\
+             "-a, --allow_delete Allow other processes to delete Quagga Routes\n" \
              "-f, --config_file  Set configuration file name\n"\
-             "-l, --log_mode     Set verbose log mode flag\n"\
              "-A, --vty_addr     Set vty's bind address\n"\
              "-P, --vty_port     Set vty's port number\n"\
              "-r, --rib_hold     Set rib-queue hold time\n"\
@@ -105,8 +111,8 @@ usage (char *progname, int status)
 
   exit (status);
 }
-\f
-static unsigned int test_ifindex = 0;
+
+static ifindex_t test_ifindex = 0;
 
 /* testrib commands */
 DEFUN (test_interface_state,
@@ -151,7 +157,7 @@ test_cmd_init (void)
 {
   install_element (INTERFACE_NODE, &test_interface_state_cmd);
 }
-\f
+
 /* SIGHUP handler. */
 static void 
 sighup (void)
@@ -197,7 +203,6 @@ struct quagga_signal_t zebra_signals[] =
     .handler = &sigint,
   },
 };
-\f
 /* Main startup routine. */
 int
 main (int argc, char **argv)
@@ -217,14 +222,14 @@ main (int argc, char **argv)
   /* preserve my name */
   progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
 
-  zlog_default = openzlog (progname, ZLOG_ZEBRA,
+  zlog_default = openzlog (progname, ZLOG_ZEBRA, 0,
                           LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
 
   while (1) 
     {
       int opt;
   
-      opt = getopt_long (argc, argv, "bdlf:hA:P:r:v", longopts, 0);
+      opt = getopt_long (argc, argv, "bdaf:hA:P:r:v", longopts, 0);
 
       if (opt == EOF)
        break;
@@ -238,8 +243,8 @@ main (int argc, char **argv)
        case 'd':
          daemon_mode = 1;
          break;
-       case 'l':
-         /* log_mode = 1; */
+       case 'a':
+         allow_delete =1;
          break;
        case 'f':
          config_file = optarg;
@@ -275,17 +280,20 @@ main (int argc, char **argv)
   
   /* port and conf file mandatory */
   if (!vty_port || !config_file)
-    usage (progname, 1);
+    {
+      fprintf (stderr, "Error: --vty_port and --config_file arguments"
+                       " are both required\n");
+      usage (progname, 1);
+    }
   
   /* Make master thread emulator. */
   zebrad.master = thread_master_create ();
 
   /* Vty related initialize. */
-  signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals);
+  signal_init (zebrad.master, array_size(zebra_signals), zebra_signals);
   cmd_init (1);
   vty_init (zebrad.master);
   memory_init ();
-  if_init();
   zebra_debug_init ();
   zebra_if_init ();
   test_cmd_init ();
@@ -295,13 +303,9 @@ main (int argc, char **argv)
   access_list_init ();
 
   /* Make kernel routing socket. */
-  kernel_init ();
-  route_read ();
+  zebra_vrf_init ();
   zebra_vty_init();
 
-  /* Sort VTY commands. */
-  sort_node ();
-
   /* Configuration file read*/
   vty_read_config (config_file, config_default);
 
@@ -313,8 +317,11 @@ main (int argc, char **argv)
     exit (0);
 
   /* Daemonize. */
-  if (daemon_mode)
-    daemon (0, 0);
+  if (daemon_mode && daemon (0, 0) < 0)
+    {
+      perror("daemon start failed");
+      exit (1);
+    }
 
   /* Needed for BSD routing socket. */
   pid = getpid ();