Hello,

Sometimes I had problems with udhcpc. I decided to use dhclient then but the 
dhcp package contains only server and relay.

Now, here is the work:
The first patch (isc_dhcp_client_support.patch) adds the dhcp-client package 
and the second one (add_basefiles-network-isc_dhcp_client_support.patch) adds 
support in base-files-network for the isc dhclient (will be used instead of 
udhcpc if dhclient is available).


The patches are against trunk (r29910).


With best regards

Christoph
-- 
Linux User Group Wernigerode
http://www.lug-wr.de/
diff -burN package.orig/base-files-network/files/lib/network/config.sh package/base-files-network/files/lib/network/config.sh
--- package.orig/base-files-network/files/lib/network/config.sh	2012-01-26 12:17:17.145214294 +0100
+++ package/base-files-network/files/lib/network/config.sh	2012-01-26 14:53:31.357124893 +0100
@@ -366,11 +366,11 @@
 			setup_interface_static "$iface" "$config"
 		;;
 		dhcp)
-			# kill running udhcpc instance
+			# kill running udhcpc/dhclient instance
 			local pidfile="/var/run/dhcp-${iface}.pid"
 
-			SERVICE_PID_FILE="$pidfile" \
-			service_stop /sbin/udhcpc
+			SERVICE_PID_FILE="$pidfile"
+			[ -x /sbin/dhclient ] && service_stop /sbin/dhclient || service_stop /sbin/udhcpc
 
 			local ipaddr netmask hostname proto1 clientid vendorid broadcast reqopts
 			config_get ipaddr "$config" ipaddr
@@ -400,6 +400,11 @@
 			}
 			[ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast=
 
+			[ -x /sbin/dhclient ] && {
+				SERVICE_DAEMONIZE=$daemonize \
+				SERVICE_PID_FILE="$pidfile" \
+				service_start /sbin/dhclient -q -lf /tmp/dhcp.leases -pf "$pidfile" -nw   "$iface"
+			}  ||  {
 			SERVICE_DAEMONIZE=$daemonize \
 			SERVICE_PID_FILE="$pidfile" \
 			service_start /sbin/udhcpc -t 0 -i "$iface" \
@@ -409,6 +414,7 @@
 				${vendorid:+-V $vendorid} \
 				-b -p "$pidfile" $broadcast \
 				${dhcpopts}
+			}
 		;;
 		none)
 			setup_interface_none "$iface" "$config"
@@ -436,7 +442,7 @@
 	remove_dns "$config"
 
 	SERVICE_PID_FILE="/var/run/dhcp-${ifname}.pid" \
-	service_stop /sbin/udhcpc
+	[ -x /sbin/dhclient ] && sbin/dhclient -q -x -lf /tmp/dhcp.leases -pf $SERVICE_PID_FILE ${ifname} ; service_stop /sbin/dhclient || service_stop /sbin/udhcpc
 
 	uci -P /var/state revert "network.$config"
 }
