summaryrefslogtreecommitdiff
path: root/ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_ism.c20
-rw-r--r--ospfd/ospf_main.c211
-rw-r--r--ospfd/ospf_nsm.c8
-rw-r--r--ospfd/ospf_packet.c13
-rw-r--r--ospfd/ospf_snmp.c14
-rw-r--r--ospfd/ospf_vty.c2
-rw-r--r--ospfd/ospfd.c4
-rw-r--r--ospfd/ospfd.h2
8 files changed, 55 insertions, 219 deletions
diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c
index ae6d0cdbc5..9630616acc 100644
--- a/ospfd/ospf_ism.c
+++ b/ospfd/ospf_ism.c
@@ -255,8 +255,7 @@ ospf_hello_timer (struct thread *thread)
oi->t_hello = NULL;
if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: Timer (Hello timer expire)",
- IF_NAME (oi));
+ zlog_debug("ISM[%s]: Timer (Hello timer expire)", IF_NAME(oi));
/* Sending hello packet. */
ospf_hello_send (oi);
@@ -276,8 +275,7 @@ ospf_wait_timer (struct thread *thread)
oi->t_wait = NULL;
if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: Timer (Wait timer expire)",
- IF_NAME (oi));
+ zlog_debug("ISM[%s]: Timer (Wait timer expire)", IF_NAME(oi));
OSPF_ISM_EVENT_SCHEDULE (oi, ISM_WaitTimer);
@@ -418,7 +416,7 @@ static int
ism_ignore (struct ospf_interface *oi)
{
if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: ism_ignore called", IF_NAME (oi));
+ zlog_debug("ISM[%s]: ism_ignore called", IF_NAME(oi));
return 0;
}
@@ -539,9 +537,9 @@ ism_change_state (struct ospf_interface *oi, int state)
/* Logging change of state. */
if (IS_DEBUG_OSPF (ism, ISM_STATUS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: State change %s -> %s", IF_NAME (oi),
- LOOKUP (ospf_ism_state_msg, oi->state),
- LOOKUP (ospf_ism_state_msg, state));
+ zlog_debug("ISM[%s]: State change %s -> %s", IF_NAME(oi),
+ LOOKUP(ospf_ism_state_msg, oi->state),
+ LOOKUP(ospf_ism_state_msg, state));
old_state = oi->state;
oi->state = state;
@@ -617,9 +615,9 @@ ospf_ism_event (struct thread *thread)
next_state = ISM [oi->state][event].next_state;
if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: %s (%s)", IF_NAME (oi),
- LOOKUP (ospf_ism_state_msg, oi->state),
- ospf_ism_event_str[event]);
+ zlog_debug("ISM[%s]: %s (%s)", IF_NAME(oi),
+ LOOKUP(ospf_ism_state_msg, oi->state),
+ ospf_ism_event_str[event]);
/* If state is changed. */
if (next_state != oi->state)
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index edb1ca470e..5705dad5d4 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -41,7 +41,7 @@
#include "sigevent.h"
#include "zclient.h"
#include "vrf.h"
-#include "sockopt.h"
+#include "libfrr.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
@@ -76,41 +76,19 @@ struct zebra_privs_t ospfd_privs =
.cap_num_i = 0
};
-/* Configuration filename and directory. */
-char config_default[100];
-
/* OSPFd options. */
-#define OPTION_VTYSOCK 1000
struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
{ "instance", required_argument, NULL, 'n'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
- { "help", no_argument, NULL, 'h'},
- { "vty_addr", required_argument, NULL, 'A'},
- { "vty_port", required_argument, NULL, 'P'},
- { "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
- { "user", required_argument, NULL, 'u'},
- { "group", required_argument, NULL, 'g'},
{ "apiserver", no_argument, NULL, 'a'},
- { "version", no_argument, NULL, 'v'},
{ 0 }
};
/* OSPFd program name */
-/* VTY Socket prefix */
-char vty_sock_path[MAXPATHLEN] = OSPF_VTYSH_PATH;
-
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-char pid_file[100];
-
#ifdef SUPPORT_OSPF_API
extern int ospf_apiserver_enable;
#endif /* SUPPORT_OSPF_API */
@@ -124,21 +102,6 @@ usage (char *progname, int status)
else
{
printf ("Usage : %s [OPTION...]\n\
-Daemon which manages OSPF.\n\n\
--d, --daemon Runs in daemon mode\n\
--n, --instance Set the instance id\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\
--u, --user User to run as\n\
--g, --group Group to run as\n\
--a. --apiserver Enable OSPF apiserver\n\
--v, --version Print program version\n\
--C, --dryrun Check configuration for validity and exit\n\
--h, --help Display this help and exit\n\
\n\
Report bugs to %s\n", progname, FRR_BUG_ADDRESS);
}
@@ -149,7 +112,7 @@ Report bugs to %s\n", progname, FRR_BUG_ADDRESS);
static void
sighup (void)
{
- zlog (NULL, LOG_INFO, "SIGHUP received");
+ zlog_info("SIGHUP received");
}
/* SIGINT / SIGTERM handler. */
@@ -164,7 +127,7 @@ sigint (void)
static void
sigusr1 (void)
{
- zlog_rotate (NULL);
+ zlog_rotate();
}
struct quagga_signal_t ospf_signals[] =
@@ -187,39 +150,38 @@ struct quagga_signal_t ospf_signals[] =
},
};
+FRR_DAEMON_INFO(ospfd, OSPF,
+ .vty_port = OSPF_VTY_PORT,
+
+ .proghelp = "Implementation of the OSPFv2 routing protocol.",
+
+ .signals = ospf_signals,
+ .n_signals = array_size(ospf_signals),
+
+ .privs = &ospfd_privs,
+)
+
/* OSPFd main routine. */
int
main (int argc, char **argv)
{
- char *p;
- char *vty_addr = NULL;
- int vty_port = OSPF_VTY_PORT;
- char vty_path[100];
- int daemon_mode = 0;
- char *config_file = NULL;
- char *progname;
u_short instance = 0;
- struct thread thread;
- int dryrun = 0;
-
- /* Set umask before anything for security */
- umask (0027);
#ifdef SUPPORT_OSPF_API
/* OSPF apiserver is disabled by default. */
ospf_apiserver_enable = 0;
#endif /* SUPPORT_OSPF_API */
- strcpy(pid_file, PATH_OSPFD_PID);
-
- /* get program name */
- progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
+ frr_preinit (&ospfd_di, argc, argv);
+ frr_opt_add ("n:a", longopts,
+ " -n, --instance Set the instance id\n"
+ " -a, --apiserver Enable OSPF apiserver\n");
while (1)
{
int opt;
- opt = getopt_long (argc, argv, "df:i:n:z:hA:P:u:g:avC", longopts, 0);
+ opt = frr_getopt (argc, argv, NULL);
if (opt == EOF)
break;
@@ -227,65 +189,19 @@ main (int argc, char **argv)
switch (opt)
{
case 'n':
- instance = atoi(optarg);
+ ospfd_di.instance = instance = atoi(optarg);
if (instance < 1)
exit(0);
break;
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'A':
- vty_addr = optarg;
- break;
- case 'i':
- strcpy(pid_file,optarg);
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
- case 'P':
- /* Deal with atoi() returning 0 on failure, and ospfd not
- listening on ospfd port... */
- if (strcmp(optarg, "0") == 0)
- {
- vty_port = 0;
- break;
- }
- vty_port = atoi (optarg);
- if (vty_port <= 0 || vty_port > 0xffff)
- vty_port = OSPF_VTY_PORT;
- break;
- case OPTION_VTYSOCK:
- set_socket_path(vty_sock_path, OSPF_VTYSH_PATH, optarg, sizeof (vty_sock_path));
- break;
- case 'u':
- ospfd_privs.user = optarg;
- break;
- case 'g':
- ospfd_privs.group = optarg;
- break;
#ifdef SUPPORT_OSPF_API
case 'a':
ospf_apiserver_enable = 1;
break;
#endif /* SUPPORT_OSPF_API */
- case 'v':
- print_version (progname);
- exit (0);
- break;
- case 'C':
- dryrun = 1;
- break;
- case 'h':
- usage (progname, 0);
- break;
default:
- usage (progname, 1);
+ frr_help_exit (1);
break;
}
}
@@ -294,29 +210,18 @@ main (int argc, char **argv)
if (geteuid () != 0)
{
errno = EPERM;
- perror (progname);
+ perror (ospfd_di.progname);
exit (1);
}
- zlog_default = openzlog (progname, ZLOG_OSPF, instance,
- LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
- zprivs_init (&ospfd_privs);
-#if defined(HAVE_CUMULUS)
- zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
-#endif
-
/* OSPF master init. */
- ospf_master_init ();
+ ospf_master_init (frr_init ());
/* Initializations. */
master = om->master;
/* Library inits. */
- signal_init (master, array_size(ospf_signals), ospf_signals);
- cmd_init (1);
debug_init ();
- vty_init (master);
- memory_init ();
vrf_init ();
access_list_init ();
@@ -349,74 +254,8 @@ main (int argc, char **argv)
exit (1);
}
- /* Get configuration file. */
- if (instance)
- sprintf(config_default, "%sospfd-%d.conf", SYSCONFDIR, instance);
- else
- sprintf(config_default, "%s%s", SYSCONFDIR, OSPF_DEFAULT_CONFIG);
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if (dryrun)
- return(0);
-
- /* Change to the daemon program. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("OSPFd daemon failed: %s", strerror(errno));
- exit (1);
- }
-
- /* Create PID file */
- if (instance)
- {
- char pidfile_temp[100];
-
- /* Override the single file with file including instance
- number in case of multi-instance */
- if (strrchr(pid_file, '/') != NULL)
- /* cut of pid_file at last / char * to get directory */
- *strrchr(pid_file, '/') = '\0';
- else
- /* pid_file contains no directory - should never happen, but deal with it anyway */
- /* throw-away all pid_file and assume it's only the filename */
- pid_file[0] = '\0';
-
- snprintf(pidfile_temp, sizeof(pidfile_temp), "%s/ospfd-%d.pid", pid_file, instance );
- strlcpy(pid_file, pidfile_temp, sizeof(pid_file));
- }
- /* Process id file create. */
- pid_output (pid_file);
-
- /* Create VTY socket */
- if (instance)
- {
- /* Multi-Instance. Use only path section of vty_sock_path with new file incl instance */
- if (strrchr(vty_sock_path, '/') != NULL)
- {
- /* cut of pid_file at last / char * to get directory */
- *strrchr(vty_sock_path, '/') = '\0';
- }
- else
- {
- /* pid_file contains no directory - should never happen, but deal with it anyway */
- /* throw-away all pid_file and assume it's only the filename */
- vty_sock_path[0] = '\0';
- }
- snprintf(vty_path, sizeof(vty_path), "%s/ospfd-%d.vty", vty_sock_path, instance );
- }
- else
- {
- strlcpy(vty_path, vty_sock_path, sizeof(vty_path));
- }
- vty_serv_sock (vty_addr, vty_port, vty_path);
-
- /* Print banner. */
- zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION, vty_port, vty_path);
-
- /* Fetch next active thread. */
- while (thread_fetch (master, &thread))
- thread_call (&thread);
+ frr_config_fork();
+ frr_run (master);
/* Not reached. */
return (0);
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index ccb82bf8fe..01617055ce 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -63,8 +63,8 @@ ospf_inactivity_timer (struct thread *thread)
nbr->t_inactivity = NULL;
if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
- zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (Inactivity timer expire)",
- IF_NAME (nbr->oi), inet_ntoa (nbr->router_id));
+ zlog_debug("NSM[%s:%s]: Timer (Inactivity timer expire)",
+ IF_NAME(nbr->oi), inet_ntoa(nbr->router_id));
OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_InactivityTimer);
@@ -80,8 +80,8 @@ ospf_db_desc_timer (struct thread *thread)
nbr->t_db_desc = NULL;
if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
- zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (DD Retransmit timer expire)",
- IF_NAME (nbr->oi), inet_ntoa (nbr->src));
+ zlog_debug("NSM[%s:%s]: Timer (DD Retransmit timer expire)",
+ IF_NAME(nbr->oi), inet_ntoa(nbr->src));
/* resent last send DD packet. */
assert (nbr->last_send);
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index bf78336ad5..a0cc367cd7 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -2971,9 +2971,8 @@ ospf_read (struct thread *thread)
ospf_ls_ack (iph, ospfh, ibuf, oi, length);
break;
default:
- zlog (NULL, LOG_WARNING,
- "interface %s: OSPF packet header type %d is illegal",
- IF_NAME (oi), ospfh->type);
+ zlog_warn("interface %s: OSPF packet header type %d is illegal",
+ IF_NAME(oi), ospfh->type);
break;
}
@@ -3453,8 +3452,8 @@ ospf_poll_timer (struct thread *thread)
nbr_nbma->t_poll = NULL;
if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
- zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (Poll timer expire)",
- IF_NAME (nbr_nbma->oi), inet_ntoa (nbr_nbma->addr));
+ zlog_debug("NSM[%s:%s]: Timer (Poll timer expire)", IF_NAME(nbr_nbma->oi),
+ inet_ntoa(nbr_nbma->addr));
ospf_poll_send (nbr_nbma);
@@ -3477,8 +3476,8 @@ ospf_hello_reply_timer (struct thread *thread)
assert (nbr->oi);
if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
- zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (hello-reply timer expire)",
- IF_NAME (nbr->oi), inet_ntoa (nbr->router_id));
+ zlog_debug("NSM[%s:%s]: Timer (hello-reply timer expire)",
+ IF_NAME(nbr->oi), inet_ntoa(nbr->router_id));
ospf_hello_send_sub (nbr->oi, nbr->address.u.prefix4.s_addr);
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index 676756d6d9..4afbda8788 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -2658,8 +2658,8 @@ ospfTrapNbrStateChange (struct ospf_neighbor *on)
char msgbuf[16];
ospf_nbr_state_message(on, msgbuf, sizeof(msgbuf));
- zlog (NULL, LOG_INFO, "ospfTrapNbrStateChange trap sent: %s now %s",
- inet_ntoa(on->address.u.prefix4), msgbuf);
+ zlog_info("ospfTrapNbrStateChange trap sent: %s now %s",
+ inet_ntoa(on->address.u.prefix4), msgbuf);
oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
index[IN_ADDR_SIZE] = 0;
@@ -2678,7 +2678,7 @@ ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
- zlog (NULL, LOG_INFO, "ospfTrapVirtNbrStateChange trap sent");
+ zlog_info("ospfTrapVirtNbrStateChange trap sent");
oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
index[IN_ADDR_SIZE] = 0;
@@ -2697,9 +2697,9 @@ ospfTrapIfStateChange (struct ospf_interface *oi)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
- zlog (NULL, LOG_INFO, "ospfTrapIfStateChange trap sent: %s now %s",
- inet_ntoa(oi->address->u.prefix4),
- LOOKUP(ospf_ism_state_msg, oi->state));
+ zlog_info("ospfTrapIfStateChange trap sent: %s now %s",
+ inet_ntoa(oi->address->u.prefix4),
+ LOOKUP(ospf_ism_state_msg, oi->state));
oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
index[IN_ADDR_SIZE] = 0;
@@ -2718,7 +2718,7 @@ ospfTrapVirtIfStateChange (struct ospf_interface *oi)
{
oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
- zlog (NULL, LOG_INFO, "ospfTrapVirtIfStateChange trap sent");
+ zlog_info("ospfTrapVirtIfStateChange trap sent");
oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
index[IN_ADDR_SIZE] = 0;
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 62498f4c82..ce4bc9dfaa 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -9117,7 +9117,7 @@ ospf_interface_clear (struct interface *ifp)
if (!if_is_operative (ifp)) return;
if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
- zlog (NULL, LOG_DEBUG, "ISM[%s]: clear by reset", ifp->name);
+ zlog_debug("ISM[%s]: clear by reset", ifp->name);
ospf_if_reset(ifp);
}
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 570734bd8c..7cd3903678 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -1917,11 +1917,11 @@ ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
}
void
-ospf_master_init ()
+ospf_master_init (struct thread_master *master)
{
memset (&ospf_master, 0, sizeof (struct ospf_master));
om = &ospf_master;
om->ospf = list_new ();
- om->master = thread_master_create ();
+ om->master = master;
}
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 8ebd3c4ec6..a3bd0ca12f 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -576,7 +576,7 @@ extern void ospf_area_del_if (struct ospf_area *, struct ospf_interface *);
extern void ospf_route_map_init (void);
extern void ospf_snmp_init (void);
-extern void ospf_master_init (void);
+extern void ospf_master_init (struct thread_master *master);
extern int ospf_interface_set (struct interface *ifp, struct in_addr area_id);
extern int ospf_interface_unset (struct interface *ifp);