From: Roy Marples Date: Tue, 13 Nov 2012 11:25:51 +0000 (+0000) Subject: Use a proper namespace for eloop X-Git-Tag: v5.99.3~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9eb6e8dc9449c3d0fc42c94fe3187be8367b9b04;p=thirdparty%2Fdhcpcd.git Use a proper namespace for eloop --- diff --git a/arp.c b/arp.c index 1905508e..0862ba02 100644 --- a/arp.c +++ b/arp.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ (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; @@ -53,72 +53,72 @@ send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip) 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; @@ -143,8 +143,8 @@ handle_arp_packet(void *arg) 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); @@ -162,13 +162,13 @@ handle_arp_packet(void *arg) (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; } @@ -179,19 +179,19 @@ handle_arp_packet(void *arg) 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; } } @@ -200,30 +200,30 @@ handle_arp_packet(void *arg) 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)) { @@ -236,19 +236,19 @@ send_arp_announce(void *arg) 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; @@ -262,49 +262,50 @@ send_arp_probe(void *arg) 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); } diff --git a/bind.c b/bind.c index 14f77027..f6228923 100644 --- a/bind.c +++ b/bind.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -62,7 +62,7 @@ daemonise(void) 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. */ @@ -213,9 +213,9 @@ bind_interface(void *arg) 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); diff --git a/control.c b/control.c index 9e728017..2bfcb77f 100644 --- a/control.c +++ b/control.c @@ -73,7 +73,7 @@ control_remove(void *arg) 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 @@ -132,7 +132,7 @@ control_handle(_unused void *arg) 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); } } @@ -165,7 +165,7 @@ control_start(void) close(fd); return -1; } - add_event(fd, control_handle, NULL); + eloop_event_add(fd, control_handle, NULL); return fd; } @@ -175,7 +175,7 @@ control_stop(void) int retval = 0; struct fd_list *l; - delete_event(fd); + eloop_event_delete(fd); if (shutdown(fd, SHUT_RDWR) == -1) retval = 1; fd = -1; @@ -185,7 +185,7 @@ control_stop(void) 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; diff --git a/dhcp6.c b/dhcp6.c index b0e9221d..d31f70eb 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -653,9 +653,10 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) 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); @@ -732,7 +733,7 @@ dhcp6_startrebind(void *arg) 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; @@ -761,7 +762,7 @@ dhcp6_startdiscover(void *arg) 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; @@ -804,7 +805,7 @@ dhcp6_startrequest(struct interface *ifp) { 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; @@ -838,7 +839,7 @@ dhcp6_startconfirm(struct interface *ifp) 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 @@ -867,7 +868,7 @@ dhcp6_startexpire(void *arg) 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); @@ -1313,7 +1314,7 @@ recv: 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; @@ -1367,11 +1368,14 @@ recv: 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, @@ -1442,7 +1446,7 @@ dhcp6_open(void) 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; @@ -1511,7 +1515,7 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) { struct dhcp6_state *state; - delete_timeout(NULL, ifp); + eloop_timeout_delete(NULL, ifp); state = D6_STATE(ifp); if (state) { dhcp6_freedrop_addrs(ifp, drop); @@ -1535,7 +1539,7 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) break; if (ifp == NULL && sock != -1) { close(sock); - delete_event(sock); + eloop_event_delete(sock); sock = -1; } } diff --git a/dhcpcd.c b/dhcpcd.c index 360ccdae..638f43e3 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -232,7 +232,7 @@ handle_exit_timeout(_unused void *arg) 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 @@ -282,7 +282,7 @@ stop_interface(struct interface *iface) 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); @@ -381,7 +381,7 @@ send_message(struct interface *iface, int type, if (!(options & DHCPCD_TEST)) drop_dhcp(iface, "FAIL"); close_sockets(iface); - delete_timeout(NULL, iface); + eloop_timeout_delete(NULL, iface); callback = NULL; } } @@ -390,7 +390,7 @@ send_message(struct interface *iface, int type, /* 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 @@ -437,7 +437,7 @@ start_expire(void *arg) } 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) @@ -540,7 +540,7 @@ handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp, const struct i } 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 { @@ -600,7 +600,7 @@ handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp, const struct i 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 @@ -641,7 +641,7 @@ handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp, const struct i } 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 @@ -954,7 +954,7 @@ handle_carrier(int action, int flags, const char *ifname) 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"); @@ -994,16 +994,17 @@ start_discover(void *arg) 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)", @@ -1049,7 +1050,7 @@ start_rebind(void *arg) 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); } @@ -1115,7 +1116,7 @@ start_static(struct interface *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); } @@ -1172,15 +1173,15 @@ start_reboot(struct 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); @@ -1240,7 +1241,7 @@ start_interface(void *arg) 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 */ @@ -1768,7 +1769,7 @@ open_sockets(struct interface *iface) 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 && @@ -1788,12 +1789,12 @@ void 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; } @@ -2083,7 +2084,7 @@ main(int argc, char **argv) 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 @@ -2105,7 +2106,7 @@ main(int argc, char **argv) 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 || @@ -2115,7 +2116,7 @@ main(int argc, char **argv) if (ipv6nsfd == -1) syslog(LOG_ERR, "ipv6nd: %m"); else - add_event(ipv6nsfd, ipv6ns_handledata, NULL); + eloop_event_add(ipv6nsfd, ipv6ns_handledata, NULL); } } @@ -2190,7 +2191,7 @@ main(int argc, char **argv) } 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); @@ -2198,8 +2199,8 @@ main(int argc, char **argv) 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); } diff --git a/eloop.c b/eloop.c index ebbf3718..85219780 100644 --- a/eloop.c +++ b/eloop.c @@ -59,7 +59,7 @@ static struct timeout { 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; @@ -90,7 +90,7 @@ add_event(int fd, void (*callback)(void *), void *arg) } void -delete_event(int fd) +eloop_event_delete(int fd) { struct event *e, *last = NULL; @@ -109,7 +109,7 @@ delete_event(int fd) } 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; @@ -170,20 +170,22 @@ add_q_timeout_tv(int queue, } 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; @@ -213,17 +215,17 @@ v_delete_q_timeouts(int queue, void *arg, void (*callback)(void *), va_list v) } 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; @@ -248,7 +250,7 @@ delete_q_timeout(int queue, void (*callback)(void *), void *arg) * 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; @@ -279,12 +281,12 @@ void 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; diff --git a/eloop.h b/eloop.h index df06dce6..1d96f983 100644 --- a/eloop.h +++ b/eloop.h @@ -35,19 +35,23 @@ #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 diff --git a/ipv4ll.c b/ipv4ll.c index 622abb7e..79e31653 100644 --- a/ipv4ll.c +++ b/ipv4ll.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -88,7 +88,7 @@ start_ipv4ll(void *arg) 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) { @@ -144,13 +144,13 @@ handle_ipv4ll_failure(void *arg) 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); } } diff --git a/ipv6ns.c b/ipv6ns.c index 762ee9a7..02e7f82e 100644 --- a/ipv6ns.c +++ b/ipv6ns.c @@ -229,10 +229,10 @@ ipv6ns_sendprobe(void *arg) 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); } @@ -354,7 +354,7 @@ ipv6ns_handledata(_unused void *arg) 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); } } diff --git a/ipv6rs.c b/ipv6rs.c index 7072b2a0..024d5d2c 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -251,7 +251,7 @@ ipv6rs_sendprobe(void *arg) 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); @@ -309,8 +309,8 @@ ipv6rs_freedrop_addrs(struct ra *rap, int drop) 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); @@ -748,8 +748,8 @@ ipv6rs_handledata(_unused void *arg) 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 && @@ -1047,7 +1047,7 @@ ipv6rs_expire(void *arg) } 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"); @@ -1059,7 +1059,7 @@ ipv6rs_start(struct interface *ifp) { struct rs_state *state; - delete_timeout(NULL, ifp); + eloop_timeout_delete(NULL, ifp); state = RS_STATE(ifp); if (state == NULL) {