diff options
-rw-r--r-- | usr.sbin/eigrpctl/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/eigrpd/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpd.c | 3 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpd.h | 21 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpe.c | 3 | ||||
-rw-r--r-- | usr.sbin/eigrpd/log.c | 220 | ||||
-rw-r--r-- | usr.sbin/eigrpd/log.h | 58 | ||||
-rw-r--r-- | usr.sbin/eigrpd/logmsg.c | 228 |
8 files changed, 292 insertions, 251 deletions
diff --git a/usr.sbin/eigrpctl/Makefile b/usr.sbin/eigrpctl/Makefile index 60b1a7dd966..ea7e98229d9 100644 --- a/usr.sbin/eigrpctl/Makefile +++ b/usr.sbin/eigrpctl/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.1 2015/10/02 04:31:52 renato Exp $ +# $OpenBSD: Makefile,v 1.2 2016/09/02 18:00:07 benno Exp $ .PATH: ${.CURDIR}/../eigrpd PROG= eigrpctl -SRCS= util.c log.c eigrpctl.c parser.c +SRCS= util.c log.c logmsg.c eigrpctl.c parser.c CFLAGS+= -Wall CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual diff --git a/usr.sbin/eigrpd/Makefile b/usr.sbin/eigrpd/Makefile index 9768067adae..1c61bc13e06 100644 --- a/usr.sbin/eigrpd/Makefile +++ b/usr.sbin/eigrpd/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.1 2015/10/02 04:26:47 renato Exp $ +# $OpenBSD: Makefile,v 1.2 2016/09/02 17:59:58 benno Exp $ PROG= eigrpd SRCS= control.c eigrpd.c eigrpe.c hello.c in_cksum.c interface.c \ - kroute.c log.c neighbor.c packet.c parse.y printconf.c query.c \ - rde.c rde_dual.c reply.c rtp.c tlv.c update.c util.c + kroute.c log.c logmsg.c neighbor.c packet.c parse.y printconf.c \ + query.c rde.c rde_dual.c reply.c rtp.c tlv.c update.c util.c MAN= eigrpd.8 eigrpd.conf.5 diff --git a/usr.sbin/eigrpd/eigrpd.c b/usr.sbin/eigrpd/eigrpd.c index 56f9b766a4e..6e5d5ddf6da 100644 --- a/usr.sbin/eigrpd/eigrpd.c +++ b/usr.sbin/eigrpd/eigrpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpd.c,v 1.20 2016/09/02 16:44:33 renato Exp $ */ +/* $OpenBSD: eigrpd.c,v 1.21 2016/09/02 17:59:58 benno Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -111,6 +111,7 @@ main(int argc, char *argv[]) conffile = CONF_FILE; eigrpd_process = PROC_MAIN; + log_procname = log_procnames[eigrpd_process]; sockname = EIGRPD_SOCKET; log_init(1); /* log to stderr until daemonized */ diff --git a/usr.sbin/eigrpd/eigrpd.h b/usr.sbin/eigrpd/eigrpd.h index 71985ad0115..f5b2a94375b 100644 --- a/usr.sbin/eigrpd/eigrpd.h +++ b/usr.sbin/eigrpd/eigrpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpd.h,v 1.21 2016/09/02 16:46:29 renato Exp $ */ +/* $OpenBSD: eigrpd.h,v 1.22 2016/09/02 17:59:58 benno Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -61,6 +61,12 @@ #define F_CTL_ACTIVE 0x0400 #define F_CTL_ALLLINKS 0x0800 +static const char * const log_procnames[] = { + "parent", + "eigrpe", + "rde" +}; + struct imsgev { struct imsgbuf ibuf; void (*handler)(int, short, void *); @@ -502,4 +508,17 @@ void config_clear(struct eigrpd_conf *); /* printconf.c */ void print_config(struct eigrpd_conf *); +/* logmsg.c */ +const char *log_in6addr(const struct in6_addr *); +const char *log_in6addr_scope(const struct in6_addr *, unsigned int); +const char *log_sockaddr(void *); +const char *log_addr(int, union eigrpd_addr *); +const char *log_prefix(struct rt_node *); +const char *log_route_origin(int, struct rde_nbr *); +const char *opcode_name(uint8_t); +const char *af_name(int); +const char *if_type_name(enum iface_type); +const char *dual_state_name(int); +const char *ext_proto_name(int); + #endif /* _EIGRPD_H_ */ diff --git a/usr.sbin/eigrpd/eigrpe.c b/usr.sbin/eigrpd/eigrpe.c index 5e891129fa5..5daba291106 100644 --- a/usr.sbin/eigrpd/eigrpe.c +++ b/usr.sbin/eigrpd/eigrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpe.c,v 1.33 2016/09/02 16:46:29 renato Exp $ */ +/* $OpenBSD: eigrpe.c,v 1.34 2016/09/02 17:59:58 benno Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -126,6 +126,7 @@ eigrpe(int debug, int verbose, char *sockname) setproctitle("eigrp engine"); eigrpd_process = PROC_EIGRP_ENGINE; + log_procname = log_procnames[eigrpd_process]; if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || diff --git a/usr.sbin/eigrpd/log.c b/usr.sbin/eigrpd/log.c index 130f370bdec..a48307538bd 100644 --- a/usr.sbin/eigrpd/log.c +++ b/usr.sbin/eigrpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.6 2016/09/02 16:46:29 renato Exp $ */ +/* $OpenBSD: log.c,v 1.7 2016/09/02 17:59:58 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -26,20 +26,17 @@ #include <stdlib.h> #include <string.h> #include <syslog.h> +#include <time.h> #include <unistd.h> +#include <arpa/inet.h> +#include <netdb.h> #include "eigrpd.h" -#include "rde.h" #include "log.h" -static const char * const procnames[] = { - "parent", - "eigrpe", - "rde" -}; - -int debug; -int verbose; +int debug; +int verbose; +const char *log_procname; void log_init(int n_debug) @@ -149,15 +146,15 @@ void fatal(const char *emsg) { if (emsg == NULL) - logit(LOG_CRIT, "fatal in %s: %s", procnames[eigrpd_process], + logit(LOG_CRIT, "fatal in %s: %s", log_procnames[eigrpd_process], strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", - procnames[eigrpd_process], emsg, strerror(errno)); + log_procnames[eigrpd_process], emsg, strerror(errno)); else logit(LOG_CRIT, "fatal in %s: %s", - procnames[eigrpd_process], emsg); + log_procnames[eigrpd_process], emsg); exit(1); } @@ -168,200 +165,3 @@ fatalx(const char *emsg) errno = 0; fatal(emsg); } - -#define NUM_LOGS 4 -const char * -log_sockaddr(void *vp) -{ - static char buf[NUM_LOGS][NI_MAXHOST]; - static int round = 0; - struct sockaddr *sa = vp; - - round = (round + 1) % NUM_LOGS; - - if (getnameinfo(sa, sa->sa_len, buf[round], NI_MAXHOST, NULL, 0, - NI_NUMERICHOST)) - return ("(unknown)"); - else - return (buf[round]); -} - -const char * -log_in6addr(const struct in6_addr *addr) -{ - struct sockaddr_in6 sa_in6; - - memset(&sa_in6, 0, sizeof(sa_in6)); - sa_in6.sin6_len = sizeof(sa_in6); - sa_in6.sin6_family = AF_INET6; - sa_in6.sin6_addr = *addr; - - recoverscope(&sa_in6); - - return (log_sockaddr(&sa_in6)); -} - -const char * -log_in6addr_scope(const struct in6_addr *addr, unsigned int ifindex) -{ - struct sockaddr_in6 sa_in6; - - memset(&sa_in6, 0, sizeof(sa_in6)); - sa_in6.sin6_len = sizeof(sa_in6); - sa_in6.sin6_family = AF_INET6; - sa_in6.sin6_addr = *addr; - - addscope(&sa_in6, ifindex); - - return (log_sockaddr(&sa_in6)); -} - -const char * -log_addr(int af, union eigrpd_addr *addr) -{ - static char buf[NUM_LOGS][INET6_ADDRSTRLEN]; - static int round = 0; - - switch (af) { - case AF_INET: - round = (round + 1) % NUM_LOGS; - if (inet_ntop(AF_INET, &addr->v4, buf[round], - sizeof(buf[round])) == NULL) - return ("???"); - return (buf[round]); - case AF_INET6: - return (log_in6addr(&addr->v6)); - default: - break; - } - - return ("???"); -} - -const char * -log_prefix(struct rt_node *rn) -{ - static char buf[64]; - - if (snprintf(buf, sizeof(buf), "%s/%u", log_addr(rn->eigrp->af, - &rn->prefix), rn->prefixlen) == -1) - return ("???"); - - return (buf); -} - -const char * -log_route_origin(int af, struct rde_nbr *nbr) -{ - if (nbr->flags & F_RDE_NBR_SELF) { - if (nbr->flags & F_RDE_NBR_REDIST) - return ("redistribute"); - if (nbr->flags & F_RDE_NBR_SUMMARY) - return ("summary"); - else - return ("connected"); - } - - return (log_addr(af, &nbr->addr)); -} - -const char * -opcode_name(uint8_t opcode) -{ - switch (opcode) { - case EIGRP_OPC_UPDATE: - return ("UPDATE"); - case EIGRP_OPC_REQUEST: - return ("REQUEST"); - case EIGRP_OPC_QUERY: - return ("QUERY"); - case EIGRP_OPC_REPLY: - return ("REPLY"); - case EIGRP_OPC_HELLO: - return ("HELLO"); - case EIGRP_OPC_PROBE: - return ("PROBE"); - case EIGRP_OPC_SIAQUERY: - return ("SIAQUERY"); - case EIGRP_OPC_SIAREPLY: - return ("SIAREPLY"); - default: - return ("UNKNOWN"); - } -} - -const char * -af_name(int af) -{ - switch (af) { - case AF_INET: - return ("ipv4"); - case AF_INET6: - return ("ipv6"); - 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"); - default: - return ("UNKNOWN"); - } -} - -const char * -dual_state_name(int state) -{ - switch (state) { - case DUAL_STA_PASSIVE: - return ("PASSIVE"); - case DUAL_STA_ACTIVE0: - return ("ACTIVE(Oij=0)"); - case DUAL_STA_ACTIVE1: - return ("ACTIVE(Oij=1)"); - case DUAL_STA_ACTIVE2: - return ("ACTIVE(Oij=2)"); - case DUAL_STA_ACTIVE3: - return ("ACTIVE(Oij=3)"); - default: - return ("UNKNOWN"); - } -} - -const char * -ext_proto_name(int proto) -{ - switch (proto) { - case EIGRP_EXT_PROTO_IGRP: - return ("IGRP"); - case EIGRP_EXT_PROTO_EIGRP: - return ("EIGRP"); - case EIGRP_EXT_PROTO_STATIC: - return ("Static"); - case EIGRP_EXT_PROTO_RIP: - return ("RIP"); - case EIGRP_EXT_PROTO_HELLO: - return ("HELLO"); - case EIGRP_EXT_PROTO_OSPF: - return ("OSPF"); - case EIGRP_EXT_PROTO_ISIS: - return ("ISIS"); - case EIGRP_EXT_PROTO_EGP: - return ("EGP"); - case EIGRP_EXT_PROTO_BGP: - return ("BGP"); - case EIGRP_EXT_PROTO_IDRP: - return ("IDRP"); - case EIGRP_EXT_PROTO_CONN: - return ("Connected"); - default: - return ("UNKNOWN"); - } -} diff --git a/usr.sbin/eigrpd/log.h b/usr.sbin/eigrpd/log.h index 557a4d47ee4..62824abd4c4 100644 --- a/usr.sbin/eigrpd/log.h +++ b/usr.sbin/eigrpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.4 2016/09/02 16:44:33 renato Exp $ */ +/* $OpenBSD: log.h,v 1.5 2016/09/02 17:59:58 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -16,39 +16,31 @@ * 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 - __attribute__((__format__ (printf, 1, 0))); -void fatalx(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); -const char *log_in6addr(const struct in6_addr *); -const char *log_in6addr_scope(const struct in6_addr *, unsigned int); -const char *log_sockaddr(void *); -const char *log_addr(int, union eigrpd_addr *); -const char *log_prefix(struct rt_node *); -const char *log_route_origin(int, struct rde_nbr *); -const char *opcode_name(uint8_t); -const char *af_name(int); -const char *if_type_name(enum iface_type); -const char *dual_state_name(int); -const char *ext_proto_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 + __attribute__((__format__ (printf, 1, 0))); +void fatalx(const char *) __dead + __attribute__((__format__ (printf, 1, 0))); + +#endif /* LOG_H */ diff --git a/usr.sbin/eigrpd/logmsg.c b/usr.sbin/eigrpd/logmsg.c new file mode 100644 index 00000000000..61e0be6d6cd --- /dev/null +++ b/usr.sbin/eigrpd/logmsg.c @@ -0,0 +1,228 @@ +/* $OpenBSD: logmsg.c,v 1.1 2016/09/02 17:59:58 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 <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include <unistd.h> +#include <arpa/inet.h> +#include <netdb.h> + +#include "eigrpd.h" +#include "rde.h" +#include "log.h" + +#define NUM_LOGS 4 +const char * +log_sockaddr(void *vp) +{ + static char buf[NUM_LOGS][NI_MAXHOST]; + static int round = 0; + struct sockaddr *sa = vp; + + round = (round + 1) % NUM_LOGS; + + if (getnameinfo(sa, sa->sa_len, buf[round], NI_MAXHOST, NULL, 0, + NI_NUMERICHOST)) + return ("(unknown)"); + else + return (buf[round]); +} + +const char * +log_in6addr(const struct in6_addr *addr) +{ + struct sockaddr_in6 sa_in6; + + memset(&sa_in6, 0, sizeof(sa_in6)); + sa_in6.sin6_len = sizeof(sa_in6); + sa_in6.sin6_family = AF_INET6; + sa_in6.sin6_addr = *addr; + + recoverscope(&sa_in6); + + return (log_sockaddr(&sa_in6)); +} + +const char * +log_in6addr_scope(const struct in6_addr *addr, unsigned int ifindex) +{ + struct sockaddr_in6 sa_in6; + + memset(&sa_in6, 0, sizeof(sa_in6)); + sa_in6.sin6_len = sizeof(sa_in6); + sa_in6.sin6_family = AF_INET6; + sa_in6.sin6_addr = *addr; + + addscope(&sa_in6, ifindex); + + return (log_sockaddr(&sa_in6)); +} + +const char * +log_addr(int af, union eigrpd_addr *addr) +{ + static char buf[NUM_LOGS][INET6_ADDRSTRLEN]; + static int round = 0; + + switch (af) { + case AF_INET: + round = (round + 1) % NUM_LOGS; + if (inet_ntop(AF_INET, &addr->v4, buf[round], + sizeof(buf[round])) == NULL) + return ("???"); + return (buf[round]); + case AF_INET6: + return (log_in6addr(&addr->v6)); + default: + break; + } + + return ("???"); +} + +const char * +log_prefix(struct rt_node *rn) +{ + static char buf[64]; + + if (snprintf(buf, sizeof(buf), "%s/%u", log_addr(rn->eigrp->af, + &rn->prefix), rn->prefixlen) == -1) + return ("???"); + + return (buf); +} + +const char * +log_route_origin(int af, struct rde_nbr *nbr) +{ + if (nbr->flags & F_RDE_NBR_SELF) { + if (nbr->flags & F_RDE_NBR_REDIST) + return ("redistribute"); + if (nbr->flags & F_RDE_NBR_SUMMARY) + return ("summary"); + else + return ("connected"); + } + + return (log_addr(af, &nbr->addr)); +} + +const char * +opcode_name(uint8_t opcode) +{ + switch (opcode) { + case EIGRP_OPC_UPDATE: + return ("UPDATE"); + case EIGRP_OPC_REQUEST: + return ("REQUEST"); + case EIGRP_OPC_QUERY: + return ("QUERY"); + case EIGRP_OPC_REPLY: + return ("REPLY"); + case EIGRP_OPC_HELLO: + return ("HELLO"); + case EIGRP_OPC_PROBE: + return ("PROBE"); + case EIGRP_OPC_SIAQUERY: + return ("SIAQUERY"); + case EIGRP_OPC_SIAREPLY: + return ("SIAREPLY"); + default: + return ("UNKNOWN"); + } +} + +const char * +af_name(int af) +{ + switch (af) { + case AF_INET: + return ("ipv4"); + case AF_INET6: + return ("ipv6"); + 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"); + default: + return ("UNKNOWN"); + } +} + +const char * +dual_state_name(int state) +{ + switch (state) { + case DUAL_STA_PASSIVE: + return ("PASSIVE"); + case DUAL_STA_ACTIVE0: + return ("ACTIVE(Oij=0)"); + case DUAL_STA_ACTIVE1: + return ("ACTIVE(Oij=1)"); + case DUAL_STA_ACTIVE2: + return ("ACTIVE(Oij=2)"); + case DUAL_STA_ACTIVE3: + return ("ACTIVE(Oij=3)"); + default: + return ("UNKNOWN"); + } +} + +const char * +ext_proto_name(int proto) +{ + switch (proto) { + case EIGRP_EXT_PROTO_IGRP: + return ("IGRP"); + case EIGRP_EXT_PROTO_EIGRP: + return ("EIGRP"); + case EIGRP_EXT_PROTO_STATIC: + return ("Static"); + case EIGRP_EXT_PROTO_RIP: + return ("RIP"); + case EIGRP_EXT_PROTO_HELLO: + return ("HELLO"); + case EIGRP_EXT_PROTO_OSPF: + return ("OSPF"); + case EIGRP_EXT_PROTO_ISIS: + return ("ISIS"); + case EIGRP_EXT_PROTO_EGP: + return ("EGP"); + case EIGRP_EXT_PROTO_BGP: + return ("BGP"); + case EIGRP_EXT_PROTO_IDRP: + return ("IDRP"); + case EIGRP_EXT_PROTO_CONN: + return ("Connected"); + default: + return ("UNKNOWN"); + } +} |