Thomas Haller 2018-11-01 11:17:49 +01:00
commit 6651915e69
16 changed files with 140 additions and 15 deletions

View file

@ -0,0 +1,6 @@
# default the DHCP client-id to MAC (instead of type 255, node-specific RFC 4361).
# But don't do so for dhclient DHCP plugin, as the default of dhclient may
# be specified via /etc/dhcp (and anyway defaults to "hardware" already).
[connection-00-server-dhcp-client-id]
match-device=except:dhcp-plugin:dhclient
ipv4.dhcp-client-id=mac

View file

@ -117,8 +117,9 @@ URL: http://www.gnome.org/projects/NetworkManager/
Source: __SOURCE1__
Source1: NetworkManager.conf
Source2: 00-server.conf
Source3: 20-connectivity-fedora.conf
Source4: 20-connectivity-redhat.conf
Source3: 00-server-dhcp-client-id.conf
Source4: 20-connectivity-fedora.conf
Source5: 20-connectivity-redhat.conf
#Patch1: 0001-some.patch
@ -677,13 +678,14 @@ make install DESTDIR=%{buildroot}
cp %{SOURCE1} %{buildroot}%{_sysconfdir}/%{name}/
cp %{SOURCE2} %{buildroot}%{nmlibdir}/conf.d/
cp %{SOURCE3} %{buildroot}%{nmlibdir}/conf.d/
%if %{with connectivity_fedora}
cp %{SOURCE3} %{buildroot}%{nmlibdir}/conf.d/
cp %{SOURCE4} %{buildroot}%{nmlibdir}/conf.d/
%endif
%if %{with connectivity_redhat}
cp %{SOURCE4} %{buildroot}%{nmlibdir}/conf.d/
cp %{SOURCE5} %{buildroot}%{nmlibdir}/conf.d/
%endif
cp examples/dispatcher/10-ifcfg-rh-routes.sh %{buildroot}%{_sysconfdir}/%{name}/dispatcher.d/
@ -961,6 +963,7 @@ fi
%dir %{nmlibdir}
%dir %{nmlibdir}/conf.d
%{nmlibdir}/conf.d/00-server.conf
%{nmlibdir}/conf.d/00-server-dhcp-client-id.conf
%files dispatcher-routing-rules

View file

@ -18,6 +18,7 @@
# SOURCE_FROM_GIT=|1|0
# SOURCE_NETWORKMANAGER_CONF=
# SOURCE_CONFIG_SERVER=
# SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID=
# SOURCE_CONFIG_CONNECTIVITY_FEDORA=
# SOURCE_CONFIG_CONNECTIVITY_REDHAT=
@ -121,6 +122,7 @@ fi
SOURCE_NETWORKMANAGER_CONF="$(abs_path "$SOURCE_NETWORKMANAGER_CONF" "$SCRIPTDIR/NetworkManager.conf")" || die "invalid \$SOURCE_NETWORKMANAGER_CONF argument"
SOURCE_CONFIG_SERVER="$(abs_path "$SOURCE_CONFIG_SERVER" "$SCRIPTDIR/00-server.conf")" || die "invalid \$SOURCE_CONFIG_SERVER argument"
SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID="$(abs_path "$SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID" "$SCRIPTDIR/00-server-dhcp-client-id.conf")" || die "invalid \$SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID argument"
SOURCE_CONFIG_CONNECTIVITY_FEDORA="$(abs_path "$SOURCE_CONFIG_CONNECTIVITY_FEDORA" "$SCRIPTDIR/20-connectivity-fedora.conf")" || die "invalid \$SOURCE_CONFIG_CONNECTIVITY_FEDORA argument"
SOURCE_CONFIG_CONNECTIVITY_REDHAT="$(abs_path "$SOURCE_CONFIG_CONNECTIVITY_REDHAT" "$SCRIPTDIR/20-connectivity-redhat.conf")" || die "invalid \$SOURCE_CONFIG_CONNECTIVITY_REDHAT argument"
@ -144,6 +146,7 @@ LOG "SOURCE=$SOURCE"
LOG "SOURCE_FROM_GIT=$SOURCE_FROM_GIT"
LOG "SOURCE_NETWORKMANAGER_CONF=$SOURCE_NETWORKMANAGER_CONF"
LOG "SOURCE_CONFIG_SERVER=$SOURCE_CONFIG_SERVER"
LOG "SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID=$SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID"
LOG "SOURCE_CONFIG_CONNECTIVITY_FEDORA=$SOURCE_CONFIG_CONNECTIVITY_FEDORA"
LOG "SOURCE_CONFIG_CONNECTIVITY_REDHAT=$SOURCE_CONFIG_CONNECTIVITY_REDHAT"
LOG "BUILDTYPE=$BUILDTYPE"
@ -164,6 +167,7 @@ if [[ "$(dirname "$SOURCE")" != "$TEMP/SOURCES" ]]; then
fi
cp "$SOURCE_NETWORKMANAGER_CONF" "$TEMP/SOURCES/NetworkManager.conf" || die "Could not copy source $SOURCE_NETWORKMANAGER_CONF to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_SERVER" "$TEMP/SOURCES/00-server.conf" || die "Could not copy source $SOURCE_CONFIG_SERVER to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID" "$TEMP/SOURCES/00-server-dhcp-client-id.conf" || die "Could not copy source $SOURCE_CONFIG_SERVER_DHCP_CLIENT_ID to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_CONNECTIVITY_FEDORA" "$TEMP/SOURCES/20-connectivity-fedora.conf" || die "Could not copy source $SOURCE_CONFIG_CONNECTIVITY_FEDORA to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_CONNECTIVITY_REDHAT" "$TEMP/SOURCES/20-connectivity-redhat.conf" || die "Could not copy source $SOURCE_CONFIG_CONNECTIVITY_REDHAT to $TEMP/SOURCES"

