summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ripd
diff options
context:
space:
mode:
authorbenno <benno@openbsd.org>2016-09-02 14:07:52 +0000
committerbenno <benno@openbsd.org>2016-09-02 14:07:52 +0000
commit537c1c4e5e811134482d6b167d2be39571f55986 (patch)
treef79213a1216e5928d1beb4ca3292816fd2f35333 /usr.sbin/ripd
parentwork on making log.c similar in all daemons: (diff)
downloadwireguard-openbsd-537c1c4e5e811134482d6b167d2be39571f55986.tar.xz
wireguard-openbsd-537c1c4e5e811134482d6b167d2be39571f55986.zip
work on making log.c similar in all daemons:
move daemon-local functions into new logmsg.c, and reduce the (mostly whitespace) differences so that log.c's can be diffed easily. ok claudio@, feedback from henning@, deraadt@, reyk@
Diffstat (limited to 'usr.sbin/ripd')
-rw-r--r--usr.sbin/ripd/Makefile4
-rw-r--r--usr.sbin/ripd/log.c83
-rw-r--r--usr.sbin/ripd/log.h45
-rw-r--r--usr.sbin/ripd/logmsg.c80
-rw-r--r--usr.sbin/ripd/rde.c3
-rw-r--r--usr.sbin/ripd/ripd.c3
-rw-r--r--usr.sbin/ripd/ripd.h21
-rw-r--r--usr.sbin/ripd/ripe.c3
8 files changed, 134 insertions, 108 deletions
diff --git a/usr.sbin/ripd/Makefile b/usr.sbin/ripd/Makefile
index b6dfc592e0e..a4a8b515523 100644
--- a/usr.sbin/ripd/Makefile
+++ b/usr.sbin/ripd/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.5 2010/05/26 16:44:32 nicm Exp $
+# $OpenBSD: Makefile,v 1.6 2016/09/02 14:07:52 benno Exp $
PROG= ripd
SRCS= auth.c carp.c control.c interface.c kroute.c \
- log.c message.c name2id.c neighbor.c packet.c parse.y \
+ log.c logmsg.c message.c name2id.c neighbor.c packet.c parse.y \
printconf.c rde.c rde_rib.c ripe.c ripd.c
MAN= ripd.8 ripd.conf.5
diff --git a/usr.sbin/ripd/log.c b/usr.sbin/ripd/log.c
index b7fd7fab2cb..28854278e0e 100644
--- a/usr.sbin/ripd/log.c
+++ b/usr.sbin/ripd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.5 2014/11/03 20:15:31 bluhm Exp $ */
+/* $OpenBSD: log.c,v 1.6 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -22,19 +22,15 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
-#include "ripd.h"
#include "log.h"
+#include "ripd.h"
-static const char * const procnames[] = {
- "parent",
- "ripe",
- "rde"
-};
-
-int debug;
-int verbose;
+int debug;
+int verbose;
+const char *log_procname;
void
log_init(int n_debug)
@@ -144,15 +140,15 @@ void
fatal(const char *emsg)
{
if (emsg == NULL)
- logit(LOG_CRIT, "fatal in %s: %s", procnames[ripd_process],
+ logit(LOG_CRIT, "fatal in %s: %s", log_procname,
strerror(errno));
else
if (errno)
logit(LOG_CRIT, "fatal in %s: %s: %s",
- procnames[ripd_process], emsg, strerror(errno));
+ log_procname, emsg, strerror(errno));
else
logit(LOG_CRIT, "fatal in %s: %s",
- procnames[ripd_process], emsg);
+ log_procname, emsg);
if (ripd_process == PROC_MAIN)
exit(1);
@@ -166,64 +162,3 @@ fatalx(const char *emsg)
errno = 0;
fatal(emsg);
}
-
-/* names */
-const char *
-nbr_state_name(int state)
-{
- switch (state) {
- case NBR_STA_DOWN:
- return ("DOWN");
- case NBR_STA_REQ_RCVD:
- return ("REQUEST RCVD");
- case NBR_STA_ACTIVE:
- return ("ACTIVE");
- default:
- return ("UNKNOWN");
- }
-}
-
-const char *
-if_type_name(enum iface_type type)
-{
- switch (type) {
- case IF_TYPE_POINTOPOINT:
- return ("POINTOPOINT");
- case IF_TYPE_BROADCAST:
- return ("BROADCAST");
- case IF_TYPE_NBMA:
- return ("NBMA");
- case IF_TYPE_POINTOMULTIPOINT:
- return ("POINTOMULTIPOINT");
- }
- /* NOTREACHED */
- return ("UNKNOWN");
-}
-
-const char *
-if_auth_name(enum auth_type type)
-{
- switch (type) {
- case AUTH_NONE:
- return ("none");
- case AUTH_SIMPLE:
- return ("simple");
- case AUTH_CRYPT:
- return ("crypt");
- }
- /* NOTREACHED */
- return ("unknown");
-}
-
-const char *
-if_state_name(int state)
-{
- switch (state) {
- case IF_STA_DOWN:
- return ("DOWN");
- case IF_STA_ACTIVE:
- return ("ACTIVE");
- default:
- return ("UNKNOWN");
- }
-}
diff --git a/usr.sbin/ripd/log.h b/usr.sbin/ripd/log.h
index 9d64448f0b3..9250fab7965 100644
--- a/usr.sbin/ripd/log.h
+++ b/usr.sbin/ripd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.5 2016/07/19 07:58:51 benno Exp $ */
+/* $OpenBSD: log.h,v 1.6 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,28 +16,29 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef LOG_H
+#define LOG_H
#include <stdarg.h>
+#include <sys/cdefs.h>
-void log_init(int);
-void log_verbose(int);
-void logit(int, const char *, ...)
- __attribute__((__format__ (printf, 2, 3)));
-void vlog(int, const char *, va_list)
- __attribute__((__format__ (printf, 2, 0)));
-void log_warn(const char *, ...)
- __attribute__((__format__ (printf, 1, 2)));
-void log_warnx(const char *, ...)
- __attribute__((__format__ (printf, 1, 2)));
-void log_info(const char *, ...)
- __attribute__((__format__ (printf, 1, 2)));
-void log_debug(const char *, ...)
- __attribute__((__format__ (printf, 1, 2)));
-void fatal(const char *) __dead;
-void fatalx(const char *) __dead;
-const char *if_type_name(enum iface_type);
-const char *nbr_state_name(int);
+extern const char *log_procname;
-#endif /* _LOG_H_ */
+void log_init(int);
+void log_verbose(int);
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void fatal(const char *) __dead;
+void fatalx(const char *) __dead;
+
+#endif /* LOG_H */
diff --git a/usr.sbin/ripd/logmsg.c b/usr.sbin/ripd/logmsg.c
new file mode 100644
index 00000000000..91709d9ce9e
--- /dev/null
+++ b/usr.sbin/ripd/logmsg.c
@@ -0,0 +1,80 @@
+/* $OpenBSD: logmsg.c,v 1.1 2016/09/02 14:07:52 benno Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "ripd.h"
+
+/* names */
+const char *
+nbr_state_name(int state)
+{
+ switch (state) {
+ case NBR_STA_DOWN:
+ return ("DOWN");
+ case NBR_STA_REQ_RCVD:
+ return ("REQUEST RCVD");
+ case NBR_STA_ACTIVE:
+ return ("ACTIVE");
+ default:
+ return ("UNKNOWN");
+ }
+}
+
+const char *
+if_type_name(enum iface_type type)
+{
+ switch (type) {
+ case IF_TYPE_POINTOPOINT:
+ return ("POINTOPOINT");
+ case IF_TYPE_BROADCAST:
+ return ("BROADCAST");
+ case IF_TYPE_NBMA:
+ return ("NBMA");
+ case IF_TYPE_POINTOMULTIPOINT:
+ return ("POINTOMULTIPOINT");
+ }
+ /* NOTREACHED */
+ return ("UNKNOWN");
+}
+
+const char *
+if_auth_name(enum auth_type type)
+{
+ switch (type) {
+ case AUTH_NONE:
+ return ("none");
+ case AUTH_SIMPLE:
+ return ("simple");
+ case AUTH_CRYPT:
+ return ("crypt");
+ }
+ /* NOTREACHED */
+ return ("unknown");
+}
+
+const char *
+if_state_name(int state)
+{
+ switch (state) {
+ case IF_STA_DOWN:
+ return ("DOWN");
+ case IF_STA_ACTIVE:
+ return ("ACTIVE");
+ default:
+ return ("UNKNOWN");
+ }
+}
diff --git a/usr.sbin/ripd/rde.c b/usr.sbin/ripd/rde.c
index e2fed2672d2..70940d62a26 100644
--- a/usr.sbin/ripd/rde.c
+++ b/usr.sbin/ripd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.19 2015/12/05 13:13:47 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.20 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -102,6 +102,7 @@ rde(struct ripd_conf *xconf, int pipe_parent2rde[2], int pipe_ripe2rde[2],
setproctitle("route decision engine");
ripd_process = PROC_RDE_ENGINE;
+ log_procname = log_procnames[ripd_process];
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git a/usr.sbin/ripd/ripd.c b/usr.sbin/ripd/ripd.c
index 1ffaf95146e..95bf8f56d5f 100644
--- a/usr.sbin/ripd/ripd.c
+++ b/usr.sbin/ripd/ripd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripd.c,v 1.28 2016/08/02 16:05:32 jca Exp $ */
+/* $OpenBSD: ripd.c,v 1.29 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -128,6 +128,7 @@ main(int argc, char *argv[])
conffile = CONF_FILE;
ripd_process = PROC_MAIN;
+ log_procname = log_procnames[ripd_process];
sockname = RIPD_SOCKET;
log_init(1); /* log to stderr until daemonized */
diff --git a/usr.sbin/ripd/ripd.h b/usr.sbin/ripd/ripd.h
index b5ed21592c4..3bc45813740 100644
--- a/usr.sbin/ripd/ripd.h
+++ b/usr.sbin/ripd/ripd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripd.h,v 1.23 2016/08/02 16:05:32 jca Exp $ */
+/* $OpenBSD: ripd.h,v 1.24 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -17,8 +17,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef _RIPD_H_
-#define _RIPD_H_
+#ifndef RIPD_H
+#define RIPD_H
#include <sys/queue.h>
#include <sys/socket.h>
@@ -96,6 +96,12 @@ enum imsg_type {
IMSG_DEMOTE
};
+static const char * const log_procnames[] = {
+ "parent",
+ "ripe",
+ "rde"
+};
+
struct imsgev {
struct imsgbuf ibuf;
void (*handler)(int, short, void *);
@@ -348,10 +354,11 @@ int carp_demote_set(char *, int);
/* printconf.c */
void print_config(struct ripd_conf *);
-/* log.c */
-const char *if_state_name(int);
-const char *if_auth_name(enum auth_type);
+/* logmsg.c */
const char *nbr_state_name(int);
+const char *if_type_name(enum iface_type);
+const char *if_auth_name(enum auth_type);
+const char *if_state_name(int);
/* interface.c */
struct iface *if_find_index(u_short);
@@ -361,4 +368,4 @@ u_int16_t rtlabel_name2id(const char *);
const char *rtlabel_id2name(u_int16_t);
void rtlabel_unref(u_int16_t);
-#endif /* _RIPD_H_ */
+#endif /* RIPD_H */
diff --git a/usr.sbin/ripd/ripe.c b/usr.sbin/ripd/ripe.c
index 36d91c435f0..b70fb8c151c 100644
--- a/usr.sbin/ripd/ripe.c
+++ b/usr.sbin/ripd/ripe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripe.c,v 1.20 2016/08/02 16:05:32 jca Exp $ */
+/* $OpenBSD: ripe.c,v 1.21 2016/09/02 14:07:52 benno Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -128,6 +128,7 @@ ripe(struct ripd_conf *xconf, int pipe_parent2ripe[2], int pipe_ripe2rde[2],
setproctitle("rip engine");
ripd_process = PROC_RIP_ENGINE;
+ log_procname = log_procnames[ripd_process];
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||