/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
(sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
static int
-send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip)
+send_arp(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
{
uint8_t arp_buffer[ARP_LEN];
struct arphdr ar;
uint8_t *p;
int retval;
- ar.ar_hrd = htons(iface->family);
+ ar.ar_hrd = htons(ifp->family);
ar.ar_pro = htons(ETHERTYPE_IP);
- ar.ar_hln = iface->hwlen;
+ ar.ar_hln = ifp->hwlen;
ar.ar_pln = sizeof(sip);
ar.ar_op = htons(op);
memcpy(arp_buffer, &ar, sizeof(ar));
p = arp_buffer + sizeof(ar);
- memcpy(p, iface->hwaddr, iface->hwlen);
- p += iface->hwlen;
+ memcpy(p, ifp->hwaddr, ifp->hwlen);
+ p += ifp->hwlen;
memcpy(p, &sip, sizeof(sip));
p += sizeof(sip);
/* ARP requests should ignore this */
- retval = iface->hwlen;
+ retval = ifp->hwlen;
while (retval--)
*p++ = '\0';
memcpy(p, &tip, sizeof(tip));
p += sizeof(tip);
len = p - arp_buffer;
- retval = send_raw_packet(iface, ETHERTYPE_ARP, arp_buffer, len);
+ retval = send_raw_packet(ifp, ETHERTYPE_ARP, arp_buffer, len);
return retval;
}
static void
-handle_arp_failure(struct interface *iface)
+handle_arp_failure(struct interface *ifp)
{
/* If we failed without a magic cookie then we need to try
* and defend our IPv4LL address. */
- if ((iface->state->offer != NULL &&
- iface->state->offer->cookie != htonl(MAGIC_COOKIE)) ||
- (iface->state->new != NULL &&
- iface->state->new->cookie != htonl(MAGIC_COOKIE)))
+ if ((ifp->state->offer != NULL &&
+ ifp->state->offer->cookie != htonl(MAGIC_COOKIE)) ||
+ (ifp->state->new != NULL &&
+ ifp->state->new->cookie != htonl(MAGIC_COOKIE)))
{
- handle_ipv4ll_failure(iface);
+ handle_ipv4ll_failure(ifp);
return;
}
- unlink(iface->leasefile);
- if (!iface->state->lease.frominfo)
- send_decline(iface);
- close_sockets(iface);
- delete_timeout(NULL, iface);
- if (iface->state->lease.frominfo)
- start_interface(iface);
+ unlink(ifp->leasefile);
+ if (!ifp->state->lease.frominfo)
+ send_decline(ifp);
+ close_sockets(ifp);
+ eloop_timeout_delete(NULL, ifp);
+ if (ifp->state->lease.frominfo)
+ start_interface(ifp);
else
- add_timeout_sec(DHCP_ARP_FAIL, start_interface, iface);
+ eloop_timeout_add_sec(DHCP_ARP_FAIL, start_interface, ifp);
}
static void
handle_arp_packet(void *arg)
{
- struct interface *iface = arg;
+ struct interface *ifp = arg;
uint8_t arp_buffer[ARP_LEN];
struct arphdr ar;
uint32_t reply_s;
uint32_t reply_t;
uint8_t *hw_s, *hw_t;
ssize_t bytes;
- struct if_state *state = iface->state;
+ struct if_state *state = ifp->state;
struct if_options *opts = state->options;
const char *hwaddr;
struct in_addr ina;
state->fail.s_addr = 0;
for(;;) {
- bytes = get_raw_packet(iface, ETHERTYPE_ARP,
+ bytes = get_raw_packet(ifp, ETHERTYPE_ARP,
arp_buffer, sizeof(arp_buffer), NULL);
if (bytes == 0 || bytes == -1)
return;
if ((hw_t + ar.ar_hln + ar.ar_pln) - arp_buffer > bytes)
continue;
/* Ignore messages from ourself */
- if (ar.ar_hln == iface->hwlen &&
- memcmp(hw_s, iface->hwaddr, iface->hwlen) == 0)
+ if (ar.ar_hln == ifp->hwlen &&
+ memcmp(hw_s, ifp->hwaddr, ifp->hwlen) == 0)
continue;
/* Copy out the IP addresses */
memcpy(&reply_s, hw_s + ar.ar_hln, ar.ar_pln);
(size_t)ar.ar_hln);
syslog(LOG_INFO,
"%s: found %s on hardware address %s",
- iface->name, inet_ntoa(ina), hwaddr);
- if (select_profile(iface, hwaddr) == -1 &&
+ ifp->name, inet_ntoa(ina), hwaddr);
+ if (select_profile(ifp, hwaddr) == -1 &&
errno == ENOENT)
- select_profile(iface, inet_ntoa(ina));
- close_sockets(iface);
- delete_timeout(NULL, iface);
- start_interface(iface);
+ select_profile(ifp, inet_ntoa(ina));
+ close_sockets(ifp);
+ eloop_timeout_delete(NULL, ifp);
+ start_interface(ifp);
return;
}
state->fail.s_addr = state->offer->yiaddr;
/* Handle IPv4LL conflicts */
- if (IN_LINKLOCAL(htonl(iface->addr.s_addr)) &&
- (reply_s == iface->addr.s_addr ||
- (reply_s == 0 && reply_t == iface->addr.s_addr)))
- state->fail.s_addr = iface->addr.s_addr;
+ if (IN_LINKLOCAL(htonl(ifp->addr.s_addr)) &&
+ (reply_s == ifp->addr.s_addr ||
+ (reply_s == 0 && reply_t == ifp->addr.s_addr)))
+ state->fail.s_addr = ifp->addr.s_addr;
if (state->fail.s_addr) {
syslog(LOG_ERR, "%s: hardware address %s claims %s",
- iface->name,
+ ifp->name,
hwaddr_ntoa((unsigned char *)hw_s,
(size_t)ar.ar_hln),
inet_ntoa(state->fail));
errno = EEXIST;
- handle_arp_failure(iface);
+ handle_arp_failure(ifp);
return;
}
}
void
send_arp_announce(void *arg)
{
- struct interface *iface = arg;
- struct if_state *state = iface->state;
+ struct interface *ifp = arg;
+ struct if_state *state = ifp->state;
struct timeval tv;
if (state->new == NULL)
return;
- if (iface->arp_fd == -1) {
- open_socket(iface, ETHERTYPE_ARP);
- add_event(iface->arp_fd, handle_arp_packet, iface);
+ if (ifp->arp_fd == -1) {
+ open_socket(ifp, ETHERTYPE_ARP);
+ eloop_event_add(ifp->arp_fd, handle_arp_packet, ifp);
}
if (++state->claims < ANNOUNCE_NUM)
syslog(LOG_DEBUG,
"%s: sending ARP announce (%d of %d), "
"next in %d.00 seconds",
- iface->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
+ ifp->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
else
syslog(LOG_DEBUG,
"%s: sending ARP announce (%d of %d)",
- iface->name, state->claims, ANNOUNCE_NUM);
- if (send_arp(iface, ARPOP_REQUEST,
+ ifp->name, state->claims, ANNOUNCE_NUM);
+ if (send_arp(ifp, ARPOP_REQUEST,
state->new->yiaddr, state->new->yiaddr) == -1)
syslog(LOG_ERR, "send_arp: %m");
if (state->claims < ANNOUNCE_NUM) {
- add_timeout_sec(ANNOUNCE_WAIT, send_arp_announce, iface);
+ eloop_timeout_add_sec(ANNOUNCE_WAIT, send_arp_announce, ifp);
return;
}
if (state->new->cookie != htonl(MAGIC_COOKIE)) {
tv.tv_sec = state->interval - DHCP_RAND_MIN;
tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U);
timernorm(&tv);
- add_timeout_tv(&tv, start_discover, iface);
+ eloop_timeout_add_tv(&tv, start_discover, ifp);
} else {
- delete_event(iface->arp_fd);
- close(iface->arp_fd);
- iface->arp_fd = -1;
+ eloop_event_delete(ifp->arp_fd);
+ close(ifp->arp_fd);
+ ifp->arp_fd = -1;
}
}
void
send_arp_probe(void *arg)
{
- struct interface *iface = arg;
- struct if_state *state = iface->state;
+ struct interface *ifp = arg;
+ struct if_state *state = ifp->state;
struct in_addr addr;
struct timeval tv;
int arping = 0;
else
addr.s_addr = state->offer->ciaddr;
} else
- addr.s_addr = iface->addr.s_addr;
+ addr.s_addr = ifp->addr.s_addr;
- if (iface->arp_fd == -1) {
- open_socket(iface, ETHERTYPE_ARP);
- add_event(iface->arp_fd, handle_arp_packet, iface);
+ if (ifp->arp_fd == -1) {
+ open_socket(ifp, ETHERTYPE_ARP);
+ eloop_event_add(ifp->arp_fd, handle_arp_packet, ifp);
}
if (state->probes == 0) {
if (arping)
syslog(LOG_INFO, "%s: searching for %s",
- iface->name, inet_ntoa(addr));
+ ifp->name, inet_ntoa(addr));
else
syslog(LOG_INFO, "%s: checking for %s",
- iface->name, inet_ntoa(addr));
+ ifp->name, inet_ntoa(addr));
}
if (++state->probes < PROBE_NUM) {
tv.tv_sec = PROBE_MIN;
tv.tv_usec = arc4random() % (PROBE_MAX_U - PROBE_MIN_U);
timernorm(&tv);
- add_timeout_tv(&tv, send_arp_probe, iface);
+ eloop_timeout_add_tv(&tv, send_arp_probe, ifp);
} else {
tv.tv_sec = ANNOUNCE_WAIT;
tv.tv_usec = 0;
if (arping) {
state->probes = 0;
if (++state->arping_index < state->options->arping_len)
- add_timeout_tv(&tv, send_arp_probe, iface);
+ eloop_timeout_add_tv(&tv, send_arp_probe, ifp);
else
- add_timeout_tv(&tv, start_interface, iface);
+ eloop_timeout_add_tv(&tv, start_interface, ifp);
} else
- add_timeout_tv(&tv, bind_interface, iface);
+ eloop_timeout_add_tv(&tv, bind_interface, ifp);
}
syslog(LOG_DEBUG,
"%s: sending ARP probe (%d of %d), next in %0.2f seconds",
- iface->name, state->probes ? state->probes : PROBE_NUM, PROBE_NUM,
+ ifp->name, state->probes ? state->probes : PROBE_NUM, PROBE_NUM,
timeval_to_double(&tv));
- if (send_arp(iface, ARPOP_REQUEST, 0, addr.s_addr) == -1)
+ if (send_arp(ifp, ARPOP_REQUEST, 0, addr.s_addr) == -1)
syslog(LOG_ERR, "send_arp: %m");
}
void
-start_arping(struct interface *iface)
+start_arping(struct interface *ifp)
{
- iface->state->probes = 0;
- iface->state->arping_index = 0;
- send_arp_probe(iface);
+
+ ifp->state->probes = 0;
+ ifp->state->arping_index = 0;
+ send_arp_probe(ifp);
}
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
char buf = '\0';
int sidpipe[2], fd;
- delete_timeout(handle_exit_timeout, NULL);
+ eloop_timeout_delete(handle_exit_timeout, NULL);
if (options & DHCPCD_DAEMONISED || !(options & DHCPCD_DAEMONISE))
return 0;
/* Setup a signal pipe so parent knows when to exit. */
if (lease->leasetime == ~0U)
lease->renewaltime = lease->rebindtime = lease->leasetime;
else {
- add_timeout_sec(lease->renewaltime, start_renew, iface);
- add_timeout_sec(lease->rebindtime, start_rebind, iface);
- add_timeout_sec(lease->leasetime, start_expire, iface);
+ eloop_timeout_add_sec(lease->renewaltime, start_renew, iface);
+ eloop_timeout_add_sec(lease->rebindtime, start_rebind, iface);
+ eloop_timeout_add_sec(lease->leasetime, start_expire, iface);
syslog(LOG_DEBUG,
"%s: renew in %u seconds, rebind in %u seconds",
iface->name, lease->renewaltime, lease->rebindtime);
n = l->next;
if (l == arg) {
close(l->fd);
- delete_event(l->fd);
+ eloop_event_delete(l->fd);
if (last == NULL)
control_fds = l->next;
else
l->listener = 0;
l->next = control_fds;
control_fds = l;
- add_event(l->fd, control_handle_data, l);
+ eloop_event_add(l->fd, control_handle_data, l);
}
}
close(fd);
return -1;
}
- add_event(fd, control_handle, NULL);
+ eloop_event_add(fd, control_handle, NULL);
return fd;
}
int retval = 0;
struct fd_list *l;
- delete_event(fd);
+ eloop_event_delete(fd);
if (shutdown(fd, SHUT_RDWR) == -1)
retval = 1;
fd = -1;
l = control_fds;
while (l != NULL) {
control_fds = l->next;
- delete_event(l->fd);
+ eloop_event_delete(l->fd);
shutdown(l->fd, SHUT_RDWR);
free(l);
l = control_fds;
state->RTC++;
if (callback) {
if (state->MRC == 0 || state->RTC < state->MRC)
- add_timeout_tv(&state->RT, callback, ifp);
+ eloop_timeout_add_tv(&state->RT, callback, ifp);
else if (state->MRC != 0 && state->MRCcallback)
- add_timeout_tv(&state->RT, state->MRCcallback, ifp);
+ eloop_timeout_add_tv(&state->RT, state->MRCcallback,
+ ifp);
else
syslog(LOG_WARNING, "%s: sent %d times with no reply",
ifp->name, state->RTC);
struct dhcp6_state *state;
ifp = arg;
- delete_timeout(dhcp6_sendrenew, ifp);
+ eloop_timeout_delete(dhcp6_sendrenew, ifp);
state = D6_STATE(ifp);
state->state = DH6S_REBIND;
state->RTC = 0;
state->MRT = SOL_MAX_RT;
state->MRC = 0;
- delete_timeout(NULL, ifp);
+ eloop_timeout_delete(NULL, ifp);
free(state->new);
state->new = NULL;
state->new_len = 0;
{
struct dhcp6_state *state;
- delete_timeout(dhcp6_senddiscover, ifp);
+ eloop_timeout_delete(dhcp6_senddiscover, ifp);
state = D6_STATE(ifp);
state->state = DH6S_REQUEST;
state->RTC = 0;
return;
}
dhcp6_sendconfirm(ifp);
- add_timeout_sec(CNF_MAX_RD, dhcp6_failconfirm, ifp);
+ eloop_timeout_add_sec(CNF_MAX_RD, dhcp6_failconfirm, ifp);
}
static void
const struct dhcp6_state *state;
ifp = arg;
- delete_timeout(dhcp6_sendrebind, ifp);
+ eloop_timeout_delete(dhcp6_sendrebind, ifp);
syslog(LOG_ERR, "%s: DHCPv6 lease expired", ifp->name);
dhcp6_freedrop_addrs(ifp, 1);
syslog(LOG_INFO, "%s: %s received from %s", ifp->name, op, sfrom);
reason = NULL;
- delete_timeout(NULL, ifp);
+ eloop_timeout_delete(NULL, ifp);
switch(state->state) {
case DH6S_INFORM:
state->renew = 0;
if (!(options & DHCPCD_TEST)) {
state->state = DH6S_BOUND;
if (state->renew)
- add_timeout_sec(state->renew, dhcp6_startrenew, ifp);
+ eloop_timeout_add_sec(state->renew,
+ dhcp6_startrenew, ifp);
if (state->rebind)
- add_timeout_sec(state->rebind, dhcp6_startrebind, ifp);
+ eloop_timeout_add_sec(state->rebind,
+ dhcp6_startrebind, ifp);
if (state->expire != ~0U)
- add_timeout_sec(state->expire, dhcp6_startexpire, ifp);
+ eloop_timeout_add_sec(state->expire,
+ dhcp6_startexpire, ifp);
ipv6_addaddrs(ifp, &state->addrs);
if (state->renew || state->rebind)
syslog(LOG_INFO,
if (set_cloexec(sock) == -1 || set_nonblock(sock) == -1)
goto errexit;
- add_event(sock, dhcp6_handledata, NULL);
+ eloop_event_add(sock, dhcp6_handledata, NULL);
return 0;
{
struct dhcp6_state *state;
- delete_timeout(NULL, ifp);
+ eloop_timeout_delete(NULL, ifp);
state = D6_STATE(ifp);
if (state) {
dhcp6_freedrop_addrs(ifp, drop);
break;
if (ifp == NULL && sock != -1) {
close(sock);
- delete_event(sock);
+ eloop_event_delete(sock);
sock = -1;
}
}
options &= ~DHCPCD_TIMEOUT_IPV4LL;
timeout = (PROBE_NUM * PROBE_MAX) + (PROBE_WAIT * 2);
syslog(LOG_WARNING, "allowing %d seconds for IPv4LL timeout", timeout);
- add_timeout_sec(timeout, handle_exit_timeout, NULL);
+ eloop_timeout_add_sec(timeout, handle_exit_timeout, NULL);
}
void
if (strcmp(iface->state->reason, "RELEASE") != 0)
drop_dhcp(iface, "STOP");
close_sockets(iface);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
free_interface(ifp);
if (!(options & (DHCPCD_MASTER | DHCPCD_TEST)))
exit(EXIT_FAILURE);
if (!(options & DHCPCD_TEST))
drop_dhcp(iface, "FAIL");
close_sockets(iface);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
callback = NULL;
}
}
/* Even if we fail to send a packet we should continue as we are
* as our failure timeouts will change out codepath when needed. */
if (callback)
- add_timeout_tv(&tv, callback, iface);
+ eloop_timeout_add_tv(&tv, callback, iface);
}
static void
}
syslog(LOG_ERR, "%s: lease expired", iface->name);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
drop_dhcp(iface, "EXPIRE");
unlink(iface->leasefile);
if (iface->carrier != LINK_DOWN)
}
close_sockets(iface);
/* If we constantly get NAKS then we should slowly back off */
- add_timeout_sec(state->nakoff, start_interface, iface);
+ eloop_timeout_add_sec(state->nakoff, start_interface, iface);
if (state->nakoff == 0)
state->nakoff = 1;
else {
run_script(iface);
exit(EXIT_SUCCESS);
}
- delete_timeout(send_discover, iface);
+ eloop_timeout_delete(send_discover, iface);
/* We don't request BOOTP addresses */
if (type) {
/* We used to ARP check here, but that seems to be in
}
lease->frominfo = 0;
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
/* We now have an offer, so close the DHCP sockets.
* This allows us to safely ARP when broken DHCP servers send an ACK
iface->carrier = LINK_DOWN;
syslog(LOG_INFO, "%s: carrier lost", iface->name);
close_sockets(iface);
- delete_timeouts(iface, start_expire, NULL);
+ eloop_timeouts_delete(iface, start_expire, NULL);
dhcp6_drop(iface, "EXPIRE6");
ipv6rs_drop(iface);
drop_dhcp(iface, "NOCARRIER");
iface->state->state = DHS_DISCOVER;
iface->state->xid = dhcp_xid(iface);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
if (ifo->fallback)
- add_timeout_sec(timeout, start_fallback, iface);
+ eloop_timeout_add_sec(timeout, start_fallback, iface);
else if (ifo->options & DHCPCD_IPV4LL &&
!IN_LINKLOCAL(htonl(iface->addr.s_addr)))
{
if (IN_LINKLOCAL(htonl(iface->state->fail.s_addr)))
- add_timeout_sec(RATE_LIMIT_INTERVAL, start_ipv4ll, iface);
+ eloop_timeout_add_sec(RATE_LIMIT_INTERVAL,
+ start_ipv4ll, iface);
else
- add_timeout_sec(timeout, start_ipv4ll, iface);
+ eloop_timeout_add_sec(timeout, start_ipv4ll, iface);
}
if (ifo->options & DHCPCD_REQUEST)
syslog(LOG_INFO, "%s: broadcasting for a lease (requesting %s)",
syslog(LOG_DEBUG, "%s: expire in %u seconds",
iface->name, lease->leasetime - lease->rebindtime);
iface->state->state = DHS_REBIND;
- delete_timeout(send_renew, iface);
+ eloop_timeout_delete(send_renew, iface);
iface->state->lease.server.s_addr = 0;
send_rebind(iface);
}
ifo = iface->state->options;
iface->state->offer =
dhcp_message_new(&ifo->req_addr, &ifo->req_mask);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
bind_interface(iface);
}
iface->state->state = DHS_REBOOT;
iface->state->xid = dhcp_xid(iface);
iface->state->lease.server.s_addr = 0;
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
if (ifo->fallback)
- add_timeout_sec(ifo->reboot, start_fallback, iface);
+ eloop_timeout_add_sec(ifo->reboot, start_fallback, iface);
else if (ifo->options & DHCPCD_LASTLEASE &&
iface->state->lease.frominfo)
- add_timeout_sec(ifo->reboot, start_timeout, iface);
+ eloop_timeout_add_sec(ifo->reboot, start_timeout, iface);
else if (!(ifo->options & DHCPCD_INFORM &&
- options & (DHCPCD_MASTER | DHCPCD_DAEMONISED)))
- add_timeout_sec(ifo->reboot, start_expire, iface);
+ options & (DHCPCD_MASTER | DHCPCD_DAEMONISED)))
+ eloop_timeout_add_sec(ifo->reboot, start_expire, iface);
/* Don't bother ARP checking as the server could NAK us first. */
if (ifo->options & DHCPCD_INFORM)
send_inform(iface);
iface->name);
drop_dhcp(iface, "FAIL");
close_sockets(iface);
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
return;
}
/* We don't want to read the old lease if we NAK an old test */
if ((r = open_socket(iface, ETHERTYPE_IP)) == -1)
syslog(LOG_ERR, "%s: open_socket: %m", iface->name);
else
- add_event(iface->raw_fd, handle_dhcp_packet, iface);
+ eloop_event_add(iface->raw_fd, handle_dhcp_packet, iface);
}
if (iface->udp_fd == -1 &&
iface->addr.s_addr != 0 &&
close_sockets(struct interface *iface)
{
if (iface->arp_fd != -1) {
- delete_event(iface->arp_fd);
+ eloop_event_delete(iface->arp_fd);
close(iface->arp_fd);
iface->arp_fd = -1;
}
if (iface->raw_fd != -1) {
- delete_event(iface->raw_fd);
+ eloop_event_delete(iface->raw_fd);
close(iface->raw_fd);
iface->raw_fd = -1;
}
if (linkfd == -1)
syslog(LOG_ERR, "open_link_socket: %m");
else
- add_event(linkfd, handle_link, NULL);
+ eloop_event_add(linkfd, handle_link, NULL);
}
#if 0
syslog(LOG_ERR, "ipv6rs: %m");
options &= ~DHCPCD_IPV6RS;
} else {
- add_event(ipv6rsfd, ipv6rs_handledata, NULL);
+ eloop_event_add(ipv6rsfd, ipv6rs_handledata, NULL);
// atexit(restore_rtadv);
}
if (options & DHCPCD_IPV6RA_OWN ||
if (ipv6nsfd == -1)
syslog(LOG_ERR, "ipv6nd: %m");
else
- add_event(ipv6nsfd, ipv6ns_handledata, NULL);
+ eloop_event_add(ipv6nsfd, ipv6ns_handledata, NULL);
}
}
} else if (i > 0) {
if (options & DHCPCD_IPV4LL)
options |= DHCPCD_TIMEOUT_IPV4LL;
- add_timeout_sec(i, handle_exit_timeout, NULL);
+ eloop_timeout_add_sec(i, handle_exit_timeout, NULL);
}
}
free_options(if_options);
sort_interfaces();
for (iface = ifaces; iface; iface = iface->next)
- add_timeout_sec(0, start_interface, iface);
+ eloop_timeout_add_sec(0, start_interface, iface);
- start_eloop(&dhcpcd_sigset);
+ eloop_start(&dhcpcd_sigset);
exit(EXIT_SUCCESS);
}
static struct timeout *free_timeouts;
void
-add_event(int fd, void (*callback)(void *), void *arg)
+eloop_event_add(int fd, void (*callback)(void *), void *arg)
{
struct event *e, *last = NULL;
}
void
-delete_event(int fd)
+eloop_event_delete(int fd)
{
struct event *e, *last = NULL;
}
void
-add_q_timeout_tv(int queue,
+eloop_q_timeout_add_tv(int queue,
const struct timeval *when, void (*callback)(void *), void *arg)
{
struct timeval w;
}
void
-add_q_timeout_sec(int queue, time_t when, void (*callback)(void *), void *arg)
+eloop_q_timeout_add_sec(int queue, time_t when,
+ void (*callback)(void *), void *arg)
{
struct timeval tv;
tv.tv_sec = when;
tv.tv_usec = 0;
- add_q_timeout_tv(queue, &tv, callback, arg);
+ eloop_q_timeout_add_tv(queue, &tv, callback, arg);
}
/* This deletes all timeouts for the interface EXCEPT for ones with the
* callbacks given. Handy for deleting everything apart from the expire
* timeout. */
static void
-v_delete_q_timeouts(int queue, void *arg, void (*callback)(void *), va_list v)
+eloop_q_timeouts_delete_v(int queue, void *arg,
+ void (*callback)(void *), va_list v)
{
struct timeout *t, *tt, *last = NULL;
va_list va;
}
void
-delete_q_timeouts(int queue, void *arg, void (*callback)(void *), ...)
+eloop_q_timeouts_delete(int queue, void *arg, void (*callback)(void *), ...)
{
va_list va;
va_start(va, callback);
- v_delete_q_timeouts(queue, arg, callback, va);
+ eloop_q_timeouts_delete_v(queue, arg, callback, va);
va_end(va);
}
void
-delete_q_timeout(int queue, void (*callback)(void *), void *arg)
+eloop_q_timeout_delete(int queue, void (*callback)(void *), void *arg)
{
struct timeout *t, *tt, *last = NULL;
* Normally we don't do this as the OS will do it for us at exit,
* but it's handy for debugging other leaks in valgrind. */
static void
-cleanup(void)
+eloop_cleanup(void)
{
struct event *e;
struct timeout *t;
eloop_init(void)
{
- atexit(cleanup);
+ atexit(eloop_cleanup);
}
#endif
_noreturn void
-start_eloop(const sigset_t *cursigs)
+eloop_start(const sigset_t *cursigs)
{
int n, max_fd;
fd_set read_fds;
#define ELOOP_QUEUE 0
#endif
-#define add_timeout_tv(a, b, c) add_q_timeout_tv(ELOOP_QUEUE, a, b, c)
-#define add_timeout_sec(a, b, c) add_q_timeout_sec(ELOOP_QUEUE, a, b, c)
-#define delete_timeout(a, b) delete_q_timeout(ELOOP_QUEUE, a, b)
-#define delete_timeouts(a, ...) delete_q_timeouts(ELOOP_QUEUE, a, __VA_ARGS__)
+#define eloop_timeout_add_tv(a, b, c) \
+ eloop_q_timeout_add_tv(ELOOP_QUEUE, a, b, c)
+#define eloop_timeout_add_sec(a, b, c) \
+ eloop_q_timeout_add_sec(ELOOP_QUEUE, a, b, c)
+#define eloop_timeout_delete(a, b) \
+ eloop_q_timeout_delete(ELOOP_QUEUE, a, b)
+#define eloop_timeouts_delete(a, ...) \
+ eloop_q_timeouts_delete(ELOOP_QUEUE, a, __VA_ARGS__)
-void add_event(int fd, void (*)(void *), void *);
-void delete_event(int fd);
-void add_q_timeout_sec(int queue, time_t, void (*)(void *), void *);
-void add_q_timeout_tv(int queue, const struct timeval *, void (*)(void *),
+void eloop_event_add(int fd, void (*)(void *), void *);
+void eloop_event_delete(int fd);
+void eloop_q_timeout_add_sec(int queue, time_t, void (*)(void *), void *);
+void eloop_q_timeout_add_tv(int queue, const struct timeval *, void (*)(void *),
void *);
-void delete_q_timeout(int, void (*)(void *), void *);
-void delete_q_timeouts(int, void *, void (*)(void *), ...);
+void eloop_q_timeout_delete(int, void (*)(void *), void *);
+void eloop_q_timeouts_delete(int, void *, void (*)(void *), ...);
void eloop_init(void);
-void start_eloop(const sigset_t *);
+void eloop_start(const sigset_t *);
#endif
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
struct interface *iface = arg;
uint32_t addr;
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
iface->state->probes = 0;
iface->state->claims = 0;
if (iface->addr.s_addr) {
close_sockets(iface);
free(iface->state->offer);
iface->state->offer = NULL;
- delete_timeout(NULL, iface);
+ eloop_timeout_delete(NULL, iface);
if (++iface->state->conflicts > MAX_CONFLICTS) {
syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
iface->name);
iface->state->interval = RATE_LIMIT_INTERVAL / 2;
start_discover(iface);
} else {
- add_timeout_sec(PROBE_WAIT, start_ipv4ll, iface);
+ eloop_timeout_add_sec(PROBE_WAIT, start_ipv4ll, iface);
}
}
rtv.tv_sec = 0;
rtv.tv_usec = arc4random() % (MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR);
timeradd(&tv, &rtv, &tv);
- add_timeout_tv(&tv, ipv6ns_sendprobe, rap);
+ eloop_timeout_add_tv(&tv, ipv6ns_sendprobe, rap);
if (rap->nsprobes++ == 0)
- add_timeout_sec(DELAY_FIRST_PROBE_TIME,
+ eloop_timeout_add_sec(DELAY_FIRST_PROBE_TIME,
ipv6ns_unreachable, rap);
}
tv.tv_sec = REACHABLE_TIME;
tv.tv_usec = 0;
}
- add_timeout_tv(&tv, ipv6ns_sendprobe, rap);
- delete_timeout(ipv6ns_unreachable, rap);
+ eloop_timeout_add_tv(&tv, ipv6ns_sendprobe, rap);
+ eloop_timeout_delete(ipv6ns_unreachable, rap);
}
}
syslog(LOG_ERR, "%s: sendmsg: %m", ifp->name);
if (state->rsprobes++ < MAX_RTR_SOLICITATIONS)
- add_timeout_sec(RTR_SOLICITATION_INTERVAL,
+ eloop_timeout_add_sec(RTR_SOLICITATION_INTERVAL,
ipv6rs_sendprobe, ifp);
else
syslog(LOG_INFO, "%s: no IPv6 Routers available", ifp->name);
void ipv6rs_freedrop_ra(struct ra *rap, int drop)
{
- delete_timeout(NULL, rap->iface);
- delete_timeout(NULL, rap);
+ eloop_timeout_delete(NULL, rap->iface);
+ eloop_timeout_delete(NULL, rap);
TAILQ_REMOVE(&ipv6_routers, rap, next);
ipv6rs_freedrop_addrs(rap, drop);
ipv6rs_free_opts(rap);
if (!(ifp->state->options->options & DHCPCD_IPV6RA_REQRDNSS))
has_dns = 1;
- delete_timeout(NULL, ifp);
- delete_timeout(NULL, rap); /* reachable timer */
+ eloop_timeout_delete(NULL, ifp);
+ eloop_timeout_delete(NULL, rap); /* reachable timer */
if (has_dns)
daemonise();
else if (options & DHCPCD_DAEMONISE &&
}
if (timerisset(&next))
- add_timeout_tv(&next, ipv6rs_expire, ifp);
+ eloop_timeout_add_tv(&next, ipv6rs_expire, ifp);
if (expired) {
ipv6_buildroutes();
run_script_reason(ifp, "ROUTERADVERT");
{
struct rs_state *state;
- delete_timeout(NULL, ifp);
+ eloop_timeout_delete(NULL, ifp);
state = RS_STATE(ifp);
if (state == NULL) {