dhcp: add nettools dhcp4 client

This is inspired by the existing systemd integration, with a few differences:

* This parses the WPAD option, which systemd requested, but did not use.
* We hook into the DAD handling, only making use of the configured address
  once DAD has completed successfully, and declining the lease if it fails.

There are still many areas of possible improvement. In particular, we need
to ensure the parsing of all options are compliant, as n-dhcp4 treats all
options as opaque, unlike sd-dhcp4. We probably also need to look at how
to handle failures and retries (in particular if we decline a lease).

We need to query the current MTU at client startu, as well as the hardware
broadcast address. Both these are provided by the kernel over netlink, so
it should simply be a matter of hooking that up with NM's netlink layer.

Contribution under LGPL2.0+, in addition to stated licenses.
This commit is contained in:
Tom Gundersen
2019-05-13 20:02:48 +02:00
committed by Beniamino Galvani
parent 401fee7c20
commit 6adade6f21
10 changed files with 1429 additions and 6 deletions

View File

@@ -266,6 +266,45 @@ endif
###############################################################################
noinst_LTLIBRARIES += shared/libndhcp4.la
shared_libndhcp4_la_CFLAGS = \
$(AM_CFLAGS) \
-std=c11 \
-Wno-error=declaration-after-statement \
-Wno-pointer-arith \
$(NULL)
shared_libndhcp4_la_CPPFLAGS = \
-D_GNU_SOURCE \
$(CODE_COVERAGE_CFLAGS) \
$(SANITIZER_LIB_CFLAGS) \
-I$(srcdir)/shared/c-stdaux/src \
-I$(srcdir)/shared/c-list/src \
-I$(srcdir)/shared/c-siphash/src \
$(NULL)
shared_libndhcp4_la_LDFLAGS = \
$(SANITIZER_LIB_LDFLAGS)
shared_libndhcp4_la_SOURCES = \
shared/n-dhcp4/src/n-dhcp4-c-connection.c \
shared/n-dhcp4/src/n-dhcp4-c-lease.c \
shared/n-dhcp4/src/n-dhcp4-c-probe.c \
shared/n-dhcp4/src/n-dhcp4-client.c \
shared/n-dhcp4/src/n-dhcp4-incoming.c \
shared/n-dhcp4/src/n-dhcp4-outgoing.c \
shared/n-dhcp4/src/n-dhcp4-private.h \
shared/n-dhcp4/src/n-dhcp4-socket.c \
shared/n-dhcp4/src/n-dhcp4.h \
shared/n-dhcp4/src/util/packet.c \
shared/n-dhcp4/src/util/packet.h \
shared/n-dhcp4/src/util/socket.c \
shared/n-dhcp4/src/util/socket.h \
$(NULL)
###############################################################################
noinst_LTLIBRARIES += shared/nm-std-aux/libnm-std-aux.la
shared_nm_std_aux_libnm_std_aux_la_CPPFLAGS = \
@@ -1866,7 +1905,9 @@ EXTRA_DIST += \
###############################################################################
src_libNetworkManagerBase_la_CPPFLAGS = $(src_cppflags)
src_libNetworkManagerBase_la_CPPFLAGS = \
$(libsystemd_cppflags) \
$(src_cppflags)
src_libNetworkManagerBase_la_SOURCES = \
\
@@ -1920,6 +1961,7 @@ src_libNetworkManagerBase_la_SOURCES = \
src/dhcp/nm-dhcp-client.c \
src/dhcp/nm-dhcp-client.h \
src/dhcp/nm-dhcp-client-logging.h \
src/dhcp/nm-dhcp-nettools.c \
src/dhcp/nm-dhcp-utils.c \
src/dhcp/nm-dhcp-utils.h \
src/dhcp/nm-dhcp-systemd.c \
@@ -2141,6 +2183,7 @@ src_libNetworkManager_la_LIBADD = \
src/libnm-systemd-core.la \
shared/systemd/libnm-systemd-shared.la \
shared/libnacd.la \
shared/libndhcp4.la \
shared/libcrbtree.la \
shared/libcsiphash.la \
$(GLIB_LIBS) \
@@ -2228,6 +2271,7 @@ src_nm_iface_helper_LDADD = \
shared/nm-std-aux/libnm-std-aux.la \
src/libnm-systemd-core.la \
shared/systemd/libnm-systemd-shared.la \
shared/libndhcp4.la \
shared/libcsiphash.la \
$(GLIB_LIBS) \
$(LIBUDEV_LIBS) \
@@ -2275,6 +2319,7 @@ src_initrd_nm_initrd_generator_LDADD = \
shared/systemd/libnm-systemd-shared.la \
shared/nm-glib-aux/libnm-glib-aux.la \
shared/nm-std-aux/libnm-std-aux.la \
shared/libndhcp4.la \
shared/libcsiphash.la \
$(GLIB_LIBS) \
$(NULL)

View File

