if (memcmp(&ifo->ia[j].iaid, iaid, sizeof(iaid)) == 0)
break;
}
- if (j == ifo->ia_len) {
+ if (j == ifo->ia_len &&
+ !(ifo->ia_len == 0 && ifp->ctx->options & DHCPCD_DUMPLEASE))
+ {
syslog(LOG_DEBUG, "%s: ignoring unrequested IAID %s",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf, sizeof(buf)));
continue;
}
- if (ifo->ia[j].ia_type != code) {
+ if ( j < ifo->ia_len && ifo->ia[j].ia_type != code) {
syslog(LOG_ERR, "%s: IAID %s: option type mismatch",
ifp->name,
hwaddr_ntoa(iaid, sizeof(iaid), buf, sizeof(buf)));
int r;
ifp->if_data[IF_DATA_DHCP6] = state = calloc(1, sizeof(*state));
- if (state == NULL)
- goto eexit;
+ if (state == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return -1;
+ }
TAILQ_INIT(&state->addrs);
dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
AF_INET6, ifp,
ifp->options->options & DHCPCD_PFXDLGONLY ? ".pd" : "");
r = dhcp6_readlease(ifp);
- if (r == -1 && errno == ENOENT) {
- strlcpy(state->leasefile, ifp->name, sizeof(state->leasefile));
- r = dhcp6_readlease(ifp);
- }
if (r == -1) {
if (errno == ENOENT)
syslog(LOG_ERR, "%s: no lease to dump", ifp->name);
}
state->reason = "DUMP6";
return script_runreason(ifp, state->reason);
-
-eexit:
- syslog(LOG_ERR, "%s: %m", __func__);
- return -1;
}
}
#ifdef INET6
- if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6) {
+ if (ifo->ia_len == 0 && ifo->options & DHCPCD_IPV6 &&
+ ifp->name[0] != '\0')
+ {
ifo->ia = malloc(sizeof(*ifo->ia));
if (ifo->ia == NULL)
syslog(LOG_ERR, "%s: %m", __func__);
main(int argc, char **argv)
{
struct dhcpcd_ctx ctx;
- char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
struct if_options *ifo;
struct interface *ifp;
uint16_t family = 0;
default:
per = "";
}
- snprintf(pidfile, sizeof(pidfile),
+ snprintf(ctx.pidfile, sizeof(ctx.pidfile),
PIDFILE, "-", argv[optind], per);
} else {
- snprintf(pidfile, sizeof(pidfile), PIDFILE, "", "", "");
+ snprintf(ctx.pidfile, sizeof(ctx.pidfile),
+ PIDFILE, "", "", "");
ctx.options |= DHCPCD_MASTER;
}
}
syslog(LOG_ERR, "%s: %m", __func__);
goto exit_failure;
}
- strlcpy(ifp->name, argv[optind], sizeof(ifp->name));
+ strlcpy(ctx.pidfile, argv[optind], sizeof(ctx.pidfile));
ifp->ctx = &ctx;
TAILQ_INSERT_HEAD(ctx.ifaces, ifp, next);
+ if (family == 0) {
+ if (ctx.pidfile[strlen(ctx.pidfile) - 1] == '6')
+ family = AF_INET6;
+ else
+ family = AF_INET;
+ }
}
configure_interface(ifp, ctx.argc, ctx.argv);
if (ctx.options & DHCPCD_PFXDLGONLY)
#ifdef USE_SIGNALS
if (sig != 0) {
- pid = read_pid(pidfile);
+ pid = read_pid(ctx.pidfile);
if (pid != 0)
syslog(LOG_INFO, "sending signal %s to pid %d",
siga, pid);
syslog(LOG_ERR, "kill: %m");
goto exit_failure;
}
- unlink(pidfile);
+ unlink(ctx.pidfile);
if (sig != SIGHUP)
goto exit_failure;
} else {
ts.tv_nsec = 100000000; /* 10th of a second */
for(i = 0; i < 100; i++) {
nanosleep(&ts, NULL);
- if (read_pid(pidfile) == 0)
+ if (read_pid(ctx.pidfile) == 0)
goto exit_success;
}
syslog(LOG_ERR, "pid %d failed to exit", pid);
}
if (!(ctx.options & DHCPCD_TEST)) {
- if ((pid = read_pid(pidfile)) > 0 &&
+ if ((pid = read_pid(ctx.pidfile)) > 0 &&
kill(pid, 0) == 0)
{
syslog(LOG_ERR, ""PACKAGE
" already running on pid %d (%s)",
- pid, pidfile);
+ pid, ctx.pidfile);
goto exit_failure;
}
#ifdef O_CLOEXEC
opt |= O_CLOEXEC;
#endif
- ctx.pid_fd = open(pidfile, opt, 0664);
+ ctx.pid_fd = open(ctx.pidfile, opt, 0664);
if (ctx.pid_fd == -1)
- syslog(LOG_ERR, "open `%s': %m", pidfile);
+ syslog(LOG_ERR, "open `%s': %m", ctx.pidfile);
else {
#ifdef LOCK_EX
/* Lock the file so that only one instance of dhcpcd
* runs on an interface */
if (flock(ctx.pid_fd, LOCK_EX | LOCK_NB) == -1) {
- syslog(LOG_ERR, "flock `%s': %m", pidfile);
+ syslog(LOG_ERR, "flock `%s': %m", ctx.pidfile);
close(ctx.pid_fd);
ctx.pid_fd = -1;
goto exit_failure;
syslog(LOG_ERR, "control_stop: %m:");
if (ctx.pid_fd != -1) {
close(ctx.pid_fd);
- unlink(pidfile);
+ unlink(ctx.pidfile);
}
eloop_free(ctx.eloop);