address TLV. Unless hardening has been disabled, this overflow
cannot be used for arbitrary code execution.
* Change:
+ + Running lldpd with "-d" will keep the process in foreground but
+ logs will still go to syslog. To log to the console, add at
+ least one "-d".
+ Fix minimal kernel version to 2.6.39. Add a runtime warning when
this is not the case.
+ Remove old bridge code (the one using ioctl).
The options are as follows:
.Bl -tag -width Ds
.It Fl d
-Enable more debugging information.
+Enable more debugging information. This flag can be repeated.
.It Fl u Ar socket
Specify the Unix-domain socket used for communication with
.Xr lldpd 8 .
int
main(int argc, char *argv[])
{
- int ch, debug = 1, rc = EXIT_FAILURE;
+ int ch, debug = 0, use_syslog = 0, rc = EXIT_FAILURE;
const char *fmt = "plain";
lldpctl_conn_t *conn = NULL;
const char *options = is_lldpctl(argv[0])?"hdvf:u:":"hdsvf:c:u:";
optind = 1;
while ((ch = getopt(argc, argv, options)) != -1) {
switch (ch) {
- case 'd': debug++; break;
- case 's': debug--; break;
+ case 'd':
+ if (use_syslog)
+ use_syslog = 0;
+ else
+ debug++;
+ break;
+ case 's':
+ if (debug == 0)
+ use_syslog = 1;
+ else
+ debug--;
+ break;
case 'h':
usage();
break;
break;
case 'c':
if (!gotinputs) {
- log_init(debug, __progname);
- lldpctl_log_level(debug);
+ log_init(use_syslog, debug, __progname);
+ lldpctl_log_level(debug + 1);
gotinputs = 1;
}
input_append(optarg, &inputs, 1);
}
if (!gotinputs) {
- log_init(debug, __progname);
- lldpctl_log_level(debug);
+ log_init(use_syslog, debug, __progname);
+ lldpctl_log_level(debug + 1);
}
/* Disable SIGPIPE */
Do not daemonize.
If this option is specified,
.Nm
-will run in the foreground and log to
-.Em stderr .
-This option can be specified many times to increase verbosity. When
-specified three times, debug logs will be enabled. They can be
-filtered with
+will run in the foreground. When specified one more time,
+.Nm will log to
+.Em stderr
+instead of using syslog. Then, this option can be specified many times
+to increase verbosity. When specified four times, debug logs will be
+enabled. They can be filtered with
.Fl D
flag.
.It Fl D Ar debug
* @return PID of running lldpcli or -1 if error.
*/
static pid_t
-lldpd_configure(int debug, const char *path, const char *ctlname)
+lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname)
{
pid_t lldpcli = vfork();
int devnull;
- char sdebug[debug + 3];
- memset(sdebug, 'd', debug + 3);
- sdebug[debug + 2] = '\0';
- sdebug[0] = '-'; sdebug[1] = 's';
+ char sdebug[debug + 4];
+ if (use_syslog)
+ strlcpy(sdebug, "-s", 3);
+ else {
+ /* debug = 0 -> -sd */
+ /* debug = 1 -> -sdd */
+ /* debug = 2 -> -sddd */
+ memset(sdebug, 'd', sizeof(sdebug));
+ sdebug[debug + 3] = '\0';
+ sdebug[0] = '-'; sdebug[1] = 's';
+ }
log_debug("main", "invoke %s %s", path, sdebug);
switch (lldpcli) {
{
struct lldpd *cfg;
struct lldpd_chassis *lchassis;
- int ch, debug = 0;
+ int ch, debug = 0, use_syslog = 1, daemonize = 1;
#ifdef USE_SNMP
int snmp = 0;
const char *agentx = NULL; /* AgentX socket */
exit(0);
break;
case 'd':
- debug++;
+ if (daemonize)
+ daemonize = 0;
+ else if (use_syslog)
+ use_syslog = 0;
+ else
+ debug++;
break;
case 'D':
log_accept(optarg);
}
smart = filters[i].b;
- log_init(debug, __progname);
+ log_init(use_syslog, debug, __progname);
tzset(); /* Get timezone info before chroot */
log_debug("main", "lldpd " PACKAGE_VERSION " starting...");
/* Configuration with lldpcli */
if (lldpcli) {
log_debug("main", "invoking lldpcli for configuration");
- if (lldpd_configure(debug, lldpcli, ctlname) == -1)
+ if (lldpd_configure(use_syslog, debug, lldpcli, ctlname) == -1)
fatal("main", "unable to spawn lldpcli");
}
/* Daemonization, unless started by upstart, systemd or launchd or debug */
#ifndef HOST_OS_OSX
- if (!lldpd_started_by_upstart() && !lldpd_started_by_systemd() &&
- !debug) {
+ if (daemonize &&
+ !lldpd_started_by_upstart() && !lldpd_started_by_systemd()) {
int pid;
char *spid;
log_debug("main", "daemonize");
void
lldpctl_log_level(int level)
{
- log_level(level);
+ if (level >= 1) log_level(level-1);
}
#include <time.h>
/* By default, logging is done on stderr. */
-static int debug = 1;
+static int use_syslog = 0;
+/* Default debug level */
+static int debug = 0;
/* Logging can be modified by providing an appropriate log handler. */
static void (*logh)(int severity, const char *msg) = NULL;
static const char *tokens[MAX_DBG_TOKENS + 1] = {NULL};
void
-log_init(int n_debug, const char *progname)
+log_init(int n_syslog, int n_debug, const char *progname)
{
+ use_syslog = n_syslog;
debug = n_debug;
- if (!debug)
+ if (use_syslog)
openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
tzset();
void
log_level(int n_debug)
{
- if (debug > 0 && n_debug >= 1)
+ if (n_debug >= 0)
debug = n_debug;
}
}
/* Otherwise, fallback to output on stderr. */
}
- if (debug || logh) {
+ if (!use_syslog || logh) {
char *nfmt;
/* best effort in out of mem situations */
if (asprintf(&nfmt, "%s %s%s%s]%s %s\n",
{
va_list ap;
- if (!debug || debug > 1 || logh) {
+ if (use_syslog || debug > 0 || logh) {
va_start(ap, emsg);
vlog(LOG_INFO, token, emsg, ap);
va_end(ap);
{
va_list ap;
- if ((debug > 2 && log_debug_accept_token(token)) || logh) {
+ if ((debug > 1 && log_debug_accept_token(token)) || logh) {
va_start(ap, emsg);
vlog(LOG_DEBUG, token, emsg, ap);
va_end(ap);
#define _LOG_H
/* log.c */
-void log_init(int, const char *);
+void log_init(int, int, const char *);
void log_warn(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
void log_warnx(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
void log_info(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));