diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile.am | 8 | ||||
| -rw-r--r-- | lib/command.c | 28 | ||||
| -rw-r--r-- | lib/filter.c | 4 | ||||
| -rw-r--r-- | lib/grammar_sandbox_main.c | 8 | ||||
| -rw-r--r-- | lib/if.c | 4 | ||||
| -rw-r--r-- | lib/libfrr.c | 392 | ||||
| -rw-r--r-- | lib/libfrr.h | 100 | ||||
| -rw-r--r-- | lib/log.c | 110 | ||||
| -rw-r--r-- | lib/log.h | 71 | ||||
| -rw-r--r-- | lib/log_int.h | 57 | ||||
| -rw-r--r-- | lib/plist.c | 3 | ||||
| -rw-r--r-- | lib/prefix.c | 3 | ||||
| -rw-r--r-- | lib/routemap.c | 11 | ||||
| -rw-r--r-- | lib/sockopt.c | 23 | ||||
| -rw-r--r-- | lib/sockopt.h | 4 | ||||
| -rw-r--r-- | lib/sockunion.c | 37 | ||||
| -rw-r--r-- | lib/thread.c | 3 | ||||
| -rw-r--r-- | lib/thread.h | 5 | ||||
| -rw-r--r-- | lib/vty.c | 33 | ||||
| -rw-r--r-- | lib/vty.h | 2 | 
20 files changed, 669 insertions, 237 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index a9fe646938..1a8c7af42b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -29,6 +29,7 @@ libfrr_la_SOURCES = \  	grammar_sandbox.c \  	srcdest_table.c \  	spf_backoff.c \ +	libfrr.c \  	strlcpy.c \  	strlcat.c @@ -52,10 +53,13 @@ pkginclude_HEADERS = \  	event_counter.h \  	monotime.h \  	spf_backoff.h \ -	srcdest_table.h +	srcdest_table.h \ +	libfrr.h \ +	# end  noinst_HEADERS = \ -	plist_int.h +	plist_int.h \ +	log_int.h  noinst_PROGRAMS = grammar_sandbox diff --git a/lib/command.c b/lib/command.c index 50976f2010..bfff581d9b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -30,6 +30,7 @@  #include "memory.h"  #include "log.h" +#include "log_int.h"  #include <lib/version.h>  #include "thread.h"  #include "vector.h" @@ -2163,7 +2164,7 @@ DEFUN (config_logmsg,    if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)      return CMD_ERR_NO_MATCH; -  zlog(NULL, level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : "")); +  zlog(level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : ""));    if (message)      XFREE(MTYPE_TMP, message); @@ -2214,7 +2215,7 @@ DEFUN (show_logging,    vty_out (vty, "%s", VTY_NEWLINE);    vty_out (vty, "Protocol name: %s%s", -           zlog_proto_names[zl->protocol], VTY_NEWLINE); +           zl->protoname, VTY_NEWLINE);    vty_out (vty, "Record priority: %s%s",             (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE);    vty_out (vty, "Timestamp precision: %d%s", @@ -2234,14 +2235,14 @@ DEFUN (config_log_stdout,    if (argc == idx_log_level)    { -    zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl); +    zlog_set_level (ZLOG_DEST_STDOUT, zlog_default->default_lvl);      return CMD_SUCCESS;    }    int level;    if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)      return CMD_ERR_NO_MATCH; -  zlog_set_level (NULL, ZLOG_DEST_STDOUT, level); +  zlog_set_level (ZLOG_DEST_STDOUT, level);    return CMD_SUCCESS;  } @@ -2253,7 +2254,7 @@ DEFUN (no_config_log_stdout,         "Cancel logging to stdout\n"         LOG_LEVEL_DESC)  { -  zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); +  zlog_set_level (ZLOG_DEST_STDOUT, ZLOG_DISABLED);    return CMD_SUCCESS;  } @@ -2268,14 +2269,14 @@ DEFUN (config_log_monitor,    if (argc == idx_log_level)    { -    zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl); +    zlog_set_level (ZLOG_DEST_MONITOR, zlog_default->default_lvl);      return CMD_SUCCESS;    }    int level;    if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)      return CMD_ERR_NO_MATCH; -  zlog_set_level (NULL, ZLOG_DEST_MONITOR, level); +  zlog_set_level (ZLOG_DEST_MONITOR, level);    return CMD_SUCCESS;  } @@ -2287,7 +2288,7 @@ DEFUN (no_config_log_monitor,         "Disable terminal line (monitor) logging\n"         LOG_LEVEL_DESC)  { -  zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); +  zlog_set_level (ZLOG_DEST_MONITOR, ZLOG_DISABLED);    return CMD_SUCCESS;  } @@ -2322,7 +2323,7 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)    else      fullpath = fname; -  ret = zlog_set_file (NULL, fullpath, loglevel); +  ret = zlog_set_file (fullpath, loglevel);    if (p)      XFREE (MTYPE_TMP, p); @@ -2376,7 +2377,7 @@ DEFUN (no_config_log_file,         "Logging file name\n"         "Logging level\n")  { -  zlog_reset_file (NULL); +  zlog_reset_file ();    if (host.logfile)      XFREE (MTYPE_HOST, host.logfile); @@ -2399,12 +2400,12 @@ DEFUN (config_log_syslog,      int level;      if ((level = level_match (argv[idx_log_levels]->arg)) == ZLOG_DISABLED)        return CMD_ERR_NO_MATCH; -    zlog_set_level (NULL, ZLOG_DEST_SYSLOG, level); +    zlog_set_level (ZLOG_DEST_SYSLOG, level);      return CMD_SUCCESS;    }    else    { -    zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); +    zlog_set_level (ZLOG_DEST_SYSLOG, zlog_default->default_lvl);      return CMD_SUCCESS;    }  } @@ -2418,7 +2419,7 @@ DEFUN (no_config_log_syslog,         LOG_FACILITY_DESC         LOG_LEVEL_DESC)  { -  zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); +  zlog_set_level (ZLOG_DEST_SYSLOG, ZLOG_DISABLED);    return CMD_SUCCESS;  } @@ -2726,7 +2727,6 @@ cmd_init (int terminal)        vrf_install_commands ();      } -  srandom(time(NULL));  #ifdef DEV_BUILD    grammar_sandbox_init(); diff --git a/lib/filter.c b/lib/filter.c index 2b9ba87137..fd73d4de73 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -1697,9 +1697,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi)      return 0;    /* Print the name of the protocol */ -  if (zlog_default) -      vty_out (vty, "%s:%s", -      zlog_proto_names[zlog_default->protocol], VTY_NEWLINE); +  vty_out(vty, "%s:%s", zlog_protoname(), VTY_NEWLINE);    for (access = master->num.head; access; access = access->next)      { diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c index 5deef406c1..681d4da440 100644 --- a/lib/grammar_sandbox_main.c +++ b/lib/grammar_sandbox_main.c @@ -40,11 +40,11 @@ int main(int argc, char **argv)    master = thread_master_create (); -  zlog_default = openzlog ("grammar_sandbox", ZLOG_NONE, 0, +  openzlog ("grammar_sandbox", "NONE", 0,                             LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); -  zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); -  zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); -  zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); +  zlog_set_level (ZLOG_DEST_SYSLOG, ZLOG_DISABLED); +  zlog_set_level (ZLOG_DEST_STDOUT, LOG_DEBUG); +  zlog_set_level (ZLOG_DEST_MONITOR, ZLOG_DISABLED);    /* Library inits. */    cmd_init (1); @@ -987,7 +987,7 @@ connected_log (struct connected *connected, char *str)        strncat (logbuf, inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),  	       BUFSIZ - strlen(logbuf));      } -  zlog (NULL, LOG_INFO, "%s", logbuf); +  zlog_info("%s", logbuf);  }  /* Print if_addr structure. */ @@ -1007,7 +1007,7 @@ nbr_connected_log (struct nbr_connected *connected, char *str)  	    inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),  	    p->prefixlen); -  zlog (NULL, LOG_INFO, "%s", logbuf); +  zlog_info("%s", logbuf);  }  /* If two connected address has same prefix return 1. */ diff --git a/lib/libfrr.c b/lib/libfrr.c new file mode 100644 index 0000000000..f9ac3158a3 --- /dev/null +++ b/lib/libfrr.c @@ -0,0 +1,392 @@ +/* + * libfrr overall management functions + * + * Copyright (C) 2016  David Lamparter for NetDEF, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA  02111-1307  USA + */ + +#include <zebra.h> + +#include "libfrr.h" +#include "getopt.h" +#include "vty.h" +#include "command.h" +#include "version.h" +#include "memory_vty.h" +#include "zclient.h" + +const char frr_sysconfdir[] = SYSCONFDIR; +const char frr_vtydir[] = DAEMON_VTY_DIR; + +char config_default[256]; +static char pidfile_default[256]; +static char vtypath_default[256]; + +static char comb_optstr[256]; +static struct option comb_lo[64]; +static struct option *comb_next_lo = &comb_lo[0]; +static char comb_helpstr[4096]; + +struct optspec { +	const char *optstr; +	const char *helpstr; +	const struct option *longopts; +}; + +static void opt_extend(const struct optspec *os) +{ +	const struct option *lo; + +	strcat(comb_optstr, os->optstr); +	strcat(comb_helpstr, os->helpstr); +	for (lo = os->longopts; lo->name; lo++) +		memcpy(comb_next_lo++, lo, sizeof(*lo)); +} + + +#define OPTION_VTYSOCK 1000 + +static const struct option lo_always[] = { +	{ "help",        no_argument,       NULL, 'h' }, +	{ "version",     no_argument,       NULL, 'v' }, +	{ "daemon",      no_argument,       NULL, 'd' }, +	{ "vty_socket",  required_argument, NULL, OPTION_VTYSOCK }, +	{ NULL } +}; +static const struct optspec os_always = { +	"hvdi:", +	"  -h, --help         Display this help and exit\n" +	"  -v, --version      Print program version\n" +	"  -d, --daemon       Runs in daemon mode\n" +	"      --vty_socket   Override vty socket path\n", +	lo_always +}; + + +static const struct option lo_cfg_pid_dry[] = { +	{ "pid_file",    required_argument, NULL, 'i' }, +	{ "config_file", required_argument, NULL, 'f' }, +	{ "dryrun",      no_argument,       NULL, 'C' }, +	{ NULL } +}; +static const struct optspec os_cfg_pid_dry = { +	"f:i:C", +	"  -f, --config_file  Set configuration file name\n" +	"  -i, --pid_file     Set process identifier file name\n" +	"  -C, --dryrun       Check configuration for validity and exit\n", +	lo_cfg_pid_dry +}; + + +static const struct option lo_zclient[] = { +	{ "socket", required_argument, NULL, 'z' }, +	{ NULL } +}; +static const struct optspec os_zclient = { +	"z:", +	"  -z, --socket       Set path of zebra socket\n", +	lo_zclient +}; + + +static const struct option lo_vty[] = { +	{ "vty_addr",   required_argument, NULL, 'A'}, +	{ "vty_port",   required_argument, NULL, 'P'}, +	{ NULL } +}; +static const struct optspec os_vty = { +	"A:P:", +	"  -A, --vty_addr     Set vty's bind address\n" +	"  -P, --vty_port     Set vty's port number\n", +	lo_vty +}; + + +static const struct option lo_user[] = { +	{ "user",  required_argument, NULL, 'u'}, +	{ "group", required_argument, NULL, 'g'}, +	{ NULL } +}; +static const struct optspec os_user = { +	"u:g:", +	"  -u, --user         User to run as\n" +	"  -g, --group        Group to run as\n", +	lo_user +}; + + +static struct frr_daemon_info *di = NULL; + +void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv) +{ +	di = daemon; + +	/* basename(), opencoded. */ +	char *p = strrchr(argv[0], '/'); +	di->progname = p ? p + 1 : argv[0]; + +	umask(0027); + +	opt_extend(&os_always); +	if (!(di->flags & FRR_NO_CFG_PID_DRY)) +		opt_extend(&os_cfg_pid_dry); +	if (!(di->flags & FRR_NO_PRIVSEP)) +		opt_extend(&os_user); +	if (!(di->flags & FRR_NO_ZCLIENT)) +		opt_extend(&os_zclient); +	if (!(di->flags & FRR_NO_TCPVTY)) +		opt_extend(&os_vty); + +	snprintf(config_default, sizeof(config_default), "%s/%s.conf", +			frr_sysconfdir, di->name); +	snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s.pid", +			frr_vtydir, di->name); +} + +void frr_opt_add(const char *optstr, const struct option *longopts, +		const char *helpstr) +{ +	const struct optspec main_opts = { optstr, helpstr, longopts }; +	opt_extend(&main_opts); +} + +void frr_help_exit(int status) +{ +	FILE *target = status ? stderr : stdout; + +	if (status != 0) +		fprintf(stderr, "Invalid options.\n\n"); + +	if (di->printhelp) +		di->printhelp(target); +	else +		fprintf(target, "Usage: %s [OPTION...]\n\n%s%s%s\n\n%s", +				di->progname, +				di->proghelp, +				di->copyright ? "\n\n" : "", +				di->copyright ? di->copyright : "", +				comb_helpstr); +	fprintf(target, "\nReport bugs to %s\n", FRR_BUG_ADDRESS); +	exit(status); +} + +static int errors = 0; + +static int frr_opt(int opt) +{ +	static int vty_port_set = 0; +	static int vty_addr_set = 0; +	char *err; + +	switch (opt) { +	case 'h': +		frr_help_exit(0); +		break; +	case 'v': +		print_version(di->progname); +		exit(0); +		break; +	case 'd': +		di->daemon_mode = 1; +		break; +	case 'i': +		if (di->flags & FRR_NO_CFG_PID_DRY) +			return 1; +		di->pid_file = optarg; +		break; +	case 'f': +		if (di->flags & FRR_NO_CFG_PID_DRY) +			return 1; +		di->config_file = optarg; +		break; +	case 'C': +		if (di->flags & FRR_NO_CFG_PID_DRY) +			return 1; +		di->dryrun = 1; +		break; +	case 'z': +		if (di->flags & FRR_NO_ZCLIENT) +			return 1; +		zclient_serv_path_set(optarg); +		break; +	case 'A': +		if (di->flags & FRR_NO_TCPVTY) +			return 1; +		if (vty_addr_set) { +			fprintf(stderr, "-A option specified more than once!\n"); +			errors++; +			break; +		} +		vty_addr_set = 1; +		di->vty_addr = optarg; +		break; +	case 'P': +		if (di->flags & FRR_NO_TCPVTY) +			return 1; +		if (vty_port_set) { +			fprintf(stderr, "-P option specified more than once!\n"); +			errors++; +			break; +		} +		vty_port_set = 1; +		di->vty_port = strtoul(optarg, &err, 0); +		if (*err || !*optarg) { +			fprintf(stderr, "invalid port number \"%s\" for -P option\n", +					optarg); +			errors++; +			break; +		} +		break; +	case OPTION_VTYSOCK: +		if (di->vty_sock_path) { +			fprintf(stderr, "--vty_socket option specified more than once!\n"); +			errors++; +			break; +		} +		di->vty_sock_path = optarg; +		break; +	case 'u': +		if (di->flags & FRR_NO_PRIVSEP) +			return 1; +		di->privs->user = optarg; +		break; +	case 'g': +		if (di->flags & FRR_NO_PRIVSEP) +			return 1; +		di->privs->group = optarg; +		break; +	default: +		return 1; +	} +	return 0; +} + +int frr_getopt(int argc, char * const argv[], int *longindex) +{ +	int opt; +	int lidx; + +	comb_next_lo->name = NULL; + +	do { +		opt = getopt_long(argc, argv, comb_optstr, comb_lo, &lidx); +		if (frr_opt(opt)) +			break; +	} while (opt != -1); + +	if (opt == -1 && errors) +		frr_help_exit(1); +	if (longindex) +		*longindex = lidx; +	return opt; +} + +struct thread_master *frr_init(void) +{ +	struct thread_master *master; + +	srandom(time(NULL)); + +	openzlog (di->progname, di->logname, di->instance, +			LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); +#if defined(HAVE_CUMULUS) +	zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); +#endif + +	zprivs_init(di->privs); + +	master = thread_master_create(); +	signal_init(master, di->n_signals, di->signals); + +	if (di->flags & FRR_LIMITED_CLI) +		cmd_init(-1); +	else +		cmd_init(1); +	vty_init(master); +	memory_init(); + +	return master; +} + +void frr_config_fork(void) +{ +	if (di->instance) { +		snprintf(config_default, sizeof(config_default), "%s/%s-%d.conf", +				frr_sysconfdir, di->name, di->instance); +		snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s-%d.pid", +				frr_vtydir, di->name, di->instance); +	} + +	vty_read_config(di->config_file, config_default); + +	/* Don't start execution if we are in dry-run mode */ +	if (di->dryrun) +		exit(0); + +	/* Daemonize. */ +	if (di->daemon_mode && daemon (0, 0) < 0) { +		zlog_err("Zebra daemon failed: %s", strerror(errno)); +		exit(1); +	} + +	if (!di->pid_file) +		di->pid_file = pidfile_default; +	pid_output (di->pid_file); +} + +void frr_vty_serv(void) +{ +	/* allow explicit override of vty_path in the future  +	 * (not currently set anywhere) */ +	if (!di->vty_path) { +		const char *dir; +		dir = di->vty_sock_path ? di->vty_sock_path : frr_vtydir; + +		if (di->instance) +			snprintf(vtypath_default, sizeof(vtypath_default), +					"%s/%s-%d.vty", +					dir, di->name, di->instance); +		else +			snprintf(vtypath_default, sizeof(vtypath_default), +					"%s/%s.vty", dir, di->name); + +		di->vty_path = vtypath_default; +	} + +	vty_serv_sock(di->vty_addr, di->vty_port, di->vty_path); +} + +void frr_run(struct thread_master *master) +{ +	char instanceinfo[64] = ""; + +	frr_vty_serv(); + +	if (di->instance) +		snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ", +				di->instance); + +	zlog_notice("%s %s starting: %svty@%d%s", +			di->name, +			FRR_VERSION, +			instanceinfo, +			di->vty_port, +			di->startinfo); + +	struct thread thread; +	while (thread_fetch(master, &thread)) +		thread_call(&thread); +} diff --git a/lib/libfrr.h b/lib/libfrr.h new file mode 100644 index 0000000000..d37f406f5b --- /dev/null +++ b/lib/libfrr.h @@ -0,0 +1,100 @@ +/* + * libfrr overall management functions + * + * Copyright (C) 2016  David Lamparter for NetDEF, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA  02111-1307  USA + */ + +#ifndef _ZEBRA_FRR_H +#define _ZEBRA_FRR_H + +#include "sigevent.h" +#include "privs.h" +#include "thread.h" +#include "log.h" +#include "getopt.h" + +#define FRR_NO_PRIVSEP		(1 << 0) +#define FRR_NO_TCPVTY		(1 << 1) +#define FRR_LIMITED_CLI		(1 << 2) +#define FRR_NO_CFG_PID_DRY		(1 << 3) +#define FRR_NO_ZCLIENT		(1 << 4) + +struct frr_daemon_info { +	unsigned flags; + +	const char *progname; +	const char *name; +	const char *logname; +	unsigned short instance; + +	char *vty_addr; +	int vty_port; +	char *vty_sock_path; +	bool dryrun; +	bool daemon_mode; +	const char *config_file; +	const char *pid_file; +	const char *vty_path; + +	const char *proghelp; +	void (*printhelp)(FILE *target); +	const char *copyright; +	char startinfo[128]; + +	struct quagga_signal_t *signals; +	size_t n_signals; + +	struct zebra_privs_t *privs; +}; + +/* execname is the daemon's executable (and pidfile and configfile) name, + * i.e. "zebra" or "bgpd" + * constname is the daemons source-level name, primarily for the logging ID, + * i.e. "ZEBRA" or "BGP" + * + * note that this macro is also a latch-on point for other changes (e.g. + * upcoming plugin support) that need to place some per-daemon things.  Each + * daemon should have one of these. + */ +#define FRR_DAEMON_INFO(execname, constname, ...) \ +	static struct frr_daemon_info execname ##_di = { \ +		.name = # execname, \ +		.logname = # constname, \ +		__VA_ARGS__ \ +	}; + +extern void frr_preinit(struct frr_daemon_info *daemon, +		int argc, char **argv); +extern void frr_opt_add(const char *optstr, +		const struct option *longopts, const char *helpstr); +extern int frr_getopt(int argc, char * const argv[], int *longindex); +extern void frr_help_exit(int status); + +extern struct thread_master *frr_init(void); + +extern void frr_config_fork(void); + +extern void frr_vty_serv(void); + +/* note: contains call to frr_vty_serv() */ +extern void frr_run(struct thread_master *master); + +extern char config_default[256]; +extern const char frr_sysconfdir[]; +extern const char frr_vtydir[]; + +#endif /* _ZEBRA_FRR_H */ @@ -26,6 +26,7 @@  #include "zclient.h"  #include "log.h" +#include "log_int.h"  #include "memory.h"  #include "command.h"  #ifndef SUNOS_5 @@ -42,29 +43,6 @@ static int logfile_fd = -1;	/* Used in signal handler. */  struct zlog *zlog_default = NULL; -/* - * This must be kept in the same order as the - * zlog_proto_t enum - */ -const char *zlog_proto_names[] =  -{ -  "NONE", -  "DEFAULT", -  "ZEBRA", -  "RIP", -  "BGP", -  "OSPF", -  "RIPNG", -  "OSPF6", -  "LDP", -  "ISIS", -  "PIM", -  "NHRP", -  "RFP", -  "WATCHFRR", -  NULL, -}; -  const char *zlog_priority[] =  {    "emergencies", @@ -185,16 +163,13 @@ time_print(FILE *fp, struct timestamp_control *ctl)  /* va_list version of zlog. */  void -vzlog (struct zlog *zl, int priority, const char *format, va_list args) +vzlog (int priority, const char *format, va_list args)  {    char proto_str[32];    int original_errno = errno;    struct timestamp_control tsctl;    tsctl.already_rendered = 0; - -  /* If zlog is not specified, use default one. */ -  if (zl == NULL) -    zl = zlog_default; +  struct zlog *zl = zlog_default;    /* When zlog_default is also NULL, use stderr for logging. */    if (zl == NULL) @@ -222,9 +197,9 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list args)      }    if (zl->instance) -   sprintf (proto_str, "%s[%d]: ", zlog_proto_names[zl->protocol], zl->instance); +   sprintf (proto_str, "%s[%d]: ", zl->protoname, zl->instance);    else -   sprintf (proto_str, "%s: ", zlog_proto_names[zl->protocol]); +   sprintf (proto_str, "%s: ", zl->protoname);    /* File output. */    if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp) @@ -265,11 +240,9 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list args)  }  int  -vzlog_test (struct zlog *zl, int priority) +vzlog_test (int priority)  { -  /* If zlog is not specified, use default one. */ -  if (zl == NULL) -    zl = zlog_default; +  struct zlog *zl = zlog_default;    /* When zlog_default is also NULL, use stderr for logging. */    if (zl == NULL) @@ -456,7 +429,7 @@ zlog_signal(int signo, const char *action    time(&now);    if (zlog_default)      { -      s = str_append(LOC,zlog_proto_names[zlog_default->protocol]); +      s = str_append(LOC,zlog_default->protoname);        *s++ = ':';        *s++ = ' ';        msgstart = s; @@ -639,7 +612,7 @@ void  zlog_backtrace(int priority)  {  #ifndef HAVE_GLIBC_BACKTRACE -  zlog(NULL, priority, "No backtrace available on this platform."); +  zlog(priority, "No backtrace available on this platform.");  #else    void *array[20];    int size, i; @@ -653,29 +626,29 @@ zlog_backtrace(int priority)  	       size, (unsigned long)(array_size(array)));        return;      } -  zlog(NULL, priority, "Backtrace for %d stack frames:", size); +  zlog(priority, "Backtrace for %d stack frames:", size);    if (!(strings = backtrace_symbols(array, size)))      {        zlog_err("Cannot get backtrace symbols (out of memory?)");        for (i = 0; i < size; i++) -	zlog(NULL, priority, "[bt %d] %p",i,array[i]); +	zlog(priority, "[bt %d] %p",i,array[i]);      }    else      {        for (i = 0; i < size; i++) -	zlog(NULL, priority, "[bt %d] %s",i,strings[i]); +	zlog(priority, "[bt %d] %s",i,strings[i]);        free(strings);      }  #endif /* HAVE_GLIBC_BACKTRACE */  }  void -zlog (struct zlog *zl, int priority, const char *format, ...) +zlog (int priority, const char *format, ...)  {    va_list args;    va_start(args, format); -  vzlog (zl, priority, format, args); +  vzlog (priority, format, args);    va_end (args);  } @@ -685,7 +658,7 @@ FUNCNAME(const char *format, ...) \  { \    va_list args; \    va_start(args, format); \ -  vzlog (NULL, PRIORITY, format, args); \ +  vzlog (PRIORITY, format, args); \    va_end(args); \  } @@ -704,11 +677,11 @@ ZLOG_FUNC(zlog_debug, LOG_DEBUG)  void zlog_thread_info (int log_level)  {    if (thread_current) -    zlog(NULL, log_level, "Current thread function %s, scheduled from " +    zlog(log_level, "Current thread function %s, scheduled from "  	 "file %s, line %u", thread_current->funcname,  	 thread_current->schedfrom, thread_current->schedfrom_line);    else -    zlog(NULL, log_level, "Current thread not known/applicable"); +    zlog(log_level, "Current thread not known/applicable");  }  void @@ -720,7 +693,7 @@ _zlog_assert_failed (const char *assertion, const char *file,        ((logfile_fd = open_crashlog()) >= 0) &&        ((zlog_default->fp = fdopen(logfile_fd, "w")) != NULL))      zlog_default->maxlvl[ZLOG_DEST_FILE] = LOG_ERR; -  zlog(NULL, LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s", +  zlog(LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s",         assertion,file,line,(function ? function : "?"));    zlog_backtrace(LOG_CRIT);    zlog_thread_info(LOG_CRIT); @@ -738,8 +711,8 @@ memory_oom (size_t size, const char *name)  }  /* Open log stream */ -struct zlog * -openzlog (const char *progname, zlog_proto_t protocol, u_short instance, +void +openzlog (const char *progname, const char *protoname, u_short instance,  	  int syslog_flags, int syslog_facility)  {    struct zlog *zl; @@ -748,7 +721,7 @@ openzlog (const char *progname, zlog_proto_t protocol, u_short instance,    zl = XCALLOC(MTYPE_ZLOG, sizeof (struct zlog));    zl->ident = progname; -  zl->protocol = protocol; +  zl->protoname = protoname;    zl->instance = instance;    zl->facility = syslog_facility;    zl->syslog_options = syslog_flags; @@ -760,13 +733,14 @@ openzlog (const char *progname, zlog_proto_t protocol, u_short instance,    zl->default_lvl = LOG_DEBUG;    openlog (progname, syslog_flags, zl->facility); -   -  return zl; +  zlog_default = zl;  }  void -closezlog (struct zlog *zl) +closezlog (void)  { +  struct zlog *zl = zlog_default; +    closelog();    if (zl->fp != NULL) @@ -776,30 +750,31 @@ closezlog (struct zlog *zl)      XFREE(MTYPE_ZLOG, zl->filename);    XFREE (MTYPE_ZLOG, zl); +  zlog_default = NULL; +} + +const char * +zlog_protoname (void) +{ +  return zlog_default ? zlog_default->protoname : "NONE";  }  /* Called from command.c. */  void -zlog_set_level (struct zlog *zl, zlog_dest_t dest, int log_level) +zlog_set_level (zlog_dest_t dest, int log_level)  { -  if (zl == NULL) -    zl = zlog_default; - -  zl->maxlvl[dest] = log_level; +  zlog_default->maxlvl[dest] = log_level;  }  int -zlog_set_file (struct zlog *zl, const char *filename, int log_level) +zlog_set_file (const char *filename, int log_level)  { +  struct zlog *zl = zlog_default;    FILE *fp;    mode_t oldumask;    /* There is opend file.  */ -  zlog_reset_file (zl); - -  /* Set default zl. */ -  if (zl == NULL) -    zl = zlog_default; +  zlog_reset_file ();    /* Open file. */    oldumask = umask (0777 & ~LOGFILE_MASK); @@ -819,10 +794,9 @@ zlog_set_file (struct zlog *zl, const char *filename, int log_level)  /* Reset opend file. */  int -zlog_reset_file (struct zlog *zl) +zlog_reset_file (void)  { -  if (zl == NULL) -    zl = zlog_default; +  struct zlog *zl = zlog_default;    if (zl->fp)      fclose (zl->fp); @@ -839,13 +813,11 @@ zlog_reset_file (struct zlog *zl)  /* Reopen log file. */  int -zlog_rotate (struct zlog *zl) +zlog_rotate (void)  { +  struct zlog *zl = zlog_default;    int level; -  if (zl == NULL) -    zl = zlog_default; -    if (zl->fp)      fclose (zl->fp);    zl->fp = NULL; @@ -42,28 +42,6 @@   * please use LOG_ERR instead.   */ -/* - * This must be kept in the same order as - * zlog_proto_names[] - */ -typedef enum  -{ -  ZLOG_NONE, -  ZLOG_DEFAULT, -  ZLOG_ZEBRA, -  ZLOG_RIP, -  ZLOG_BGP, -  ZLOG_OSPF, -  ZLOG_RIPNG, -  ZLOG_OSPF6, -  ZLOG_LDP, -  ZLOG_ISIS, -  ZLOG_PIM, -  ZLOG_NHRP, -  ZLOG_RFP, -  ZLOG_WATCHFRR, -} zlog_proto_t; -  /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent     to that logging destination. */  #define ZLOG_DISABLED	(LOG_EMERG-1) @@ -77,23 +55,6 @@ typedef enum  } zlog_dest_t;  #define ZLOG_NUM_DESTS		(ZLOG_DEST_FILE+1) -struct zlog  -{ -  const char *ident;	/* daemon name (first arg to openlog) */ -  zlog_proto_t protocol; -  u_short      instance; -  int maxlvl[ZLOG_NUM_DESTS];	/* maximum priority to send to associated -  				   logging destination */ -  int default_lvl;	/* maxlvl to use if none is specified */ -  FILE *fp; -  char *filename; -  int facility;		/* as per syslog facility */ -  int record_priority;	/* should messages logged through stdio include the -  			   priority of the message? */ -  int syslog_options;	/* 2nd arg to openlog */ -  int timestamp_precision;	/* # of digits of subsecond precision */ -}; -  /* Message structure. */  struct message  { @@ -101,15 +62,14 @@ struct message    const char *str;  }; -/* Default logging strucutre. */ -extern struct zlog *zlog_default; -  /* Open zlog function */ -extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, -		              u_short instance, int syslog_options, int syslog_facility); +extern void openzlog (const char *progname, const char *protoname, +                      u_short instance, int syslog_options, int syslog_facility);  /* Close zlog function. */ -extern void closezlog (struct zlog *zl); +extern void closezlog (void); + +extern const char *zlog_protoname (void);  /* GCC have printf type attribute check.  */  #ifdef __GNUC__ @@ -118,35 +78,28 @@ extern void closezlog (struct zlog *zl);  #define PRINTF_ATTRIBUTE(a,b)  #endif /* __GNUC__ */ -/* Generic function for zlog. */ -extern void zlog (struct zlog *zl, int priority, const char *format, ...) -  PRINTF_ATTRIBUTE(3, 4); -  /* Handy zlog functions. */ -extern void vzlog (struct zlog *zl, int priority, const char *format, va_list args);  extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);  extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);  extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);  extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);  extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -extern void vzlog (struct zlog *, int , const char *, va_list ); -  extern void zlog_thread_info (int log_level);  /* Set logging level for the given destination.  If the log_level     argument is ZLOG_DISABLED, then the destination is disabled.     This function should not be used for file logging (use zlog_set_file     or zlog_reset_file instead). */ -extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); +extern void zlog_set_level (zlog_dest_t, int log_level);  /* Set logging to the given filename at the specified level. */ -extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level); +extern int zlog_set_file (const char *filename, int log_level);  /* Disable file logging. */ -extern int zlog_reset_file (struct zlog *zl); +extern int zlog_reset_file (void);  /* Rotate log. */ -extern int zlog_rotate (struct zlog *); +extern int zlog_rotate (void);  /* For hackey message lookup and check */  #define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x) @@ -157,9 +110,6 @@ extern const char *mes_lookup (const struct message *meslist,                                 int max, int index,                                 const char *no_item, const char *mesname); -extern const char *zlog_priority[]; -extern const char *zlog_proto_names[]; -  /* Safe version of strerror -- never returns NULL. */  extern const char *safe_strerror(int errnum); @@ -193,8 +143,7 @@ extern void zlog_hexdump(const void *mem, unsigned int len);  extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in, size_t inlen); -extern int  -vzlog_test (struct zlog *zl, int priority); +extern int vzlog_test (int priority);  /* structure useful for avoiding repeated rendering of the same timestamp */  struct timestamp_control { diff --git a/lib/log_int.h b/lib/log_int.h new file mode 100644 index 0000000000..c21d723ac6 --- /dev/null +++ b/lib/log_int.h @@ -0,0 +1,57 @@ +/* + * Zebra logging funcions. + * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING.  If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _ZEBRA_LOG_PRIVATE_H +#define _ZEBRA_LOG_PRIVATE_H + +#include "log.h" + +struct zlog +{ +  const char *ident;	/* daemon name (first arg to openlog) */ +  const char *protoname; +  u_short instance; +  int maxlvl[ZLOG_NUM_DESTS];   /* maximum priority to send to associated +                                   logging destination */ +  int default_lvl;      /* maxlvl to use if none is specified */ +  FILE *fp; +  char *filename; +  int facility;         /* as per syslog facility */ +  int record_priority;  /* should messages logged through stdio include the +                           priority of the message? */ +  int syslog_options;   /* 2nd arg to openlog */ +  int timestamp_precision;      /* # of digits of subsecond precision */ +}; + +/* Default logging strucutre. */ +extern struct zlog *zlog_default; + +extern const char *zlog_priority[]; + +/* Generic function for zlog. */ +extern void vzlog (int priority, const char *format, va_list args); +extern void zlog (int priority, const char *format, ...) +  PRINTF_ATTRIBUTE(2, 3); + +#endif /* _ZEBRA_LOG_PRIVATE_H */ + + diff --git a/lib/plist.c b/lib/plist.c index 3ed5c8fc5c..3714969696 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1175,8 +1175,7 @@ vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,    struct prefix_list_entry *pentry;    /* Print the name of the protocol */ -  if (zlog_default) -      vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]); +  vty_out(vty, "%s: ", zlog_protoname());    if (dtype == normal_display)      { diff --git a/lib/prefix.c b/lib/prefix.c index dec22a44a3..0cc759bb7c 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -313,8 +313,7 @@ prefix_copy (struct prefix *dest, const struct prefix *src)      }    else      { -      zlog (NULL, LOG_ERR, "prefix_copy(): Unknown address family %d", -	      src->family); +      zlog_err("prefix_copy(): Unknown address family %d", src->family);        assert (0);      }  } diff --git a/lib/routemap.c b/lib/routemap.c index 39d9a5d375..1647ac3668 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -28,6 +28,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  #include "routemap.h"  #include "command.h"  #include "log.h" +#include "log_int.h"  #include "hash.h"  DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP,          "Route map") @@ -991,7 +992,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map)    /* Print the name of the protocol */    if (zlog_default)    { -    vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]); +    vty_out (vty, "%s", zlog_protoname());      if (zlog_default->instance)        vty_out (vty, " %d", zlog_default->instance);    } @@ -1051,8 +1052,7 @@ vty_show_route_map (struct vty *vty, const char *name)          }        else          { -          if (zlog_default) -            vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]); +          vty_out (vty, "%s", zlog_protoname());            if (zlog_default && zlog_default->instance)              vty_out (vty, " %d", zlog_default->instance);            vty_out (vty, ": 'route-map %s' not found%s", name, VTY_NEWLINE); @@ -1614,9 +1614,8 @@ route_map_apply (struct route_map *map, struct prefix *prefix,    if (recursion > RMAP_RECURSION_LIMIT)      { -      zlog (NULL, LOG_WARNING, -            "route-map recursion limit (%d) reached, discarding route", -            RMAP_RECURSION_LIMIT); +      zlog_warn("route-map recursion limit (%d) reached, discarding route", +                RMAP_RECURSION_LIMIT);        recursion = 0;        return RMAP_DENYMATCH;      } diff --git a/lib/sockopt.c b/lib/sockopt.c index 91b0602b3a..2a9f907cb3 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -29,29 +29,6 @@  #include "sockopt.h"  #include "sockunion.h" -/* Replace the path of given defaultpath with newpath, but keep filename */ -void -set_socket_path (char *path, const char *defaultpath, char *newpath, int maxsize) -{ -  const char *sock_name; - -  sock_name = strrchr(defaultpath, '/'); -  if (sock_name) -    /* skip '/' */ -    sock_name++; -  else -    /* -     * VTYSH_PATH configured as relative path -     * during config? Should really never happen for -     * sensible config -     */ -    sock_name = defaultpath; - -  strlcpy (path, newpath, maxsize); -  strlcat (path, "/", maxsize); -  strlcat (path, sock_name, maxsize); -} -  void  setsockopt_so_recvbuf (int sock, int size)  { diff --git a/lib/sockopt.h b/lib/sockopt.h index d5724ce60f..1b7be1e49f 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -24,10 +24,6 @@  #include "sockunion.h" -/* Override (vty) socket paths, but keep the filename */ -extern void set_socket_path (char *path, const char *defaultpath, -                             char *newpath, int maxsize); -  extern void setsockopt_so_recvbuf (int sock, int size);  extern void setsockopt_so_sendbuf (const int sock, int size);  extern int getsockopt_so_sendbuf (const int sock); diff --git a/lib/sockunion.c b/lib/sockunion.c index 5b508d1bf8..9ba2ce82f6 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -148,8 +148,8 @@ sockunion_socket (const union sockunion *su)    if (sock < 0)      {        char buf[SU_ADDRSTRLEN]; -      zlog (NULL, LOG_WARNING, "Can't make socket for %s : %s", -            sockunion_log (su, buf, SU_ADDRSTRLEN), safe_strerror (errno)); +      zlog_warn("Can't make socket for %s : %s", +                sockunion_log(su, buf, SU_ADDRSTRLEN), safe_strerror(errno));        return -1;      } @@ -264,7 +264,7 @@ sockunion_stream_socket (union sockunion *su)    sock = socket (su->sa.sa_family, SOCK_STREAM, 0);    if (sock < 0) -    zlog (NULL, LOG_WARNING, "can't make socket sockunion_stream_socket"); +    zlog_warn("can't make socket sockunion_stream_socket");    return sock;  } @@ -308,8 +308,8 @@ sockunion_bind (int sock, union sockunion *su, unsigned short port,    if (ret < 0)      {        char buf[SU_ADDRSTRLEN]; -      zlog (NULL, LOG_WARNING, "can't bind socket for %s : %s", -            sockunion_log (su, buf, SU_ADDRSTRLEN), safe_strerror (errno)); +      zlog_warn("can't bind socket for %s : %s", +                sockunion_log(su, buf, SU_ADDRSTRLEN), safe_strerror(errno));      }    return ret; @@ -325,7 +325,7 @@ sockopt_reuseaddr (int sock)  		    (void *) &on, sizeof (on));    if (ret < 0)      { -      zlog (NULL, LOG_WARNING, "can't set sockopt SO_REUSEADDR to socket %d", sock); +      zlog_warn("can't set sockopt SO_REUSEADDR to socket %d", sock);        return -1;      }    return 0; @@ -342,7 +342,7 @@ sockopt_reuseport (int sock)  		    (void *) &on, sizeof (on));    if (ret < 0)      { -      zlog (NULL, LOG_WARNING, "can't set sockopt SO_REUSEPORT to socket %d", sock); +      zlog_warn("can't set sockopt SO_REUSEPORT to socket %d", sock);        return -1;      }    return 0; @@ -367,7 +367,7 @@ sockopt_ttl (int family, int sock, int ttl)  			(void *) &ttl, sizeof (int));        if (ret < 0)  	{ -	  zlog (NULL, LOG_WARNING, "can't set sockopt IP_TTL %d to socket %d", ttl, sock); +	  zlog_warn("can't set sockopt IP_TTL %d to socket %d", ttl, sock);  	  return -1;  	}        return 0; @@ -379,8 +379,8 @@ sockopt_ttl (int family, int sock, int ttl)  			(void *) &ttl, sizeof (int));        if (ret < 0)  	{ -	  zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_UNICAST_HOPS %d to socket %d", -		    ttl, sock); +	  zlog_warn("can't set sockopt IPV6_UNICAST_HOPS %d to socket %d", +                    ttl, sock);  	  return -1;  	}        return 0; @@ -425,9 +425,8 @@ sockopt_minttl (int family, int sock, int minttl)      {        int ret = setsockopt (sock, IPPROTO_IP, IP_MINTTL, &minttl, sizeof(minttl));        if (ret < 0) -	  zlog (NULL, LOG_WARNING, -		"can't set sockopt IP_MINTTL to %d on socket %d: %s", -		minttl, sock, safe_strerror (errno)); +	  zlog_warn("can't set sockopt IP_MINTTL to %d on socket %d: %s", +                    minttl, sock, safe_strerror(errno));        return ret;      }  #endif /* IP_MINTTL */ @@ -436,9 +435,8 @@ sockopt_minttl (int family, int sock, int minttl)      {        int ret = setsockopt (sock, IPPROTO_IPV6, IPV6_MINHOPCOUNT, &minttl, sizeof(minttl));        if (ret < 0) -	  zlog (NULL, LOG_WARNING, -		"can't set sockopt IPV6_MINHOPCOUNT to %d on socket %d: %s", -		minttl, sock, safe_strerror (errno)); +	  zlog_warn("can't set sockopt IPV6_MINHOPCOUNT to %d on socket %d: %s", +                    minttl, sock, safe_strerror(errno));        return ret;      }  #endif @@ -459,8 +457,8 @@ sockopt_v6only (int family, int sock)  			(void *) &on, sizeof (int));        if (ret < 0)  	{ -	  zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_V6ONLY " -		    "to socket %d", sock); +	  zlog_warn("can't set sockopt IPV6_V6ONLY " "to socket %d", +                    sock);  	  return -1;  	}        return 0; @@ -626,8 +624,7 @@ sockunion_getpeername (int fd)    ret = getpeername (fd, (struct sockaddr *)&name, &len);    if (ret < 0)      { -      zlog (NULL, LOG_WARNING, "Can't get remote address and port: %s", -	    safe_strerror (errno)); +      zlog_warn("Can't get remote address and port: %s", safe_strerror(errno));        return NULL;      } diff --git a/lib/thread.c b/lib/thread.c index c1558a83e1..6138e79718 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -719,7 +719,8 @@ funcname_thread_add_read_write (int dir, struct thread_master *m,  #else    if (FD_ISSET (fd, fdset))      { -      zlog (NULL, LOG_WARNING, "There is already %s fd [%d]", (dir == THREAD_READ) ? "read" : "write", fd); +      zlog_warn ("There is already %s fd [%d]", +                 (dir == THREAD_READ) ? "read" : "write", fd);        return NULL;      } diff --git a/lib/thread.h b/lib/thread.h index 0489246ea6..34adcc4d09 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -246,11 +246,6 @@ extern void thread_cmd_init (void);  extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,  					  unsigned long *cpu_time_elapsed); -/* Global variable containing a recent result from gettimeofday.  This can -   be used instead of calling gettimeofday if a recent value is sufficient. -   This is guaranteed to be refreshed before a thread is called. */ -extern struct timeval recent_time; -  /* only for use in logging functions! */  extern struct thread *thread_current; @@ -214,7 +214,7 @@ vty_time_print (struct vty *vty, int cr)    if (quagga_timestamp(0, buf, sizeof(buf)) == 0)      { -      zlog (NULL, LOG_INFO, "quagga_timestamp error"); +      zlog_info("quagga_timestamp error");        return;      }    if (cr) @@ -437,7 +437,7 @@ vty_command (struct vty *vty, char *buf)        snprintf(prompt_str, sizeof(prompt_str), cmd_prompt (vty->node), vty_str);        /* now log the command */ -      zlog(NULL, LOG_ERR, "%s%s", prompt_str, buf); +      zlog_err("%s%s", prompt_str, buf);      }    /* Split readline string up into the vector */    vline = cmd_make_strvec (buf); @@ -457,10 +457,7 @@ vty_command (struct vty *vty, char *buf)    ret = cmd_execute_command (vline, vty, NULL, 0);    /* Get the name of the protocol if any */ -  if (zlog_default) -      protocolname = zlog_proto_names[zlog_default->protocol]; -  else -      protocolname = zlog_proto_names[ZLOG_NONE]; +  protocolname = zlog_protoname();  #ifdef CONSUMED_TIME_CHECK      GETRUSAGE(&after); @@ -1856,8 +1853,8 @@ vty_accept (struct thread *thread)        if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) &&            (access_list_apply (acl, &p) == FILTER_DENY))          { -          zlog (NULL, LOG_INFO, "Vty connection refused from %s", -                sockunion2str (&su, buf, SU_ADDRSTRLEN)); +          zlog_info ("Vty connection refused from %s", +                     sockunion2str (&su, buf, SU_ADDRSTRLEN));            close (vty_sock);            /* continue accepting connections */ @@ -1873,8 +1870,8 @@ vty_accept (struct thread *thread)        if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) &&            (access_list_apply (acl, &p) == FILTER_DENY))          { -          zlog (NULL, LOG_INFO, "Vty connection refused from %s", -                sockunion2str (&su, buf, SU_ADDRSTRLEN)); +          zlog_info ("Vty connection refused from %s", +                     sockunion2str (&su, buf, SU_ADDRSTRLEN));            close (vty_sock);            /* continue accepting connections */ @@ -1888,11 +1885,11 @@ vty_accept (struct thread *thread)    ret = setsockopt (vty_sock, IPPROTO_TCP, TCP_NODELAY,                      (char *) &on, sizeof (on));    if (ret < 0) -    zlog (NULL, LOG_INFO, "can't set sockopt to vty_sock : %s", -          safe_strerror (errno)); +    zlog_info ("can't set sockopt to vty_sock : %s", +               safe_strerror (errno)); -  zlog (NULL, LOG_INFO, "Vty connection from %s", -        sockunion2str (&su, buf, SU_ADDRSTRLEN)); +  zlog_info ("Vty connection from %s", +             sockunion2str (&su, buf, SU_ADDRSTRLEN));    vty_create (vty_sock, &su); @@ -2354,7 +2351,7 @@ vty_read_file (FILE *confp)  }  static FILE * -vty_use_backup_config (char *fullpath) +vty_use_backup_config (const char *fullpath)  {    char *fullpath_sav, *fullpath_tmp;    FILE *ret = NULL; @@ -2413,12 +2410,12 @@ out_close_sav:  /* Read up configuration file from file_name. */  void -vty_read_config (char *config_file, +vty_read_config (const char *config_file,                   char *config_default_dir)  {    char cwd[MAXPATHLEN];    FILE *confp = NULL; -  char *fullpath; +  const char *fullpath;    char *tmp = NULL;    /* If -f flag specified. */ @@ -2518,7 +2515,7 @@ vty_read_config (char *config_file,  tmp_free_and_out:    if (tmp) -    XFREE (MTYPE_TMP, fullpath); +    XFREE (MTYPE_TMP, tmp);  }  /* Small utility function which output log to the VTY. */ @@ -324,7 +324,7 @@ extern void vty_reset (void);  extern struct vty *vty_new (void);  extern struct vty *vty_stdio (void (*atclose)(void));  extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); -extern void vty_read_config (char *, char *); +extern void vty_read_config (const char *, char *);  extern void vty_time_print (struct vty *, int);  extern void vty_serv_sock (const char *, unsigned short, const char *);  extern void vty_close (struct vty *);  | 
