2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2018-08-09 18:02:51 +02:00
|
|
|
* Copyright (C) 2018 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-09 09:30:13 +01:00
|
|
|
#include "libnm-core-impl/nm-default-libnm-core.h"
|
2018-08-09 18:02:51 +02:00
|
|
|
|
2020-12-13 16:08:56 +01:00
|
|
|
#include <linux/if_ether.h>
|
|
|
|
|
#include <linux/if_infiniband.h>
|
|
|
|
|
|
2021-05-02 21:47:22 +02:00
|
|
|
#include "libnm-glib-aux/nm-uuid.h"
|
2021-03-09 09:30:13 +01:00
|
|
|
#include "libnm-log-core/nm-logging.h"
|
2021-02-12 15:01:09 +01:00
|
|
|
#include "libnm-core-intern/nm-core-internal.h"
|
2018-08-09 18:02:51 +02:00
|
|
|
#include "nm-initrd-generator.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define _NMLOG(level, domain, ...) \
|
|
|
|
|
nm_log((level), \
|
|
|
|
|
(domain), \
|
|
|
|
|
NULL, \
|
|
|
|
|
NULL, \
|
|
|
|
|
"cmdline-reader: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) \
|
|
|
|
|
_NM_UTILS_MACRO_REST(__VA_ARGS__))
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
typedef struct {
|
2021-11-09 13:28:54 +01:00
|
|
|
GHashTable *hash;
|
|
|
|
|
GPtrArray *array;
|
|
|
|
|
GPtrArray *vlan_parents;
|
|
|
|
|
GHashTable *explicit_ip_connections;
|
2020-03-21 22:28:31 +01:00
|
|
|
NMConnection *bootdev_connection; /* connection for bootdev=$ifname */
|
|
|
|
|
NMConnection *default_connection; /* connection not bound to any ifname */
|
2021-11-09 13:28:54 +01:00
|
|
|
char *hostname;
|
2022-01-24 22:42:07 +01:00
|
|
|
GHashTable *znet_ifnames;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-04 09:57:51 +02:00
|
|
|
/* Parameters to be set for all connections */
|
|
|
|
|
gboolean ignore_auto_dns;
|
2020-05-04 10:26:21 +02:00
|
|
|
int dhcp_timeout;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *dhcp4_vci;
|
2021-01-18 03:15:14 +09:00
|
|
|
|
|
|
|
|
gint64 carrier_timeout_sec;
|
2020-03-21 09:57:57 +01:00
|
|
|
} Reader;
|
|
|
|
|
|
|
|
|
|
static Reader *
|
|
|
|
|
reader_new(void)
|
2019-07-02 10:03:00 +02:00
|
|
|
{
|
2020-03-21 09:57:57 +01:00
|
|
|
Reader *reader;
|
2019-07-02 10:03:00 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
reader = g_slice_new(Reader);
|
|
|
|
|
*reader = (Reader){
|
2020-11-18 14:27:19 +01:00
|
|
|
.hash = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_object_unref),
|
|
|
|
|
.explicit_ip_connections =
|
|
|
|
|
g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL),
|
|
|
|
|
.vlan_parents = g_ptr_array_new_with_free_func(g_free),
|
|
|
|
|
.array = g_ptr_array_new(),
|
2022-01-24 22:42:07 +01:00
|
|
|
.znet_ifnames = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free),
|
2020-03-21 09:57:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return reader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GHashTable *
|
|
|
|
|
reader_destroy(Reader *reader, gboolean free_hash)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_hashtable GHashTable *hash = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
g_ptr_array_unref(reader->array);
|
2020-11-18 14:27:19 +01:00
|
|
|
g_ptr_array_unref(reader->vlan_parents);
|
|
|
|
|
g_hash_table_unref(reader->explicit_ip_connections);
|
2020-03-21 09:57:57 +01:00
|
|
|
hash = g_steal_pointer(&reader->hash);
|
2020-05-04 10:03:21 +02:00
|
|
|
nm_clear_g_free(&reader->hostname);
|
2022-01-24 22:42:07 +01:00
|
|
|
g_hash_table_unref(reader->znet_ifnames);
|
2020-08-27 17:43:54 +02:00
|
|
|
nm_clear_g_free(&reader->dhcp4_vci);
|
2020-03-21 09:57:57 +01:00
|
|
|
nm_g_slice_free(reader);
|
|
|
|
|
if (!free_hash)
|
|
|
|
|
return g_steal_pointer(&hash);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMConnection *
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_connection(Reader *reader, const char *name, NMConnection *connection_take)
|
2020-03-21 09:57:57 +01:00
|
|
|
{
|
|
|
|
|
char *name_dup;
|
|
|
|
|
|
|
|
|
|
name_dup = g_strdup(name);
|
|
|
|
|
if (g_hash_table_insert(reader->hash, name_dup, connection_take))
|
|
|
|
|
g_ptr_array_add(reader->array, name_dup);
|
|
|
|
|
|
|
|
|
|
return connection_take;
|
2019-07-02 10:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
/* Returns a new connection owned by the reader */
|
2019-11-11 10:56:31 +01:00
|
|
|
static NMConnection *
|
2021-11-09 13:28:54 +01:00
|
|
|
reader_create_connection(Reader *reader,
|
|
|
|
|
const char *basename,
|
|
|
|
|
const char *id,
|
|
|
|
|
const char *ifname,
|
|
|
|
|
const char *mac,
|
|
|
|
|
const char *type_name,
|
2022-09-12 11:33:46 +02:00
|
|
|
int autoconnect_priority,
|
2020-03-25 10:17:03 +01:00
|
|
|
NMConnectionMultiConnect multi_connect)
|
2019-11-11 10:56:31 +01:00
|
|
|
{
|
|
|
|
|
NMConnection *connection;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMSetting *setting;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_add_connection(reader, basename, nm_simple_connection_new());
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
/* Start off assuming dynamic IP configurations. */
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
setting = nm_setting_ip4_config_new();
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
|
|
|
|
g_object_set(setting,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
TRUE,
|
2020-05-04 09:57:51 +02:00
|
|
|
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
|
|
|
|
|
reader->ignore_auto_dns,
|
2020-05-04 10:26:21 +02:00
|
|
|
NM_SETTING_IP_CONFIG_DHCP_TIMEOUT,
|
|
|
|
|
reader->dhcp_timeout,
|
2020-08-27 17:43:54 +02:00
|
|
|
NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER,
|
|
|
|
|
reader->dhcp4_vci,
|
2021-06-24 08:09:10 +02:00
|
|
|
NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT,
|
|
|
|
|
NMI_IP_REQUIRED_TIMEOUT_MSEC,
|
2019-11-11 10:56:31 +01:00
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
setting = nm_setting_ip6_config_new();
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
|
|
|
|
g_object_set(setting,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
TRUE,
|
2019-12-04 18:25:39 +01:00
|
|
|
NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE,
|
all: make "ipv6.addr-gen-mode" configurable by global default
It can be useful to choose a different "ipv6.addr-gen-mode". And it can be
useful to override the default for a set of profiles.
For example, in cloud or in a data center, stable-privacy might not be
the best choice. Add a mechanism to override the default via global defaults
in NetworkManager.conf:
# /etc/NetworkManager/conf.d/90-ipv6-addr-gen-mode-override.conf
[connection-90-ipv6-addr-gen-mode-override]
match-device=type:ethernet
ipv6.addr-gen-mode=0
"ipv6.addr-gen-mode" is a special property, because its default depends on
the component that configures the profile.
- when read from disk (keyfile and ifcfg-rh), a missing addr-gen-mode
key means to default to "eui64".
- when configured via D-Bus, a missing addr-gen-mode property means to
default to "stable-privacy".
- libnm's ip6-config::addr-gen-mode property defaults to
"stable-privacy".
- when some tool creates a profile, they either can explicitly
set the mode, or they get the default of the underlying mechanisms
above.
- nm-initrd-generator explicitly sets "eui64" for profiles it creates.
- nmcli doesn' explicitly set it, but inherits the default form
libnm's ip6-config::addr-gen-mode.
- when NM creates a auto-default-connection for ethernet ("Wired connection 1"),
it inherits the default from libnm's ip6-config::addr-gen-mode.
Global connection defaults only take effect when the per-profile
value is set to a special default/unset value. To account for the
different cases above, we add two such special values: "default" and
"default-or-eui64". That's something we didn't do before, but it seams
useful and easy to understand.
Also, this neatly expresses the current behaviors we already have. E.g.
if you don't specify the "addr-gen-mode" in a keyfile, "default-or-eui64"
is a pretty clear thing.
Note that usually we cannot change default values, in particular not for
libnm's properties. That is because we don't serialize the default
values to D-Bus/keyfile, so if we change the default, we change
behavior. Here we change from "stable-privacy" to "default" and
from "eui64" to "default-or-eui64". That means, the user only experiences
a change in behavior, if they have a ".conf" file that overrides the default.
https://bugzilla.redhat.com/show_bug.cgi?id=1743161
https://bugzilla.redhat.com/show_bug.cgi?id=2082682
See-also: https://github.com/coreos/fedora-coreos-tracker/issues/907
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1213
2022-05-06 16:57:51 +02:00
|
|
|
(int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT_OR_EUI64,
|
2020-05-04 09:57:51 +02:00
|
|
|
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
|
|
|
|
|
reader->ignore_auto_dns,
|
2020-05-04 10:26:21 +02:00
|
|
|
NM_SETTING_IP_CONFIG_DHCP_TIMEOUT,
|
|
|
|
|
reader->dhcp_timeout,
|
2019-11-11 10:56:31 +01:00
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
setting = nm_setting_connection_new();
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
|
|
|
|
g_object_set(setting,
|
|
|
|
|
NM_SETTING_CONNECTION_ID,
|
|
|
|
|
id,
|
|
|
|
|
NM_SETTING_CONNECTION_UUID,
|
2021-05-02 14:55:46 +02:00
|
|
|
nm_uuid_generate_random_str_a(),
|
2019-11-11 10:56:31 +01:00
|
|
|
NM_SETTING_CONNECTION_INTERFACE_NAME,
|
|
|
|
|
ifname,
|
|
|
|
|
NM_SETTING_CONNECTION_TYPE,
|
|
|
|
|
type_name,
|
|
|
|
|
NM_SETTING_CONNECTION_MULTI_CONNECT,
|
|
|
|
|
multi_connect,
|
2021-02-12 09:50:48 +01:00
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES,
|
|
|
|
|
1,
|
2022-09-12 11:33:46 +02:00
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY,
|
|
|
|
|
autoconnect_priority,
|
2019-11-11 10:56:31 +01:00
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-10-15 09:44:52 +02:00
|
|
|
if (nm_streq0(type_name, NM_SETTING_INFINIBAND_SETTING_NAME)) {
|
|
|
|
|
setting = nm_setting_infiniband_new();
|
2020-09-22 17:54:18 +02:00
|
|
|
nm_connection_add_setting(connection, setting);
|
2020-10-15 09:44:52 +02:00
|
|
|
g_object_set(setting, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mac) {
|
|
|
|
|
if (nm_streq0(type_name, NM_SETTING_INFINIBAND_SETTING_NAME)) {
|
|
|
|
|
setting = (NMSetting *) nm_connection_get_setting_infiniband(connection);
|
|
|
|
|
g_object_set(setting, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
setting = nm_setting_wired_new();
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
|
|
|
|
g_object_set(setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
|
|
|
|
}
|
2020-09-22 17:54:18 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
static NMConnection *
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_get_default_connection(Reader *reader)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2020-03-21 22:28:31 +01:00
|
|
|
NMConnection *con;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!reader->default_connection) {
|
2020-03-25 10:17:03 +01:00
|
|
|
con = reader_create_connection(reader,
|
|
|
|
|
"default_connection",
|
|
|
|
|
"Wired Connection",
|
|
|
|
|
NULL,
|
2020-09-22 17:54:18 +02:00
|
|
|
NULL,
|
2020-03-25 10:17:03 +01:00
|
|
|
NM_SETTING_WIRED_SETTING_NAME,
|
2022-09-12 11:33:46 +02:00
|
|
|
NMI_AUTOCONNECT_PRIORITY_CMDLINE,
|
2020-03-25 10:17:03 +01:00
|
|
|
NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
|
2020-07-03 15:26:28 +02:00
|
|
|
nm_connection_add_setting(con, nm_setting_wired_new());
|
2020-03-21 22:28:31 +01:00
|
|
|
reader->default_connection = con;
|
2019-01-14 16:10:44 +01:00
|
|
|
}
|
2020-03-21 22:28:31 +01:00
|
|
|
return reader->default_connection;
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
static NMConnection *
|
2021-11-09 13:28:54 +01:00
|
|
|
reader_get_connection(Reader *reader,
|
2020-09-22 17:54:18 +02:00
|
|
|
const char *iface_spec,
|
2020-03-25 10:17:03 +01:00
|
|
|
const char *type_name,
|
|
|
|
|
gboolean create_if_missing)
|
2020-03-21 22:28:31 +01:00
|
|
|
{
|
|
|
|
|
NMConnection *connection = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMSetting *setting;
|
|
|
|
|
const char *ifname = NULL;
|
2020-09-22 17:54:18 +02:00
|
|
|
gs_free char *mac = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-09-22 17:54:18 +02:00
|
|
|
if (iface_spec) {
|
|
|
|
|
if (nm_utils_is_valid_iface_name(iface_spec, NULL))
|
|
|
|
|
ifname = iface_spec;
|
|
|
|
|
else {
|
2020-10-15 09:44:52 +02:00
|
|
|
mac = nm_utils_hwaddr_canonical(iface_spec, -1);
|
2020-09-22 17:54:18 +02:00
|
|
|
if (!mac)
|
|
|
|
|
_LOGW(LOGD_CORE, "invalid interface '%s'", iface_spec);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-09-22 17:54:18 +02:00
|
|
|
if (!ifname && !mac) {
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *candidate;
|
2020-03-21 09:57:57 +01:00
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-07-02 10:03:00 +02:00
|
|
|
/*
|
|
|
|
|
* If ifname was not given, we'll match the connection by type.
|
|
|
|
|
* If the type was not given either, then we're happy with any connection but slaves.
|
|
|
|
|
* This is so that things like "bond=bond0:eth1,eth2 nameserver=1.3.3.7 end up
|
|
|
|
|
* slapping the nameserver to the most reasonable connection (bond0).
|
|
|
|
|
*/
|
2020-03-21 09:57:57 +01:00
|
|
|
for (i = 0; i < reader->array->len; i++) {
|
|
|
|
|
candidate = g_hash_table_lookup(reader->hash, reader->array->pdata[i]);
|
|
|
|
|
s_con = nm_connection_get_setting_connection(candidate);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
if (type_name == NULL && nm_setting_connection_get_master(s_con) == NULL) {
|
|
|
|
|
connection = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
if (type_name != NULL
|
|
|
|
|
&& nm_streq(nm_setting_connection_get_connection_type(s_con), type_name)) {
|
|
|
|
|
connection = candidate;
|
|
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2020-03-21 09:57:57 +01:00
|
|
|
}
|
2020-03-21 22:28:31 +01:00
|
|
|
} else
|
2020-09-22 17:54:18 +02:00
|
|
|
connection = g_hash_table_lookup(reader->hash, (gpointer) ifname ?: mac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-11-11 10:56:31 +01:00
|
|
|
if (!connection) {
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!create_if_missing)
|
|
|
|
|
return NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-10-15 09:44:52 +02:00
|
|
|
if (!type_name) {
|
|
|
|
|
if (NM_STR_HAS_PREFIX(ifname, "ib")
|
|
|
|
|
|| (mac && nm_utils_hwaddr_valid(mac, INFINIBAND_ALEN)))
|
|
|
|
|
type_name = NM_SETTING_INFINIBAND_SETTING_NAME;
|
|
|
|
|
else
|
|
|
|
|
type_name = NM_SETTING_WIRED_SETTING_NAME;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-09-22 17:54:18 +02:00
|
|
|
connection = reader_create_connection(reader,
|
|
|
|
|
ifname ?: mac,
|
|
|
|
|
ifname ?: (mac ?: "Wired Connection"),
|
|
|
|
|
ifname,
|
|
|
|
|
mac,
|
|
|
|
|
type_name,
|
2022-09-12 11:33:46 +02:00
|
|
|
NMI_AUTOCONNECT_PRIORITY_CMDLINE,
|
2020-03-25 10:17:03 +01:00
|
|
|
NM_CONNECTION_MULTI_CONNECT_SINGLE);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-03-21 22:28:31 +01:00
|
|
|
setting = (NMSetting *) nm_connection_get_setting_connection(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (type_name) {
|
|
|
|
|
g_object_set(setting, NM_SETTING_CONNECTION_TYPE, type_name, NULL);
|
|
|
|
|
if (!nm_connection_get_setting_by_name(connection, type_name)) {
|
|
|
|
|
setting = g_object_new(nm_setting_lookup_type(type_name), NULL);
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_word(char **argument, const char separator)
|
|
|
|
|
{
|
|
|
|
|
char *word;
|
|
|
|
|
int nest = 0;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (*argument == NULL)
|
|
|
|
|
return NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (**argument == '[') {
|
|
|
|
|
nest++;
|
|
|
|
|
(*argument)++;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
word = *argument;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
while (**argument != '\0') {
|
|
|
|
|
if (nest && **argument == ']') {
|
|
|
|
|
**argument = '\0';
|
|
|
|
|
(*argument)++;
|
|
|
|
|
nest--;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (nest == 0 && **argument == separator) {
|
|
|
|
|
**argument = '\0';
|
|
|
|
|
(*argument)++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
(*argument)++;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
return *word ? word : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-02 10:04:08 +02:00
|
|
|
connection_set(NMConnection *connection,
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *setting_name,
|
|
|
|
|
const char *property,
|
|
|
|
|
const char *value)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMSetting *setting;
|
|
|
|
|
GType setting_type;
|
2020-07-02 10:04:08 +02:00
|
|
|
nm_auto_unref_gtypeclass GObjectClass *object_class = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
GParamSpec *spec;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-07-02 10:04:08 +02:00
|
|
|
setting_type = nm_setting_lookup_type(setting_name);
|
|
|
|
|
object_class = g_type_class_ref(setting_type);
|
|
|
|
|
spec = g_object_class_find_property(object_class, property);
|
|
|
|
|
nm_assert(spec);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-07-02 10:04:08 +02:00
|
|
|
setting = nm_connection_get_setting_by_name(connection, setting_name);
|
|
|
|
|
if (!setting) {
|
|
|
|
|
setting = g_object_new(setting_type, NULL);
|
|
|
|
|
nm_connection_add_setting(connection, setting);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-10-22 08:26:45 +02:00
|
|
|
if (G_IS_PARAM_SPEC_UINT(spec)) {
|
|
|
|
|
guint v;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-10-22 08:26:45 +02:00
|
|
|
v = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT, 0);
|
|
|
|
|
if (errno || !nm_g_object_set_property_uint(G_OBJECT(setting), property, v, NULL)) {
|
|
|
|
|
_LOGW(LOGD_CORE,
|
|
|
|
|
"Could not set property '%s.%s' to '%s'",
|
2020-07-02 10:04:08 +02:00
|
|
|
setting_name,
|
|
|
|
|
property,
|
|
|
|
|
value);
|
2018-10-22 08:26:45 +02:00
|
|
|
}
|
|
|
|
|
} else if (G_IS_PARAM_SPEC_STRING(spec))
|
2018-08-09 18:02:51 +02:00
|
|
|
g_object_set(setting, property, value, NULL);
|
|
|
|
|
else
|
2020-07-02 10:04:08 +02:00
|
|
|
_LOGW(LOGD_CORE, "Don't know how to set '%s' of %s", property, setting_name);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-11 14:13:19 +01:00
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_read_all_connections_from_fw(Reader *reader, const char *sysfs_dir)
|
2020-01-11 14:13:19 +01:00
|
|
|
{
|
|
|
|
|
gs_unref_hashtable GHashTable *ibft = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *dt_connection;
|
|
|
|
|
const char *mac;
|
|
|
|
|
GHashTable *nic;
|
|
|
|
|
const char *index;
|
|
|
|
|
GError *error = NULL;
|
2020-03-21 15:33:29 +01:00
|
|
|
guint i, length;
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free const char **keys = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-01-11 14:13:19 +01:00
|
|
|
ibft = nmi_ibft_read(sysfs_dir);
|
2021-07-30 09:15:38 +02:00
|
|
|
keys = nm_strdict_get_keys(ibft, TRUE, &length);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 15:33:29 +01:00
|
|
|
for (i = 0; i < length; i++) {
|
2020-03-25 18:34:01 +01:00
|
|
|
gs_unref_object NMConnection *connection = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *name = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 15:33:29 +01:00
|
|
|
mac = keys[i];
|
|
|
|
|
nic = g_hash_table_lookup(ibft, mac);
|
2020-03-25 18:34:01 +01:00
|
|
|
connection = nm_simple_connection_new();
|
2020-01-11 14:13:19 +01:00
|
|
|
index = g_hash_table_lookup(nic, "index");
|
|
|
|
|
if (!index) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Ignoring an iBFT entry without an index");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-01-11 14:13:19 +01:00
|
|
|
if (!nmi_ibft_update_connection_from_nic(connection, nic, &error)) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Unable to merge iBFT configuration: %s", error->message);
|
|
|
|
|
g_error_free(error);
|
2020-03-25 18:34:01 +01:00
|
|
|
continue;
|
2020-01-11 14:13:19 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
name = g_strdup_printf("ibft%s", index);
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_connection(reader, name, g_steal_pointer(&connection));
|
2020-01-11 14:13:19 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 18:34:01 +01:00
|
|
|
dt_connection = nmi_dt_reader_parse(sysfs_dir);
|
2020-03-21 09:57:57 +01:00
|
|
|
if (dt_connection)
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_connection(reader, "ofw", dt_connection);
|
2020-01-11 14:13:19 +01:00
|
|
|
}
|
|
|
|
|
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
#define _strv_is_same_unordered(strv, ...) \
|
|
|
|
|
nm_strv_is_same_unordered(NM_CAST_STRV_CC(strv), -1, NM_MAKE_STRV(__VA_ARGS__), -1)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_strv_remove(const char **strv, const char *needle)
|
|
|
|
|
{
|
|
|
|
|
gssize idx;
|
|
|
|
|
gsize len;
|
|
|
|
|
gsize i;
|
|
|
|
|
|
2021-07-29 10:02:11 +02:00
|
|
|
idx = nm_strv_find_first(strv, -1, needle);
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (idx < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Remove element at idx, by shifting the remaining ones
|
|
|
|
|
* (including the terminating NULL). */
|
|
|
|
|
len = NM_PTRARRAY_LEN(strv);
|
|
|
|
|
for (i = idx; i < len; i++)
|
|
|
|
|
strv[i] = strv[i + 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
_parse_ip_method(const char *kind)
|
|
|
|
|
{
|
|
|
|
|
const char *const KINDS[] = {
|
|
|
|
|
"none",
|
|
|
|
|
"dhcp",
|
|
|
|
|
"dhcp6",
|
|
|
|
|
"link6",
|
|
|
|
|
"auto",
|
|
|
|
|
"ibft",
|
|
|
|
|
};
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *kind_to_free = NULL;
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
gs_free const char **strv = NULL;
|
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
|
|
kind = nm_strstrip_avoid_copy_a(300, kind, &kind_to_free);
|
|
|
|
|
|
|
|
|
|
if (nm_str_is_empty(kind)) {
|
|
|
|
|
/* Dracut defaults empty/missing to "dhcp". We treat them differently, as it
|
|
|
|
|
* depends on whether we have IP addresses too.
|
|
|
|
|
* https://github.com/dracutdevs/dracut/blob/3cc9f1c10c67dcdb5254e0eb69f19e9ab22abf20/modules.d/35network-legacy/parse-ip-opts.sh#L62 */
|
|
|
|
|
return "auto";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS(KINDS); i++) {
|
|
|
|
|
if (nm_streq(kind, KINDS[i]))
|
|
|
|
|
return KINDS[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the following are (currently) treated as aliases. */
|
|
|
|
|
if (nm_streq(kind, "fw"))
|
|
|
|
|
return "ibft";
|
|
|
|
|
if (nm_streq(kind, "single-dhcp"))
|
|
|
|
|
return "dhcp";
|
|
|
|
|
if (nm_streq(kind, "off"))
|
|
|
|
|
return "none";
|
|
|
|
|
if (nm_streq(kind, "auto6"))
|
|
|
|
|
return "dhcp6";
|
|
|
|
|
if (NM_IN_STRSET(kind, "on", "any"))
|
|
|
|
|
return "auto";
|
|
|
|
|
|
|
|
|
|
if (!strchr(kind, ','))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* dracut also supports combinations, separated by comma. We don't
|
|
|
|
|
* support arbitrary combinations, but accept specific subsets. */
|
2021-07-30 09:15:38 +02:00
|
|
|
strv = nm_strsplit_set_full(kind, ",", NM_STRSPLIT_SET_FLAGS_STRSTRIP);
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (!strv)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* first normalize the strv array by replacing all entries by their
|
|
|
|
|
* normalized kind. */
|
|
|
|
|
for (i = 0; strv[i]; i++) {
|
|
|
|
|
strv[i] = _parse_ip_method(strv[i]);
|
|
|
|
|
if (!strv[i]) {
|
|
|
|
|
/* Unknown key. Not recognized. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* sort list and remove duplicates. */
|
2021-07-29 10:02:11 +02:00
|
|
|
nm_strv_sort(strv, -1);
|
|
|
|
|
nm_strv_cleanup_const(strv, TRUE, TRUE);
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
|
2021-07-29 10:02:11 +02:00
|
|
|
if (nm_strv_find_first(strv, -1, "auto") >= 0) {
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
/* if "auto" is present, then "dhcp4", "dhcp6", and "local6" is implied. */
|
|
|
|
|
_strv_remove(strv, "dhcp4");
|
|
|
|
|
_strv_remove(strv, "dhcp6");
|
|
|
|
|
_strv_remove(strv, "local6");
|
2021-07-29 10:02:11 +02:00
|
|
|
} else if (nm_strv_find_first(strv, -1, "dhcp6") >= 0) {
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
/* if "dhcp6" is present, then "local6" is implied. */
|
|
|
|
|
_strv_remove(strv, "local6");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strv[0] && !strv[1]) {
|
|
|
|
|
/* there is only one value left. It's good. */
|
|
|
|
|
return strv[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only certain combinations are allowed... those are listed
|
|
|
|
|
* and mapped to a canonical value.
|
2021-10-13 15:02:56 +02:00
|
|
|
*/
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (_strv_is_same_unordered(strv, "dhcp", "dhcp6"))
|
2021-10-13 15:02:56 +02:00
|
|
|
return "dhcp4+auto6";
|
|
|
|
|
/* For the moment, this maps to "auto". This might be revisited
|
|
|
|
|
* in the future to add new kinds like "dhcp+local6"
|
|
|
|
|
*/
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (_strv_is_same_unordered(strv, "dhcp", "local6"))
|
|
|
|
|
return "auto";
|
|
|
|
|
|
|
|
|
|
/* undetected. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSettingIPConfig *s_ip4 = NULL, *s_ip6 = NULL;
|
2018-08-09 18:02:51 +02:00
|
|
|
gs_unref_hashtable GHashTable *ibft = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *tmp;
|
|
|
|
|
const char *tmp2;
|
|
|
|
|
const char *tmp3;
|
|
|
|
|
const char *kind;
|
|
|
|
|
const char *client_ip = NULL;
|
|
|
|
|
const char *peer = NULL;
|
|
|
|
|
const char *gateway_ip = NULL;
|
|
|
|
|
const char *netmask = NULL;
|
|
|
|
|
const char *client_hostname = NULL;
|
|
|
|
|
const char *iface_spec = NULL;
|
|
|
|
|
const char *mtu = NULL;
|
|
|
|
|
const char *macaddr = NULL;
|
2021-06-24 08:09:10 +02:00
|
|
|
int client_ip_family = AF_UNSPEC;
|
|
|
|
|
int client_ip_prefix = -1;
|
|
|
|
|
gboolean clear_ip4_required_timeout = TRUE;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *dns[2] = {
|
2021-02-16 21:23:37 +01:00
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2018-08-09 18:02:51 +02:00
|
|
|
};
|
|
|
|
|
int dns_addr_family[2] = {
|
2021-02-16 21:23:37 +01:00
|
|
|
AF_UNSPEC,
|
|
|
|
|
AF_UNSPEC,
|
2020-09-28 16:03:33 +02:00
|
|
|
};
|
2018-08-09 18:02:51 +02:00
|
|
|
int i;
|
|
|
|
|
GError *error = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (!*argument)
|
|
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
tmp = get_word(&argument, ':');
|
|
|
|
|
if (!*argument) {
|
2020-07-23 21:42:56 +02:00
|
|
|
/* ip={dhcp|on|any|dhcp6|auto6|link6|ibft} */
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
kind = _parse_ip_method(tmp);
|
|
|
|
|
if (!kind) {
|
|
|
|
|
/* invalid method. We treat it as "auto". */
|
|
|
|
|
kind = "auto";
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
} else {
|
2020-11-25 17:39:48 +01:00
|
|
|
tmp2 = get_word(&argument, ':');
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (!nm_str_is_empty(tmp2) && (tmp3 = _parse_ip_method(tmp2))) {
|
2020-07-23 21:42:56 +02:00
|
|
|
/* <ifname>:{none|off|dhcp|on|any|dhcp6|auto|auto6|link6|ibft} */
|
2020-11-25 17:39:48 +01:00
|
|
|
iface_spec = tmp;
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
kind = tmp3;
|
2020-11-25 17:39:48 +01:00
|
|
|
} else {
|
|
|
|
|
/* <client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<kind> */
|
|
|
|
|
client_ip = tmp;
|
|
|
|
|
if (client_ip) {
|
|
|
|
|
client_ip_family = get_ip_address_family(client_ip, TRUE);
|
|
|
|
|
if (client_ip_family == AF_UNSPEC) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Invalid IP address '%s'.", client_ip);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peer = tmp2;
|
2018-08-09 18:02:51 +02:00
|
|
|
gateway_ip = get_word(&argument, ':');
|
|
|
|
|
netmask = get_word(&argument, ':');
|
|
|
|
|
client_hostname = get_word(&argument, ':');
|
2020-09-22 17:54:18 +02:00
|
|
|
iface_spec = get_word(&argument, ':');
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
tmp2 = get_word(&argument, ':');
|
|
|
|
|
kind = _parse_ip_method(tmp2);
|
|
|
|
|
if (!kind) {
|
|
|
|
|
/* invalid method. We treat that as "auto". */
|
|
|
|
|
kind = "auto";
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2022-04-12 17:25:53 +02:00
|
|
|
if (client_hostname && !nm_hostname_is_valid(client_hostname, FALSE))
|
2020-05-04 10:03:21 +02:00
|
|
|
client_hostname = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-04 10:03:21 +02:00
|
|
|
if (client_hostname) {
|
|
|
|
|
g_free(reader->hostname);
|
|
|
|
|
reader->hostname = g_strdup(client_hostname);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
tmp = get_word(&argument, ':');
|
2020-11-17 11:10:54 +01:00
|
|
|
dns_addr_family[0] = get_ip_address_family(tmp, FALSE);
|
2018-08-09 18:02:51 +02:00
|
|
|
if (dns_addr_family[0] != AF_UNSPEC) {
|
2021-02-16 21:23:37 +01:00
|
|
|
dns[0] = tmp;
|
|
|
|
|
dns[1] = get_word(&argument, ':');
|
|
|
|
|
if (dns[1]) {
|
|
|
|
|
dns_addr_family[1] = get_ip_address_family(dns[1], FALSE);
|
|
|
|
|
if (dns_addr_family[1] == AF_UNSPEC)
|
|
|
|
|
_LOGW(LOGD_CORE, "Ignoring invalid DNS server: '%s'.", dns[1]);
|
|
|
|
|
if (*argument)
|
|
|
|
|
_LOGW(LOGD_CORE, "Ignoring extra: '%s'.", argument);
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
} else {
|
|
|
|
|
mtu = tmp;
|
|
|
|
|
macaddr = argument;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (iface_spec == NULL && nm_streq(kind, "ibft")) {
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_read_all_connections_from_fw(reader, sysfs_dir);
|
2018-08-09 18:02:51 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
/* Parsing done, construct the NMConnection. */
|
2020-09-22 17:54:18 +02:00
|
|
|
if (iface_spec)
|
|
|
|
|
connection = reader_get_connection(reader, iface_spec, NULL, TRUE);
|
2020-03-21 22:28:31 +01:00
|
|
|
else
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_default_connection(reader);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-11-18 14:27:19 +01:00
|
|
|
g_hash_table_add(reader->explicit_ip_connections, g_object_ref(connection));
|
|
|
|
|
|
2021-03-11 09:15:37 +01:00
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
2018-08-09 18:02:51 +02:00
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config(connection);
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (netmask && *netmask) {
|
2020-09-23 10:58:03 +02:00
|
|
|
gboolean is_ipv4 = client_ip_family == AF_INET;
|
2018-08-09 18:02:51 +02:00
|
|
|
NMIPAddr addr;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
if (is_ipv4 && nm_inet_parse_bin(AF_INET, netmask, NULL, &addr))
|
|
|
|
|
client_ip_prefix = nm_ip4_addr_netmask_to_prefix(addr.addr4);
|
2019-07-02 09:45:22 +02:00
|
|
|
else
|
2020-09-23 10:58:03 +02:00
|
|
|
client_ip_prefix = _nm_utils_ascii_str_to_int64(netmask, 10, 0, is_ipv4 ? 32 : 128, -1);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-07-02 09:45:22 +02:00
|
|
|
if (client_ip_prefix == -1)
|
2019-07-02 09:31:46 +02:00
|
|
|
_LOGW(LOGD_CORE, "Invalid IP mask: %s", netmask);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
/* Static IP configuration might be present. */
|
|
|
|
|
if (client_ip && *client_ip) {
|
|
|
|
|
NMIPAddress *address = NULL;
|
|
|
|
|
NMIPAddr addr;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
if (nm_inet_parse_with_prefix_bin(client_ip_family,
|
|
|
|
|
client_ip,
|
|
|
|
|
NULL,
|
|
|
|
|
&addr,
|
|
|
|
|
client_ip_prefix == -1 ? &client_ip_prefix : NULL)) {
|
2018-08-09 18:02:51 +02:00
|
|
|
if (client_ip_prefix == -1) {
|
|
|
|
|
switch (client_ip_family) {
|
|
|
|
|
case AF_INET:
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
client_ip_prefix = nm_ip4_addr_get_default_prefix(addr.addr4);
|
2018-08-09 18:02:51 +02:00
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
client_ip_prefix = 64;
|
|
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
address = nm_ip_address_new_binary(client_ip_family,
|
|
|
|
|
&addr.addr_ptr,
|
|
|
|
|
client_ip_prefix,
|
|
|
|
|
&error);
|
|
|
|
|
if (!address) {
|
2018-10-06 11:26:42 +02:00
|
|
|
_LOGW(LOGD_CORE, "Invalid address '%s': %s", client_ip, error->message);
|
2018-08-09 18:02:51 +02:00
|
|
|
g_clear_error(&error);
|
|
|
|
|
}
|
2020-11-17 11:10:54 +01:00
|
|
|
} else
|
|
|
|
|
nm_assert_not_reached();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (address) {
|
2021-03-11 09:15:37 +01:00
|
|
|
/* We don't want to have multiple devices up with the
|
|
|
|
|
* same static address. */
|
|
|
|
|
g_object_set(s_con,
|
|
|
|
|
NM_SETTING_CONNECTION_MULTI_CONNECT,
|
|
|
|
|
NM_CONNECTION_MULTI_CONNECT_SINGLE,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
switch (client_ip_family) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
g_object_set(s_ip4,
|
2018-09-18 18:44:42 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
nm_setting_ip_config_add_address(s_ip4, address);
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
g_object_set(s_ip6,
|
2018-09-18 18:44:42 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
nm_setting_ip_config_add_address(s_ip6, address);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-11-17 11:10:54 +01:00
|
|
|
nm_assert_not_reached();
|
2018-08-09 18:02:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
nm_ip_address_unref(address);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
/* Dynamic IP configuration configured explicitly. */
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
if (nm_streq(kind, "none")) {
|
2018-08-09 18:02:51 +02:00
|
|
|
if (nm_setting_ip_config_get_num_addresses(s_ip6) == 0) {
|
|
|
|
|
g_object_set(s_ip6,
|
2020-06-22 12:00:22 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
2020-10-08 22:19:12 +02:00
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_DISABLED,
|
2018-09-18 18:44:42 +02:00
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
if (nm_setting_ip_config_get_num_addresses(s_ip4) == 0) {
|
|
|
|
|
g_object_set(s_ip4,
|
2018-09-18 18:44:42 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
} else if (nm_streq(kind, "dhcp")) {
|
2018-08-09 18:02:51 +02:00
|
|
|
g_object_set(s_ip4,
|
2018-09-18 18:44:42 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
if (nm_setting_ip_config_get_num_addresses(s_ip6) == 0) {
|
|
|
|
|
g_object_set(s_ip6,
|
2020-06-22 11:56:51 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
2018-09-18 18:44:42 +02:00
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
} else if (nm_streq(kind, "dhcp6")) {
|
2020-07-23 21:37:36 +02:00
|
|
|
g_object_set(s_ip6,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
if (nm_setting_ip_config_get_num_addresses(s_ip4) == 0) {
|
|
|
|
|
g_object_set(s_ip4,
|
2018-09-18 18:44:42 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
|
|
|
|
NULL);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2021-10-13 15:02:56 +02:00
|
|
|
} else if (nm_streq(kind, "dhcp4+auto6")) {
|
|
|
|
|
/* Both DHCPv4 and IPv6 autoconf are enabled, and
|
|
|
|
|
* each of them is tried for at least IP_REQUIRED_TIMEOUT_MSEC,
|
|
|
|
|
* even if the other one completes before.
|
|
|
|
|
*/
|
|
|
|
|
clear_ip4_required_timeout = FALSE;
|
|
|
|
|
g_object_set(s_ip6,
|
|
|
|
|
NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT,
|
|
|
|
|
NMI_IP_REQUIRED_TIMEOUT_MSEC,
|
|
|
|
|
NULL);
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
} else if (nm_streq(kind, "link6")) {
|
2020-07-23 21:42:56 +02:00
|
|
|
g_object_set(s_ip6,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
if (nm_setting_ip_config_get_num_addresses(s_ip4) == 0) {
|
|
|
|
|
g_object_set(s_ip4,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
} else if (nm_streq(kind, "ibft")) {
|
2020-09-22 17:54:18 +02:00
|
|
|
NMSettingWired *s_wired;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *mac = NULL;
|
|
|
|
|
const char *ifname;
|
|
|
|
|
gs_free char *mac_free = NULL;
|
|
|
|
|
gs_free char *address_path = NULL;
|
|
|
|
|
GHashTable *nic = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-09-22 17:54:18 +02:00
|
|
|
if ((s_wired = nm_connection_get_setting_wired(connection))
|
|
|
|
|
&& (mac = nm_setting_wired_get_mac_address(s_wired))) {
|
|
|
|
|
/* got mac from the connection */
|
|
|
|
|
} else if ((ifname = nm_connection_get_interface_name(connection))) {
|
|
|
|
|
/* read it from sysfs */
|
|
|
|
|
address_path = g_build_filename(sysfs_dir, "class", "net", ifname, "address", NULL);
|
|
|
|
|
if (g_file_get_contents(address_path, &mac_free, NULL, &error)) {
|
|
|
|
|
g_strchomp(mac_free);
|
|
|
|
|
mac = mac_free;
|
|
|
|
|
} else {
|
|
|
|
|
_LOGW(LOGD_CORE, "Can't get a MAC address for %s: %s", ifname, error->message);
|
|
|
|
|
g_clear_error(&error);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (mac) {
|
2020-09-22 17:54:18 +02:00
|
|
|
gs_free char *mac_up = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
mac_up = g_ascii_strup(mac, -1);
|
2020-01-11 14:13:19 +01:00
|
|
|
ibft = nmi_ibft_read(sysfs_dir);
|
2018-08-09 18:02:51 +02:00
|
|
|
nic = g_hash_table_lookup(ibft, mac_up);
|
|
|
|
|
if (!nic)
|
2020-09-22 17:54:18 +02:00
|
|
|
_LOGW(LOGD_CORE, "No iBFT NIC for %s (%s)", iface_spec, mac_up);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (nic) {
|
|
|
|
|
if (!nmi_ibft_update_connection_from_nic(connection, nic, &error)) {
|
2018-10-06 11:26:42 +02:00
|
|
|
_LOGW(LOGD_CORE, "Unable to merge iBFT configuration: %s", error->message);
|
2018-08-09 18:02:51 +02:00
|
|
|
g_clear_error(&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-24 08:09:10 +02:00
|
|
|
} else {
|
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.
NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.
Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.
Also, use the same validation code at all 3 places where IP methods
can appear, that is
ip=<method>
ip=<ifname>:<method>[:...]
ip=<client-ip>:...:<method>[:...]
Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.
Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-23 12:30:20 +02:00
|
|
|
nm_assert(nm_streq(kind, "auto"));
|
2021-06-24 08:09:10 +02:00
|
|
|
clear_ip4_required_timeout = FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-24 08:09:10 +02:00
|
|
|
if (clear_ip4_required_timeout)
|
|
|
|
|
g_object_set(s_ip4, NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT, -1, NULL);
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (peer && *peer)
|
2019-07-02 09:33:20 +02:00
|
|
|
_LOGW(LOGD_CORE, "Ignoring peer: %s (not implemented)\n", peer);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (gateway_ip && *gateway_ip) {
|
2020-11-17 11:10:54 +01:00
|
|
|
switch (get_ip_address_family(gateway_ip, FALSE)) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
g_object_set(s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway_ip, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
g_object_set(s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, gateway_ip, NULL);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-10-06 11:26:42 +02:00
|
|
|
_LOGW(LOGD_CORE, "Invalid gateway: %s", gateway_ip);
|
2020-11-17 11:10:54 +01:00
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (client_hostname && *client_hostname) {
|
|
|
|
|
g_object_set(s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, client_hostname, NULL);
|
|
|
|
|
g_object_set(s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, client_hostname, NULL);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
if (dns_addr_family[i] == AF_UNSPEC)
|
|
|
|
|
break;
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
nm_assert(nm_inet_is_valid(dns_addr_family[i], dns[i]));
|
2021-02-16 21:23:37 +01:00
|
|
|
nm_setting_ip_config_add_dns(NM_IS_IPv4(dns_addr_family[i]) ? s_ip4 : s_ip6, dns[i]);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (mtu && *mtu)
|
2020-07-02 10:04:08 +02:00
|
|
|
connection_set(connection, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU, mtu);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (macaddr && *macaddr)
|
2020-07-02 10:04:08 +02:00
|
|
|
connection_set(connection,
|
|
|
|
|
NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
|
|
|
|
|
macaddr);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_master(Reader *reader, char *argument, const char *type_name, const char *default_name)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2018-08-09 18:02:51 +02:00
|
|
|
NMSettingConnection *s_con;
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *master_to_free = NULL;
|
|
|
|
|
const char *master;
|
|
|
|
|
char *slaves;
|
|
|
|
|
const char *slave;
|
|
|
|
|
char *opts;
|
|
|
|
|
const char *mtu = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
master = get_word(&argument, ':');
|
|
|
|
|
if (!master)
|
2019-11-07 15:29:31 +01:00
|
|
|
master = master_to_free = g_strdup_printf("%s0", default_name ?: type_name);
|
2018-08-09 18:02:51 +02:00
|
|
|
slaves = get_word(&argument, ':');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, master, type_name, TRUE);
|
2018-08-09 18:02:51 +02:00
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
|
|
|
|
master = nm_setting_connection_get_uuid(s_con);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-08-05 13:26:34 +02:00
|
|
|
if (nm_streq(type_name, NM_SETTING_BRIDGE_SETTING_NAME)) {
|
|
|
|
|
NMSettingBridge *s_bridge = nm_connection_get_setting_bridge(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-08-05 13:26:34 +02:00
|
|
|
/* Avoid the forwarding delay */
|
|
|
|
|
g_object_set(s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL);
|
|
|
|
|
} else if (nm_streq(type_name, NM_SETTING_BOND_SETTING_NAME)) {
|
|
|
|
|
NMSettingBond *s_bond = nm_connection_get_setting_bond(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
opts = get_word(&argument, ':');
|
|
|
|
|
while (opts && *opts) {
|
libnm/bond: remove validation from nm_setting_bond_add_option() and explicitly validate
For historic reasons is NMSettingBond implemented differently from other
settings. It uses a strdict, and adds some validation on top of that.
The idea was probably to be able to treat bond options more generically.
But in practice we cannot treat them as opaque values, but need to know,
validate and understand all the options. Thus, this implementation with a
strdict is not nice.
The user can set the GObject property NM_SETTING_BOND_OPTIONS to any
strdict, and the setter performs no validation or normalization. That
is probably good, because g_object_set() cannot return an error to
signalize invalid settings. As often, we have corresponding C API like
nm_setting_bond_add_option() and nm_setting_bond_remove_option(). It
should be possible to get the same result both with the C API and with
the GObject property setting. Since there is already a way to set
certain invalid values, it does not help if the C API tries to prevent
that. That implies, that also add-option does not perform additional
validation and sets whatever the user asks.
Remove all validation from nm_setting_bond_add_option() and
nm_setting_bond_remove_option(). This validation was anyway only very
basic. It was calling nm_setting_bond_validate_option(), which can check
whether the string is (for example) and integer, but it cannot do
validation beyond one option. In most cases, the validation needs to
take into account the bond mode or other options, so validating one
option in isolation is not very useful.
Proper validation should instead be done via nm_connection_verify().
However, due to another historic oddity, that verification is very
forgiving too and doesn't reject many invalid settings when it should.
That is hard to fix, because making validation more strict can break
existing (and working) configurations. However, verify() already contains
basic validation via nm_setting_bond_validate_option(). So in the previous
behavior nm_setting_bond_add_option() would silently do nothing (only
returning %FALSE) for invalid options, while now it would add the
invalid options to the dictionary -- only to have it later fail validation
during nm_connection_verify(). That is a slight change in behavior, however it
seems preferable.
It seems preferable and acceptable because most users that call
nm_setting_bond_add_option() already understand the meaning and valid
values. Keyfile and ifcfg-rh readers are the few exceptions, which really just
parse a string dictionary, without need to understand them. But nmtui
or nmstate already know the option they want to set. They don't expect
a failure there, nor do they need the validation.
Note that this change in behavior could be dangerous for example for the
keyfile/ifcfg-rh readers, which silently ignored errors before. We
don't want them to start failing if they read invalid options from a
file, so instead let those callers explicitly pre-validate the value
and log an warning.
https://bugzilla.redhat.com/show_bug.cgi?id=1887523
2020-10-15 10:57:51 +02:00
|
|
|
gs_free_error GError *error = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *opt;
|
|
|
|
|
const char *opt_name;
|
libnm/bond: remove validation from nm_setting_bond_add_option() and explicitly validate
For historic reasons is NMSettingBond implemented differently from other
settings. It uses a strdict, and adds some validation on top of that.
The idea was probably to be able to treat bond options more generically.
But in practice we cannot treat them as opaque values, but need to know,
validate and understand all the options. Thus, this implementation with a
strdict is not nice.
The user can set the GObject property NM_SETTING_BOND_OPTIONS to any
strdict, and the setter performs no validation or normalization. That
is probably good, because g_object_set() cannot return an error to
signalize invalid settings. As often, we have corresponding C API like
nm_setting_bond_add_option() and nm_setting_bond_remove_option(). It
should be possible to get the same result both with the C API and with
the GObject property setting. Since there is already a way to set
certain invalid values, it does not help if the C API tries to prevent
that. That implies, that also add-option does not perform additional
validation and sets whatever the user asks.
Remove all validation from nm_setting_bond_add_option() and
nm_setting_bond_remove_option(). This validation was anyway only very
basic. It was calling nm_setting_bond_validate_option(), which can check
whether the string is (for example) and integer, but it cannot do
validation beyond one option. In most cases, the validation needs to
take into account the bond mode or other options, so validating one
option in isolation is not very useful.
Proper validation should instead be done via nm_connection_verify().
However, due to another historic oddity, that verification is very
forgiving too and doesn't reject many invalid settings when it should.
That is hard to fix, because making validation more strict can break
existing (and working) configurations. However, verify() already contains
basic validation via nm_setting_bond_validate_option(). So in the previous
behavior nm_setting_bond_add_option() would silently do nothing (only
returning %FALSE) for invalid options, while now it would add the
invalid options to the dictionary -- only to have it later fail validation
during nm_connection_verify(). That is a slight change in behavior, however it
seems preferable.
It seems preferable and acceptable because most users that call
nm_setting_bond_add_option() already understand the meaning and valid
values. Keyfile and ifcfg-rh readers are the few exceptions, which really just
parse a string dictionary, without need to understand them. But nmtui
or nmstate already know the option they want to set. They don't expect
a failure there, nor do they need the validation.
Note that this change in behavior could be dangerous for example for the
keyfile/ifcfg-rh readers, which silently ignored errors before. We
don't want them to start failing if they read invalid options from a
file, so instead let those callers explicitly pre-validate the value
and log an warning.
https://bugzilla.redhat.com/show_bug.cgi?id=1887523
2020-10-15 10:57:51 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
opt = get_word(&opts, ',');
|
|
|
|
|
opt_name = get_word(&opt, '=');
|
libnm/bond: remove validation from nm_setting_bond_add_option() and explicitly validate
For historic reasons is NMSettingBond implemented differently from other
settings. It uses a strdict, and adds some validation on top of that.
The idea was probably to be able to treat bond options more generically.
But in practice we cannot treat them as opaque values, but need to know,
validate and understand all the options. Thus, this implementation with a
strdict is not nice.
The user can set the GObject property NM_SETTING_BOND_OPTIONS to any
strdict, and the setter performs no validation or normalization. That
is probably good, because g_object_set() cannot return an error to
signalize invalid settings. As often, we have corresponding C API like
nm_setting_bond_add_option() and nm_setting_bond_remove_option(). It
should be possible to get the same result both with the C API and with
the GObject property setting. Since there is already a way to set
certain invalid values, it does not help if the C API tries to prevent
that. That implies, that also add-option does not perform additional
validation and sets whatever the user asks.
Remove all validation from nm_setting_bond_add_option() and
nm_setting_bond_remove_option(). This validation was anyway only very
basic. It was calling nm_setting_bond_validate_option(), which can check
whether the string is (for example) and integer, but it cannot do
validation beyond one option. In most cases, the validation needs to
take into account the bond mode or other options, so validating one
option in isolation is not very useful.
Proper validation should instead be done via nm_connection_verify().
However, due to another historic oddity, that verification is very
forgiving too and doesn't reject many invalid settings when it should.
That is hard to fix, because making validation more strict can break
existing (and working) configurations. However, verify() already contains
basic validation via nm_setting_bond_validate_option(). So in the previous
behavior nm_setting_bond_add_option() would silently do nothing (only
returning %FALSE) for invalid options, while now it would add the
invalid options to the dictionary -- only to have it later fail validation
during nm_connection_verify(). That is a slight change in behavior, however it
seems preferable.
It seems preferable and acceptable because most users that call
nm_setting_bond_add_option() already understand the meaning and valid
values. Keyfile and ifcfg-rh readers are the few exceptions, which really just
parse a string dictionary, without need to understand them. But nmtui
or nmstate already know the option they want to set. They don't expect
a failure there, nor do they need the validation.
Note that this change in behavior could be dangerous for example for the
keyfile/ifcfg-rh readers, which silently ignored errors before. We
don't want them to start failing if they read invalid options from a
file, so instead let those callers explicitly pre-validate the value
and log an warning.
https://bugzilla.redhat.com/show_bug.cgi?id=1887523
2020-10-15 10:57:51 +02:00
|
|
|
|
|
|
|
|
if (!_nm_setting_bond_validate_option(opt_name, opt, &error)) {
|
|
|
|
|
_LOGW(LOGD_CORE,
|
|
|
|
|
"Ignoring invalid bond option: %s%s%s = %s%s%s: %s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(opt_name),
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(opt),
|
|
|
|
|
error->message);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
nm_setting_bond_add_option(s_bond, opt_name, opt);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
mtu = get_word(&argument, ':');
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-03-01 21:16:08 +01:00
|
|
|
if (mtu)
|
|
|
|
|
connection_set(connection, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU, mtu);
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
do {
|
|
|
|
|
slave = get_word(&slaves, ',');
|
|
|
|
|
if (slave == NULL)
|
|
|
|
|
slave = "eth0";
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, slave, NULL, TRUE);
|
2018-08-09 18:02:51 +02:00
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
|
|
|
|
g_object_set(s_con,
|
|
|
|
|
NM_SETTING_CONNECTION_SLAVE_TYPE,
|
|
|
|
|
type_name,
|
|
|
|
|
NM_SETTING_CONNECTION_MASTER,
|
|
|
|
|
master,
|
|
|
|
|
NULL);
|
|
|
|
|
} while (slaves && *slaves != '\0');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (argument && *argument)
|
2018-10-06 11:26:42 +02:00
|
|
|
_LOGW(LOGD_CORE, "Ignoring extra: '%s'.", argument);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_routes(Reader *reader, GPtrArray *array)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2020-03-21 22:28:31 +01:00
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
for (i = 0; i < array->len; i++) {
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection = NULL;
|
|
|
|
|
const char *net;
|
|
|
|
|
const char *gateway;
|
|
|
|
|
const char *interface;
|
|
|
|
|
int family = AF_UNSPEC;
|
|
|
|
|
NMIPAddr net_addr = {};
|
|
|
|
|
NMIPAddr gateway_addr = {};
|
|
|
|
|
int net_prefix = -1;
|
|
|
|
|
NMIPRoute *route;
|
|
|
|
|
NMSettingIPConfig *s_ip;
|
|
|
|
|
char *argument;
|
2020-03-21 22:28:31 +01:00
|
|
|
gs_free_error GError *error = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
argument = array->pdata[i];
|
|
|
|
|
net = get_word(&argument, ':');
|
|
|
|
|
gateway = get_word(&argument, ':');
|
|
|
|
|
interface = get_word(&argument, ':');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (interface)
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, interface, NULL, TRUE);
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!connection)
|
|
|
|
|
connection = reader->bootdev_connection;
|
|
|
|
|
if (!connection)
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, interface, NULL, FALSE);
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!connection)
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_default_connection(reader);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (net && *net) {
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
if (!nm_inet_parse_with_prefix_bin(family, net, &family, &net_addr, &net_prefix)) {
|
2020-03-21 22:28:31 +01:00
|
|
|
_LOGW(LOGD_CORE, "Unrecognized address: %s", net);
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2020-03-21 22:28:31 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (gateway && *gateway) {
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
if (!nm_inet_parse_bin(family, gateway, &family, &gateway_addr)) {
|
2020-03-21 22:28:31 +01:00
|
|
|
_LOGW(LOGD_CORE, "Unrecognized address: %s", gateway);
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2020-03-21 22:28:31 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
switch (family) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
s_ip = nm_connection_get_setting_ip4_config(connection);
|
|
|
|
|
if (net_prefix == -1)
|
|
|
|
|
net_prefix = 32;
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
s_ip = nm_connection_get_setting_ip6_config(connection);
|
|
|
|
|
if (net_prefix == -1)
|
|
|
|
|
net_prefix = 128;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_LOGW(LOGD_CORE, "Unknown address family: %s", net);
|
|
|
|
|
continue;
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
route = nm_ip_route_new_binary(family,
|
|
|
|
|
&net_addr.addr_ptr,
|
|
|
|
|
net_prefix,
|
|
|
|
|
&gateway_addr.addr_ptr,
|
|
|
|
|
-1,
|
|
|
|
|
&error);
|
|
|
|
|
if (!route) {
|
|
|
|
|
g_warning("Invalid route '%s via %s': %s\n", net, gateway, error->message);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
nm_setting_ip_config_add_route(s_ip, route);
|
|
|
|
|
nm_ip_route_unref(route);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_vlan(Reader *reader, char *argument)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2018-08-09 18:02:51 +02:00
|
|
|
NMSettingVlan *s_vlan;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *vlan;
|
|
|
|
|
const char *phy;
|
|
|
|
|
const char *vlanid;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
vlan = get_word(&argument, ':');
|
|
|
|
|
phy = get_word(&argument, ':');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
for (vlanid = vlan + strlen(vlan); vlanid > vlan; vlanid--) {
|
|
|
|
|
if (!g_ascii_isdigit(*(vlanid - 1)))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, vlan, NM_SETTING_VLAN_SETTING_NAME, TRUE);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
g_object_set(s_vlan,
|
|
|
|
|
NM_SETTING_VLAN_PARENT,
|
|
|
|
|
phy,
|
2020-04-01 12:50:53 +02:00
|
|
|
NM_SETTING_VLAN_ID,
|
|
|
|
|
(guint) _nm_utils_ascii_str_to_int64(vlanid, 10, 0, G_MAXUINT, G_MAXUINT),
|
2018-08-09 18:02:51 +02:00
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (argument && *argument)
|
2018-10-06 11:26:42 +02:00
|
|
|
_LOGW(LOGD_CORE, "Ignoring extra: '%s'.", argument);
|
2020-11-18 14:27:19 +01:00
|
|
|
|
|
|
|
|
if (!nm_strv_ptrarray_contains(reader->vlan_parents, phy))
|
|
|
|
|
g_ptr_array_add(reader->vlan_parents, g_strdup(phy));
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 18:03:29 +02:00
|
|
|
static void
|
|
|
|
|
reader_parse_ib_pkey(Reader *reader, char *argument)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2021-06-08 18:03:29 +02:00
|
|
|
NMSettingInfiniband *s_ib;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *ifname;
|
|
|
|
|
gs_free char *parent = NULL;
|
|
|
|
|
char *pkey;
|
2021-06-08 18:03:29 +02:00
|
|
|
gint64 pkey_int;
|
|
|
|
|
|
|
|
|
|
/* At the moment we only support ib.pkey=<parent>.<pkey>;
|
|
|
|
|
* in the future we want to possibly support other options:
|
|
|
|
|
* ib.pkey=<parent>.<pkey>:<option>:...
|
|
|
|
|
*/
|
|
|
|
|
ifname = get_word(&argument, ':');
|
|
|
|
|
if (!ifname) {
|
|
|
|
|
_LOGW(LOGD_CORE, "ib.pkey= without argument");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent = g_strdup(ifname);
|
|
|
|
|
pkey = strchr(parent, '.');
|
|
|
|
|
if (!pkey) {
|
|
|
|
|
_LOGW(LOGD_CORE, "No pkey found for '%s'", ifname);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pkey = '\0';
|
|
|
|
|
pkey++;
|
|
|
|
|
|
|
|
|
|
pkey_int = _nm_utils_ascii_str_to_int64(pkey, 16, 0, 0xFFFF, -1);
|
|
|
|
|
if (pkey_int == -1) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Invalid pkey '%s'", pkey);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection = reader_get_connection(reader, ifname, NM_SETTING_INFINIBAND_SETTING_NAME, TRUE);
|
|
|
|
|
|
|
|
|
|
s_ib = nm_connection_get_setting_infiniband(connection);
|
|
|
|
|
g_object_set(s_ib,
|
|
|
|
|
NM_SETTING_INFINIBAND_PARENT,
|
|
|
|
|
parent,
|
|
|
|
|
NM_SETTING_INFINIBAND_P_KEY,
|
|
|
|
|
(int) pkey_int,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (argument && *argument)
|
|
|
|
|
_LOGW(LOGD_CORE, "Ignoring extra: '%s' for ib.pkey=", argument);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 22:42:07 +01:00
|
|
|
static void
|
|
|
|
|
reader_parse_znet_ifname(Reader *reader, char *argument)
|
|
|
|
|
{
|
|
|
|
|
char *ifname;
|
|
|
|
|
|
|
|
|
|
ifname = get_word(&argument, ':');
|
|
|
|
|
if (!ifname) {
|
|
|
|
|
_LOGW(LOGD_CORE, "rd.znet_ifname= without argument");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_hash_table_replace(reader->znet_ifnames, g_strdup(argument), g_strdup(ifname))) {
|
|
|
|
|
_LOGW(LOGD_CORE, "duplicate rd.znet_ifname for ifname=%s", ifname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 16:25:17 +02:00
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
|
2019-09-20 16:25:17 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *nettype;
|
|
|
|
|
const char *subchannels[4] = {0, 0, 0, 0};
|
|
|
|
|
const char *tmp;
|
2022-01-24 22:42:07 +01:00
|
|
|
gs_free char *ifname = NULL;
|
|
|
|
|
gs_free char *str_subchannels = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *prefix;
|
|
|
|
|
NMConnection *connection;
|
initrd: avoid assertion inparse_rd_znet() and cleanup
- nm_setting_wired_add_s390_option() asserts that a "value" argument
is given. Check that the string contains a '=' where we can split.
- pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn().
Otherwise, @s_wired might be %NULL, resulting in an assertion.
I do wonder whether this always retrieves a connection of the
appropriate type for modification, or whether a profile could
be returned that was created for a different purpose. But that
isn't changed.
- avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the
3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it
to be the opposite). The reasons for this are not documented, but I
presume it is correct.
Anyway, using streq() makes this slightly more clear to me, as with
strcmp() I would wonder whether this was just a typo while with
streq() I'd be more confident that this is indeed intended.
- don't initialize local variables unnecessarily. The compiler would
warn if we would forget about this. Also, don'\''t use { } for a
one-line block.
2019-09-27 07:58:58 +02:00
|
|
|
NMSettingWired *s_wired;
|
2019-10-23 11:56:47 +02:00
|
|
|
static int count_ctc = 0;
|
|
|
|
|
static int count_eth = 0;
|
2022-01-24 22:42:07 +01:00
|
|
|
int index = -1;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-09-20 16:25:17 +02:00
|
|
|
nettype = get_word(&argument, ',');
|
|
|
|
|
subchannels[0] = get_word(&argument, ',');
|
|
|
|
|
subchannels[1] = get_word(&argument, ',');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-03-16 10:00:44 +01:00
|
|
|
/* Without subchannels we can't univocally match
|
|
|
|
|
* a device. */
|
|
|
|
|
if (!subchannels[0] || !subchannels[1])
|
|
|
|
|
return;
|
|
|
|
|
|
2019-10-22 11:18:09 +02:00
|
|
|
if (nm_streq0(nettype, "ctc")) {
|
2019-10-23 11:56:47 +02:00
|
|
|
if (net_ifnames == TRUE) {
|
|
|
|
|
prefix = "sl";
|
|
|
|
|
} else {
|
|
|
|
|
prefix = "ctc";
|
|
|
|
|
index = count_ctc++;
|
|
|
|
|
}
|
2019-10-22 11:18:09 +02:00
|
|
|
} else {
|
2019-09-20 16:25:17 +02:00
|
|
|
subchannels[2] = get_word(&argument, ',');
|
2019-10-23 11:56:47 +02:00
|
|
|
if (net_ifnames == TRUE) {
|
|
|
|
|
prefix = "en";
|
|
|
|
|
} else {
|
|
|
|
|
prefix = "eth";
|
|
|
|
|
index = count_eth++;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2019-10-23 11:56:47 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2022-01-24 22:42:07 +01:00
|
|
|
str_subchannels = g_strjoinv(",", (char **) subchannels);
|
|
|
|
|
ifname = g_hash_table_lookup(reader->znet_ifnames, str_subchannels);
|
|
|
|
|
|
|
|
|
|
if (ifname) {
|
|
|
|
|
ifname = g_strdup(ifname);
|
|
|
|
|
g_hash_table_remove(reader->znet_ifnames, str_subchannels);
|
|
|
|
|
} else if (net_ifnames == TRUE) {
|
2019-10-22 16:56:38 +02:00
|
|
|
const char *bus_id;
|
|
|
|
|
size_t bus_id_len;
|
|
|
|
|
size_t bus_id_start;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-10-22 16:56:38 +02:00
|
|
|
/* The following logic is taken from names_ccw() in systemd/src/udev/udev-builtin-net_id.c */
|
|
|
|
|
bus_id = subchannels[0];
|
|
|
|
|
bus_id_len = strlen(bus_id);
|
|
|
|
|
bus_id_start = strspn(bus_id, ".0");
|
|
|
|
|
bus_id += bus_id_start < bus_id_len ? bus_id_start : bus_id_len - 1;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-10-22 16:56:38 +02:00
|
|
|
ifname = g_strdup_printf("%sc%s", prefix, bus_id);
|
2019-10-23 11:56:47 +02:00
|
|
|
} else {
|
2022-01-24 22:42:07 +01:00
|
|
|
nm_assert(index > -1);
|
2019-10-23 11:56:47 +02:00
|
|
|
ifname = g_strdup_printf("%s%d", prefix, index);
|
2019-10-22 16:56:38 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-27 12:01:21 +02:00
|
|
|
connection = reader_get_connection(reader, ifname, NM_SETTING_WIRED_SETTING_NAME, FALSE);
|
|
|
|
|
if (!connection)
|
|
|
|
|
return;
|
2019-09-20 16:25:17 +02:00
|
|
|
s_wired = nm_connection_get_setting_wired(connection);
|
|
|
|
|
g_object_set(s_wired,
|
|
|
|
|
NM_SETTING_WIRED_S390_NETTYPE,
|
|
|
|
|
nettype,
|
|
|
|
|
NM_SETTING_WIRED_S390_SUBCHANNELS,
|
|
|
|
|
&subchannels,
|
|
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-09-20 16:25:17 +02:00
|
|
|
while ((tmp = get_word(&argument, ',')) != NULL) {
|
2021-03-16 11:37:56 +01:00
|
|
|
const char *key;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *val;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
initrd: avoid assertion inparse_rd_znet() and cleanup
- nm_setting_wired_add_s390_option() asserts that a "value" argument
is given. Check that the string contains a '=' where we can split.
- pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn().
Otherwise, @s_wired might be %NULL, resulting in an assertion.
I do wonder whether this always retrieves a connection of the
appropriate type for modification, or whether a profile could
be returned that was created for a different purpose. But that
isn't changed.
- avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the
3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it
to be the opposite). The reasons for this are not documented, but I
presume it is correct.
Anyway, using streq() makes this slightly more clear to me, as with
strcmp() I would wonder whether this was just a typo while with
streq() I'd be more confident that this is indeed intended.
- don't initialize local variables unnecessarily. The compiler would
warn if we would forget about this. Also, don'\''t use { } for a
one-line block.
2019-09-27 07:58:58 +02:00
|
|
|
val = strchr(tmp, '=');
|
2021-03-16 11:37:56 +01:00
|
|
|
if (!val) {
|
|
|
|
|
/* an invalid (or empty) entry. Ignore. */
|
|
|
|
|
continue;
|
initrd: avoid assertion inparse_rd_znet() and cleanup
- nm_setting_wired_add_s390_option() asserts that a "value" argument
is given. Check that the string contains a '=' where we can split.
- pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn().
Otherwise, @s_wired might be %NULL, resulting in an assertion.
I do wonder whether this always retrieves a connection of the
appropriate type for modification, or whether a profile could
be returned that was created for a different purpose. But that
isn't changed.
- avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the
3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it
to be the opposite). The reasons for this are not documented, but I
presume it is correct.
Anyway, using streq() makes this slightly more clear to me, as with
strcmp() I would wonder whether this was just a typo while with
streq() I'd be more confident that this is indeed intended.
- don't initialize local variables unnecessarily. The compiler would
warn if we would forget about this. Also, don'\''t use { } for a
one-line block.
2019-09-27 07:58:58 +02:00
|
|
|
}
|
2021-03-16 11:37:56 +01:00
|
|
|
|
|
|
|
|
key = tmp;
|
|
|
|
|
val[0] = '\0';
|
|
|
|
|
val++;
|
|
|
|
|
if (!_nm_setting_wired_is_valid_s390_option(key)
|
|
|
|
|
|| !_nm_setting_wired_is_valid_s390_option_value(key, val)) {
|
|
|
|
|
/* Invalid setting. Silently ignore, but also ensure we
|
|
|
|
|
* didn't already set it. */
|
|
|
|
|
nm_setting_wired_remove_s390_option(s_wired, key);
|
|
|
|
|
} else
|
|
|
|
|
nm_setting_wired_add_s390_option(s_wired, key, val);
|
2019-09-20 16:25:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:14:19 -03:00
|
|
|
static void
|
|
|
|
|
reader_parse_ethtool(Reader *reader, char *argument)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2021-09-16 16:50:14 +02:00
|
|
|
NMSettingWired *s_wired;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *autoneg_str;
|
|
|
|
|
const char *speed_str;
|
|
|
|
|
const char *interface;
|
2021-09-16 16:50:14 +02:00
|
|
|
int autoneg;
|
|
|
|
|
guint speed;
|
2021-07-26 12:14:19 -03:00
|
|
|
|
|
|
|
|
interface = get_word(&argument, ':');
|
|
|
|
|
if (!interface) {
|
2021-09-16 16:50:15 +02:00
|
|
|
_LOGW(LOGD_CORE, "rd.ethtool: interface unspecified. Ignore");
|
2021-07-26 12:14:19 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2021-08-17 12:00:37 -03:00
|
|
|
|
|
|
|
|
autoneg_str = get_word(&argument, ':');
|
2021-09-16 16:50:14 +02:00
|
|
|
speed_str = get_word(&argument, ':');
|
|
|
|
|
|
|
|
|
|
autoneg = -1;
|
2021-08-17 12:00:37 -03:00
|
|
|
if (autoneg_str) {
|
|
|
|
|
autoneg = _nm_utils_ascii_str_to_bool(autoneg_str, -1);
|
2021-07-26 12:14:19 -03:00
|
|
|
if (autoneg == -1)
|
2021-09-16 16:50:15 +02:00
|
|
|
_LOGW(LOGD_CORE, "rd.ethtool: autoneg invalid. Must be boolean or empty");
|
2021-07-26 12:14:19 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 16:50:14 +02:00
|
|
|
speed = 0;
|
2021-08-17 12:00:37 -03:00
|
|
|
if (speed_str) {
|
2021-09-16 16:50:14 +02:00
|
|
|
speed = _nm_utils_ascii_str_to_int64(speed_str, 10, 0, G_MAXUINT32, 0);
|
|
|
|
|
if (errno)
|
2021-09-16 16:50:15 +02:00
|
|
|
_LOGW(LOGD_CORE, "rd.ethtool: speed invalid. Must be an integer or empty");
|
2021-07-26 12:14:19 -03:00
|
|
|
}
|
2021-08-17 12:00:37 -03:00
|
|
|
|
2021-09-16 16:50:15 +02:00
|
|
|
if (speed == 0 && autoneg == FALSE) {
|
|
|
|
|
_LOGW(LOGD_CORE,
|
|
|
|
|
"rd.ethtool: autoneg ignored. Cannot disable autoneg without setting speed");
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 16:50:14 +02:00
|
|
|
connection = reader_get_connection(reader, interface, NM_SETTING_WIRED_SETTING_NAME, TRUE);
|
|
|
|
|
|
2021-09-16 16:50:15 +02:00
|
|
|
if (autoneg != -1 || speed != 0) {
|
|
|
|
|
if (autoneg == -1)
|
|
|
|
|
autoneg = FALSE;
|
|
|
|
|
s_wired = nm_connection_get_setting_wired(connection);
|
|
|
|
|
g_object_set(s_wired,
|
|
|
|
|
NM_SETTING_WIRED_AUTO_NEGOTIATE,
|
|
|
|
|
(gboolean) autoneg,
|
|
|
|
|
NM_SETTING_WIRED_SPEED,
|
|
|
|
|
speed,
|
|
|
|
|
NM_SETTING_WIRED_DUPLEX,
|
|
|
|
|
speed == 0 ? NULL : "full",
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
2021-09-16 16:50:14 +02:00
|
|
|
|
|
|
|
|
if (*argument)
|
2021-09-16 16:50:15 +02:00
|
|
|
_LOGW(LOGD_CORE, "rd.ethtool: extra argument ignored");
|
2021-07-26 12:14:19 -03:00
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
static void
|
|
|
|
|
_normalize_conn(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
|
{
|
2023-07-13 10:18:33 +02:00
|
|
|
NMConnection *connection = value;
|
|
|
|
|
NMSettingIPConfig *s_ip4 = NULL, *s_ip6 = NULL;
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config(connection);
|
|
|
|
|
if (s_ip4) {
|
|
|
|
|
const char *method = nm_setting_ip_config_get_method(s_ip4);
|
|
|
|
|
|
|
|
|
|
if (!nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
|
|
|
|
|
g_object_set(s_ip4,
|
|
|
|
|
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME,
|
|
|
|
|
NULL,
|
|
|
|
|
NM_SETTING_IP_CONFIG_DHCP_TIMEOUT,
|
|
|
|
|
NULL,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config(connection);
|
|
|
|
|
if (s_ip6) {
|
|
|
|
|
const char *method = nm_setting_ip_config_get_method(s_ip6);
|
|
|
|
|
|
|
|
|
|
if (!nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
|
|
|
|
|
&& !nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) {
|
|
|
|
|
g_object_set(s_ip6,
|
|
|
|
|
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME,
|
|
|
|
|
NULL,
|
|
|
|
|
NM_SETTING_IP_CONFIG_DHCP_TIMEOUT,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
|
|
|
|
|
nm_connection_normalize(connection, NULL, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
static void
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_nameservers(Reader *reader, GPtrArray *nameservers)
|
2020-03-21 22:28:31 +01:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2020-03-21 22:28:31 +01:00
|
|
|
NMSettingIPConfig *s_ip;
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
int addr_family;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *ns;
|
2020-03-21 22:28:31 +01:00
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
for (i = 0; i < nameservers->len; i++) {
|
|
|
|
|
ns = nameservers->pdata[i];
|
2020-11-17 11:10:54 +01:00
|
|
|
addr_family = get_ip_address_family(ns, FALSE);
|
2020-03-21 22:28:31 +01:00
|
|
|
if (addr_family == AF_UNSPEC) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Unknown address family: %s", ns);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
g_hash_table_iter_init(&iter, reader->hash);
|
|
|
|
|
while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &connection)) {
|
|
|
|
|
switch (addr_family) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
s_ip = nm_connection_get_setting_ip4_config(connection);
|
|
|
|
|
if (!NM_IN_STRSET(nm_setting_ip_config_get_method(s_ip),
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
s_ip = nm_connection_get_setting_ip6_config(connection);
|
|
|
|
|
if (!NM_IN_STRSET(nm_setting_ip_config_get_method(s_ip),
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_DHCP,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
nm_assert_not_reached();
|
2020-03-27 11:47:35 +01:00
|
|
|
continue;
|
2020-03-21 22:28:31 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
nm_setting_ip_config_add_dns(s_ip, ns);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 16:57:41 +02:00
|
|
|
static void
|
|
|
|
|
connection_set_needed(NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
|
|
|
|
if (!nm_streq0(nm_setting_connection_get_connection_type(s_con), NM_SETTING_WIRED_SETTING_NAME))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_set(s_con,
|
2020-08-12 17:35:25 +02:00
|
|
|
NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT,
|
2021-07-05 09:48:54 +02:00
|
|
|
(int) NMI_WAIT_DEVICE_TIMEOUT_MSEC,
|
2020-08-05 16:57:41 +02:00
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
connection_set_needed_cb(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
connection_set_needed(value);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
GHashTable *
|
2021-11-02 15:27:17 +01:00
|
|
|
nmi_cmdline_reader_parse(const char *etc_connections_dir,
|
|
|
|
|
const char *sysfs_dir,
|
2021-01-18 03:15:14 +09:00
|
|
|
const char *const *argv,
|
2021-11-09 13:28:54 +01:00
|
|
|
char **hostname,
|
|
|
|
|
gint64 *carrier_timeout_sec)
|
2018-08-09 18:02:51 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
Reader *reader;
|
|
|
|
|
const char *tag;
|
|
|
|
|
gboolean ignore_bootif = FALSE;
|
|
|
|
|
gboolean neednet = FALSE;
|
|
|
|
|
gs_free char *bootif_val = NULL;
|
|
|
|
|
gs_free char *bootdev = NULL;
|
|
|
|
|
gboolean net_ifnames = TRUE;
|
|
|
|
|
gs_unref_ptrarray GPtrArray *nameservers = NULL;
|
|
|
|
|
gs_unref_ptrarray GPtrArray *routes = NULL;
|
|
|
|
|
gs_unref_ptrarray GPtrArray *znets = NULL;
|
2018-08-09 18:02:51 +02:00
|
|
|
int i;
|
2021-02-12 09:56:36 +01:00
|
|
|
guint64 dhcp_timeout = 90;
|
|
|
|
|
guint64 dhcp_num_tries = 1;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
reader = reader_new();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-10-22 16:56:38 +02:00
|
|
|
for (i = 0; argv[i]; i++) {
|
2020-05-04 09:57:51 +02:00
|
|
|
gs_free char *argument_clone = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *argument;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-04 09:57:51 +02:00
|
|
|
argument_clone = g_strdup(argv[i]);
|
|
|
|
|
argument = argument_clone;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-04 09:57:51 +02:00
|
|
|
tag = get_word(&argument, '=');
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-08-30 09:01:21 +02:00
|
|
|
if (!tag) {
|
|
|
|
|
/* pass */
|
|
|
|
|
} else if (nm_streq(tag, "net.ifnames"))
|
2020-06-03 17:55:30 +02:00
|
|
|
net_ifnames = !nm_streq(argument, "0");
|
|
|
|
|
else if (nm_streq(tag, "rd.peerdns"))
|
2020-05-04 09:57:51 +02:00
|
|
|
reader->ignore_auto_dns = !_nm_utils_ascii_str_to_bool(argument, TRUE);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "rd.net.timeout.dhcp")) {
|
2021-02-12 09:53:30 +01:00
|
|
|
if (nm_streq0(argument, "infinity")) {
|
2021-02-12 09:56:36 +01:00
|
|
|
dhcp_timeout = G_MAXINT32;
|
2021-02-12 09:53:30 +01:00
|
|
|
} else {
|
2021-02-12 09:56:36 +01:00
|
|
|
dhcp_timeout =
|
|
|
|
|
_nm_utils_ascii_str_to_int64(argument, 10, 1, G_MAXINT32, dhcp_timeout);
|
2021-02-12 09:53:30 +01:00
|
|
|
}
|
2021-02-12 09:56:36 +01:00
|
|
|
} else if (nm_streq(tag, "rd.net.dhcp.retry")) {
|
|
|
|
|
dhcp_num_tries =
|
|
|
|
|
_nm_utils_ascii_str_to_int64(argument, 10, 1, G_MAXINT32, dhcp_num_tries);
|
2020-08-27 17:43:54 +02:00
|
|
|
} else if (nm_streq(tag, "rd.net.dhcp.vendor-class")) {
|
|
|
|
|
if (nm_utils_validate_dhcp4_vendor_class_id(argument, NULL))
|
2021-07-30 09:04:53 +02:00
|
|
|
nm_strdup_reset(&reader->dhcp4_vci, argument);
|
2021-01-18 03:15:14 +09:00
|
|
|
} else if (nm_streq(tag, "rd.net.timeout.carrier")) {
|
|
|
|
|
reader->carrier_timeout_sec =
|
|
|
|
|
_nm_utils_ascii_str_to_int64(argument, 10, 0, G_MAXINT32, 0);
|
2020-05-04 10:26:21 +02:00
|
|
|
}
|
2019-10-22 16:56:38 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-02-12 09:56:36 +01:00
|
|
|
reader->dhcp_timeout = NM_CLAMP(dhcp_timeout * dhcp_num_tries, 1, G_MAXINT32);
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
for (i = 0; argv[i]; i++) {
|
2019-09-27 08:36:49 +02:00
|
|
|
gs_free char *argument_clone = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *argument;
|
|
|
|
|
char *word;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-09-27 08:36:49 +02:00
|
|
|
argument_clone = g_strdup(argv[i]);
|
|
|
|
|
argument = argument_clone;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
tag = get_word(&argument, '=');
|
2021-08-30 09:01:21 +02:00
|
|
|
if (!tag) {
|
|
|
|
|
/* pass */
|
|
|
|
|
} else if (nm_streq(tag, "ip"))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_ip(reader, sysfs_dir, argument);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "rd.route")) {
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!routes)
|
|
|
|
|
routes = g_ptr_array_new_with_free_func(g_free);
|
|
|
|
|
g_ptr_array_add(routes, g_strdup(argument));
|
2020-06-03 17:55:30 +02:00
|
|
|
} else if (nm_streq(tag, "bridge"))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_master(reader, argument, NM_SETTING_BRIDGE_SETTING_NAME, "br");
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "bond"))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_master(reader, argument, NM_SETTING_BOND_SETTING_NAME, NULL);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "team"))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_master(reader, argument, NM_SETTING_TEAM_SETTING_NAME, NULL);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "vlan"))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_parse_vlan(reader, argument);
|
2021-06-08 18:03:29 +02:00
|
|
|
else if (nm_streq(tag, "ib.pkey"))
|
|
|
|
|
reader_parse_ib_pkey(reader, argument);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "bootdev")) {
|
2020-03-21 22:28:31 +01:00
|
|
|
g_free(bootdev);
|
|
|
|
|
bootdev = g_strdup(argument);
|
2020-06-03 17:55:30 +02:00
|
|
|
} else if (nm_streq(tag, "nameserver")) {
|
2020-03-21 22:28:31 +01:00
|
|
|
word = get_word(&argument, '\0');
|
|
|
|
|
if (word) {
|
|
|
|
|
if (!nameservers)
|
|
|
|
|
nameservers = g_ptr_array_new_with_free_func(g_free);
|
|
|
|
|
g_ptr_array_add(nameservers, g_strdup(word));
|
|
|
|
|
}
|
|
|
|
|
if (argument && *argument)
|
|
|
|
|
_LOGW(LOGD_CORE, "Ignoring extra: '%s'.", argument);
|
2020-06-03 17:55:30 +02:00
|
|
|
} else if (nm_streq(tag, "rd.iscsi.ibft") && _nm_utils_ascii_str_to_bool(argument, TRUE))
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_read_all_connections_from_fw(reader, sysfs_dir);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "rd.bootif"))
|
2018-08-09 18:02:51 +02:00
|
|
|
ignore_bootif = !_nm_utils_ascii_str_to_bool(argument, TRUE);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "rd.neednet"))
|
2019-05-27 11:24:45 +02:00
|
|
|
neednet = _nm_utils_ascii_str_to_bool(argument, TRUE);
|
2020-06-03 17:55:30 +02:00
|
|
|
else if (nm_streq(tag, "rd.znet")) {
|
2020-05-27 12:01:21 +02:00
|
|
|
if (!znets)
|
|
|
|
|
znets = g_ptr_array_new_with_free_func(g_free);
|
|
|
|
|
g_ptr_array_add(znets, g_strdup(argument));
|
2022-01-24 22:42:07 +01:00
|
|
|
} else if (nm_streq(tag, "rd.znet_ifname")) {
|
|
|
|
|
reader_parse_znet_ifname(reader, argument);
|
2020-05-27 12:01:21 +02:00
|
|
|
} else if (g_ascii_strcasecmp(tag, "BOOTIF") == 0) {
|
2019-09-27 08:36:49 +02:00
|
|
|
nm_clear_g_free(&bootif_val);
|
|
|
|
|
bootif_val = g_strdup(argument);
|
2021-07-26 12:14:19 -03:00
|
|
|
} else if (nm_streq(tag, "rd.ethtool"))
|
|
|
|
|
reader_parse_ethtool(reader, argument);
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-18 14:27:19 +01:00
|
|
|
for (i = 0; i < reader->vlan_parents->len; i++) {
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2020-11-18 14:27:19 +01:00
|
|
|
NMSettingIPConfig *s_ip;
|
|
|
|
|
|
|
|
|
|
/* Disable IP configuration for parent connections of VLANs,
|
|
|
|
|
* unless those interfaces were explicitly configured otherwise. */
|
|
|
|
|
|
|
|
|
|
connection = reader_get_connection(reader, reader->vlan_parents->pdata[i], NULL, TRUE);
|
|
|
|
|
if (!g_hash_table_contains(reader->explicit_ip_connections, connection)) {
|
|
|
|
|
s_ip = nm_connection_get_setting_ip4_config(connection);
|
|
|
|
|
if (s_ip) {
|
|
|
|
|
g_object_set(s_ip,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s_ip = nm_connection_get_setting_ip6_config(connection);
|
|
|
|
|
if (s_ip) {
|
|
|
|
|
g_object_set(s_ip,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD_DISABLED,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
if (ignore_bootif)
|
2019-09-27 08:36:49 +02:00
|
|
|
nm_clear_g_free(&bootif_val);
|
|
|
|
|
if (bootif_val) {
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2018-08-09 18:02:51 +02:00
|
|
|
NMSettingWired *s_wired;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *bootif = bootif_val;
|
2020-12-23 14:21:21 +01:00
|
|
|
char prefix[4];
|
|
|
|
|
|
|
|
|
|
if (!nm_utils_hwaddr_valid(bootif, ETH_ALEN)) {
|
|
|
|
|
strncpy(prefix, bootif, 3);
|
|
|
|
|
prefix[3] = '\0';
|
|
|
|
|
|
|
|
|
|
if (NM_IN_STRSET(prefix, "01-", "01:", "00-", "00:")
|
|
|
|
|
&& nm_utils_hwaddr_valid(&bootif[3], ETH_ALEN)) {
|
|
|
|
|
/*
|
|
|
|
|
* BOOTIF MAC address can be prefixed with a hardware type identifier.
|
|
|
|
|
* "01" stays for "wired", "00" is also accepted as it means "undefined".
|
|
|
|
|
* No others are known.
|
|
|
|
|
*/
|
|
|
|
|
bootif += 3;
|
|
|
|
|
}
|
2019-07-02 15:56:38 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, NULL, NM_SETTING_WIRED_SETTING_NAME, FALSE);
|
2020-03-21 22:28:31 +01:00
|
|
|
if (!connection)
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_default_connection(reader);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-09 18:02:51 +02:00
|
|
|
s_wired = nm_connection_get_setting_wired(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-03-26 07:26:55 +01:00
|
|
|
if (nm_connection_get_interface_name(connection)
|
|
|
|
|
|| (nm_setting_wired_get_mac_address(s_wired)
|
|
|
|
|
&& !nm_utils_hwaddr_matches(nm_setting_wired_get_mac_address(s_wired),
|
|
|
|
|
-1,
|
|
|
|
|
bootif,
|
|
|
|
|
-1))) {
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_create_connection(reader,
|
|
|
|
|
"bootif_connection",
|
|
|
|
|
"BOOTIF Connection",
|
|
|
|
|
NULL,
|
2020-09-22 17:54:18 +02:00
|
|
|
bootif,
|
2020-03-25 10:17:03 +01:00
|
|
|
NM_SETTING_WIRED_SETTING_NAME,
|
2022-09-12 11:33:46 +02:00
|
|
|
NMI_AUTOCONNECT_PRIORITY_FIRMWARE,
|
2020-03-25 10:17:03 +01:00
|
|
|
NM_CONNECTION_MULTI_CONNECT_SINGLE);
|
2020-09-22 17:54:18 +02:00
|
|
|
} else {
|
|
|
|
|
g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, bootif, NULL);
|
2019-11-11 11:23:53 +01:00
|
|
|
}
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (bootdev) {
|
|
|
|
|
NMConnection *connection;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-25 10:17:03 +01:00
|
|
|
connection = reader_get_connection(reader, bootdev, NULL, TRUE);
|
2020-03-21 22:28:31 +01:00
|
|
|
reader->bootdev_connection = connection;
|
2020-08-05 16:57:41 +02:00
|
|
|
connection_set_needed(connection);
|
2020-03-21 22:28:31 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-08-05 16:57:41 +02:00
|
|
|
if (neednet) {
|
2021-11-02 15:27:17 +01:00
|
|
|
if (!(etc_connections_dir && g_file_test(etc_connections_dir, G_FILE_TEST_IS_DIR))
|
|
|
|
|
&& g_hash_table_size(reader->hash) == 0) {
|
2020-08-05 16:57:41 +02:00
|
|
|
/* Make sure there's some connection. */
|
|
|
|
|
reader_get_default_connection(reader);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-08-05 16:57:41 +02:00
|
|
|
g_hash_table_foreach(reader->hash, connection_set_needed_cb, NULL);
|
2019-05-27 11:24:45 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (routes)
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_routes(reader, routes);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-21 22:28:31 +01:00
|
|
|
if (nameservers)
|
2020-03-25 10:17:03 +01:00
|
|
|
reader_add_nameservers(reader, nameservers);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-27 12:01:21 +02:00
|
|
|
if (znets) {
|
|
|
|
|
for (i = 0; i < znets->len; i++)
|
|
|
|
|
reader_parse_rd_znet(reader, znets->pdata[i], net_ifnames);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2022-01-24 22:42:07 +01:00
|
|
|
if (g_hash_table_size(reader->znet_ifnames)) {
|
|
|
|
|
_LOGW(LOGD_CORE, "Mismatch between rd.znet_ifname and rd.znet");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
g_hash_table_foreach(reader->hash, _normalize_conn, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-05-04 10:03:21 +02:00
|
|
|
NM_SET_OUT(hostname, g_steal_pointer(&reader->hostname));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-01-18 03:15:14 +09:00
|
|
|
NM_SET_OUT(carrier_timeout_sec, reader->carrier_timeout_sec);
|
|
|
|
|
|
2020-03-21 09:57:57 +01:00
|
|
|
return reader_destroy(reader, FALSE);
|
2018-08-09 18:02:51 +02:00
|
|
|
}
|