dhcp: don't fail with dhclient v3

This commit is contained in:
Mathieu Trudel-Lapierre 2010-08-12 17:52:20 -05:00 committed by Dan Williams
parent 73e5b74c6c
commit d39fda7722
3 changed files with 34 additions and 6 deletions

View file

@ -319,21 +319,30 @@ AC_SUBST(PPPD_PLUGIN_DIR)
AC_ARG_WITH([dhclient], AS_HELP_STRING([--with-dhclient=yes|no|path], [Enable dhclient 4.x support]))
# If a full path is given, use that and do not test if it works or not.
case "${with_dhclient}" in
# NM only works with ISC dhclient - other derivatives don't have
# the same userland. dhclient 4.x is required for IPv6 support;
# with older versions NM won't be able to use DHCPv6.
/*)
DHCLIENT_PATH="${with_dhclient}"
DHCLIENT_VERSION=4
if test -x "${with_dhclient}"; then
case `"${with_dhclient}" --version 2>&1` in
"isc-dhclient-4"*) DHCLIENT_VERSION=4; break;;
"isc-dhclient-V3"*) DHCLIENT_VERSION=3; break;;
esac
fi
AC_MSG_NOTICE(using dhclient at ${DHCLIENT_PATH})
;;
no) AC_MSG_NOTICE(dhclient support disabled)
;;
*)
AC_MSG_CHECKING(for dhclient)
# NM only works with ISC dhclient - other derivatives don't have
# the same userland. NM also requires dhclient 4.x since older
# versions do not have IPv6 support.
for path in /sbin /usr/sbin /usr/pkg/sbin /usr/local/sbin; do
test -x "${path}/dhclient" || continue
case `"$path/dhclient" --version 2>&1` in
"isc-dhclient-4"*) DHCLIENT_PATH="$path/dhclient"; break;;
"isc-dhclient-4"*) DHCLIENT_PATH="$path/dhclient"; DHCLIENT_VERSION=4; break;;
"isc-dhclient-V3"*) DHCLIENT_PATH="$path/dhclient"; DHCLIENT_VERSION=3; break;;
esac
done
if test -n "${DHCLIENT_PATH}"; then
@ -554,6 +563,7 @@ echo
if test -n "${DHCLIENT_PATH}"; then
echo ISC dhclient support: ${DHCLIENT_PATH}
echo ISC dhclient version: ${DHCLIENT_VERSION}
else
echo ISC dhclient support: no
fi

View file

@ -29,6 +29,7 @@ libdhcp_manager_la_CPPFLAGS = \
-DLIBEXECDIR=\"$(libexecdir)\" \
-DLOCALSTATEDIR=\"$(localstatedir)\" \
-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
-DDHCLIENT_V$(DHCLIENT_VERSION) \
-DDHCPCD_PATH=\"$(DHCPCD_PATH)\"
libdhcp_manager_la_LIBADD = \

View file

@ -45,7 +45,11 @@ G_DEFINE_TYPE (NMDHCPDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
#define NM_DHCP_DHCLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCLIENT, NMDHCPDhclientPrivate))
#if defined(TARGET_DEBIAN) || defined(TARGET_SUSE) || defined(TARGET_MANDRIVA)
#if defined(DHCLIENT_V3)
#define NM_DHCLIENT_LEASE_DIR LOCALSTATEDIR "/lib/dhcp3"
#else
#define NM_DHCLIENT_LEASE_DIR LOCALSTATEDIR "/lib/dhcp"
#endif
#else
#define NM_DHCLIENT_LEASE_DIR LOCALSTATEDIR "/lib/dhclient"
#endif
@ -437,7 +441,11 @@ create_dhclient_config (const char *iface,
#if defined(TARGET_SUSE)
orig = g_strdup (SYSCONFDIR "/dhclient.conf");
#elif defined(TARGET_DEBIAN) || defined(TARGET_GENTOO)
#if defined(DHCLIENT_V3)
orig = g_strdup (SYSCONFDIR "/dhcp3/dhclient.conf");
#else
orig = g_strdup (SYSCONFDIR "/dhcp/dhclient.conf");
#endif
#else
orig = g_strdup_printf (SYSCONFDIR "/dhclient-%s.conf", iface);
#endif
@ -499,12 +507,20 @@ dhclient_start (NMDHCPClient *client,
guint log_domain;
g_return_val_if_fail (priv->pid_file == NULL, -1);
g_return_val_if_fail (ip_opt != NULL, -1);
iface = nm_dhcp_client_get_iface (client);
uuid = nm_dhcp_client_get_uuid (client);
ipv6 = nm_dhcp_client_get_ipv6 (client);
#if defined(DHCLIENT_V3)
if (ipv6) {
nm_log_warn (log_domain, "(%s): ISC dhcp3 does not support IPv6", iface);
return -1;
}
#else
g_return_val_if_fail (ip_opt != NULL, -1);
#endif
log_domain = ipv6 ? LOGD_DHCP6 : LOGD_DHCP4;
priv->pid_file = g_strdup_printf (LOCALSTATEDIR "/run/dhclient%s-%s.pid",
@ -536,10 +552,11 @@ dhclient_start (NMDHCPClient *client,
g_ptr_array_add (argv, (gpointer) "-d");
#if !defined(DHCLIENT_V3)
g_ptr_array_add (argv, (gpointer) ip_opt);
if (mode_opt)
g_ptr_array_add (argv, (gpointer) mode_opt);
#endif
g_ptr_array_add (argv, (gpointer) "-sf"); /* Set script file */
g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH );