in_addr_t a = INADDR_ANY;
struct timespec tv;
int s;
+#ifdef IN_IFF_NOTUSEABLE
+ struct ipv4_addr *ia;
+#endif
if (!callback)
logger(ifp->ctx, LOG_DEBUG, "%s: sending %s with xid 0x%x",
if (state->added && !(state->added & STATE_FAKE) &&
state->addr.s_addr != INADDR_ANY &&
state->new != NULL &&
+#ifdef IN_IFF_NOTUSEABLE
+ ((ia = ipv4_iffindaddr(ifp, &state->addr, NULL)) &&
+ !(ia->addr_flags & IN_IFF_NOTUSEABLE)) &&
+#endif
(state->new->cookie == htonl(MAGIC_COOKIE) ||
ifp->options->options & DHCPCD_INFORM))
{
size_t auth_len;
char *msg;
struct arp_state *astate;
+#ifdef IN_IFF_DUPLICATED
+ struct ipv4_addr *ia;
+#endif
/* We may have found a BOOTP server */
if (get_option_uint8(ifp->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
return;
}
- if ((type == 0 || type == DHCP_OFFER) &&
- (state->state == DHS_DISCOVER || state->state == DHS_IPV4LL_BOUND))
- {
#ifdef IN_IFF_DUPLICATED
- struct ipv4_addr *ia;
+ ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
+ if (ia && ia->addr_flags & IN_IFF_DUPLICATED) {
+ log_dhcp(LOG_WARNING, "declined duplicate address",
+ ifp, dhcp, from);
+ if (type)
+ dhcp_decline(ifp);
+ eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
+ eloop_timeout_add_sec(ifp->ctx->eloop,
+ DHCP_RAND_MAX, dhcp_discover, ifp);
+ return;
+ }
#endif
+ if ((type == 0 || type == DHCP_OFFER) &&
+ (state->state == DHS_DISCOVER || state->state == DHS_IPV4LL_BOUND))
+ {
lease->frominfo = 0;
lease->addr.s_addr = dhcp->yiaddr;
lease->cookie = dhcp->cookie;
&lease->server, dhcp, DHO_SERVERID) != 0)
lease->server.s_addr = INADDR_ANY;
log_dhcp(LOG_INFO, "offered", ifp, dhcp, from);
-#ifdef IN_IFF_DUPLICATED
- ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
- if (ia && ia->addr_flags & IN_IFF_DUPLICATED) {
- log_dhcp(LOG_WARNING, "declined duplicate address",
- ifp, dhcp, from);
- dhcp_decline(ifp);
- eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
- eloop_timeout_add_sec(ifp->ctx->eloop,
- DHCP_RAND_MAX, dhcp_discover, ifp);
- return;
- }
-#endif
free(state->offer);
state->offer = dhcp;
*dhcpp = NULL;
lease->frominfo = 0;
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
astate = NULL;
- if (ifo->options & DHCPCD_ARP &&
- state->addr.s_addr != state->offer->yiaddr)
+
+#ifndef IN_IFF_TENTATIVE
+ if (ifo->options & DHCPCD_ARP
+ && state->addr.s_addr != state->offer->yiaddr)
+#endif
{
+ addr.s_addr = state->offer->yiaddr;
+#ifndef IN_IFF_TENTATIVE
/* If the interface already has the address configured
* then we can't ARP for duplicate detection. */
- addr.s_addr = state->offer->yiaddr;
- if (!ipv4_iffindaddr(ifp, &addr, NULL)) {
+ ia = ipv4_findaddr(ifp->ctx, &addr);
+ if (ia) {
+#endif
astate = arp_new(ifp, &addr);
if (astate) {
astate->probed_cb = dhcp_arp_probed;
}
#ifndef IN_IFF_TENTATIVE
return;
-#endif
}
+#endif
}
dhcp_bind(ifp, astate);
/* Don't log an error if some other process
* is handling this. */
if (errno != EADDRINUSE)
- logger(ifp->ctx, LOG_ERR, "dhcp_openudp: %m");
+ logger(ifp->ctx, LOG_ERR,
+ "%s: dhcp_openudp: %m", __func__);
} else
eloop_event_add(ifp->ctx->eloop,
ifp->ctx->udp_fd, dhcp_handleudp,
}
static void
-configure_interface1(struct interface *ifp, struct if_options *old)
+configure_interface1(struct interface *ifp)
{
struct if_options *ifo = ifp->options;
int ra_global, ra_iface;
/* If we are not sending an authentication option, don't require it */
if (!(ifo->auth.options & DHCPCD_AUTH_SEND))
ifo->auth.options &= ~DHCPCD_AUTH_REQUIRE;
-
- /* If we ARPing something or options have changed,
- * drop leases and restart */
- if (old) {
- /* Remove warning options for a fair comparison */
- old->options &= ~(DHCPCD_WARNINGS | DHCPCD_CONF);
- if (ifo->arping_len || memcmp(ifo, old, sizeof(*old)))
- dhcpcd_drop(ifp, 0);
- free(old);
- }
}
int
} else
*ifp->profile = '\0';
- if (profile) {
- struct if_options *old;
-
- old = ifp->options;
- ifp->options = ifo;
- configure_interface1(ifp, old);
- } else {
- free_options(ifp->options);
- ifp->options = ifo;
- }
+ free_options(ifp->options);
+ ifp->options = ifo;
+ if (profile)
+ configure_interface1(ifp);
return 1;
}
configure_interface(struct interface *ifp, int argc, char **argv,
unsigned long long options)
{
- struct if_options *old;
+ time_t old;
- old = ifp->options;
+ old = ifp->options ? ifp->options->mtime : 0;
dhcpcd_selectprofile(ifp, NULL);
add_options(ifp->ctx, ifp->name, ifp->options, argc, argv);
ifp->options->options |= options;
- configure_interface1(ifp, old);
+ configure_interface1(ifp);
+
+ /* If the mtime has changed drop any old lease */
+ if (ifp->options && old != 0 && ifp->options->mtime != old) {
+ logger(ifp->ctx, LOG_WARNING,
+ "%s: confile file changed, expiring leases", ifp->name);
+ dhcpcd_drop(ifp, 0);
+ }
}
static void