Import dhcpcd-7.0.0 with the following changes:
* dhcp: when unicasting on L3, unicast on L2 as well * dhcp: when rebooting, don't set cidaddr * dhcp6: don't listen on IPv6 addresses when not using DHCPv6 * dhcp: only set probe state when probing (fixes REBOOT reason) * ipv6: disable kernel RA if interface is active * hooks: set protocol to link for link layer events
This commit is contained in:
parent
011165c38b
commit
8f03b3ce8d
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Copyright (c) 2006-2017 Roy Marples
|
||||
.\" Copyright (c) 2006-2018 Roy Marples
|
||||
.\" All rights reserved
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - ARP handler
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd: BPF arp and bootp filtering
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd: BPF arp and bootp filtering
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -28,7 +28,7 @@
|
|||
#define CONFIG_H
|
||||
|
||||
#define PACKAGE "dhcpcd"
|
||||
#define VERSION "7.0.0-rc4"
|
||||
#define VERSION "7.0.0"
|
||||
|
||||
#ifndef CONFIG
|
||||
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -777,7 +777,8 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
|
|||
(type == DHCP_INFORM || type == DHCP_RELEASE ||
|
||||
(type == DHCP_REQUEST &&
|
||||
state->addr->mask.s_addr == lease->mask.s_addr &&
|
||||
(state->new == NULL || IS_DHCP(state->new)))))
|
||||
(state->new == NULL || IS_DHCP(state->new)) &&
|
||||
!(state->added & STATE_FAKE))))
|
||||
bootp->ciaddr = state->addr->addr.s_addr;
|
||||
|
||||
bootp->op = BOOTREQUEST;
|
||||
|
@ -845,6 +846,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
|
|||
if (type == DHCP_DECLINE ||
|
||||
(type == DHCP_REQUEST &&
|
||||
(state->addr == NULL ||
|
||||
state->added & STATE_FAKE ||
|
||||
lease->addr.s_addr != state->addr->addr.s_addr)))
|
||||
{
|
||||
PUT_ADDR(DHO_IPADDRESS, &lease->addr);
|
||||
|
@ -1587,10 +1589,6 @@ dhcp_openudp(struct interface *ifp)
|
|||
int s;
|
||||
struct sockaddr_in sin;
|
||||
int n;
|
||||
struct dhcp_state *state;
|
||||
#ifdef SO_BINDTODEVICE
|
||||
struct ifreq ifr;
|
||||
#endif
|
||||
|
||||
if ((s = xsocket(PF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP)) == -1)
|
||||
return -1;
|
||||
|
@ -1598,20 +1596,12 @@ dhcp_openudp(struct interface *ifp)
|
|||
n = 1;
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1)
|
||||
goto eexit;
|
||||
#ifdef SO_BINDTODEVICE
|
||||
if (ifp) {
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
|
||||
if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr,
|
||||
sizeof(ifr)) == -1)
|
||||
goto eexit;
|
||||
}
|
||||
#endif
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(BOOTPC);
|
||||
if (ifp) {
|
||||
state = D_STATE(ifp);
|
||||
struct dhcp_state *state = D_STATE(ifp);
|
||||
|
||||
if (state->addr)
|
||||
sin.sin_addr.s_addr = state->addr->addr.s_addr;
|
||||
}
|
||||
|
@ -1694,6 +1684,63 @@ dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length,
|
|||
return udpp;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
dhcp_sendudp(struct interface *ifp, struct in_addr *to, void *data, size_t len)
|
||||
{
|
||||
int s;
|
||||
struct msghdr msg;
|
||||
struct sockaddr_in sin;
|
||||
struct iovec iov[1];
|
||||
ssize_t r;
|
||||
#ifdef IP_PKTINFO
|
||||
uint8_t cmsg[CMSG_SPACE(sizeof(struct in_pktinfo))];
|
||||
struct cmsghdr *cm;
|
||||
struct in_pktinfo ipi;
|
||||
#endif
|
||||
|
||||
iov[0].iov_base = data;
|
||||
iov[0].iov_len = len;
|
||||
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr = *to;
|
||||
sin.sin_port = htons(BOOTPS);
|
||||
#ifdef HAVE_SA_LEN
|
||||
sin.sin_len = sizeof(sin);
|
||||
#endif
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_name = (void *)&sin;
|
||||
msg.msg_namelen = sizeof(sin);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
#ifdef IP_PKTINFO
|
||||
/* Set the outbound interface */
|
||||
msg.msg_control = cmsg;
|
||||
msg.msg_controllen = sizeof(cmsg);
|
||||
|
||||
memset(&ipi, 0, sizeof(ipi));
|
||||
ipi.ipi_ifindex = ifp->index;
|
||||
cm = CMSG_FIRSTHDR(&msg);
|
||||
if (cm == NULL) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
cm->cmsg_level = IPPROTO_IP;
|
||||
cm->cmsg_type = IP_PKTINFO;
|
||||
cm->cmsg_len = CMSG_LEN(sizeof(ipi));
|
||||
memcpy(CMSG_DATA(cm), &ipi, sizeof(ipi));
|
||||
#endif
|
||||
|
||||
s = dhcp_openudp(ifp);
|
||||
if (s == -1)
|
||||
return -1;
|
||||
r = sendmsg(s, &msg, 0);
|
||||
close(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
send_message(struct interface *ifp, uint8_t type,
|
||||
void (*callback)(void *))
|
||||
|
@ -1738,9 +1785,6 @@ send_message(struct interface *ifp, uint8_t type,
|
|||
timespec_to_double(&tv));
|
||||
}
|
||||
|
||||
if (dhcp_openbpf(ifp) == -1)
|
||||
return;
|
||||
|
||||
r = make_message(&bootp, ifp, type);
|
||||
if (r == -1)
|
||||
goto fail;
|
||||
|
@ -1750,6 +1794,18 @@ send_message(struct interface *ifp, uint8_t type,
|
|||
to.s_addr = state->lease.server.s_addr;
|
||||
else
|
||||
to.s_addr = INADDR_ANY;
|
||||
|
||||
/* If unicasting, try and void sending by BPF so we don't
|
||||
* use a L2 broadcast. */
|
||||
if (to.s_addr != INADDR_ANY && to.s_addr != INADDR_BROADCAST) {
|
||||
if (dhcp_sendudp(ifp, &to, bootp, len) != -1)
|
||||
goto out;
|
||||
logerr("%s: dhcp_sendudp", ifp->name);
|
||||
}
|
||||
|
||||
if (dhcp_openbpf(ifp) == -1)
|
||||
goto out;
|
||||
|
||||
udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from, to);
|
||||
if (udp == NULL) {
|
||||
logerr("%s: dhcp_makeudppacket", ifp->name);
|
||||
|
@ -1780,6 +1836,8 @@ send_message(struct interface *ifp, uint8_t type,
|
|||
callback = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
free(bootp);
|
||||
|
||||
fail:
|
||||
|
@ -1972,7 +2030,7 @@ dhcp_rebind(void *arg)
|
|||
ifp->name, lease->leasetime - lease->rebindtime);
|
||||
state->state = DHS_REBIND;
|
||||
eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
|
||||
state->lease.server.s_addr = 0;
|
||||
state->lease.server.s_addr = INADDR_ANY;
|
||||
state->interval = 0;
|
||||
ifp->options->options &= ~(DHCPCD_CSR_WARNED |
|
||||
DHCPCD_ROUTER_HOST_ROUTE_WARNED);
|
||||
|
@ -2327,7 +2385,6 @@ dhcp_arp_address(struct interface *ifp)
|
|||
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
|
||||
|
||||
state = D_STATE(ifp);
|
||||
state->state = DHS_PROBE;
|
||||
addr.s_addr = state->offer->yiaddr == INADDR_ANY ?
|
||||
state->offer->ciaddr : state->offer->yiaddr;
|
||||
/* If the interface already has the address configured
|
||||
|
@ -2340,6 +2397,7 @@ dhcp_arp_address(struct interface *ifp)
|
|||
|
||||
#ifdef IN_IFF_TENTATIVE
|
||||
if (ia == NULL || ia->addr_flags & IN_IFF_NOTUSEABLE) {
|
||||
state->state = DHS_PROBE;
|
||||
if (ia == NULL) {
|
||||
struct dhcp_lease l;
|
||||
|
||||
|
@ -2355,6 +2413,7 @@ dhcp_arp_address(struct interface *ifp)
|
|||
if (ifp->options->options & DHCPCD_ARP && ia == NULL) {
|
||||
struct dhcp_lease l;
|
||||
|
||||
state->state = DHS_PROBE;
|
||||
get_lease(ifp, &l, state->offer, state->offer_len);
|
||||
loginfox("%s: probing address %s/%d",
|
||||
ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask));
|
||||
|
@ -2570,7 +2629,7 @@ dhcp_reboot(struct interface *ifp)
|
|||
#endif
|
||||
|
||||
dhcp_new_xid(ifp);
|
||||
state->lease.server.s_addr = 0;
|
||||
state->lease.server.s_addr = INADDR_ANY;
|
||||
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
|
||||
|
||||
#ifdef IPV4LL
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -1099,7 +1099,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
|
|||
memset(&dst, 0, sizeof(dst));
|
||||
dst.sin6_family = AF_INET6;
|
||||
dst.sin6_port = htons(DHCP6_SERVER_PORT);
|
||||
#ifdef SIN6_LEN
|
||||
#ifdef HAVE_SA_LEN
|
||||
dst.sin6_len = sizeof(dst);
|
||||
#endif
|
||||
|
||||
|
@ -2051,7 +2051,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
|
|||
a->flags &= ~(IPV6_AF_STALE |
|
||||
IPV6_AF_EXTENDED |
|
||||
IPV6_AF_REQUEST);
|
||||
if (a->prefix_vltime != ntohl(pdp.vltime))
|
||||
if (a->prefix_vltime != pdp.vltime)
|
||||
a->flags |= IPV6_AF_NEW;
|
||||
}
|
||||
|
||||
|
@ -2405,6 +2405,7 @@ dhcp6_readlease(struct interface *ifp, int validate)
|
|||
return -1;
|
||||
retval = -1;
|
||||
lease = NULL;
|
||||
free(state->new);
|
||||
state->new_len = dhcp_read_lease_fd(fd, (void **)&lease);
|
||||
state->new = lease;
|
||||
if (fd_opened)
|
||||
|
@ -3676,8 +3677,6 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state)
|
|||
if (state != NULL) {
|
||||
switch (init_state) {
|
||||
case DH6S_INIT:
|
||||
/* This should only happen on OS's where we keep state
|
||||
* on carrier down, such as NetBSD-8. */
|
||||
goto gogogo;
|
||||
case DH6S_INFORM:
|
||||
if (state->state == DH6S_INFORMED)
|
||||
|
@ -3695,8 +3694,6 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state)
|
|||
}
|
||||
break;
|
||||
case DH6S_CONFIRM:
|
||||
/* This should only happen on OS's where we keep state
|
||||
* on carrier down, such as NetBSD-8. */
|
||||
init_state = DH6S_INIT;
|
||||
goto gogogo;
|
||||
default:
|
||||
|
@ -3879,16 +3876,18 @@ void
|
|||
dhcp6_handleifa(int cmd, struct ipv6_addr *ia)
|
||||
{
|
||||
struct dhcp6_state *state;
|
||||
struct interface *ifp = ia->iface;
|
||||
|
||||
/* If not running in master mode, listen to this address */
|
||||
if (cmd == RTM_NEWADDR &&
|
||||
!(ia->addr_flags & IN6_IFF_NOTUSEABLE) &&
|
||||
ia->iface->active == IF_ACTIVE_USER &&
|
||||
!(ia->iface->ctx->options & DHCPCD_MASTER) &&
|
||||
ifp->active == IF_ACTIVE_USER &&
|
||||
!(ifp->ctx->options & DHCPCD_MASTER) &&
|
||||
ifp->options->options & DHCPCD_DHCP6 &&
|
||||
ia->dhcp6_fd == -1)
|
||||
dhcp6_listen(ia->iface->ctx, ia);
|
||||
|
||||
if ((state = D6_STATE(ia->iface)) != NULL)
|
||||
if ((state = D6_STATE(ifp)) != NULL)
|
||||
ipv6_handleifa_addrs(cmd, &state->addrs, ia);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Copyright (c) 2006-2017 Roy Marples
|
||||
.\" Copyright (c) 2006-2018 Roy Marples
|
||||
.\" All rights reserved
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -25,7 +25,7 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
const char dhcpcd_copyright[] = "Copyright (c) 2006-2017 Roy Marples";
|
||||
const char dhcpcd_copyright[] = "Copyright (c) 2006-2018 Roy Marples";
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -438,7 +438,7 @@ configure_interface1(struct interface *ifp)
|
|||
~(DHCPCD_IPV6RS | DHCPCD_DHCP6 | DHCPCD_WAITIP6);
|
||||
|
||||
/* We want to disable kernel interface RA as early as possible. */
|
||||
if (ifo->options & DHCPCD_IPV6RS &&
|
||||
if (ifp->active == IF_ACTIVE_USER &&
|
||||
!(ifp->ctx->options & DHCPCD_DUMPLEASE))
|
||||
{
|
||||
int ra_global, ra_iface;
|
||||
|
@ -975,6 +975,7 @@ int
|
|||
dhcpcd_handleinterface(void *arg, int action, const char *ifname)
|
||||
{
|
||||
struct dhcpcd_ctx *ctx;
|
||||
struct ifaddrs *ifaddrs;
|
||||
struct if_head *ifs;
|
||||
struct interface *ifp, *iff, *ifn;
|
||||
const char * const argv[] = { ifname };
|
||||
|
@ -998,7 +999,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
|
|||
}
|
||||
|
||||
i = -1;
|
||||
ifs = if_discover(ctx, -1, UNCONST(argv));
|
||||
ifs = if_discover(ctx, &ifaddrs, -1, UNCONST(argv));
|
||||
if (ifs == NULL) {
|
||||
logerr(__func__);
|
||||
return -1;
|
||||
|
@ -1043,6 +1044,17 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
|
|||
dhcpcd_prestartinterface(iff);
|
||||
}
|
||||
|
||||
if_learnaddrs(ctx, ifs, &ifaddrs);
|
||||
|
||||
/* Now we have learned addresses, start the interface */
|
||||
TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
|
||||
if (strcmp(ifp->name, ifname) != 0)
|
||||
continue;
|
||||
iff = if_find(ctx->ifaces, ifp->name);
|
||||
if (action > 0 && iff->active)
|
||||
dhcpcd_prestartinterface(iff);
|
||||
}
|
||||
|
||||
/* Free our discovered list */
|
||||
while ((ifp = TAILQ_FIRST(ifs))) {
|
||||
TAILQ_REMOVE(ifs, ifp, next);
|
||||
|
@ -1403,6 +1415,7 @@ int
|
|||
main(int argc, char **argv)
|
||||
{
|
||||
struct dhcpcd_ctx ctx;
|
||||
struct ifaddrs *ifaddrs = NULL;
|
||||
struct if_options *ifo;
|
||||
struct interface *ifp;
|
||||
uint16_t family = 0;
|
||||
|
@ -1678,7 +1691,7 @@ printpidfile:
|
|||
if (optind != argc) {
|
||||
/* We need to try and find the interface so we can load
|
||||
* the hardware address to compare automated IAID */
|
||||
ctx.ifaces = if_discover(&ctx,
|
||||
ctx.ifaces = if_discover(&ctx, &ifaddrs,
|
||||
argc - optind, argv + optind);
|
||||
} else {
|
||||
if ((ctx.ifaces = malloc(sizeof(*ctx.ifaces))) != NULL)
|
||||
|
@ -1842,7 +1855,7 @@ printpidfile:
|
|||
(DHCPCD_MASTER | DHCPCD_DEV))
|
||||
dev_start(&ctx);
|
||||
|
||||
ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
|
||||
ctx.ifaces = if_discover(&ctx, &ifaddrs, ctx.ifc, ctx.ifv);
|
||||
if (ctx.ifaces == NULL) {
|
||||
logerr("%s: if_discover", __func__);
|
||||
goto exit_failure;
|
||||
|
@ -1878,6 +1891,7 @@ printpidfile:
|
|||
if (ifp->active)
|
||||
dhcpcd_initstate1(ifp, argc, argv, 0);
|
||||
}
|
||||
if_learnaddrs(&ctx, ctx.ifaces, &ifaddrs);
|
||||
|
||||
if (ctx.options & DHCPCD_BACKGROUND && dhcpcd_daemonise(&ctx))
|
||||
goto exit_success;
|
||||
|
@ -1948,6 +1962,8 @@ exit_failure:
|
|||
i = EXIT_FAILURE;
|
||||
|
||||
exit1:
|
||||
if (ifaddrs != NULL)
|
||||
freeifaddrs(ifaddrs);
|
||||
if (control_stop(&ctx) == -1)
|
||||
logerr("%s: control_stop", __func__);
|
||||
/* Free memory and close fd's */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Copyright (c) 2006-2017 Roy Marples
|
||||
.\" Copyright (c) 2006-2018 Roy Marples
|
||||
.\" All rights reserved
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* eloop - portable event based main loop.
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved.
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* BSD interface driver for dhcpcd
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -190,8 +190,9 @@ if_hasconf(struct dhcpcd_ctx *ctx, const char *ifname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
|
||||
struct ifaddrs *ifaddrs)
|
||||
void
|
||||
if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
|
||||
struct ifaddrs **ifaddrs)
|
||||
{
|
||||
struct ifaddrs *ifa;
|
||||
struct interface *ifp;
|
||||
|
@ -203,7 +204,7 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
|
|||
#endif
|
||||
int addrflags;
|
||||
|
||||
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
||||
for (ifa = *ifaddrs; ifa; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue;
|
||||
if ((ifp = if_find(ifs, ifa->ifa_name)) == NULL)
|
||||
|
@ -262,6 +263,9 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(*ifaddrs);
|
||||
*ifaddrs = NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -283,9 +287,10 @@ if_valid_hwaddr(const uint8_t *hwaddr, size_t hwlen)
|
|||
}
|
||||
|
||||
struct if_head *
|
||||
if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
|
||||
if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
|
||||
int argc, char * const *argv)
|
||||
{
|
||||
struct ifaddrs *ifaddrs, *ifa;
|
||||
struct ifaddrs *ifa;
|
||||
int i;
|
||||
unsigned int active;
|
||||
struct if_head *ifs;
|
||||
|
@ -307,14 +312,17 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
|
|||
const struct sockaddr_ll *sll;
|
||||
#endif
|
||||
|
||||
if (getifaddrs(&ifaddrs) == -1)
|
||||
if ((ifs = malloc(sizeof(*ifs))) == NULL) {
|
||||
logerr(__func__);
|
||||
return NULL;
|
||||
|
||||
if ((ifs = malloc(sizeof(*ifs))) == NULL)
|
||||
goto failed;
|
||||
}
|
||||
TAILQ_INIT(ifs);
|
||||
if (getifaddrs(ifaddrs) == -1) {
|
||||
logerr(__func__);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
|
||||
for (ifa = *ifaddrs; ifa; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr != NULL) {
|
||||
#ifdef AF_LINK
|
||||
if (ifa->ifa_addr->sa_family != AF_LINK)
|
||||
|
@ -565,9 +573,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
|
|||
TAILQ_INSERT_TAIL(ifs, ifp, next);
|
||||
}
|
||||
|
||||
if_learnaddrs(ctx, ifs, ifaddrs);
|
||||
failed:
|
||||
freeifaddrs(ifaddrs);
|
||||
out:
|
||||
return ifs;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -35,6 +35,8 @@
|
|||
#include <netinet/in_var.h> /* for IN_IFF_TENTATIVE et all */
|
||||
#endif
|
||||
|
||||
#include <ifaddrs.h>
|
||||
|
||||
/* Some systems have in-built IPv4 DAD.
|
||||
* However, we need them to do DAD at carrier up as well. */
|
||||
#ifdef IN_IFF_TENTATIVE
|
||||
|
@ -112,7 +114,9 @@ int if_getifaddrs(struct ifaddrs **);
|
|||
int if_setflag(struct interface *ifp, short flag);
|
||||
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING))
|
||||
bool if_valid_hwaddr(const uint8_t *, size_t);
|
||||
struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
|
||||
struct if_head *if_discover(struct dhcpcd_ctx *, struct ifaddrs **,
|
||||
int, char * const *);
|
||||
void if_learnaddrs(struct dhcpcd_ctx *, struct if_head *, struct ifaddrs **);
|
||||
struct interface *if_find(struct if_head *, const char *);
|
||||
struct interface *if_findindex(struct if_head *, unsigned int);
|
||||
struct interface *if_loopback(struct dhcpcd_ctx *);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - IPv6 ND handling
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -286,7 +286,7 @@ ipv6nd_sendrsprobe(void *arg)
|
|||
|
||||
memset(&dst, 0, sizeof(dst));
|
||||
dst.sin6_family = AF_INET6;
|
||||
#ifdef SIN6_LEN
|
||||
#ifdef HAVE_SA_LEN
|
||||
dst.sin6_len = sizeof(dst);
|
||||
#endif
|
||||
dst.sin6_scope_id = ifp->index;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - IPv6 ND handling
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* logerr: errx with logging
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* logerr: errx with logging
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - route management
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - route management
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* rEDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS, WITH OR WITHOUT
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Socket Address handling for dhcpcd
|
||||
* Copyright (c) 2015-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2015-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Socket Address handling for dhcpcd
|
||||
* Copyright (c) 2015-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2015-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -218,14 +218,14 @@ arraytostr(const char *const *argv, char **s)
|
|||
return (ssize_t)len;
|
||||
}
|
||||
|
||||
#define PROTO_NONE 0
|
||||
#define PROTO_LINK 0
|
||||
#define PROTO_DHCP 1
|
||||
#define PROTO_IPV4LL 2
|
||||
#define PROTO_RA 3
|
||||
#define PROTO_DHCP6 4
|
||||
#define PROTO_STATIC6 5
|
||||
static const char *protocols[] = {
|
||||
NULL,
|
||||
"link",
|
||||
"dhcp",
|
||||
"ipv4ll",
|
||||
"ra",
|
||||
|
@ -295,7 +295,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
|
|||
strcmp(reason, "UNKNOWN") == 0 ||
|
||||
strcmp(reason, "DEPARTED") == 0 ||
|
||||
strcmp(reason, "STOPPED") == 0)
|
||||
protocol = PROTO_NONE;
|
||||
protocol = PROTO_LINK;
|
||||
#ifdef INET
|
||||
#ifdef IPV4LL
|
||||
else if (strcmp(reason, "IPV4LL") == 0)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
* Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
|
||||
* Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
|
||||
* All rights reserved
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
Loading…
Reference in New Issue