+Use the DUID stored to create an RFC 4361 conformant client identifier
+if none is specified instead of just using the MAC address.
+Create a DUID-LLT according to RFC 3315 and store it in peristent file.
config.h now has the compile time options, instead of being dotted around.
Added -E option, which reads the last info file and uses the information there
if we timeout and the lease is still valid, thanks to Roberto Angelino.
TARGET = $(SBIN_TARGETS)
dhcpcd_H = version.h
-dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o \
+dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
info.o interface.o logger.o signals.o socket.o
# By default we don't need to link to anything
/*
* dhcpcd - DHCP client daemon -
- * Copyright 2005 - 2007 Roy Marples <uberlord@gentoo.org>
- *
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
+ *
* dhcpcd is an RFC2131 compliant DHCP client daemon.
*
* This is free software; you can redistribute it and/or modify it
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#ifndef PATHNAMES_H
-#define PATHNAMES_H
+#ifndef CONFIG_H
+#define CONFIG_H
+
+/* You can enable/disable various chunks of optional code here.
+ * You would only do this to try and shrink the end binary if dhcpcd
+ * was running on a low memory device */
+
+#define ENABLE_ARP
+#define ENABLE_NTP
+#define ENABLE_NIS
+#define ENABLE_INFO
+/* Define this to enable some compatability with 1.x and 2.x info files */
+// #define ENABLE_INFO_COMPAT
+
+/* We will auto create a DUID_LLT file if it doesn't exist.
+ * You can always create your own DUID file that just contains the
+ * hex string that represents the DUID.
+ * See RFC 3315 for details on this. */
+#define ENABLE_DUID
+
+/* Packname name and pathname definitions */
#define PACKAGE "dhcpcd"
#define CONFIGDIR STATEDIR "/lib/" PACKAGE
#define INFOFILE CONFIGDIR "/" PACKAGE "-%s.info"
+#define DUIDFILE CONFIGDIR "/" PACKAGE ".duid"
+
#endif
#endif
#include "interface.h"
#include "dhcpcd.h"
-#include "pathnames.h"
#include "logger.h"
#include "socket.h"
*p++ = 0; /* string */
memcpy (p, options, l);
p += l;
+#ifdef ENABLE_DUID
+ } else if (iface->duid) {
+ *p++ = iface->duid_length + 5;
+ *p++ = 255; /* RFC 4361 */
+
+ /* IAID is 4 bytes, so if the interface name is 4 bytes then use it */
+ if (strlen (iface->name) == 4) {
+ memcpy (p, iface->name, 4);
+ } else {
+ /* Name isn't 4 bytes, so use the index */
+ ul = htonl (if_nametoindex (iface->name));
+ memcpy (p, &ul, 4);
+ }
+ p += 4;
+
+ memcpy (p, iface->duid, iface->duid_length);
+ p += iface->duid_length;
+#endif
} else {
*p++ = iface->hwlen + 1;
*p++ = iface->family;
file.
.TP
.BI \-I \ clientID
-Specifies the client identifier string.
+Specifies the client identifier string. If not specified then
.B dhcpcd
-uses the default client identifier (MAC address of the network
-interface) if it is not specified.
+will attempt to create a client identifier according to \fBRFC 4361\fR
+and store the DUID part in /var/lib/dhcpcd/dhcpcd.duid, otherwise
+.B dhcpcd
+uses the MAC address of the network interface.
.TP
.BI \-M
Prevents
#include <string.h>
#include <unistd.h>
+#include "config.h"
#include "client.h"
#include "dhcpcd.h"
#include "dhcp.h"
#include "interface.h"
#include "logger.h"
-#include "pathnames.h"
#include "version.h"
-#define PACKAGE "dhcpcd"
-
#define STRINGINT(_string, _int) { \
char *_tmp; \
long _number = strtol (_string, &_tmp, 0); \
--- /dev/null
+/*
+ * dhcpcd - DHCP client daemon -
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
+ *
+ * dhcpcd is an RFC2131 compliant DHCP client daemon.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "common.h"
+#include "duid.h"
+#include "logger.h"
+
+#ifdef ENABLE_DUID
+#define DUID_LEN 130
+
+#define THIRTY_YEARS_IN_SECONDS 946707779
+
+void get_duid (interface_t *iface)
+{
+ FILE *fp;
+ uint16_t type = 0;
+ uint16_t hw = 0;
+ uint32_t ul;
+ time_t t;
+ unsigned char *p = iface->duid;
+ int x = 0;
+
+ if (! iface)
+ return;
+
+ /* Remove any existing */
+ iface->duid[0] = '\0';
+ iface->duid_length = 0;
+
+ /* If we already have a DUID then use it as it's never supposed
+ * to change once we have one even if the interfaces do */
+ if ((fp = fopen (DUIDFILE, "r"))) {
+ char *fduid;
+ char *fdp;
+ fduid = fdp = xmalloc ((sizeof (char *) * DUID_LEN * 2) + 1);
+ if (fscanf (fp, "%260s", fduid) == 1) {
+ char c[3];
+ c[2] = '\0';
+ while (*fdp) {
+ c[0] = *fdp++;
+ c[1] = *fdp++;
+ *p++ = (char) strtol (c, NULL, 16);
+ }
+ }
+ free (fduid);
+ iface->duid_length = p - iface->duid;
+ fclose (fp);
+ return;
+ }
+
+ if (errno != ENOENT) {
+ logger (LOG_ERR, "fopen `%s': %s", DUIDFILE, strerror (errno));
+ return;
+ }
+
+ /* No file? OK, lets make one based on our interface */
+ type = htons (1); /* DUI-D-LLT */
+ memcpy (p, &type, 2);
+ p += 2;
+
+ hw = htons (iface->family);
+ memcpy (p, &hw, 2);
+ p += 2;
+
+ /* time returns seconds from jan 1 1970, but DUID-LLT is
+ * seconds from jan 1 2000 modulo 2^32 */
+ t = time (NULL) - THIRTY_YEARS_IN_SECONDS;
+ ul = htonl (t & 0xffffffff);
+ memcpy (p, &ul, 4);
+ p += 4;
+
+ /* Finally, add the MAC address of the interface */
+ memcpy (p, iface->hwaddr, iface->hwlen);
+ p += iface->hwlen;
+
+ iface->duid_length = p - iface->duid;
+
+ if (! (fp = fopen (DUIDFILE, "w")))
+ logger (LOG_ERR, "fopen `%s': %s", DUIDFILE, strerror (errno));
+ else {
+ int i;
+ for (i = 0; i < iface->duid_length; i++)
+ x += fprintf (fp, "%.2X", iface->duid[i]);
+ fprintf (fp, "\n");
+ fclose (fp);
+ }
+
+ /* Failed to write the duid? scrub it, we cannot use it */
+ if (x < 1) {
+ memset (iface->duid, 0, sizeof (iface->duid));
+ iface->duid_length = 0;
+ }
+}
+#endif
--- /dev/null
+/*
+ * dhcpcd - DHCP client daemon -
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
+ *
+ * dhcpcd is an RFC2131 compliant DHCP client daemon.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef DUID_H
+#define DUID_H
+
+#include "config.h"
+
+#ifdef ENABLE_DUID
+#ifndef DUID_LENGTH_MAX
+#define DUID_LENGTH_MAX 128 + 2
+#endif
+
+#include "interface.h"
+
+void get_duid (interface_t *iface);
+#endif
+#endif
#include <string.h>
#include <unistd.h>
+#include "config.h"
#include "common.h"
#include "dhcp.h"
#include "interface.h"
#include "logger.h"
-#include "pathnames.h"
+
+#ifdef ENABLE_DUID
+#include "duid.h"
+#endif
void free_address (address_t *addresses)
{
logger (LOG_INFO, "hardware address = %s",
hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+#ifdef ENABLE_DUID
+ get_duid (iface);
+ if (iface->duid_length > 0)
+ logger (LOG_INFO, "DUID = %s",
+ hwaddr_ntoa (iface->duid, iface->duid_length));
+#endif
+
/* 0 is a valid fd, so init to -1 */
iface->fd = -1;
#include <limits.h>
#include <stdbool.h>
+#include "config.h"
+#ifdef ENABLE_DUID
+#ifndef DUID_LENGTH_MAX
+#define DUID_LENGTH_MAX 128 + 2
+#endif
+#endif
+
#define EUI64_ADDR_LEN 8
#define INFINIBAND_ADDR_LEN 20
route_t *previous_routes;
long start_uptime;
+
+#ifdef ENABLE_DUID
+ unsigned char duid[DUID_LENGTH_MAX];
+ int duid_length;
+#endif
} interface_t;
void free_address (address_t *addresses);