Import dhcpcd-5.2.9 with the following changes:

* syntax in 50-ypbind hook has been fixed
* man page corrections
* report hwaddr used by dhcpcd when debug is enabled
* Fix detecting inet address for INFORM support
* document reason RELEASE in dhcpcd-run-hooks
* Support RTM_CHGADDR in the upcoming NetBSD-6
  This is used to work out if the hwaddr has changed as the interface
  does not go down/up unlike other OSes
* ntp hook no longer attempts to restart ntpd if 1st attempt failed
This commit is contained in:
roy 2010-11-27 11:24:09 +00:00
parent b7f896571b
commit 0632cf1e32
13 changed files with 118 additions and 44 deletions

View File

@ -26,7 +26,9 @@
*/
/* Needed define to get at getline for glibc and FreeBSD */
#define _GNU_SOURCE
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <sys/cdefs.h>

View File

@ -28,7 +28,7 @@
#define CONFIG_H
#define PACKAGE "dhcpcd"
#define VERSION "5.2.8"
#define VERSION "5.2.9"
#ifndef CONFIG
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"

View File

@ -8,7 +8,7 @@
# NTP_CONF=/usr/pkg/etc/ntpd.conf
# to use openntpd from pkgsrc instead of the system provided ntp.
: ${ntpd_restart_cmd:="service_condcommand ntpd restart || service_condcommand ntp restart"}
: ${ntpd_restart_cmd:=service_condcommand ntpd restart}
if type invoke-rc.d >/dev/null 2>&1; then
# Debian has a seperate file for DHCP config to avoid stamping on
# the master.

View File

@ -1,8 +1,8 @@
# Sample dhcpcd hook for ypbind
# This script is only suitable for the Linux version.
: ${ypbind_restart_cmd:="service_command ypbind restart"}
: ${ypbind_stop_cmd:="service_condcommand ypbind stop"}
: ${ypbind_restart_cmd:=service_command ypbind restart}
: ${ypbind_stop_cmd:=service_condcommand ypbind stop}
ypbind_dir="$state_dir/ypbind"
best_domain()
@ -65,7 +65,7 @@ restore_yp_binding()
if [ "$reason" = PREINIT ]; then
rm -f "$ypbind_dir/$interface"
else if $if_up || $if_down; then
elif $if_up || $if_down; then
if [ -n "$new_nis_domain" ]; then
make_yp_binding
elif [ -n "$old_nis_domain" ]; then

View File

@ -27,7 +27,7 @@
.Os
.Sh NAME
.Nm dhcpcd-run-hooks
.Nd DHCP client configuration script
.Nd DHCP client configuration script
.Sh DESCRIPTION
.Nm
is used by
@ -35,7 +35,7 @@ is used by
to run any system and user defined hook scripts.
System hook scripts are found in
.Pa @HOOKDIR@
and the user defined hooks are
and the user defined hooks are
.Pa @SYSCONFDIR@/dhcpcd.enter-hook .
and
.Pa @SYSCONFDIR@/dhcpcd.exit-hook .
@ -97,6 +97,8 @@ dhcpcd is monitoring the interface for a 3rd party to give it an IP address.
dhcpcd failed to contact any DHCP servers but was able to use an old lease.
.It Dv EXPIRE
dhcpcd's lease or state expired and it failed to obtain a new one.
.It Dv RELEASE
dhcpcd's lease was released back to the DHCP server for re-use.
.It Dv NAK
dhcpcd received a NAK from the DHCP server.
This should be treated as EXPIRE.
@ -110,16 +112,15 @@ means it cannot work as a DHCP or ZeroConf client.
Static configuration and DHCP INFORM is still allowed.
.It Dv STOP
dhcpcd stopped running on the interface.
.iT Dv DUMP
.It Dv DUMP
dhcpcd has been asked to dump the last lease for the interface.
.It Dv TEST
dhcpcd received an OFFER from a DHCP server but will not configure the
interface.
This is primarily used to test the variables are filled correctly for the
script to process them.
.El
.Sh FILES
.Sh FILES
When
.Nm
runs, it loads

View File

