+Ensure that dhcpcd.sh is always called.
flock the pidfile and stop writing the parent pid to it so we're more robst.
Enable DHCP_INFORM support via the -S option (requires -s ipaddr too)
Use the DUID stored to create an RFC 4361 conformant client identifier
#define DROP_CONFIG { \
memset (&dhcp->address, 0, sizeof (struct in_addr)); \
- if (iface->previous_address.s_addr != 0 && ! options->persistent) \
+ if (! options->persistent) \
configure (options, iface, dhcp); \
free_dhcp (dhcp); \
memset (dhcp, 0, sizeof (dhcp_t)); \
state = STATE_INIT;
timeout = 0;
xid = 0;
- DROP_CONFIG;
+ free_dhcp (dhcp);
+ memset (dhcp, 0, sizeof (dhcp_t));
continue;
}
SOCKET_MODE (SOCKET_OPEN);
SEND_MESSAGE (DHCP_DECLINE);
SOCKET_MODE (SOCKET_CLOSED);
- DROP_CONFIG;
+ free_dhcp (dhcp);
+ memset (dhcp, 0, sizeof (dhcp_t));
xid = 0;
timeout = 0;
state = STATE_INIT;
+
/* RFC 2131 says that we should wait for 10 seconds
before doing anything else */
logger (LOG_INFO, "sleeping for 10 seconds");
{
struct stat buf;
-#ifdef ENABLE_INFO
if (! script || ! infofile || ! arg)
return;
-#else
- if (! script || ! arg)
- return ;
-#endif
if (stat (script, &buf) < 0) {
if (strcmp (script, DEFAULT_SCRIPT) != 0)
return;
}
-#ifdef ENABLE_INFO
- logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg);
+ logger (LOG_DEBUG, "exec \"%s\" \"%s\" \"%s\"", script, infofile, arg);
exec_cmd (script, infofile, arg, (char *) NULL);
-#else
- infofile = NULL; /* appease gcc */
- logger (LOG_DEBUG, "exec \"%s \"\" %s\"", script, arg);
- exec_cmd (script, "", arg, (char *) NULL);
-#endif
}
static int make_resolv (const char *ifname, const dhcp_t *dhcp)
iface->previous_mtu = iface->mtu;
}
+#ifdef ENABLE_INFO
+ /* If we haven't created an info file, do so now */
+ if (! dhcp->frominfo && iface->previous_address.s_addr == 0)
+ write_info (iface, dhcp, options);
+#endif
+
/* Only reset things if we had set them before */
if (iface->previous_address.s_addr != 0) {
if (! options->keep_address) {
memset (&iface->previous_address, 0, sizeof (struct in_addr));
memset (&iface->previous_netmask, 0, sizeof (struct in_addr));
}
+ }
- restore_resolv (iface->name);
+ restore_resolv (iface->name);
+ /* we currently don't have a resolvconf style programs for ntp/nis */
+
+ exec_script (options->script, iface->infofile, "down");
- /* we currently don't have a resolvconf style programs for ntp/nis */
- exec_script (options->script, iface->infofile, "down");
- }
return 0;
}
state="$2"
# Reading HostInfo file for configuration parameters
-. "${hostinfo}"
+[ -e "${hostinfo}" ] && . "${hostinfo}"
case "${state}" in
up)
return (false);
}
- fprintf (f, "IPADDR='%s'\n", inet_ntoa (dhcp->address));
- fprintf (f, "NETMASK='%s'\n", inet_ntoa (dhcp->netmask));
- fprintf (f, "BROADCAST='%s'\n", inet_ntoa (dhcp->broadcast));
+ if (dhcp->address.s_addr) {
+ fprintf (f, "IPADDR='%s'\n", inet_ntoa (dhcp->address));
+ fprintf (f, "NETMASK='%s'\n", inet_ntoa (dhcp->netmask));
+ fprintf (f, "BROADCAST='%s'\n", inet_ntoa (dhcp->broadcast));
+ }
if (dhcp->mtu > 0)
fprintf (f, "MTU='%d'\n", dhcp->mtu);
if (dhcp->rootpath)
fprintf (f, "ROOTPATH='%s'\n", cleanmetas (dhcp->rootpath));
- fprintf (f, "DHCPSID='%s'\n", inet_ntoa (dhcp->serveraddress));
- fprintf (f, "DHCPSNAME='%s'\n", cleanmetas (dhcp->servername));
- if (! options->doinform) {
+ if (dhcp->serveraddress.s_addr)
+ fprintf (f, "DHCPSID='%s'\n", inet_ntoa (dhcp->serveraddress));
+ if (dhcp->servername[0])
+ fprintf (f, "DHCPSNAME='%s'\n", cleanmetas (dhcp->servername));
+ if (! options->doinform && dhcp->address.s_addr) {
fprintf (f, "LEASEDFROM='%u'\n", dhcp->leasedfrom);
fprintf (f, "LEASETIME='%u'\n", dhcp->leasetime);
fprintf (f, "RENEWALTIME='%u'\n", dhcp->renewaltime);
}
#endif
- fprintf (f, "\n");
fclose (f);
return (true);
}
iface = xmalloc (sizeof (interface_t));
memset (iface, 0, sizeof (interface_t));
strlcpy (iface->name, ifname, IF_NAMESIZE);
+#ifdef ENABLE_INFO
snprintf (iface->infofile, PATH_MAX, INFOFILE, ifname);
+#endif
memcpy (&iface->hwaddr, hwaddr, hwlen);
iface->hwlen = hwlen;