Had a few complaints that the lastlog option was dropped.
It's now been restored, but with a new way of logging which is
the same as errx(3) as found on the BSD platforms but the output
also goes to the logging option of choice.
This allows the function to define the log priority for syslog
and there is no more need to specify %m.
In turn, this makes the code needed to write error messages
a lot shorter than before.
loginfo and logdebug have no optional x suffix because they are not
meant to record errors, unlike logerr and logwarn.
# dhcpcd Makefile
PROG= dhcpcd
-SRCS= common.c control.c dhcpcd.c duid.c eloop.c
+SRCS= common.c control.c dhcpcd.c duid.c eloop.c logerr.c
SRCS+= if.c if-options.c sa.c route.c
SRCS+= dhcp-common.c script.c
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 5
#include "if.h"
#include "if-options.h"
#include "ipv4ll.h"
+#include "logerr.h"
#if defined(ARP) && (!defined(KERNEL_RFC5227) || defined(ARPING))
#define ARP_LEN \
}
if (ifn) {
#ifdef ARP_DEBUG
- syslog(LOG_DEBUG, "%s: ignoring ARP from self", ifp->name);
+ logdebug("%s: ignoring ARP from self", ifp->name);
#endif
return;
}
while (!(flags & BPF_EOF)) {
bytes = bpf_read(ifp, state->fd, buf, sizeof(buf), &flags);
if (bytes == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
arp_close(ifp);
return;
}
if (state->fd == -1) {
state->fd = bpf_open(ifp, bpf_arp);
if (state->fd == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
return -1;
}
eloop_event_add(ifp->ctx->eloop, state->fd, arp_read, ifp);
tv.tv_nsec = 0;
eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
}
- syslog(LOG_DEBUG,
- "%s: ARP probing %s (%d of %d), next in %0.1f seconds",
+ logdebug("%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_request(ifp, 0, astate->addr.s_addr) == -1)
- syslog(LOG_ERR, "send_arp: %m");
+ logerr(__func__);
}
void
{
if (arp_open(astate->iface) == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+ logerr(__func__);
return;
} else {
const struct iarp_state *state = ARP_CSTATE(astate->iface);
bpf_arp(astate->iface, state->fd);
}
astate->probes = 0;
- syslog(LOG_DEBUG, "%s: probing for %s",
+ logdebug("%s: probing for %s",
astate->iface->name, inet_ntoa(astate->addr));
arp_probe1(astate);
}
astate->claims++;
#else
if (++astate->claims < ANNOUNCE_NUM)
- syslog(LOG_DEBUG,
- "%s: ARP announcing %s (%d of %d), "
+ logdebug("%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,
- "%s: ARP announcing %s (%d of %d)",
+ logdebug("%s: ARP announcing %s (%d of %d)",
ifp->name, inet_ntoa(astate->addr),
astate->claims, ANNOUNCE_NUM);
if (arp_request(ifp, astate->addr.s_addr, astate->addr.s_addr) == -1)
- syslog(LOG_ERR, "arp_request: %m");
+ logerr(__func__);
#endif
eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
#ifndef KERNEL_RFC5227
if (arp_open(astate->iface) == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+ logerr(__func__);
return;
}
#endif
if (amsg != NULL) {
char buf[HWADDR_LEN * 3];
- syslog(LOG_ERR, "%s: hardware address %s claims %s",
+ logerrx("%s: hardware address %s claims %s",
astate->iface->name,
hwaddr_ntoa(amsg->sha, astate->iface->hwlen,
buf, sizeof(buf)),
inet_ntoa(astate->failed));
} else
- syslog(LOG_ERR, "%s: DAD detected %s",
+ logerrx("%s: DAD detected %s",
astate->iface->name, inet_ntoa(astate->failed));
}
ifp->if_data[IF_DATA_ARP] = malloc(sizeof(*state));
state = ARP_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
state->fd = -1;
}
if ((astate = calloc(1, sizeof(*astate))) == NULL) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr(__func__);
return NULL;
}
astate->iface = ifp;
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include "common.h"
#include "arp.h"
#include "bpf.h"
#include "dhcp.h"
#include "if.h"
+#include "logerr.h"
#define ARP_ADDRS_MAX 3
goto eexit;
if (pv.bv_major != BPF_MAJOR_VERSION ||
pv.bv_minor < BPF_MINOR_VERSION) {
- syslog(LOG_ERR, "BPF version mismatch - recompile");
+ logerrx("BPF version mismatch - recompile");
goto eexit;
}
TAILQ_FOREACH(astate, &state->arp_states, next) {
if (++naddrs > ARP_ADDRS_MAX) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
}
BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "common.h"
#include "dhcpcd.h"
#include "if-options.h"
+#include "logerr.h"
/* Most route(4) messages are less than 256 bytes. */
#define IOVEC_BUFSIZ 256
if (prefix)
len += strlen(prefix) + 1;
- *e = malloc(len);
- if (*e == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ if ((*e = malloc(len)) == NULL) {
+ logerr(__func__);
return -1;
}
if (prefix)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "control.h"
#include "eloop.h"
#include "if.h"
+#include "logerr.h"
#ifndef SUN_LEN
#define SUN_LEN(su) \
}
*ap = NULL;
if (dhcpcd_handleargs(fd->ctx, fd, argc, argvp) == -1) {
- syslog(LOG_ERR, "%s: dhcpcd_handleargs: %m", __func__);
+ logerr(__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);
+ logerr(__func__);
if (errno != EINTR && errno != EAGAIN)
control_delete(fd);
return;
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
-#include <syslog.h>
#include <string.h>
#define _INDEV
#include "dev.h"
#include "eloop.h"
#include "dhcpcd.h"
+#include "logerr.h"
int
dev_initialized(struct dhcpcd_ctx *ctx, const char *ifname)
if (ctx->dev) {
if (stop)
- syslog(LOG_DEBUG, "dev: unloaded %s", ctx->dev->name);
+ logdebug("dev: unloaded %s", ctx->dev->name);
eloop_event_delete(ctx->eloop, ctx->dev_fd);
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());
+ logerrx("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());
+ logerrx("dlsym: %s", dlerror());
dlclose(h);
return -1;
}
if ((ctx->dev = calloc(1, sizeof(*ctx->dev))) == NULL) {
- syslog(LOG_ERR, "%s: calloc: %m", __func__);
+ logerr("%s: calloc", __func__);
dlclose(h);
return -1;
}
dlclose(h);
return -1;
}
- syslog(LOG_INFO, "dev: loaded %s", ctx->dev->name);
+ loginfo("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);
+ logerrx("dev: already started %s", ctx->dev->name);
return -1;
}
dp = opendir(DEVDIR);
if (dp == NULL) {
- syslog(LOG_DEBUG, "dev: %s: %m", DEVDIR);
+ logdebug("dev: %s: %m", DEVDIR);
return 0;
}
{
if (ctx->dev_fd != -1) {
- syslog(LOG_ERR, "%s: already started on fd %d", __func__,
- ctx->dev_fd);
+ logerrx("%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) == -1)
{
- syslog(LOG_ERR, "%s: eloop_event_add: %m", __func__);
+ logerr(__func__);
dev_stop1(ctx, 1);
return -1;
}
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <arpa/nameser.h> /* after normal includes for sunos */
#include "dhcp.h"
#include "if.h"
#include "ipv6.h"
+#include "logerr.h"
/* Support very old arpa/nameser.h as found in OpenBSD */
#ifndef NS_MAXDNAME
prefix, opt, 1, od, ol, ifname))
return 1;
else
- syslog(LOG_ERR, "%s: %s %d: %m",
+ logerr("%s: %s %d",
ifname, __func__, opt->option);
}
return 0;
if (opt->type & OT_INDEX) {
if (opt->index > 999) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return 0;
}
}
(opt->type & OT_INDEX ? 3 : 0);
pfx = malloc(e);
if (pfx == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return 0;
}
if (opt->type & OT_INDEX)
eo = dhcp_optlen(eopt, ol);
if (eo == -1) {
if (env == NULL)
- syslog(LOG_ERR,
- "%s: %s %d.%d/%zu: "
+ logerrx("%s: %s %d.%d/%zu: "
"malformed embedded option",
ifname, __func__, opt->option,
eopt->option, i);
* option which is optional. */
if (env == NULL &&
(ol != 0 || !(eopt->type & OT_OPTIONAL)))
- syslog(LOG_ERR,
- "%s: %s %d.%d/%zu: missing embedded option",
+ logerrx("%s: %s %d.%d/%zu: missing embedded option",
ifname, __func__, opt->option,
eopt->option, i);
goto out;
pfx, eopt, ov, od, (size_t)eo, ifname))
n++;
else if (env == NULL)
- syslog(LOG_ERR,
- "%s: %s %d.%d/%zu: %m",
+ logerr("%s: %s %d.%d/%zu",
ifname, __func__,
opt->option, eopt->option, i);
}
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 2
#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
+#include "logerr.h"
#include "sa.h"
#include "script.h"
if (!(ifo->options & DHCPCD_CSR_WARNED) &&
!(state->added & STATE_FAKE))
{
- syslog(LOG_DEBUG,
- "%s: using %sClassless Static Routes",
+ logdebug("%s: using %sClassless Static Routes",
ifp->name, csr);
ifo->options |= DHCPCD_CSR_WARNED;
}
#endif
if ((mtu = if_getmtu(ifp)) == -1)
- syslog(LOG_ERR, "%s: if_getmtu: %m", ifp->name);
+ logerr("%s: if_getmtu", ifp->name);
else if (mtu < MTU_MIN) {
if (if_setmtu(ifp, MTU_MIN) == -1)
- syslog(LOG_ERR, "%s: if_setmtu: %m", ifp->name);
+ logerr("%s: if_setmtu", ifp->name);
mtu = MTU_MIN;
}
{
AREA_FIT(vivco->len);
if (vivco->len + 2 + *lp > 255) {
- syslog(LOG_ERR,
- "%s: VIVCO option too big",
+ logerrx("%s: VIVCO option too big",
ifp->name);
free(bootp);
return -1;
alen = -1;
}
if (alen == -1)
- syslog(LOG_ERR, "%s: dhcp_auth_encode: %m", ifp->name);
+ logerr("%s: dhcp_auth_encode", ifp->name);
else if (alen != 0) {
auth_len = (uint8_t)alen;
AREA_CHECK(auth_len);
return (ssize_t)len;
toobig:
- syslog(LOG_ERR, "%s: DHCP message too big", ifp->name);
+ logerrx("%s: DHCP message too big", ifp->name);
free(bootp);
return -1;
}
ssize_t bytes;
const struct dhcp_state *state = D_CSTATE(ifp);
- syslog(LOG_DEBUG, "%s: writing lease `%s'",
- ifp->name, state->leasefile);
+ logdebug("%s: writing lease `%s'", ifp->name, state->leasefile);
fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1)
}
if (fd == -1) {
if (errno != ENOENT)
- syslog(LOG_ERR, "%s: open `%s': %m",
+ logerr("%s: open `%s'",
ifp->name, state->leasefile);
return 0;
}
if (state->leasefile[0] == '\0')
- syslog(LOG_DEBUG, "reading standard input");
+ logdebug("reading standard input");
else
- syslog(LOG_DEBUG, "%s: reading lease `%s'",
+ logdebug("%s: reading lease `%s'",
ifp->name, state->leasefile);
bytes = dhcp_read_lease_fd(fd, (void **)&lease);
close(fd);
if (bytes == 0) {
free(lease);
- syslog(LOG_ERR, "%s: dhcp_read_lease_fd: %m", __func__);
+ logerr("%s: dhcp_read_lease_fd", __func__);
return 0;
}
* scribble whatever in the stored lease file. */
if (bytes < offsetof(struct bootp, vend) + 4) {
free(lease);
- syslog(LOG_ERR, "%s: truncated lease", __func__);
+ logerrx("%s: %s: truncated lease", ifp->name, __func__);
return 0;
}
if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
lease, bytes, 4, type, auth, auth_len) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
- ifp->name);
+ logdebug("%s: dhcp_auth_validate", ifp->name);
free(lease);
return 0;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logdebug("%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_DEBUG, "%s: accepted reconfigure key",
- ifp->name);
+ logdebug("%s: accepted reconfigure key", ifp->name);
} else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
DHCPCD_AUTH_SENDREQUIRE)
{
- syslog(LOG_ERR, "%s: authentication now required", ifp->name);
+ logerrx("%s: authentication now required", ifp->name);
free(lease);
return 0;
}
/* No carrier? Don't bother sending the packet. */
if (ifp->carrier == LINK_DOWN)
return;
- syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
+ logdebug("%s: sending %s with xid 0x%x",
ifp->name,
ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
state->xid);
* However, we do need to advance the timeout. */
if (ifp->carrier == LINK_DOWN)
goto fail;
- syslog(LOG_DEBUG,
- "%s: sending %s (xid 0x%x), next in %0.1f seconds",
+ logdebug("%s: sending %s (xid 0x%x), next in %0.1f seconds",
ifp->name,
ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
state->xid,
s = dhcp_openudp(ifp);
if (s == -1) {
if (errno != EADDRINUSE)
- syslog(LOG_ERR, "%s: dhcp_openudp: %m",
- ifp->name);
+ logerr("%s: dhcp_openudp", ifp->name);
/* We cannot renew */
state->addr = NULL;
}
r = sendto(s, (uint8_t *)bootp, len, 0,
(struct sockaddr *)&sin, sizeof(sin));
if (r == -1)
- syslog(LOG_ERR, "%s: dhcp_sendpacket: %m", ifp->name);
+ logerr("%s: dhcp_sendpacket", ifp->name);
} else {
size_t ulen;
udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from,to);
if (udp == NULL) {
- syslog(LOG_ERR, "dhcp_makeudppacket: %m");
+ logerr("%s: dhcp_makeudppacket", ifp->name);
r = 0;
} else {
r = bpf_send(ifp, state->bpf_fd,
* As such we remove it from consideration without actually
* stopping the interface. */
if (r == -1) {
- syslog(LOG_ERR, "%s: if_sendraw: %m", ifp->name);
+ logerr("%s: if_sendraw", ifp->name);
switch(errno) {
case ENETDOWN:
case ENETRESET:
ifo->reboot, ipv4ll_start, ifp);
#endif
if (ifo->options & DHCPCD_REQUEST)
- syslog(LOG_INFO, "%s: soliciting a DHCP lease (requesting %s)",
+ loginfo("%s: soliciting a DHCP lease (requesting %s)",
ifp->name, inet_ntoa(ifo->req_addr));
else
- syslog(LOG_INFO, "%s: soliciting a %s lease",
+ loginfo("%s: soliciting a %s lease",
ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
send_discover(ifp);
}
return -1;
#endif
- syslog(LOG_WARNING,
- "%s: extending lease until DaD failure or DHCP", ifp->name);
+ logwarnx("%s: extending lease until DaD failure or DHCP",
+ ifp->name);
return 0;
}
#endif
- syslog(LOG_WARNING, "%s: extending lease", ifp->name);
+ logwarnx("%s: extending lease", ifp->name);
return 0;
}
{
struct interface *ifp = arg;
- syslog(LOG_ERR, "%s: DHCP lease expired", ifp->name);
+ logerrx("%s: DHCP lease expired", ifp->name);
if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
if (dhcp_leaseextend(ifp) == 0)
return;
- syslog(LOG_ERR, "%s: dhcp_leaseextend: %m", ifp->name);
+ logerr(__func__);
}
dhcp_expire1(ifp);
}
eloop_timeout_delete(ifp->ctx->eloop, dhcp_startrenew, ifp);
lease = &state->lease;
- syslog(LOG_DEBUG, "%s: renewing lease of %s", ifp->name,
+ logdebug("%s: renewing lease of %s", ifp->name,
inet_ntoa(lease->addr));
state->state = DHS_RENEW;
dhcp_new_xid(ifp);
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",
+ logwarnx("%s: failed to renew DHCP, rebinding", ifp->name);
+ logdebug("%s: expire in %"PRIu32" seconds",
ifp->name, lease->leasetime - lease->rebindtime);
state->state = DHS_REBIND;
eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
if (state->state == DHS_BOUND)
return;
- syslog(LOG_DEBUG, "%s: DAD completed for %s",
+ logdebug("%s: DAD completed for %s",
ifp->name, inet_ntoa(astate->addr));
if (state->state != DHS_INFORM)
dhcp_bind(ifp);
}
get_lease(ifp, lease, state->new, state->new_len);
if (ifo->options & DHCPCD_STATIC) {
- syslog(LOG_INFO, "%s: using static address %s/%d",
+ loginfo("%s: using static address %s/%d",
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->mask));
lease->leasetime = ~0U;
state->reason = "STATIC";
} else if (ifo->options & DHCPCD_INFORM) {
- syslog(LOG_INFO, "%s: received approval for %s",
+ loginfo("%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",
- ifp->name, inet_ntoa(lease->addr));
+ loginfo("%s: leased %s for infinity",
+ ifp->name, inet_ntoa(lease->addr));
} else {
if (lease->leasetime < DHCP_MIN_LEASE) {
- syslog(LOG_WARNING,
- "%s: minimum lease is %d seconds",
+ logwarnx("%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,
- "%s: rebind time greater than lease "
+ logwarnx("%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,
- "%s: renewal time greater than rebind "
- "time, forcing to %"PRIu32" seconds",
+ logwarnx("%s: renewal time greater than "
+ "rebind time, forcing to %"PRIu32" seconds",
ifp->name, lease->renewaltime);
}
- syslog(state->addr &&
+ if (state->addr &&
lease->addr.s_addr == state->addr->addr.s_addr &&
- !(state->added & STATE_FAKE) ?
- LOG_DEBUG : LOG_INFO,
- "%s: leased %s for %"PRIu32" seconds", ifp->name,
- inet_ntoa(lease->addr), lease->leasetime);
+ !(state->added & STATE_FAKE))
+ logdebug("%s: leased %s for %"PRIu32" seconds",
+ ifp->name, inet_ntoa(lease->addr),
+ lease->leasetime);
+ else
+ loginfo("%s: leased %s for %"PRIu32" seconds",
+ ifp->name, inet_ntoa(lease->addr),
+ lease->leasetime);
}
}
if (ifp->ctx->options & DHCPCD_TEST) {
(time_t)lease->rebindtime, dhcp_rebind, ifp);
eloop_timeout_add_sec(ifp->ctx->eloop,
(time_t)lease->leasetime, dhcp_expire, ifp);
- syslog(LOG_DEBUG,
- "%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
+ logdebug("%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, state->new_len) == -1)
- syslog(LOG_ERR, "%s: write_lease: %m", __func__);
+ logerr(__func__);
ipv4_applyaddr(ifp);
}
struct interface *ifp = arg;
struct dhcp_state *state = D_STATE(ifp);
- syslog(LOG_INFO,
- "%s: timed out contacting a DHCP server, using last lease",
+ loginfo("%s: timed out contacting a DHCP server, using last lease",
ifp->name);
dhcp_bind(ifp);
/* If we forked, stop here. */
if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND &&
dhcp_leaseextend(ifp) == -1)
{
- syslog(LOG_ERR, "%s: dhcp_leaseextend: %m", ifp->name);
+ logerr("%s: %s", ifp->name, __func__);
dhcp_expire(ifp);
}
dhcp_discover(ifp);
/* Add the address now, let the kernel handle DAD. */
ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd);
} else
- syslog(LOG_INFO, "%s: waiting for DAD on %s",
+ loginfo("%s: waiting for DAD on %s",
ifp->name, inet_ntoa(addr));
return 0;
}
struct dhcp_lease l;
get_lease(ifp, &l, state->offer, state->offer_len);
- syslog(LOG_INFO, "%s: probing address %s/%d",
+ loginfo("%s: probing address %s/%d",
ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask));
/* We need to handle DAD. */
arp_probe(astate);
if (ifo->req_addr.s_addr == INADDR_ANY &&
(ia = ipv4_iffindaddr(ifp, NULL, NULL)) == NULL)
{
- syslog(LOG_INFO, "%s: waiting for 3rd party to "
+ loginfo("%s: waiting for 3rd party to "
"configure IP address", ifp->name);
state->reason = "3RDPARTY";
script_runreason(ifp, state->reason);
if (ifo->req_addr.s_addr == INADDR_ANY) {
ia = ipv4_iffindaddr(ifp, NULL, NULL);
if (ia == NULL) {
- syslog(LOG_INFO,
- "%s: waiting for 3rd party to configure IP address",
+ loginfo("%s: waiting for 3rd party to "
+ "configure IP address",
ifp->name);
if (!(ifp->ctx->options & DHCPCD_TEST)) {
state->reason = "3RDPARTY";
ia = ipv4_iffindaddr(ifp, &ifo->req_addr, &ifo->req_mask);
if (ia == NULL) {
if (ifp->ctx->options & DHCPCD_TEST) {
- syslog(LOG_ERR,
- "%s: cannot add IP address in test mode",
+ logerrx("%s: cannot add IP address in test mode",
ifp->name);
return;
}
state->interval = 0;
if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_DOWN) {
- syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
+ loginfo("%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",
+ loginfo("%s: informing address of %s",
ifp->name, inet_ntoa(state->lease.addr));
dhcp_inform(ifp);
return;
if (!IS_DHCP(state->offer))
return;
- syslog(LOG_INFO, "%s: rebinding lease of %s",
+ loginfo("%s: rebinding lease of %s",
ifp->name, inet_ntoa(state->lease.addr));
dhcp_new_xid(ifp);
state->lease.server.s_addr = 0;
state->new != NULL &&
state->lease.server.s_addr != INADDR_ANY)
{
- syslog(LOG_INFO, "%s: releasing lease of %s",
+ loginfo("%s: releasing lease of %s",
ifp->name, inet_ntoa(state->lease.addr));
dhcp_new_xid(ifp);
send_message(ifp, DHCP_RELEASE, NULL);
}
static void
-log_dhcp(int lvl, const char *msg,
+log_dhcp(logfunc_t *logfunc, const char *msg,
const struct interface *ifp, const struct bootp *bootp, size_t bootp_len,
const struct in_addr *from, int ad)
{
tmpl = (al * 4) + 1;
tmp = malloc(tmpl);
if (tmp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(a);
return;
}
addr.s_addr = bootp->yiaddr;
a = strdup(inet_ntoa(addr));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return;
}
} else
print_string(sname, sizeof(sname), OT_STRING | OT_DOMAIN,
bootp->sname, sizeof(bootp->sname));
if (a == NULL)
- syslog(lvl, "%s: %s %s %s `%s'",
+ logfunc("%s: %s %s %s `%s'",
ifp->name, msg, tfrom, inet_ntoa(addr), sname);
else
- syslog(lvl, "%s: %s %s %s %s `%s'",
+ logfunc("%s: %s %s %s %s `%s'",
ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
} else {
if (r != 0) {
addr = *from;
}
if (a == NULL)
- syslog(lvl, "%s: %s %s %s",
+ logfunc("%s: %s %s %s",
ifp->name, msg, tfrom, inet_ntoa(addr));
else
- syslog(lvl, "%s: %s %s %s %s",
+ logfunc("%s: %s %s %s %s",
ifp->name, msg, a, tfrom, inet_ntoa(addr));
}
free(a);
/* Handled in our BPF filter. */
#if 0
if (bootp->op != BOOTREPLY) {
- syslog(LOG_DEBUG, "%s: op (%d) is not BOOTREPLY",
+ logdebug("%s: op (%d) is not BOOTREPLY",
ifp->name, bootp->op);
return;
}
{
char buf[sizeof(bootp->chaddr) * 3];
- syslog(LOG_DEBUG, "%s: xid 0x%x is for hwaddr %s",
+ logdebug("%s: xid 0x%x is for hwaddr %s",
ifp->name, ntohl(bootp->xid),
hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr),
buf, sizeof(buf)));
bootp, bootp_len, DHO_MESSAGETYPE) == -1)
type = 0;
else if (ifo->options & DHCPCD_BOOTP) {
- syslog(LOG_DEBUG, "%s: ignoring DHCP reply (expecting BOOTP)",
+ logdebug("%s: ignoring DHCP reply (expecting BOOTP)",
ifp->name);
return;
}
(uint8_t *)bootp, bootp_len, 4, type,
auth, auth_len) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
+ logdebug("%s: dhcp_auth_validate",
ifp->name);
- LOGDHCP0(LOG_ERR, "authentication failed");
+ LOGDHCP0(logerrx, "authentication failed");
return;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logdebug("%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_INFO, "%s: accepted reconfigure key",
- ifp->name);
+ loginfo("%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
- LOGDHCP0(LOG_ERR, "no authentication");
+ LOGDHCP0(logerrx, "no authentication");
return;
}
- LOGDHCP0(LOG_WARNING, "no authentication");
+ LOGDHCP0(logwarnx, "no authentication");
}
#endif
if (from->s_addr == INADDR_ANY ||
from->s_addr == INADDR_BROADCAST)
{
- LOGDHCP(LOG_ERR, "discarding Force Renew");
+ LOGDHCP(logerrx, "discarding Force Renew");
return;
}
#ifdef AUTH
if (auth == NULL) {
- LOGDHCP(LOG_ERR, "unauthenticated Force Renew");
+ LOGDHCP(logerrx, "unauthenticated Force Renew");
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
return;
}
if (state->state != DHS_BOUND && state->state != DHS_INFORM) {
- LOGDHCP(LOG_DEBUG, "not bound, ignoring Force Renew");
+ LOGDHCP(logdebug, "not bound, ignoring Force Renew");
return;
}
- LOGDHCP(LOG_INFO, "Force Renew from");
+ LOGDHCP(loginfo, "Force Renew from");
/* The rebind and expire timings are still the same, we just
* enter the renew state early */
if (state->state == DHS_BOUND)
dhcp_inform(ifp);
}
#else
- LOGDHCP(LOG_ERR, "unauthenticated Force Renew");
+ LOGDHCP(logerrx, "unauthenticated Force Renew");
#endif
return;
}
/* Before we supported FORCERENEW we closed off the raw
* port so we effectively ignored all messages.
* As such we'll not log by default here. */
- //LOGDHCP(LOG_DEBUG, "bound, ignoring");
+ //LOGDHCP(logdebug, "bound, ignoring");
return;
}
#if 0
/* Ensure it's the right transaction */
if (state->xid != ntohl(bootp->xid)) {
- syslog(LOG_DEBUG,
- "%s: wrong xid 0x%x (expecting 0x%x) from %s",
+ logdebug("%s: wrong xid 0x%x (expecting 0x%x) from %s",
ifp->name, ntohl(bootp->xid), state->xid,
inet_ntoa(*from));
return;
if (state->state == DHS_PROBE) {
/* Ignore any DHCP messages whilst probing a lease to bind. */
- LOGDHCP(LOG_DEBUG, "probing, ignoring");
+ LOGDHCP(logdebug, "probing, ignoring");
return;
}
get_option_uint8(ifp->ctx, &tmp,
bootp, bootp_len, (uint8_t)i) == 0)
{
- LOGDHCP(LOG_WARNING, "reject DHCP");
+ LOGDHCP(logwarnx, "reject DHCP");
return;
}
}
get_option_addr(ifp->ctx, &addr,
bootp, bootp_len, DHO_SERVERID) == -1)
{
- LOGDHCP(LOG_WARNING, "reject NAK");
+ LOGDHCP(logwarnx, "reject NAK");
return;
}
/* We should restart on a NAK */
- LOGDHCP(LOG_WARNING, "NAK:");
+ LOGDHCP(logwarnx, "NAK:");
if ((msg = get_option_string(ifp->ctx,
bootp, bootp_len, DHO_MESSAGE)))
{
- syslog(LOG_WARNING, "%s: message: %s", ifp->name, msg);
+ logwarnx("%s: message: %s", ifp->name, msg);
free(msg);
}
if (state->state == DHS_INFORM) /* INFORM should not be NAKed */
* always true. */
if (type == 0 && i == DHO_SERVERID)
continue;
- LOGDHCP(LOG_WARNING, "reject DHCP");
+ LOGDHCP(logwarnx, "reject DHCP");
return;
}
}
/* DHCP Auto-Configure, RFC 2563 */
if (type == DHCP_OFFER && bootp->yiaddr == 0) {
- LOGDHCP(LOG_WARNING, "no address given");
+ LOGDHCP(logwarnx, "no address given");
if ((msg = get_option_string(ifp->ctx,
bootp, bootp_len, DHO_MESSAGE)))
{
- syslog(LOG_WARNING, "%s: message: %s", ifp->name, msg);
+ logwarnx("%s: message: %s", ifp->name, msg);
free(msg);
}
#ifdef IPV4LL
{
switch (tmp) {
case 0:
- LOGDHCP(LOG_WARNING, "IPv4LL disabled from");
+ LOGDHCP(logwarnx, "IPv4LL disabled from");
ipv4ll_drop(ifp);
arp_drop(ifp);
break;
case 1:
- LOGDHCP(LOG_WARNING, "IPv4LL enabled from");
+ LOGDHCP(logwarnx, "IPv4LL enabled from");
ipv4ll_start(ifp);
break;
default:
- syslog(LOG_ERR,
- "%s: unknown auto configuration option %d",
+ logerrx("%s: unknown auto configuration "
+ "option %d",
ifp->name, tmp);
break;
}
&&
(bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST))
{
- LOGDHCP(LOG_WARNING, "reject invalid address");
+ LOGDHCP(logwarnx, "reject invalid address");
return;
}
#ifdef IN_IFF_DUPLICATED
ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
if (ia && ia->addr_flags & IN_IFF_DUPLICATED) {
- LOGDHCP(LOG_WARNING, "declined duplicate address");
+ LOGDHCP(logwarnx, "declined duplicate address");
if (type)
dhcp_decline(ifp);
ipv4_deladdr(ia, 0);
goto rapidcommit;
}
- LOGDHCP(LOG_INFO, "offered");
+ LOGDHCP(loginfo, "offered");
if (state->offer_len < bootp_len) {
free(state->offer);
if ((state->offer = malloc(bootp_len)) == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
state->offer_len = 0;
return;
}
if (type) {
if (type == DHCP_OFFER) {
- LOGDHCP(LOG_WARNING, "ignoring offer of");
+ LOGDHCP(logwarnx, "ignoring offer of");
return;
}
/* We should only be dealing with acks */
if (type != DHCP_ACK) {
- LOGDHCP(LOG_ERR, "not ACK or OFFER");
+ LOGDHCP(logerr, "not ACK or OFFER");
return;
}
DHO_RAPIDCOMMIT, NULL))
state->state = DHS_REQUEST;
else {
- LOGDHCP(LOG_DEBUG, "ignoring ack of");
+ LOGDHCP(logdebug, "ignoring ack of");
return;
}
}
rapidcommit:
if (!(ifo->options & DHCPCD_INFORM))
- LOGDHCP(LOG_DEBUG, "acknowledged");
+ LOGDHCP(logdebug, "acknowledged");
else
ifo->options &= ~DHCPCD_STATIC;
}
if (state->offer_len < bootp_len) {
free(state->offer);
if ((state->offer = malloc(bootp_len)) == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
state->offer_len = 0;
return;
}
if (valid_udp_packet(data, len, &from, flags & RAW_PARTIALCSUM) == -1)
{
- syslog(LOG_ERR, "%s: invalid UDP packet from %s",
+ logerrx("%s: invalid UDP packet from %s",
ifp->name, inet_ntoa(from));
return;
}
i = whitelisted_ip(ifp->options, from.s_addr);
if (i == 0) {
- syslog(LOG_WARNING, "%s: non whitelisted DHCP packet from %s",
+ logwarnx("%s: non whitelisted DHCP packet from %s",
ifp->name, inet_ntoa(from));
return;
} else if (i != 1 && blacklisted_ip(ifp->options, from.s_addr) == 1) {
- syslog(LOG_WARNING, "%s: blacklisted DHCP packet from %s",
+ logwarnx("%s: blacklisted DHCP packet from %s",
ifp->name, inet_ntoa(from));
return;
}
if (ifp->flags & IFF_POINTOPOINT &&
(state->addr == NULL || state->addr->brd.s_addr != from.s_addr))
{
- syslog(LOG_WARNING, "%s: server %s is not destination",
+ logwarnx("%s: server %s is not destination",
ifp->name, inet_ntoa(from));
}
/* udp_len must be correct because the values are checked in
* valid_udp_packet(). */
if (udp_len < offsetof(struct bootp, vend)) {
- syslog(LOG_ERR, "%s: truncated packet (%zu) from %s",
+ logerrx("%s: truncated packet (%zu) from %s",
ifp->name, udp_len, inet_ntoa(from));
return;
}
while (!(flags & BPF_EOF)) {
bytes = bpf_read(ifp, state->bpf_fd, buf, sizeof(buf), &flags);
if (bytes == -1) {
- syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+ logerr(__func__);
dhcp_close(ifp);
return;
}
/* 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__);
+ logerr(__func__);
eloop_event_delete(ctx->eloop, ctx->udp_fd);
close(ctx->udp_fd);
ctx->udp_fd = -1;
state->bpf_fd = bpf_open(ifp, bpf_bootp);
if (state->bpf_fd == -1) {
if (errno == ENOENT) {
- syslog(LOG_ERR, "%s not found", bpf_name);
+ logerrx("%s not found", bpf_name);
/* 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",
- __func__, ifp->name);
+ logerr(__func__);
return -1;
}
eloop_event_add(ifp->ctx->eloop,
AF_INET, ifp);
state->new_len = read_lease(ifp, &state->new);
if (state->new == NULL) {
- syslog(LOG_ERR, "%s: %s: %m",
+ logerr("%s: %s",
*ifp->name ? ifp->name : state->leasefile, __func__);
return -1;
}
return script_runreason(ifp, state->reason);
eexit:
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
return 0;
if (ifo->options & DHCPCD_CLIENTID)
- syslog(LOG_DEBUG, "%s: using ClientID %s", ifp->name,
+ logdebug("%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,
+ logdebug("%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__);
+ logerr(__func__);
return -1;
}
/* Don't log an error if some other process
* is handling this. */
if (errno != EADDRINUSE)
- syslog(LOG_ERR, "%s: dhcp_openudp: %m",
- __func__);
+ logerr("%s: dhcp_openudp", __func__);
} else
eloop_event_add(ifp->ctx->eloop,
ifp->ctx->udp_fd, dhcp_handleudp, ifp->ctx);
}
if (dhcp_init(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp_init: %m", ifp->name);
+ logerr("%s: dhcp_init", ifp->name);
return;
}
return;
}
if (ifp->hwlen == 0 && ifo->clientid[0] == '\0') {
- syslog(LOG_WARNING, "%s: needs a clientid to configure",
- ifp->name);
+ logwarnx("%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;
rt_build(ifp->ctx, AF_INET);
} else
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
}
if (!IS_DHCP(state->offer)) {
free(state->offer);
if (now == -1 ||
(time_t)state->lease.leasetime < now - st.st_mtime)
{
- syslog(LOG_DEBUG,
- "%s: discarding expired lease", ifp->name);
+ logdebug("%s: discarding expired lease",
+ ifp->name);
free(state->offer);
state->offer = NULL;
state->offer_len = 0;
tv.tv_nsec = (suseconds_t)arc4random_uniform(
(DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC);
timespecnorm(&tv);
- syslog(LOG_DEBUG, "%s: delaying IPv4 for %0.1f seconds",
+ logdebug("%s: delaying IPv4 for %0.1f seconds",
ifp->name, timespec_to_double(&tv));
eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_start1, ifp);
if (cmd == RTM_DELADDR) {
if (state->addr == ia) {
- syslog(LOG_INFO, "%s: deleted IP address %s",
+ loginfo("%s: deleted IP address %s",
ifp->name, ia->saddr);
state->addr = NULL;
/* Don't clear the added state as we need
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <fcntl.h>
#include "if.h"
#include "if-options.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "script.h"
#ifdef HAVE_SYS_BITOPS_H
}
if (len > UINT16_MAX) {
- syslog(LOG_ERR, "%s: DHCPv6 Vendor Class too big", ifp->name);
+ logerrx("%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__);
+ logerr(__func__);
return -1;
}
{
sa = inet_ntop(AF_INET6, &prefix->prefix,
sabuf, sizeof(sabuf));
- syslog(LOG_ERR, "%s: invalid prefix %s/%d + %d/%d: %m",
+ logerr("%s: invalid prefix %s/%d + %d/%d",
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",
+ logerrx("%s: cannot delegate excluded prefix %s/%d",
ifp->name, sa, prefix->prefix_exclude_len);
return -1;
}
alen = -1;
}
if (alen == -1)
- syslog(LOG_ERR, "%s: dhcp_auth_encode: %m", ifp->name);
+ logerr("%s: %s: dhcp_auth_encode", __func__, ifp->name);
else if (alen != 0) {
auth_len = (uint16_t)alen;
len += sizeof(o) + auth_len;
}
if (!callback)
- syslog(LOG_DEBUG, "%s: %s %s with xid 0x%02x%02x%02x",
+ logdebug("%s: %s %s with xid 0x%02x%02x%02x",
ifp->name,
broad_uni,
dhcp6_get_op(state->send->type),
logsend:
if (ifp->carrier != LINK_DOWN)
- syslog(LOG_DEBUG,
- "%s: %s %s (xid 0x%02x%02x%02x),"
+ logdebug("%s: %s %s (xid 0x%02x%02x%02x),"
" next in %0.1f seconds",
ifp->name,
broad_uni,
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);
+ logerr("%s: %s: dhcp6_updateauth", __func__, ifp->name);
if (errno != ESRCH)
return -1;
}
memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
if (sendmsg(ctx->dhcp6_fd, &ctx->sndhdr, 0) == -1) {
- syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
+ logerr("%s: %s: sendmsg", __func__, ifp->name);
/* Allow DHCPv6 to continue .... the errors
* would be rate limited by the protocol.
* Generally the error is ENOBUFS when struggling to
eloop_timeout_add_tv(ifp->ctx->eloop,
&state->RT, state->MRCcallback, ifp);
else
- syslog(LOG_WARNING, "%s: sent %d times with no reply",
+ logwarnx("%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);
+ logerr("%s: %s", __func__, 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",
- ap->iface->name, ap->saddr);
+ logwarnx("%s: DAD detected %s", ap->iface->name, ap->saddr);
if (!wascompleted) {
ifp = ap->iface;
}
}
if (!wascompleted) {
- syslog(LOG_DEBUG, "%s: DHCPv6 DAD completed",
+ logdebug("%s: DHCPv6 DAD completed",
ifp->name);
script_runreason(ifp,
ap->delegating_prefix ?
continue;
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return;
}
a->flags = IPV6_AF_REQUEST;
#ifndef SMALL
dhcp6_delete_delegates(ifp);
#endif
- syslog(LOG_INFO, "%s: soliciting a DHCPv6 lease", ifp->name);
+ loginfo("%s: soliciting a DHCPv6 lease", ifp->name);
state = D6_STATE(ifp);
state->state = DH6S_DISCOVER;
state->RTC = 0;
dhcp6_addrequestedaddrs(ifp);
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
else
dhcp6_senddiscover(ifp);
}
struct interface *ifp;
ifp = arg;
- syslog(LOG_ERR, "%s: failed to confirm prior address", ifp->name);
+ logerrx("%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);
+ logerrx("%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);
+ logerrx("%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);
+ logwarnx("%s: failed to renew DHCPv6, rebinding", ifp->name);
else
- syslog(LOG_INFO, "%s: rebinding prior DHCPv6 lease", ifp->name);
+ loginfo("%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);
+ logerr("%s: %s", __func__, ifp->name);
else
dhcp6_sendrebind(ifp);
state->MRCcallback = dhcp6_failrequest;
if (dhcp6_makemessage(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
return;
}
state->MRT = CNF_MAX_RT;
state->MRC = 0;
- syslog(LOG_INFO, "%s: confirming prior DHCPv6 lease", ifp->name);
+ loginfo("%s: confirming prior DHCPv6 lease", ifp->name);
if (dhcp6_makemessage(ifp) == -1) {
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logerr("%s: %s", __func__, 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);
+ loginfo("%s: requesting DHCPv6 information", ifp->name);
state->state = DH6S_INFORM;
state->RTC = 0;
state->IMD = INF_MAX_DELAY;
state->MRC = 0;
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logerr("%s: %s", __func__, 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);
+ logerrx("%s: DHCPv6 lease expired", ifp->name);
dhcp6_freedrop_addrs(ifp, 1, NULL);
#ifndef SMALL
dhcp6_delete_delegates(ifp);
if (ipv6nd_hasradhcp(ifp) || dhcp6_hasprefixdelegation(ifp))
dhcp6_startdiscover(ifp);
else
- syslog(LOG_WARNING, "%s: no advertising IPv6 router wants DHCP",
- ifp->name);
+ logwarnx("%s: no advertising IPv6 router wants DHCP",ifp->name);
}
static void
#endif
if (dhcp6_makemessage(ifp) == -1)
- syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
else {
dhcp6_sendrelease(ifp);
dhcp6_finishrelease(ifp);
else
farg = m;
if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) {
- //syslog(LOG_DEBUG, "%s: no status", ifp->name);
+ //logdebug("%s: no status", ifp->name);
return 0;
}
if (opt_len < sizeof(code)) {
- syslog(LOG_ERR, "%s: status truncated", ifp->name);
+ logerrx("%s: status truncated", ifp->name);
return -1;
}
memcpy(&code, opt, sizeof(code));
}
} else {
if ((sbuf = malloc((size_t)opt_len + 1)) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return false;
}
memcpy(sbuf, opt, opt_len);
status = sbuf;
}
- syslog(LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status);
+ logerrx("%s: DHCPv6 REPLY: %s", ifp->name, status);
free(sbuf);
return -1;
}
d = nd;
if (ol < 24) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA Address option truncated",
- ifp->name);
+ logerrx("%s: IA Address option truncated", ifp->name);
continue;
}
memcpy(&ia, o, ol);
/* RFC 3315 22.6 */
if (ia.pltime > ia.vltime) {
errno = EINVAL;
- syslog(LOG_ERR,
- "%s: IA Address pltime %"PRIu32" > vltime %"PRIu32,
+ logerr("%s: IA Address pltime %"PRIu32
+ " > vltime %"PRIu32,
ifp->name, ia.pltime, ia.vltime);
continue;
}
if (a == NULL) {
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
}
a->iface = ifp;
d = nd;
if (ol < sizeof(pdp)) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA Prefix option truncated",
- ifp->name);
+ logerrx("%s: IA Prefix option truncated", ifp->name);
continue;
}
/* RFC 3315 22.6 */
if (pdp.pltime > pdp.vltime) {
errno = EINVAL;
- syslog(LOG_ERR,
- "%s: IA Prefix pltime %"PRIu32" > vltime %"PRIu32,
+ logerrx("%s: IA Prefix pltime %"PRIu32
+ " > vltime %"PRIu32,
ifp->name, pdp.pltime, pdp.vltime);
continue;
}
if (a == NULL) {
a = calloc(1, sizeof(*a));
if (a == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
}
a->iface = ifp;
if (o == NULL)
continue;
if (ol < 2) {
- syslog(LOG_ERR, "%s: truncated PD Exclude", ifp->name);
+ logerrx("%s: truncated PD Exclude", ifp->name);
continue;
}
a->prefix_exclude_len = *o++;
if (((a->prefix_exclude_len - a->prefix_len - 1) / NBBY) + 1
!= ol)
{
- syslog(LOG_ERR, "%s: PD Exclude length mismatch",
- ifp->name);
+ logerrx("%s: PD Exclude length mismatch", ifp->name);
a->prefix_exclude_len = 0;
continue;
}
o.len = ntohs(o.len);
if (o.len > l || sizeof(o) + o.len > l) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: option overflow", ifp->name);
+ logerrx("%s: option overflow", ifp->name);
break;
}
p = d + sizeof(o);
}
if (o.len < nl) {
errno = EINVAL;
- syslog(LOG_ERR, "%s: IA option truncated", ifp->name);
+ logerrx("%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",
+ logdebug("%s: ignoring unrequested IAID %s",
ifp->name,
hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
buf, sizeof(buf)));
continue;
}
if ( j < ifo->ia_len && ifo->ia[j].ia_type != o.code) {
- syslog(LOG_ERR, "%s: IAID %s: option type mismatch",
+ logerrx("%s: IAID %s: option type mismatch",
ifp->name,
hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
buf, sizeof(buf)));
ia.t2 = ntohl(ia.t2);
/* RFC 3315 22.4 */
if (ia.t2 > 0 && ia.t1 > ia.t2) {
- syslog(LOG_WARNING,
- "%s: IAID %s T1 (%d) > T2 (%d) from %s",
+ logwarnx("%s: IAID %s T1(%d) > T2(%d) from %s",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf,
sizeof(buf)),
if (dhcp6_findpd(ifp, ia.iaid, p, o.len,
acquired) == 0)
{
- syslog(LOG_WARNING,
- "%s: %s: DHCPv6 REPLY missing Prefix",
+ logwarnx("%s: %s: DHCPv6 REPLY missing Prefix",
ifp->name, sfrom);
continue;
}
if (dhcp6_findna(ifp, o.code, ia.iaid, p, o.len,
acquired) == 0)
{
- syslog(LOG_WARNING,
- "%s: %s: DHCPv6 REPLY missing IA Address",
+ logwarnx("%s: %s: DHCPv6 REPLY missing "
+ "IA Address",
ifp->name, sfrom);
continue;
}
struct timespec aq;
if (len <= sizeof(*m)) {
- syslog(LOG_ERR, "%s: DHCPv6 lease truncated", ifp->name);
+ logerrx("%s: DHCPv6 lease truncated", ifp->name);
return -1;
}
nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
if (nia == 0) {
if (state->state != DH6S_CONFIRM && ok != 1) {
- syslog(LOG_ERR, "%s: no useable IA found in lease",
- ifp->name);
+ logerrx("%s: no useable IA found in lease", ifp->name);
return -1;
}
ssize_t bytes;
state = D6_CSTATE(ifp);
- syslog(LOG_DEBUG, "%s: writing lease `%s'",
- ifp->name, state->leasefile);
+ logdebug("%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);
+ logerr(__func__);
return -1;
}
bytes = write(fd, state->new, state->new_len);
state = D6_STATE(ifp);
if (state->leasefile[0] == '\0') {
- syslog(LOG_DEBUG, "reading standard input");
+ logdebug("reading standard input");
fd = fileno(stdin);
fd_opened = false;
} else {
- syslog(LOG_DEBUG, "%s: reading lease `%s'",
- ifp->name, state->leasefile);
+ logdebug("%s: reading lease `%s'", ifp->name, state->leasefile);
fd = open(state->leasefile, O_RDONLY);
if (fd != -1 && fstat(fd, &st) == -1) {
close(fd);
state->leasefile[0] != '\0')
{
if ((time_t)state->expire < now - st.st_mtime) {
- syslog(LOG_DEBUG,"%s: discarding expired lease",
- ifp->name);
+ logdebug("%s: discarding expired lease", ifp->name);
retval = 0;
goto ex;
}
(uint8_t *)state->new, state->new_len, 6, state->new->type,
o, ol) == NULL)
{
- syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
- ifp->name);
- syslog(LOG_ERR, "%s: authentication failed", ifp->name);
+ logdebug("%s: dhcp_auth_validate", __func__);
+ logerr("%s: authentication failed", ifp->name);
goto ex;
}
if (state->auth.token)
- syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+ logdebug("%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_INFO, "%s: accepted reconfigure key",
- ifp->name);
+ loginfo("%s: accepted reconfigure key", ifp->name);
} else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
DHCPCD_AUTH_SENDREQUIRE)
{
- syslog(LOG_ERR, "%s: authentication now required", ifp->name);
+ logerrx("%s: authentication now required", ifp->name);
goto ex;
}
#endif
r = dhcp6_readlease(ifp, 1);
if (r == -1) {
if (errno != ENOENT)
- syslog(LOG_ERR, "%s: dhcp6_readlease: %s: %m",
- ifp->name, state->leasefile);
+ logerr("%s: %s", __func__, state->leasefile);
} else if (r != 0) {
/* RFC 3633 section 12.1 */
#ifndef SMALL
if (prefix->prefix_exclude_len == 0) {
/* Don't spam the log automatically */
if (sla)
- syslog(LOG_WARNING,
- "%s: DHCPv6 server does not support "
+ logwarnx("%s: DHCPv6 server does not support "
"OPTION_PD_EXCLUDE",
ifp->name);
return NULL;
return NULL;
if (fls64(sla->suffix) > 128 - pfxlen) {
- syslog(LOG_ERR, "%s: suffix %" PRIu64 " + prefix_len %d > 128",
+ logerrx("%s: suffix %" PRIu64 " + prefix_len %d > 128",
ifp->name, sla->suffix, pfxlen);
return NULL;
}
} else {
dadcounter = ipv6_makeaddr(&daddr, ifp, &addr, pfxlen);
if (dadcounter == -1) {
- syslog(LOG_ERR,
- "%s: error adding slaac to prefix_len %d",
+ logerrx("%s: error adding slaac to prefix_len %d",
ifp->name, pfxlen);
return NULL;
}
if (ia == NULL) {
ia = calloc(1, sizeof(*ia));
if (ia == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
ia->iface = ifp;
if (!delegated)
dhcpcd_daemonise(ifp->ctx);
} else
- syslog(LOG_DEBUG, "%s: waiting for DHCPv6 DAD to complete",
- ifp->name);
+ logdebug("%s: waiting for DHCPv6 DAD to complete", ifp->name);
}
#ifdef SMALL
if (!(ap->flags & IPV6_AF_DELEGATEDPFX))
continue;
if (!(ap->flags & IPV6_AF_DELEGATEDLOG)) {
+ logfunc_t *logfunc;
+
+ if (ap->flags & IPV6_AF_NEW)
+ logfunc = loginfo;
+ else
+ logfunc = logdebug;
/* We only want to log this the once as we loop
* through many interfaces first. */
ap->flags |= IPV6_AF_DELEGATEDLOG;
- syslog(ap->flags & IPV6_AF_NEW ?
- LOG_INFO : LOG_DEBUG,
- "%s: delegated prefix %s",
+ logfunc("%s: delegated prefix %s",
ifp->name, ap->saddr);
ap->flags &= ~IPV6_AF_NEW;
}
/* no SLA configured, so lets
* automate it */
if (ifd->carrier != LINK_UP) {
- syslog(LOG_DEBUG,
+ logdebug(
"%s: has no carrier, cannot"
" delegate addresses",
ifd->name);
if (strcmp(ifd->name, sla->ifname))
continue;
if (ifd->carrier != LINK_UP) {
- syslog(LOG_DEBUG,
+ logdebug(
"%s: has no carrier, cannot"
" delegate addresses",
ifd->name);
if (strcmp(ifp->name, sla->ifname))
continue;
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
+ logdebug(
"%s: delaying adding"
" delegated addresses for"
" LL address",
}
if (k) {
- syslog(LOG_INFO, "%s: adding delegated prefixes", ifp->name);
+ loginfo("%s: adding delegated prefixes", ifp->name);
state = D6_STATE(ifp);
state->state = DH6S_DELEGATED;
ipv6_addaddrs(&state->addrs);
struct ipv6_addr *ap;
bool valid_op, has_new;
uint32_t u32;
+ logfunc_t *lognewinfo;
#ifdef AUTH
uint8_t *auth;
uint16_t auth_len;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
bytes = recvmsg_realloc(ctx->dhcp6_fd, &ctx->rcvhdr, 0);
if (bytes == -1) {
- syslog(LOG_ERR, "%s: recvmsg: %m", __func__);
+ logerr("%s: recvmsg_realloc", __func__);
close(ctx->dhcp6_fd);
eloop_event_delete(ctx->eloop, ctx->dhcp6_fd);
ctx->dhcp6_fd = -1;
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);
+ logerrx("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",
+ logerrx("DHCPv6 reply did not contain index from %s",
ctx->sfrom);
return;
}
break;
}
if (ifp == NULL) {
- syslog(LOG_DEBUG,
- "DHCPv6 reply for unexpected interface from %s",
+ logdebug("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",
+ logdebug("%s: DHCPv6 reply received but not running",
ifp->name);
return;
}
if (r->type != DHCP6_RECONFIGURE &&
(state->state == DH6S_BOUND || state->state == DH6S_INFORMED))
{
- syslog(LOG_DEBUG, "%s: DHCPv6 reply received but already bound",
+ logdebug("%s: DHCPv6 reply received but already bound",
ifp->name);
return;
}
r->xid[1] != state->send->xid[1] ||
r->xid[2] != state->send->xid[2]))
{
- syslog(LOG_DEBUG, "%s: wrong xid 0x%02x%02x%02x"
+ logdebug("%s: wrong xid 0x%02x%02x%02x"
" (expecting 0x%02x%02x%02x) from %s",
ifp->name,
r->xid[0], r->xid[1], r->xid[2],
}
if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) {
- syslog(LOG_DEBUG, "%s: no DHCPv6 server ID from %s",
+ logdebug("%s: no DHCPv6 server ID from %s",
ifp->name, ctx->sfrom);
return;
}
if (o == NULL || ol != ctx->duid_len ||
memcmp(o, ctx->duid, ol) != 0)
{
- syslog(LOG_DEBUG, "%s: incorrect client ID from %s",
+ logdebug("%s: incorrect client ID from %s",
ifp->name, ctx->sfrom);
return;
}
if (has_option_mask(ifo->requiremask6, opt->option) &&
!dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
{
- syslog(LOG_WARNING,
- "%s: reject DHCPv6 (no option %s) from %s",
+ logwarnx("%s: reject DHCPv6 (no option %s) from %s",
ifp->name, opt->var, ctx->sfrom);
return;
}
if (has_option_mask(ifo->rejectmask6, opt->option) &&
dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
{
- syslog(LOG_WARNING,
- "%s: reject DHCPv6 (option %s) from %s",
+ logwarnx("%s: reject DHCPv6 (option %s) from %s",
ifp->name, opt->var, ctx->sfrom);
return;
}
if (dhcp_auth_validate(&state->auth, &ifo->auth,
(uint8_t *)r, len, 6, r->type, auth, auth_len) == NULL)
{
- syslog(LOG_DEBUG, "dhcp_auth_validate: %m");
- syslog(LOG_ERR, "%s: authentication failed from %s",
+ logdebug("dhcp_auth_validate");
+ logerrx("%s: authentication failed from %s",
ifp->name, ctx->sfrom);
return;
}
if (state->auth.token)
- syslog(LOG_DEBUG,
- "%s: validated using 0x%08" PRIu32,
+ logdebug("%s: validated using 0x%08" PRIu32,
ifp->name, state->auth.token->secretid);
else
- syslog(LOG_INFO,
- "%s: accepted reconfigure key", ifp->name);
+ loginfo("%s: accepted reconfigure key", ifp->name);
} else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
- syslog(LOG_ERR, "%s: no authentication from %s",
+ logerr("%s: no authentication from %s",
ifp->name, ctx->sfrom);
return;
}
- syslog(LOG_WARNING, "%s: no authentication from %s",
+ logwarnx("%s: no authentication from %s",
ifp->name, ctx->sfrom);
}
#endif
memcpy(&max_rt, o, sizeof(max_rt));
max_rt = ntohl(max_rt);
if (max_rt >= 60 && max_rt <= 86400) {
- syslog(LOG_DEBUG, "%s: SOL_MAX_RT %llu -> %u",
+ logdebug("%s: SOL_MAX_RT %llu -> %u",
ifp->name,
(unsigned long long)state->sol_max_rt,
max_rt);
state->sol_max_rt = (time_t)max_rt;
} else
- syslog(LOG_ERR, "%s: invalid SOL_MAX_RT %u",
+ logerr("%s: invalid SOL_MAX_RT %u",
ifp->name, max_rt);
}
o = dhcp6_findmoption(r, len, D6_OPTION_INF_MAX_RT, &ol);
memcpy(&max_rt, o, sizeof(max_rt));
max_rt = ntohl(max_rt);
if (max_rt >= 60 && max_rt <= 86400) {
- syslog(LOG_DEBUG, "%s: INF_MAX_RT %llu -> %u",
+ logdebug("%s: INF_MAX_RT %llu -> %u",
ifp->name,
(unsigned long long)state->inf_max_rt,
max_rt);
state->inf_max_rt = (time_t)max_rt;
} else
- syslog(LOG_ERR, "%s: invalid INF_MAX_RT %u",
+ logerrx("%s: invalid INF_MAX_RT %u",
ifp->name, max_rt);
}
if (dhcp6_validatelease(ifp, r, len, ctx->sfrom, NULL) == -1)
#ifdef AUTH
if (auth == NULL) {
#endif
- syslog(LOG_ERR, "%s: unauthenticated %s from %s",
+ logerrx("%s: unauthenticated %s from %s",
ifp->name, op, ctx->sfrom);
if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
return;
#ifdef AUTH
}
- syslog(LOG_INFO, "%s: %s from %s",
- ifp->name, op, ctx->sfrom);
+ loginfo("%s: %s from %s", ifp->name, op, ctx->sfrom);
o = dhcp6_findmoption(r, len, D6_OPTION_RECONF_MSG, &ol);
if (o == NULL) {
- syslog(LOG_ERR,
- "%s: missing Reconfigure Message option",
+ logerrx("%s: missing Reconfigure Message option",
ifp->name);
return;
}
if (ol != 1) {
- syslog(LOG_ERR, "%s: missing Reconfigure Message type",
+ logerrx("%s: missing Reconfigure Message type",
ifp->name);
return;
}
switch(*o) {
case DHCP6_RENEW:
if (state->state != DH6S_BOUND) {
- syslog(LOG_ERR, "%s: not bound, ignoring %s",
+ logerrx("%s: not bound, ignoring %s",
ifp->name, op);
return;
}
break;
case DHCP6_INFORMATION_REQ:
if (state->state != DH6S_INFORMED) {
- syslog(LOG_ERR, "%s: not informed, ignoring %s",
+ logerrx("%s: not informed, ignoring %s",
ifp->name, op);
return;
}
dhcp6_startinform(ifp);
break;
default:
- syslog(LOG_ERR, "%s: unsupported %s type %d",
+ logerr("%s: unsupported %s type %d",
ifp->name, op, *o);
break;
}
return;
#endif
default:
- syslog(LOG_ERR, "%s: invalid DHCP6 type %s (%d)",
+ logerrx("%s: invalid DHCP6 type %s (%d)",
ifp->name, op, r->type);
return;
}
if (!valid_op) {
- syslog(LOG_WARNING, "%s: invalid state for DHCP6 type %s (%d)",
+ logwarnx("%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);
+ logerr(__func__);
return;
}
}
}
if (ap == NULL)
ap = TAILQ_FIRST(&state->addrs);
- syslog(LOG_INFO, "%s: ADV %s from %s",
- ifp->name, ap->saddr, ctx->sfrom);
+ loginfo("%s: ADV %s from %s", ifp->name, ap->saddr, ctx->sfrom);
if (ifp->ctx->options & DHCPCD_TEST)
break;
dhcp6_startrequest(ifp);
break;
}
}
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
- "%s: %s received from %s", ifp->name, op, ctx->sfrom);
+ lognewinfo = has_new ? loginfo : logdebug;
+ lognewinfo("%s: %s received from %s", ifp->name, op, ctx->sfrom);
state->reason = NULL;
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
if (ap->flags & IPV6_AF_STALE)
continue;
if (ap->prefix_vltime <= state->renew)
- syslog(LOG_WARNING,
+ logwarnx(
"%s: %s will expire before renewal",
ifp->name, ap->saddr);
else
* and T2 fields for the T1 and T2 parameters,
* unless those values in those fields are 0.
*/
- syslog(LOG_WARNING,
- "%s: ignoring T1 %"PRIu32
+ logwarnx("%s: ignoring T1 %"PRIu32
" to due address expiry",
ifp->name, state->renew);
state->renew = state->rebind = 0;
ipv6_addaddrs(&state->addrs);
if (state->state == DH6S_INFORMED)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
- "%s: refresh in %"PRIu32" seconds",
+ lognewinfo("%s: refresh in %"PRIu32" seconds",
ifp->name, state->renew);
else if (state->renew || state->rebind)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
- "%s: renew in %"PRIu32", "
+ lognewinfo("%s: renew in %"PRIu32", "
"rebind in %"PRIu32", "
"expire in %"PRIu32" seconds",
ifp->name,
state->renew, state->rebind, state->expire);
else if (state->expire == 0)
- syslog(has_new ? LOG_INFO : LOG_DEBUG,
- "%s: will expire", ifp->name);
+ lognewinfo("%s: will expire", ifp->name);
if_initrt(ifp->ctx, AF_INET6);
rt_build(ifp->ctx, AF_INET6);
dhcp6_writelease(ifp);
n = 1;
if (setsockopt(ctx->dhcp6_fd, SOL_SOCKET, SO_REUSEPORT,
&n, sizeof(n)) == -1)
- syslog(LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
+ logerr("SO_REUSEPORT");
#endif
if (!(ctx->options & DHCPCD_MASTER)) {
sla = &ia->sla[j];
ifd = if_find(ifp->ctx->ifaces, sla->ifname);
if (ifd == NULL) {
- syslog(LOG_WARNING,
- "%s: cannot delegate to %s: %m",
+ logwarn("%s: cannot delegate to %s",
ifp->name, sla->ifname);
continue;
}
if (!ifd->active) {
- syslog(LOG_INFO,
- "%s: activating for delegation",
+ loginfo("%s: activating for delegation",
sla->ifname);
dhcpcd_activateinterface(ifd,
DHCPCD_IPV6 | DHCPCD_DHCP6);
dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
AF_INET6, ifp);
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
- "%s: delaying DHCPv6 soliciation for LL address",
+ logdebug("%s: delaying DHCPv6 soliciation for LL address",
ifp->name);
ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp);
return 0;
i = strlen(prefix) + strlen("_dhcp6") + 1;
pfx = malloc(i);
if (pfx == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__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__);
+ logerr(__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__);
+ logerr(__func__);
return -1;
}
TAILQ_INIT(&state->addrs);
dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
AF_INET6, ifp);
if (dhcp6_readlease(ifp, 0) == -1) {
- syslog(LOG_ERR, "%s: %s: %m",
- *ifp->name ? ifp->name : state->leasefile, __func__);
+ logerr("%s: %s", __func__,
+ *ifp->name ? ifp->name : state->leasefile);
return -1;
}
state->reason = "DUMP6";
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 2, 2017
+.Dd April 8, 2017
.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 truncated when opened and 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>
#include "ipv4ll.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "script.h"
#ifdef HAVE_UTIL_H
struct dhcpcd_ctx *ctx;
ctx = arg;
- syslog(LOG_ERR, "timed out");
+ logerrx("timed out");
if (!(ctx->options & DHCPCD_MASTER)) {
eloop_exit(ctx->eloop, EXIT_FAILURE);
return;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
- syslog(LOG_DEBUG,
- "%s: waiting for an %s address",
+ logdebug("%s: waiting for an %s address",
ifp->name, dhcpcd_af(af));
return 0;
}
}
if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) {
- syslog(LOG_DEBUG,
- "waiting for an %s address",
+ logdebug("waiting for an %s address",
dhcpcd_af(af));
return 0;
}
}
if (ctx->options & DHCPCD_ONESHOT) {
- syslog(LOG_INFO, "exiting due to oneshot");
+ loginfo("exiting due to oneshot");
eloop_exit(ctx->eloop, EXIT_SUCCESS);
return 0;
}
if (ctx->options & DHCPCD_DAEMONISED ||
!(ctx->options & DHCPCD_DAEMONISE))
return 0;
- syslog(LOG_DEBUG, "forking to background");
+ logdebug("forking to background");
/* Setup a signal pipe so parent knows when to exit. */
if (pipe(sidpipe) == -1) {
- syslog(LOG_ERR, "pipe: %m");
+ logerr("%s: pipe", __func__);
return 0;
}
switch (pid = fork()) {
case -1:
- syslog(LOG_ERR, "fork: %m");
+ logerr("%s: fork", __func__);
return 0;
case 0:
if ((lpid = pidfile_lock(ctx->pidfile)) != 0)
- syslog(LOG_ERR, "%s: pidfile_lock %d: %m",
- __func__, lpid);
+ logerr("%s: pidfile_lock %d", __func__, lpid);
setsid();
/* 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");
+ logerr("%s: write", __func__);
close(sidpipe[1]);
/* 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");
+ logerr("%s: eloop_requeue", __func__);
eloop_exit(ctx->eloop, EXIT_FAILURE);
}
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
/* Wait for child to detach */
close(sidpipe[1]);
if (read(sidpipe[0], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to read child: %m");
+ logerr("%s: read", __func__);
close(sidpipe[0]);
- syslog(LOG_INFO, "forked to background, child pid %d", pid);
+ loginfo("forked to background, child pid %d", pid);
ctx->options |= DHCPCD_FORKED;
eloop_exit(ctx->eloop, EXIT_SUCCESS);
return pid;
struct dhcpcd_ctx *ctx;
ctx = ifp->ctx;
- syslog(LOG_INFO, "%s: removing interface", ifp->name);
+ loginfo("%s: removing interface", ifp->name);
ifp->options->options |= DHCPCD_STOPPING;
dhcpcd_drop(ifp, 1);
{
ifo->ia = malloc(sizeof(*ifo->ia));
if (ifo->ia == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
else {
ifo->ia_len = 1;
ifo->ia->ia_type = D6_OPTION_IA_NA;
r = print_string(pssid, sizeof(pssid), OT_ESCSTRING,
ifp->ssid, ifp->ssid_len);
if (r == -1) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr(__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);
+ logdebug("%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",
- ifp->name, profile);
+ loginfo("%s: selected profile %s", ifp->name, profile);
} else
*ifp->profile = '\0';
/* If the mtime has changed drop any old lease */
if (old != 0 && ifp->options->mtime != old) {
- syslog(LOG_WARNING,
- "%s: confile file changed, expiring leases", ifp->name);
+ logwarnx("%s: confile file changed, expiring leases",
+ ifp->name);
dhcpcd_drop(ifp, 0);
}
}
if (options) {
if ((ifo = default_config(ifp->ctx)) == NULL) {
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr(__func__);
return;
}
ifo->options |= options;
ifo = ifp->options;
if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) {
- syslog(LOG_ERR, "ipv6_init: %m");
+ logerr(__func__);
ifo->options &= ~DHCPCD_IPV6;
}
}
if (carrier == LINK_UNKNOWN) {
if (errno != ENOTTY) /* For example a PPP link on BSD */
- syslog(LOG_ERR, "%s: carrier_status: %m", ifname);
+ logerr("%s: %s", ifp->name, __func__);
} 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);
+ loginfo("%s: carrier lost", ifp->name);
ifp->carrier = LINK_DOWN;
script_runreason(ifp, "NOCARRIER");
#ifdef NOCARRIER_PRESERVE_IP
}
} else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
if (ifp->carrier != LINK_UP) {
- syslog(LOG_INFO, "%s: carrier acquired", ifp->name);
+ loginfo("%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)
- syslog(LOG_ERR,
- "%s: IAID conflicts with one assigned to %s",
+ logerr("%s: IAID conflicts with one assigned to %s",
ifp->name, ifn->name);
}
case LINK_UP:
break;
case LINK_DOWN:
- syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
+ loginfo("%s: waiting for carrier", ifp->name);
return;
case LINK_UNKNOWN:
/* No media state available.
if (ifp->ctx->duid == NULL) {
if (duid_init(ifp) == 0)
return;
- syslog(LOG_INFO, "DUID %s",
+ loginfo("DUID %s",
hwaddr_ntoa(ifp->ctx->duid,
ifp->ctx->duid_len,
buf, sizeof(buf)));
if (ifo->options & (DHCPCD_DUID | DHCPCD_IPV6)) {
/* Report IAIDs */
- syslog(LOG_INFO, "%s: IAID %s", ifp->name,
+ loginfo("%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",
+ loginfo("%s: IAID %s",
ifp->name, hwaddr_ntoa(ifo->ia[i].iaid,
sizeof(ifo->ia[i].iaid),
buf, sizeof(buf)));
}
if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
- syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
+ logerr("%s: ipv6_start", ifp->name);
ifo->options &= ~DHCPCD_IPV6;
}
if (ifo->options & DHCPCD_IPV6) {
#endif
}
if (nolease == -1)
- syslog(LOG_ERR, "%s: dhcp6_start: %m",
- ifp->name);
+ logerr("%s: dhcp6_start", ifp->name);
}
}
if ((!(ifp->ctx->options & DHCPCD_MASTER) ||
ifp->options->options & DHCPCD_IF_UP) &&
if_up(ifp) == -1)
- syslog(LOG_ERR, "%s: if_up: %m", ifp->name);
+ logerr("%s: %s", __func__, ifp->name);
if (ifp->options->options & DHCPCD_LINK &&
ifp->carrier == LINK_UNKNOWN)
ifp->flags, ifp->name);
return;
}
- syslog(LOG_INFO,
- "%s: unknown carrier, waiting for interface flags",
+ loginfo("%s: unknown carrier, waiting for interface flags",
ifp->name);
}
ctx = arg;
if (if_handlelink(ctx) == -1) {
- syslog(LOG_ERR, "if_handlelink: %m");
+ logerr(__func__);
eloop_event_delete(ctx->eloop, ctx->link_fd);
close(ctx->link_fd);
ctx->link_fd = -1;
return -1;
}
if (ifp->active) {
- syslog(LOG_DEBUG, "%s: interface departed",
- ifp->name);
+ logdebug("%s: interface departed", ifp->name);
ifp->options->options |= DHCPCD_DEPARTED;
stop_interface(ifp);
}
i = -1;
ifs = if_discover(ctx, -1, UNCONST(argv));
if (ifs == NULL) {
- syslog(LOG_ERR, "%s: if_discover: %m", __func__);
+ logerr(__func__);
return -1;
}
TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
iff = if_find(ctx->ifaces, ifp->name);
if (iff) {
if (iff->active)
- syslog(LOG_DEBUG, "%s: interface updated",
- iff->name);
+ logdebug("%s: interface updated", iff->name);
/* The flags and hwaddr could have changed */
iff->flags = ifp->flags;
iff->hwlen = ifp->hwlen;
TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
if (!ifp->active)
continue;
- syslog(LOG_DEBUG, "%s: interface added", ifp->name);
+ logdebug("%s: interface added", ifp->name);
dhcpcd_initstate(ifp, 0);
run_preinit(ifp);
iff = ifp;
if (hwlen > sizeof(ifp->hwaddr)) {
errno = ENOBUFS;
- syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+ logerr("%s: %s", __func__, ifp->name);
return;
}
if (ifp->hwlen == hwlen && memcmp(ifp->hwaddr, hwaddr, hwlen) == 0)
return;
- syslog(LOG_INFO, "%s: new hardware address: %s", ifp->name,
+ loginfo("%s: new hardware address: %s", ifp->name,
hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
ifp->hwlen = hwlen;
memcpy(ifp->hwaddr, hwaddr, hwlen);
exit_code = EXIT_FAILURE;
switch (sig) {
case SIGINT:
- syslog(LOG_INFO, sigmsg, "SIGINT", "stopping");
+ loginfo(sigmsg, "SIGINT", "stopping");
break;
case SIGTERM:
- syslog(LOG_INFO, sigmsg, "SIGTERM", "stopping");
+ loginfo(sigmsg, "SIGTERM", "stopping");
exit_code = EXIT_SUCCESS;
break;
case SIGALRM:
- syslog(LOG_INFO, sigmsg, "SIGALRM", "releasing");
+ loginfo(sigmsg, "SIGALRM", "releasing");
opts |= DHCPCD_RELEASE;
exit_code = EXIT_SUCCESS;
break;
case SIGHUP:
- syslog(LOG_INFO, sigmsg, "SIGHUP", "rebinding");
+ loginfo(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, "SIGUSR1", "renewing");
+ loginfo(sigmsg, "SIGUSR1", "renewing");
dhcpcd_renew(ctx);
return;
case SIGUSR2:
- closelog();
- openlog(NULL, ctx->log_opts, LOG_DAEMON);
- syslog(LOG_INFO, sigmsg, "SIGUSR2", "reopened syslog");
+ loginfo(sigmsg, "SIGUSR2", "reopening log");
+ logclose();
+ if (logopen(ctx->logfile) == -1)
+ logerr(__func__);
return;
case SIGPIPE:
- syslog(LOG_WARNING, "received SIGPIPE");
+ logwarnx("received SIGPIPE");
return;
default:
- syslog(LOG_ERR, "received signal %d, "
- "but don't know what to do with it",
+ logerrx("received signal %d but don't know what to do with it",
sig);
return;
}
if (!ifp->active)
continue;
if (send_interface(fd, ifp) == -1)
- syslog(LOG_ERR, "send_interface %d: %m", fd->fd);
+ logerr(__func__);
}
}
*p++ = ' ';
}
*--p = '\0';
- syslog(LOG_INFO, "control command: %s", tmp);
+ loginfo("control command: %s", tmp);
free(tmp);
optind = 0;
struct interface *ifp;
uint16_t family = 0;
int opt, oi = 0, i;
+ unsigned int logopts;
time_t t;
ssize_t len;
#if defined(USE_SIGNALS) || !defined(THERE_IS_NO_FORK)
#ifdef INET
ctx.udp_fd = -1;
#endif
- ctx.log_opts = LOG_PID;
-#ifdef LOG_PERROR
- ctx.log_opts |= LOG_PERROR;
-#endif
-#ifdef LOG_PTRIM
- ctx.log_opts |= LOG_PTRIM;
-#endif
+ logopts = LOGERR_WLOG;
i = 0;
while ((opt = getopt_long(argc, argv,
ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
case 'f':
ctx.cffile = optarg;
break;
+ case 'j':
+ free(ctx.logfile);
+ ctx.logfile = strdup(optarg);
+ break;
#ifdef USE_SIGNALS
case 'k':
sig = SIGALRM;
i = 4;
break;
case 'q':
-#ifdef LOG_PERROR
- ctx.log_opts &= ~LOG_PERROR;
+ logopts |= LOGERR_QUIET;
break;
-#endif
case 'x':
sig = SIGTERM;
siga = "TERM";
break;
case 'T':
i = 1;
-#ifdef LOG_NLOG
- ctx.log_opts |= LOG_NLOG;
-#endif
+ logopts &= ~LOGERR_WLOG;
break;
case 'U':
i = 3;
}
}
- openlog(NULL, ctx.log_opts, LOG_DAEMON);
- setlogmask(LOG_UPTO(LOG_INFO));
+ logsetopts(logopts);
+ logopen(ctx.logfile);
ctx.argv = argv;
ctx.argc = argc;
#endif
if (ctx.options & DHCPCD_DEBUG)
- setlogmask(LOG_UPTO(LOG_DEBUG));
+ logsetopts(logopts | LOGERR_DEBUG);
if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
printpidfile:
const char *per;
if (strlen(argv[optind]) > IF_NAMESIZE) {
- syslog(LOG_ERR,
- "%s: interface name too long",
+ logerrx("%s: interface name too long",
argv[optind]);
goto exit_failure;
}
}
if (chdir("/") == -1)
- syslog(LOG_ERR, "chdir `/': %m");
+ logerr("%s: chdir `/'", __func__);
/* Freeing allocated addresses from dumping leases can trigger
* eloop removals as well, so init here. */
if ((ctx.eloop = eloop_new()) == NULL) {
- syslog(LOG_ERR, "%s: eloop_init: %m", __func__);
+ logerr("%s: eloop_init", __func__);
goto exit_failure;
}
if (sig == 0) {
#endif
if (if_opensockets(&ctx) == -1) {
- syslog(LOG_ERR, "if_opensockets: %m");
+ logerr("%s: if_opensockets", __func__);
goto exit_failure;
}
#ifdef USE_SIGNALS
TAILQ_INIT(ctx.ifaces);
}
if (ctx.ifaces == NULL) {
- syslog(LOG_ERR, "if_discover: %m");
+ logerr("%s: if_discover", __func__);
goto exit_failure;
}
ifp = if_find(ctx.ifaces, argv[optind]);
if (ifp == NULL) {
ifp = calloc(1, sizeof(*ifp));
if (ifp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
goto exit_failure;
}
if (optind != argc)
if (ctx.control_fd == -1)
ctx.control_fd = control_open(NULL);
if (ctx.control_fd != -1) {
- syslog(LOG_INFO,
- "sending commands to master dhcpcd process");
+ loginfo("sending commands to master dhcpcd process");
len = control_send(&ctx, argc, argv);
control_close(&ctx);
if (len > 0) {
- syslog(LOG_DEBUG, "send OK");
+ logdebug("send OK");
goto exit_success;
} else {
- syslog(LOG_ERR, "failed to send commands");
+ logerr("%s: control_send", __func__);
goto exit_failure;
}
} else {
if (errno != ENOENT)
- syslog(LOG_ERR, "control_open: %m");
+ logerr("%s: control_open", __func__);
}
#ifdef USE_SIGNALS
}
if (sig != 0) {
pid = pidfile_read(ctx.pidfile);
if (pid != 0 && pid != -1)
- syslog(LOG_INFO, "sending signal %s to pid %d",
- siga, pid);
+ loginfo("sending signal %s to pid %d", siga, pid);
if (pid == 0 || pid == -1 || kill(pid, sig) != 0) {
if (sig != SIGHUP && sig != SIGUSR1 && errno != EPERM)
- syslog(LOG_ERR, ""PACKAGE" not running");
+ logerrx(PACKAGE" not running");
if (pid != 0 && pid != -1 && errno != ESRCH) {
- syslog(LOG_ERR, "kill: %m");
+ logerr("kill");
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);
+ loginfo("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 (pidfile_read(ctx.pidfile) == -1)
goto exit_success;
}
- syslog(LOG_ERR, "pid %d failed to exit", pid);
+ logerrx("pid %d failed to exit", pid);
goto exit_failure;
}
}
if (!(ctx.options & DHCPCD_TEST)) {
/* Ensure we have the needed directories */
if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
- syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR);
+ logerr("%s: mkdir `%s'", __func__, RUNDIR);
if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST)
- syslog(LOG_ERR, "mkdir `%s': %m", DBDIR);
+ logerr("%s: mkdir `%s'", __func__, DBDIR);
if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
if (pid == -1)
- syslog(LOG_ERR, "%s: pidfile_lock: %m",
- __func__);
+ logerr("%s: pidfile_lock", __func__);
else
- syslog(LOG_ERR, ""PACKAGE
+ logerrx(PACKAGE
" already running on pid %d (%s)",
pid, ctx.pidfile);
goto exit_failure;
if (ctx.options & DHCPCD_MASTER) {
if (control_start(&ctx, NULL) == -1)
- syslog(LOG_ERR, "control_start: %m");
+ logerr("%s: control_start", __func__);
}
#else
if (control_start(&ctx,
ctx.options & DHCPCD_MASTER ? NULL : argv[optind]) == -1)
{
- syslog(LOG_ERR, "control_start: %m");
+ logerr("%s: control_start", __func__);
goto exit_failure;
}
#endif
- syslog(LOG_DEBUG, PACKAGE "-" VERSION " starting");
+ logdebug(PACKAGE "-" VERSION " starting");
ctx.options |= DHCPCD_STARTED;
#ifdef USE_SIGNALS
if (eloop_signal_set_cb(ctx.eloop,
dhcpcd_signals, dhcpcd_signals_len,
signal_cb, &ctx) == -1)
{
- syslog(LOG_ERR, "eloop_signal_set_cb: %m");
+ logerr("%s: eloop_signal_set_cb", __func__);
goto exit_failure;
}
/* Save signal mask, block and redirect signals to our handler */
if (eloop_signal_mask(ctx.eloop, &ctx.sigset) == -1) {
- syslog(LOG_ERR, "eloop_signal_mask: %m");
+ logerr("%s: eloop_signal_mask", __func__);
goto exit_failure;
}
#endif
ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
if (ctx.ifaces == NULL) {
- syslog(LOG_ERR, "if_discover: %m");
+ logerr("%s: if_discover", __func__);
goto exit_failure;
}
for (i = 0; i < ctx.ifc; i++) {
if ((ifp = if_find(ctx.ifaces, ctx.ifv[i])) == NULL ||
!ifp->active)
- syslog(LOG_ERR, "%s: interface not found or invalid",
+ logerrx("%s: interface not found or invalid",
ctx.ifv[i]);
}
TAILQ_FOREACH(ifp, ctx.ifaces, next) {
break;
}
if (ifp == NULL) {
- if (ctx.ifc == 0)
- syslog(ctx.options & DHCPCD_INACTIVE ?
- LOG_DEBUG : LOG_ERR,
- "no valid interfaces found");
- else
+ if (ctx.ifc == 0) {
+ logfunc_t *logfunc;
+
+ logfunc = ctx.options & DHCPCD_INACTIVE ?
+ logdebug : logerrx;
+ logfunc("no valid interfaces found");
+ } else
goto exit_failure;
if (!(ctx.options & DHCPCD_LINK)) {
- syslog(LOG_ERR,
- "aborting as link detection is disabled");
+ logerr("aborting as link detection is disabled");
goto exit_failure;
}
}
ctx.options & DHCPCD_LINK &&
!(ctx.options & DHCPCD_WAITIP))
{
- syslog(ctx.options & DHCPCD_INACTIVE ?
- LOG_DEBUG : LOG_WARNING,
- "no interfaces have a carrier");
+ logfunc_t *logfunc;
+
+ logfunc = ctx.options & DHCPCD_INACTIVE ?
+ logdebug : logwarnx;
+ logfunc("no interfaces have a carrier");
if (dhcpcd_daemonise(&ctx))
goto exit_success;
} else if (t > 0 &&
i = eloop_start(ctx.eloop, &ctx.sigset);
if (i < 0) {
- syslog(LOG_ERR, "eloop_start: %m");
+ logerr("%s: eloop_start", __func__);
goto exit_failure;
}
goto exit1;
exit1:
if (control_stop(&ctx) == -1)
- syslog(LOG_ERR, "control_stop: %m:");
+ logerr("%s: control_stop", __func__);
/* Free memory and close fd's */
if (ctx.ifaces) {
while ((ifp = TAILQ_FIRST(ctx.ifaces))) {
free(ctx.iov[0].iov_base);
if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED))
- syslog(LOG_INFO, PACKAGE " exited");
- closelog();
+ loginfo(PACKAGE " exited");
+ logclose();
#ifdef USE_SIGNALS
if (ctx.options & DHCPCD_FORKED)
_exit(i); /* so atexit won't remove our pidfile */
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 2, 2017
+.Dd April 8, 2017
.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 truncated when opened and 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;
- int log_opts;
+ char *logfile;
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>
#include "common.h"
#include "dhcpcd.h"
#include "duid.h"
+#include "logerr.h"
static size_t
duid_make(uint8_t *d, const struct interface *ifp, uint16_t type)
*d = data;
return len;
}
- syslog(LOG_ERR, "DUID too big (max %u): %s", DUID_LEN, DUID);
+ logerrx("DUID too big (max %u): %s", DUID_LEN, DUID);
/* Keep the buffer, will assign below. */
} else {
if (errno != ENOENT)
- syslog(LOG_ERR, "error reading DUID: %s: %m", DUID);
+ logerr("%s", DUID);
if ((data = malloc(DUID_LEN)) == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
return 0;
}
}
/* No file? OK, lets make one based on our interface */
if (ifp->family == ARPHRD_NETROM) {
- syslog(LOG_WARNING, "%s: is a NET/ROM pseudo interface",
- ifp->name);
+ logwarnx("%s: is a NET/ROM pseudo interface", ifp->name);
TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
if (ifp2->family != ARPHRD_NETROM)
break;
}
if (ifp2) {
ifp = ifp2;
- syslog(LOG_WARNING,
- "picked interface %s to generate a DUID",
+ logwarnx("picked interface %s to generate a DUID",
ifp->name);
} else {
- syslog(LOG_WARNING,
- "no interfaces have a fixed hardware address");
+ logwarnx("no interfaces have a fixed hardware "
+ "address");
return duid_make(data, ifp, DUID_LL);
}
}
if (!(fp = fopen(DUID, "w"))) {
- syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+ logerr("%s", DUID);
return duid_make(data, ifp, DUID_LL);
}
len = duid_make(data, ifp, DUID_LLT);
x = -1;
/* Failed to write the duid? scrub it, we cannot use it */
if (x < 1) {
- syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+ logerr("%s", DUID);
unlink(DUID);
return duid_make(data, ifp, DUID_LL);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#if defined(OpenBSD) && OpenBSD >= 201411
#include "ipv4ll.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "route.h"
#include "sa.h"
#ifdef ROUTE_MSGFILTER
if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
&msgfilter, sizeof(msgfilter)) == -1)
- syslog(LOG_ERR, "ROUTE_MSGFILTER: %m");
+ logerr(__func__);
#endif
return ctx->link_fd == -1 ? -1 : 0;
ifr_sin->sin_family = AF_INET;
ifr_sin->sin_addr = addr;
if (ioctl(ctx->pf_inet_fd, SIOCGIFADDR, &ifr) == 0) {
- syslog(LOG_WARNING,
- "%s: ignored false RTM_DELADDR for %s",
+ logwarnx("%s: ignored false RTM_DELADDR for %s",
ifp->name, inet_ntoa(addr));
break;
}
if (ifam->ifam_type == RTM_DELADDR)
addrflags = 0 ;
else if ((addrflags = if_addrflags(ifp, &addr, NULL)) == -1) {
- syslog(LOG_ERR, "%s: if_addrflags: %s: %m",
+ logerr("%s: if_addrflags: %s",
ifp->name, inet_ntoa(addr));
break;
}
if (ifam->ifam_type == RTM_DELADDR)
addrflags = 0;
else if ((addrflags = if_addrflags6(ifp, &addr6, NULL)) == -1) {
- syslog(LOG_ERR, "%s: if_addrflags6: %m", ifp->name);
+ logerr("%s: if_addrflags6", ifp->name);
break;
}
#endif
if (!(ctx->options & DHCPCD_TEST) &&
flags & ND6_IFF_AUTO_LINKLOCAL)
{
- syslog(LOG_DEBUG,
- "%s: disabling Kernel IPv6 auto link-local support",
+ logdebug("%s: disabling Kernel IPv6 auto "
+ "link-local support",
ifp->name);
flags &= ~ND6_IFF_AUTO_LINKLOCAL;
}
if (!(ctx->options & DHCPCD_TEST) &&
flags & ND6_IFF_ACCEPT_RTADV)
{
- syslog(LOG_DEBUG,
- "%s: disabling Kernel IPv6 RA support",
+ logdebug("%s: disabling Kernel IPv6 RA support",
ifp->name);
flags &= ~ND6_IFF_ACCEPT_RTADV;
}
if (nd.ndi.flags != (uint32_t)flags) {
if (ctx->options & DHCPCD_TEST) {
- syslog(LOG_WARNING,
- "%s: interface not IPv6 enabled",
+ logwarnx("%s: interface not IPv6 enabled",
ifp->name);
return -1;
}
nd.ndi.flags = (uint32_t)flags;
if (ioctl(s, SIOCSIFINFO_FLAGS, &nd) == -1) {
- syslog(LOG_ERR, "%s: SIOCSIFINFO_FLAGS: %m",
- ifp->name);
+ logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
return -1;
}
}
* LLADDR auto configuration are disabled where applicable. */
#ifdef SIOCIFAFATTACH
if (af_attach(s, ifp, AF_INET6) == -1) {
- syslog(LOG_ERR, "%s: af_attach: %m", ifp->name);
+ logerr("%s: af_attach", ifp->name);
return -1;
}
#endif
#ifdef SIOCGIFXFLAGS
if (set_ifxflags(s, ifp) == -1) {
- syslog(LOG_ERR, "%s: set_ifxflags: %m", ifp->name);
+ logerr("%s: set_ifxflags", ifp->name);
return -1;
}
#endif
#ifdef IPV6CTL_ACCEPT_RTADV
ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
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,
- "IPV6CTL_ACCEPT_RTADV: %m");
+ if (errno == ENOENT)
+ ra = 0;
+ else
+ logerr("IPV6CTL_ACCEPT_RTADV");
else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
- syslog(LOG_DEBUG, "disabling Kernel IPv6 RA support");
+ logdebug("disabling Kernel IPv6 RA support");
if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) {
- syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
+ logerr("IPV6CTL_ACCEPT_RTADV");
return ra;
}
ra = 0;
* and prefixes so the kernel does not expire prefixes
* and default routes we are trying to own. */
if (if_raflush(s) == -1)
- syslog(LOG_WARNING, "if_raflush: %m");
+ logwarn("if_raflush");
}
ctx->ra_global = ra;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "ipv4ll.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "route.h"
#include "sa.h"
ifname = "all";
else if (!(ctx->options & DHCPCD_TEST)) {
if (if_disable_autolinklocal(ctx, ifp->index) == -1)
- syslog(LOG_DEBUG, "%s: if_disable_autolinklocal: %m",
- ifp->name);
+ logdebug("%s: if_disable_autolinklocal: %s",
+ ifp->name, strerror(errno));
}
if (ifp)
ifname = ifp->name;
ra = check_proc_int(path);
if (ra != 1) {
if (ctx->options & DHCPCD_TEST)
- syslog(LOG_WARNING, "%s: IPv6 kernel autoconf disabled",
- ifname);
+ logwarnx("%s: IPv6 kernel autoconf disabled", ifname);
} else if (ra != -1 && !(ctx->options & DHCPCD_TEST)) {
if (write_path(path, "0") == -1) {
- syslog(LOG_ERR, "write_path: %s: %m", path);
+ logerr("%s: %s", __func__, path);
return -1;
}
}
snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname);
ra = check_proc_int(path);
- if (ra == -1)
+ if (ra == -1) {
+ logfunc_t *logfunc = errno == ENOENT? logdebug : logwarnx;
+
/* 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, "%s: %m", path);
- else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
- syslog(LOG_DEBUG, "%s: disabling kernel IPv6 RA support",
- ifname);
+ logfunc("%s: %s", path, strerror(errno));
+ } else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
+ logdebug("%s: disabling kernel IPv6 RA support", ifname);
if (write_path(path, "0") == -1) {
- syslog(LOG_ERR, "write_path: %s: %m", path);
+ logerr("%s: %s", __func__, path);
return ra;
}
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <time.h>
#include "if.h"
#include "if-options.h"
#include "ipv4.h"
+#include "logerr.h"
#include "sa.h"
/* These options only make sense in the config file, so don't use any
{"reconfigure", no_argument, NULL, 'g'},
{"hostname", optional_argument, NULL, 'h'},
{"vendorclassid", optional_argument, NULL, 'i'},
+ {"logfile", optional_argument, NULL, 'j'},
{"release", no_argument, NULL, 'k'},
{"leasetime", required_argument, NULL, 'l'},
{"metric", required_argument, NULL, 'm'},
match = strdup(value);
if (match == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
p = strchr(match, '=');
if (p == NULL) {
- syslog(LOG_ERR, "%s: no assignment: %s", __func__, value);
+ logerrx("%s: no assignment: %s", __func__, value);
free(match);
return NULL;
}
if (uniq) {
n = strdup(value);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(match);
return NULL;
}
lv = strlen(p);
n = realloc(lst[i], l + lv + 2);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(match);
return NULL;
}
free(match);
n = strdup(value);
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
newlist = reallocarray(lst, i + 2, sizeof(char *));
if (newlist == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(n);
return NULL;
}
char *o = strdup(arg), *p, *t, *nt;
if (o == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return v;
}
p = o;
while ((t = strsep(&p, ", "))) {
nt = strdup(t);
if (nt == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(o);
return v;
}
n = reallocarray(v, (size_t)(*argc) + 1, sizeof(char *));
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(o);
free(nt);
return v;
if (e != 0 ||
(net != NULL && inet_cidrtoaddr((int)i, net) != 0))
{
- syslog(LOG_ERR, "`%s' is not a valid CIDR", p);
+ logerrx("`%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);
+ logerrx("`%s' is not a valid IP address", arg);
return -1;
}
if (p != NULL)
__unused const char *arg)
{
- syslog(LOG_ERR, "No IPv4 support");
+ logerrx("No IPv4 support");
return -1;
}
#endif
free(ifo->script);
ifo->script = strdup(arg);
if (ifo->script == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
case 'd':
ifo->options |= DHCPCD_DEBUG;
}
s = parse_string(ifo->hostname, HOSTNAME_MAX_LEN, arg);
if (s == -1) {
- syslog(LOG_ERR, "hostname: %m");
+ logerr("%s: hostname", __func__);
return -1;
}
if (s != 0 && ifo->hostname[0] == '.') {
- syslog(LOG_ERR, "hostname cannot begin with .");
+ logerrx("hostname cannot begin with .");
return -1;
}
ifo->hostname[s] = '\0';
else
s = 0;
if (s == -1) {
- syslog(LOG_ERR, "vendorclassid: %m");
+ logerr("vendorclassid");
return -1;
}
*ifo->vendorclassid = (uint8_t)s;
break;
+ case 'j':
+ ARG_REQUIRED;
+ /* per interface logging is not supported
+ * don't want to overide the commandline */
+ if (ifname == NULL && ctx->logfile == NULL) {
+ logclose();
+ ctx->logfile = strdup(arg);
+ logopen(ctx->logfile);
+ }
+ 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);
+ logerrx("failed to convert leasetime %s", arg);
return -1;
}
break;
ARG_REQUIRED;
ifo->metric = (int)strtoi(arg, NULL, 0, 0, INT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert metric %s", arg);
+ logerrx("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);
+ logerrx("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);
+ logerrx("unknown option `%s'", arg);
return -1;
}
break;
ARG_REQUIRED;
ifo->timeout = (time_t)strtoi(arg, NULL, 0, 0, INT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert timeout");
+ logerrx("failed to convert timeout %s", arg);
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");
+ logerr("userclass");
return -1;
}
if (s != 0) {
ARG_REQUIRED;
p = strchr(arg, ',');
if (!p || !p[1]) {
- syslog(LOG_ERR, "invalid vendor format: %s", arg);
+ logerrx("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");
+ logerr("vendor");
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"
+ logerrx("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");
+ logerr("vendor");
return -1;
}
if (s != 0) {
ARG_REQUIRED;
ifo->reboot = (time_t)strtoi(arg, NULL, 0, 0, UINT32_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert reboot %s", arg);
+ logerr("failed to convert reboot %s", arg);
return -1;
}
break;
dl = strlen("skip_hooks=") + strlen(arg) + 1;
p = malloc(sizeof(char) * dl);
if (p == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
snprintf(p, dl, "skip_hooks=%s", arg);
else if (strcmp(arg, "disable") == 0)
ifo->fqdn = FQDN_DISABLE;
else {
- syslog(LOG_ERR, "invalid value `%s' for FQDN", arg);
+ logerrx("invalid value `%s' for FQDN", arg);
return -1;
}
break;
else
s = 0;
if (s == -1) {
- syslog(LOG_ERR, "clientid: %m");
+ logerr("clientid");
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);
+ logerrx("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);
+ logerrx("unknown option `%s'", arg);
return -1;
}
break;
ARG_REQUIRED;
p = strchr(arg, '=');
if (p == NULL) {
- syslog(LOG_ERR, "static assignment required");
+ logerrx("static assignment required");
return -1;
}
p++;
fp = np = strwhite(p);
if (np == NULL) {
- syslog(LOG_ERR, "all routes need a gateway");
+ logerrx("all routes need a gateway");
return -1;
}
*np++ = '\0';
ifo->mtu = (unsigned int)strtou(p, NULL, 0,
MTU_MIN, MTU_MAX, &e);
if (e) {
- syslog(LOG_ERR, "invalid MTU %s", p);
+ logerrx("invalid MTU %s", p);
return -1;
}
} else if (strncmp(arg, "ip6_address=", strlen("ip6_address=")) == 0) {
ifo->req_prefix_len = (uint8_t)strtou(np,
NULL, 0, 0, 128, &e);
if (e) {
- syslog(LOG_ERR,
- "%s: failed to "
+ logerrx("%s: failed to "
"convert prefix len",
ifname);
return -1;
{
p = strdup(arg);
if (p == NULL) {
- syslog(LOG_ERR,
- "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
free(ifo->config[dl]);
}
p = strdup(arg);
if (p == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
nconf = reallocarray(ifo->config, dl+2, sizeof(char *));
if (nconf == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(p);
return -1;
}
naddr = reallocarray(ifo->whitelist,
ifo->whitelist_len + 2, sizeof(in_addr_t));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
ifo->whitelist = naddr;
naddr = reallocarray(ifo->blacklist,
ifo->blacklist_len + 2, sizeof(in_addr_t));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
ifo->blacklist = naddr;
naddr = reallocarray(ifo->arping,
(size_t)ifo->arping_len + 1, sizeof(in_addr_t));
if (naddr == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
ifo->arping = naddr;
ifo->dstmask, arg, 2) != 0)
{
if (errno == EINVAL)
- syslog(LOG_ERR, "option `%s' does not take"
+ logerrx("option `%s' does not take"
" an IPv4 address", arg);
else
- syslog(LOG_ERR, "unknown option `%s'", arg);
+ logerrx("unknown option `%s'", arg);
return -1;
}
break;
free(ifo->fallback);
ifo->fallback = strdup(arg);
if (ifo->fallback == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerrx(__func__);
return -1;
}
break;
case O_IAID:
ARG_REQUIRED;
if (ifname == NULL) {
- syslog(LOG_ERR,
- "IAID must belong in an interface block");
+ logerrx("IAID must belong in an interface block");
return -1;
}
if (parse_iaid(ifo->iaid, arg, sizeof(ifo->iaid)) == -1) {
- syslog(LOG_ERR, "invalid IAID %s", arg);
+ logerrx("invalid IAID %s", arg);
return -1;
}
ifo->options |= DHCPCD_IAID;
case O_IA_PD:
if (i == 0) {
if (ifname == NULL) {
- syslog(LOG_ERR,
- "IA PD must belong in an interface block");
+ logerr("IA PD must belong in an "
+ "interface block");
return -1;
}
i = D6_OPTION_IA_PD;
}
if (ifname == NULL && arg) {
- syslog(LOG_ERR,
- "IA with IAID must belong in an interface block");
+ logerrx("IA with IAID must belong in an "
+ "interface block");
return -1;
}
ifo->options |= DHCPCD_IA_FORCED;
if (p)
*p++ = '\0';
if (parse_iaid(iaid, arg, sizeof(iaid)) == -1) {
- syslog(LOG_ERR, "invalid IAID: %s", arg);
+ logerr("invalid IAID: %s", arg);
return -1;
}
}
}
}
if (ia && ia->ia_type != (uint16_t)i) {
- syslog(LOG_ERR, "Cannot mix IA for the same IAID");
+ logerrx("Cannot mix IA for the same IAID");
break;
}
if (ia == NULL) {
ia = reallocarray(ifo->ia,
ifo->ia_len + 1, sizeof(*ifo->ia));
if (ia == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__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);
+ logerr("%s", arg);
memset(&ia->addr, 0, sizeof(ia->addr));
}
if (p && ia->ia_type == D6_OPTION_IA_PD) {
ia->prefix_len = (uint8_t)strtou(p,
NULL, 0, 8, 120, &e);
if (e) {
- syslog(LOG_ERR,
- "%s: failed to convert"
+ logerrx("%s: failed to convert"
" prefix len",
p);
ia->prefix_len = 0;
sla = reallocarray(ia->sla,
ia->sla_len + 1, sizeof(*ia->sla));
if (sla == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__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", arg);
+ logerrx("%s: interface name too long", arg);
goto err_sla;
}
sla->sla_set = 0;
0, 0, UINT32_MAX, &e);
sla->sla_set = 1;
if (e) {
- syslog(LOG_ERR,
- "%s: failed to convert sla",
+ logerrx("%s: failed to convert "
+ "sla",
ifname);
goto err_sla;
}
sla->prefix_len = (uint8_t)strtou(p,
NULL, 0, 0, 120, &e);
if (e) {
- syslog(LOG_ERR,
- "%s: failed to "
+ logerrx("%s: failed to "
"convert prefix len",
ifname);
goto err_sla;
sla->suffix = (uint64_t)strtou(p, NULL,
0, 0, UINT64_MAX, &e);
if (e) {
- syslog(LOG_ERR,
- "%s: failed to "
+ logerrx("%s: failed to "
"convert suffix",
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_ERR,
- "%s: cannot mix automatic "
+ logerrx("%s: cannot mix automatic "
"and fixed SLA",
sla->ifname);
goto err_sla;
(sla->prefix_len == ia->prefix_len ||
slap->prefix_len == ia->prefix_len))
{
- syslog(LOG_ERR,
- "%s: cannot delegte the same"
+ logerrx("%s: cannot delegte the same"
"prefix length more than once",
sla->ifname);
goto err_sla;
if (sla->sla_set == 0 &&
strcmp(slap->ifname, sla->ifname) == 0)
{
- syslog(LOG_WARNING,
- "%s: cannot specify the "
+ logwarnx("%s: cannot specify the "
"same interface twice with "
"an automatic SLA",
sla->ifname);
if (slap->sla_set && sla->sla_set &&
slap->sla == sla->sla)
{
- syslog(LOG_ERR, "%s: cannot"
+ logerrx("%s: cannot"
" assign the same SLA %u"
" more than once",
sla->ifname, sla->sla);
dop = &(*ldop)->embopts;
dop_len = &(*ldop)->embopts_len;
} else {
- syslog(LOG_ERR,
- "embed must be after a define or encap");
+ logerrx("embed must be after a define "
+ "or encap");
return -1;
}
}
ARG_REQUIRED;
if (dop == NULL) {
if (*ldop == NULL) {
- syslog(LOG_ERR, "encap must be after a define");
+ logerrx("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);
+ logerrx("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);
+ logerrx("invalid code: %s", arg);
return -1;
}
arg = strskipwhite(fp);
if (arg == NULL) {
- syslog(LOG_ERR, "invalid syntax");
+ logerrx("invalid syntax");
return -1;
}
}
bp = NULL; /* No bitflag */
l = (long)strtou(np, NULL, 0, 0, LONG_MAX, &e);
if (e) {
- syslog(LOG_ERR, "failed to convert length");
+ logerrx("failed to convert length");
return -1;
}
} else {
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete request type");
+ logerrx("incomplete request type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete request type");
+ logerrx("incomplete request type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete optional type");
+ logerrx("incomplete optional type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete index type");
+ logerrx("incomplete index type");
return -1;
}
*fp++ = '\0';
arg = strskipwhite(fp);
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "incomplete array type");
+ logerrx("incomplete array type");
return -1;
}
*fp++ = '\0';
else if (strcasecmp(arg, "option") == 0)
t |= OT_OPTION;
else {
- syslog(LOG_ERR, "unknown type: %s", arg);
+ logerrx("unknown type: %s", arg);
return -1;
}
if (l && !(t & (OT_STRING | OT_BINHEX))) {
- syslog(LOG_WARNING,
- "ignoring length for type `%s'", arg);
+ logwarnx("ignoring length for type `%s'", arg);
l = 0;
}
if (t & OT_ARRAY && t & (OT_STRING | OT_BINHEX) &&
!(t & (OT_RFC1035 | OT_DOMAIN)))
{
- syslog(LOG_WARNING, "ignoring array for strings");
+ logwarnx("ignoring array for strings");
t &= ~OT_ARRAY;
}
if (t & OT_BITFLAG) {
if (bp == NULL)
- syslog(LOG_WARNING,
- "missing bitflag assignment");
+ logwarnx("missing bitflag assignment");
}
/* variable */
if (!fp) {
if (!(t & OT_OPTION)) {
- syslog(LOG_ERR,
- "type %s requires a variable name", arg);
+ logerrx("type %s requires a variable name",
+ arg);
return -1;
}
np = NULL;
if (strcasecmp(arg, "reserved")) {
np = strdup(arg);
if (np == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
} else {
if (ndop == NULL) {
ndop = reallocarray(*dop, *dop_len + 1, sizeof(**dop));
if (ndop == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__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);
+ logerrx("invalid code: %s", arg);
return -1;
}
if (fp) {
s = parse_string(NULL, 0, fp);
if (s == -1) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
dl = (size_t)s;
if (dl + (sizeof(uint16_t) * 2) > UINT16_MAX) {
- syslog(LOG_ERR, "vendor class is too big");
+ logerrx("vendor class is too big");
return -1;
}
np = malloc(dl);
if (np == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
parse_string(np, dl, fp);
vivco = reallocarray(ifo->vivco,
ifo->vivco_len + 1, sizeof(*ifo->vivco));
if (vivco == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr( __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);
+ logerrx("%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);
+ logerrx("%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);
+ logerrx("%s: unsupported RDM", arg);
return -1;
}
ifo->auth.options |= DHCPCD_AUTH_SEND;
break;
#else
- syslog(LOG_ERR, "no authentication support");
+ logerrx("no authentication support");
return -1;
#endif
case O_AUTHTOKEN:
#ifdef AUTH
fp = strwhite(arg);
if (fp == NULL) {
- syslog(LOG_ERR, "authtoken requires a realm");
+ logerrx("authtoken requires a realm");
return -1;
}
*fp++ = '\0';
token = malloc(sizeof(*token));
if (token == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(token);
return -1;
}
if (parse_uint32(&token->secretid, arg) == -1) {
- syslog(LOG_ERR, "%s: not a number", arg);
+ logerrx("%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");
+ logerrx("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");
+ logerr("realm_len");
free(token);
return -1;
}
token->realm_len = (size_t)s;
token->realm = malloc(token->realm_len);
if (token->realm == NULL) {
+ logerr(__func__);
free(token);
- syslog(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");
+ logerrx("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);
+ logerrx("%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__);
+ logerr("%s: mktime", __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" :
- "authtoken needs a key");
+ if (s == -1)
+ logerr("token_len");
+ else
+ logerrx("authtoken needs a key");
free(token->realm);
free(token);
return -1;
parse_string((char *)token->key, token->key_len, arg);
TAILQ_INSERT_TAIL(&ifo->auth.tokens, token, next);
#else
- syslog(LOG_ERR, "no authentication support");
+ logerrx("no authentication support");
return -1;
#endif
break;
dl = (size_t)l;
p = malloc(dl);
if (p == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__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");
+ logerrx("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");
+ logerr(__func__);
free(p);
return -1;
}
}
if (i != 0) {
errno = i;
- syslog(LOG_ERR, "getgrnam_r: %m");
+ logerr("getgrnam_r");
free(p);
return -1;
}
if (grp == NULL) {
- syslog(LOG_ERR, "controlgroup: %s: not found", arg);
+ logerrx("controlgroup: %s: not found", arg);
free(p);
return -1;
}
#else
grp = getgrnam(arg);
if (grp == NULL) {
- syslog(LOG_ERR, "controlgroup: %s: not found", arg);
+ logerrx("controlgroup: %s: not found", arg);
return -1;
}
ctx->control_group = grp->gr_gid;
ARG_REQUIRED;
s = parse_string((char *)ifo->mudurl + 1, MUDURL_MAX_LEN, arg);
if (s == -1) {
- syslog(LOG_ERR, "mudurl: %m");
+ logerr("mudurl");
return -1;
}
*ifo->mudurl = (uint8_t)s;
#ifdef ARG_REQUIRED
arg_required:
- syslog(LOG_ERR, "option %d requires an argument", opt);
+ logerrx("option %d requires an argument", opt);
return -1;
#undef ARG_REQUIRED
#endif
continue;
if (cf_options[i].has_arg == required_argument && !line) {
- syslog(LOG_ERR, "option requires an argument -- %s",
- opt);
+ logerrx("option requires an argument -- %s", opt);
return -1;
}
ldop, edop);
}
- syslog(LOG_ERR, "unknown option: %s", opt);
+ logerrx("unknown option: %s", opt);
return -1;
}
/* Seed our default options */
if ((ifo = calloc(1, sizeof(*ifo))) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
ifo->options |= DHCPCD_IF_UP | DHCPCD_LINK | DHCPCD_INITIAL_DELAY;
ifo->dhcp_override =
calloc(INITDEFINES, sizeof(*ifo->dhcp_override));
if (ifo->dhcp_override == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
else
ifo->dhcp_override_len = INITDEFINES;
#endif
ifo->nd_override =
calloc(INITDEFINENDS, sizeof(*ifo->nd_override));
if (ifo->nd_override == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
else
ifo->nd_override_len = INITDEFINENDS;
#endif
ifo->dhcp6_override =
calloc(INITDEFINE6S, sizeof(*ifo->dhcp6_override));
if (ifo->dhcp6_override == NULL)
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__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);
+ logerr("%s: fopen `%s'", __func__, 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__);
+ logerr(__func__);
free_options(ifo);
return NULL;
}
buflen = ol;
nbuf = realloc(buf, buflen);
if (nbuf == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(buf);
free_options(ifo);
return NULL;
if (fp == NULL) {
/* dhcpcd can continue without it, but no DNS options
* would be requested ... */
- syslog(LOG_WARNING, "fopen `%s': %m", ctx->cffile);
+ logwarn("%s: fopen `%s'", __func__, ctx->cffile);
free(buf);
return ifo;
}
n = reallocarray(ctx->ifcv,
(size_t)ctx->ifcc + 1, sizeof(char *));
if (n == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
continue;
}
ctx->ifcv = n;
ctx->ifcv[ctx->ifcc] = strdup(line);
if (ctx->ifcv[ctx->ifcc] == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
continue;
}
ctx->ifcc++;
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
-#define IF_OPTS "146bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:" \
+#define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
"ABC:DEF:HI:JKLMNO:PQ:S:TUVW:X:Z:"
#define NOERR_IF_OPTS ":" IF_OPTS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include <fcntl.h>
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6nd.h"
+#include "logerr.h"
void
if_free(struct interface *ifp)
ifa->ifa_name);
if (addrflags == -1) {
if (errno != EEXIST)
- syslog(LOG_ERR,
- "%s: if_addrflags: %s: %m",
+ logerr("%s: if_addrflags: %s",
__func__,
inet_ntoa(addr->sin_addr));
continue;
ifa->ifa_name);
if (addrflags == -1) {
if (errno != EEXIST)
- syslog(LOG_ERR,
- "%s: if_addrflags6: %m", __func__);
+ logerr("%s: if_addrflags6", __func__);
continue;
}
#endif
}
if (if_vimaster(ctx, spec.devname) == 1) {
- syslog(argc ? LOG_ERR : LOG_DEBUG,
- "%s: is a Virtual Interface Master, skipping",
- spec.devname);
+ if (argc)
+ logerr("%s: is a Virtual Interface Master, "
+ "skipping",
+ spec.devname);
+ else
+ logdebug("%s: is a Virtual Interface Master, "
+ "skipping",
+ spec.devname);
continue;
}
ifp = calloc(1, sizeof(*ifp));
if (ifp == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
break;
}
ifp->ctx = ctx;
ctx->ifac == 0 && active &&
!if_hasconf(ctx, ifp->name))
{
- syslog(LOG_DEBUG,
- "%s: ignoring due to"
+ logdebug("%s: ignoring due to"
" interface type and"
" no config",
ifp->name);
!if_hasconf(ctx, ifp->name))
active = IF_INACTIVE;
if (active)
- syslog(LOG_WARNING,
- "%s: unsupported"
+ logwarnx("%s: unsupported"
" interface type %.2x",
ifp->name, sdl->sdl_type);
/* Pretend it's ethernet */
#ifndef AF_LINK
default:
if (active)
- syslog(LOG_WARNING,
- "%s: unsupported"
+ logwarnx("%s: unsupported"
" interface family %.2x",
ifp->name, ifp->family);
break;
if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
/* Handle any platform init for the interface */
if (active != IF_INACTIVE && if_init(ifp) == -1) {
- syslog(LOG_ERR, "%s: if_init: %m", ifp->name);
+ logerr("%s: if_init", ifp->name);
if_free(ifp);
continue;
}
if (if_getmtu(ifp) < MTU_MIN && active &&
if_setmtu(ifp, MTU_MIN) == -1)
{
- syslog(LOG_ERR, "%s: if_setmtu: %m", ifp->name);
+ logerr("%s: if_setmtu", ifp->name);
if_free(ifp);
continue;
}
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
#include "if-options.h"
#include "ipv4.h"
#include "ipv4ll.h"
+#include "logerr.h"
#include "route.h"
#include "script.h"
#include "sa.h"
char buf[INET_MAX_ADDRSTRLEN];
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
- syslog(LOG_WARNING,
- "%s: forcing router %s through interface",
+ logwarnx("%s: forcing router %s through "
+ "interface",
ifp->name,
sa_addrtop(&rt->rt_gateway,
buf, sizeof(buf)));
char buf[INET_MAX_ADDRSTRLEN];
ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
- syslog(LOG_WARNING,
- "%s: router %s requires a host route",
+ logwarnx("%s: router %s requires a host route",
ifp->name,
sa_addrtop(&rt->rt_gateway, buf, sizeof(buf)));
}
UNUSED(keeparp);
#endif
- syslog(LOG_DEBUG, "%s: deleting IP address %s",
+ logdebug("%s: deleting IP address %s",
addr->iface->name, addr->saddr);
r = if_address(RTM_DELADDR, addr);
if (r == -1 &&
errno != EADDRNOTAVAIL && errno != ESRCH &&
errno != ENXIO && errno != ENODEV)
- syslog(LOG_ERR, "%s: %s: %m", addr->iface->name, __func__);
+ logerr("%s: %s", addr->iface->name, __func__);
#ifdef ARP
if (!keeparp && (astate = arp_find(addr->iface, &addr->addr)) != NULL)
ifp->if_data[IF_DATA_IPV4] = malloc(sizeof(*state));
state = IPV4_STATE(ifp);
if (state == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
TAILQ_INIT(&state->addrs);
#endif
if ((state = ipv4_getstate(ifp)) == NULL) {
- syslog(LOG_ERR, "%s: ipv4_getstate: %m", __func__);
+ logerr(__func__);
return NULL;
}
if (ifp->options->options & DHCPCD_NOALIAS) {
}
if ((ia = malloc(sizeof(*ia))) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
#ifdef ALIAS_ADDR
blank = (ia->alias[0] == '\0');
if ((replaced = ipv4_aliasaddr(ia, &replaced_ia)) == -1) {
- syslog(LOG_ERR, "%s: ipv4_aliasaddr: %m", ifp->name);
+ logerr("%s: ipv4_aliasaddr", ifp->name);
free(ia);
return NULL;
}
if (blank)
- syslog(LOG_DEBUG, "%s: aliased %s", ia->alias, ia->saddr);
+ logdebug("%s: aliased %s", ia->alias, ia->saddr);
#endif
- syslog(LOG_DEBUG, "%s: adding IP address %s broadcast %s",
+ logdebug("%s: adding IP address %s broadcast %s",
ifp->name, ia->saddr, inet_ntoa(*bcast));
if (if_address(RTM_NEWADDR, ia) == -1) {
if (errno != EEXIST)
- syslog(LOG_ERR, "%s: if_addaddress: %m",
+ logerr("%s: if_addaddress",
__func__);
free(ia);
return NULL;
nstate->addr->addr.s_addr == lease->addr.s_addr)
{
if (r == 0) {
- syslog(LOG_INFO,
- "%s: preferring %s on %s",
+ loginfo("%s: preferring %s on %s",
ifp->name,
inet_ntoa(lease->addr),
ifn->name);
return;
}
- syslog(LOG_INFO, "%s: preferring %s on %s",
+ loginfo("%s: preferring %s on %s",
ifn->name,
inet_ntoa(lease->addr),
ifp->name);
if (ia &&
ia->mask.s_addr == lease->mask.s_addr &&
ia->brd.s_addr == lease->brd.s_addr)
- syslog(LOG_DEBUG, "%s: IP address %s already exists",
+ logdebug("%s: IP address %s already exists",
ifp->name, ia->saddr);
else {
#if __linux__
ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
if (ia == NULL) {
- syslog(LOG_ERR, "%s: added address vanished",
- ifp->name);
+ logerrx("%s: added address vanished", ifp->name);
return;
}
#if defined(ARP) && defined(IN_IFF_NOTUSEABLE)
case RTM_NEWADDR:
if (ia == NULL) {
if ((ia = malloc(sizeof(*ia))) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return;
}
ia->iface = ifp;
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 6
#include "if-options.h"
#include "ipv4.h"
#include "ipv4ll.h"
+#include "logerr.h"
#include "sa.h"
#include "script.h"
#ifdef IN_IFF_NOTREADY
if (ia == NULL || ia->addr_flags & IN_IFF_NOTREADY)
#endif
- syslog(LOG_INFO, "%s: using IPv4LL address %s",
+ loginfo("%s: using IPv4LL address %s",
ifp->name, inet_ntoa(astate->addr));
if (ia == NULL) {
if (ifp->ctx->options & DHCPCD_TEST)
#ifdef IN_IFF_NOTREADY
if (ia->addr_flags & IN_IFF_NOTREADY)
return;
- syslog(LOG_DEBUG, "%s: DAD completed for %s",
+ logdebug("%s: DAD completed for %s",
ifp->name, inet_ntoa(astate->addr));
#endif
test:
astate->failed.s_addr == state->addr->addr.s_addr)
{
#ifdef KERNEL_RFC5227
- syslog(LOG_WARNING, "%s: IPv4LL defence failed for %s",
+ logwarnx("%s: IPv4LL defence failed for %s",
ifp->name, state->addr->saddr);
#else
struct timespec now, defend;
defend.tv_nsec = state->defend.tv_nsec;
clock_gettime(CLOCK_MONOTONIC, &now);
if (timespeccmp(&defend, &now, >))
- syslog(LOG_WARNING,
- "%s: IPv4LL %d second defence failed for %s",
+ logwarnx("%s: IPv4LL %d second defence failed for %s",
ifp->name, DEFEND_INTERVAL, state->addr->saddr);
else if (arp_request(ifp,
state->addr->addr.s_addr, state->addr->addr.s_addr) == -1)
- syslog(LOG_ERR, "%s: arp_request: %m", __func__);
+ logerr(__func__);
else {
- syslog(LOG_DEBUG, "%s: defended IPv4LL address %s",
+ logdebug("%s: defended IPv4LL address %s",
ifp->name, state->addr->saddr);
state->defend = now;
return;
arp_cancel(astate);
if (++state->conflicts == MAX_CONFLICTS)
- syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
+ logerr("%s: failed to acquire an IPv4LL address",
ifp->name);
astate->addr.s_addr = ipv4ll_pickaddr(astate);
eloop_timeout_add_sec(ifp->ctx->eloop,
if ((state = IPV4LL_STATE(ifp)) == NULL) {
ifp->if_data[IF_DATA_IPV4LL] = calloc(1, sizeof(*state));
if ((state = IPV4LL_STATE(ifp)) == NULL) {
- syslog(LOG_ERR, "%s: calloc %m", __func__);
+ logerr(__func__);
return;
}
}
astate->addr = ia->addr;
#ifdef IN_IFF_TENTATIVE
if (ia->addr_flags & (IN_IFF_TENTATIVE | IN_IFF_DETACHED)) {
- syslog(LOG_INFO,
- "%s: waiting for DAD to complete on %s",
+ loginfo("%s: waiting for DAD to complete on %s",
ifp->name, inet_ntoa(ia->addr));
return;
}
- syslog(LOG_INFO, "%s: using IPv4LL address %s",
- ifp->name, ia->saddr);
+ loginfo("%s: using IPv4LL address %s", ifp->name, ia->saddr);
#endif
ipv4ll_probed(astate);
return;
}
- syslog(LOG_INFO, "%s: probing for an IPv4LL address", ifp->name);
+ loginfo("%s: probing for an IPv4LL address", ifp->name);
astate->addr.s_addr = ipv4ll_pickaddr(astate);
#ifdef IN_IFF_TENTATIVE
ipv4ll_probed(astate);
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 7
#include "eloop.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "sa.h"
#include "script.h"
return (ssize_t)ctx->secret_len;
if (errno != ENOENT)
- syslog(LOG_ERR, "error reading secret: %s: %m", SECRET);
+ logerr("%s: %s", __func__, SECRET);
/* Chaining arc4random should be good enough.
* RFC7217 section 5.1 states the key SHOULD be at least 128 bits.
* 512 bits (64 bytes). */
if (ctx->secret_len < 64) {
if ((ctx->secret = malloc(64)) == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
return -1;
}
ctx->secret_len = 64;
return (ssize_t)ctx->secret_len;
eexit:
- syslog(LOG_ERR, "error writing secret: %s: %m", SECRET);
+ logerr("%s: %s", __func__, SECRET);
if (fp != NULL)
fclose(fp);
unlink(SECRET);
alias = NULL;
#endif
if ((flags = if_addrflags6(ia->iface, &ia->addr, alias)) == -1) {
- syslog(LOG_ERR, "%s: if_addrflags6: %m", ia->iface->name);
+ logerr("%s: if_addrflags6", ia->iface->name);
return;
}
struct ipv6_state *state;
struct ipv6_addr *ap;
- syslog(LOG_INFO, "%s: deleting address %s", ia->iface->name, ia->saddr);
+ loginfo("%s: deleting address %s", ia->iface->name, ia->saddr);
if (if_address6(RTM_DELADDR, ia) == -1 &&
errno != EADDRNOTAVAIL && errno != ESRCH &&
errno != ENXIO && errno != ENODEV)
- syslog(LOG_ERR, "if_address6: %m");
+ logerr(__func__);
/* NOREJECT is set if we delegated exactly the prefix to another
* address.
struct ipv6_state *state;
struct ipv6_addr *nap;
uint32_t pltime, vltime;
+ __printflike(1, 2) void (*logfunc)(const char *, ...);
/* Ensure no other interface has this address */
TAILQ_FOREACH(ifp, ap->iface->ctx->ifaces, next) {
ipv6_iffindaddr(ap->iface, &ap->addr, IN6_IFF_NOTUSEABLE))
ap->flags |= IPV6_AF_DADCOMPLETED;
- syslog(ap->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG,
- "%s: adding %saddress %s", ap->iface->name,
+ logfunc = ap->flags & IPV6_AF_NEW ? loginfo : logdebug;
+ logfunc("%s: adding %saddress %s", ap->iface->name,
#ifdef IPV6_AF_TEMPORARY
ap->flags & IPV6_AF_TEMPORARY ? "temporary " : "",
#else
ap->saddr);
if (ap->prefix_pltime == ND6_INFINITE_LIFETIME &&
ap->prefix_vltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG, "%s: pltime infinity, vltime infinity",
+ logdebug("%s: pltime infinity, vltime infinity",
ap->iface->name);
else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG,
- "%s: pltime infinity, vltime %"PRIu32" seconds",
+ logdebug("%s: pltime infinity, vltime %"PRIu32" seconds",
ap->iface->name, ap->prefix_vltime);
else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME)
- syslog(LOG_DEBUG,
- "%s: pltime %"PRIu32"seconds, vltime infinity",
+ logdebug("%s: pltime %"PRIu32"seconds, vltime infinity",
ap->iface->name, ap->prefix_pltime);
else
- syslog(LOG_DEBUG,
- "%s: pltime %"PRIu32" seconds, vltime %"PRIu32" seconds",
+ logdebug("%s: pltime %"PRIu32" seconds, vltime %"PRIu32
+ " seconds",
ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
/* Adjust plftime and vltime based on acquired time */
ap->prefix_vltime -= (uint32_t)n.tv_sec;
#if 0
- syslog(LOG_DEBUG,
- "%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld",
+ logdebug("%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld",
ap->iface->name,
(long long)ap->acquired.tv_sec, ap->acquired.tv_nsec,
(long long)now->tv_sec, now->tv_nsec,
(long long)n.tv_sec, n.tv_nsec);
- syslog(LOG_DEBUG,
- "%s: adj pltime %"PRIu32" seconds, "
+ logdebug("%s: adj pltime %"PRIu32" seconds, "
"vltime %"PRIu32" seconds",
ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
#endif
}
if (if_address6(RTM_NEWADDR, ap) == -1) {
- syslog(LOG_ERR, "if_addaddress6: %m");
+ logerr(__func__);
/* Restore real pltime and vltime */
ap->prefix_pltime = pltime;
ap->prefix_vltime = vltime;
}
if (nap == NULL) {
if ((nap = malloc(sizeof(*nap))) == NULL) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
return 0; /* Well, we did add the address */
}
memcpy(nap, ap, sizeof(*nap));
if ((replaced = ipv6_aliasaddr(ia, &replaced_ia)) == -1)
return -1;
if (blank)
- syslog(LOG_DEBUG, "%s: aliased %s", ia->alias, ia->saddr);
+ logdebug("%s: aliased %s", ia->alias, ia->saddr);
#endif
if ((r = ipv6_addaddr1(ia, now)) == 0) {
&ap->addr, IPV6_AF_ADDED);
if (apf && apf->iface != ap->iface) {
if (apf->iface->metric <= ap->iface->metric) {
- syslog(LOG_INFO,
- "%s: preferring %s on %s",
+ loginfo("%s: preferring %s on %s",
ap->iface->name,
ap->saddr,
apf->iface->name);
continue;
}
- syslog(LOG_INFO,
- "%s: preferring %s on %s",
+ loginfo("%s: preferring %s on %s",
apf->iface->name,
ap->saddr,
ap->iface->name);
if (if_address6(RTM_DELADDR, apf) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "if_address6: %m");
+ logerr(__func__);
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__);
+ logerr(__func__);
return NULL;
}
TAILQ_INIT(&state->addrs);
dbp = inet_ntop(AF_INET6, &addr->s6_addr,
dbuf, INET6_ADDRSTRLEN);
- syslog(LOG_INFO, "%s: cmd %d addr %s",
+ loginfo("%s: cmd %d addr %s",
ifname, cmd, dbp);
#endif
const char *cbp;
if ((ia = calloc(1, sizeof(*ia))) == NULL) {
- syslog(LOG_ERR, "%s: calloc: %m", __func__);
+ logerr(__func__);
break;
}
#ifdef ALIAS_ADDR
if (cb == NULL) {
cb = malloc(sizeof(*cb));
if (cb == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return -1;
}
cb->callback = callback;
return -1;
}
- syslog(LOG_WARNING, "%s: waiting for %s to complete",
+ logwarnx("%s: waiting for %s to complete",
ap2->iface->name, ap2->saddr);
free(ap);
errno = EEXIST;
wascompleted = (ia->flags & IPV6_AF_DADCOMPLETED);
ia->flags |= IPV6_AF_DADCOMPLETED;
if (ia->flags & IPV6_AF_DUPLICATED)
- syslog(LOG_WARNING, "%s: DAD detected %s", ia->iface->name,
+ logwarnx("%s: DAD detected %s", ia->iface->name,
ia->saddr);
else if (!wascompleted) {
- syslog(LOG_DEBUG, "%s: IPv6 static DAD completed",
+ logdebug("%s: IPv6 static DAD completed",
ia->iface->name);
}
switch (cmd) {
case RTM_DELADDR:
if (ia->flags & IPV6_AF_ADDED) {
- syslog(LOG_INFO, "%s: deleted address %s",
+ loginfo("%s: deleted address %s",
ia->iface->name, ia->saddr);
ia->flags &= ~IPV6_AF_ADDED;
}
struct timespec tv;
if (++ia->dadcounter == TEMP_IDGEN_RETRIES) {
- syslog(LOG_ERR,
- "%s: too many duplicate temporary addresses",
+ logerrx("%s: too many duplicate temporary addresses",
ia->iface->name);
return;
}
clock_gettime(CLOCK_MONOTONIC, &tv);
if ((ia1 = ipv6_createtempaddr(ia, &tv)) == NULL)
- syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+ logerr(__func__);
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", ia->iface->name, ia->saddr);
+ logdebug("%s: regen temp addr %s", ia->iface->name, ia->saddr);
clock_gettime(CLOCK_MONOTONIC, &tv);
ia1 = ipv6_createtempaddr(ia, &tv);
if (ia1)
ipv6_addaddr(ia1, &tv);
else
- syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+ logerr(__func__);
}
static void
break;
}
if (lo0 == NULL)
- syslog(LOG_WARNING,
- "cannot find a loopback interface to reject via");
+ logwarnx("cannot find a loopback interface "
+ "to reject via");
else
ifp = lo0;
}
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#define ELOOP_QUEUE 3
#include "if.h"
#include "ipv6.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "route.h"
#include "script.h"
struct in6_pktinfo pi;
if (ipv6_linklocal(ifp) == NULL) {
- syslog(LOG_DEBUG,
- "%s: delaying Router Solicitation for LL address",
+ logdebug("%s: delaying Router Solicitation for LL address",
ifp->name);
ipv6_addlinklocalcallback(ifp, ipv6nd_sendrsprobe, ifp);
return;
#endif
dst.sin6_scope_id = ifp->index;
if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr) != 1) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return;
}
pi.ipi6_ifindex = ifp->index;
memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
- syslog(LOG_DEBUG,
- "%s: sending Router Solicitation", ifp->name);
+ logdebug("%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__);
+ logerr(__func__);
/* Allow IPv6ND to continue .... at most a few errors
* would be logged.
* Generally the error is ENOBUFS when struggling to
eloop_timeout_add_sec(ifp->ctx->eloop,
RTR_SOLICITATION_INTERVAL, ipv6nd_sendrsprobe, ifp);
else {
- syslog(LOG_WARNING, "%s: no IPv6 Routers available", ifp->name);
+ logwarnx("%s: no IPv6 Routers available", ifp->name);
ipv6nd_drop(ifp);
dhcp6_dropnondelegates(ifp);
}
if (flags & IPV6ND_REACHABLE) {
if (rap->lifetime && rap->expired) {
- syslog(LOG_INFO, "%s: %s is reachable again",
+ loginfo("%s: %s is reachable again",
rap->iface->name, rap->sfrom);
rap->expired = 0;
rt_build(rap->iface->ctx, AF_INET6);
}
} else {
if (rap->lifetime && !rap->expired) {
- syslog(LOG_WARNING,
- "%s: %s is unreachable, expiring it",
+ logwarnx("%s: %s is unreachable, expiring it",
rap->iface->name, rap->sfrom);
rap->expired = 1;
rt_build(rap->iface->ctx, AF_INET6);
case ND_RA_FLAG_RTPREF_LOW:
return (RTPREF_LOW);
default:
- syslog(LOG_ERR, "rtpref: impossible RA flag %x", rap->flags);
+ logerrx("rtpref: impossible RA flag %x", rap->flags);
return (RTPREF_INVALID);
}
/* NOTREACHED */
IN6_IFF_TENTATIVE))
ap->flags |= IPV6_AF_DADCOMPLETED;
if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
- syslog(LOG_DEBUG,
- "%s: waiting for Router Advertisement"
+ logdebug("%s: waiting for Router Advertisement"
" DAD to complete",
rap->iface->name);
return 0;
#if 0
else if (options & DHCPCD_DAEMONISE &&
!(options & DHCPCD_DAEMONISED) && new_data)
- syslog(LOG_WARNING, "%s: did not fork due to an absent"
+ logwarnx("%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",
- ifp->name, ap->saddr);
+ logwarnx("%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, "%s: unable to obtain a"
+ logerrx("%s: unable to obtain a"
" stable private address",
ifp->name);
goto try_script;
}
- syslog(LOG_INFO, "%s: deleting address %s",
+ loginfo("%s: deleting address %s",
ifp->name, ap->saddr);
if (if_address6(RTM_DELADDR, ap) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "if_address6: %m");
+ logerr(__func__);
dadcounter = ap->dadcounter;
if (ipv6_makestableprivate(&ap->addr,
&ap->prefix, ap->prefix_len,
ifp, &dadcounter) == -1)
{
- syslog(LOG_ERR,
- "%s: ipv6_makestableprivate: %m",
- ifp->name);
+ logerr("ipv6_makestableprivate");
return;
}
ap->dadcounter = dadcounter;
}
if (wascompleted && found) {
- syslog(LOG_DEBUG,
- "%s: Router Advertisement DAD completed",
+ logdebug("%s: Router Advertisement DAD "
+ "completed",
rap->iface->name);
if (ipv6nd_scriptrun(rap))
return;
struct ipv6_addr *ap;
struct dhcp_opt *dho;
uint8_t new_rap, new_data;
+ __printflike(1, 2) void (*logfunc)(const char *, ...);
#ifdef IPV6_MANAGETEMPADDR
uint8_t new_ap;
#endif
if (ifp == NULL) {
#ifdef DEBUG_RS
- syslog(LOG_DEBUG, "RA for unexpected interface from %s",
+ logdebug("RA for unexpected interface from %s",
ctx->sfrom);
#endif
return;
}
if (len < sizeof(struct nd_router_advert)) {
- syslog(LOG_ERR, "IPv6 RA packet too short from %s", ctx->sfrom);
+ logerr("IPv6 RA packet too short from %s", ctx->sfrom);
return;
}
/* RFC 4861 7.1.2 */
if (hoplimit != 255) {
- syslog(LOG_ERR, "invalid hoplimit(%d) in RA from %s",
+ logerr("invalid hoplimit(%d) in RA from %s",
hoplimit, ctx->sfrom);
return;
}
if (!IN6_IS_ADDR_LINKLOCAL(&ctx->from.sin6_addr)) {
- syslog(LOG_ERR, "RA from non local address %s", ctx->sfrom);
+ logerr("RA from non local address %s", ctx->sfrom);
return;
}
if (!(ifp->options->options & DHCPCD_IPV6RS)) {
#ifdef DEBUG_RS
- syslog(LOG_DEBUG, "%s: unexpected RA from %s",
+ logerr("%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)",
+ logdebug("%s: received RA from %s (no link-local)",
ifp->name, ctx->sfrom);
#endif
return;
}
if (ipv6_iffindaddr(ifp, &ctx->from.sin6_addr, IN6_IFF_TENTATIVE)) {
- syslog(LOG_DEBUG, "%s: ignoring RA from ourself %s",
+ logdebug("%s: ignoring RA from ourself %s",
ifp->name, ctx->sfrom);
return;
}
if (rap == NULL) {
rap = calloc(1, sizeof(*rap));
if (rap == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return;
}
rap->iface = ifp;
if (rap->data_len == 0) {
rap->data = malloc(len);
if (rap->data == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
if (new_rap)
free(rap);
return;
* routers like to decrease the advertised valid and preferred times
* in accordance with the own prefix times which would result in too
* much needless log spam. */
- syslog(new_rap ? LOG_INFO : LOG_DEBUG,
- "%s: Router Advertisement from %s",
+ logfunc = new_rap ? loginfo : logdebug,
+ logfunc("%s: Router Advertisement from %s",
ifp->name, ctx->sfrom);
clock_gettime(CLOCK_MONOTONIC, &rap->acquired);
p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
for (; len > 0; p += olen, len -= olen) {
if (len < sizeof(ndo)) {
- syslog(LOG_ERR, "%s: short option", ifp->name);
+ logerrx("%s: short option", ifp->name);
break;
}
memcpy(&ndo, p, sizeof(ndo));
olen = (size_t)ndo.nd_opt_len * 8;
if (olen == 0) {
- syslog(LOG_ERR, "%s: zero length option", ifp->name);
+ logerrx("%s: zero length option", ifp->name);
break;
}
if (olen > len) {
- syslog(LOG_ERR, "%s: option length exceeds message",
+ logerrx("%s: option length exceeds message",
ifp->name);
break;
}
break;
}
if (dho != NULL)
- syslog(LOG_WARNING,
- "%s: reject RA (option %s) from %s",
+ logwarnx("%s: reject RA (option %s) from %s",
ifp->name, dho->var, ctx->sfrom);
else
- syslog(LOG_WARNING,
- "%s: reject RA (option %d) from %s",
+ logwarnx("%s: reject RA (option %d) from %s",
ifp->name, ndo.nd_opt_type, ctx->sfrom);
if (new_rap)
ipv6nd_removefreedrop_ra(rap, 0, 0);
switch (ndo.nd_opt_type) {
case ND_OPT_PREFIX_INFORMATION:
+ logfunc = new_data ? logerrx : logdebug;
if (ndo.nd_opt_len != 4) {
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
- "%s: invalid option len for prefix",
+ logfunc("%s: invalid option len for prefix",
ifp->name);
continue;
}
memcpy(&pi, p, sizeof(pi));
if (pi.nd_opt_pi_prefix_len > 128) {
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
- "%s: invalid prefix len",
- ifp->name);
+ logfunc("%s: invalid prefix len", ifp->name);
continue;
}
/* nd_opt_pi_prefix is not aligned. */
if (IN6_IS_ADDR_MULTICAST(&pi_prefix) ||
IN6_IS_ADDR_LINKLOCAL(&pi_prefix))
{
- syslog(new_data ? LOG_ERR : LOG_DEBUG,
- "%s: invalid prefix in RA", ifp->name);
+ logfunc("%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,
- "%s: pltime > vltime", ifp->name);
+ logfunc("%s: pltime > vltime", ifp->name);
continue;
}
TAILQ_FOREACH(ap, &rap->addrs, next)
ND_OPT_PI_FLAG_ONLINK))
continue;
ap = calloc(1, sizeof(*ap));
- if (ap == NULL)
+ if (ap == NULL) {
+ logerr(__func__);
break;
+ }
ap->iface = rap->iface;
ap->flags = IPV6_AF_NEW;
ap->prefix_len = pi.nd_opt_pi_prefix_len;
if (new_ap && ap->prefix_pltime) {
if (ipv6_createtempaddr(ap,
&ap->acquired) == NULL)
- syslog(LOG_ERR,
- "ipv6_createtempaddr: %m");
+ logerr("ipv6_createtempaddr");
}
}
#endif
memcpy(&mtu, p, sizeof(mtu));
mtu.nd_opt_mtu_mtu = ntohl(mtu.nd_opt_mtu_mtu);
if (mtu.nd_opt_mtu_mtu < IPV6_MMTU) {
- syslog(LOG_ERR, "%s: invalid MTU %d",
+ logerrx("%s: invalid MTU %d",
ifp->name, mtu.nd_opt_mtu_mtu);
break;
}
if (has_option_mask(ifp->options->requiremasknd,
dho->option))
{
- syslog(LOG_WARNING,
- "%s: reject RA (no option %s) from %s",
+ logwarnx("%s: reject RA (no option %s) from %s",
ifp->name, dho->var, ctx->sfrom);
if (new_rap)
ipv6nd_removefreedrop_ra(rap, 0, 0);
goto nodhcp6;
/* Only log a DHCPv6 start error if compiled in or debugging is enabled. */
#ifdef DHCP6
-#define LOG_DHCP6 LOG_ERR
+#define LOG_DHCP6 logerr
#else
-#define LOG_DHCP6 LOG_DEBUG
+#define LOG_DHCP6 logdebug
#endif
if (rap->flags & ND_RA_FLAG_MANAGED) {
if (new_data && dhcp6_start(ifp, DH6S_INIT) == -1)
- syslog(LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name);
+ LOG_DHCP6("dhcp6_start: %s", ifp->name);
} else if (rap->flags & ND_RA_FLAG_OTHER) {
if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1)
- syslog(LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name);
+ LOG_DHCP6("dhcp6_start: %s", ifp->name);
} else {
if (new_data)
- syslog(LOG_DEBUG, "%s: No DHCPv6 instruction in RA",
- ifp->name);
+ logdebug("%s: No DHCPv6 instruction in RA", ifp->name);
nodhcp6:
if (ifp->ctx->options & DHCPCD_TEST) {
eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
if (rap->lifetime == 0 || timespeccmp(&now, &expire, >))
{
if (!rap->expired) {
- syslog(LOG_WARNING,
- "%s: %s: router expired",
+ logwarnx("%s: %s: router expired",
ifp->name, rap->sfrom);
rap->expired = expired = 1;
rap->lifetime = 0;
timespecadd(&ia->acquired, <, &expire);
if (timespeccmp(&now, &expire, >)) {
if (ia->flags & IPV6_AF_ADDED) {
- syslog(LOG_WARNING,
- "%s: expired address %s",
+ logwarnx("%s: expired address %s",
ia->iface->name, ia->saddr);
if (if_address6(RTM_DELADDR, ia)== -1 &&
errno != EADDRNOTAVAIL &&
errno != ENXIO)
- syslog(LOG_ERR,
- "if_address6: %m");
+ logerr(__func__);
}
ia->prefix_vltime = ia->prefix_pltime = 0;
ia->flags &=
if (ifp == NULL) {
#ifdef DEBUG_NS
- syslog(LOG_DEBUG, "NA for unexpected interface from %s",
+ logdebug("NA for unexpected interface from %s",
ctx->sfrom);
#endif
return;
}
if ((size_t)len < sizeof(struct nd_neighbor_advert)) {
- syslog(LOG_ERR, "%s: IPv6 NA too short from %s",
+ logerrx("%s: IPv6 NA too short from %s",
ifp->name, ctx->sfrom);
return;
}
/* RFC 4861 7.1.2 */
if (hoplimit != 255) {
- syslog(LOG_ERR, "invalid hoplimit(%d) in NA from %s",
+ logerrx("invalid hoplimit(%d) in NA from %s",
hoplimit, ctx->sfrom);
return;
}
/* nd_na->nd_na_target is not aligned. */
memcpy(&nd_na_target, &nd_na->nd_na_target, sizeof(nd_na_target));
if (IN6_IS_ADDR_MULTICAST(&nd_na_target)) {
- syslog(LOG_ERR, "%s: NA multicast address %s (%s)",
+ logerrx("%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",
+ logdebug("%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",
+ logdebug("%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)",
+ loginfo("%s: %s not a router (%s)",
ifp->name, taddr, ctx->sfrom);
rap->expired = 1;
rt_build(ifp->ctx, AF_INET6);
if (is_solicited && is_router && rap->lifetime) {
if (rap->expired) {
rap->expired = 0;
- syslog(LOG_INFO, "%s: %s reachable (%s)",
+ loginfo("%s: %s reachable (%s)",
ifp->name, taddr, ctx->sfrom);
rt_build(ifp->ctx, AF_INET6);
script_runreason(rap->iface, "ROUTERADVERT"); /* XXX */
CMSG_SPACE(sizeof(int));
len = recvmsg_realloc(ctx->nd_fd, &ctx->rcvhdr, 0);
if (len == -1) {
- syslog(LOG_ERR, "recvmsg: %m");
+ logerr(__func__);
eloop_event_delete(ctx->eloop, ctx->nd_fd);
close(ctx->nd_fd);
ctx->nd_fd = -1;
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",
- ctx->sfrom);
+ logerrx("IPv6 ICMP packet too short from %s", ctx->sfrom);
return;
}
}
if (pkt.ipi6_ifindex == 0) {
- syslog(LOG_ERR, "IPv6 RA/NA did not contain index from %s",
- ctx->sfrom);
+ logerrx("IPv6 RA/NA did not contain index from %s", ctx->sfrom);
return;
}
}
}
- syslog(LOG_ERR, "invalid IPv6 type %d or code %d from %s",
+ logerrx("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);
+ loginfo("%s: soliciting an IPv6 router", ifp->name);
if (ipv6nd_open(ifp->ctx) == -1) {
- syslog(LOG_ERR, "%s: ipv6nd_open: %m", __func__);
+ logerr(__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__);
+ logerr(__func__);
return;
}
}
* address could have changed. */
ipv6nd_makersprobe(ifp);
if (state->rs == NULL) {
- syslog(LOG_ERR, "%s: ipv6ns_makersprobe: %m", __func__);
+ logerr(__func__);
return;
}
tv.tv_nsec = (suseconds_t)arc4random_uniform(
MAX_RTR_SOLICITATION_DELAY * NSEC_PER_SEC);
timespecnorm(&tv);
- syslog(LOG_DEBUG,
- "%s: delaying IPv6 router solicitation for %0.1f seconds",
+ logdebug("%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);
return;
--- /dev/null
+/*
+ * logerr: errx with logging
+ * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "logerr.h"
+
+#ifndef LOGERR_FACILITY
+#define LOGERR_FACILITY LOG_DAEMON
+#endif
+#ifndef LOGERR_OPTS
+#define LOGERR_OPTS LOG_PID
+#endif
+
+struct logctx {
+ unsigned int log_opts;
+ FILE *log_file;
+};
+
+static struct logctx _logctx = {
+ .log_opts = LOGERR_WLOG,
+ .log_file = NULL,
+};
+
+__printflike(2, 0) static void
+vlogprintf(FILE *stream, const char *fmt, va_list args)
+{
+ va_list a;
+
+ va_copy(a, args);
+ vfprintf(stream, fmt, a);
+ fputc('\n', stream);
+ va_end(a);
+}
+
+/*
+ * NetBSD's gcc has been modified to check for the non standard %m in printf
+ * like functions and warn noisily about it that they should be marked as
+ * syslog like instead.
+ * This is all well and good, but our logger also goes via vfprintf and
+ * when marked as a sysloglike funcion, gcc will then warn us that the
+ * function should be printflike instead!
+ * This creates an infinte loop of gcc warnings.
+ * Until NetBSD solves this issue, we have to disable a gcc diagnostic
+ * for our fully standards compliant code in the logger function.
+ */
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
+#endif
+__printflike(2, 0) static void
+vlogmessage(int pri, const char *fmt, va_list args)
+{
+
+ if (pri <= LOG_ERR ||
+ (!(_logctx.log_opts & LOGERR_QUIET) && pri <= LOG_INFO) ||
+ (_logctx.log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG))
+ vlogprintf(stderr, fmt, args);
+
+ if (!(_logctx.log_opts & LOGERR_WLOG))
+ return;
+
+ if (_logctx.log_file != NULL) {
+ struct timeval tv;
+
+ if (pri == LOG_DEBUG && !(_logctx.log_opts & LOGERR_DEBUG))
+ return;
+
+ /* Write the time, syslog style. month day time - */
+ if (gettimeofday(&tv, NULL) != -1) {
+ time_t now;
+ struct tm tmnow;
+ char buf[32];
+
+ now = tv.tv_sec;
+ tzset();
+ localtime_r(&now, &tmnow);
+ strftime(buf, sizeof(buf), "%b %d %T ", &tmnow);
+ fprintf(_logctx.log_file, "%s", buf);
+ }
+
+ vlogprintf(_logctx.log_file, fmt, args);
+ } else
+ vsyslog(pri, fmt, args);
+}
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))
+#pragma GCC diagnostic pop
+#endif
+
+__printflike(2, 3) static void
+logmessage(int pri, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogmessage(pri, fmt, args);
+ va_end(args);
+}
+
+__printflike(2, 0) static void
+vlogerrmessage(int pri, const char *fmt, va_list args)
+{
+ int _errno = errno;
+ char buf[1024];
+
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ logmessage(pri, "%s: %s", buf, strerror(_errno));
+}
+
+void
+logdebug(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogmessage(LOG_DEBUG, fmt, args);
+ va_end(args);
+}
+
+void
+loginfo(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogmessage(LOG_INFO, fmt, args);
+ va_end(args);
+}
+
+void
+logwarn(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogerrmessage(LOG_WARNING, fmt, args);
+ va_end(args);
+}
+
+void
+logwarnx(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogmessage(LOG_WARNING, fmt, args);
+ va_end(args);
+}
+
+void
+logerr(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogerrmessage(LOG_ERR, fmt, args);
+ va_end(args);
+}
+
+void
+logerrx(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vlogerrmessage(LOG_ERR, fmt, args);
+ va_end(args);
+}
+
+void
+logsetopts(unsigned int opts)
+{
+
+ _logctx.log_opts = opts;
+ setlogmask(LOG_UPTO(opts & LOGERR_DEBUG ? LOG_DEBUG : LOG_INFO));
+}
+
+int
+logopen(const char *path)
+{
+
+ if (path == NULL) {
+ openlog(NULL, LOGERR_OPTS, LOGERR_FACILITY);
+ return 1;
+ }
+
+ if ((_logctx.log_file = fopen(path, "w")) == NULL)
+ return -1;
+ setlinebuf(_logctx.log_file);
+ return fileno(_logctx.log_file);
+}
+
+void
+logclose()
+{
+
+ closelog();
+ if (_logctx.log_file == NULL)
+ return;
+ fclose(_logctx.log_file);
+ _logctx.log_file = NULL;
+}
--- /dev/null
+/*
+ * logerr: errx with logging
+ * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LOGERR_H
+#define LOERRG_H
+
+#include <sys/param.h>
+
+#ifndef __printflike
+#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
+#define __printflike(a, b) __attribute__((format(printf, a, b)))
+#else
+#define __printflike
+#endif
+#endif /* !__printflike */
+
+__printflike(1, 2) typedef void logfunc_t(const char *, ...);
+
+__printflike(1, 2) void logdebug(const char *, ...);
+__printflike(1, 2) void loginfo(const char *, ...);
+__printflike(1, 2) void logwarn(const char *, ...);
+__printflike(1, 2) void logwarnx(const char *, ...);
+__printflike(1, 2) void logerr(const char *, ...);
+#define LOGERROR logerr("%s: %d", __FILE__, __LINE__)
+__printflike(1, 2) void logerrx(const char *, ...);
+
+void logsetopts(unsigned int);
+#define LOGERR_WLOG (1U << 1)
+#define LOGERR_DEBUG (1U << 2)
+#define LOGERR_QUIET (1U << 3)
+
+int logopen(const char *);
+void logclose(void);
+int logreopen(void);
+
+#endif
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "ipv6.h"
+#include "logerr.h"
#include "route.h"
#include "sa.h"
if (rt->rt_flags & RTF_HOST) {
if (gateway_unspec)
- syslog(LOG_INFO, "%s: %s host route to %s",
+ loginfo("%s: %s host route to %s",
ifname, cmd, dest);
else
- syslog(LOG_INFO, "%s: %s host route to %s via %s",
+ loginfo("%s: %s host route to %s via %s",
ifname, cmd, dest, gateway);
} else if (sa_is_unspecified(&rt->rt_dest) &&
sa_is_unspecified(&rt->rt_netmask))
{
if (gateway_unspec)
- syslog(LOG_INFO, "%s: %s default route",
+ loginfo("%s: %s default route",
ifname, cmd);
else
- syslog(LOG_INFO, "%s: %s default route via %s",
+ loginfo("%s: %s default route via %s",
ifname, cmd, gateway);
} else if (gateway_unspec)
- syslog(LOG_INFO, "%s: %s%s route to %s/%d",
+ loginfo("%s: %s%s route to %s/%d",
ifname, cmd,
rt->rt_flags & RTF_REJECT ? " reject" : "",
dest, prefix);
else
- syslog(LOG_INFO, "%s: %s%s route to %s/%d via %s",
+ loginfo("%s: %s%s route to %s/%d via %s",
ifname, cmd,
rt->rt_flags & RTF_REJECT ? " reject" : "",
dest, prefix, gateway);
if ((rt = TAILQ_FIRST(&ctx->froutes)) != NULL)
TAILQ_REMOVE(&ctx->froutes, rt, rt_next);
else if ((rt = malloc(sizeof(*rt))) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
memset(rt, 0, sizeof(*rt));
if (if_route(RTM_CHANGE, nrt) != -1)
return true;
if (errno != ESRCH)
- syslog(LOG_ERR, "if_route (CHG): %m");
+ logerr("if_route (CHG)");
}
#ifdef HAVE_ROUTE_METRIC
if (if_route(RTM_ADD, nrt) != -1) {
if (ort != NULL) {
if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "if_route (DEL): %m");
+ logerr("if_route (DEL)");
rt_kfree(ort);
}
return true;
#endif
if (ort != NULL) {
if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "if_route (DEL): %m");
+ logerr("if_route (DEL)");
else
rt_kfree(ort);
}
#ifdef HAVE_ROUTE_METRIC
logerr:
#endif
- syslog(LOG_ERR, "if_route (ADD): %m");
+ logerr("if_route (ADD)");
return false;
}
rt_desc("deleting", rt);
retval = if_route(RTM_DELETE, rt) == -1 ? false : true;
if (!retval && errno != ENOENT && errno != ESRCH)
- syslog(LOG_ERR, "%s: if_delroute: %m", rt->rt_ifp->name);
+ logerr(__func__);
/* Remove the route from our kernel table so we can add a
* IPv4LL default route if possible. */
else
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <unistd.h>
#include "config.h"
#include "if-options.h"
#include "ipv4ll.h"
#include "ipv6nd.h"
+#include "logerr.h"
#include "script.h"
/* Allow the OS to define another script env var name */
len = strlen(prefix) + strlen(var) + 2;
if ((v = malloc(len)) == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
return NULL;
}
snprintf(v, len, "%s_%s", prefix, var);
}
nep = realloc(ne, sizeof(char *) * (j + 1));
if (nep == NULL) {
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
free(p);
ret = -1;
break;
return (ssize_t)elen;
eexit:
- syslog(LOG_ERR, "%s: %m", __func__);
+ logerr(__func__);
if (env) {
nenv = env;
while (*nenv)
/* 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);
+ logerr(__func__);
return -1;
}
argv[0] = ifp->options->script ? ifp->options->script : UNCONST(SCRIPT);
argv[1] = NULL;
- syslog(LOG_DEBUG, "%s: executing `%s' %s", ifp->name, argv[0], reason);
+ logdebug("%s: executing `%s' %s", ifp->name, argv[0], reason);
/* Resize for PATH and RC_SVCNAME */
svcname = getenv(RC_SVCNAME);
pid = exec_script(ifp->ctx, argv, env);
if (pid == -1)
- syslog(LOG_ERR, "%s: %s: %m", __func__, argv[0]);
+ logerr("%s: %s", __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");
+ logerr("%s: waitpid", __func__);
status = 0;
break;
}
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status))
- syslog(LOG_ERR, "%s: %s: WEXITSTATUS %d",
+ logerrx("%s: %s: WEXITSTATUS %d",
__func__, argv[0], WEXITSTATUS(status));
} else if (WIFSIGNALED(status))
- syslog(LOG_ERR, "%s: %s: %s",
+ logerrx("%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",
- ifp->name);
+ logerr("%s: arraytostr", ifp->name);
break;
}
}
if (control_queue(fd, bigenv, elen, 1) == -1)
- syslog(LOG_ERR, "%s: control_queue: %m", __func__);
+ logerr("%s: control_queue", __func__);
else
status = 1;
}
free(*ep++);
free(env);
if (elen == 0) {
- syslog(LOG_ERR, "%s: malloc: %m", __func__);
+ logerr(__func__);
return -1;
}
return WEXITSTATUS(status);