@ -29,7 +29,7 @@ uniqify()
echo "${result# *}"
}
# List interface config files in a dir
# List interface config files in a directory.
# If dhcpcd is running as a single instance then it will have a list of
# interfaces in the preferred order.
# Otherwise we just use what we have.
@ -94,8 +94,8 @@ remove_markers()
fi
}
# Compare two files
# If different, replace first with second otherwise remove second
# Compare two files.
# If different, replace first with second otherwise remove second.
change_file()
{
if [ -e "$1" ]; then

View File

@ -809,17 +809,23 @@ configure_interface1(struct interface *iface)
if (ifo->options & DHCPCD_CLIENTID)
syslog(LOG_DEBUG, "%s: using ClientID %s", iface->name,
hwaddr_ntoa(iface->clientid + 1, *iface->clientid));
else
syslog(LOG_DEBUG, "%s: using hwaddr %s", iface->name,
hwaddr_ntoa(iface->hwaddr, iface->hwlen));
}
int
select_profile(struct interface *iface, const char *profile)
{
struct if_options *ifo;
int ret;
ret = 0;
ifo = read_config(cffile, iface->name, iface->ssid, profile);
if (ifo == NULL) {
syslog(LOG_DEBUG, "%s: no profile %s", iface->name, profile);
return -1;
ret = -1;
goto exit;
}
if (profile != NULL) {
strlcpy(iface->state->profile, profile,
@ -830,8 +836,11 @@ select_profile(struct interface *iface, const char *profile)
*iface->state->profile = '\0';
free_options(iface->state->options);
iface->state->options = ifo;
configure_interface1(iface);
return 0;
exit:
if (profile)
configure_interface1(iface);
return ret;
}
static void
@ -841,7 +850,6 @@ start_fallback(void *arg)
iface = (struct interface *)arg;
select_profile(iface, iface->state->options->fallback);
configure_interface1(iface);
start_interface(iface);
}
@ -1273,6 +1281,43 @@ handle_interface(int action, const char *ifname)
}
}
#ifdef RTM_CHGADDR
void
handle_hwaddr(const char *ifname, unsigned char *hwaddr, size_t hwlen)
{
struct interface *ifp;
struct if_options *ifo;
for (ifp = ifaces; ifp; ifp = ifp->next)
if (strcmp(ifp->name, ifname) == 0 && ifp->hwlen <= hwlen) {
ifo = ifp->state->options;
if (!(ifo->options &
(DHCPCD_INFORM | DHCPCD_STATIC | DHCPCD_CLIENTID))
&& ifp->state->new != NULL &&
ifp->state->new->cookie == htonl(MAGIC_COOKIE))
{
syslog(LOG_INFO,
"%s: expiring for new hardware address",
ifp->name);
drop_config(ifp, "EXPIRE");
}
memcpy(ifp->hwaddr, hwaddr, hwlen);
ifp->hwlen = hwlen;
if (!(ifo->options &
(DHCPCD_INFORM | DHCPCD_STATIC | DHCPCD_CLIENTID)))
{
syslog(LOG_DEBUG, "%s: using hwaddr %s",
ifp->name,
hwaddr_ntoa(ifp->hwaddr, ifp->hwlen));
ifp->state->interval = 0;
ifp->state->nakoff = 1;
start_interface(ifp);
}
}
free(hwaddr);
}
#endif
void
handle_ifa(int type, const char *ifname,
struct in_addr *addr, struct in_addr *net, struct in_addr *dst)
@ -1640,7 +1685,8 @@ open_sockets(struct interface *iface)
if (iface->udp_fd == -1 &&
iface->addr.s_addr != 0 &&
iface->state->new != NULL &&
iface->state->new->cookie == htonl(MAGIC_COOKIE))
(iface->state->new->cookie == htonl(MAGIC_COOKIE) ||
iface->state->options->options & DHCPCD_INFORM))
{
if (open_udp_socket(iface) == -1 && errno != EADDRINUSE)
syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name);

View File

@ -27,7 +27,7 @@
.Os
.Sh NAME
.Nm dhcpcd.conf
.Nd dhcpcd configuration file
.Nd dhcpcd configuration file
.Sh DESCRIPTION
Although
.Nm dhcpcd

View File

@ -123,6 +123,7 @@ extern struct interface *ifaces;
struct interface *find_interface(const char *);
int handle_args(struct fd_list *, int, char **);
void handle_interface(int, const char *);
void handle_hwaddr(const char *, unsigned char *, size_t);
void handle_ifa(int, const char *,
struct in_addr *, struct in_addr *, struct in_addr *);
void handle_exit_timeout(void *);

View File

