dhcp: merge branch 'bg/nettools'

Introduce the nettools DHCPv4 backend.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/171
This commit is contained in:
Beniamino Galvani 2019-07-05 11:17:16 +02:00
commit f3b831aba1
27 changed files with 1656 additions and 55 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 = \
@ -1620,6 +1659,7 @@ libsystemd_cppflags = \
-I$(srcdir)/shared/systemd/ \
-I$(srcdir)/shared/systemd/sd-adapt-shared \
-I$(srcdir)/shared/systemd/src/basic \
-I$(srcdir)/shared/systemd/src/shared \
$(LIBSYSTEMD_NM_CFLAGS) \
$(GLIB_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \
@ -1763,6 +1803,8 @@ shared_systemd_libnm_systemd_shared_la_SOURCES = \
shared/systemd/src/basic/utf8.h \
shared/systemd/src/basic/util.c \
shared/systemd/src/basic/util.h \
shared/systemd/src/shared/dns-domain.c \
shared/systemd/src/shared/dns-domain.h \
$(NULL)
shared_systemd_libnm_systemd_shared_la_LIBADD = \
@ -1779,7 +1821,6 @@ src_libnm_systemd_core_la_cppflags = \
-I$(srcdir)/src \
-I$(srcdir)/src/systemd/sd-adapt-core \
-I$(srcdir)/src/systemd/src/systemd \
-I$(srcdir)/src/systemd/src/shared \
-I$(srcdir)/src/systemd/src/libsystemd-network \
-I$(srcdir)/src/systemd/src/libsystemd/sd-event \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_SYSTEMD \
@ -1840,8 +1881,6 @@ src_libnm_systemd_core_la_SOURCES = \
src/systemd/src/libsystemd/sd-id128/id128-util.c \
src/systemd/src/libsystemd/sd-id128/id128-util.h \
src/systemd/src/libsystemd/sd-id128/sd-id128.c \
src/systemd/src/shared/dns-domain.c \
src/systemd/src/shared/dns-domain.h \
src/systemd/src/systemd/_sd-common.h \
src/systemd/src/systemd/sd-dhcp-client.h \
src/systemd/src/systemd/sd-dhcp-lease.h \
@ -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)
@ -238,11 +275,13 @@ libnm_systemd_shared = static_library(
'systemd/src/basic/tmpfile-util.c',
'systemd/src/basic/utf8.c',
'systemd/src/basic/util.c',
'systemd/src/shared/dns-domain.c',
'systemd/nm-sd-utils-shared.c',
),
include_directories: include_directories(
'systemd/sd-adapt-shared',
'systemd/src/basic',
'systemd/src/shared',
),
dependencies: shared_nm_glib_aux_dep,
c_args: [
@ -255,6 +294,7 @@ libnm_systemd_shared_dep = declare_dependency(
include_directories: include_directories(
'systemd/sd-adapt-shared',
'systemd/src/basic',
'systemd/src/shared',
),
dependencies: [
shared_nm_glib_aux_dep,

View file

@ -8,6 +8,8 @@
#include <c-stdaux.h>
#include <errno.h>
#include <limits.h>
#include <sys/socket.h> /* needed by linux/netdevice.h */
#include <linux/netdevice.h>
#include <net/if_arp.h>
#include <stdbool.h>
#include <stdlib.h>
@ -82,6 +84,7 @@ int n_dhcp4_c_connection_init(NDhcp4CConnection *connection,
*/
void n_dhcp4_c_connection_deinit(NDhcp4CConnection *connection) {
n_dhcp4_c_connection_close(connection);
n_dhcp4_outgoing_free(connection->request);
*connection = (NDhcp4CConnection)N_DHCP4_C_CONNECTION_NULL(*connection);
}

View file

@ -483,6 +483,7 @@ _c_public_ NDhcp4ClientProbe *n_dhcp4_client_probe_free(NDhcp4ClientProbe *probe
if (probe == probe->client->current_probe)
probe->client->current_probe = NULL;
n_dhcp4_client_lease_unref(probe->current_lease);
n_dhcp4_c_connection_deinit(&probe->connection);
n_dhcp4_client_unref(probe->client);
n_dhcp4_client_probe_config_free(probe->config);

View file

@ -183,7 +183,11 @@ _c_public_ void n_dhcp4_client_config_set_request_broadcast(NDhcp4ClientConfig *
*/
_c_public_ void n_dhcp4_client_config_set_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) {
config->n_mac = n_mac;
memcpy(config->mac, mac, c_min(n_mac, sizeof(config->mac)));
if (n_mac > sizeof(config->mac))
n_mac = sizeof(config->mac);
memcpy(config->mac, mac, n_mac);
}
/**
@ -209,7 +213,11 @@ _c_public_ void n_dhcp4_client_config_set_mac(NDhcp4ClientConfig *config, const
*/
_c_public_ void n_dhcp4_client_config_set_broadcast_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) {
config->n_broadcast_mac = n_mac;
memcpy(config->broadcast_mac, mac, c_min(n_mac, sizeof(config->broadcast_mac)));
if (n_mac > sizeof(config->mac))
n_mac = sizeof(config->mac);
memcpy(config->broadcast_mac, mac, n_mac);
}
/**

View file

@ -220,8 +220,9 @@ int n_dhcp4_outgoing_append(NDhcp4Outgoing *outgoing,
/* try fitting into allowed OPTIONs space */
if (outgoing->max_size - outgoing->i_message >= n_data + 2U + 3U + 1U) {
/* try over-allocation to reduce allocation pressure */
n = c_min(outgoing->max_size,
outgoing->n_message + n_data + 128);
n = outgoing->n_message + n_data + 128;
if (n > outgoing->max_size)
n = outgoing->max_size;
m = realloc(outgoing->message, n);
if (!m)
return -ENOMEM;

View file

@ -7,7 +7,6 @@
#include <endian.h>
#include <inttypes.h>
#include <limits.h>
#include <linux/netdevice.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
@ -234,9 +233,9 @@ struct NDhcp4ClientConfig {
int ifindex;
unsigned int transport;
bool request_broadcast;
uint8_t mac[MAX_ADDR_LEN];
uint8_t mac[32]; /* MAX_ADDR_LEN */
size_t n_mac;
uint8_t broadcast_mac[MAX_ADDR_LEN];
uint8_t broadcast_mac[32]; /* MAX_ADDR_LEN */
size_t n_broadcast_mac;
uint8_t *client_id;
size_t n_client_id;

View file

@ -5,16 +5,17 @@
#include <c-stdaux.h>
#include <errno.h>
#include <linux/filter.h>
#include <sys/socket.h> /* needed by linux/if.h */
#include <linux/if.h>
#include <linux/if_packet.h>
#include <linux/netdevice.h>
#include <linux/udp.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "n-dhcp4-private.h"
#include "util/packet.h"
#include "util/socket.h"

View file

@ -7,7 +7,6 @@
#include <c-stdaux.h>
#include <inttypes.h>
#include <linux/if_packet.h>
#include <linux/netdevice.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <unistd.h>
@ -25,7 +24,7 @@ struct packet_sockaddr_ll {
unsigned short sll_hatype;
unsigned char sll_pkttype;
unsigned char sll_halen;
unsigned char sll_addr[MAX_ADDR_LEN];
unsigned char sll_addr[32]; /* MAX_ADDR_LEN */
};
uint16_t packet_internet_checksum(const uint8_t *data, size_t len);

View file

@ -24,6 +24,7 @@
#include "path-util.h"
#include "hexdecoct.h"
#include "dns-domain.h"
/*****************************************************************************/
@ -83,3 +84,11 @@ nm_sd_utils_unbase64mem (const char *p,
{
return unbase64mem_full (p, l, secure, (void **) mem, len);
}
int nm_sd_dns_name_to_wire_format (const char *domain,
guint8 *buffer,
size_t len,
gboolean canonical)
{
return dns_name_to_wire_format (domain, buffer, len, canonical);
}

View file

@ -39,4 +39,9 @@ int nm_sd_utils_unbase64mem (const char *p,
/*****************************************************************************/
int nm_sd_dns_name_to_wire_format (const char *domain,
guint8 *buffer,
size_t len,
gboolean canonical);
#endif /* __NM_SD_UTILS_SHARED_H__ */

View file

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "nm-sd-adapt-core.h"
#include "nm-sd-adapt-shared.h"
#if 0 /* NM_IGNORED */
#if HAVE_LIBIDN2

View file

@ -7694,9 +7694,13 @@ clear_config:
static void
dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success)
{
if (success)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (success) {
nm_dhcp_client_accept (priv->dhcp4.client, NULL);
nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (configs[1]));
else {
} else {
nm_dhcp_client_decline (priv->dhcp4.client, "Address conflict detected", NULL);
nm_device_ip_method_failed (self, AF_INET,
NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE);
}
@ -7962,9 +7966,11 @@ dhcp4_start (NMDevice *self)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMSettingIPConfig *s_ip4;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *client_id = NULL;
NMConnection *connection;
GError *error = NULL;
const NMPlatformLink *pllink;
connection = nm_device_get_applied_connection (self);
g_return_val_if_fail (connection, FALSE);
@ -7975,8 +7981,11 @@ dhcp4_start (NMDevice *self)
nm_dbus_object_clear_and_unexport (&priv->dhcp4.config);
priv->dhcp4.config = nm_dhcp4_config_new ();
hwaddr = nm_platform_link_get_address_as_bytes (nm_device_get_platform (self),
nm_device_get_ip_ifindex (self));
pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self));
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
client_id = dhcp4_get_client_id (self, connection, hwaddr);
@ -7986,6 +7995,7 @@ dhcp4_start (NMDevice *self)
nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self),
hwaddr,
bcast_hwaddr,
nm_connection_get_uuid (connection),
nm_device_get_route_table (self, AF_INET),
nm_device_get_route_metric (self, AF_INET),
@ -8763,8 +8773,10 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMSettingIPConfig *s_ip6;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *duid = NULL;
gboolean enforce_duid = FALSE;
const NMPlatformLink *pllink;
GError *error = NULL;
const NMPlatformIP6Address *ll_addr = NULL;
@ -8784,8 +8796,11 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
return FALSE;
}
hwaddr = nm_platform_link_get_address_as_bytes (nm_device_get_platform (self),
nm_device_get_ip_ifindex (self));
pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self));
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
duid = dhcp6_get_duid (self, connection, hwaddr, &enforce_duid);
priv->dhcp6.client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (),
@ -8793,6 +8808,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self),
hwaddr,
bcast_hwaddr,
&ll_addr->address,
nm_connection_get_uuid (connection),
nm_device_get_route_table (self, AF_INET6),

View file

@ -51,6 +51,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpClient,
PROP_ADDR_FAMILY,
PROP_FLAGS,
PROP_HWADDR,
PROP_BROADCAST_HWADDR,
PROP_IFACE,
PROP_IFINDEX,
PROP_MULTI_IDX,
@ -65,6 +66,7 @@ typedef struct _NMDhcpClientPrivate {
NMDedupMultiIndex *multi_idx;
char * iface;
GBytes * hwaddr;
GBytes * bcast_hwaddr;
char * uuid;
GBytes * client_id;
char * hostname;
@ -143,6 +145,14 @@ nm_dhcp_client_get_hw_addr (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->hwaddr;
}
GBytes *
nm_dhcp_client_get_broadcast_hw_addr (NMDhcpClient *self)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
return NM_DHCP_CLIENT_GET_PRIVATE (self)->bcast_hwaddr;
}
guint32
nm_dhcp_client_get_route_table (NMDhcpClient *self)
{
@ -530,6 +540,36 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
error);
}
gboolean
nm_dhcp_client_accept (NMDhcpClient *self,
GError **error)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
if (NM_DHCP_CLIENT_GET_CLASS (self)->accept) {
return NM_DHCP_CLIENT_GET_CLASS (self)->accept (self,
error);
}
return TRUE;
}
gboolean
nm_dhcp_client_decline (NMDhcpClient *self,
const char *error_message,
GError **error)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
if (NM_DHCP_CLIENT_GET_CLASS (self)->decline) {
return NM_DHCP_CLIENT_GET_CLASS (self)->decline (self,
error_message,
error);
}
return TRUE;
}
static GBytes *
get_duid (NMDhcpClient *self)
{
@ -839,6 +879,9 @@ get_property (GObject *object, guint prop_id,
case PROP_HWADDR:
g_value_set_boxed (value, priv->hwaddr);
break;
case PROP_BROADCAST_HWADDR:
g_value_set_boxed (value, priv->bcast_hwaddr);
break;
case PROP_ADDR_FAMILY:
g_value_set_int (value, priv->addr_family);
break;
@ -900,6 +943,10 @@ set_property (GObject *object, guint prop_id,
/* construct-only */
priv->hwaddr = g_value_dup_boxed (value);
break;
case PROP_BROADCAST_HWADDR:
/* construct-only */
priv->bcast_hwaddr = g_value_dup_boxed (value);
break;
case PROP_ADDR_FAMILY:
/* construct-only */
priv->addr_family = g_value_get_int (value);
@ -966,6 +1013,7 @@ dispose (GObject *object)
g_clear_pointer (&priv->uuid, g_free);
g_clear_pointer (&priv->client_id, g_bytes_unref);
g_clear_pointer (&priv->hwaddr, g_bytes_unref);
g_clear_pointer (&priv->bcast_hwaddr, g_bytes_unref);
G_OBJECT_CLASS (nm_dhcp_client_parent_class)->dispose (object);
@ -1010,6 +1058,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_BROADCAST_HWADDR] =
g_param_spec_boxed (NM_DHCP_CLIENT_BROADCAST_HWADDR, "", "",
G_TYPE_BYTES,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDR_FAMILY] =
g_param_spec_int (NM_DHCP_CLIENT_ADDR_FAMILY, "", "",
0, G_MAXINT, AF_UNSPEC,

View file

@ -34,17 +34,18 @@
#define NM_IS_DHCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CLIENT))
#define NM_DHCP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass))
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
#define NM_DHCP_CLIENT_FLAGS "flags"
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
#define NM_DHCP_CLIENT_INTERFACE "iface"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_HOSTNAME "hostname"
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
#define NM_DHCP_CLIENT_FLAGS "flags"
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
#define NM_DHCP_CLIENT_BROADCAST_HWADDR "broadcast-hwaddr"
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
#define NM_DHCP_CLIENT_INTERFACE "iface"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_HOSTNAME "hostname"
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
@ -82,6 +83,13 @@ typedef struct {
const char *last_ip4_address,
GError **error);
gboolean (*accept) (NMDhcpClient *self,
GError **error);
gboolean (*decline) (NMDhcpClient *self,
const char *error_message,
GError **error);
gboolean (*ip6_start) (NMDhcpClient *self,
const char *anycast_addr,
const struct in6_addr *ll_addr,
@ -122,6 +130,8 @@ GBytes *nm_dhcp_client_get_duid (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_broadcast_hw_addr (NMDhcpClient *self);
guint32 nm_dhcp_client_get_route_table (NMDhcpClient *self);
void nm_dhcp_client_set_route_table (NMDhcpClient *self, guint32 route_table);
@ -155,6 +165,13 @@ gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
guint needed_prefixes,
GError **error);
gboolean nm_dhcp_client_accept (NMDhcpClient *self,
GError **error);
gboolean nm_dhcp_client_decline (NMDhcpClient *self,
const char *error_message,
GError **error);
void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release);
/* Backend helpers for subclasses */
@ -199,5 +216,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

@ -204,6 +204,7 @@ client_start (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
@ -233,10 +234,11 @@ client_start (NMDhcpManager *self,
g_return_val_if_fail (!dhcp_client_id || g_bytes_get_size (dhcp_client_id) >= 2, NULL);
g_return_val_if_fail (!error || !*error, NULL);
if (!hwaddr) {
if (!hwaddr || !bcast_hwaddr) {
nm_utils_error_set (error,
NM_UTILS_ERROR_UNKNOWN,
"missing MAC address");
"missing %s address",
hwaddr ? "broadcast" : "MAC");
return NULL;
}
@ -249,6 +251,8 @@ client_start (NMDhcpManager *self,
g_return_val_if_reached (NULL) ;
}
nm_assert (g_bytes_get_size (hwaddr) == g_bytes_get_size (bcast_hwaddr));
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
client_factory = _client_factory_get_effective (priv->client_factory, addr_family);
@ -273,6 +277,7 @@ client_start (NMDhcpManager *self,
NM_DHCP_CLIENT_INTERFACE, iface,
NM_DHCP_CLIENT_IFINDEX, ifindex,
NM_DHCP_CLIENT_HWADDR, hwaddr,
NM_DHCP_CLIENT_BROADCAST_HWADDR, bcast_hwaddr,
NM_DHCP_CLIENT_UUID, uuid,
NM_DHCP_CLIENT_HOSTNAME, hostname,
NM_DHCP_CLIENT_ROUTE_TABLE, (guint) route_table,
@ -345,6 +350,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
@ -395,6 +401,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
iface,
ifindex,
hwaddr,
bcast_hwaddr,
uuid,
route_table,
route_metric,
@ -419,6 +426,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const struct in6_addr *ll_addr,
const char *uuid,
guint32 route_table,
@ -450,6 +458,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
iface,
ifindex,
hwaddr,
bcast_hwaddr,
uuid,
route_table,
route_metric,

View file

@ -49,6 +49,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
@ -66,6 +67,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const struct in6_addr *ll_addr,
const char *uuid,
guint32 route_table,
@ -84,7 +86,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);

1380
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

@ -381,8 +381,10 @@ main (int argc, char *argv[])
gs_unref_object NMDhcpClient *dhcp4_client = NULL;
gs_unref_object NMNDisc *ndisc = NULL;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *client_id = NULL;
gs_free NMUtilsIPv6IfaceId *iid = NULL;
const NMPlatformLink *pllink;
guint sd_id;
int errsv;
@ -469,7 +471,11 @@ main (int argc, char *argv[])
/* Set up platform interaction layer */
nm_linux_platform_setup ();
hwaddr = nm_platform_link_get_address_as_bytes (NM_PLATFORM_GET, gl.ifindex);
pllink = nm_platform_link_get (NM_PLATFORM_GET, gl.ifindex);
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
if (global_opt.iid_str) {
GBytes *bytes;
@ -505,6 +511,7 @@ main (int argc, char *argv[])
global_opt.ifname,
gl.ifindex,
hwaddr,
bcast_hwaddr,
global_opt.uuid,
RT_TABLE_MAIN,
global_opt.priority_v4,
@ -589,8 +596,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,
};
/*****************************************************************************/

View file

@ -100,6 +100,19 @@ nmp_link_address_get (const NMPLinkAddress *addr, size_t *length)
return addr->data;
}
GBytes *
nmp_link_address_get_as_bytes (const NMPLinkAddress *addr)
{
gconstpointer data;
size_t length;
data = nmp_link_address_get (addr, &length);
return length > 0
? g_bytes_new (data, length)
: NULL;
}
/*****************************************************************************/
#define _NMLOG_DOMAIN LOGD_PLATFORM

View file

@ -164,6 +164,7 @@ typedef struct {
} NMPLinkAddress;
gconstpointer nmp_link_address_get (const NMPLinkAddress *addr, size_t *length);
GBytes *nmp_link_address_get_as_bytes (const NMPLinkAddress *addr);
typedef enum {
@ -1407,18 +1408,6 @@ gboolean nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex
gconstpointer nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length);
static inline GBytes *
nm_platform_link_get_address_as_bytes (NMPlatform *self, int ifindex)
{
gconstpointer p;
gsize l;
p = nm_platform_link_get_address (self, ifindex, &l);
return p
? g_bytes_new (p, l)
: NULL;
}
int nm_platform_link_get_master (NMPlatform *self, int slave);
gboolean nm_platform_link_can_assume (NMPlatform *self, int ifindex);

View file

@ -23,7 +23,6 @@ libnm_systemd_core = static_library(
'src/libsystemd/sd-event/sd-event.c',
'src/libsystemd/sd-id128/id128-util.c',
'src/libsystemd/sd-id128/sd-id128.c',
'src/shared/dns-domain.c',
'nm-sd.c',
'nm-sd-utils-core.c',
),
@ -33,7 +32,6 @@ libnm_systemd_core = static_library(
'sd-adapt-core',
'src/libsystemd-network',
'src/libsystemd/sd-event',
'src/shared',
'src/systemd',
)
],