diff -burN package.orig/dhcp/files/dhclient-script package/dhcp/files/dhclient-script
--- package.orig/dhcp/files/dhclient-script	1970-01-01 01:00:00.000000000 +0100
+++ package/dhcp/files/dhclient-script	2012-01-26 14:46:50.913128712 +0100
@@ -0,0 +1,160 @@
+#!/bin/sh
+
+. /etc/functions.sh
+include /lib/network
+RESOLV_CONF="/tmp/resolv.conf.auto"
+
+change_state () {
+	[ -n "$ifc" ] || return
+	uci_revert_state "$1" "$2" "$3" "$4"
+	uci_set_state "$1" "$2" "$3" "$4"
+}
+
+set_classless_routes() {
+	local max=128
+	local type
+	while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+		[ ${1##*/} -eq 32 ] && type=host || type=net
+		echo "dhclient: adding route for $type $1 via $2"
+		route add -$type "$1" gw "$2" dev "$interface"
+		max=$(($max-1))
+		shift 2
+	done
+}
+
+setup_interface () {
+	local old_ip
+	local old_broadcast
+	local old_subnet
+	local old_router
+	local old_dns
+	local user_dns
+	local user_router
+	local user_metric
+
+	[ -n "$ifc" ] && {
+		old_ip="$(uci_get_state network "$ifc" ipaddr)"
+		old_broadcast="$(uci_get_state network "$ifc" broadcast)"
+		old_subnet="$(uci_get_state network "$ifc" netmask)"
+	}
+
+	[ "$new_ip_address" != "$old_ip" ] \
+	|| [ "${new_broadcast_address:-+}" != "$old_broadcast" ] \
+	|| [ "${new_subnet_mask:-255.255.255.0}" != "$old_subnet" ] && {
+		echo "dhclient: ifconfig $interface $new_ip_address netmask ${new_subnet_mask:-255.255.255.0} broadcast ${new_broadcast_address:-+}"
+		ifconfig $interface $new_ip_address netmask ${new_subnet_mask:-255.255.255.0} broadcast ${new_broadcast_address:-+}
+
+		change_state network "$ifc" ipaddr "$new_ip_address"
+		change_state network "$ifc" broadcast "${new_broadcast_address:-+}"
+		change_state network "$ifc" netmask "${new_subnet_mask:-255.255.255.0}"
+	}
+
+
+	# Default Route
+	[ -n "$ifc" ] && {
+		change_state network "$ifc" lease_gateway "$new_routers"
+		old_router="$(uci_get_state network "$ifc" gateway)"
+		user_router="$(uci_get network "$ifc" gateway)"
+		user_metric="$(uci_get network "$ifc" metric)"
+		[ -n "$user_router" ] && router="$user_router"
+	}
+
+	[ -n "$new_routers" ] && [ "$new_routers" != "0.0.0.0" ] && [ "$new_routers" != "255.255.255.255" ] && [ "$new_routers" != "$old_router" ] && {
+		echo "dhclient: setting default routers: $new_routers"
+
+		local valid_gw=""
+		for i in $new_routers ; do
+			route add default gw $i ${user_metric:+metric $user_metric} dev $interface
+			valid_gw="${valid_gw:+$valid_gw|}$i"
+		done
+		
+		eval $(route -n | awk '
+			/^0.0.0.0\W{9}('$valid_gw')\W/ {next}
+			/^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
+		')
+
+		change_state network "$ifc" gateway "$new_routers"
+	}
+
+	# CIDR STATIC ROUTES (rfc3442)
+	[ -n "$staticroutes" ] && set_classless_routes $staticroutes
+	[ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
+
+	# DNS
+	old_dns=$(uci_get_state network "$ifc" dns)
+	old_domain=$(uci_get_state network "$ifc" dnsdomain)
+	user_dns=$(uci_get "network.$ifc.dns")
+	[ -n "$user_dns" ] && dns="$user_dns"
+
+	[ -n "$new_domain_name_servers" ] && [ "$new_domain_name_servers" != "$old_dns" -o -n "$user_dns" ] && {
+		echo "dhclient: setting dns servers: $new_domain_name_servers"
+		add_dns "$ifc" $new_domain_name_servers
+
+		[ -n "$new_domain_name" ] && [ "$new_domain_name" != "$old_domain" ] && {
+			echo "dhclient: setting dns domain: $new_domain_name"
+			sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $new_domain_name$/d" "${RESOLV_CONF}"
+			echo "search $new_domain_name" >> "${RESOLV_CONF}"
+			change_state network "$ifc" dnsdomain "$new_domain_name"
+		}
+	}
+
+	[ -n "$ifc" ] || return
+
+	# UCI State
+	change_state network "$ifc" lease_server "$new_dhcp_server_identifier"
+	change_state network "$ifc" lease_acquired "$(sed -ne 's![^0-9].*$!!p' /proc/uptime)"
+	change_state network "$ifc" lease_lifetime "$new_dhcp_lease_time"
+	[ -n "$new_ntp_servers" ] && 	change_state network "$ifc" lease_ntpsrv "$new_ntp_servers"
+	[ -n "$timesvr" ] && 	change_state network "$ifc" lease_timesrv "$timesvr"
+	[ -n "$hostname" ] &&	change_state network "$ifc" lease_hostname "$hostname"
+	[ -n "$timezone" ] && 	change_state network "$ifc" lease_timezone "$timezone"
+
+
+	# Hotplug
+	env -i ACTION="ifup" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
+}
+
+
+scan_interfaces
+applied=
+for ifc in $interfaces __default; do
+	if [ "$ifc" = __default ]; then
+		ifc=""
+		[ -n "$applied" ] && continue
+	else
+		config_get ifname "$ifc" ifname
+		[ "$ifname" = "$interface" ] || continue
+
+		config_get proto "$ifc" proto
+		[ "$proto" = "dhcp" ] || continue
+		applied=true
+	fi
+
+	case "$reason" in
+		STOP)
+			ifconfig "$interface" 0.0.0.0
+			[ -n "$ifc" ] && {
+				env -i ACTION="ifdown" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
+			
+				config_get device "$ifc" device
+				config_get ifname "$ifc" ifname
+				config_get aliases "$ifc" aliases
+				uci_revert_state network "$ifc"
+				[ -n "$device" ] && uci_set_state network "$ifc" device "$device"
+				[ -n "$ifname" ] && uci_set_state network "$ifc" ifname "$ifname"
+				[ -n "$aliases" ] && uci_set_state network "$ifc" aliases "$aliases"
+			}
+		;;
+		REBOOT)
+			setup_interface update
+		;;
+		BOUND)
+			setup_interface ifup
+		;;
+	esac
+done
+
+# user rules
+[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+
+exit 0
diff -burN package.orig/dhcp/Makefile package/dhcp/Makefile
--- package.orig/dhcp/Makefile	2012-01-26 14:59:27.573121497 +0100
+++ package/dhcp/Makefile	2012-01-26 14:16:15.565146217 +0100
@@ -35,6 +35,10 @@
   TITLE+= server
 endef
 
+define Package/dhcp-client
+  $(call Package/dhcp/Default)
+  TITLE+= client
+endef
 
 define Build/Configure
 	# it's not GNU autoconf stuff
@@ -74,5 +78,13 @@
 	$(INSTALL_BIN) ./files/dhcpd.init $(1)/etc/init.d/dhcpd
 endef
 
+define Package/dhcp-client/install
+	$(INSTALL_DIR) $(1)/sbin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/sbin/dhclient $(1)/sbin/
+	$(INSTALL_BIN) ./files/dhclient-script $(1)/sbin/
+	$(STRIP) $(1)/sbin/dhclient
+endef
+
 $(eval $(call BuildPackage,dhcp-relay))
 $(eval $(call BuildPackage,dhcp-server))
+$(eval $(call BuildPackage,dhcp-client))

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to