View file

@ -1365,6 +1365,11 @@ enable=nm-version-min:1.3,nm-version-min:1.2.6,nm-version-min:1.0.16
Optionally, a driver version may be specified separated by '/'. Globbing is supported for the version.
</para></listitem>
</varlistentry>
<varlistentry>
<term>dhcp-plugin:DHCP</term>
<listitem><para>Match the configured DHCP plugin "<literal>main.dhcp</literal>".
</para></listitem>
</varlistentry>
<varlistentry>
<term>except:SPEC</term>
<listitem><para>Negative match of a device. <literal>SPEC</literal> must be explicitly qualified with

View file

@ -1347,6 +1347,42 @@ _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, cons
/*****************************************************************************/
#ifdef __NETWORKMANAGER_LOGGING_H__
static inline gpointer
nmtst_logging_disable (gboolean always)
{
gpointer p;
g_assert (nmtst_initialized ());
if (!always && __nmtst_internal.no_expect_message) {
/* The caller does not want to @always suppress logging. Instead,
* the caller wants to suppress unexpected log messages that would
* fail assertions (since we possibly assert against all unexpected
* log messages).
*
* If the test is run with no-expect-message, then don't suppress
* the loggings, because they also wouldn't fail assertions. */
return NULL;
}
p = g_memdup (_nm_logging_enabled_state, sizeof (_nm_logging_enabled_state));
memset (_nm_logging_enabled_state, 0, sizeof (_nm_logging_enabled_state));
return p;
}
static inline void
nmtst_logging_reenable (gpointer old_state)
{
g_assert (nmtst_initialized ());
if (old_state) {
memcpy (_nm_logging_enabled_state, old_state, sizeof (_nm_logging_enabled_state));
g_free (old_state);
}
}
#endif
/*****************************************************************************/
#ifdef NM_SETTING_IP_CONFIG_H
static inline void
nmtst_setting_ip_config_add_address (NMSettingIPConfig *s_ip,

View file

@ -882,6 +882,7 @@ nm_utils_match_connection (NMConnection *const*connections,
int
nm_match_spec_device_by_pllink (const NMPlatformLink *pllink,
const char *match_device_type,
const char *match_dhcp_plugin,
const GSList *specs,
int no_match_value)
{
@ -898,7 +899,8 @@ nm_match_spec_device_by_pllink (const NMPlatformLink *pllink,
pllink ? pllink->driver : NULL,
NULL,
NULL,
NULL);
NULL,
match_dhcp_plugin);
switch (m) {
case NM_MATCH_SPEC_MATCH:

View file

@ -50,6 +50,7 @@ NMConnection *nm_utils_match_connection (NMConnection *const*connections,
int nm_match_spec_device_by_pllink (const NMPlatformLink *pllink,
const char *match_device_type,
const char *match_dhcp_plugin,
const GSList *specs,
int no_match_value);

View file

@ -15776,6 +15776,7 @@ nm_device_spec_match_list_full (NMDevice *self, const GSList *specs, int no_matc
nm_device_get_driver (self),
nm_device_get_driver_version (self),
nm_device_get_permanent_hw_address (self),
nm_dhcp_manager_get_config (nm_dhcp_manager_get ()),
klass->get_s390_subchannels ? klass->get_s390_subchannels (self) : NULL);
switch (m) {

View file

@ -384,6 +384,12 @@ nm_dhcp_manager_get_config (NMDhcpManager *self)
NM_DEFINE_SINGLETON_GETTER (NMDhcpManager, nm_dhcp_manager_get, NM_TYPE_DHCP_MANAGER);
void
nmtst_dhcp_manager_unget (gpointer self)
{
_nmtst_nm_dhcp_manager_get_reset (self);
}
static void
nm_dhcp_manager_init (NMDhcpManager *self)
{
@ -446,6 +452,10 @@ nm_dhcp_manager_init (NMDhcpManager *self)
nm_log_info (LOGD_DHCP, "dhcp-init: Using DHCP client '%s'", client_factory->name);
/* NOTE: currently the DHCP plugin is chosen once at start. It's not
* possible to reload that configuration. If that ever becomes possible,
* beware that the "dhcp-plugin" device spec made decisions based on
* the previous plugin and may need reevaluation. */
priv->client_factory = client_factory;
}

View file

@ -87,4 +87,6 @@ extern const char* nm_dhcp_helper_path;
extern const NMDhcpClientFactory *const _nm_dhcp_manager_factories[4];
void nmtst_dhcp_manager_unget (gpointer singleton_instance);
#endif /* __NETWORKMANAGER_DHCP_MANAGER_H__ */

View file

@ -1250,9 +1250,13 @@ _match_section_infos_lookup (const MatchSectionInfo *match_section_infos,
const char *match_device_type,
char **out_value)
{
const char *match_dhcp_plugin;
if (!match_section_infos)
return NULL;
match_dhcp_plugin = nm_dhcp_manager_get_config (nm_dhcp_manager_get ());
for (; match_section_infos->group_name; match_section_infos++) {
char *value = NULL;
gboolean match;
@ -1272,7 +1276,7 @@ _match_section_infos_lookup (const MatchSectionInfo *match_section_infos,
if (device)
match = nm_device_spec_match_list (device, match_section_infos->match_device.spec);
else if (pllink)
match = nm_match_spec_device_by_pllink (pllink, match_device_type, match_section_infos->match_device.spec, FALSE);
match = nm_match_spec_device_by_pllink (pllink, match_device_type, match_dhcp_plugin, match_section_infos->match_device.spec, FALSE);
else
match = FALSE;
} else

View file

@ -233,5 +233,14 @@ GKeyFile *_nm_config_data_get_keyfile (const NMConfigData *self);
GKeyFile *_nm_config_data_get_keyfile_user (const NMConfigData *self);
GKeyFile *_nm_config_data_get_keyfile_intern (const NMConfigData *self);
/*****************************************************************************/
/* nm-config-data.c requires getting the DHCP manager's configuration. That is a bit
* ugly, and optimally, NMConfig* is independent of NMDhcpManager. Instead of
* including the header, forward declare the two functions that we need. */
struct _NMDhcpManager;
struct _NMDhcpManager *nm_dhcp_manager_get (void);
const char *nm_dhcp_manager_get_config (struct _NMDhcpManager *self);
#endif /* NM_CONFIG_DATA_H */

View file

@ -1141,6 +1141,7 @@ nm_utils_read_link_absolute (const char *link_file, GError **error)
#define DEVICE_TYPE_TAG "type:"
#define DRIVER_TAG "driver:"
#define SUBCHAN_TAG "s390-subchannels:"
#define DHCP_PLUGIN_TAG "dhcp-plugin:"
#define EXCEPT_TAG "except:"
#define MATCH_TAG_CONFIG_NM_VERSION "nm-version:"
#define MATCH_TAG_CONFIG_NM_VERSION_MIN "nm-version-min:"
@ -1152,6 +1153,7 @@ typedef struct {
const char *device_type;
const char *driver;
const char *driver_version;
const char *dhcp_plugin;
struct {
const char *value;
gboolean is_parsed;
@ -1369,6 +1371,9 @@ match_device_eval (const char *spec_str,
if (_MATCH_CHECK (spec_str, SUBCHAN_TAG))
return match_data_s390_subchannels_eval (spec_str, match_data);
if (_MATCH_CHECK (spec_str, DHCP_PLUGIN_TAG))
return nm_streq0 (spec_str, match_data->dhcp_plugin);
if (allow_fuzzy) {
if (match_device_hwaddr_eval (spec_str, match_data))
return TRUE;
@ -1387,7 +1392,8 @@ nm_match_spec_device (const GSList *specs,
const char *driver,
const char *driver_version,
const char *hwaddr,
const char *s390_subchannels)
const char *s390_subchannels,
const char *dhcp_plugin)
{
const GSList *iter;
NMMatchSpecMatchType match;
@ -1398,6 +1404,7 @@ nm_match_spec_device (const GSList *specs,
.device_type = nm_str_not_empty (device_type),
.driver = nm_str_not_empty (driver),
.driver_version = nm_str_not_empty (driver_version),
.dhcp_plugin = nm_str_not_empty (dhcp_plugin),
.hwaddr = {
.value = hwaddr,
},

View file

@ -63,20 +63,35 @@ void _nm_singleton_instance_register_destruction (GObject *instance);
#define NM_DEFINE_SINGLETON_GETTER(TYPE, GETTER, GTYPE, ...) \
NM_DEFINE_SINGLETON_INSTANCE (TYPE); \
NM_DEFINE_SINGLETON_REGISTER (TYPE); \
static char _already_created_##GETTER = FALSE; \
TYPE * \
GETTER (void) \
{ \
if (G_UNLIKELY (!singleton_instance)) { \
static char _already_created = FALSE; \
\
g_assert (!_already_created || (NM_DEFINE_SINGLETON_ALLOW_MULTIPLE)); \
_already_created = TRUE;\
g_assert (!(_already_created_##GETTER) || (NM_DEFINE_SINGLETON_ALLOW_MULTIPLE)); \
(_already_created_##GETTER) = TRUE;\
singleton_instance = (g_object_new (GTYPE, ##__VA_ARGS__, NULL)); \
g_assert (singleton_instance); \
nm_singleton_instance_register (); \
nm_log_dbg (LOGD_CORE, "create %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \
} \
return singleton_instance; \
} \
_nm_unused static void \
_nmtst_##GETTER##_reset (TYPE *instance) \
{ \
/* usually, the singleton can only be created once (and further instantiations
* are guarded by an assert). For testing, we need to reset the singleton to
* allow multiple instantiations. */ \
g_assert (G_IS_OBJECT (instance)); \
g_assert (instance == singleton_instance); \
g_assert (_already_created_##GETTER); \
g_object_unref (instance); \
\
/* require that the last unref also destroyed the singleton. If this fails,
* somebody still keeps a reference. Fix your test! */ \
g_assert (!singleton_instance); \
_already_created_##GETTER = FALSE; \
}
/* attach @instance to the data or @owner. @owner owns a reference
@ -210,7 +225,8 @@ NMMatchSpecMatchType nm_match_spec_device (const GSList *specs,
const char *driver,
const char *driver_version,
const char *hwaddr,
const char *s390_subchannels);
const char *s390_subchannels,
const char *dhcp_plugin);
NMMatchSpecMatchType nm_match_spec_config (const GSList *specs,
guint nm_version,
const char *env);

View file

@ -25,6 +25,7 @@
#include "nm-config.h"
#include "nm-test-device.h"
#include "platform/nm-fake-platform.h"
#include "dhcp/nm-dhcp-manager.h"
#include "nm-dbus-manager.h"
#include "nm-connectivity.h"
@ -123,6 +124,24 @@ setup_config (GError **error, const char *config_file, const char *intern_config
g_assert_no_error (local_error);
}
nm_config_cmd_line_options_free (cli);
if (config) {
NMDhcpManager *dhcp_manager;
gpointer logging_old_state;
logging_old_state = nmtst_logging_disable (FALSE);
dhcp_manager = nm_dhcp_manager_get ();
g_test_assert_expected_messages ();
nmtst_logging_reenable (logging_old_state);
g_object_set_data_full (G_OBJECT (config),
"nmtst-config-keep-dhcp-manager-alive",
dhcp_manager,
nmtst_dhcp_manager_unget);
}
return config;
}

View file

@ -1093,7 +1093,7 @@ static NMMatchSpecMatchType
_test_match_spec_device (const GSList *specs, const char *match_str)
{
if (match_str && g_str_has_prefix (match_str, MATCH_S390))
return nm_match_spec_device (specs, NULL, NULL, NULL, NULL, NULL, &match_str[NM_STRLEN (MATCH_S390)]);
return nm_match_spec_device (specs, NULL, NULL, NULL, NULL, NULL, &match_str[NM_STRLEN (MATCH_S390)], NULL);
if (match_str && g_str_has_prefix (match_str, MATCH_DRIVER)) {
gs_free char *s = g_strdup (&match_str[NM_STRLEN (MATCH_DRIVER)]);
char *t;
@ -1103,9 +1103,9 @@ _test_match_spec_device (const GSList *specs, const char *match_str)
t[0] = '\0';
t++;
}
return nm_match_spec_device (specs, NULL, NULL, s, t, NULL, NULL);
return nm_match_spec_device (specs, NULL, NULL, s, t, NULL, NULL, NULL);
}
return nm_match_spec_device (specs, match_str, NULL, NULL, NULL, NULL, NULL);
return nm_match_spec_device (specs, match_str, NULL, NULL, NULL, NULL, NULL, NULL);
}
static void