
Author: aurel32
Status: sent to dhcp-bugs@isc.org and dhcp-hackers@isc.org (20060206)

diff -Nur dhcp-3.0.4b2.old/Makefile.conf dhcp-3.0.4b2/Makefile.conf
--- dhcp-3.0.4b2.old/Makefile.conf	2005-06-16 21:39:35.000000000 +0200
+++ dhcp-3.0.4b2/Makefile.conf	2006-02-06 12:23:25.000000000 +0100
@@ -486,3 +486,22 @@
 #FFMANEXT = .5
 #MANINSTALL = install -i -m 444
 ##--hpux-gcc--
+
+## GNU/kFreeBSD
+##--kfreebsd--
+#CF = cf/kfreebsd.h
+#COPTS = $(BINDDEF) $(CC_OPTIONS)
+#ADMMANDIR = /usr/share/man/man8
+#ADMMANEXT = .8
+#FFMANDIR = /usr/share/man/man5
+#FFMANEXT = .5
+#LIBMANDIR = /usr/share/man/man3
+#LIBMANEXT = .3
+#USRMANDIR = /usr/share/man/man1
+#USRMANEXT = .1
+#MANCAT = man
+#VARRUN = /var/run
+#VARDB = /var/lib/dhcp
+#SCRIPT=kfreebsd
+##--kfreebsd--
+
diff -Nur dhcp-3.0.4b2.old/client/scripts/kfreebsd dhcp-3.0.4b2/client/scripts/kfreebsd
--- dhcp-3.0.4b2.old/client/scripts/kfreebsd	1970-01-01 01:00:00.000000000 +0100
+++ dhcp-3.0.4b2/client/scripts/kfreebsd	2006-02-06 12:23:25.000000000 +0100
@@ -0,0 +1,174 @@
+#!/bin/bash
+# dhclient-script for GNU/kFreeBSD. Aurelien Jarno, May, 2005.
+# Based on Linux and FreeBSD scripts.
+
+make_resolv_conf() {
+  if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
+    echo search $new_domain_name >/etc/resolv.conf
+    chmod 644 /etc/resolv.conf
+    for nameserver in $new_domain_name_servers; do
+      echo nameserver $nameserver >>/etc/resolv.conf
+    done
+  fi
+}
+
+# Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
+exit_with_hooks() {
+  exit_status=$1
+  if [ -f /etc/dhclient-exit-hooks ]; then
+    . /etc/dhclient-exit-hooks
+  fi
+# probably should do something with exit status of the local script
+  exit $exit_status
+}
+
+# Invoke the local dhcp client enter hooks, if they exist.
+if [ -f /etc/dhclient-enter-hooks ]; then
+  exit_status=0
+  . /etc/dhclient-enter-hooks
+  # allow the local script to abort processing of this state
+  # local script must set exit_status variable to nonzero.
+  if [ $exit_status -ne 0 ]; then
+    exit $exit_status
+  fi
+fi
+
+if [ x$new_broadcast_address != x ]; then
+  new_broadcast_arg="broadcast $new_broadcast_address"
+fi
+if [ x$old_broadcast_address != x ]; then
+  old_broadcast_arg="broadcast $old_broadcast_address"
+fi
+if [ x$new_subnet_mask != x ]; then
+  new_subnet_arg="netmask $new_subnet_mask"
+fi
+if [ x$old_subnet_mask != x ]; then
+  old_subnet_arg="netmask $old_subnet_mask"
+fi
+if [ x$alias_subnet_mask != x ]; then
+  alias_subnet_arg="netmask $alias_subnet_mask"
+fi
+
+if [ x$reason = xMEDIUM ]; then
+  eval "ifconfig $interface $medium"
+  eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
+  sleep 1
+  exit_with_hooks 0
+fi
+
+if [ x$reason = xPREINIT ]; then
+  if [ x$alias_ip_address != x ]; then
+    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
+    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+  fi
+  ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
+		broadcast 255.255.255.255 up
+  exit_with_hooks 0
+fi
+
+if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
+  exit_with_hooks 0
+fi
+  
+if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
+   [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
+  current_hostname=`hostname`
+  if [ x$current_hostname = x ] || \
+     [ x$current_hostname = x$old_host_name ]; then
+    if [ x$current_hostname = x ] || \
+       [ x$new_host_name != x$old_host_name ]; then
+      hostname $new_host_name
+    fi
+  fi
+
+  if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
+		[ x$alias_ip_address != x$old_ip_address ]; then
+    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
+    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+  fi
+  if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
+    eval "ifconfig $interface inet -alias $old_ip_address $medium"
+    route delete $old_ip_address 127.1 >/dev/null 2>&1
+    # IP address changed. Bringing down the interface will delete all other
+    # routes, and clear the ARP cache.
+    ifconfig $interface inet 0 down
+  fi
+  if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
+     [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
+    eval "ifconfig $interface inet $new_ip_address $new_subnet_arg \
+					$new_broadcast_arg $medium"
+    route add $new_ip_address 127.1 >/dev/null 2>&1
+    for router in $new_routers; do
+      route add default $router >/dev/null 2>&1
+    done
+    if [ -n "$new_static_routes" ]; then
+      set -- $new_static_routes
+      while [ $# -gt 1 ]; do
+	route add $1 $2
+	shift; shift
+      done
+    fi
+  fi
+  if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
+   then
+    ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
+    route add $alias_ip_address 127.0.0.1
+  fi
+  make_resolv_conf
+  exit_with_hooks 0
+fi
+
+if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
+   || [ x$reason = xSTOP ]; then
+  if [ x$alias_ip_address != x ]; then
+    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
+    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+  fi
+  if [ x$old_ip_address != x ]; then
+    eval "ifconfig $interface inet -alias $old_ip_address $medium"
+    route delete $old_ip_address 127.1 >/dev/null 2>&1
+    # Shut down interface, which will delete all other routes and clear arp cache.
+    ifconfig $interface inet 0 down
+  fi
+  if [ x$alias_ip_address != x ]; then
+    ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
+    route add $alias_ip_address 127.0.0.1
+  fi
+  exit_with_hooks 0
+fi
+
+if [ x$reason = xTIMEOUT ]; then
+  if [ x$alias_ip_address != x ]; then
+    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
+    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+  fi
+  eval "ifconfig $interface inet $new_ip_address $new_subnet_arg \
+					$new_broadcast_arg $medium"
+  sleep 1
+  if [ -n "$new_routers" ]; then
+    set -- $new_routers
+    if ping -q -c 1 $1; then
+      if [ x$new_ip_address != x$alias_ip_address ] && \
+			[ x$alias_ip_address != x ]; then
+	ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
+	route add $alias_ip_address 127.0.0.1
+      fi
+      route add $new_ip_address 127.1 >/dev/null 2>&1
+      for router in $new_routers; do
+	route add default $router >/dev/null 2>&1
+      done
+      set -- $new_static_routes
+      while [ $# -gt 1 ]; do
+	route add $1 $2
+	shift; shift
+      done
+      make_resolv_conf
+      exit_with_hooks 0
+    fi
+  fi
+  eval "ifconfig $interface inet -alias $new_ip_address $medium"
+  ifconfig $interface inet 0
+  exit_with_hooks 1
+fi
+
+exit_with_hooks 0
diff -Nur dhcp-3.0.4b2.old/common/bpf.c dhcp-3.0.4b2/common/bpf.c
--- dhcp-3.0.4b2.old/common/bpf.c	2004-11-24 18:39:15.000000000 +0100
+++ dhcp-3.0.4b2/common/bpf.c	2006-02-06 12:23:25.000000000 +0100
@@ -407,7 +407,7 @@
 				       interface -> rbuf,
 				       (size_t)interface -> rbuf_max);
 			if (length <= 0) {
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 				if (errno == ENXIO) {
 #else
 				if (errno == EIO) {
diff -Nur dhcp-3.0.4b2.old/configure dhcp-3.0.4b2/configure
--- dhcp-3.0.4b2.old/configure	2004-09-10 23:02:30.000000000 +0200
+++ dhcp-3.0.4b2/configure	2006-02-06 12:23:25.000000000 +0100
@@ -184,6 +184,8 @@
       sysname=nextstep;;
     UnixWare)
       sysname=uw7;;
+    GNU/kFreeBSD)
+      sysname=kfreebsd;
   esac
 fi
 
@@ -213,6 +215,7 @@
     echo "   qnx		QNX 4.2 or higher"
     echo "   NEXTSTEP     NeXTSTEP"
     echo "   sco	SCO Open Server"
+    echo "   kfreebsd		GNU/kFreeBSD"
     exit 1;
   fi
 fi
diff -Nur dhcp-3.0.4b2.old/includes/cf/kfreebsd.h dhcp-3.0.4b2/includes/cf/kfreebsd.h
--- dhcp-3.0.4b2.old/includes/cf/kfreebsd.h	1970-01-01 01:00:00.000000000 +0100
+++ dhcp-3.0.4b2/includes/cf/kfreebsd.h	2006-02-06 12:23:25.000000000 +0100
@@ -0,0 +1,148 @@
+/* kfreebsd.h
+
+   System dependencies for GNU/kFreeBSD... */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1996-2003 by Internet Software Consortium
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *   Internet Systems Consortium, Inc.
+ *   950 Charter Street
+ *   Redwood City, CA 94063
+ *   <info@isc.org>
+ *   http://www.isc.org/
+ *
+ * This software has been written for Internet Systems Consortium
+ * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
+ * To learn more about Internet Systems Consortium, see
+ * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
+ * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
+ * ``http://www.nominum.com''.
+ */
+
+#include <features.h>
+
+typedef u_int8_t u8;
+typedef u_int16_t u16;
+typedef u_int32_t u32;
+
+#include <syslog.h>
+#include <sys/types.h>
+#include <string.h>
+#include <paths.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <limits.h>
+
+extern int h_errno;
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_arp.h>
+#include <net/route.h>
+#if !defined (INADDR_LOOPBACK)
+# define INADDR_LOOPBACK ((u_int32_t)0x7f000001)
+#endif
+
+#include <sys/time.h>		/* gettimeofday()*/
+
+/* Databases go in /var/state/dhcp.   It would also be valid to put them
+   in /var/state/misc - indeed, given that there's only one lease file, it
+   would probably be better.   However, I have some ideas for optimizing
+   the lease database that may result in a _lot_ of smaller files being
+   created, so in that context it makes more sense to have a seperate
+   directory. */
+
+#ifndef _PATH_DHCPD_DB
+#define _PATH_DHCPD_DB		"/var/state/dhcp/dhcpd.leases"
+#endif
+
+#ifndef _PATH_DHCLIENT_DB
+#define _PATH_DHCLIENT_DB	"/var/state/dhcp/dhclient.leases"
+#endif
+
+/* Varargs stuff... */
+#include <stdarg.h>
+#define VA_DOTDOTDOT ...
+#define VA_start(list, last) va_start (list, last)
+#define va_dcl
+
+#if defined(__alpha__) || defined(__amd64__) || defined(__ia64__) || \
+	defined(__sparc64__)
+# define PTRSIZE_64BIT
+#endif
+
+#define VOIDPTR	void *
+
+#define EOL	'\n'
+
+/* Time stuff... */
+
+#include <time.h>
+
+#define TIME time_t
+#define GET_TIME(x)	time ((x))
+
+#define HAVE_SA_LEN
+
+#if defined (USE_DEFAULT_NETWORK)
+#  define USE_BPF
+#endif
+#define HAVE_MKSTEMP
+#ifdef NEED_PRAND_CONF
+#ifndef HAVE_DEV_RANDOM
+ # define HAVE_DEV_RANDOM 1
+ #endif /* HAVE_DEV_RANDOM */
+
+const char *cmds[] = {
+	"/bin/ps -axlw 2>&1",
+	"/sbin/arp -an 2>&1",
+	"/bin/netstat -an 2>&1",
+	"/bin/df  2>&1",
+	"/usr/bin/dig com. soa +ti=1 +retry=0 2>&1",
+	"/usr/bin/uptime  2>&1",
+	"/usr/bin/netstat -an 2>&1",
+	"/usr/bin/dig . soa +ti=1 +retry=0 2>&1",
+	"/usr/bin/vmstat  2>&1",
+	"/usr/bin/w  2>&1",
+	NULL
+};
+
+const char *dirs[] = {
+	"/tmp",
+	"/usr/tmp",
+	".",
+	"/",
+	"/var/spool",
+	"/dev",
+	"/var/spool/mail",
+	"/home",
+	"/usr/home",
+	NULL
+};
+
+const char *files[] = {
+	"/proc/stat",
+	"/proc/meminfo",
+	"/proc/self/status",
+	"/var/log/messages",
+	"/var/log/wtmp",
+	"/var/log/lastlog",
+	NULL
+};
+#endif /* NEED_PRAND_CONF */
diff -Nur dhcp-3.0.4b2.old/includes/osdep.h dhcp-3.0.4b2/includes/osdep.h
--- dhcp-3.0.4b2.old/includes/osdep.h	2005-09-28 20:58:27.000000000 +0200
+++ dhcp-3.0.4b2/includes/osdep.h	2006-02-06 12:23:25.000000000 +0100
@@ -133,6 +133,10 @@
 # endif
 #endif
 
+#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
+#  include "cf/kfreebsd.h"
+#endif
+
 /* snprintf/vsnprintf hacks.  for systems with no libc versions only. */
 #ifdef NO_SNPRINTF
   extern int isc_print_snprintf(char *, size_t, const char *, ...);
