summaryrefslogtreecommitdiff
path: root/pimd/pim_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'pimd/pim_main.c')
-rw-r--r--pimd/pim_main.c151
1 files changed, 19 insertions, 132 deletions
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
index 2e81ac53fd..ba1c511d16 100644
--- a/pimd/pim_main.c
+++ b/pimd/pim_main.c
@@ -38,7 +38,7 @@
#include "prefix.h"
#include "plist.h"
#include "vrf.h"
-#include "sockopt.h"
+#include "libfrr.h"
#include "pimd.h"
#include "pim_version.h"
@@ -50,27 +50,10 @@
extern struct host host;
-char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG;
-
-/* pimd options */
-#define OPTION_VTYSOCK 1000
struct option longopts[] = {
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "vty_addr", required_argument, NULL, 'A'},
- { "vty_port", required_argument, NULL, 'P'},
- { "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
- { "version", no_argument, NULL, 'v'},
- { "debug_zclient", no_argument, NULL, 'Z'},
- { "help", no_argument, NULL, 'h'},
{ 0 }
};
-/* VTY Socket prefix */
-char vty_sock_path[MAXPATHLEN] = PIM_VTYSH_PATH;
-
/* pimd privileges */
zebra_capabilities_t _caps_p [] =
{
@@ -95,101 +78,40 @@ struct zebra_privs_t pimd_privs =
.cap_num_i = 0
};
-char* progname;
-const char *pid_file = PATH_PIMD_PID;
+FRR_DAEMON_INFO(pimd, PIM,
+ .vty_port = PIMD_VTY_PORT,
-static void usage(int status)
-{
- if (status != 0)
- fprintf (stderr, "Try `%s --help' for more information.\n", progname);
- else {
- printf ("Usage : %s [OPTION...]\n\
-Daemon which manages PIM.\n\n\
--d, --daemon Run in daemon mode\n\
--f, --config_file Set configuration file name\n\
--i, --pid_file Set process identifier file name\n\
--z, --socket Set path of zebra socket\n\
--A, --vty_addr Set vty's bind address\n\
--P, --vty_port Set vty's port number\n\
- --vty_socket Override vty socket path\n\
--v, --version Print program version\n\
--h, --help Display this help and exit\n\
-\n\
-Report bugs to %s\n", progname, PACKAGE_BUGREPORT);
- }
+ .proghelp = "Implementation of the PIM routing protocol.",
- exit (status);
-}
+ .signals = pimd_signals,
+ .n_signals = 4 /* XXX array_size(pimd_signals) XXX*/,
+ .privs = &pimd_privs,
+)
int main(int argc, char** argv, char** envp) {
- char *p;
- char *vty_addr = NULL;
- int vty_port = -1;
- int daemon_mode = 0;
- char *config_file = NULL;
- char *zebra_sock_path = NULL;
- struct thread thread;
-
- umask(0027);
-
- progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
-
- zlog_default = openzlog(progname, ZLOG_PIM, 0,
- LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
- zprivs_init (&pimd_privs);
-#if defined(HAVE_CUMULUS)
- zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
-#endif
+ frr_preinit(&pimd_di, argc, argv);
+ frr_opt_add("", longopts, "");
- /* this while just reads the options */
+ /* this while just reads the options */
while (1) {
int opt;
-
- opt = getopt_long (argc, argv, "df:i:z:A:P:vZh", longopts, 0);
-
+
+ opt = frr_getopt(argc, argv, NULL);
+
if (opt == EOF)
break;
switch (opt) {
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zebra_sock_path = optarg;
- break;
- case 'A':
- vty_addr = optarg;
- break;
- case 'P':
- vty_port = atoi (optarg);
- break;
- case OPTION_VTYSOCK:
- set_socket_path(vty_sock_path, PIM_VTYSH_PATH, optarg, sizeof (vty_sock_path));
- break;
- case 'v':
- printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION);
- print_version(progname);
- exit (0);
- break;
- case 'h':
- usage (0);
- break;
default:
- usage (1);
+ frr_help_exit (1);
break;
}
}
- master = thread_master_create();
+ master = frr_init();
zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting",
FRR_VERSION, PIMD_VERSION);
@@ -197,10 +119,6 @@ int main(int argc, char** argv, char** envp) {
/*
* Initializations
*/
- pim_signals_init();
- cmd_init(1);
- vty_init(master);
- memory_init();
vrf_init ();
access_list_init();
prefix_list_init ();
@@ -214,36 +132,9 @@ int main(int argc, char** argv, char** envp) {
/*
* Initialize zclient "update" and "lookup" sockets
*/
- pim_zebra_init(zebra_sock_path);
-
- zlog_notice("Loading configuration - begin");
-
- /* Get configuration file. */
- vty_read_config(config_file, config_default);
-
- /*
- Starting from here zlog_* functions will log according configuration
- */
+ pim_zebra_init();
- zlog_notice("Loading configuration - end");
-
- /* Change to the daemon program. */
- if (daemon_mode) {
- if (daemon(0, 0)) {
- zlog_warn("failed to daemonize");
- }
- }
-
- /* Process ID file creation. */
- pid_output(pid_file);
-
- /* Create pimd VTY socket */
- if (vty_port < 0)
- vty_port = PIMD_VTY_PORT;
- vty_serv_sock(vty_addr, vty_port, vty_sock_path);
-
- zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
- FRR_VERSION, PIMD_VERSION, vty_port);
+ frr_config_fork();
#ifdef PIM_DEBUG_BYDEFAULT
zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
@@ -267,11 +158,7 @@ int main(int argc, char** argv, char** envp) {
zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
#endif
- while (thread_fetch(master, &thread))
- thread_call(&thread);
-
- zlog_err("%s %s: thread_fetch() returned NULL, exiting",
- __FILE__, __PRETTY_FUNCTION__);
+ frr_run(master);
/* never reached */
return 0;