@@ -181,7 +181,7 @@ next if $filename =~ /\/nm-[^\/]+-enum-types\.[ch]$/;
next if $filename =~ /\bsrc\/systemd\//
and not $filename =~ /\/sd-adapt\//
and not $filename =~ /\/nm-/;
next if $filename =~ /\/(n-acd|c-list|c-siphash)\//;
next if $filename =~ /\/(n-acd|c-list|c-siphash|n-dhcp4)\//;
complain ('Tabs are only allowed at the beginning of a line') if $line =~ /[^\t]\t/;
complain ('Trailing whitespace') if $line =~ /[ \t]$/;

View File

@@ -53,7 +53,7 @@ option('config_dns_rc_manager_default', type: 'combo', choices: ['symlink', 'fil
option('dhclient', type: 'string', value: '', description: 'Enable dhclient support')
option('dhcpcanon', type: 'string', value: '', description: 'Enable dhcpcanon support (experimental)')
option('dhcpcd', type: 'string', value: '', description: 'Enable dhcpcd support')
option('config_dhcp_default', type: 'combo', choices: ['dhcpcanon', 'dhclient', 'dhcpcd', 'internal'], value: 'internal', description: 'Default configuration option for main.dhcp setting, used as fallback if the configuration option is unset')
option('config_dhcp_default', type: 'combo', choices: ['dhcpcanon', 'dhclient', 'dhcpcd', 'internal', 'nettools'], value: 'internal', description: 'Default configuration option for main.dhcp setting, used as fallback if the configuration option is unset')
# miscellaneous
option('introspection', type: 'boolean', value: true, description: 'Enable introspection for this build')

View File

@@ -88,6 +88,43 @@ shared_n_acd_dep = declare_dependency(
###############################################################################
shared_n_dhcp4 = static_library(
'n-dhcp4',
sources: files('n-dhcp4/src/n-dhcp4-c-connection.c',
'n-dhcp4/src/n-dhcp4-c-lease.c',
'n-dhcp4/src/n-dhcp4-c-probe.c',
'n-dhcp4/src/n-dhcp4-client.c',
'n-dhcp4/src/n-dhcp4-incoming.c',
'n-dhcp4/src/n-dhcp4-outgoing.c',
'n-dhcp4/src/n-dhcp4-private.h',
'n-dhcp4/src/n-dhcp4-socket.c',
'n-dhcp4/src/n-dhcp4.h',
'n-dhcp4/src/util/packet.c',
'n-dhcp4/src/util/packet.h',
'n-dhcp4/src/util/socket.c',
'n-dhcp4/src/util/socket.h'),
c_args: [
'-D_GNU_SOURCE',
'-Wno-declaration-after-statement',
'-Wno-pointer-arith',
],
include_directories: [
include_directories('c-list/src'),
include_directories('c-siphash/src'),
include_directories('c-stdaux/src'),
],
dependencies: [
shared_c_siphash_dep,
],
)
shared_n_dhcp4_dep = declare_dependency(
include_directories: shared_inc,
link_with: shared_n_dhcp4,
)
###############################################################################
version_conf = configuration_data()
version_conf.set('NM_MAJOR_VERSION', nm_major_version)
version_conf.set('NM_MINOR_VERSION', nm_minor_version)

View File

@@ -213,5 +213,6 @@ extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_internal;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_nettools;
#endif /* __NETWORKMANAGER_DHCP_CLIENT_H__ */

View File

@@ -38,7 +38,7 @@
/*****************************************************************************/
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[4] = {
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5] = {
/* the order here matters, as we will try the plugins in this order to find
* the first available plugin. */
@@ -52,6 +52,7 @@ const NMDhcpClientFactory *const _nm_dhcp_manager_factories[4] = {
&_nm_dhcp_client_factory_dhcpcd,
#endif
&_nm_dhcp_client_factory_internal,
&_nm_dhcp_client_factory_nettools,
};
/*****************************************************************************/

View File

@@ -84,7 +84,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
/* For testing only */
extern const char* nm_dhcp_helper_path;
extern const NMDhcpClientFactory *const _nm_dhcp_manager_factories[4];
extern const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5];
void nmtst_dhcp_manager_unget (gpointer singleton_instance);

1336
src/dhcp/nm-dhcp-nettools.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -22,6 +22,7 @@ cflags = nm_cflags
sources = files(
'dhcp/nm-dhcp-client.c',
'dhcp/nm-dhcp-manager.c',
'dhcp/nm-dhcp-nettools.c',
'dhcp/nm-dhcp-systemd.c',
'dhcp/nm-dhcp-utils.c',
'ndisc/nm-lndp-ndisc.c',
@@ -50,6 +51,7 @@ deps = [
libsystemd_dep,
libudev_dep,
libnm_core_dep,
shared_n_dhcp4_dep,
]
if enable_wext

View File

@@ -589,8 +589,9 @@ main (int argc, char *argv[])
/*****************************************************************************/
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[4] = {
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5] = {
&_nm_dhcp_client_factory_internal,
&_nm_dhcp_client_factory_nettools,
};
/*****************************************************************************/