@ -223,16 +223,6 @@ delete_q_timeouts(int queue, void *arg, void (*callback)(void *), ...)
va_end(va);
}
void
delete_timeouts( void *arg, void (*callback)(void *), ...)
{
va_list va;
va_start(va, callback);
v_delete_q_timeouts(0, arg, callback, va);
va_end(va);
}
void
delete_q_timeout(int queue, void (*callback)(void *), void *arg)
{

View File

@ -30,9 +30,14 @@
#include <time.h>
#define add_timeout_tv(a, b, c) add_q_timeout_tv(0, a, b, c)
#define add_timeout_sec(a, b, c) add_q_timeout_sec(0, a, b, c)
#define delete_timeout(a, b) delete_q_timeout(0, a, b)
#ifndef ELOOP_QUEUE
#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__)
void add_event(int fd, void (*)(void *), void *);
void delete_event(int fd);
@ -41,7 +46,6 @@ void add_q_timeout_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 delete_timeouts(void *, void (*)(void *), ...);
void start_eloop(void);
#endif

View File

@ -65,9 +65,7 @@
/* FIXME: Why do we need to check for sa_family 255 */
#define COPYOUT(sin, sa) \
sin.s_addr = ((sa) != NULL && ((sa)->sa_family == AF_INET || \
(sa)->sa_family == 255)) \
? \
sin.s_addr = ((sa) != NULL) ? \
(((struct sockaddr_in *)(void *)sa)->sin_addr).s_addr : 0
static int r_fd = -1;
@ -317,6 +315,10 @@ manage_link(int fd)
struct rt rt;
struct sockaddr *sa, *rti_info[RTAX_MAX];
int len;
#ifdef RTM_CHGADDR
struct sockaddr_dl sdl;
unsigned char *hwaddr;
#endif
for (;;) {
if (ioctl(fd, FIONREAD, &len) == -1)
@ -376,17 +378,41 @@ manage_link(int fd)
COPYOUT(rt.gate, rti_info[RTAX_GATEWAY]);
route_deleted(&rt);
break;
case RTM_DELADDR:
#ifdef RTM_CHGADDR
case RTM_CHGADDR: /* FALLTHROUGH */
#endif
case RTM_DELADDR: /* FALLTHROUGH */
case RTM_NEWADDR:
ifam = (struct ifa_msghdr *)(void *)p;
if (!if_indextoname(ifam->ifam_index, ifname))
break;
cp = (char *)(void *)(ifam + 1);
get_addrs(ifam->ifam_addrs, cp, rti_info);
COPYOUT(rt.dest, rti_info[RTAX_IFA]);
COPYOUT(rt.net, rti_info[RTAX_NETMASK]);
COPYOUT(rt.gate, rti_info[RTAX_BRD]);
if (if_indextoname(ifam->ifam_index, ifname))
if (rti_info[RTAX_IFA] == NULL)
break;
switch (rti_info[RTAX_IFA]->sa_family) {
#ifdef RTM_CHGADDR
case AF_LINK:
if (rtm->rtm_type != RTM_CHGADDR)
break;
memcpy(&sdl, rti_info[RTAX_IFA],
rti_info[RTAX_IFA]->sa_len);
hwaddr = xmalloc(sdl.sdl_alen);
memcpy(hwaddr, LLADDR(&sdl),
sdl.sdl_alen);
handle_hwaddr(ifname, hwaddr,
sdl.sdl_alen);
break;
#endif
case AF_INET:
case 255: /* FIXME: Why 255? */
COPYOUT(rt.dest, rti_info[RTAX_IFA]);
COPYOUT(rt.net, rti_info[RTAX_NETMASK]);
COPYOUT(rt.gate, rti_info[RTAX_BRD]);
handle_ifa(rtm->rtm_type, ifname,
&rt.dest, &rt.net, &rt.gate);
break;
}
break;
}
}

View File

@ -525,8 +525,12 @@ do_address(const char *ifname,
if (act == 1) {
addr->s_addr = a->sin_addr.s_addr;
net->s_addr = n->sin_addr.s_addr;
if (dst && ifa->ifa_flags & IFF_POINTOPOINT)
dst->s_addr = d->sin_addr.s_addr;
if (dst) {
if (ifa->ifa_flags & IFF_POINTOPOINT)
dst->s_addr = d->sin_addr.s_addr;
else
dst->s_addr = INADDR_ANY;
}
retval = 1;
break;
}