lost. Also, it's output with LOG_PERROR is ugly and LOG_PERROR isn't portable.
logger is a new function to solve the above which is identical to syslog(3)
but takes a dhcpcd_ctx for context so it functions in the RTEMS OS.
When writing to stdout/stderr or a given logfile, logger will convert %m
into the error string based on errno, just like syslog(3) does.
If your libc supports %m via printf, then define HAVE_PRINTF_M to remove
a fair chunk of code. There is no way of working out if your libc supports
this, especially in cross-compiled environment.
If the logfile is rotated, send dhcpcd a SIGUSR2 and the logfile will be
re-opened.
This does add about an exta 4K on 64-bit platforms so for size constraints
this can be compiled out by defining USE_LOGFILE to 0.
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 5
{
char buf[HWADDR_LEN * 3];
- syslog(LOG_ERR, "%s: hardware address %s claims %s",
+ logger(astate->iface->ctx, LOG_ERR, "%s: hardware address %s claims %s",
astate->iface->name,
hwaddr_ntoa(amsg->sha, astate->iface->hwlen, buf, sizeof(buf)),
inet_ntoa(astate->failed));
bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
arp_buffer, sizeof(arp_buffer), &flags);
if (bytes == -1) {
- syslog(LOG_ERR, "%s: arp if_readrawpacket: %m",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: arp if_readrawpacket: %m", ifp->name);
dhcp_close(ifp);
return;
}
if (state->arp_fd == -1) {
state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
if (state->arp_fd == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
+ __func__, ifp->name);
return;
}
eloop_event_add(ifp->ctx->eloop, state->arp_fd,
struct interface *ifp = astate->iface;
if (++astate->claims < ANNOUNCE_NUM)
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: ARP announcing %s (%d of %d), "
"next in %d.0 seconds",
ifp->name, inet_ntoa(astate->addr),
astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
else
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: ARP announcing %s (%d of %d)",
ifp->name, inet_ntoa(astate->addr),
astate->claims, ANNOUNCE_NUM);
if (arp_send(ifp, ARPOP_REQUEST,
astate->addr.s_addr, astate->addr.s_addr) == -1)
- syslog(LOG_ERR, "send_arp: %m");
+ logger(ifp->ctx, LOG_ERR, "send_arp: %m");
eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
astate);
tv.tv_nsec = 0;
eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
}
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: ARP probing %s (%d of %d), next in %0.1f seconds",
ifp->name, inet_ntoa(astate->addr),
astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
timespec_to_double(&tv));
if (arp_send(ifp, ARPOP_REQUEST, 0, astate->addr.s_addr) == -1)
- syslog(LOG_ERR, "send_arp: %m");
+ logger(ifp->ctx, LOG_ERR, "send_arp: %m");
}
void
arp_open(astate->iface);
astate->probes = 0;
- syslog(LOG_DEBUG, "%s: probing for %s",
+ logger(astate->iface->ctx, LOG_DEBUG, "%s: probing for %s",
astate->iface->name, inet_ntoa(astate->addr));
arp_probe1(astate);
}
-
struct arp_state *
arp_new(struct interface *ifp) {
struct arp_state *astate;
astate = calloc(1, sizeof(*astate));
if (astate == NULL) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
return NULL;
}
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#ifdef BSD
# include <paths.h>
#endif
+#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
+#include "dhcpcd.h"
+#include "if-options.h"
#ifndef _PATH_DEVNULL
# define _PATH_DEVNULL "/dev/null"
#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC)
return clock_gettime(CLOCK_MONOTONIC, ts);
- return 0;
#elif defined(__APPLE__)
/* We can use mach kernel functions here.
* This is crap though - why can't they implement clock_gettime?*/
#if 0
/* Something above failed, so fall back to gettimeofday */
if (!posix_clock_set) {
- syslog(LOG_WARNING, NO_MONOTONIC);
+ logger(NULL, LOG_WARNING, NO_MONOTONIC);
posix_clock_set = 1;
}
#endif
return -1;
}
+#if USE_LOGFILE
+void
+logger_open(struct dhcpcd_ctx *ctx)
+{
+
+ if (ctx->logfile) {
+ int f = O_CREAT | O_APPEND;
+
+#ifdef O_CLOEXEC
+ f |= O_CLOEXEC;
+#endif
+ ctx->log_fd = open(ctx->logfile, O_WRONLY | f, 0644);
+ if (ctx->log_fd == -1)
+ warn("open: %s", ctx->logfile);
+#ifndef O_CLOEXEC
+ else {
+ if (fcntl(ctx->log_fd, F_GETFD, &f) == -1 ||
+ fcntl(ctx->log_fd, F_SETFD, f | FD_CLOEXEC) == -1)
+ warn("fcntl: %s", ctx->logfile);
+ }
+#endif
+ } else
+ openlog(PACKAGE, LOG_PID, LOG_DAEMON);
+}
+
+void
+logger_close(struct dhcpcd_ctx *ctx)
+{
+
+ if (ctx->log_fd != -1) {
+ close(ctx->log_fd);
+ ctx->log_fd = -1;
+ }
+ closelog();
+}
+
+void
+logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...)
+{
+ va_list va;
+ int serrno;
+#ifndef HAVE_PRINTF_M
+ char fmt_cpy[1024];
+#endif
+
+ serrno = errno;
+ va_start(va, fmt);
+
+ if (pri >= LOG_DEBUG && ctx && !(ctx->options & DHCPCD_DEBUG))
+ return;
+
+#ifndef HAVE_PRINTF_M
+ /* Print strerrno(errno) in place of %m */
+ if (ctx == NULL || !(ctx->options & DHCPCD_QUIET) || ctx->log_fd != -1)
+ {
+ const char *p;
+ char *fp = fmt_cpy, *serr = NULL;
+ size_t fmt_left = sizeof(fmt_cpy) - 1, fmt_wrote;
+
+ for (p = fmt; *p != '\0'; p++) {
+ if (p[0] == '%' && p[1] == '%') {
+ if (fmt_left < 2)
+ break;
+ *fp++ = '%';
+ *fp++ = '%';
+ fmt_left -= 2;
+ p++;
+ } else if (p[0] == '%' && p[1] == 'm') {
+ if (serr == NULL)
+ serr = strerror(serrno);
+ fmt_wrote = strlcpy(fp, serr, fmt_left);
+ if (fmt_wrote > fmt_left)
+ break;
+ fp += fmt_wrote;
+ fmt_left -= fmt_wrote;
+ p++;
+ } else {
+ *fp++ = *p;
+ --fmt_left;
+ }
+ if (fmt_left == 0)
+ break;
+ }
+ *fp++ = '\0';
+ }
+
+ fmt = fmt_cpy;
+#endif
+
+ if (ctx == NULL || !(ctx->options & DHCPCD_QUIET)) {
+ va_list vac;
+
+ va_copy(vac, va);
+ vfprintf(pri <= LOG_ERR ? stderr : stdout, fmt, vac);
+ fputc('\n', pri <= LOG_ERR ? stderr : stdout);
+ va_end(vac);
+ }
+
+#ifdef HAVE_PRINTF_M
+ errno = serrno;
+#endif
+ if (ctx && ctx->log_fd != -1) {
+ struct timeval tv;
+ char buf[32];
+
+ /* Write the time, syslog style. month day time - */
+ if (gettimeofday(&tv, NULL) != -1) {
+ time_t now;
+ struct tm tmnow;
+
+ tzset();
+ now = tv.tv_sec;
+ localtime_r(&now, &tmnow);
+ strftime(buf, sizeof(buf), "%b %d %T ", &tmnow);
+ dprintf(ctx->log_fd, "%s", buf);
+ }
+
+ vdprintf(ctx->log_fd, fmt, va);
+ dprintf(ctx->log_fd, "\n");
+ } else
+ vsyslog(pri, fmt, va);
+ va_end(va);
+}
+#endif
+
ssize_t
-setvar(char ***e, const char *prefix, const char *var, const char *value)
+setvar(struct dhcpcd_ctx *ctx,
+ char ***e, const char *prefix, const char *var, const char *value)
{
size_t len = strlen(var) + strlen(value) + 3;
len += strlen(prefix) + 1;
**e = malloc(len);
if (**e == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
if (prefix)
}
ssize_t
-setvard(char ***e, const char *prefix, const char *var, size_t value)
+setvard(struct dhcpcd_ctx *ctx,
+ char ***e, const char *prefix, const char *var, size_t value)
{
char buffer[32];
snprintf(buffer, sizeof(buffer), "%zu", value);
- return setvar(e, prefix, var, buffer);
+ return setvar(ctx, e, prefix, var, buffer);
}
#include <sys/param.h>
#include <sys/time.h>
#include <stdio.h>
+#include <syslog.h>
#include "config.h"
#include "defs.h"
+#include "dhcpcd.h"
#ifndef HOSTNAME_MAX_LEN
#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#define STRINGIFY(a) #a
#define TOSTRING(a) STRINGIFY(a)
+#define UNUSED(a) (void)(a)
#define USEC_PER_SEC 1000000L
#define USEC_PER_NSEC 1000L
# ifndef __packed
# define __packed __attribute__((__packed__))
# endif
+# ifndef __printflike
+# define __printflike(a, b) __attribute__((format(printf, a, b)))
+# endif
# ifndef __unused
# define __unused __attribute__((__unused__))
# endif
# ifndef __packed
# define __packed
# endif
+# ifndef __printflike
+# define __printflike
+# endif
# ifndef __unused
# define __unused
# endif
const char *get_hostname(char *, size_t, int);
extern int clock_monotonic;
int get_monotonic(struct timespec *);
-ssize_t setvar(char ***, const char *, const char *, const char *);
-ssize_t setvard(char ***, const char *, const char *, size_t);
+
+/* We could shave a few k off the binary size by just using the
+ * syslog(3) interface.
+ * However, this results in a ugly output on the command line
+ * and relies on syslogd(8) starting before dhcpcd which is not
+ * always the case. */
+#ifndef USE_LOGFILE
+# define USE_LOGFILE 1
+#endif
+#if USE_LOGFILE
+void logger_open(struct dhcpcd_ctx *);
+#define logger_mask(ctx, lvl) setlogmask((lvl))
+__printflike(3, 4) void logger(struct dhcpcd_ctx *, int, const char *, ...);
+void logger_close(struct dhcpcd_ctx *);
+#else
+#define logger_open(ctx) openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON)
+#define logger_mask(ctx, lvl) setlogmask((lvl))
+#define logger(ctx, pri, fmt, ...) \
+ do { \
+ UNUSED((ctx)); \
+ syslog((pri), (fmt), ##__VA_ARGS__); \
+ } while (0 /*CONSTCOND */)
+#define logger_close(ctx) closelog()
+#endif
+
+ssize_t setvar(struct dhcpcd_ctx *,
+ char ***, const char *, const char *, const char *);
+ssize_t setvard(struct dhcpcd_ctx *,
+ char ***, const char *, const char *, size_t);
time_t uptime(void);
char *hwaddr_ntoa(const unsigned char *, size_t, char *, size_t);
#include "dprintf.h"
int
-dprintf(int fd, const char *fmt, ...)
+vdprintf(int fd, const char *fmt, va_list va)
{
int e;
FILE *fp;
return -1;
}
- va_start(va, fmt);
e = vfprintf(fp, fmt, va);
- va_end(va);
fclose(fp);
return e;
}
+
+int
+dprintf(int fd, const char *fmt, ...)
+{
+ int e;
+
+ va_start(va, fmt);
+ e = vdprintf(fd, fmt, va);
+ va_end(va);
+ return e;
+}
+
#ifndef DPRINTF_H
#define DPRINTF_H
+int dprintf(int, const char *, va_list);
int dprintf(int, const char *, ...);
#endif
;;
esac
-if [ -z "$LOG_PERROR" ]; then
- printf "Testing for LOG_PERROR ... "
- cat <<EOF >_log_perror.c
-#include <syslog.h>
-int main(void) {
- openlog("test", LOG_PERROR, LOG_DAEMON);
- return 0;
-}
-EOF
- if $XCC _log_perror.c -o _log_perror 2>&3; then
- LOG_PERROR=yes
- else
- LOG_PERROR=no
- fi
- echo "$LOG_PERROR"
- rm -f _log_perror.c _log_perror
-fi
-if [ "$LOG_PERROR" = no ]; then
- echo "COMPAT_SRCS+= compat/psyslog.c" >>$CONFIG_MK
- echo "#include \"compat/psyslog.h\"" >>$CONFIG_H
- echo "#define syslog psyslog" >>$CONFIG_H
-fi
-
if [ -z "$BE64ENC" ]; then
printf "Testing for be64enc ... "
cat <<EOF >_be64enc.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
}
*ap = NULL;
if (dhcpcd_handleargs(fd->ctx, fd, argc, argvp) == -1) {
- syslog(LOG_ERR, "%s: dhcpcd_handleargs: %m", __func__);
+ logger(fd->ctx, LOG_ERR,
+ "%s: dhcpcd_handleargs: %m", __func__);
if (errno != EINTR && errno != EAGAIN) {
control_delete(fd);
return;
iov[1].iov_base = data->data;
iov[1].iov_len = data->data_len;
if (writev(fd->fd, iov, 2) == -1) {
- syslog(LOG_ERR, "%s: writev fd %d: %m", __func__, fd->fd);
+ logger(fd->ctx, LOG_ERR,
+ "%s: writev fd %d: %m", __func__, fd->fd);
if (errno != EINTR && errno != EAGAIN)
control_delete(fd);
return;
#define CONFIG_H
#define PACKAGE "dhcpcd"
-#define VERSION "6.7.99.4"
+#define VERSION "6.7.99.5"
#ifndef CONFIG
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#define _INDEV
#include "common.h"
if (ctx->dev) {
if (stop)
- syslog(LOG_DEBUG, "dev: unloaded %s", ctx->dev->name);
+ logger(ctx, LOG_DEBUG,
+ "dev: unloaded %s", ctx->dev->name);
eloop_event_delete(ctx->eloop, ctx->dev_fd, 0);
ctx->dev->stop();
free(ctx->dev);
snprintf(file, sizeof(file), DEVDIR "/%s", name);
h = dlopen(file, RTLD_LAZY);
if (h == NULL) {
- syslog(LOG_ERR, "dlopen: %s", dlerror());
+ logger(ctx, LOG_ERR, "dlopen: %s", dlerror());
return -1;
}
fptr = (void (*)(struct dev *, const struct dev_dhcpcd *))
dlsym(h, "dev_init");
if (fptr == NULL) {
- syslog(LOG_ERR, "dlsym: %s", dlerror());
+ logger(ctx, LOG_ERR, "dlsym: %s", dlerror());
dlclose(h);
return -1;
}
dlclose(h);
return -1;
}
- syslog(LOG_INFO, "dev: loaded %s", ctx->dev->name);
+ logger(ctx, LOG_INFO, "dev: loaded %s", ctx->dev->name);
ctx->dev_handle = h;
return r;
}
int r;
if (ctx->dev) {
- syslog(LOG_ERR, "dev: already started %s", ctx->dev->name);
+ logger(ctx, LOG_ERR, "dev: already started %s", ctx->dev->name);
return -1;
}
dp = opendir(DEVDIR);
if (dp == NULL) {
- syslog(LOG_DEBUG, "dev: %s: %m", DEVDIR);
+ logger(ctx, LOG_DEBUG, "dev: %s: %m", DEVDIR);
return 0;
}
{
if (ctx->dev_fd != -1) {
- syslog(LOG_ERR, "%s: already started on fd %d", __func__,
+ logger(ctx, LOG_ERR, "%s: already started on fd %d", __func__,
ctx->dev_fd);
return ctx->dev_fd;
}
if (eloop_event_add(ctx->eloop,
ctx->dev_fd, dev_handle_data, ctx, NULL, NULL) == -1)
{
- syslog(LOG_ERR, "%s: eloop_event_add: %m", __func__);
+ logger(ctx, LOG_ERR,
+ "%s: eloop_event_add: %m", __func__);
dev_stop1(ctx, 1);
return -1;
}
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
}
static size_t
-dhcp_envoption1(char **env, const char *prefix,
+dhcp_envoption1(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
const struct dhcp_opt *opt, int vname, const uint8_t *od, size_t ol,
const char *ifname)
{
return e;
v = val = *env = malloc(e);
if (v == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return 0;
}
if (vname)
/* If no embedded or encapsulated options, it's easy */
if (opt->embopts_len == 0 && opt->encopts_len == 0) {
- if (dhcp_envoption1(env == NULL ? NULL : &env[0],
+ if (dhcp_envoption1(ctx, env == NULL ? NULL : &env[0],
prefix, opt, 1, od, ol, ifname))
return 1;
return 0;
if (opt->type & INDEX) {
if (opt->index > 999) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return 0;
}
}
(opt->type & INDEX ? 3 : 0);
pfx = malloc(e);
if (pfx == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return 0;
}
if (opt->type & INDEX)
* name is different.
* This avoids new_fqdn_fqdn which would be silly. */
ov = strcmp(opt->var, eopt->var);
- if (dhcp_envoption1(env == NULL ? NULL : &env[n],
+ if (dhcp_envoption1(ctx, env == NULL ? NULL : &env[n],
pfx, eopt, ov, od, e, ifname))
n++;
od += e;
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 2
}
static struct rt_head *
-decode_rfc3442_rt(const uint8_t *data, size_t dl)
+decode_rfc3442_rt(struct dhcpcd_ctx *ctx, const uint8_t *data, size_t dl)
{
const uint8_t *p = data;
const uint8_t *e;
rt = calloc(1, sizeof(*rt));
if (rt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(routes);
return NULL;
}
csr = "MS ";
}
if (p) {
- routes = decode_rfc3442_rt(p, len);
+ routes = decode_rfc3442_rt(ifp->ctx, p, len);
if (routes) {
const struct dhcp_state *state;
if (!(ifo->options & DHCPCD_CSR_WARNED) &&
!(state->added & STATE_FAKE))
{
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: using %sClassless Static Routes",
ifp->name, csr);
ifo->options |= DHCPCD_CSR_WARNED;
/* OK, get our static routes first. */
routes = malloc(sizeof(*routes));
if (routes == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
TAILQ_INIT(routes);
while (p < e) {
route = calloc(1, sizeof(*route));
if (route == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(routes);
return NULL;
}
while (p < e) {
route = calloc(1, sizeof(*route));
if (route == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(routes);
return NULL;
}
ssize_t
make_message(struct dhcp_message **message,
- const struct interface *iface,
+ const struct interface *ifp,
uint8_t type)
{
struct dhcp_message *dhcp;
uint16_t sz;
size_t len, i, auth_len;
const struct dhcp_opt *opt;
- struct if_options *ifo = iface->options;
- const struct dhcp_state *state = D_CSTATE(iface);
+ struct if_options *ifo = ifp->options;
+ const struct dhcp_state *state = D_CSTATE(ifp);
const struct dhcp_lease *lease = &state->lease;
time_t up = uptime() - state->start_uptime;
char hbuf[HOSTNAME_MAX_LEN + 1];
}
dhcp->op = DHCP_BOOTREQUEST;
- dhcp->hwtype = (uint8_t)iface->family;
- switch (iface->family) {
+ dhcp->hwtype = (uint8_t)ifp->family;
+ switch (ifp->family) {
case ARPHRD_ETHER:
case ARPHRD_IEEE802:
- dhcp->hwlen = (uint8_t)iface->hwlen;
- memcpy(&dhcp->chaddr, &iface->hwaddr, iface->hwlen);
+ dhcp->hwlen = (uint8_t)ifp->hwlen;
+ memcpy(&dhcp->chaddr, &ifp->hwaddr, ifp->hwlen);
break;
}
}
if (type == DHCP_DISCOVER &&
- !(iface->ctx->options & DHCPCD_TEST) &&
+ !(ifp->ctx->options & DHCPCD_TEST) &&
has_option_mask(ifo->requestmask, DHO_RAPIDCOMMIT))
{
/* RFC 4039 Section 3 */
*p++ = DHO_MAXMESSAGESIZE;
*p++ = 2;
- mtu = if_getmtu(iface->name);
+ mtu = if_getmtu(ifp->name);
if (mtu < MTU_MIN) {
- if (if_setmtu(iface->name, MTU_MIN) == 0)
+ if (if_setmtu(ifp->name, MTU_MIN) == 0)
sz = MTU_MIN;
} else if (mtu > MTU_MAX) {
/* Even though our MTU could be greater than
if (len > sizeof(*dhcp))
goto toobig;
if (vivco->len + 2 + *lp > 255) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: VIVCO option too big",
- iface->name);
+ ifp->name);
free(dhcp);
return -1;
}
*p++ = DHO_PARAMETERREQUESTLIST;
n_params = p;
*p++ = 0;
- for (i = 0, opt = iface->ctx->dhcp_opts;
- i < iface->ctx->dhcp_opts_len;
+ for (i = 0, opt = ifp->ctx->dhcp_opts;
+ i < ifp->ctx->dhcp_opts_len;
i++, opt++)
{
if (!(opt->type & REQUEST ||
- has_option_mask(ifo->requestmask, opt->option)))
+ has_option_mask(ifo->requestmask, opt->option)))
continue;
if (opt->type & NOREQ)
continue;
if (lp < p)
continue;
if (!(opt->type & REQUEST ||
- has_option_mask(ifo->requestmask, opt->option)))
+ has_option_mask(ifo->requestmask, opt->option)))
continue;
if (opt->type & NOREQ)
continue;
state->auth.token,
NULL, 0, 4, type, NULL, 0);
if ((ssize_t)auth_len == -1) {
- syslog(LOG_ERR, "%s: dhcp_auth_encode: %m",
- iface->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp_auth_encode: %m", ifp->name);
auth_len = 0;
} else if (auth_len != 0) {
len = (size_t)((p + auth_len) - m);
return (ssize_t)len;
toobig:
- syslog(LOG_ERR, "%s: DHCP messge too big", iface->name);
+ logger(ifp->ctx, LOG_ERR, "%s: DHCP messge too big", ifp->name);
free(dhcp);
return -1;
}
return 0;
}
- syslog(LOG_DEBUG, "%s: writing lease `%s'",
+ logger(ifp->ctx, LOG_DEBUG, "%s: writing lease `%s'",
ifp->name, state->leasefile);
fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
fd = open(state->leasefile, O_RDONLY);
if (fd == -1) {
if (errno != ENOENT)
- syslog(LOG_ERR, "%s: open `%s': %m",
+ logger(ifp->ctx, LOG_ERR, "%s: open `%s': %m",
ifp->name, state->leasefile);
return NULL;
}
- syslog(LOG_DEBUG, "%s: reading lease `%s'",
+ logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
ifp->name, state->leasefile);
dhcp = calloc(1, sizeof(*dhcp));
if (dhcp == NULL) {
(uint8_t *)dhcp, sizeof(*dhcp), 4, type,
auth, auth_len) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: dhcp_auth_validate: %m", ifp->name);
free(dhcp);
return NULL;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_DEBUG, "%s: accepted reconfigure key",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: accepted reconfigure key", ifp->name);
}
return dhcp;
/* Set some useful variables that we derive from the DHCP
* message but are not necessarily in the options */
addr.s_addr = dhcp->yiaddr ? dhcp->yiaddr : dhcp->ciaddr;
- setvar(&ep, prefix, "ip_address", inet_ntoa(addr));
+ setvar(ifp->ctx, &ep, prefix, "ip_address", inet_ntoa(addr));
if (get_option_addr(ifp->ctx, &net,
dhcp, DHO_SUBNETMASK) == -1) {
net.s_addr = ipv4_getnetmask(addr.s_addr);
- setvar(&ep, prefix, "subnet_mask", inet_ntoa(net));
+ setvar(ifp->ctx, &ep, prefix,
+ "subnet_mask", inet_ntoa(net));
}
snprintf(cidr, sizeof(cidr), "%d", inet_ntocidr(net));
- setvar(&ep, prefix, "subnet_cidr", cidr);
+ setvar(ifp->ctx, &ep, prefix, "subnet_cidr", cidr);
if (get_option_addr(ifp->ctx, &brd,
dhcp, DHO_BROADCAST) == -1) {
brd.s_addr = addr.s_addr | ~net.s_addr;
- setvar(&ep, prefix, "broadcast_address",
- inet_ntoa(brd));
+ setvar(ifp->ctx, &ep, prefix,
+ "broadcast_address", inet_ntoa(brd));
}
addr.s_addr = dhcp->yiaddr & net.s_addr;
- setvar(&ep, prefix, "network_number", inet_ntoa(addr));
+ setvar(ifp->ctx, &ep, prefix,
+ "network_number", inet_ntoa(addr));
}
if (*dhcp->bootfile && !(overl & 1)) {
print_string(safe, sizeof(safe), STRING,
dhcp->bootfile, sizeof(dhcp->bootfile));
- setvar(&ep, prefix, "filename", safe);
+ setvar(ifp->ctx, &ep, prefix, "filename", safe);
}
if (*dhcp->servername && !(overl & 2)) {
print_string(safe, sizeof(safe), STRING | DOMAIN,
dhcp->servername, sizeof(dhcp->servername));
- setvar(&ep, prefix, "server_name", safe);
+ setvar(ifp->ctx, &ep, prefix, "server_name", safe);
}
/* Zero our indexes */
}
static void
-send_message(struct interface *iface, uint8_t type,
+send_message(struct interface *ifp, uint8_t type,
void (*callback)(void *))
{
- struct dhcp_state *state = D_STATE(iface);
- struct if_options *ifo = iface->options;
+ struct dhcp_state *state = D_STATE(ifp);
+ struct if_options *ifo = ifp->options;
struct dhcp_message *dhcp;
struct udp_dhcp_packet *udp;
size_t len;
int s;
if (!callback)
- syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
- iface->name, get_dhcp_op(type), state->xid);
+ logger(ifp->ctx, LOG_DEBUG, "%s: sending %s with xid 0x%x",
+ ifp->name, get_dhcp_op(type), state->xid);
else {
if (state->interval == 0)
state->interval = 4;
tv.tv_nsec = (suseconds_t)arc4random_uniform(
(DHCP_RAND_MAX - DHCP_RAND_MIN) * NSEC_PER_SEC);
timespecnorm(&tv);
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: sending %s (xid 0x%x), next in %0.1f seconds",
- iface->name, get_dhcp_op(type), state->xid,
+ ifp->name, get_dhcp_op(type), state->xid,
timespec_to_double(&tv));
}
- if (dhcp_open(iface) == -1)
+ if (dhcp_open(ifp) == -1)
return;
if (state->added && !(state->added & STATE_FAKE) &&
state->addr.s_addr != INADDR_ANY &&
state->new != NULL &&
(state->new->cookie == htonl(MAGIC_COOKIE) ||
- iface->options->options & DHCPCD_INFORM))
+ ifp->options->options & DHCPCD_INFORM))
{
- s = dhcp_openudp(iface);
+ s = dhcp_openudp(ifp);
if (s == -1 && errno != EADDRINUSE)
- syslog(LOG_ERR, "%s: dhcp_openudp: %m", iface->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp_openudp: %m", ifp->name);
} else
s = -1;
* Also, we should not unicast from a BOOTP lease. */
if (s == -1 ||
(!(ifo->options & DHCPCD_INFORM) &&
- is_bootp(iface, state->new)))
+ is_bootp(ifp, state->new)))
{
a = state->addr.s_addr;
state->addr.s_addr = INADDR_ANY;
}
- r = make_message(&dhcp, iface, type);
+ r = make_message(&dhcp, ifp, type);
if (r == -1)
goto fail;
len = (size_t)r;
r = sendto(s, (uint8_t *)dhcp, len, 0,
(struct sockaddr *)&sin, sizeof(sin));
if (r == -1)
- syslog(LOG_ERR, "%s: dhcp_sendpacket: %m", iface->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp_sendpacket: %m", ifp->name);
} else {
size_t ulen;
r = 0;
udp = dhcp_makeudppacket(&ulen, (uint8_t *)dhcp, len, from, to);
if (udp == NULL) {
- syslog(LOG_ERR, "dhcp_makeudppacket: %m");
+ logger(ifp->ctx, LOG_ERR, "dhcp_makeudppacket: %m");
} else {
- r = if_sendrawpacket(iface, ETHERTYPE_IP,
+ r = if_sendrawpacket(ifp, ETHERTYPE_IP,
(uint8_t *)udp, ulen);
free(udp);
}
* As such we remove it from consideration without actually
* stopping the interface. */
if (r == -1) {
- syslog(LOG_ERR, "%s: if_sendrawpacket: %m",
- iface->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: if_sendrawpacket: %m", ifp->name);
switch(errno) {
case ENETDOWN:
case ENETRESET:
case ENETUNREACH:
break;
default:
- if (!(iface->ctx->options & DHCPCD_TEST))
- dhcp_drop(iface, "FAIL");
- dhcp_free(iface);
- eloop_timeout_delete(iface->ctx->eloop,
- NULL, iface);
+ if (!(ifp->ctx->options & DHCPCD_TEST))
+ dhcp_drop(ifp, "FAIL");
+ dhcp_free(ifp);
+ eloop_timeout_delete(ifp->ctx->eloop,
+ NULL, ifp);
callback = NULL;
}
}
/* Even if we fail to send a packet we should continue as we are
* as our failure timeouts will change out codepath when needed. */
if (callback)
- eloop_timeout_add_tv(iface->ctx->eloop, &tv, callback, iface);
+ eloop_timeout_add_tv(ifp->ctx->eloop, &tv, callback, ifp);
}
static void
eloop_timeout_add_sec(ifp->ctx->eloop,
ifo->reboot, ipv4ll_start, ifp);
if (ifo->options & DHCPCD_REQUEST)
- syslog(LOG_INFO, "%s: soliciting a DHCP lease (requesting %s)",
+ logger(ifp->ctx, LOG_INFO,
+ "%s: soliciting a DHCP lease (requesting %s)",
ifp->name, inet_ntoa(ifo->req_addr));
else
- syslog(LOG_INFO, "%s: soliciting a DHCP lease", ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: soliciting a DHCP lease", ifp->name);
send_discover(ifp);
}
struct interface *ifp = arg;
struct dhcp_state *state = D_STATE(ifp);
- syslog(LOG_ERR, "%s: DHCP lease expired", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: DHCP lease expired", ifp->name);
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
dhcp_drop(ifp, "EXPIRE");
unlink(state->leasefile);
struct dhcp_state *state = D_STATE(ifp);
struct dhcp_lease *lease = &state->lease;
- syslog(LOG_DEBUG, "%s: renewing lease of %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: renewing lease of %s",
ifp->name, inet_ntoa(lease->addr));
- syslog(LOG_DEBUG, "%s: rebind in %"PRIu32" seconds,"
+ logger(ifp->ctx, LOG_DEBUG, "%s: rebind in %"PRIu32" seconds,"
" expire in %"PRIu32" seconds",
ifp->name, lease->rebindtime - lease->renewaltime,
lease->leasetime - lease->renewaltime);
struct dhcp_state *state = D_STATE(ifp);
struct dhcp_lease *lease = &state->lease;
- syslog(LOG_WARNING, "%s: failed to renew DHCP, rebinding",
- ifp->name);
- syslog(LOG_DEBUG, "%s: expire in %"PRIu32" seconds",
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: failed to renew DHCP, rebinding", ifp->name);
+ logger(ifp->ctx, LOG_DEBUG, "%s: expire in %"PRIu32" seconds",
ifp->name, lease->leasetime - lease->rebindtime);
state->state = DHS_REBIND;
eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
state->offer = NULL;
get_lease(ifp->ctx, lease, state->new);
if (ifo->options & DHCPCD_STATIC) {
- syslog(LOG_INFO, "%s: using static address %s/%d",
+ logger(ifp->ctx, LOG_INFO, "%s: using static address %s/%d",
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->net));
lease->leasetime = ~0U;
state->reason = "STATIC";
} else if (state->new->cookie != htonl(MAGIC_COOKIE)) {
- syslog(LOG_INFO, "%s: using IPv4LL address %s",
+ logger(ifp->ctx, LOG_INFO, "%s: using IPv4LL address %s",
ifp->name, inet_ntoa(lease->addr));
lease->leasetime = ~0U;
state->reason = "IPV4LL";
lease->addr.s_addr = ifo->req_addr.s_addr;
else
lease->addr.s_addr = state->addr.s_addr;
- syslog(LOG_INFO, "%s: received approval for %s",
+ logger(ifp->ctx, LOG_INFO, "%s: received approval for %s",
ifp->name, inet_ntoa(lease->addr));
lease->leasetime = ~0U;
state->reason = "INFORM";
lease->renewaltime =
lease->rebindtime =
lease->leasetime;
- syslog(LOG_INFO, "%s: leased %s for infinity",
+ logger(ifp->ctx, LOG_INFO, "%s: leased %s for infinity",
ifp->name, inet_ntoa(lease->addr));
} else {
if (lease->leasetime < DHCP_MIN_LEASE) {
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: minimum lease is %d seconds",
ifp->name, DHCP_MIN_LEASE);
lease->leasetime = DHCP_MIN_LEASE;
else if (lease->rebindtime >= lease->leasetime) {
lease->rebindtime =
(uint32_t)(lease->leasetime * T2);
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: rebind time greater than lease "
"time, forcing to %"PRIu32" seconds",
ifp->name, lease->rebindtime);
else if (lease->renewaltime > lease->rebindtime) {
lease->renewaltime =
(uint32_t)(lease->leasetime * T1);
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: renewal time greater than rebind "
"time, forcing to %"PRIu32" seconds",
ifp->name, lease->renewaltime);
}
- syslog(lease->addr.s_addr == state->addr.s_addr &&
+ logger(ifp->ctx,
+ lease->addr.s_addr == state->addr.s_addr &&
!(state->added & STATE_FAKE) ?
LOG_DEBUG : LOG_INFO,
"%s: leased %s for %"PRIu32" seconds", ifp->name,
(time_t)lease->rebindtime, dhcp_rebind, ifp);
eloop_timeout_add_sec(ifp->ctx->eloop,
(time_t)lease->leasetime, dhcp_expire, ifp);
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
" seconds",
ifp->name, lease->renewaltime, lease->rebindtime);
if (!state->lease.frominfo &&
!(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
if (write_lease(ifp, state->new) == -1)
- syslog(LOG_ERR, "%s: write_lease: %m", __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: write_lease: %m", __func__);
applyaddr:
ipv4_applyaddr(ifp);
state = D_STATE(ifp);
ifo = ifp->options;
if (ifo->req_addr.s_addr == INADDR_ANY) {
- syslog(LOG_INFO,
+ logger(ifp->ctx, LOG_INFO,
"%s: waiting for 3rd party to "
"configure IP address",
ifp->name);
state = D_STATE(ifp);
ap = ipv4_iffindaddr(ifp, NULL, NULL);
if (ap == NULL) {
- syslog(LOG_INFO,
- "%s: waiting for 3rd party to "
- "configure IP address",
- ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: waiting for 3rd party to "
+ "configure IP address",
+ ifp->name);
state->reason = "3RDPARTY";
script_runreason(ifp, state->reason);
return;
state->interval = 0;
if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_DOWN) {
- syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: waiting for carrier", ifp->name);
return;
}
if (ifo->options & DHCPCD_STATIC) {
return;
}
if (ifo->options & DHCPCD_INFORM) {
- syslog(LOG_INFO, "%s: informing address of %s",
+ logger(ifp->ctx, LOG_INFO, "%s: informing address of %s",
ifp->name, inet_ntoa(state->lease.addr));
dhcp_inform(ifp);
return;
if (state->offer->cookie == 0)
return;
- syslog(LOG_INFO, "%s: rebinding lease of %s",
+ logger(ifp->ctx, LOG_INFO, "%s: rebinding lease of %s",
ifp->name, inet_ntoa(state->lease.addr));
state->xid = dhcp_xid(ifp);
state->lease.server.s_addr = 0;
state->new != NULL &&
state->new->cookie == htonl(MAGIC_COOKIE))
{
- syslog(LOG_INFO, "%s: releasing lease of %s",
+ logger(ifp->ctx, LOG_INFO, "%s: releasing lease of %s",
ifp->name, inet_ntoa(state->lease.addr));
state->xid = dhcp_xid(ifp);
send_message(ifp, DHCP_RELEASE, NULL);
static void
log_dhcp1(int lvl, const char *msg,
- const struct interface *iface, const struct dhcp_message *dhcp,
+ const struct interface *ifp, const struct dhcp_message *dhcp,
const struct in_addr *from, int ad)
{
const char *tfrom;
int r;
if (strcmp(msg, "NAK:") == 0) {
- a = get_option_string(iface->ctx, dhcp, DHO_MESSAGE);
+ a = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE);
if (a) {
char *tmp;
size_t al, tmpl;
tmpl = (al * 4) + 1;
tmp = malloc(tmpl);
if (tmp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
free(a);
return;
}
addr.s_addr = dhcp->yiaddr;
a = strdup(inet_ntoa(addr));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
} else
a = NULL;
tfrom = "from";
- r = get_option_addr(iface->ctx, &addr, dhcp, DHO_SERVERID);
+ r = get_option_addr(ifp->ctx, &addr, dhcp, DHO_SERVERID);
if (dhcp->servername[0] && r == 0) {
print_string(sname, sizeof(sname), STRING,
dhcp->servername, strlen((const char *)dhcp->servername));
if (a == NULL)
- syslog(lvl, "%s: %s %s %s `%s'", iface->name, msg,
- tfrom, inet_ntoa(addr), sname);
+ logger(ifp->ctx, lvl, "%s: %s %s %s `%s'",
+ ifp->name, msg, tfrom, inet_ntoa(addr), sname);
else
- syslog(lvl, "%s: %s %s %s %s `%s'", iface->name, msg, a,
- tfrom, inet_ntoa(addr), sname);
+ logger(ifp->ctx, lvl, "%s: %s %s %s %s `%s'",
+ ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
} else {
if (r != 0) {
tfrom = "via";
addr = *from;
}
if (a == NULL)
- syslog(lvl, "%s: %s %s %s",
- iface->name, msg, tfrom, inet_ntoa(addr));
+ logger(ifp->ctx, lvl, "%s: %s %s %s",
+ ifp->name, msg, tfrom, inet_ntoa(addr));
else
- syslog(lvl, "%s: %s %s %s %s",
- iface->name, msg, a, tfrom, inet_ntoa(addr));
+ logger(ifp->ctx, lvl, "%s: %s %s %s %s",
+ ifp->name, msg, a, tfrom, inet_ntoa(addr));
}
free(a);
}
static void
log_dhcp(int lvl, const char *msg,
- const struct interface *iface, const struct dhcp_message *dhcp,
+ const struct interface *ifp, const struct dhcp_message *dhcp,
const struct in_addr *from)
{
- log_dhcp1(lvl, msg, iface, dhcp, from, 1);
+ log_dhcp1(lvl, msg, ifp, dhcp, from, 1);
}
static int
}
static void
-dhcp_handledhcp(struct interface *iface, struct dhcp_message **dhcpp,
+dhcp_handledhcp(struct interface *ifp, struct dhcp_message **dhcpp,
const struct in_addr *from)
{
- struct dhcp_state *state = D_STATE(iface);
- struct if_options *ifo = iface->options;
+ struct dhcp_state *state = D_STATE(ifp);
+ struct if_options *ifo = ifp->options;
struct dhcp_message *dhcp = *dhcpp;
struct dhcp_lease *lease = &state->lease;
uint8_t type, tmp;
char *msg;
/* We may have found a BOOTP server */
- if (get_option_uint8(iface->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
+ if (get_option_uint8(ifp->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
type = 0;
/* Authenticate the message */
- auth = get_option(iface->ctx, dhcp, DHO_AUTHENTICATION, &auth_len);
+ auth = get_option(ifp->ctx, dhcp, DHO_AUTHENTICATION, &auth_len);
if (auth) {
if (dhcp_auth_validate(&state->auth, &ifo->auth,
(uint8_t *)*dhcpp, sizeof(**dhcpp), 4, type,
auth, auth_len) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
- iface->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: dhcp_auth_validate: %m", ifp->name);
log_dhcp1(LOG_ERR, "authentication failed",
- iface, dhcp, from, 0);
+ ifp, dhcp, from, 0);
return;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
- iface->name, state->auth.token->secretid);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: validated using 0x%08" PRIu32,
+ ifp->name, state->auth.token->secretid);
else
- syslog(LOG_DEBUG, "%s: accepted reconfigure key",
- iface->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
- log_dhcp1(LOG_ERR, "no authentication", iface, dhcp, from, 0);
+ log_dhcp1(LOG_ERR, "no authentication", ifp, dhcp, from, 0);
return;
} else if (ifo->auth.options & DHCPCD_AUTH_SEND)
log_dhcp1(LOG_WARNING, "no authentication",
- iface, dhcp, from, 0);
+ ifp, dhcp, from, 0);
/* RFC 3203 */
if (type == DHCP_FORCERENEW) {
from->s_addr == INADDR_BROADCAST)
{
log_dhcp(LOG_ERR, "discarding Force Renew",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
if (auth == NULL) {
log_dhcp(LOG_ERR, "unauthenticated Force Renew",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
if (state->state != DHS_BOUND && state->state != DHS_INFORM) {
log_dhcp(LOG_DEBUG, "not bound, ignoring Force Renew",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
- log_dhcp(LOG_ERR, "Force Renew from", iface, dhcp, from);
+ log_dhcp(LOG_ERR, "Force Renew from", ifp, dhcp, from);
/* The rebind and expire timings are still the same, we just
* enter the renew state early */
if (state->state == DHS_BOUND) {
- eloop_timeout_delete(iface->ctx->eloop,
- dhcp_renew, iface);
- dhcp_renew(iface);
+ eloop_timeout_delete(ifp->ctx->eloop,
+ dhcp_renew, ifp);
+ dhcp_renew(ifp);
} else {
- eloop_timeout_delete(iface->ctx->eloop,
- send_inform, iface);
- dhcp_inform(iface);
+ eloop_timeout_delete(ifp->ctx->eloop,
+ send_inform, ifp);
+ dhcp_inform(ifp);
}
return;
}
/* Ensure it's the right transaction */
if (state->xid != ntohl(dhcp->xid)) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: wrong xid 0x%x (expecting 0x%x) from %s",
- iface->name, ntohl(dhcp->xid), state->xid,
+ ifp->name, ntohl(dhcp->xid), state->xid,
inet_ntoa(*from));
return;
}
/* Ensure that no reject options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->rejectmask, i) &&
- get_option_uint8(iface->ctx, &tmp, dhcp, (uint8_t)i) == 0)
+ get_option_uint8(ifp->ctx, &tmp, dhcp, (uint8_t)i) == 0)
{
- log_dhcp(LOG_WARNING, "reject DHCP", iface, dhcp, from);
+ log_dhcp(LOG_WARNING, "reject DHCP", ifp, dhcp, from);
return;
}
}
if (type == DHCP_NAK) {
/* For NAK, only check if we require the ServerID */
if (has_option_mask(ifo->requiremask, DHO_SERVERID) &&
- get_option_addr(iface->ctx, &addr, dhcp, DHO_SERVERID) == -1)
+ get_option_addr(ifp->ctx, &addr, dhcp, DHO_SERVERID) == -1)
{
- log_dhcp(LOG_WARNING, "reject NAK", iface, dhcp, from);
+ log_dhcp(LOG_WARNING, "reject NAK", ifp, dhcp, from);
return;
}
/* We should restart on a NAK */
- log_dhcp(LOG_WARNING, "NAK:", iface, dhcp, from);
- if ((msg = get_option_string(iface->ctx, dhcp, DHO_MESSAGE))) {
- syslog(LOG_WARNING, "%s: message: %s",
- iface->name, msg);
+ log_dhcp(LOG_WARNING, "NAK:", ifp, dhcp, from);
+ if ((msg = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE))) {
+ logger(ifp->ctx, LOG_WARNING, "%s: message: %s",
+ ifp->name, msg);
free(msg);
}
if (state->state == DHS_INFORM) /* INFORM should not be NAKed */
return;
- if (!(iface->ctx->options & DHCPCD_TEST)) {
- dhcp_drop(iface, "NAK");
+ if (!(ifp->ctx->options & DHCPCD_TEST)) {
+ dhcp_drop(ifp, "NAK");
unlink(state->leasefile);
}
/* If we constantly get NAKS then we should slowly back off */
- eloop_timeout_add_sec(iface->ctx->eloop,
- state->nakoff, dhcp_discover, iface);
+ eloop_timeout_add_sec(ifp->ctx->eloop,
+ state->nakoff, dhcp_discover, ifp);
if (state->nakoff == 0)
state->nakoff = 1;
else {
/* Ensure that all required options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->requiremask, i) &&
- get_option_uint8(iface->ctx, &tmp, dhcp, (uint8_t)i) != 0)
+ get_option_uint8(ifp->ctx, &tmp, dhcp, (uint8_t)i) != 0)
{
/* If we are bootp, then ignore the need for serverid.
* To ignore bootp, require dhcp_message_type.
* always true. */
if (type == 0 && i == DHO_SERVERID)
continue;
- log_dhcp(LOG_WARNING, "reject DHCP", iface, dhcp, from);
+ log_dhcp(LOG_WARNING, "reject DHCP", ifp, dhcp, from);
return;
}
}
/* DHCP Auto-Configure, RFC 2563 */
if (type == DHCP_OFFER && dhcp->yiaddr == 0) {
- log_dhcp(LOG_WARNING, "no address given", iface, dhcp, from);
- if ((msg = get_option_string(iface->ctx, dhcp, DHO_MESSAGE))) {
- syslog(LOG_WARNING, "%s: message: %s",
- iface->name, msg);
+ log_dhcp(LOG_WARNING, "no address given", ifp, dhcp, from);
+ if ((msg = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE))) {
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: message: %s", ifp->name, msg);
free(msg);
}
if ((state->state == DHS_DISCOVER ||
state->state == DHS_IPV4LL_BOUND) &&
- get_option_uint8(iface->ctx, &tmp, dhcp,
+ get_option_uint8(ifp->ctx, &tmp, dhcp,
DHO_AUTOCONFIGURE) == 0)
{
switch (tmp) {
case 0:
log_dhcp(LOG_WARNING, "IPv4LL disabled from",
- iface, dhcp, from);
- dhcp_drop(iface, "EXPIRE");
- arp_close(iface);
- eloop_timeout_delete(iface->ctx->eloop,
- NULL, iface);
- eloop_timeout_add_sec(iface->ctx->eloop,
+ ifp, dhcp, from);
+ dhcp_drop(ifp, "EXPIRE");
+ arp_close(ifp);
+ eloop_timeout_delete(ifp->ctx->eloop,
+ NULL, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop,
DHCP_MAX, dhcp_discover,
- iface);
+ ifp);
break;
case 1:
log_dhcp(LOG_WARNING, "IPv4LL enabled from",
- iface, dhcp, from);
- eloop_timeout_delete(iface->ctx->eloop,
- NULL, iface);
+ ifp, dhcp, from);
+ eloop_timeout_delete(ifp->ctx->eloop,
+ NULL, ifp);
if (IN_LINKLOCAL(htonl(state->addr.s_addr)))
- eloop_timeout_add_sec(iface->ctx->eloop,
- DHCP_MAX, dhcp_discover, iface);
+ eloop_timeout_add_sec(ifp->ctx->eloop,
+ DHCP_MAX, dhcp_discover, ifp);
else
- ipv4ll_start(iface);
+ ipv4ll_start(ifp);
break;
default:
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: unknown auto configuration option %d",
- iface->name, tmp);
+ ifp->name, tmp);
break;
}
}
(dhcp->yiaddr == INADDR_ANY || dhcp->yiaddr == INADDR_BROADCAST))
{
log_dhcp(LOG_WARNING, "reject invalid address",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
lease->addr.s_addr = dhcp->yiaddr;
lease->cookie = dhcp->cookie;
if (type == 0 ||
- get_option_addr(iface->ctx,
+ get_option_addr(ifp->ctx,
&lease->server, dhcp, DHO_SERVERID) != 0)
lease->server.s_addr = INADDR_ANY;
- log_dhcp(LOG_INFO, "offered", iface, dhcp, from);
+ log_dhcp(LOG_INFO, "offered", ifp, dhcp, from);
free(state->offer);
state->offer = dhcp;
*dhcpp = NULL;
- if (iface->ctx->options & DHCPCD_TEST) {
+ if (ifp->ctx->options & DHCPCD_TEST) {
free(state->old);
state->old = state->new;
state->new = state->offer;
state->offer = NULL;
state->reason = "TEST";
- script_runreason(iface, state->reason);
- eloop_exit(iface->ctx->eloop, EXIT_SUCCESS);
+ script_runreason(ifp, state->reason);
+ eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
return;
}
- eloop_timeout_delete(iface->ctx->eloop, send_discover, iface);
+ eloop_timeout_delete(ifp->ctx->eloop, send_discover, ifp);
/* We don't request BOOTP addresses */
if (type) {
/* We used to ARP check here, but that seems to be in
* It also seems that some MS DHCP servers actually
* ignore DECLINE if no REQUEST, ie we decline a
* DISCOVER. */
- dhcp_request(iface);
+ dhcp_request(ifp);
return;
}
}
if (type) {
if (type == DHCP_OFFER) {
log_dhcp(LOG_WARNING, "ignoring offer of",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
/* We should only be dealing with acks */
if (type != DHCP_ACK) {
log_dhcp(LOG_ERR, "not ACK or OFFER",
- iface, dhcp, from);
+ ifp, dhcp, from);
return;
}
if (!(ifo->options & DHCPCD_INFORM))
- log_dhcp(LOG_DEBUG, "acknowledged", iface, dhcp, from);
+ log_dhcp(LOG_DEBUG, "acknowledged", ifp, dhcp, from);
else
ifo->options &= ~DHCPCD_STATIC;
}
}
lease->frominfo = 0;
- eloop_timeout_delete(iface->ctx->eloop, NULL, iface);
+ eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
if (ifo->options & DHCPCD_ARP &&
state->addr.s_addr != state->offer->yiaddr)
/* If the interface already has the address configured
* then we can't ARP for duplicate detection. */
addr.s_addr = state->offer->yiaddr;
- if (!ipv4_iffindaddr(iface, &addr, NULL)) {
+ if (!ipv4_iffindaddr(ifp, &addr, NULL)) {
struct arp_state *astate;
- astate = arp_new(iface);
+ astate = arp_new(ifp);
if (astate) {
astate->addr = addr;
astate->probed_cb = dhcp_arp_probed;
}
}
- dhcp_bind(iface, NULL);
+ dhcp_bind(ifp, NULL);
}
static size_t
bytes = (size_t)if_readrawpacket(ifp, ETHERTYPE_IP,
ifp->ctx->packet, udp_dhcp_len, &flags);
if ((ssize_t)bytes == -1) {
- syslog(LOG_ERR, "%s: dhcp if_readrawpacket: %m",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp if_readrawpacket: %m", ifp->name);
dhcp_close(ifp);
arp_close(ifp);
break;
if (valid_udp_packet(ifp->ctx->packet, bytes,
&from, flags & RAW_PARTIALCSUM) == -1)
{
- syslog(LOG_ERR, "%s: invalid UDP packet from %s",
+ logger(ifp->ctx, LOG_ERR,
+ "%s: invalid UDP packet from %s",
ifp->name, inet_ntoa(from));
continue;
}
i = whitelisted_ip(ifp->options, from.s_addr);
if (i == 0) {
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: non whitelisted DHCP packet from %s",
ifp->name, inet_ntoa(from));
continue;
} else if (i != 1 &&
blacklisted_ip(ifp->options, from.s_addr) == 1)
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: blacklisted DHCP packet from %s",
ifp->name, inet_ntoa(from));
continue;
if (ifp->flags & IFF_POINTOPOINT &&
state->dst.s_addr != from.s_addr)
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: server %s is not destination",
ifp->name, inet_ntoa(from));
}
bytes = get_udp_data(&pp, ifp->ctx->packet);
if (bytes > sizeof(*dhcp)) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: packet greater than DHCP size from %s",
ifp->name, inet_ntoa(from));
continue;
if (dhcp == NULL) {
dhcp = calloc(1, sizeof(*dhcp));
if (dhcp == NULL) {
- syslog(LOG_ERR, "%s: calloc: %m", __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: calloc: %m", __func__);
break;
}
}
memcpy(dhcp, pp, bytes);
if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
- syslog(LOG_DEBUG, "%s: bogus cookie from %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: bogus cookie from %s",
ifp->name, inet_ntoa(from));
continue;
}
{
char buf[sizeof(dhcp->chaddr) * 3];
- syslog(LOG_DEBUG, "%s: xid 0x%x is for hwaddr %s",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: xid 0x%x is for hwaddr %s",
ifp->name, ntohl(dhcp->xid),
hwaddr_ntoa(dhcp->chaddr, sizeof(dhcp->chaddr),
buf, sizeof(buf)));
/* Just read what's in the UDP fd and discard it as we always read
* from the raw fd */
if (read(ctx->udp_fd, buffer, sizeof(buffer)) == -1) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
eloop_event_delete(ctx->eloop, ctx->udp_fd, 0);
close(ctx->udp_fd);
ctx->udp_fd = -1;
if (ifp->ctx->packet == NULL) {
ifp->ctx->packet = malloc(udp_dhcp_len);
if (ifp->ctx->packet == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
}
state->raw_fd = if_openrawsocket(ifp, ETHERTYPE_IP);
if (state->raw_fd == -1) {
if (errno == ENOENT) {
- syslog(LOG_ERR, "%s not found", if_pfname);
+ logger(ifp->ctx, LOG_ERR,
+ "%s not found", if_pfname);
/* May as well disable IPv4 entirely at
* this point as we really need it. */
ifp->options->options &= ~DHCPCD_IPV4;
} else
- syslog(LOG_ERR, "%s: %s: %m",
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
__func__, ifp->name);
return -1;
}
state->new = read_lease(ifp);
if (state->new == NULL) {
if (errno == ENOENT)
- syslog(LOG_ERR, "%s: no lease to dump", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: no lease to dump", ifp->name);
return -1;
}
state->reason = "DUMP";
return script_runreason(ifp, state->reason);
eexit:
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
return 0;
if (ifo->options & DHCPCD_CLIENTID)
- syslog(LOG_DEBUG, "%s: using ClientID %s", ifp->name,
+ logger(ifp->ctx, LOG_DEBUG, "%s: using ClientID %s", ifp->name,
hwaddr_ntoa(state->clientid + 1, state->clientid[0],
buf, sizeof(buf)));
else if (ifp->hwlen)
- syslog(LOG_DEBUG, "%s: using hwaddr %s", ifp->name,
+ logger(ifp->ctx, LOG_DEBUG, "%s: using hwaddr %s", ifp->name,
hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
return 0;
eexit:
- syslog(LOG_ERR, "%s: Error making ClientID: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: error making ClientID: %m", __func__);
return -1;
}
/* Don't log an error if some other process
* is handling this. */
if (errno != EADDRINUSE)
- syslog(LOG_ERR, "dhcp_openudp: %m");
+ logger(ifp->ctx, LOG_ERR, "dhcp_openudp: %m");
} else
eloop_event_add(ifp->ctx->eloop,
ifp->ctx->udp_fd, dhcp_handleudp,
}
if (dhcp_init(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp_init: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: dhcp_init: %m", ifp->name);
return;
}
return;
}
if (ifp->hwlen == 0 && ifo->clientid[0] == '\0') {
- syslog(LOG_WARNING, "%s: needs a clientid to configure",
- ifp->name);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: needs a clientid to configure", ifp->name);
dhcp_drop(ifp, "FAIL");
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
return;
state->added |= STATE_ADDED | STATE_FAKE;
ipv4_buildroutes(ifp->ctx);
} else
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
}
if (state->offer->cookie == 0) {
if (state->offer->yiaddr == state->addr.s_addr) {
if (now == -1 ||
(time_t)state->lease.leasetime < now - st.st_mtime)
{
- syslog(LOG_DEBUG,
- "%s: discarding expired lease",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: discarding expired lease", ifp->name);
free(state->offer);
state->offer = NULL;
state->lease.addr.s_addr = 0;
tv.tv_nsec = (suseconds_t)arc4random_uniform(
(DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC);
timespecnorm(&tv);
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: delaying IPv4 for %0.1f seconds",
ifp->name, timespec_to_double(&tv));
(state->new->yiaddr == INADDR_ANY &&
state->new->ciaddr == addr->s_addr)))
{
- syslog(LOG_INFO, "%s: removing IP address %s/%d",
+ logger(ifp->ctx, LOG_INFO,
+ "%s: removing IP address %s/%d",
ifp->name, inet_ntoa(state->lease.addr),
inet_ntocidr(state->lease.net));
dhcp_drop(ifp, "EXPIRE");
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 4
}
if (len > UINT16_MAX) {
- syslog(LOG_ERR, "%s: DHCPv6 Vendor Class too big", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: DHCPv6 Vendor Class too big", ifp->name);
return 0;
}
ifp->if_data[IF_DATA_DHCP6] = calloc(1, sizeof(*state));
state = D6_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
{
sa = inet_ntop(AF_INET6, &prefix->prefix,
sabuf, sizeof(sabuf));
- syslog(LOG_ERR, "%s: invalid prefix %s/%d + %d/%d: %m",
- ifp->name, sa, prefix->prefix_len,
- sla->sla, sla->prefix_len);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: invalid prefix %s/%d + %d/%d: %m",
+ ifp->name, sa, prefix->prefix_len,
+ sla->sla, sla->prefix_len);
return -1;
}
{
sa = inet_ntop(AF_INET6, &prefix->prefix_exclude,
sabuf, sizeof(sabuf));
- syslog(LOG_ERR, "%s: cannot delegate excluded prefix %s/%d",
+ logger(ifp->ctx, LOG_ERR,
+ "%s: cannot delegate excluded prefix %s/%d",
ifp->name, sa, prefix->prefix_exclude_len);
return -1;
}
auth_len = (size_t)dhcp_auth_encode(&ifo->auth,
state->auth.token, NULL, 0, 6, type, NULL, 0);
if ((ssize_t)auth_len == -1) {
- syslog(LOG_ERR, "%s: dhcp_auth_encode: %m",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp_auth_encode: %m", ifp->name);
auth_len = 0;
} else if (auth_len != 0)
len += sizeof(*o) + auth_len;
}
if (!callback)
- syslog(LOG_DEBUG, "%s: %s %s with xid 0x%02x%02x%02x",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: %s %s with xid 0x%02x%02x%02x",
ifp->name,
broad_uni,
dhcp6_get_op(state->send->type),
}
logsend:
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: %s %s (xid 0x%02x%02x%02x),"
" next in %0.1f seconds",
ifp->name,
if (ifp->options->auth.options & DHCPCD_AUTH_SEND &&
dhcp6_update_auth(ifp, state->send, state->send_len) == -1)
{
- syslog(LOG_ERR, "%s: dhcp6_updateauth: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_updateauth: %m", ifp->name);
if (errno != ESRCH)
return -1;
}
memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
if (sendmsg(ctx->dhcp_fd, &ctx->sndhdr, 0) == -1) {
- syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: %s: sendmsg: %m", ifp->name, __func__);
ifp->options->options &= ~DHCPCD_IPV6;
dhcp6_drop(ifp, "EXPIRE6");
return -1;
eloop_timeout_add_tv(ifp->ctx->eloop,
&state->RT, state->MRCcallback, ifp);
else
- syslog(LOG_WARNING, "%s: sent %d times with no reply",
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: sent %d times with no reply",
ifp->name, state->RTC);
}
return 0;
state->MRC = 0;
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
else
dhcp6_sendrenew(ifp);
}
if (ap->flags & IPV6_AF_DUPLICATED)
/* XXX FIXME
* We should decline the address */
- syslog(LOG_WARNING, "%s: DAD detected %s",
+ logger(ap->iface->ctx, LOG_WARNING, "%s: DAD detected %s",
ap->iface->name, ap->saddr);
if (!wascompleted) {
}
}
if (!wascompleted) {
- syslog(LOG_DEBUG, "%s: DHCPv6 DAD completed",
- ifp->name);
+ logger(ap->iface->ctx, LOG_DEBUG,
+ "%s: DHCPv6 DAD completed", ifp->name);
script_runreason(ifp,
ap->delegating_iface ?
"DELEGATED6" : state->reason);
continue;
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
a->flags = IPV6_AF_REQUEST;
ifp = arg;
dhcp6_delete_delegates(ifp);
- syslog(LOG_INFO, "%s: soliciting a DHCPv6 lease", ifp->name);
+ logger(ifp->ctx, LOG_INFO, "%s: soliciting a DHCPv6 lease", ifp->name);
state = D6_STATE(ifp);
state->state = DH6S_DISCOVER;
state->start_uptime = uptime();
dhcp6_addrequestedaddrs(ifp);
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
else
dhcp6_senddiscover(ifp);
}
struct interface *ifp;
ifp = arg;
- syslog(LOG_ERR, "%s: failed to confirm prior address", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: failed to confirm prior address", ifp->name);
/* Section 18.1.2 says that we SHOULD use the last known
* IP address(s) and lifetimes if we didn't get a reply.
* I disagree with this. */
struct interface *ifp;
ifp = arg;
- syslog(LOG_ERR, "%s: failed to request address", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: failed to request address", ifp->name);
/* Section 18.1.1 says that client local policy dictates
* what happens if a REQUEST fails.
* Of the possible scenarios listed, moving back to the
struct interface *ifp;
ifp = arg;
- syslog(LOG_ERR, "%s: failed to rebind prior delegation", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: failed to rebind prior delegation", ifp->name);
dhcp6_delete_delegates(ifp);
/* Section 18.1.2 says that we SHOULD use the last known
* IP address(s) and lifetimes if we didn't get a reply.
eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrenew, ifp);
state = D6_STATE(ifp);
if (state->state == DH6S_RENEW)
- syslog(LOG_WARNING, "%s: failed to renew DHCPv6, rebinding",
- ifp->name);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: failed to renew DHCPv6, rebinding", ifp->name);
else
- syslog(LOG_INFO, "%s: rebinding prior DHCPv6 lease",
- ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: rebinding prior DHCPv6 lease", ifp->name);
state->state = DH6S_REBIND;
state->RTC = 0;
state->MRC = 0;
}
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
else
dhcp6_sendrebind(ifp);
state->MRCcallback = dhcp6_failrequest;
if (dhcp6_makemessage(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
return;
}
state->MRT = CNF_MAX_RT;
state->MRC = 0;
- syslog(LOG_INFO, "%s: confirming prior DHCPv6 lease", ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: confirming prior DHCPv6 lease", ifp->name);
if (dhcp6_makemessage(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
return;
}
dhcp6_sendconfirm(ifp);
ifp = arg;
state = D6_STATE(ifp);
if (state->new == NULL || ifp->options->options & DHCPCD_DEBUG)
- syslog(LOG_INFO, "%s: requesting DHCPv6 information",
- ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: requesting DHCPv6 information", ifp->name);
state->state = DH6S_INFORM;
state->start_uptime = uptime();
state->RTC = 0;
state->MRC = 0;
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
else
dhcp6_sendinform(ifp);
}
ifp = arg;
eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrebind, ifp);
- syslog(LOG_ERR, "%s: DHCPv6 lease expired", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: DHCPv6 lease expired", ifp->name);
dhcp6_freedrop_addrs(ifp, 1, NULL);
dhcp6_delete_delegates(ifp);
script_runreason(ifp, "EXPIRE6");
if (ipv6nd_hasradhcp(ifp) || dhcp6_hasprefixdelegation(ifp))
dhcp6_startdiscover(ifp);
else
- syslog(LOG_WARNING,
- "%s: no advertising IPv6 router wants DHCP",
- ifp->name);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: no advertising IPv6 router wants DHCP", ifp->name);
}
static void
state->MRCcallback = NULL;
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_makemessage: %m", ifp->name);
else
/* XXX: We should loop a few times
* Luckily RFC3315 section 18.1.6 says this is optional */
else
o = dhcp6_getmoption(D6_OPTION_STATUS_CODE, m, len);
if (o == NULL) {
- //syslog(LOG_DEBUG, "%s: no status", ifp->name);
+ //logger(ifp->ctx, LOG_DEBUG, "%s: no status", ifp->name);
return 0;
}
len = ntohs(o->len);
if (len < sizeof(code)) {
- syslog(LOG_ERR, "%s: status truncated", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: status truncated", ifp->name);
return -1;
}
status = malloc(len + 1);
if (status == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
if (p)
memcpy(status, p, len);
status[len] = '\0';
- syslog(LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status);
+ logger(ifp->ctx, LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status);
free(status);
return -1;
}
d += sizeof(*o) + u32;
if (u32 < 24) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA Address option truncated",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: IA Address option truncated", ifp->name);
continue;
}
iap = (const struct dhcp6_ia_addr *)D6_COPTION_DATA(o);
if (a == NULL) {
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
break;
}
a->iface = ifp;
d += sizeof(*o) + ol;
if (ol < sizeof(*pdp)) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA Prefix option truncated",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: IA Prefix option truncated", ifp->name);
continue;
}
if (a == NULL) {
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
break;
}
a->iface = ifp;
continue;
ol = ntohs(ex->len);
if (ol < 2) {
- syslog(LOG_ERR, "%s: truncated PD Exclude",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: truncated PD Exclude", ifp->name);
continue;
}
op = D6_COPTION_DATA(ex);
if (((a->prefix_exclude_len - a->prefix_len - 1) / NBBY) + 1
!= ol)
{
- syslog(LOG_ERR, "%s: PD Exclude length mismatch",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: PD Exclude length mismatch", ifp->name);
a->prefix_exclude_len = 0;
continue;
}
ol = ntohs(o->len);
if (sizeof(*o) + ol > l) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: option overflow", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: option overflow", ifp->name);
break;
}
l -= sizeof(*o) + ol;
}
if (ol < u32) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA option truncated", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: IA option truncated", ifp->name);
continue;
}
if (j == ifo->ia_len &&
!(ifo->ia_len == 0 && ifp->ctx->options & DHCPCD_DUMPLEASE))
{
- syslog(LOG_DEBUG, "%s: ignoring unrequested IAID %s",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: ignoring unrequested IAID %s",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf, sizeof(buf)));
continue;
}
if ( j < ifo->ia_len && ifo->ia[j].ia_type != code) {
- syslog(LOG_ERR, "%s: IAID %s: option type mismatch",
+ logger(ifp->ctx, LOG_ERR,
+ "%s: IAID %s: option type mismatch",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf, sizeof(buf)));
continue;
if (!(ifo->options & DHCPCD_NOPFXDLG) &&
dhcp6_findpd(ifp, iaid, p, ol, acquired) == 0)
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: %s: DHCPv6 REPLY missing Prefix",
ifp->name, sfrom);
continue;
} else if (!(ifo->options & DHCPCD_PFXDLGONLY)) {
if (dhcp6_findna(ifp, code, iaid, p, ol, acquired) == 0)
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: %s: DHCPv6 REPLY missing IA Address",
ifp->name, sfrom);
continue;
if (code != D6_OPTION_IA_TA) {
if (renew > rebind && rebind > 0) {
if (sfrom)
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: T1 (%d) > T2 (%d) from %s",
ifp->name, renew, rebind, sfrom);
renew = 0;
struct timespec aq;
if (len <= sizeof(*m)) {
- syslog(LOG_ERR, "%s: DHCPv6 lease truncated", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: DHCPv6 lease truncated", ifp->name);
return -1;
}
}
nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
if (nia == 0) {
- syslog(LOG_ERR, "%s: no useable IA found in lease",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: no useable IA found in lease", ifp->name);
return -1;
}
return nia;
ssize_t bytes;
state = D6_CSTATE(ifp);
- syslog(LOG_DEBUG, "%s: writing lease `%s'",
- ifp->name, state->leasefile);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: writing lease `%s'", ifp->name, state->leasefile);
fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1) {
- syslog(LOG_ERR, "%s: dhcp6_writelease: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: dhcp6_writelease: %m", ifp->name);
return -1;
}
bytes = write(fd, state->new, state->new_len);
if (stat(state->leasefile, &st) == -1) {
if (errno == ENOENT)
return 0;
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
return -1;
}
- syslog(LOG_DEBUG, "%s: reading lease `%s'",
+ logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
ifp->name, state->leasefile);
if (st.st_size > UINT32_MAX) {
- syslog(LOG_ERR, "%s: file too big", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: file too big", ifp->name);
return -1;
}
state->new = malloc((size_t)st.st_size);
if (state->new == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
state->new_len = (size_t)st.st_size;
fd = open(state->leasefile, O_RDONLY);
if (fd == -1) {
- syslog(LOG_ERR, "%s: %s: %s: %m", ifp->name, __func__,
- state->leasefile);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %s: %m",
+ ifp->name, __func__, state->leasefile);
return -1;
}
bytes = read(fd, state->new, state->new_len);
close(fd);
if (bytes != (ssize_t)state->new_len) {
- syslog(LOG_ERR, "%s: read: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: read: %m", __func__);
goto ex;
}
if ((now = time(NULL)) == -1) {
- syslog(LOG_ERR, "%s: time: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: time: %m", __func__);
goto ex;
}
state->expire != ND6_INFINITE_LIFETIME)
{
if ((time_t)state->expire < now - st.st_mtime) {
- syslog(LOG_DEBUG,"%s: discarding expired lease",
+ logger(ifp->ctx,
+ LOG_DEBUG,"%s: discarding expired lease",
ifp->name);
goto ex;
}
(uint8_t *)state->new, state->new_len, 6, state->new->type,
D6_COPTION_DATA(o), ntohs(o->len)) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
- ifp->name);
- syslog(LOG_ERR, "%s: authentication failed",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: dhcp_auth_validate: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: authentication failed", ifp->name);
goto ex;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_DEBUG, "%s: accepted reconfigure key",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: accepted reconfigure key", ifp->name);
} else if (ifp->options->auth.options & DHCPCD_AUTH_REQUIRE) {
- syslog(LOG_ERR, "%s: authentication now required", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: authentication now required", ifp->name);
goto ex;
}
{
r = dhcp6_readlease(ifp);
if (r == -1)
- syslog(LOG_ERR, "%s: dhcp6_readlease: %s: %m",
- ifp->name, state->leasefile);
+ logger(ifp->ctx, LOG_ERR, "%s: dhcp6_readlease: %s: %m",
+ ifp->name, state->leasefile);
else if (r != 0) {
/* RFC 3633 section 12.1 */
if (dhcp6_hasprefixdelegation(ifp))
if (prefix->prefix_exclude_len == 0) {
/* Don't spam the log automatically */
if (sla)
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: DHCPv6 server does not support "
"OPTION_PD_EXCLUDE",
ifp->name);
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
a->iface = ifp;
if (!delegated)
dhcpcd_daemonise(ifp->ctx);
} else
- syslog(LOG_DEBUG,
- "%s: waiting for DHCPv6 DAD to complete",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: waiting for DHCPv6 DAD to complete", ifp->name);
}
static void
if (j >= i &&
if_find(ifp->ctx, sla->ifname) == NULL)
{
- syslog(LOG_INFO,
+ logger(ifp->ctx, LOG_INFO,
"%s: loading for delegation", sla->ifname);
if (dhcpcd_handleinterface(ifp->ctx, 2,
sla->ifname) == -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: interface does not exist"
" for delegation",
sla->ifname);
continue;
if (ap->flags & IPV6_AF_NEW) {
ap->flags &= ~IPV6_AF_NEW;
- syslog(LOG_DEBUG, "%s: delegated prefix %s",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: delegated prefix %s",
ifp->name, ap->saddr);
}
for (i = 0; i < ifo->ia_len; i++) {
/* no SLA configured, so lets
* automate it */
if (ifd->carrier != LINK_UP) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: has no carrier, cannot"
" delegate addresses",
ifd->name);
if (strcmp(ifd->name, sla->ifname))
continue;
if (ifd->carrier != LINK_UP) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: has no carrier, cannot"
" delegate addresses",
ifd->name);
if (strcmp(ifp->name, sla->ifname))
continue;
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: delaying adding"
" delegated addresses for"
" LL address",
}
if (k) {
- syslog(LOG_INFO, "%s: adding delegated prefixes", ifp->name);
+ logger(ifp->ctx, LOG_INFO,
+ "%s: adding delegated prefixes", ifp->name);
state = D6_STATE(ifp);
state->state = DH6S_DELEGATED;
ipv6_addaddrs(&state->addrs);
static void
dhcp6_handledata(void *arg)
{
- struct dhcpcd_ctx *dhcpcd_ctx;
+ struct dhcpcd_ctx *dctx;
struct ipv6_ctx *ctx;
size_t i, len;
ssize_t bytes;
int error;
uint32_t u32;
- dhcpcd_ctx = arg;
- ctx = dhcpcd_ctx->ipv6;
+ dctx = arg;
+ ctx = dctx->ipv6;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
bytes = recvmsg(ctx->dhcp_fd, &ctx->rcvhdr, 0);
if (bytes == -1) {
- syslog(LOG_ERR, "recvmsg: %m");
+ logger(dctx, LOG_ERR, "%s: recvmsg: %m", __func__);
close(ctx->dhcp_fd);
- eloop_event_delete(dhcpcd_ctx->eloop, ctx->dhcp_fd, 0);
+ eloop_event_delete(dctx->eloop, ctx->dhcp_fd, 0);
ctx->dhcp_fd = -1;
return;
}
ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
ctx->ntopbuf, sizeof(ctx->ntopbuf));
if (len < sizeof(struct dhcp6_message)) {
- syslog(LOG_ERR, "DHCPv6 packet too short from %s",
- ctx->sfrom);
+ logger(dctx, LOG_ERR,
+ "DHCPv6 packet too short from %s", ctx->sfrom);
return;
}
}
if (pkt.ipi6_ifindex == 0) {
- syslog(LOG_ERR,
- "DHCPv6 reply did not contain index from %s",
- ctx->sfrom);
+ logger(dctx, LOG_ERR,
+ "DHCPv6 reply did not contain index from %s", ctx->sfrom);
return;
}
- TAILQ_FOREACH(ifp, dhcpcd_ctx->ifaces, next) {
+ TAILQ_FOREACH(ifp, dctx->ifaces, next) {
if (ifp->index == (unsigned int)pkt.ipi6_ifindex)
break;
}
if (ifp == NULL) {
- syslog(LOG_DEBUG,
+ logger(dctx, LOG_DEBUG,
"DHCPv6 reply for unexpected interface from %s",
ctx->sfrom);
return;
state = D6_STATE(ifp);
if (state == NULL || state->send == NULL) {
- syslog(LOG_DEBUG, "%s: DHCPv6 reply received but not running",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: DHCPv6 reply received but not running", ifp->name);
return;
}
/* We're already bound and this message is for another machine */
r->xid[1] != state->send->xid[1] ||
r->xid[2] != state->send->xid[2]))
{
- syslog(LOG_DEBUG,
+ logger(dctx, LOG_DEBUG,
"%s: wrong xid 0x%02x%02x%02x"
" (expecting 0x%02x%02x%02x) from %s",
ifp->name,
}
if (dhcp6_getmoption(D6_OPTION_SERVERID, r, len) == NULL) {
- syslog(LOG_DEBUG, "%s: no DHCPv6 server ID from %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: no DHCPv6 server ID from %s",
ifp->name, ctx->sfrom);
return;
}
o = dhcp6_getmoption(D6_OPTION_CLIENTID, r, len);
- if (o == NULL || ntohs(o->len) != dhcpcd_ctx->duid_len ||
- memcmp(D6_COPTION_DATA(o),
- dhcpcd_ctx->duid, dhcpcd_ctx->duid_len) != 0)
+ if (o == NULL || ntohs(o->len) != dctx->duid_len ||
+ memcmp(D6_COPTION_DATA(o), dctx->duid, dctx->duid_len) != 0)
{
- syslog(LOG_DEBUG, "%s: incorrect client ID from %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: incorrect client ID from %s",
ifp->name, ctx->sfrom);
return;
}
ifo = ifp->options;
- for (i = 0, opt = dhcpcd_ctx->dhcp6_opts;
- i < dhcpcd_ctx->dhcp6_opts_len;
+ for (i = 0, opt = dctx->dhcp6_opts;
+ i < dctx->dhcp6_opts_len;
i++, opt++)
{
if (has_option_mask(ifo->requiremask6, opt->option) &&
dhcp6_getmoption(opt->option, r, len) == NULL)
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: reject DHCPv6 (no option %s) from %s",
ifp->name, opt->var, ctx->sfrom);
return;
if (has_option_mask(ifo->rejectmask6, opt->option) &&
dhcp6_getmoption(opt->option, r, len))
{
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: reject DHCPv6 (option %s) from %s",
ifp->name, opt->var, ctx->sfrom);
return;
(uint8_t *)r, len, 6, r->type,
D6_COPTION_DATA(auth), ntohs(auth->len)) == NULL)
{
- syslog(LOG_DEBUG, "dhcp_auth_validate: %m");
- syslog(LOG_ERR, "%s: authentication failed from %s",
+ logger(ifp->ctx, LOG_DEBUG, "dhcp_auth_validate: %m");
+ logger(ifp->ctx, LOG_ERR,
+ "%s: authentication failed from %s",
ifp->name, ctx->sfrom);
return;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_DEBUG, "%s: accepted reconfigure key",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
- syslog(LOG_ERR, "%s: no authentication from %s",
- ifp->name, ctx->sfrom);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: no authentication from %s", ifp->name, ctx->sfrom);
return;
} else if (ifo->auth.options & DHCPCD_AUTH_SEND)
- syslog(LOG_WARNING,
- "%s: no authentication from %s",
- ifp->name, ctx->sfrom);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: no authentication from %s", ifp->name, ctx->sfrom);
op = dhcp6_get_op(r->type);
switch(r->type) {
memcpy(&u32, D6_COPTION_DATA(o), sizeof(u32));
u32 = ntohl(u32);
if (u32 >= 60 && u32 <= 86400) {
- syslog(LOG_DEBUG, "%s: SOL_MAX_RT %llu -> %d",
- ifp->name,
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: SOL_MAX_RT %llu -> %d", ifp->name,
(unsigned long long)state->sol_max_rt, u32);
state->sol_max_rt = (time_t)u32;
} else
- syslog(LOG_ERR, "%s: invalid SOL_MAX_RT %d",
+ logger(ifp->ctx, LOG_ERR,
+ "%s: invalid SOL_MAX_RT %d",
ifp->name, u32);
}
o = dhcp6_getmoption(D6_OPTION_INF_MAX_RT, r, len);
memcpy(&u32, D6_COPTION_DATA(o), sizeof(u32));
u32 = ntohl(u32);
if (u32 >= 60 && u32 <= 86400) {
- syslog(LOG_DEBUG, "%s: INF_MAX_RT %llu -> %d",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: INF_MAX_RT %llu -> %d",
ifp->name,
(unsigned long long)state->inf_max_rt, u32);
state->inf_max_rt = (time_t)u32;
} else
- syslog(LOG_ERR, "%s: invalid INF_MAX_RT %d",
+ logger(ifp->ctx, LOG_ERR,
+ "%s: invalid INF_MAX_RT %d",
ifp->name, u32);
}
if (dhcp6_validatelease(ifp, r, len, ctx->sfrom, NULL) == -1)
break;
case DHCP6_RECONFIGURE:
if (auth == NULL) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: unauthenticated %s from %s",
ifp->name, op, ctx->sfrom);
return;
}
- syslog(LOG_INFO, "%s: %s from %s",
+ logger(ifp->ctx, LOG_INFO, "%s: %s from %s",
ifp->name, op, ctx->sfrom);
o = dhcp6_getmoption(D6_OPTION_RECONF_MSG, r, len);
if (o == NULL) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: missing Reconfigure Message option",
ifp->name);
return;
}
if (ntohs(o->len) != 1) {
- syslog(LOG_ERR,
- "%s: missing Reconfigure Message type",
- ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: missing Reconfigure Message type", ifp->name);
return;
}
switch(*D6_COPTION_DATA(o)) {
case DHCP6_RENEW:
if (state->state != DH6S_BOUND) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: not bound, ignoring %s",
ifp->name, op);
return;
break;
case DHCP6_INFORMATION_REQ:
if (state->state != DH6S_INFORMED) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: not informed, ignoring %s",
ifp->name, op);
return;
dhcp6_startinform(ifp);
break;
default:
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: unsupported %s type %d",
ifp->name, op, *D6_COPTION_DATA(o));
break;
}
return;
default:
- syslog(LOG_ERR, "%s: invalid DHCP6 type %s (%d)",
+ logger(ifp->ctx, LOG_ERR, "%s: invalid DHCP6 type %s (%d)",
ifp->name, op, r->type);
return;
}
if (op == NULL) {
- syslog(LOG_WARNING, "%s: invalid state for DHCP6 type %s (%d)",
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: invalid state for DHCP6 type %s (%d)",
ifp->name, op, r->type);
return;
}
free(state->recv);
state->recv = malloc(len);
if (state->recv == NULL) {
- syslog(LOG_ERR, "%s: malloc recv: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: malloc recv: %m", ifp->name);
return;
}
}
if (state->state == DH6S_REQUEST) /* rapid commit */
break;
ap = TAILQ_FIRST(&state->addrs);
- syslog(LOG_INFO, "%s: ADV %s from %s",
+ logger(ifp->ctx, LOG_INFO, "%s: ADV %s from %s",
ifp->name, ap->saddr, ctx->sfrom);
if (ifp->ctx->options & DHCPCD_TEST)
break;
break;
}
}
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
+ logger(ifp->ctx, has_new ? LOG_INFO : LOG_DEBUG,
"%s: %s received from %s", ifp->name, op, ctx->sfrom);
state->reason = NULL;
dhcp6_delegate_prefix(ifp);
if (state->state == DH6S_INFORMED)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
+ logger(ifp->ctx, has_new ? LOG_INFO : LOG_DEBUG,
"%s: refresh in %"PRIu32" seconds",
ifp->name, state->renew);
else if (state->renew || state->rebind)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
+ logger(ifp->ctx, has_new ? LOG_INFO : LOG_DEBUG,
"%s: renew in %"PRIu32" seconds,"
" rebind in %"PRIu32" seconds",
ifp->name, state->renew, state->rebind);
else if (state->expire == 0)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
+ logger(ifp->ctx, has_new ? LOG_INFO : LOG_DEBUG,
"%s: will expire", ifp->name);
ipv6_buildroutes(ifp->ctx);
dhcp6_writelease(ifp);
n = 1;
if (setsockopt(ctx->dhcp_fd, SOL_SOCKET, SO_REUSEPORT,
&n, sizeof(n)) == -1)
- syslog(LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
+ logger(dctx, LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
#endif
if (bind(ctx->dhcp_fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
if (ifs) {
ifn = TAILQ_FIRST(ifs);
if (ifn) {
- syslog(LOG_INFO,
+ logger(ifp->ctx, LOG_INFO,
"%s: creating pseudo interface"
" to handle Prefix Delegation",
ifp->name);
AF_INET6, ifp,
ifp->options->options & DHCPCD_PFXDLGONLY ? ".pd" : "");
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: delaying DHCPv6 soliciation for LL address",
ifp->name);
ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp);
i = strlen(prefix) + strlen("_dhcp6") + 1;
pfx = malloc(i);
if (pfx == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
snprintf(pfx, i, "%s_dhcp6", prefix);
i += strlen(prefix) + strlen("_delegated_dhcp6_prefix=");
v = val = env[n] = malloc(i);
if (v == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
v += snprintf(val, i, "%s_delegated_dhcp6_prefix=", prefix);
ifp->if_data[IF_DATA_DHCP6] = state = calloc(1, sizeof(*state));
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
TAILQ_INIT(&state->addrs);
r = dhcp6_readlease(ifp);
if (r == -1) {
if (errno == ENOENT)
- syslog(LOG_ERR, "%s: no lease to dump", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: no lease to dump", ifp->name);
else
- syslog(LOG_ERR, "%s: dhcp6_readlease: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp6_readlease: %m", ifp->name);
return -1;
}
state->reason = "DUMP6";
fi
[ -n "$lvl" ] && shift
[ -n "$*" ] || return 0
+ case "$lvl" in
+ err|error) echo "$interface: $*" >&2;;
+ *) echo "$interface: $*";;
+ esac
if type logger >/dev/null 2>&1; then
- logger -i -p daemon."$lvl" -s -t dhcpcd "$interface: $*"
+ logger -i -p daemon."$lvl" -t dhcpcd-run-hooks "$interface: $*"
fi
}
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 16, 2015
+.Dd March 17, 2015
.Dt DHCPCD 8
.Os
.Sh NAME
.Op Fl h , Fl Fl hostname Ar hostname
.Op Fl I , Fl Fl clientid Ar clientid
.Op Fl i , Fl Fl vendorclassid Ar vendorclassid
+.Op Fl j , Fl Fl logfile Ar logfile
.Op Fl l , Fl Fl leasetime Ar seconds
.Op Fl m , Fl Fl metric Ar metric
.Op Fl O , Fl Fl nooption Ar option
If not set then none is sent.
Some badly configured DHCP servers reject unknown vendorclassids.
To work around it, try and impersonate Windows by using the MSFT vendorclassid.
+.It Fl j , Fl Fl logfile Ar logfile
+Writes to the specified
+.Ar logfile
+rather than
+.Xr syslog 3 .
+The
+.Ar logfile
+is reopened when
+.Nm
+receives the
+.Dv SIGUSR2
+signal.
.It Fl k , Fl Fl release Op Ar interface
This causes an existing
.Nm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <time.h>
SIGALRM,
SIGHUP,
SIGUSR1,
+ SIGUSR2,
SIGPIPE,
0
};
struct dhcpcd_ctx *ctx;
ctx = arg;
- syslog(LOG_ERR, "timed out");
+ logger(ctx, LOG_ERR, "timed out");
if (!(ctx->options & DHCPCD_MASTER)) {
eloop_exit(ctx->eloop, EXIT_FAILURE);
return;
return 0;
/* Setup a signal pipe so parent knows when to exit. */
if (pipe(sidpipe) == -1) {
- syslog(LOG_ERR, "pipe: %m");
+ logger(ctx, LOG_ERR, "pipe: %m");
return 0;
}
- syslog(LOG_DEBUG, "forking to background");
+ logger(ctx, LOG_DEBUG, "forking to background");
switch (pid = fork()) {
case -1:
- syslog(LOG_ERR, "fork: %m");
+ logger(ctx, LOG_ERR, "fork: %m");
return 0;
case 0:
setsid();
/* Some polling methods don't survive after forking,
* so ensure we can requeue all our events. */
if (eloop_requeue(ctx->eloop) == -1) {
- syslog(LOG_ERR, "eloop_requeue: %m");
+ logger(ctx, LOG_ERR, "eloop_requeue: %m");
eloop_exit(ctx->eloop, EXIT_FAILURE);
}
/* Notify parent it's safe to exit as we've detached. */
close(sidpipe[0]);
if (write(sidpipe[1], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to notify parent: %m");
+ logger(ctx, LOG_ERR, "failed to notify parent: %m");
close(sidpipe[1]);
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO);
/* Wait for child to detach */
close(sidpipe[1]);
if (read(sidpipe[0], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to read child: %m");
+ logger(ctx, LOG_ERR, "failed to read child: %m");
close(sidpipe[0]);
break;
}
/* Done with the fd now */
if (pid != 0) {
- syslog(LOG_INFO, "forked to background, child pid %d", pid);
+ logger(ctx, LOG_INFO, "forked to background, child pid %d", pid);
write_pid(ctx->pid_fd, pid);
close(ctx->pid_fd);
ctx->pid_fd = -1;
struct dhcpcd_ctx *ctx;
ctx = ifp->ctx;
- syslog(LOG_INFO, "%s: removing interface", ifp->name);
+ logger(ctx, LOG_INFO, "%s: removing interface", ifp->name);
ifp->options->options |= DHCPCD_STOPPING;
dhcp6_drop(ifp, NULL);
{
ifo->ia = malloc(sizeof(*ifo->ia));
if (ifo->ia == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
else {
ifo->ia_len = 1;
ifo->ia->ia_type = D6_OPTION_IA_NA;
r = print_string(pssid, sizeof(pssid), ESCSTRING,
ifp->ssid, ifp->ssid_len);
if (r == -1) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: %s: %m", ifp->name, __func__);
pssid[0] = '\0';
}
} else
pssid[0] = '\0';
ifo = read_config(ifp->ctx, ifp->name, pssid, profile);
if (ifo == NULL) {
- syslog(LOG_DEBUG, "%s: no profile %s", ifp->name, profile);
+ logger(ifp->ctx, LOG_DEBUG, "%s: no profile %s",
+ ifp->name, profile);
return -1;
}
if (profile != NULL) {
strlcpy(ifp->profile, profile, sizeof(ifp->profile));
- syslog(LOG_INFO, "%s: selected profile %s",
+ logger(ifp->ctx, LOG_INFO, "%s: selected profile %s",
ifp->name, profile);
} else
*ifp->profile = '\0';
if (carrier == LINK_UNKNOWN) {
if (errno != ENOTTY) /* For example a PPP link on BSD */
- syslog(LOG_ERR, "%s: carrier_status: %m", ifname);
+ logger(ctx, LOG_ERR, "%s: carrier_status: %m", ifname);
} else if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
if (ifp->carrier != LINK_DOWN) {
if (ifp->carrier == LINK_UP)
- syslog(LOG_INFO, "%s: carrier lost", ifp->name);
+ logger(ctx, LOG_INFO, "%s: carrier lost", ifp->name);
ifp->carrier = LINK_DOWN;
script_runreason(ifp, "NOCARRIER");
dhcp6_drop(ifp, "EXPIRE6");
}
} else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
if (ifp->carrier != LINK_UP) {
- syslog(LOG_INFO, "%s: carrier acquired", ifp->name);
+ logger(ctx, LOG_INFO, "%s: carrier acquired", ifp->name);
ifp->carrier = LINK_UP;
#if !defined(__linux__) && !defined(__NetBSD__)
/* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
/* This is only a problem if the interfaces are on the same network. */
if (ifn && strcmp(ifp->name, ifn->name))
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: IAID conflicts with one assigned to %s",
ifp->name, ifn->name);
}
* This is also a safety check incase it was ripped out
* from under us. */
if (ifp->options->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
- syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: ipv6_start: %m", ifp->name);
ifp->options->options &= ~DHCPCD_IPV6;
}
}
case LINK_UP:
break;
case LINK_DOWN:
- syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
+ logger(ifp->ctx, LOG_INFO, "%s: waiting for carrier",
+ ifp->name);
return;
case LINK_UNKNOWN:
/* No media state available.
if (duid_init(ifp) == 0)
return;
if (!(ifo->options & DHCPCD_PFXDLGONLY))
- syslog(LOG_INFO, "DUID %s",
+ logger(ifp->ctx, LOG_INFO, "DUID %s",
hwaddr_ntoa(ifp->ctx->duid,
ifp->ctx->duid_len,
buf, sizeof(buf)));
!(ifo->options & DHCPCD_PFXDLGONLY))
{
/* Report IAIDs */
- syslog(LOG_INFO, "%s: IAID %s", ifp->name,
+ logger(ifp->ctx, LOG_INFO, "%s: IAID %s", ifp->name,
hwaddr_ntoa(ifo->iaid, sizeof(ifo->iaid),
buf, sizeof(buf)));
warn_iaid_conflict(ifp, ifo->iaid);
if (memcmp(ifo->iaid, ifo->ia[i].iaid,
sizeof(ifo->iaid)))
{
- syslog(LOG_INFO, "%s: IAID %s", ifp->name,
- hwaddr_ntoa(ifo->ia[i].iaid,
+ logger(ifp->ctx, LOG_INFO, "%s: IAID %s",
+ ifp->name, hwaddr_ntoa(ifo->ia[i].iaid,
sizeof(ifo->ia[i].iaid),
buf, sizeof(buf)));
warn_iaid_conflict(ifp, ifo->ia[i].iaid);
#endif
}
if (nolease == -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: dhcp6_start: %m", ifp->name);
}
}
pre_start(ifp);
if (if_up(ifp) == -1)
- syslog(LOG_ERR, "%s: if_up: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: if_up: %m", ifp->name);
if (ifp->options->options & DHCPCD_LINK &&
ifp->carrier == LINK_UNKNOWN)
ifp->flags, ifp->name);
return;
}
- syslog(LOG_INFO,
+ logger(ifp->ctx, LOG_INFO,
"%s: unknown carrier, waiting for interface flags",
ifp->name);
}
ctx = arg;
if (if_managelink(ctx) == -1) {
- syslog(LOG_ERR, "if_managelink: %m");
+ logger(ctx, LOG_ERR, "if_managelink: %m");
eloop_event_delete(ctx->eloop, ctx->link_fd, 0);
close(ctx->link_fd);
ctx->link_fd = -1;
ifo = ifp->options;
if (ifo->options & DHCPCD_IPV4 && ipv4_init(ifp->ctx) == -1) {
- syslog(LOG_ERR, "ipv4_init: %m");
+ logger(ifp->ctx, LOG_ERR, "ipv4_init: %m");
ifo->options &= ~DHCPCD_IPV4;
}
if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == NULL) {
- syslog(LOG_ERR, "ipv6_init: %m");
+ logger(ifp->ctx, LOG_ERR, "ipv6_init: %m");
ifo->options &= ~DHCPCD_IPV6RS;
}
* This needs to happen before PREINIT incase a hook script
* inadvertently ups the interface. */
if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
- syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: ipv6_start: %m", ifp->name);
ifo->options &= ~DHCPCD_IPV6;
}
}
errno = ESRCH;
return -1;
}
- syslog(LOG_DEBUG, "%s: interface departed", ifp->name);
+ logger(ctx, LOG_DEBUG, "%s: interface departed", ifp->name);
ifp->options->options |= DHCPCD_DEPARTED;
stop_interface(ifp);
return 0;
i = -1;
ifs = if_discover(ctx, -1, UNCONST(argv));
if (ifs == NULL) {
- syslog(LOG_ERR, "%s: if_discover: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: if_discover: %m", __func__);
return -1;
}
TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
/* Check if we already have the interface */
iff = if_find(ctx, ifp->name);
if (iff) {
- syslog(LOG_DEBUG, "%s: interface updated", iff->name);
+ logger(ctx, LOG_DEBUG, "%s: interface updated", iff->name);
/* The flags and hwaddr could have changed */
iff->flags = ifp->flags;
iff->hwlen = ifp->hwlen;
if (ifp->hwlen != 0)
memcpy(iff->hwaddr, ifp->hwaddr, iff->hwlen);
} else {
- syslog(LOG_DEBUG, "%s: interface added", ifp->name);
+ logger(ctx, LOG_DEBUG, "%s: interface added", ifp->name);
TAILQ_REMOVE(ifs, ifp, next);
TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
dhcpcd_initstate(ifp, 0);
if (hwlen > sizeof(ifp->hwaddr)) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logger(ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
return;
}
if (ifp->hwlen == hwlen && memcmp(ifp->hwaddr, hwaddr, hwlen) == 0)
return;
- syslog(LOG_INFO, "%s: new hardware address: %s", ifp->name,
+ logger(ctx, LOG_INFO, "%s: new hardware address: %s", ifp->name,
hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
ifp->hwlen = hwlen;
memcpy(ifp->hwaddr, hwaddr, hwlen);
ifs = if_discover(ctx, argc - oi, argv + oi);
if (ifs == NULL) {
- syslog(LOG_ERR, "%s: if_discover: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: if_discover: %m", __func__);
return;
}
#ifdef USE_SIGNALS
struct dhcpcd_siginfo dhcpcd_siginfo;
-#define sigmsg "received signal %s, %s"
+#define sigmsg "received %s, %s"
void
dhcpcd_handle_signal(void *arg)
{
exit_code = EXIT_FAILURE;
switch (si->signo) {
case SIGINT:
- syslog(LOG_INFO, sigmsg, "INT", "stopping");
+ logger(ctx, LOG_INFO, sigmsg, "SIGINT", "stopping");
break;
case SIGTERM:
- syslog(LOG_INFO, sigmsg, "TERM", "stopping");
+ logger(ctx, LOG_INFO, sigmsg, "SIGTERM", "stopping");
exit_code = EXIT_SUCCESS;
break;
case SIGALRM:
- syslog(LOG_INFO, sigmsg, "ALRM", "releasing");
+ logger(ctx, LOG_INFO, sigmsg, "SIGALRM", "releasing");
do_release = 1;
exit_code = EXIT_SUCCESS;
break;
case SIGHUP:
- syslog(LOG_INFO, sigmsg, "HUP", "rebinding");
+ logger(ctx, LOG_INFO, sigmsg, "SIGHUP", "rebinding");
reload_config(ctx);
/* Preserve any options passed on the commandline
* when we were started. */
ctx->argc - ctx->ifc);
return;
case SIGUSR1:
- syslog(LOG_INFO, sigmsg, "USR1", "reconfiguring");
+ logger(ctx, LOG_INFO, sigmsg, "SIGUSR1", "reconfiguring");
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
ipv4_applyaddr(ifp);
}
return;
+ case SIGUSR2:
+ logger_close(ctx);
+ logger_open(ctx);
+ logger(ctx, LOG_INFO, sigmsg, "SIGUSR2", "reopened logfile");
+ return;
case SIGPIPE:
- syslog(LOG_WARNING, "received signal PIPE");
+ logger(ctx, LOG_WARNING, "received SIGPIPE");
return;
default:
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"received signal %d, "
"but don't know what to do with it",
si->signo);
eloop_event_delete(fd->ctx->eloop, fd->fd, 1);
TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) {
if (send_interface(fd, ifp) == -1)
- syslog(LOG_ERR, "send_interface %d: %m", fd->fd);
+ logger(ifp->ctx, LOG_ERR,
+ "send_interface %d: %m", fd->fd);
}
}
*p++ = ' ';
}
*--p = '\0';
- syslog(LOG_INFO, "control command: %s", tmp);
+ logger(ctx, LOG_INFO, "control command: %s", tmp);
free(tmp);
optind = 0;
const char *siga;
#endif
- memset(&ctx, 0, sizeof(ctx));
-#ifdef USE_SIGNALS
- dhcpcd_ctx = &ctx;
- sig = 0;
- siga = NULL;
-#endif
- closefrom(3);
-#ifdef LOG_PERROR
- openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
-#else
- openlog(PACKAGE, LOG_PID, LOG_DAEMON);
-#endif
- setlogmask(LOG_UPTO(LOG_INFO));
-#ifndef LOG_PERROR
- psyslog_prio = LOG_UPTO(LOG_INFO);
-#endif
-
/* Test for --help and --version */
if (argc > 1) {
if (strcmp(argv[1], "--help") == 0) {
}
}
+ memset(&ctx, 0, sizeof(ctx));
+#ifdef USE_SIGNALS
+ dhcpcd_ctx = &ctx;
+ sig = 0;
+ siga = NULL;
+#endif
+ closefrom(3);
+
+ ctx.log_fd = -1;
+ logger_open(&ctx);
+ logger_mask(&ctx, LOG_UPTO(LOG_INFO));
+
ifo = NULL;
ctx.cffile = CONFIG;
ctx.pid_fd = ctx.control_fd = ctx.control_unpriv_fd = ctx.link_fd = -1;
{
switch (opt) {
case '4':
- if (family) {
- syslog(LOG_ERR, "cannot specify more than one"
- " address family");
- goto exit_failure;
- }
family = AF_INET;
break;
case '6':
- if (family) {
- syslog(LOG_ERR, "cannot specify more than one"
- " address family");
- goto exit_failure;
- }
family = AF_INET6;
break;
case 'f':
sig = SIGUSR1;
siga = "USR1";
break;
+ case 'j':
+ ctx.logfile = strdup(optarg);
+ logger_close(&ctx);
+ logger_open(&ctx);
+ break;
case 'k':
sig = SIGALRM;
siga = "ARLM";
ctx.options &= ~DHCPCD_DAEMONISE;
#endif
- if (ctx.options & DHCPCD_DEBUG) {
- setlogmask(LOG_UPTO(LOG_DEBUG));
-#ifndef LOG_PERROR
- psyslog_prio = LOG_UPTO(LOG_DEBUG);
-#endif
- }
+ if (ctx.options & DHCPCD_DEBUG)
+ logger_mask(&ctx, LOG_UPTO(LOG_DEBUG));
if (ctx.options & DHCPCD_QUIET) {
i = open(_PATH_DEVNULL, O_RDWR);
if (i == -1)
- syslog(LOG_ERR, "%s: open: %m", __func__);
+ logger(&ctx, LOG_ERR, "%s: open: %m", __func__);
else {
dup2(i, STDERR_FILENO);
close(i);
const char *per;
if (strlen(argv[optind]) > IF_NAMESIZE) {
- syslog(LOG_ERR, "%s: interface name too long",
+ logger(&ctx, LOG_ERR,
+ "%s: interface name too long",
argv[optind]);
goto exit_failure;
}
}
if (chdir("/") == -1)
- syslog(LOG_ERR, "chdir `/': %m");
+ logger(&ctx, LOG_ERR, "chdir `/': %m");
/* Freeing allocated addresses from dumping leases can trigger
* eloop removals as well, so init here. */
- ctx.eloop = eloop_init();
+ ctx.eloop = eloop_init(&ctx);
if (ctx.eloop == NULL) {
- syslog(LOG_ERR, "%s: eloop_init: %m", __func__);
+ logger(&ctx, LOG_ERR, "%s: eloop_init: %m", __func__);
goto exit_failure;
}
if (ctx.options & DHCPCD_DUMPLEASE) {
if (optind != argc - 1) {
- syslog(LOG_ERR, "dumplease requires an interface");
+ logger(&ctx, LOG_ERR,
+ "dumplease requires an interface");
goto exit_failure;
}
i = 0;
* load the hardware address to compare automated IAID */
ctx.ifaces = if_discover(&ctx, 1, argv + optind);
if (ctx.ifaces == NULL) {
- syslog(LOG_ERR, "if_discover: %m");
+ logger(&ctx, LOG_ERR, "if_discover: %m");
goto exit_failure;
}
ifp = TAILQ_FIRST(ctx.ifaces);
if (ifp == NULL) {
ifp = calloc(1, sizeof(*ifp));
if (ifp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(&ctx, LOG_ERR, "%s: %m", __func__);
goto exit_failure;
}
strlcpy(ctx.pidfile, argv[optind], sizeof(ctx.pidfile));
if (i == -1)
i = control_open(&ctx, NULL);
if (i != -1) {
- syslog(LOG_INFO,
+ logger(&ctx, LOG_INFO,
"sending commands to master dhcpcd process");
len = control_send(&ctx, argc, argv);
control_close(&ctx);
if (len > 0) {
- syslog(LOG_DEBUG, "send OK");
+ logger(&ctx, LOG_DEBUG, "send OK");
goto exit_success;
} else {
- syslog(LOG_ERR, "failed to send commands");
+ logger(&ctx, LOG_ERR,
+ "failed to send commands");
goto exit_failure;
}
} else {
if (errno != ENOENT)
- syslog(LOG_ERR, "control_open: %m");
+ logger(&ctx, LOG_ERR, "control_open: %m");
}
#ifdef USE_SIGNALS
}
#endif
if (geteuid())
- syslog(LOG_WARNING,
+ logger(&ctx, LOG_WARNING,
PACKAGE " will not work correctly unless run as root");
#ifdef USE_SIGNALS
if (sig != 0) {
pid = read_pid(ctx.pidfile);
if (pid != 0)
- syslog(LOG_INFO, "sending signal %s to pid %d",
+ logger(&ctx, LOG_INFO, "sending signal %s to pid %d",
siga, pid);
if (pid == 0 || kill(pid, sig) != 0) {
if (sig != SIGHUP && errno != EPERM)
- syslog(LOG_ERR, ""PACKAGE" not running");
+ logger(&ctx, LOG_ERR, ""PACKAGE" not running");
if (pid != 0 && errno != ESRCH) {
- syslog(LOG_ERR, "kill: %m");
+ logger(&ctx, LOG_ERR, "kill: %m");
goto exit_failure;
}
unlink(ctx.pidfile);
if (sig == SIGHUP || sig == SIGUSR1)
goto exit_success;
/* Spin until it exits */
- syslog(LOG_INFO, "waiting for pid %d to exit", pid);
+ logger(&ctx, LOG_INFO,
+ "waiting for pid %d to exit", pid);
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 10th of a second */
for(i = 0; i < 100; i++) {
if (read_pid(ctx.pidfile) == 0)
goto exit_success;
}
- syslog(LOG_ERR, "pid %d failed to exit", pid);
+ logger(&ctx, LOG_ERR, "pid %d failed to exit", pid);
goto exit_failure;
}
}
if ((pid = read_pid(ctx.pidfile)) > 0 &&
kill(pid, 0) == 0)
{
- syslog(LOG_ERR, ""PACKAGE
+ logger(&ctx, LOG_ERR, ""PACKAGE
" already running on pid %d (%s)",
pid, ctx.pidfile);
goto exit_failure;
/* Ensure we have the needed directories */
if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
- syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR);
+ logger(&ctx, LOG_ERR, "mkdir `%s': %m", RUNDIR);
if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST)
- syslog(LOG_ERR, "mkdir `%s': %m", DBDIR);
+ logger(&ctx, LOG_ERR, "mkdir `%s': %m", DBDIR);
opt = O_WRONLY | O_CREAT | O_NONBLOCK;
#ifdef O_CLOEXEC
#endif
ctx.pid_fd = open(ctx.pidfile, opt, 0664);
if (ctx.pid_fd == -1)
- syslog(LOG_ERR, "open `%s': %m", ctx.pidfile);
+ logger(&ctx, LOG_ERR, "open `%s': %m", ctx.pidfile);
else {
#ifdef LOCK_EX
/* Lock the file so that only one instance of dhcpcd
* runs on an interface */
if (flock(ctx.pid_fd, LOCK_EX | LOCK_NB) == -1) {
- syslog(LOG_ERR, "flock `%s': %m", ctx.pidfile);
+ logger(&ctx, LOG_ERR, "flock `%s': %m", ctx.pidfile);
close(ctx.pid_fd);
ctx.pid_fd = -1;
goto exit_failure;
if (fcntl(ctx.pid_fd, F_GETFD, &opt) == -1 ||
fcntl(ctx.pid_fd, F_SETFD, opt | FD_CLOEXEC) == -1)
{
- syslog(LOG_ERR, "fcntl: %m");
+ logger(&ctx, LOG_ERR, "fcntl: %m");
close(ctx.pid_fd);
ctx.pid_fd = -1;
goto exit_failure;
if (ctx.options & DHCPCD_MASTER) {
if (control_start(&ctx, NULL) == -1)
- syslog(LOG_ERR, "control_start: %m");
+ logger(&ctx, LOG_ERR, "control_start: %m");
}
#else
if (control_start(&ctx,
ctx.options & DHCPCD_MASTER ? NULL : argv[optind]) == -1)
{
- syslog(LOG_ERR, "control_start: %m");
+ logger(&ctx, LOG_ERR, "control_start: %m");
goto exit_failure;
}
#endif
- syslog(LOG_INFO, "version " VERSION " starting");
+ logger(&ctx, LOG_DEBUG, PACKAGE "-" VERSION " starting");
ctx.options |= DHCPCD_STARTED;
#ifdef USE_SIGNALS
/* Save signal mask, block and redirect signals to our handler */
if (signal_init(&ctx.sigset) == -1) {
- syslog(LOG_ERR, "signal_setup: %m");
+ logger(&ctx, LOG_ERR, "signal_setup: %m");
goto exit_failure;
}
#endif
* so that we pickup any new addresses during the discover phase. */
ctx.link_fd = if_openlinksocket();
if (ctx.link_fd == -1)
- syslog(LOG_ERR, "open_link_socket: %m");
+ logger(&ctx, LOG_ERR, "open_link_socket: %m");
else
eloop_event_add(ctx.eloop, ctx.link_fd,
handle_link, &ctx, NULL, NULL);
ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
if (ctx.ifaces == NULL) {
- syslog(LOG_ERR, "if_discover: %m");
+ logger(&ctx, LOG_ERR, "if_discover: %m");
goto exit_failure;
}
for (i = 0; i < ctx.ifc; i++) {
if (if_find(&ctx, ctx.ifv[i]) == NULL)
- syslog(LOG_ERR, "%s: interface not found or invalid",
+ logger(&ctx, LOG_ERR,
+ "%s: interface not found or invalid",
ctx.ifv[i]);
}
if (TAILQ_FIRST(ctx.ifaces) == NULL) {
if (ctx.ifc == 0)
- syslog(LOG_ERR, "no valid interfaces found");
+ logger(&ctx, LOG_ERR, "no valid interfaces found");
else
goto exit_failure;
if (!(ctx.options & DHCPCD_LINK)) {
- syslog(LOG_ERR,
+ logger(&ctx, LOG_ERR,
"aborting as link detection is disabled");
goto exit_failure;
}
ctx.options & DHCPCD_LINK &&
!(ctx.options & DHCPCD_WAITIP))
{
- syslog(LOG_WARNING, "no interfaces have a carrier");
+ logger(&ctx, LOG_WARNING,
+ "no interfaces have a carrier");
if (dhcpcd_daemonise(&ctx))
goto exit_success;
} else if (t > 0 &&
dhcpcd_prestartinterface, ifp);
}
- i = eloop_start(&ctx);
+ i = eloop_start(ctx.eloop);
goto exit1;
exit_success:
ipv6_ctxfree(&ctx);
dev_stop(&ctx);
if (control_stop(&ctx) == -1)
- syslog(LOG_ERR, "control_stop: %m:");
+ logger(&ctx, LOG_ERR, "control_stop: %m:");
if (ctx.pid_fd != -1) {
close(ctx.pid_fd);
unlink(ctx.pidfile);
eloop_free(ctx.eloop);
if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED))
- syslog(LOG_INFO, "exited");
- closelog();
+ logger(&ctx, LOG_INFO, PACKAGE " exited");
+ logger_close(&ctx);
+ free(ctx.logfile);
return i;
}
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 20, 2015
+.Dd March 17, 2015
.Dt DHCPCD.CONF 5
.Os
.Sh NAME
.It Ic leasetime Ar seconds
Request a leasetime of
.Ar seconds .
+.It Ic logfile Ar logfile
+Writes to the specified
+.Ar logfile
+rather than
+.Xr syslog 3 .
+The
+.Ar logfile
+is reopened when
+.Nm dhcpcd
+receives the
+.Dv SIGUSR2
+signal.
.It Ic metric Ar metric
Metrics are used to prefer an interface over another one, lowest wins.
.Nm dhcpcd
char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
const char *cffile;
unsigned long long options;
+ char *logfile;
+ int log_fd;
int argc;
char **argv;
int ifac; /* allowed interfaces */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
return len;
} else {
if (errno != ENOENT)
- syslog(LOG_ERR, "error reading DUID: %s: %m", DUID);
+ logger(ifp->ctx, LOG_ERR,
+ "error reading DUID: %s: %m", DUID);
}
/* No file? OK, lets make one based on our interface */
if (ifp->family == ARPHRD_NETROM) {
- syslog(LOG_WARNING, "%s: is a NET/ROM psuedo interface",
- ifp->name);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: is a NET/ROM psuedo interface", ifp->name);
TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
if (ifp2->family != ARPHRD_NETROM)
break;
}
if (ifp2) {
ifp = ifp2;
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"picked interface %s to generate a DUID",
ifp->name);
} else {
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"no interfaces have a fixed hardware address");
return duid_make(d, ifp, DUID_LL);
}
}
if (!(fp = fopen(DUID, "w"))) {
- syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+ logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID);
return duid_make(d, ifp, DUID_LL);
}
len = duid_make(d, ifp, DUID_LLT);
fclose(fp);
/* Failed to write the duid? scrub it, we cannot use it */
if (x < 1) {
- syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+ logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID);
unlink(DUID);
return duid_make(d, ifp, DUID_LL);
}
if (ifp->ctx->duid == NULL) {
ifp->ctx->duid = malloc(DUID_LEN);
if (ifp->ctx->duid == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return 0;
}
ifp->ctx->duid_len = duid_get(ifp->ctx->duid, ifp);
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
return 0;
err:
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx->ctx, LOG_ERR, "%s: %m", __func__);
if (e) {
ctx->events_len--;
TAILQ_INSERT_TAIL(&ctx->free_events, e, next);
} else {
t = malloc(sizeof(*t));
if (t == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
}
return eloop_q_timeout_add_tv(ctx, queue, &tv, callback, arg);
}
+#if !defined(HAVE_KQUEUE)
int
eloop_timeout_add_now(struct eloop_ctx *ctx,
void (*callback)(void *), void *arg)
{
if (ctx->timeout0 != NULL) {
- syslog(LOG_WARNING, "%s: timeout0 already set", __func__);
+ logger(ctx->ctx, LOG_WARNING,
+ "%s: timeout0 already set", __func__);
return eloop_q_timeout_add_sec(ctx, 0, 0, callback, arg);
}
ctx->timeout0_arg = arg;
return 0;
}
+#endif
void
eloop_q_timeout_delete(struct eloop_ctx *ctx, int queue,
#endif
struct eloop_ctx *
-eloop_init(void)
+eloop_init(struct dhcpcd_ctx *dctx)
{
struct eloop_ctx *ctx;
struct timespec now;
ctx = calloc(1, sizeof(*ctx));
if (ctx) {
+ ctx->ctx = dctx;
TAILQ_INIT(&ctx->events);
TAILQ_INIT(&ctx->free_events);
TAILQ_INIT(&ctx->timeouts);
}
int
-eloop_start(struct dhcpcd_ctx *dctx)
+eloop_start(struct eloop_ctx *ctx)
{
- struct eloop_ctx *ctx;
int n;
struct eloop_event *e;
struct eloop_timeout *t;
struct epoll_event epe;
#endif
- ctx = dctx->eloop;
for (;;) {
if (ctx->exitnow)
break;
tsp = NULL;
if (tsp == NULL && ctx->events_len == 0) {
- syslog(LOG_ERR, "nothing to do");
+ logger(ctx->ctx, LOG_ERR, "nothing to do");
break;
}
n = kevent(ctx->poll_fd, NULL, 0, &ke, 1, tsp);
#elif defined(HAVE_EPOLL)
#ifdef USE_SIGNALS
- n = epoll_pwait(ctx->poll_fd, &epe, 1, timeout, &dctx->sigset);
+ n = epoll_pwait(ctx->poll_fd, &epe, 1, timeout,
+ &ctx->ctx->sigset);
#else
n = epoll_wait(ctx->poll_fd, &epe, 1, timeout);
#endif
#else
#ifdef USE_SIGNALS
- n = pollts(ctx->fds, (nfds_t)ctx->events_len,
- tsp, &dctx->sigset);
+ n = pollts(ctx->fds, (nfds_t)ctx->events_len, tsp,
+ &ctx->ctx->sigset);
#else
n = poll(ctx->fds, (nfds_t)ctx->events_len, timeout);
#endif
if (n == -1) {
if (errno == EINTR)
continue;
- syslog(LOG_ERR, "poll: %m");
+ logger(ctx->ctx, LOG_ERR, "poll: %m");
break;
}
};
struct eloop_ctx {
+ struct dhcpcd_ctx *ctx;
+
size_t events_len;
TAILQ_HEAD (event_head, eloop_event) events;
struct event_head free_events;
time_t, void (*)(void *), void *);
int eloop_q_timeout_add_tv(struct eloop_ctx *, int queue,
const struct timespec *, void (*)(void *), void *);
+#if !defined(HAVE_KQUEUE)
int eloop_timeout_add_now(struct eloop_ctx *, void (*)(void *), void *);
+#endif
void eloop_q_timeout_delete(struct eloop_ctx *, int, void (*)(void *), void *);
-struct eloop_ctx * eloop_init(void);
+struct eloop_ctx * eloop_init(struct dhcpcd_ctx *);
#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL)
int eloop_requeue(struct eloop_ctx *);
#else
#endif
void eloop_free(struct eloop_ctx *);
void eloop_exit(struct eloop_ctx *, int);
-int eloop_start(struct dhcpcd_ctx *);
+int eloop_start(struct eloop_ctx *);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#if defined(OpenBSD) && OpenBSD >= 201411
goto eexit;
if (pv.bv_major != BPF_MAJOR_VERSION ||
pv.bv_minor < BPF_MINOR_VERSION) {
- syslog(LOG_ERR, "BPF version mismatch - recompile");
+ logger(ifp->ctx, LOG_ERR, "BPF version mismatch - recompile");
goto eexit;
}
}
static int
-if_raflush(void)
+if_raflush(struct dhcpcd_ctx *ctx)
{
int s;
char dummy[IFNAMSIZ + 8];
return -1;
strlcpy(dummy, "lo0", sizeof(dummy));
if (ioctl(s, SIOCSRTRFLUSH_IN6, (void *)&dummy) == -1)
- syslog(LOG_ERR, "SIOSRTRFLUSH_IN6: %m");
+ logger(ctx, LOG_ERR, "SIOSRTRFLUSH_IN6: %m");
if (ioctl(s, SIOCSPFXFLUSH_IN6, (void *)&dummy) == -1)
- syslog(LOG_ERR, "SIOSPFXFLUSH_IN6: %m");
+ logger(ctx, LOG_ERR, "SIOSPFXFLUSH_IN6: %m");
close(s);
return 0;
}
#ifdef ND6_IFF_IFDISABLED
if (del_if_nd6_flag(ifp->name, ND6_IFF_IFDISABLED) == -1) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: del_if_nd6_flag: ND6_IFF_IFDISABLED: %m",
ifp->name);
return -1;
#ifdef ND6_IFF_PERFORMNUD
if (set_if_nd6_flag(ifp->name, ND6_IFF_PERFORMNUD) == -1) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: set_if_nd6_flag: ND6_IFF_PERFORMNUD: %m",
ifp->name);
return -1;
all = get_if_nd6_flag(ifp->name,ND6_IFF_AUTO_LINKLOCAL);
if (all == -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: get_if_nd6_flag: "
"ND6_IFF_AUTO_LINKLOCAL: %m",
ifp->name);
else if (all != 0) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: disabling Kernel IPv6 "
"auto link-local support",
ifp->name);
if (del_if_nd6_flag(ifp->name,
ND6_IFF_AUTO_LINKLOCAL) == -1)
{
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: del_if_nd6_flag: "
"ND6_IFF_AUTO_LINKLOCAL: %m",
ifp->name);
#ifdef ND6_IFF_OVERRIDE_RTADV
override = get_if_nd6_flag(ifp->name, ND6_IFF_OVERRIDE_RTADV);
if (override == -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: get_if_nd6_flag: ND6_IFF_OVERRIDE_RTADV: %m",
ifp->name);
else if (override == 0 && own) {
if (set_if_nd6_flag(ifp->name, ND6_IFF_OVERRIDE_RTADV)
== -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: set_if_nd6_flag: "
"ND6_IFF_OVERRIDE_RTADV: %m",
ifp->name);
#ifdef ND6_IFF_ACCEPT_RTADV
ra = get_if_nd6_flag(ifp->name, ND6_IFF_ACCEPT_RTADV);
if (ra == -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: get_if_nd6_flag: ND6_IFF_ACCEPT_RTADV: %m",
ifp->name);
else if (ra != 0 && own) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: disabling Kernel IPv6 RA support",
ifp->name);
if (del_if_nd6_flag(ifp->name, ND6_IFF_ACCEPT_RTADV)
== -1)
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: del_if_nd6_flag: "
"ND6_IFF_ACCEPT_RTADV: %m",
ifp->name);
else
ra = 0;
} else if (ra == 0 && !own)
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: IPv6 kernel autoconf disabled", ifp->name);
#ifdef ND6_IFF_OVERRIDE_RTADV
if (override == 0 && ra)
if (ra == -1)
/* The sysctl probably doesn't exist, but this isn't an
* error as such so just log it and continue */
- syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
+ logger(ifp->ctx, errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
"IPV6CTL_ACCEPT_RTADV: %m");
else if (ra != 0 && own) {
- syslog(LOG_DEBUG, "disabling Kernel IPv6 RA support");
+ logger(ifp->ctx, LOG_DEBUG, "disabling Kernel IPv6 RA support");
if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) {
- syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
+ logger(ifp->ctx, LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
return ra;
}
ra = 0;
/* Flush the kernel knowledge of advertised routers
* and prefixes so the kernel does not expire prefixes
* and default routes we are trying to own. */
- if_raflush();
+ if_raflush(ctx);
}
ctx->ra_global = ra;
#include <string.h>
#include <unistd.h>
-#include "common.h"
#include "config.h"
/* We can't include if.h or dhcpcd.h because
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
ifname = "all";
else if (own) {
if (if_disable_autolinklocal(ctx, (int)ifp->index) == -1)
- syslog(LOG_DEBUG, "%s: if_disable_autolinklocal: %m",
- ifp->name);
+ logger(ctx, LOG_DEBUG,
+ "%s: if_disable_autolinklocal: %m", ifp->name);
}
if (ifp)
ifname = ifp->name;
ra = check_proc_int(path);
if (ra != 1) {
if (!own)
- syslog(LOG_WARNING,
+ logger(ctx, LOG_WARNING,
"%s: IPv6 kernel autoconf disabled", ifname);
} else if (ra != -1 && own) {
if (write_path(path, "0") == -1) {
- syslog(LOG_ERR, "write_path: %s: %m", path);
+ logger(ctx, LOG_ERR, "write_path: %s: %m", path);
return -1;
}
}
if (ra == -1)
/* The sysctl probably doesn't exist, but this isn't an
* error as such so just log it and continue */
- syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
+ logger(ctx, errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
"%s: %m", path);
else if (ra != 0 && own) {
- syslog(LOG_DEBUG, "%s: disabling kernel IPv6 RA support",
+ logger(ctx, LOG_DEBUG, "%s: disabling kernel IPv6 RA support",
ifname);
if (write_path(path, "0") == -1) {
- syslog(LOG_ERR, "write_path: %s: %m", path);
+ logger(ctx, LOG_ERR, "write_path: %s: %m", path);
return ra;
}
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <time.h>
{"reconfigure", no_argument, NULL, 'g'},
{"hostname", optional_argument, NULL, 'h'},
{"vendorclassid", optional_argument, NULL, 'i'},
+ {"logfile", required_argument, NULL, 'j'},
{"release", no_argument, NULL, 'k'},
{"leasetime", required_argument, NULL, 'l'},
{"metric", required_argument, NULL, 'm'},
};
static char *
-add_environ(struct if_options *ifo, const char *value, int uniq)
+add_environ(struct dhcpcd_ctx *ctx, struct if_options *ifo,
+ const char *value, int uniq)
{
char **newlist;
char **lst = ifo->environ;
match = strdup(value);
if (match == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
p = strchr(match, '=');
if (p == NULL) {
- syslog(LOG_ERR, "%s: no assignment: %s", __func__, value);
+ logger(ctx, LOG_ERR, "%s: no assignment: %s", __func__, value);
free(match);
return NULL;
}
if (uniq) {
n = strdup(value);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR,
+ "%s: %m", __func__);
free(match);
return NULL;
}
lv = strlen(p);
n = realloc(lst[i], l + lv + 2);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR,
+ "%s: %m", __func__);
free(match);
return NULL;
}
free(match);
n = strdup(value);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
newlist = realloc(lst, sizeof(char *) * (i + 2));
if (newlist == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(n);
return NULL;
}
return 0;
}
- if ((s = parse_string((char *)iaid, len, arg)) < 1) {
- syslog(LOG_ERR, "%s: invalid IAID", arg);
+ if ((s = parse_string((char *)iaid, len, arg)) < 1)
return -1;
- }
if (s < 4)
iaid[3] = '\0';
if (s < 3)
}
static char **
-splitv(int *argc, char **argv, const char *arg)
+splitv(struct dhcpcd_ctx *ctx, int *argc, char **argv, const char *arg)
{
char **n, **v = argv;
char *o = strdup(arg), *p, *t, *nt;
if (o == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return v;
}
p = o;
while ((t = strsep(&p, ", "))) {
nt = strdup(t);
if (nt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(o);
return v;
}
n = realloc(v, sizeof(char *) * ((size_t)(*argc) + 1));
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(o);
free(nt);
return v;
#ifdef INET
static int
-parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg)
+parse_addr(struct dhcpcd_ctx *ctx,
+ struct in_addr *addr, struct in_addr *net, const char *arg)
{
char *p;
int i;
(sscanf(p, "%d", &i) != 1 ||
inet_cidrtoaddr(i, net) != 0))
{
- syslog(LOG_ERR, "`%s' is not a valid CIDR", p);
+ logger(ctx, LOG_ERR, "`%s' is not a valid CIDR", p);
return -1;
}
}
if (addr != NULL && inet_aton(arg, addr) == 0) {
- syslog(LOG_ERR, "`%s' is not a valid IP address", arg);
+ logger(ctx, LOG_ERR, "`%s' is not a valid IP address", arg);
return -1;
}
if (p != NULL)
}
#else
static int
-parse_addr(__unused struct in_addr *addr, __unused struct in_addr *net,
+parse_addr(struct dhcpcd_ctx *ctx,
+ __unused struct in_addr *addr, __unused struct in_addr *net,
__unused const char *arg)
{
- syslog(LOG_ERR, "No IPv4 support");
+ logger(ctx, LOG_ERR, "No IPv4 support");
return -1;
}
#endif
free(ifo->script);
ifo->script = strdup(arg);
if (ifo->script == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
break;
case 'd':
ifo->options |= DHCPCD_DEBUG;
break;
case 'e':
- add_environ(ifo, arg, 1);
+ add_environ(ctx, ifo, arg, 1);
break;
case 'h':
if (!arg) {
}
s = parse_string(ifo->hostname, HOSTNAME_MAX_LEN, arg);
if (s == -1) {
- syslog(LOG_ERR, "hostname: %m");
+ logger(ctx, LOG_ERR, "hostname: %m");
return -1;
}
if (s != 0 && ifo->hostname[0] == '.') {
- syslog(LOG_ERR, "hostname cannot begin with .");
+ logger(ctx, LOG_ERR, "hostname cannot begin with .");
return -1;
}
ifo->hostname[s] = '\0';
else
s = 0;
if (s == -1) {
- syslog(LOG_ERR, "vendorclassid: %m");
+ logger(ctx, LOG_ERR, "vendorclassid: %m");
return -1;
}
*ifo->vendorclassid = (uint8_t)s;
break;
+ case 'j':
+ /* per interface logging is not supported
+ * don't want to overide the commandline */
+ if (ifname == NULL && ctx->logfile == NULL) {
+ logger_close(ctx);
+ ctx->logfile = strdup(arg);
+ logger_open(ctx);
+ }
+ break;
case 'k':
ifo->options |= DHCPCD_RELEASE;
break;
ifo->leasetime = (uint32_t)strtou(arg, NULL,
0, 0, UINT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert leasetime %s", arg);
+ logger(ctx, LOG_ERR, "failed to convert leasetime %s", arg);
return -1;
}
break;
case 'm':
ifo->metric = (int)strtoi(arg, NULL, 0, 0, INT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert metric %s", arg);
+ logger(ctx, LOG_ERR, "failed to convert metric %s", arg);
return -1;
}
break;
make_option_mask(d, dl, od, odl, no, arg, -1) != 0 ||
make_option_mask(d, dl, od, odl, reject, arg, -1) != 0)
{
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logger(ctx, LOG_ERR, "unknown option `%s'", arg);
return -1;
}
break;
make_option_mask(d, dl, od, odl, request, arg, -1) != 0 ||
make_option_mask(d, dl, od, odl, require, arg, -1) != 0)
{
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logger(ctx, LOG_ERR, "unknown option `%s'", arg);
return -1;
}
break;
ifo->options |= DHCPCD_QUIET;
break;
case 'r':
- if (parse_addr(&ifo->req_addr, NULL, arg) != 0)
+ if (parse_addr(ctx, &ifo->req_addr, NULL, arg) != 0)
return -1;
ifo->options |= DHCPCD_REQUEST;
ifo->req_mask.s_addr = 0;
break;
}
if (arg && *arg != '\0') {
- if (parse_addr(&ifo->req_addr, &ifo->req_mask,
- arg) != 0)
+ if (parse_addr(ctx,
+ &ifo->req_addr, &ifo->req_mask, arg) != 0)
return -1;
} else {
ifo->req_addr.s_addr = 0;
case 't':
ifo->timeout = (time_t)strtoi(arg, NULL, 0, 0, INT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert timeout");
+ logger(ctx, LOG_ERR, "failed to convert timeout");
return -1;
}
break;
s = parse_string((char *)ifo->userclass +
ifo->userclass[0] + 2, (size_t)s, arg);
if (s == -1) {
- syslog(LOG_ERR, "userclass: %m");
+ logger(ctx, LOG_ERR, "userclass: %m");
return -1;
}
if (s != 0) {
case 'v':
p = strchr(arg, ',');
if (!p || !p[1]) {
- syslog(LOG_ERR, "invalid vendor format: %s", arg);
+ logger(ctx, LOG_ERR, "invalid vendor format: %s", arg);
return -1;
}
s = parse_string((char *)ifo->vendor + 1,
VENDOR_MAX_LEN, arg);
if (s == -1) {
- syslog(LOG_ERR, "vendor: %m");
+ logger(ctx, LOG_ERR, "vendor: %m");
return -1;
}
ifo->vendor[0] = (uint8_t)s;
i = (int)strtoi(arg, NULL, 0, 1, 254, &e);
*p = ',';
if (e) {
- syslog(LOG_ERR, "vendor option should be between"
+ logger(ctx, LOG_ERR, "vendor option should be between"
" 1 and 254 inclusive");
return -1;
}
ifo->vendor[0] + 3, (size_t)s, arg);
}
if (s == -1) {
- syslog(LOG_ERR, "vendor: %m");
+ logger(ctx, LOG_ERR, "vendor: %m");
return -1;
}
if (s != 0) {
case 'y':
ifo->reboot = (time_t)strtoi(arg, NULL, 0, 0, UINT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert reboot %s", arg);
+ logger(ctx, LOG_ERR, "failed to convert reboot %s", arg);
return -1;
}
break;
case 'z':
if (ifname == NULL)
- ctx->ifav = splitv(&ctx->ifac, ctx->ifav, arg);
+ ctx->ifav = splitv(ctx, &ctx->ifac, ctx->ifav, arg);
break;
case 'A':
ifo->options &= ~DHCPCD_ARP;
dl = strlen("skip_hooks=") + strlen(arg) + 1;
p = malloc(sizeof(char) * dl);
if (p == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
snprintf(p, dl, "skip_hooks=%s", arg);
- add_environ(ifo, p, 0);
+ add_environ(ctx, ifo, p, 0);
free(p);
break;
case 'D':
else if (strcmp(arg, "disable") == 0)
ifo->fqdn = FQDN_DISABLE;
else {
- syslog(LOG_ERR, "invalid value `%s' for FQDN", arg);
+ logger(ctx, LOG_ERR, "invalid value `%s' for FQDN", arg);
return -1;
}
break;
else
s = 0;
if (s == -1) {
- syslog(LOG_ERR, "clientid: %m");
+ logger(ctx, LOG_ERR, "clientid: %m");
return -1;
}
ifo->options |= DHCPCD_CLIENTID;
make_option_mask(d, dl, od, odl, require, arg, -1) != 0 ||
make_option_mask(d, dl, od, odl, no, arg, 1) != 0)
{
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logger(ctx, LOG_ERR, "unknown option `%s'", arg);
return -1;
}
break;
make_option_mask(d, dl, od, odl, no, arg, -1) != 0 ||
make_option_mask(d, dl, od, odl, reject, arg, -1) != 0)
{
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logger(ctx, LOG_ERR, "unknown option `%s'", arg);
return -1;
}
break;
case 'S':
p = strchr(arg, '=');
if (p == NULL) {
- syslog(LOG_ERR, "static assignment required");
+ logger(ctx, LOG_ERR, "static assignment required");
return -1;
}
p++;
if (strncmp(arg, "ip_address=", strlen("ip_address=")) == 0) {
- if (parse_addr(&ifo->req_addr,
+ if (parse_addr(ctx, &ifo->req_addr,
ifo->req_mask.s_addr == 0 ? &ifo->req_mask : NULL,
p) != 0)
return -1;
ifo->options |= DHCPCD_STATIC;
ifo->options &= ~DHCPCD_INFORM;
- } else if (strncmp(arg, "subnet_mask=", strlen("subnet_mask=")) == 0) {
- if (parse_addr(&ifo->req_mask, NULL, p) != 0)
+ } else if (strncmp(arg, "subnet_mask=",
+ strlen("subnet_mask=")) == 0)
+ {
+ if (parse_addr(ctx, &ifo->req_mask, NULL, p) != 0)
return -1;
} else if (strncmp(arg, "routes=", strlen("routes=")) == 0 ||
- strncmp(arg, "static_routes=", strlen("static_routes=")) == 0 ||
- strncmp(arg, "classless_static_routes=", strlen("classless_static_routes=")) == 0 ||
- strncmp(arg, "ms_classless_static_routes=", strlen("ms_classless_static_routes=")) == 0)
+ strncmp(arg, "static_routes=",
+ strlen("static_routes=")) == 0 ||
+ strncmp(arg, "classless_static_routes=",
+ strlen("classless_static_routes=")) == 0 ||
+ strncmp(arg, "ms_classless_static_routes=",
+ strlen("ms_classless_static_routes=")) == 0)
{
fp = np = strwhite(p);
if (np == NULL) {
- syslog(LOG_ERR, "all routes need a gateway");
+ logger(ctx, LOG_ERR,
+ "all routes need a gateway");
return -1;
}
*np++ = '\0';
if (ifo->routes == NULL) {
ifo->routes = malloc(sizeof(*ifo->routes));
if (ifo->routes == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR,
+ "%s: %m", __func__);
return -1;
}
TAILQ_INIT(ifo->routes);
}
rt = malloc(sizeof(*rt));
if (rt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
*fp = ' ';
return -1;
}
- if (parse_addr(&rt->dest, &rt->net, p) == -1 ||
- parse_addr(&rt->gate, NULL, np) == -1)
+ if (parse_addr(ctx, &rt->dest, &rt->net, p) == -1 ||
+ parse_addr(ctx, &rt->gate, NULL, np) == -1)
{
free(rt);
*fp = ' ';
if (ifo->routes == NULL) {
ifo->routes = malloc(sizeof(*ifo->routes));
if (ifo->routes == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR,
+ "%s: %m", __func__);
return -1;
}
TAILQ_INIT(ifo->routes);
}
rt = malloc(sizeof(*rt));
if (rt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
rt->dest.s_addr = INADDR_ANY;
rt->net.s_addr = INADDR_ANY;
- if (parse_addr(&rt->gate, NULL, p) == -1) {
+ if (parse_addr(ctx, &rt->gate, NULL, p) == -1) {
free(rt);
return -1;
}
{
p = strdup(arg);
if (p == NULL) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"%s: %m", __func__);
return -1;
}
}
p = strdup(arg);
if (p == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
nconf = realloc(ifo->config, sizeof(char *) * (dl + 2));
if (nconf == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->config = nconf;
}
break;
case 'W':
- if (parse_addr(&addr, &addr2, arg) != 0)
+ if (parse_addr(ctx, &addr, &addr2, arg) != 0)
return -1;
if (strchr(arg, '/') == NULL)
addr2.s_addr = INADDR_BROADCAST;
naddr = realloc(ifo->whitelist,
sizeof(in_addr_t) * (ifo->whitelist_len + 2));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->whitelist = naddr;
ifo->whitelist[ifo->whitelist_len++] = addr2.s_addr;
break;
case 'X':
- if (parse_addr(&addr, &addr2, arg) != 0)
+ if (parse_addr(ctx, &addr, &addr2, arg) != 0)
return -1;
if (strchr(arg, '/') == NULL)
addr2.s_addr = INADDR_BROADCAST;
naddr = realloc(ifo->blacklist,
sizeof(in_addr_t) * (ifo->blacklist_len + 2));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->blacklist = naddr;
break;
case 'Z':
if (ifname == NULL)
- ctx->ifdv = splitv(&ctx->ifdc, ctx->ifdv, arg);
+ ctx->ifdv = splitv(ctx, &ctx->ifdc, ctx->ifdv, arg);
break;
case '4':
ifo->options &= ~DHCPCD_IPV6;
fp = strwhite(arg);
if (fp)
*fp++ = '\0';
- if (parse_addr(&addr, NULL, arg) != 0)
+ if (parse_addr(ctx, &addr, NULL, arg) != 0)
return -1;
naddr = realloc(ifo->arping,
sizeof(in_addr_t) * (ifo->arping_len + 1));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->arping = naddr;
ifo->dstmask, arg, 2) != 0)
{
if (errno == EINVAL)
- syslog(LOG_ERR, "option `%s' does not take"
+ logger(ctx, LOG_ERR, "option `%s' does not take"
" an IPv4 address", arg);
else
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logger(ctx, LOG_ERR, "unknown option `%s'", arg);
return -1;
}
break;
free(ifo->fallback);
ifo->fallback = strdup(arg);
if (ifo->fallback == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
break;
#endif
case O_IAID:
if (ifname == NULL) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"IAID must belong in an interface block");
return -1;
}
- if (parse_iaid(ifo->iaid, arg, sizeof(ifo->iaid)) == -1)
+ if (parse_iaid(ifo->iaid, arg, sizeof(ifo->iaid)) == -1) {
+ logger(ctx, LOG_ERR, "invalid IAID %s", arg);
return -1;
+ }
ifo->options |= DHCPCD_IAID;
break;
case O_IPV6RS:
case O_IA_PD:
if (i == 0) {
if (ifname == NULL) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"IA PD must belong in an interface block");
return -1;
}
i = D6_OPTION_IA_PD;
}
if (ifname == NULL && arg) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"IA with IAID must belong in an interface block");
return -1;
}
p = strchr(arg, '/');
if (p)
*p++ = '\0';
- if (parse_iaid(iaid, arg, sizeof(iaid)) == -1)
+ if (parse_iaid(iaid, arg, sizeof(iaid)) == -1) {
+ logger(ctx, LOG_ERR, "invalid IAID: %s", arg);
return -1;
+ }
}
ia = NULL;
for (sl = 0; sl < ifo->ia_len; sl++) {
}
}
if (ia && ia->ia_type != (uint16_t)i) {
- syslog(LOG_ERR, "Cannot mix IA for the same IAID");
+ logger(ctx, LOG_ERR, "Cannot mix IA for the same IAID");
break;
}
if (ia == NULL) {
ia = realloc(ifo->ia,
sizeof(*ifo->ia) * (ifo->ia_len + 1));
if (ia == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->ia = ia;
if (p)
*p++ = '\0';
if (inet_pton(AF_INET6, arg, &ia->addr) == -1) {
- syslog(LOG_ERR, "%s: %m", arg);
+ logger(ctx, LOG_ERR, "%s: %m", arg);
memset(&ia->addr, 0, sizeof(ia->addr));
}
if (p && ia->ia_type == D6_OPTION_IA_PD) {
i = (int)strtoi(p, NULL, 0, 8, 120, &e);
if (e) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"%s: failed to convert"
" prefix len",
p);
sla = realloc(ia->sla,
sizeof(*ia->sla) * (ia->sla_len + 1));
if (sla == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ia->sla = sla;
if (strlcpy(sla->ifname, p,
sizeof(sla->ifname)) >= sizeof(sla->ifname))
{
- syslog(LOG_ERR, "%s: interface name too long",
+ logger(ctx, LOG_ERR, "%s: interface name too long",
arg);
goto err_sla;
}
0, 0, UINT32_MAX, &e);
sla->sla_set = 1;
if (e) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"%s: failed to convert sla",
ifname);
goto err_sla;
sla->prefix_len = (uint8_t)strtoi(np,
NULL, 0, 0, 128, &e);
if (e) {
- syslog(LOG_ERR, "%s: failed to "
+ logger(ctx, LOG_ERR, "%s: failed to "
"convert prefix len",
ifname);
goto err_sla;
for (sl = 0; sl < ia->sla_len - 1; sl++) {
slap = &ia->sla[sl];
if (slap->sla_set != sla->sla_set) {
- syslog(LOG_WARNING,
+ logger(ctx, LOG_WARNING,
"%s: cannot mix automatic "
"and fixed SLA",
sla->ifname);
if (sla->sla_set == 0 &&
strcmp(slap->ifname, sla->ifname) == 0)
{
- syslog(LOG_WARNING,
+ logger(ctx, LOG_WARNING,
"%s: cannot specify the "
"same interface twice with "
"an automatic SLA",
goto err_sla;
}
if (slap->sla == 0 || sla->sla == 0) {
- syslog(LOG_ERR, "%s: cannot"
+ logger(ctx, LOG_ERR, "%s: cannot"
" assign multiple prefixes"
" with a SLA of 0",
ifname);
dop = &(*ldop)->embopts;
dop_len = &(*ldop)->embopts_len;
} else {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"embed must be after a define or encap");
return -1;
}
case O_ENCAP:
if (dop == NULL) {
if (*ldop == NULL) {
- syslog(LOG_ERR, "encap must be after a define");
+ logger(ctx, LOG_ERR, "encap must be after a define");
return -1;
}
dop = &(*ldop)->encopts;
else {
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "invalid syntax: %s", arg);
+ logger(ctx, LOG_ERR, "invalid syntax: %s", arg);
return -1;
}
*fp++ = '\0';
u = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "invalid code: %s", arg);
+ logger(ctx, LOG_ERR, "invalid code: %s", arg);
return -1;
}
arg = strskipwhite(fp);
if (arg == NULL) {
- syslog(LOG_ERR, "invalid syntax");
+ logger(ctx, LOG_ERR, "invalid syntax");
return -1;
}
}
*np++ = '\0';
l = (long)strtou(np, NULL, 0, 0, LONG_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert length");
+ logger(ctx, LOG_ERR, "failed to convert length");
return -1;
}
} else
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete request type");
+ logger(ctx, LOG_ERR, "incomplete request type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete request type");
+ logger(ctx, LOG_ERR, "incomplete request type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete index type");
+ logger(ctx, LOG_ERR, "incomplete index type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete array type");
+ logger(ctx, LOG_ERR, "incomplete array type");
return -1;
}
*fp++ = '\0';
else if (strcasecmp(arg, "option") == 0)
t |= OPTION;
else {
- syslog(LOG_ERR, "unknown type: %s", arg);
+ logger(ctx, LOG_ERR, "unknown type: %s", arg);
return -1;
}
if (l && !(t & (STRING | BINHEX))) {
- syslog(LOG_WARNING,
+ logger(ctx, LOG_WARNING,
"ignoring length for type `%s'", arg);
l = 0;
}
if (t & ARRAY && t & (STRING | BINHEX) &&
!(t & (RFC3397 | DOMAIN)))
{
- syslog(LOG_WARNING, "ignoring array for strings");
+ logger(ctx, LOG_WARNING, "ignoring array for strings");
t &= ~ARRAY;
}
/* variable */
if (!fp) {
if (!(t & OPTION)) {
- syslog(LOG_ERR,
+ logger(ctx, LOG_ERR,
"type %s requires a variable name", arg);
return -1;
}
*fp++ = '\0';
np = strdup(arg);
if (np == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
}
if ((ndop = realloc(*dop,
sizeof(**dop) * ((*dop_len) + 1))) == NULL)
{
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(np);
return -1;
}
*fp++ = '\0';
u = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "invalid code: %s", arg);
+ logger(ctx, LOG_ERR, "invalid code: %s", arg);
return -1;
}
if (fp) {
s = parse_string(NULL, 0, fp);
if (s == -1) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
dl = (size_t)s;
if (dl + (sizeof(uint16_t) * 2) > UINT16_MAX) {
- syslog(LOG_ERR, "vendor class is too big");
+ logger(ctx, LOG_ERR, "vendor class is too big");
return -1;
}
np = malloc(dl);
if (np == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
parse_string(np, dl, fp);
vivco = realloc(ifo->vivco, sizeof(*ifo->vivco) *
(ifo->vivco_len + 1));
if (vivco == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->vivco = vivco;
else if (strcasecmp(arg, "delayedrealm") == 0)
ifo->auth.protocol = AUTH_PROTO_DELAYEDREALM;
else {
- syslog(LOG_ERR, "%s: unsupported protocol", arg);
+ logger(ctx, LOG_ERR, "%s: unsupported protocol", arg);
return -1;
}
arg = strskipwhite(fp);
strcasecmp(arg, "hmac-md5") == 0)
ifo->auth.algorithm = AUTH_ALG_HMAC_MD5;
else {
- syslog(LOG_ERR, "%s: unsupported algorithm", arg);
+ logger(ctx, LOG_ERR, "%s: unsupported algorithm", arg);
return 1;
}
arg = fp;
strcasecmp(arg, "monotime") == 0)
ifo->auth.rdm = AUTH_RDM_MONOTONIC;
else {
- syslog(LOG_ERR, "%s: unsupported RDM", arg);
+ logger(ctx, LOG_ERR, "%s: unsupported RDM", arg);
return -1;
}
ifo->auth.options |= DHCPCD_AUTH_SEND;
case O_AUTHTOKEN:
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "authtoken requires a realm");
+ logger(ctx, LOG_ERR, "authtoken requires a realm");
return -1;
}
*fp++ = '\0';
token = malloc(sizeof(*token));
if (token == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(token);
return -1;
}
if (parse_uint32(&token->secretid, arg) == -1) {
- syslog(LOG_ERR, "%s: not a number", arg);
+ logger(ctx, LOG_ERR, "%s: not a number", arg);
free(token);
return -1;
}
arg = fp;
fp = strend(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "authtoken requies an a key");
+ logger(ctx, LOG_ERR, "authtoken requies an a key");
free(token);
return -1;
}
*fp++ = '\0';
s = parse_string(NULL, 0, arg);
if (s == -1) {
- syslog(LOG_ERR, "realm_len: %m");
+ logger(ctx, LOG_ERR, "realm_len: %m");
free(token);
return -1;
}
token->realm = malloc(token->realm_len);
if (token->realm == NULL) {
free(token);
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
parse_string((char *)token->realm, token->realm_len,
arg = fp;
fp = strend(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "authtoken requies an an expiry date");
+ logger(ctx, LOG_ERR, "authtoken requies an an expiry date");
free(token->realm);
free(token);
return -1;
memset(&tm, 0, sizeof(tm));
if (strptime(arg, "%Y-%m-%d %H:%M", &tm) == NULL) {
- syslog(LOG_ERR, "%s: invalid date time", arg);
+ logger(ctx, LOG_ERR, "%s: invalid date time", arg);
free(token->realm);
free(token);
return -1;
}
if ((token->expire = mktime(&tm)) == (time_t)-1) {
- syslog(LOG_ERR, "%s: mktime: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: mktime: %m", __func__);
free(token->realm);
free(token);
return -1;
arg = fp;
s = parse_string(NULL, 0, arg);
if (s == -1 || s == 0) {
- syslog(LOG_ERR, s == -1 ? "token_len: %m" :
+ logger(ctx, LOG_ERR, s == -1 ? "token_len: %m" :
"authtoken needs a key");
free(token->realm);
free(token);
dl = (size_t)l;
p = malloc(dl);
if (p == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: malloc: %m", __func__);
return -1;
}
while ((i = getgrnam_r(arg, &grpbuf, p, (size_t)l, &grp)) ==
{
size_t nl = dl * 2;
if (nl < dl) {
- syslog(LOG_ERR, "control_group: out of buffer");
+ logger(ctx, LOG_ERR, "control_group: out of buffer");
free(p);
return -1;
}
dl = nl;
np = realloc(p, dl);
if (np == NULL) {
- syslog(LOG_ERR, "control_group: realloc: %m");
+ logger(ctx, LOG_ERR, "control_group: realloc: %m");
free(p);
return -1;
}
}
if (i != 0) {
errno = i;
- syslog(LOG_ERR, "getgrnam_r: %m");
+ logger(ctx, LOG_ERR, "getgrnam_r: %m");
free(p);
return -1;
}
if (grp == NULL) {
- syslog(LOG_ERR, "controlgroup: %s: not found", arg);
+ logger(ctx, LOG_ERR, "controlgroup: %s: not found", arg);
free(p);
return -1;
}
#else
grp = getgrnam(arg);
if (grp == NULL) {
- syslog(LOG_ERR, "controlgroup: %s: not found", arg);
+ logger(ctx, LOG_ERR, "controlgroup: %s: not found", arg);
return -1;
}
ctx->control_group = grp->gr_gid;
ldop, edop);
}
- syslog(LOG_ERR, "unknown option: %s", opt);
+ logger(ctx, LOG_ERR, "unknown option: %s", opt);
return -1;
}
/* Seed our default options */
ifo = calloc(1, sizeof(*ifo));
if (ifo == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
ifo->options |= DHCPCD_DAEMONISE | DHCPCD_LINK;
ifo->dhcp_override =
calloc(INITDEFINES, sizeof(*ifo->dhcp_override));
if (ifo->dhcp_override == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
else
ifo->dhcp_override_len = INITDEFINES;
#endif
ifo->dhcp6_override =
calloc(INITDEFINE6S, sizeof(*ifo->dhcp6_override));
if (ifo->dhcp6_override == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
else
ifo->dhcp6_override_len = INITDEFINE6S;
#endif
#ifdef EMBEDDED_CONFIG
fp = fopen(EMBEDDED_CONFIG, "r");
if (fp == NULL)
- syslog(LOG_ERR, "fopen `%s': %m", EMBEDDED_CONFIG);
+ logger(ctx, LOG_ERR, "fopen `%s': %m", EMBEDDED_CONFIG);
while (fp && (line = get_line(&buf, &buflen, fp))) {
#else
buflen = 80;
buf = malloc(buflen);
if (buf == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
ldop = edop = NULL;
buflen = ol;
buf = realloc(buf, buflen);
if (buf == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(buf);
return NULL;
}
fp = fopen(ctx->cffile, "r");
if (fp == NULL) {
if (strcmp(ctx->cffile, CONFIG))
- syslog(LOG_ERR, "fopen `%s': %m", ctx->cffile);
+ logger(ctx, LOG_ERR, "fopen `%s': %m", ctx->cffile);
free(buf);
return ifo;
}
n = realloc(ctx->ifcv,
sizeof(char *) * ((size_t)ctx->ifcc + 1));
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
continue;
}
ctx->ifcv = n;
ctx->ifcv[ctx->ifcc] = strdup(line);
if (ctx->ifcv[ctx->ifcc] == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
continue;
}
ctx->ifcc++;
- syslog(LOG_DEBUG, "allowing interface %s",
+ logger(ctx, LOG_DEBUG, "allowing interface %s",
ctx->ifcv[ctx->ifcc - 1]);
continue;
}
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
-#define IF_OPTS "46bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLMO:Q:S:TUVW:X:Z:"
+#define IF_OPTS "46bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
+ "ABC:DEF:GHI:JKLMO:Q:S:TUVW:X:Z:"
#define DEFAULT_TIMEOUT 30
#define DEFAULT_REBOOT 5
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
}
if (if_vimaster(p) == 1) {
- syslog(argc ? LOG_ERR : LOG_DEBUG,
+ logger(ctx, argc ? LOG_ERR : LOG_DEBUG,
"%s: is a Virtual Interface Master, skipping", p);
continue;
}
ifp = calloc(1, sizeof(*ifp));
if (ifp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
break;
}
ifp->ctx = ctx;
ctx->ifac == 0 &&
!if_hasconf(ctx, ifp->name))
{
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: ignoring due to"
" interface type and"
" no config",
if_free(ifp);
continue;
}
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: unsupported interface type %.2x",
ifp->name, sdl->sdl_type);
/* Pretend it's ethernet */
/* IFT already checked */
#ifndef AF_LINK
default:
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: unsupported interface family %.2x",
ifp->name, ifp->family);
break;
/* Handle any platform init for the interface */
if (if_init(ifp) == -1) {
- syslog(LOG_ERR, "%s: if_init: %m", p);
+ logger(ifp->ctx, LOG_ERR, "%s: if_init: %m", p);
if_free(ifp);
continue;
}
if (if_getmtu(ifp->name) < MTU_MIN &&
if_setmtu(ifp->name, MTU_MIN) == -1)
{
- syslog(LOG_ERR, "%s: set_mtu: %m", p);
+ logger(ifp->ctx, LOG_ERR, "%s: set_mtu: %m", p);
if_free(ifp);
continue;
}
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
desc_route(const char *cmd, const struct rt *rt)
{
char addr[sizeof("000.000.000.000") + 1];
- const char *ifname = rt->iface->name;
+ struct dhcpcd_ctx *ctx = rt->iface ? rt->iface->ctx : NULL;
+ const char *ifname = rt->iface ? rt->iface->name : NULL;
strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr));
if (rt->gate.s_addr == INADDR_ANY)
- syslog(LOG_INFO, "%s: %s route to %s/%d", ifname, cmd,
- addr, inet_ntocidr(rt->net));
+ logger(ctx, LOG_INFO, "%s: %s route to %s/%d",
+ ifname, cmd, addr, inet_ntocidr(rt->net));
else if (rt->gate.s_addr == rt->dest.s_addr &&
rt->net.s_addr == INADDR_BROADCAST)
- syslog(LOG_INFO, "%s: %s host route to %s", ifname, cmd,
- addr);
+ logger(ctx, LOG_INFO, "%s: %s host route to %s",
+ ifname, cmd, addr);
else if (rt->gate.s_addr == htonl(INADDR_LOOPBACK) &&
rt->net.s_addr == INADDR_BROADCAST)
- syslog(LOG_INFO, "%s: %s host route to %s via %s", ifname, cmd,
- addr, inet_ntoa(rt->gate));
+ logger(ctx, LOG_INFO, "%s: %s host route to %s via %s",
+ ifname, cmd, addr, inet_ntoa(rt->gate));
else if (rt->dest.s_addr == INADDR_ANY && rt->net.s_addr == INADDR_ANY)
- syslog(LOG_INFO, "%s: %s default route via %s", ifname, cmd,
- inet_ntoa(rt->gate));
+ logger(ctx, LOG_INFO, "%s: %s default route via %s",
+ ifname, cmd, inet_ntoa(rt->gate));
else
- syslog(LOG_INFO, "%s: %s route to %s/%d via %s", ifname, cmd,
- addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate));
+ logger(ctx, LOG_INFO, "%s: %s route to %s/%d via %s",
+ ifname, cmd, addr, inet_ntocidr(rt->net),
+ inet_ntoa(rt->gate));
}
static struct rt *
/* With route metrics, we can safely add the new route before
* deleting the old route. */
if ((retval = if_route(RTM_ADD, nrt)) == -1)
- syslog(LOG_ERR, "if_route (ADD): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m");
if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "if_route (DEL): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
return retval;
#else
/* No route metrics, we need to delete the old route before
* adding the new one. */
if (ort && if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "if_route (DEL): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route (DEL): %m");
if (if_route(RTM_ADD, nrt) == 0)
return 0;
- syslog(LOG_ERR, "if_route (ADD): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route (ADD): %m");
return -1;
#endif
}
desc_route("deleting", rt);
retval = if_route(RTM_DELETE, rt);
if (retval != 0 && errno != ENOENT && errno != ESRCH)
- syslog(LOG_ERR,"%s: if_delroute: %m", rt->iface->name);
+ logger(rt->iface->ctx, LOG_ERR,
+ "%s: if_delroute: %m", rt->iface->name);
return retval;
}
r = malloc(sizeof(*r));
if (r == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
r->dest.s_addr = s->addr.s_addr & s->net.s_addr;
r = malloc(sizeof(*r));
if (r == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(rt);
return NULL;
}
break;
r = malloc(sizeof(*r));
if (r == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(nrt);
return NULL;
}
}
static struct rt_head *
-add_destination_route(struct rt_head *rt, const struct interface *iface)
+add_destination_route(struct rt_head *rt, const struct interface *ifp)
{
struct rt *r;
if (rt == NULL || /* failed a malloc earlier probably */
- !(iface->flags & IFF_POINTOPOINT) ||
- !has_option_mask(iface->options->dstmask, DHO_ROUTER))
+ !(ifp->flags & IFF_POINTOPOINT) ||
+ !has_option_mask(ifp->options->dstmask, DHO_ROUTER))
return rt;
r = malloc(sizeof(*r));
if (r == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(rt);
return NULL;
}
r->dest.s_addr = INADDR_ANY;
r->net.s_addr = INADDR_ANY;
- r->gate.s_addr = D_CSTATE(iface)->dst.s_addr;
+ r->gate.s_addr = D_CSTATE(ifp)->dst.s_addr;
TAILQ_INSERT_HEAD(rt, r, next);
return rt;
}
!(state->added & STATE_FAKE))
{
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: forcing router %s through interface",
ifp->name, inet_ntoa(rtp->gate));
}
!(state->added & STATE_FAKE))
{
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: router %s requires a host route",
ifp->name, inet_ntoa(rtp->gate));
}
rtn = malloc(sizeof(*rtn));
if (rtn == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
ipv4_freeroutes(rt);
return NULL;
}
nrs = malloc(sizeof(*nrs));
if (nrs == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return;
}
TAILQ_INIT(nrs);
struct ipv4_state *state;
struct ipv4_addr *ap;
- syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
+ logger(ifp->ctx, LOG_DEBUG, "%s: deleting IP address %s/%d",
ifp->name, inet_ntoa(*addr), inet_ntocidr(*net));
r = if_deladdress(ifp, addr, net);
if (r == -1 && errno != EADDRNOTAVAIL && errno != ENXIO &&
errno != ENODEV)
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m", ifp->name, __func__);
state = IPV4_STATE(ifp);
TAILQ_FOREACH(ap, &state->addrs, next) {
ifp->if_data[IF_DATA_IPV4] = malloc(sizeof(*state));
state = IPV4_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
TAILQ_INIT(&state->addrs);
}
}
- syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
+ logger(ifp->ctx, LOG_DEBUG, "%s: adding IP address %s/%d",
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->net));
r = if_addaddress(ifp, &lease->addr, &lease->net, &lease->brd);
if (r == -1 && errno != EEXIST)
- syslog(LOG_ERR, "%s: if_addaddress: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: if_addaddress: %m", __func__);
return r;
}
nstate->addr.s_addr == lease->addr.s_addr)
{
if (ifn->metric <= ifp->metric) {
- syslog(LOG_INFO, "%s: preferring %s on %s",
+ logger(ifp->ctx, LOG_INFO,
+ "%s: preferring %s on %s",
ifp->name,
inet_ntoa(lease->addr),
ifn->name);
state->net.s_addr = lease->net.s_addr;
goto routes;
}
- syslog(LOG_INFO, "%s: preferring %s on %s",
+ logger(ifp->ctx, LOG_INFO, "%s: preferring %s on %s",
ifn->name,
inet_ntoa(lease->addr),
ifp->name);
delete_address1(ifp, &ap->addr, &ap->net);
if (ipv4_iffindaddr(ifp, &lease->addr, &lease->net))
- syslog(LOG_DEBUG, "%s: IP address %s/%d already exists",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: IP address %s/%d already exists",
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->net));
else {
if (type == RTM_NEWADDR && ap == NULL) {
ap = malloc(sizeof(*ap));
if (ap == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
ap->iface = ifp;
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 6
offer = state->offer;
state->offer = ipv4ll_make_lease(astate->addr.s_addr);
if (state->offer == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(astate->iface->ctx, LOG_ERR, "%s: %m", __func__);
else
dhcp_bind(astate->iface, astate);
state->offer = offer;
/* RFC 3927 Section 2.5 */
up = uptime();
if (state->defend + DEFEND_INTERVAL > up) {
- syslog(LOG_WARNING,
+ logger(astate->iface->ctx, LOG_WARNING,
"%s: IPv4LL %d second defence failed for %s",
astate->iface->name, DEFEND_INTERVAL,
inet_ntoa(state->addr));
dhcp_drop(astate->iface, "EXPIRE");
} else {
- syslog(LOG_DEBUG, "%s: defended IPv4LL address %s",
+ logger(astate->iface->ctx, LOG_DEBUG,
+ "%s: defended IPv4LL address %s",
astate->iface->name, inet_ntoa(state->addr));
state->defend = up;
return;
arp_cancel(astate);
if (++state->conflicts == MAX_CONFLICTS)
- syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
+ logger(astate->iface->ctx, LOG_ERR,
+ "%s: failed to acquire an IPv4LL address",
astate->iface->name);
astate->addr.s_addr = ipv4ll_pick_addr(astate);
eloop_timeout_add_sec(astate->iface->ctx->eloop,
setstate(state->randomstate);
/* We maybe rebooting an IPv4LL address. */
if (!IN_LINKLOCAL(htonl(astate->addr.s_addr))) {
- syslog(LOG_INFO, "%s: probing for an IPv4LL address",
+ logger(ifp->ctx, LOG_INFO, "%s: probing for an IPv4LL address",
ifp->name);
astate->addr.s_addr = INADDR_ANY;
}
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 7
return (ssize_t)len;
} else {
if (errno != ENOENT)
- syslog(LOG_ERR, "error reading secret: %s: %m", SECRET);
+ logger(ctx, LOG_ERR,
+ "error reading secret: %s: %m", SECRET);
}
/* Chaining arc4random should be good enough.
return (ssize_t)ctx->secret_len;
eexit:
- syslog(LOG_ERR, "error writing secret: %s: %m", SECRET);
+ logger(ctx, LOG_ERR, "error writing secret: %s: %m", SECRET);
unlink(SECRET);
ctx->secret_len = 0;
return -1;
ap = arg;
ifa_flags = if_addrflags6(&ap->addr, ap->iface);
if (ifa_flags == -1)
- syslog(LOG_ERR, "%s: if_addrflags6: %m", ap->iface->name);
+ logger(ap->iface->ctx, LOG_ERR,
+ "%s: if_addrflags6: %m", ap->iface->name);
else if (!(ifa_flags & IN6_IFF_TENTATIVE)) {
ipv6_handleifa(ap->iface->ctx, RTM_NEWADDR,
ap->iface->ctx->ifaces, ap->iface->name,
static void
-ipv6_deleteaddr(struct ipv6_addr *addr)
+ipv6_deleteaddr(struct ipv6_addr *ia)
{
struct ipv6_state *state;
struct ipv6_addr *ap;
- syslog(LOG_INFO, "%s: deleting address %s",
- addr->iface->name, addr->saddr);
- if (if_deladdress6(addr) == -1 &&
+ logger(ia->iface->ctx, LOG_INFO, "%s: deleting address %s",
+ ia->iface->name, ia->saddr);
+ if (if_deladdress6(ia) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO && errno != ENODEV)
- syslog(LOG_ERR, "if_deladdress6: :%m");
+ logger(ia->iface->ctx, LOG_ERR, "if_deladdress6: :%m");
- state = IPV6_STATE(addr->iface);
+ state = IPV6_STATE(ia->iface);
TAILQ_FOREACH(ap, &state->addrs, next) {
- if (IN6_ARE_ADDR_EQUAL(&ap->addr, &addr->addr)) {
+ if (IN6_ARE_ADDR_EQUAL(&ap->addr, &ia->addr)) {
TAILQ_REMOVE(&state->addrs, ap, next);
ipv6_freeaddr(ap);
break;
ipv6_iffindaddr(ap->iface, &ap->addr))
ap->flags |= IPV6_AF_DADCOMPLETED;
- syslog(ap->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG,
+ logger(ap->iface->ctx, ap->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG,
"%s: adding address %s", ap->iface->name, ap->saddr);
if (ap->prefix_pltime == ND6_INFINITE_LIFETIME &&
ap->prefix_vltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: pltime infinity, vltime infinity",
ap->iface->name);
else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: pltime infinity, vltime %"PRIu32" seconds",
ap->iface->name, ap->prefix_vltime);
else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: pltime %"PRIu32"seconds, vltime infinity",
ap->iface->name, ap->prefix_pltime);
else
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: pltime %"PRIu32" seconds, vltime %"PRIu32" seconds",
ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
}
if (if_addaddress6(ap) == -1) {
- syslog(LOG_ERR, "if_addaddress6: %m");
+ logger(ap->iface->ctx, LOG_ERR, "if_addaddress6: %m");
#if 0
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: adj pltime %"PRIu32" seconds, "
"vltime %"PRIu32" seconds",
ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
strcmp(apf->iface->name, ap->iface->name))
{
if (apf->iface->metric <= ap->iface->metric) {
- syslog(LOG_INFO,
+ logger(apf->iface->ctx, LOG_INFO,
"%s: preferring %s on %s",
ap->iface->name,
ap->saddr,
apf->iface->name);
continue;
}
- syslog(LOG_INFO,
+ logger(apf->iface->ctx, LOG_INFO,
"%s: preferring %s on %s",
apf->iface->name,
ap->saddr,
ap->iface->name);
if (if_deladdress6(apf) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "if_deladdress6: %m");
+ logger(apf->iface->ctx, LOG_ERR,
+ "if_deladdress6: %m");
apf->flags &=
~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
} else if (apf)
ifp->if_data[IF_DATA_IPV6] = calloc(1, sizeof(*state));
state = IPV6_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
TAILQ_INIT(&state->addrs);
char buf[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &addr->s6_addr,
buf, INET6_ADDRSTRLEN);
- syslog(LOG_DEBUG, "%s: cmd %d addr %s flags %d",
+ logger(ctx, LOG_DEBUG, "%s: cmd %d addr %s flags %d",
ifname, cmd, buf, flags);
#endif
if (cb == NULL) {
cb = malloc(sizeof(*cb));
if (cb == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return -1;
}
cb->callback = callback;
return -1;
}
- syslog(LOG_WARNING, "%s: waiting for %s to complete",
+ logger(ap2->iface->ctx, LOG_WARNING,
+ "%s: waiting for %s to complete",
ap2->iface->name, ap2->saddr);
free(ap);
errno = EEXIST;
switch (cmd) {
case RTM_DELADDR:
if (ap->flags & IPV6_AF_ADDED) {
- syslog(LOG_INFO, "%s: deleted address %s",
+ logger(ap->iface->ctx, LOG_INFO,
+ "%s: deleted address %s",
ap->iface->name, ap->saddr);
ap->flags &= ~IPV6_AF_ADDED;
}
struct timespec tv;
if (++ia->dadcounter == TEMP_IDGEN_RETRIES) {
- syslog(LOG_ERR,
+ logger(ia->iface->ctx, LOG_ERR,
"%s: too many duplicate temporary addresses",
ia->iface->name);
return;
}
get_monotonic(&tv);
if ((ia1 = ipv6_createtempaddr(ia, &tv)) == NULL)
- syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+ logger(ia->iface->ctx, LOG_ERR,
+ "ipv6_createtempaddr: %m");
else
ia1->dadcounter = ia->dadcounter;
ipv6_deleteaddr(ia);
struct ipv6_addr *ia = arg, *ia1;
struct timespec tv;
- syslog(LOG_DEBUG, "%s: regen temp addr %s",
+ logger(ia->iface->ctx, LOG_DEBUG, "%s: regen temp addr %s",
ia->iface->name, ia->saddr);
get_monotonic(&tv);
ia1 = ipv6_createtempaddr(ia, &tv);
if (ia1)
ipv6_addaddr(ia1, &tv);
else
- syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+ logger(ia->iface->ctx, LOG_ERR, "ipv6_createtempaddr: %m");
}
static void
char destbuf[INET6_ADDRSTRLEN];
char gatebuf[INET6_ADDRSTRLEN];
const char *ifname, *dest, *gate;
+ struct dhcpcd_ctx *ctx;
+ ctx = rt->iface ? rt->iface->ctx : NULL;
ifname = rt->iface ? rt->iface->name : "(no iface)";
dest = inet_ntop(AF_INET6, &rt->dest, destbuf, INET6_ADDRSTRLEN);
gate = inet_ntop(AF_INET6, &rt->gate, gatebuf, INET6_ADDRSTRLEN);
if (IN6_ARE_ADDR_EQUAL(&rt->gate, &in6addr_any))
- syslog(LOG_INFO, "%s: %s route to %s/%d", ifname, cmd,
- dest, ipv6_prefixlen(&rt->net));
+ logger(ctx, LOG_INFO, "%s: %s route to %s/%d",
+ ifname, cmd, dest, ipv6_prefixlen(&rt->net));
else if (IN6_ARE_ADDR_EQUAL(&rt->dest, &in6addr_any) &&
IN6_ARE_ADDR_EQUAL(&rt->net, &in6addr_any))
- syslog(LOG_INFO, "%s: %s default route via %s", ifname, cmd,
- gate);
+ logger(ctx, LOG_INFO, "%s: %s default route via %s",
+ ifname, cmd, gate);
else
- syslog(LOG_INFO, "%s: %s%s route to %s/%d via %s", ifname, cmd,
+ logger(ctx, LOG_INFO, "%s: %s%s route to %s/%d via %s",
+ ifname, cmd,
rt->flags & RTF_REJECT ? " reject" : "",
dest, ipv6_prefixlen(&rt->net), gate);
}
/* With route metrics, we can safely add the new route before
* deleting the old route. */
if ((retval = if_route6(RTM_ADD, nrt)) == -1)
- syslog(LOG_ERR, "if_route6 (ADD): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m");
if (ort && if_route6(RTM_DELETE, ort) == -1 &&
errno != ESRCH)
- syslog(LOG_ERR, "if_route6 (DEL): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route6 (DEL): %m");
return retval;
#else
/* No route metrics, we need to delete the old route before
* adding the new one. */
if (ort && if_route6(RTM_DELETE, ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "if_route6: %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route6: %m");
if (if_route6(RTM_ADD, nrt) == 0)
return 0;
- syslog(LOG_ERR, "if_route6 (ADD): %m");
+ logger(nrt->iface->ctx, LOG_ERR, "if_route6 (ADD): %m");
return -1;
#endif
}
desc_route("deleting", rt);
retval = if_route6(RTM_DELETE, rt);
if (retval != 0 && errno != ENOENT && errno != ESRCH)
- syslog(LOG_ERR,"%s: if_delroute6: %m", rt->iface->name);
+ logger(rt->iface->ctx, LOG_ERR,
+ "%s: if_delroute6: %m", rt->iface->name);
return retval;
}
r = calloc(1, sizeof(*r));
if (r == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
r->iface = ifp;
nrs = malloc(sizeof(*nrs));
if (nrs == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return;
}
TAILQ_INIT(nrs);
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 3
struct in6_pktinfo pi;
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: delaying Router Solicitation for LL address",
ifp->name);
ipv6_addlinklocalcallback(ifp, ipv6nd_sendrsprobe, ifp);
#endif
dst.sin6_scope_id = ifp->index;
if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr) != 1) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
pi.ipi6_ifindex = CAST_IPI6_IFINDEX(ifp->index);
memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
- syslog(LOG_DEBUG, "%s: sending Router Solicitation", ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: sending Router Solicitation", ifp->name);
if (sendmsg(ctx->nd_fd, &ctx->sndhdr, 0) == -1) {
- syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: %s: sendmsg: %m", ifp->name, __func__);
ipv6nd_drop(ifp);
ifp->options->options &= ~(DHCPCD_IPV6 | DHCPCD_IPV6RS);
return;
eloop_timeout_add_sec(ifp->ctx->eloop,
RTR_SOLICITATION_INTERVAL, ipv6nd_sendrsprobe, ifp);
else
- syslog(LOG_WARNING, "%s: no IPv6 Routers available", ifp->name);
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: no IPv6 Routers available", ifp->name);
}
static void
if (flags & IPV6ND_REACHABLE) {
if (rap->lifetime && rap->expired) {
- syslog(LOG_INFO, "%s: %s is reachable again",
+ logger(rap->iface->ctx, LOG_INFO,
+ "%s: %s is reachable again",
rap->iface->name, rap->sfrom);
rap->expired = 0;
ipv6_buildroutes(rap->iface->ctx);
}
} else {
if (rap->lifetime && !rap->expired) {
- syslog(LOG_WARNING,
+ logger(rap->iface->ctx, LOG_WARNING,
"%s: %s is unreachable, expiring it",
rap->iface->name, rap->sfrom);
rap->expired = 1;
case ND_RA_FLAG_RTPREF_LOW:
return (RTPREF_LOW);
default:
- syslog(LOG_ERR, "rtpref: impossible RA flag %x", rap->flags);
+ logger(rap->iface->ctx, LOG_ERR,
+ "rtpref: impossible RA flag %x", rap->flags);
return (RTPREF_INVALID);
}
/* NOTREACHED */
ipv6_iffindaddr(ap->iface, &ap->addr))
ap->flags |= IPV6_AF_DADCOMPLETED;
if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
- syslog(LOG_DEBUG,
+ logger(ap->iface->ctx, LOG_DEBUG,
"%s: waiting for Router Advertisement"
" DAD to complete",
rap->iface->name);
#if 0
else if (options & DHCPCD_DAEMONISE &&
!(options & DHCPCD_DAEMONISED) && new_data)
- syslog(LOG_WARNING,
+ logger(rap->iface->ctx, LOG_WARNING,
"%s: did not fork due to an absent"
" RDNSS option in the RA",
ifp->name);
ap->flags |= IPV6_AF_DADCOMPLETED;
if (ap->flags & IPV6_AF_DUPLICATED) {
ap->dadcounter++;
- syslog(LOG_WARNING, "%s: DAD detected %s",
- ap->iface->name, ap->saddr);
+ logger(ifp->ctx, LOG_WARNING, "%s: DAD detected %s",
+ ifp->name, ap->saddr);
/* Try and make another stable private address.
* Because ap->dadcounter is always increamented,
/* XXX Cache DAD counter per prefix/id/ssid? */
if (ifp->options->options & DHCPCD_SLAACPRIVATE) {
if (ap->dadcounter >= IDGEN_RETRIES) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: unable to obtain a"
" stable private address",
ifp->name);
goto try_script;
}
- syslog(LOG_INFO, "%s: deleting address %s",
+ logger(ifp->ctx, LOG_INFO, "%s: deleting address %s",
ifp->name, ap->saddr);
if (if_deladdress6(ap) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "if_deladdress6: %m");
+ logger(ifp->ctx, LOG_ERR, "if_deladdress6: %m");
dadcounter = ap->dadcounter;
if (ipv6_makestableprivate(&ap->addr,
&ap->prefix, ap->prefix_len,
ifp, &dadcounter) == -1)
{
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: ipv6_makestableprivate: %m",
ifp->name);
return;
}
if (wascompleted && found) {
- syslog(LOG_DEBUG,
+ logger(rap->iface->ctx, LOG_DEBUG,
"%s: Router Advertisement DAD completed",
rap->iface->name);
if (ipv6nd_scriptrun(rap))
}
static void
-ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
+ipv6nd_handlera(struct dhcpcd_ctx *dctx, struct interface *ifp,
struct icmp6_hdr *icp, size_t len)
{
+ struct ipv6_ctx *ctx = dctx->ipv6;
size_t olen, l, n;
ssize_t r;
struct nd_router_advert *nd_ra;
#endif
if (len < sizeof(struct nd_router_advert)) {
- syslog(LOG_ERR, "IPv6 RA packet too short from %s", ctx->sfrom);
+ logger(dctx, LOG_ERR,
+ "IPv6 RA packet too short from %s", ctx->sfrom);
return;
}
if (!IN6_IS_ADDR_LINKLOCAL(&ctx->from.sin6_addr)) {
- syslog(LOG_ERR, "RA from non local address %s", ctx->sfrom);
+ logger(dctx, LOG_ERR,
+ "RA from non local address %s", ctx->sfrom);
return;
}
if (ifp == NULL) {
#ifdef DEBUG_RS
- syslog(LOG_DEBUG, "RA for unexpected interface from %s",
- ctx->sfrom);
+ logger(dctx, LOG_DEBUG,
+ "RA for unexpected interface from %s", ctx->sfrom);
#endif
return;
}
if (!(ifp->options->options & DHCPCD_IPV6RS)) {
#ifdef DEBUG_RS
- syslog(LOG_DEBUG, "%s: unexpected RA from %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: unexpected RA from %s",
ifp->name, ctx->sfrom);
#endif
return;
/* We could receive a RA before we sent a RS*/
if (ipv6_linklocal(ifp) == NULL) {
#ifdef DEBUG_RS
- syslog(LOG_DEBUG, "%s: received RA from %s (no link-local)",
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: received RA from %s (no link-local)",
ifp->name, ctx->sfrom);
#endif
return;
}
if (ipv6_iffindaddr(ifp, &ctx->from.sin6_addr)) {
- syslog(LOG_DEBUG, "%s: ignoring RA from ourself %s",
- ifp->name, ctx->sfrom);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: ignoring RA from ourself %s", ifp->name, ctx->sfrom);
return;
}
} else
new_data = 0;
if (new_data || ifp->options->options & DHCPCD_DEBUG)
- syslog(LOG_INFO, "%s: Router Advertisement from %s",
+ logger(ifp->ctx, LOG_INFO, "%s: Router Advertisement from %s",
ifp->name, ctx->sfrom);
if (rap == NULL) {
rap = calloc(1, sizeof(*rap));
if (rap == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
rap->iface = ifp;
if (rap->data_len == 0) {
rap->data = malloc(len);
if (rap->data == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
if (new_rap)
free(rap);
return;
get_monotonic(&rap->received);
rap->flags = nd_ra->nd_ra_flags_reserved;
if (new_rap == 0 && rap->lifetime == 0)
- syslog(LOG_WARNING, "%s: %s router available",
+ logger(ifp->ctx, LOG_WARNING, "%s: %s router available",
ifp->name, rap->sfrom);
rap->lifetime = ntohs(nd_ra->nd_ra_router_lifetime);
if (nd_ra->nd_ra_reachable) {
lifetime = ~0U;
for (; len > 0; p += olen, len -= olen) {
if (len < sizeof(struct nd_opt_hdr)) {
- syslog(LOG_ERR, "%s: short option", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: short option", ifp->name);
break;
}
ndo = (struct nd_opt_hdr *)p;
olen = (size_t)ndo->nd_opt_len * 8;
if (olen == 0) {
- syslog(LOG_ERR, "%s: zero length option", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: zero length option", ifp->name);
break;
}
if (olen > len) {
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: Option length exceeds message", ifp->name);
break;
}
case ND_OPT_PREFIX_INFORMATION:
pi = (struct nd_opt_prefix_info *)(void *)ndo;
if (pi->nd_opt_pi_len != 4) {
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
+ logger(ifp->ctx, new_data ? LOG_ERR : LOG_DEBUG,
"%s: invalid option len for prefix",
ifp->name);
continue;
}
if (pi->nd_opt_pi_prefix_len > 128) {
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
+ logger(ifp->ctx, new_data ? LOG_ERR : LOG_DEBUG,
"%s: invalid prefix len",
ifp->name);
continue;
if (IN6_IS_ADDR_MULTICAST(&pi->nd_opt_pi_prefix) ||
IN6_IS_ADDR_LINKLOCAL(&pi->nd_opt_pi_prefix))
{
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
+ logger(ifp->ctx, new_data ? LOG_ERR : LOG_DEBUG,
"%s: invalid prefix in RA", ifp->name);
continue;
}
if (ntohl(pi->nd_opt_pi_preferred_time) >
ntohl(pi->nd_opt_pi_valid_time))
{
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
+ logger(ifp->ctx, new_data ? LOG_ERR : LOG_DEBUG,
"%s: pltime > vltime", ifp->name);
continue;
}
if (new_ap && ap->prefix_pltime) {
if (ipv6_createtempaddr(ap,
&ap->acquired) == NULL)
- syslog(LOG_ERR,
+ logger(ap->iface->ctx, LOG_ERR,
"ipv6_createtempaddr: %m");
}
}
mtu = (struct nd_opt_mtu *)(void *)p;
mtuv = ntohl(mtu->nd_opt_mtu_mtu);
if (mtuv < IPV6_MMTU) {
- syslog(LOG_ERR, "%s: invalid MTU %d",
+ logger(ifp->ctx, LOG_ERR, "%s: invalid MTU %d",
ifp->name, mtuv);
break;
}
n = (size_t)(dnssl->nd_opt_dnssl_len - 1) * 8;
r = decode_rfc3397(NULL, 0, op, n);
if (r < 1) {
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
+ logger(ifp->ctx, new_data ? LOG_ERR : LOG_DEBUG,
"%s: invalid DNSSL option",
ifp->name);
continue;
STRING | ARRAY | DOMAIN,
(const uint8_t *)tmp, l);
} else
- syslog(LOG_ERR, "%s: %m",
+ logger(ifp->ctx, LOG_ERR, "%s: %m",
__func__);
free(tmp);
}
}
if (opt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
continue;
}
if (rao == NULL) {
rao = malloc(sizeof(*rao));
if (rao == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
continue;
}
rao->type = (uint16_t)n;
goto nodhcp6;
if (rap->flags & ND_RA_FLAG_MANAGED) {
if (new_data && dhcp6_start(ifp, DH6S_INIT) == -1)
- syslog(LOG_ERR, "dhcp6_start: %s: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "dhcp6_start: %s: %m", ifp->name);
} else if (rap->flags & ND_RA_FLAG_OTHER) {
if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1)
- syslog(LOG_ERR, "dhcp6_start: %s: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR,
+ "dhcp6_start: %s: %m", ifp->name);
} else {
if (new_data)
- syslog(LOG_DEBUG, "%s: No DHCPv6 instruction in RA",
- ifp->name);
+ logger(ifp->ctx, LOG_DEBUG,
+ "%s: No DHCPv6 instruction in RA", ifp->name);
nodhcp6:
if (ifp->ctx->options & DHCPCD_TEST) {
eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
if (env) {
snprintf(buffer, sizeof(buffer),
"ra%zu_from", i);
- setvar(&env, prefix, buffer, rap->sfrom);
+ setvar(ifp->ctx, &env, prefix, buffer, rap->sfrom);
}
l++;
if (rao->type == ND_OPT_MTU) {
new = strchr(**var, '=');
if (new == NULL) {
- syslog(LOG_ERR, "new is null");
+ logger(ifp->ctx, LOG_ERR,
+ "new is null");
continue;
} else
new++;
rao->option,
len - 1);
} else
- syslog(LOG_ERR,
+ logger(ifp->ctx,
+ LOG_ERR,
"new is null");
}
continue;
*new++ = ' ';
strlcpy(new, rao->option, len);
} else
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: %m", __func__);
continue;
}
if (env) {
snprintf(buffer, sizeof(buffer),
"ra%zu_%s", i, optn);
- setvar(&env, prefix, buffer, rao->option);
+ setvar(ifp->ctx, &env,
+ prefix, buffer, rao->option);
}
}
}
if (env)
- setvard(&env, prefix, "ra_count", i);
+ setvard(ifp->ctx, &env, prefix, "ra_count", i);
l++;
return (ssize_t)l;
}
if (rap->lifetime == 0 || timespeccmp(&now, &expire, >))
{
if (!rap->expired) {
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: %s: router expired",
ifp->name, rap->sfrom);
rap->expired = expired = 1;
if (timespeccmp(&now, &rao->expire, >)) {
/* Expired prefixes are logged above */
if (rao->type != ND_OPT_PREFIX_INFORMATION)
- syslog(LOG_WARNING,
+ logger(ifp->ctx, LOG_WARNING,
"%s: %s: expired option %d",
ifp->name, rap->sfrom, rao->type);
TAILQ_REMOVE(&rap->options, rao, next);
}
static void
-ipv6nd_handlena(struct ipv6_ctx *ctx, struct interface *ifp,
+ipv6nd_handlena(struct dhcpcd_ctx *dctx, struct interface *ifp,
struct icmp6_hdr *icp, size_t len)
{
+ struct ipv6_ctx *ctx = dctx->ipv6;
struct nd_neighbor_advert *nd_na;
struct ra *rap;
int is_router, is_solicited;
if (ifp == NULL) {
#ifdef DEBUG_NS
- syslog(LOG_DEBUG, "NA for unexpected interface from %s",
- ctx->sfrom);
+ logger(ctx, LOG_DEBUG, "NA for unexpected interface from %s",
+ dctx->sfrom);
#endif
return;
}
if ((size_t)len < sizeof(struct nd_neighbor_advert)) {
- syslog(LOG_ERR, "%s: IPv6 NA too short from %s",
+ logger(ifp->ctx, LOG_ERR, "%s: IPv6 NA too short from %s",
ifp->name, ctx->sfrom);
return;
}
buf, INET6_ADDRSTRLEN);
if (IN6_IS_ADDR_MULTICAST(&nd_na->nd_na_target)) {
- syslog(LOG_ERR, "%s: NA multicast address %s (%s)",
+ logger(ifp->ctx, LOG_ERR, "%s: NA multicast address %s (%s)",
ifp->name, taddr, ctx->sfrom);
return;
}
}
if (rap == NULL) {
#ifdef DEBUG_NS
- syslog(LOG_DEBUG, "%s: unexpected NA from %s for %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: unexpected NA from %s for %s",
ifp->name, ctx->sfrom, taddr);
#endif
return;
}
#ifdef DEBUG_NS
- syslog(LOG_DEBUG, "%s: %sNA for %s from %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: %sNA for %s from %s",
ifp->name, is_solicited ? "solicited " : "", taddr, ctx->sfrom);
#endif
/* Node is no longer a router, so remove it from consideration */
if (!is_router && !rap->expired) {
- syslog(LOG_INFO, "%s: %s not a router (%s)",
+ logger(ifp->ctx, LOG_INFO, "%s: %s not a router (%s)",
ifp->name, taddr, ctx->sfrom);
rap->expired = 1;
ipv6_buildroutes(ifp->ctx);
if (is_solicited && is_router && rap->lifetime) {
if (rap->expired) {
rap->expired = 0;
- syslog(LOG_INFO, "%s: %s reachable (%s)",
+ logger(ifp->ctx, LOG_INFO, "%s: %s reachable (%s)",
ifp->name, taddr, ctx->sfrom);
ipv6_buildroutes(ifp->ctx);
script_runreason(rap->iface, "ROUTERADVERT"); /* XXX */
static void
ipv6nd_handledata(void *arg)
{
- struct dhcpcd_ctx *dhcpcd_ctx;
+ struct dhcpcd_ctx *dctx;
struct ipv6_ctx *ctx;
ssize_t len;
struct cmsghdr *cm;
struct icmp6_hdr *icp;
struct interface *ifp;
- dhcpcd_ctx = arg;
- ctx = dhcpcd_ctx->ipv6;
+ dctx = arg;
+ ctx = dctx->ipv6;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
len = recvmsg(ctx->nd_fd, &ctx->rcvhdr, 0);
if (len == -1) {
- syslog(LOG_ERR, "recvmsg: %m");
- eloop_event_delete(dhcpcd_ctx->eloop, ctx->nd_fd, 0);
+ logger(dctx, LOG_ERR, "recvmsg: %m");
+ eloop_event_delete(dctx->eloop, ctx->nd_fd, 0);
close(ctx->nd_fd);
ctx->nd_fd = -1;
return;
ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
ctx->ntopbuf, INET6_ADDRSTRLEN);
if ((size_t)len < sizeof(struct icmp6_hdr)) {
- syslog(LOG_ERR, "IPv6 ICMP packet too short from %s",
+ logger(dctx, LOG_ERR, "IPv6 ICMP packet too short from %s",
ctx->sfrom);
return;
}
}
if (pkt.ipi6_ifindex == 0 || hoplimit == 0) {
- syslog(LOG_ERR,
+ logger(dctx, LOG_ERR,
"IPv6 RA/NA did not contain index or hop limit from %s",
ctx->sfrom);
return;
}
- TAILQ_FOREACH(ifp, dhcpcd_ctx->ifaces, next) {
+ TAILQ_FOREACH(ifp, dctx->ifaces, next) {
if (ifp->index == (unsigned int)pkt.ipi6_ifindex) {
if (!(ifp->options->options & DHCPCD_IPV6) ||
ifp->options->options & DHCPCD_PFXDLGONLY)
if (icp->icmp6_code == 0) {
switch(icp->icmp6_type) {
case ND_NEIGHBOR_ADVERT:
- ipv6nd_handlena(ctx, ifp, icp, (size_t)len);
+ ipv6nd_handlena(dctx, ifp, icp, (size_t)len);
return;
case ND_ROUTER_ADVERT:
- ipv6nd_handlera(ctx, ifp, icp, (size_t)len);
+ ipv6nd_handlera(dctx, ifp, icp, (size_t)len);
return;
}
}
- syslog(LOG_ERR, "invalid IPv6 type %d or code %d from %s",
+ logger(dctx, LOG_ERR, "invalid IPv6 type %d or code %d from %s",
icp->icmp6_type, icp->icmp6_code, ctx->sfrom);
}
struct interface *ifp = arg;
struct rs_state *state;
- syslog(LOG_INFO, "%s: soliciting an IPv6 router", ifp->name);
+ logger(ifp->ctx, LOG_INFO, "%s: soliciting an IPv6 router", ifp->name);
if (ipv6nd_open(ifp->ctx) == -1) {
- syslog(LOG_ERR, "%s: ipv6nd_open: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: ipv6nd_open: %m", __func__);
return;
}
ifp->if_data[IF_DATA_IPV6ND] = calloc(1, sizeof(*state));
state = RS_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
return;
}
}
* address could have changed. */
ipv6nd_makersprobe(ifp);
if (state->rs == NULL) {
- syslog(LOG_ERR, "%s: ipv6ns_makersprobe: %m", __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: ipv6ns_makersprobe: %m", __func__);
return;
}
tv.tv_nsec = (suseconds_t)arc4random_uniform(
MAX_RTR_SOLICITATION_DELAY * NSEC_PER_SEC);
timespecnorm(&tv);
- syslog(LOG_DEBUG,
+ logger(ifp->ctx, LOG_DEBUG,
"%s: delaying IPv6 router solicitation for %0.1f seconds",
ifp->name, timespec_to_double(&tv));
eloop_timeout_add_tv(ifp->ctx->eloop, &tv, ipv6nd_startrs1, ifp);
* config.h will pull it in, or our compat one. */
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
#ifdef INET
static char *
-make_var(const char *prefix, const char *var)
+make_var(struct dhcpcd_ctx *ctx, const char *prefix, const char *var)
{
size_t len;
char *v;
len = strlen(prefix) + strlen(var) + 2;
v = malloc(len);
if (v == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
return NULL;
}
snprintf(v, len, "%s_%s", prefix, var);
static int
-append_config(char ***env, size_t *len,
+append_config(struct dhcpcd_ctx *ctx, char ***env, size_t *len,
const char *prefix, const char *const *config)
{
size_t i, j, e1;
if (strncmp(ne[j] + strlen(prefix) + 1,
config[i], e1) == 0)
{
- p = make_var(prefix, config[i]);
+ p = make_var(ctx, prefix, config[i]);
if (p == NULL) {
ret = -1;
break;
}
if (j == *len) {
j++;
- p = make_var(prefix, config[i]);
+ p = make_var(ctx, prefix, config[i]);
if (p == NULL) {
ret = -1;
break;
}
nep = realloc(ne, sizeof(char *) * (j + 1));
if (nep == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ctx, LOG_ERR, "%s: %m", __func__);
free(p);
ret = -1;
break;
goto eexit;
elen += (size_t)n;
}
- if (append_config(&env, &elen, "old",
+ if (append_config(ifp->ctx, &env, &elen, "old",
(const char *const *)ifo->config) == -1)
goto eexit;
}
goto eexit;
elen += (size_t)n;
}
- if (append_config(&env, &elen, "new",
+ if (append_config(ifp->ctx, &env, &elen, "new",
(const char *const *)ifo->config) == -1)
goto eexit;
}
return (ssize_t)elen;
eexit:
- syslog(LOG_ERR, "%s: %m", __func__);
+ logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
if (env) {
nenv = env;
while (*nenv)
argv[0] = ifp->options->script ? ifp->options->script : UNCONST(SCRIPT);
argv[1] = NULL;
- syslog(LOG_DEBUG, "%s: executing `%s' %s",
+ logger(ifp->ctx, LOG_DEBUG, "%s: executing `%s' %s",
ifp->name, argv[0], reason);
/* Make our env */
elen = (size_t)make_env(ifp, reason, &env);
if (elen == (size_t)-1) {
- syslog(LOG_ERR, "%s: make_env: %m", ifp->name);
+ logger(ifp->ctx, LOG_ERR, "%s: make_env: %m", ifp->name);
return -1;
}
/* Resize for PATH and RC_SVCNAME */
pid = exec_script(ifp->ctx, argv, env);
if (pid == -1)
- syslog(LOG_ERR, "%s: %s: %m", __func__, argv[0]);
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %m", __func__, argv[0]);
else if (pid != 0) {
/* Wait for the script to finish */
while (waitpid(pid, &status, 0) == -1) {
if (errno != EINTR) {
- syslog(LOG_ERR, "waitpid: %m");
+ logger(ifp->ctx, LOG_ERR, "waitpid: %m");
status = 0;
break;
}
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status))
- syslog(LOG_ERR,
+ logger(ifp->ctx, LOG_ERR,
"%s: %s: WEXITSTATUS %d",
__func__, argv[0], WEXITSTATUS(status));
} else if (WIFSIGNALED(status))
- syslog(LOG_ERR, "%s: %s: %s",
+ logger(ifp->ctx, LOG_ERR, "%s: %s: %s",
__func__, argv[0], strsignal(WTERMSIG(status)));
}
elen = (size_t)arraytostr((const char *const *)env,
&bigenv);
if ((ssize_t)elen == -1) {
- syslog(LOG_ERR, "%s: arraytostr: %m",
+ logger(ifp->ctx, LOG_ERR, "%s: arraytostr: %m",
ifp->name);
break;
}
}
if (control_queue(fd, bigenv, elen, 1) == -1)
- syslog(LOG_ERR, "%s: control_queue: %m", __func__);
+ logger(ifp->ctx, LOG_ERR,
+ "%s: control_queue: %m", __func__);
else
status = 1;
}