mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-03 21:48:21 +02:00
all: merge branch 'af/settings-add-matches'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/431
This commit is contained in:
commit
20f5d8877b
16 changed files with 747 additions and 98 deletions
|
|
@ -3430,35 +3430,6 @@ _objlist_set_fcn_ip_config_routing_rules (NMSetting *setting,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gconstpointer
|
||||
_get_fcn_match_interface_name (ARGS_GET_FCN)
|
||||
{
|
||||
NMSettingMatch *s_match = NM_SETTING_MATCH (setting);
|
||||
GString *str = NULL;
|
||||
guint i, num;
|
||||
|
||||
RETURN_UNSUPPORTED_GET_TYPE ();
|
||||
|
||||
num = nm_setting_match_get_num_interface_names (s_match);
|
||||
for (i = 0; i < num; i++) {
|
||||
const char *name;
|
||||
|
||||
name = nm_setting_match_get_interface_name (s_match, i);
|
||||
if (!name || !name[0])
|
||||
continue;
|
||||
if (!str)
|
||||
str = g_string_new ("");
|
||||
else
|
||||
g_string_append_c (str, ESCAPED_TOKENS_WITH_SPACES_DELIMTER);
|
||||
nm_utils_escaped_tokens_escape_gstr (name, ESCAPED_TOKENS_WITH_SPACES_DELIMTERS, str);
|
||||
}
|
||||
|
||||
NM_SET_OUT (out_is_default, num == 0);
|
||||
if (!str)
|
||||
return NULL;
|
||||
RETURN_STR_TO_FREE (g_string_free (str, FALSE));
|
||||
}
|
||||
|
||||
static gconstpointer
|
||||
_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
|
||||
{
|
||||
|
|
@ -6194,11 +6165,7 @@ static const NMMetaPropertyInfo *const property_infos_MACVLAN[] = {
|
|||
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MATCH
|
||||
static const NMMetaPropertyInfo *const property_infos_MATCH[] = {
|
||||
PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_INTERFACE_NAME,
|
||||
.property_type = DEFINE_PROPERTY_TYPE (
|
||||
.get_fcn = _get_fcn_match_interface_name,
|
||||
.set_fcn = _set_fcn_multilist,
|
||||
.set_supports_remove = TRUE,
|
||||
),
|
||||
.property_type = &_pt_multilist,
|
||||
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (
|
||||
PROPERTY_TYP_DATA_SUBTYPE (multilist,
|
||||
.get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_interface_names),
|
||||
|
|
@ -6209,6 +6176,30 @@ static const NMMetaPropertyInfo *const property_infos_MATCH[] = {
|
|||
),
|
||||
),
|
||||
),
|
||||
PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_KERNEL_COMMAND_LINE,
|
||||
.property_type = &_pt_multilist,
|
||||
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (
|
||||
PROPERTY_TYP_DATA_SUBTYPE (multilist,
|
||||
.get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_kernel_command_lines),
|
||||
.add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_kernel_command_line),
|
||||
.remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_kernel_command_line),
|
||||
.remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_kernel_command_line_by_value),
|
||||
.strsplit_with_spaces = TRUE,
|
||||
),
|
||||
),
|
||||
),
|
||||
PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_DRIVER,
|
||||
.property_type = &_pt_multilist,
|
||||
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (
|
||||
PROPERTY_TYP_DATA_SUBTYPE (multilist,
|
||||
.get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_drivers),
|
||||
.add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_driver),
|
||||
.remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_driver),
|
||||
.remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_driver_by_value),
|
||||
.strsplit_with_spaces = TRUE,
|
||||
),
|
||||
),
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -280,7 +280,9 @@
|
|||
#define DESCRIBE_DOC_NM_SETTING_MACVLAN_PARENT N_("If given, specifies the parent interface name or parent connection UUID from which this MAC-VLAN interface should be created. If this property is not specified, the connection must contain an \"802-3-ethernet\" setting with a \"mac-address\" property.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_MACVLAN_PROMISCUOUS N_("Whether the interface should be put in promiscuous mode.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_MACVLAN_TAP N_("Whether the interface should be a MACVTAP.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_MATCH_DRIVER N_("A list of driver names to match. Each element is a shell wildcard pattern. When an element is prefixed with exclamation mark (!) the condition is inverted. A candidate driver name is considered matching when both these conditions are satisfied: (a) any of the elements not prefixed with '!' matches or there aren't such elements; (b) none of the elements prefixed with '!' match.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_MATCH_INTERFACE_NAME N_("A list of interface names to match. Each element is a shell wildcard pattern. When an element is prefixed with exclamation mark (!) the condition is inverted. A candidate interface name is considered matching when both these conditions are satisfied: (a) any of the elements not prefixed with '!' matches or there aren't such elements; (b) none of the elements prefixed with '!' match.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_MATCH_KERNEL_COMMAND_LINE N_("A list of kernel command line arguments to match. This may be used to check whether a specific kernel command line option is set (or if prefixed with the exclamation mark unset). The argument must either be a single word, or an assignment (i.e. two words, separated \"=\"). In the former case the kernel command line is searched for the word appearing as is, or as left hand side of an assignment. In the latter case, the exact assignment is looked for with right and left hand side matching.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_DATAPATH_TYPE N_("The data path type. One of \"system\", \"netdev\" or empty.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_FAIL_MODE N_("The bridge failure mode. One of \"secure\", \"standalone\" or empty.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE N_("Enable or disable multicast snooping.")
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
NM_GOBJECT_PROPERTIES_DEFINE (NMSettingMatch,
|
||||
PROP_INTERFACE_NAME,
|
||||
PROP_KERNEL_COMMAND_LINE,
|
||||
PROP_DRIVER,
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +33,9 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingMatch,
|
|||
*/
|
||||
struct _NMSettingMatch {
|
||||
NMSetting parent;
|
||||
GPtrArray *interface_name;
|
||||
GArray *interface_name;
|
||||
GArray *kernel_command_line;
|
||||
GArray *driver;
|
||||
};
|
||||
|
||||
struct _NMSettingMatchClass {
|
||||
|
|
@ -55,7 +59,7 @@ nm_setting_match_get_num_interface_names (NMSettingMatch *setting)
|
|||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0);
|
||||
|
||||
return setting->interface_name->len;
|
||||
return nm_g_array_len (setting->interface_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,9 +76,9 @@ nm_setting_match_get_interface_name (NMSettingMatch *setting, int idx)
|
|||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
|
||||
g_return_val_if_fail (idx >= 0 && idx < setting->interface_name->len, NULL);
|
||||
g_return_val_if_fail (setting->interface_name && idx >= 0 && idx < setting->interface_name->len, NULL);
|
||||
|
||||
return setting->interface_name->pdata[idx];
|
||||
return g_array_index (setting->interface_name, const char *, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,7 +98,7 @@ nm_setting_match_add_interface_name (NMSettingMatch *setting,
|
|||
g_return_if_fail (interface_name != NULL);
|
||||
g_return_if_fail (interface_name[0] != '\0');
|
||||
|
||||
g_ptr_array_add (setting->interface_name, g_strdup (interface_name));
|
||||
nm_strvarray_add (nm_strvarray_ensure (&setting->interface_name), interface_name);
|
||||
_notify (setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
|
||||
|
|
@ -112,9 +116,9 @@ nm_setting_match_remove_interface_name (NMSettingMatch *setting, int idx)
|
|||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
g_return_if_fail (idx >= 0 && idx < setting->interface_name->len);
|
||||
g_return_if_fail (setting->interface_name && idx >= 0 && idx < setting->interface_name->len);
|
||||
|
||||
g_ptr_array_remove_index (setting->interface_name, idx);
|
||||
g_array_remove_index (setting->interface_name, idx);
|
||||
_notify (setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
|
||||
|
|
@ -139,9 +143,12 @@ nm_setting_match_remove_interface_name_by_value (NMSettingMatch *setting,
|
|||
g_return_val_if_fail (interface_name != NULL, FALSE);
|
||||
g_return_val_if_fail (interface_name[0] != '\0', FALSE);
|
||||
|
||||
if (!setting->interface_name)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < setting->interface_name->len; i++) {
|
||||
if (nm_streq (interface_name, setting->interface_name->pdata[i])) {
|
||||
g_ptr_array_remove_index (setting->interface_name, i);
|
||||
if (nm_streq (interface_name, g_array_index (setting->interface_name, const char *, i))) {
|
||||
g_array_remove_index (setting->interface_name, i);
|
||||
_notify (setting, PROP_INTERFACE_NAME);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -162,8 +169,8 @@ nm_setting_match_clear_interface_names (NMSettingMatch *setting)
|
|||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
if (setting->interface_name->len != 0) {
|
||||
g_ptr_array_set_size (setting->interface_name, 0);
|
||||
if (nm_g_array_len (setting->interface_name) != 0) {
|
||||
nm_clear_pointer (&setting->interface_name, g_array_unref);
|
||||
_notify (setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,11 +178,14 @@ nm_setting_match_clear_interface_names (NMSettingMatch *setting)
|
|||
/**
|
||||
* nm_setting_match_get_interface_names:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @length: (out): the length of the returned interface names array.
|
||||
* @length: (out) (allow-none): the length of the returned interface names array.
|
||||
*
|
||||
* Returns all the interface names.
|
||||
*
|
||||
* Returns: (transfer none) (array length=length): the configured interface names.
|
||||
* Returns: (transfer none) (array length=length): the NULL terminated list of
|
||||
* configured interface names.
|
||||
*
|
||||
* Before 1.26, the returned array was not %NULL terminated and you MUST provide a length.
|
||||
*
|
||||
* Since: 1.14
|
||||
**/
|
||||
|
|
@ -183,10 +193,308 @@ const char *const *
|
|||
nm_setting_match_get_interface_names (NMSettingMatch *setting, guint *length)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
g_return_val_if_fail (length, NULL);
|
||||
|
||||
NM_SET_OUT (length, setting->interface_name->len);
|
||||
return (const char *const *) setting->interface_name->pdata;
|
||||
return nm_strvarray_get_strv (&setting->interface_name, length);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_num_kernel_command_lines:
|
||||
* @setting: the #NMSettingMatch
|
||||
*
|
||||
* Returns: the number of configured kernel command line arguments
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
guint
|
||||
nm_setting_match_get_num_kernel_command_lines (NMSettingMatch *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0);
|
||||
|
||||
return nm_g_array_len (setting->kernel_command_line);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_kernel_command_line:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @idx: index number of the kernel command line argument to return
|
||||
*
|
||||
* Returns: the kernel command line argument at index @idx
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
const char *
|
||||
nm_setting_match_get_kernel_command_line (NMSettingMatch *setting, guint idx)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
|
||||
g_return_val_if_fail (setting->kernel_command_line && idx < setting->kernel_command_line->len, NULL);
|
||||
|
||||
return g_array_index (setting->kernel_command_line, const char *, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_add_kernel_command_line:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @kernel_command_line: the kernel command line argument to add
|
||||
*
|
||||
* Adds a new kernel command line argument to the setting.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_add_kernel_command_line (NMSettingMatch *setting,
|
||||
const char *kernel_command_line)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
g_return_if_fail (kernel_command_line != NULL);
|
||||
g_return_if_fail (kernel_command_line[0] != '\0');
|
||||
|
||||
nm_strvarray_add (nm_strvarray_ensure (&setting->kernel_command_line), kernel_command_line);
|
||||
_notify (setting, PROP_KERNEL_COMMAND_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_remove_kernel_command_line:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @idx: index number of the kernel command line argument
|
||||
*
|
||||
* Removes the kernel command line argument at index @idx.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_remove_kernel_command_line (NMSettingMatch *setting, guint idx)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
g_return_if_fail (setting->kernel_command_line && idx < setting->kernel_command_line->len);
|
||||
|
||||
g_array_remove_index (setting->kernel_command_line, idx);
|
||||
_notify (setting, PROP_KERNEL_COMMAND_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_remove_kernel_command_line_by_value:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @kernel_command_line: the kernel command line argument name to remove
|
||||
*
|
||||
* Removes @kernel_command_line.
|
||||
*
|
||||
* Returns: %TRUE if the kernel command line argument was found and removed; %FALSE if it was not.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_match_remove_kernel_command_line_by_value (NMSettingMatch *setting,
|
||||
const char *kernel_command_line)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE);
|
||||
g_return_val_if_fail (kernel_command_line != NULL, FALSE);
|
||||
g_return_val_if_fail (kernel_command_line[0] != '\0', FALSE);
|
||||
|
||||
if (!setting->kernel_command_line)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < setting->kernel_command_line->len; i++) {
|
||||
if (nm_streq (kernel_command_line, g_array_index (setting->kernel_command_line, const char *, i))) {
|
||||
g_array_remove_index (setting->kernel_command_line, i);
|
||||
_notify (setting, PROP_KERNEL_COMMAND_LINE);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_clear_kernel_command_lines:
|
||||
* @setting: the #NMSettingMatch
|
||||
*
|
||||
* Removes all configured kernel command line arguments.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_clear_kernel_command_lines (NMSettingMatch *setting)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
if (nm_g_array_len (setting->kernel_command_line) != 0) {
|
||||
nm_clear_pointer (&setting->kernel_command_line, g_array_unref);
|
||||
_notify (setting, PROP_KERNEL_COMMAND_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_kernel_command_lines:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @length: (out) (allow-none): the length of the returned interface names array.
|
||||
*
|
||||
* Returns all the interface names.
|
||||
*
|
||||
* Returns: (transfer none) (array length=length): the configured interface names.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
const char *const *
|
||||
nm_setting_match_get_kernel_command_lines (NMSettingMatch *setting, guint *length)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
|
||||
return nm_strvarray_get_strv (&setting->kernel_command_line, length);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_num_drivers:
|
||||
* @setting: the #NMSettingMatch
|
||||
*
|
||||
* Returns: the number of configured drivers
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
guint
|
||||
nm_setting_match_get_num_drivers (NMSettingMatch *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0);
|
||||
|
||||
return nm_g_array_len (setting->driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_driver:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @idx: index number of the DNS search domain to return
|
||||
*
|
||||
* Returns: the driver at index @idx
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
const char *
|
||||
nm_setting_match_get_driver (NMSettingMatch *setting, guint idx)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
|
||||
g_return_val_if_fail (setting->driver && idx < setting->driver->len, NULL);
|
||||
|
||||
return g_array_index (setting->driver, const char *, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_add_driver:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @driver: the driver to add
|
||||
*
|
||||
* Adds a new driver to the setting.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_add_driver (NMSettingMatch *setting,
|
||||
const char *driver)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
g_return_if_fail (driver != NULL);
|
||||
g_return_if_fail (driver[0] != '\0');
|
||||
|
||||
nm_strvarray_add (nm_strvarray_ensure (&setting->driver), driver);
|
||||
_notify (setting, PROP_DRIVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_remove_driver:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @idx: index number of the driver
|
||||
*
|
||||
* Removes the driver at index @idx.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_remove_driver (NMSettingMatch *setting, guint idx)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
g_return_if_fail (setting->driver && idx < setting->driver->len);
|
||||
|
||||
g_array_remove_index (setting->driver, idx);
|
||||
_notify (setting, PROP_DRIVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_remove_driver_by_value:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @driver: the driver to remove
|
||||
*
|
||||
* Removes @driver.
|
||||
*
|
||||
* Returns: %TRUE if the driver was found and removed; %FALSE if it was not.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_match_remove_driver_by_value (NMSettingMatch *setting,
|
||||
const char *driver)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE);
|
||||
g_return_val_if_fail (driver != NULL, FALSE);
|
||||
g_return_val_if_fail (driver[0] != '\0', FALSE);
|
||||
|
||||
if (!setting->driver)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < setting->driver->len; i++) {
|
||||
if (nm_streq (driver, g_array_index (setting->driver, const char *, i))) {
|
||||
g_array_remove_index (setting->driver, i);
|
||||
_notify (setting, PROP_DRIVER);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_clear_drivers:
|
||||
* @setting: the #NMSettingMatch
|
||||
*
|
||||
* Removes all configured drivers.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
nm_setting_match_clear_drivers (NMSettingMatch *setting)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING_MATCH (setting));
|
||||
|
||||
if (nm_g_array_len (setting->driver) != 0) {
|
||||
nm_clear_pointer (&setting->driver, g_array_unref);
|
||||
_notify (setting, PROP_DRIVER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_match_get_drivers:
|
||||
* @setting: the #NMSettingMatch
|
||||
* @length: (out) (allow-none): the length of the returned interface names array.
|
||||
*
|
||||
* Returns all the drivers.
|
||||
*
|
||||
* Returns: (transfer none) (array length=length): the configured drivers.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
const char *const *
|
||||
nm_setting_match_get_drivers (NMSettingMatch *setting, guint *length)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL);
|
||||
|
||||
return nm_strvarray_get_strv (&setting->driver, length);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -199,7 +507,13 @@ get_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_INTERFACE_NAME:
|
||||
g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (self->interface_name));
|
||||
g_value_set_boxed (value, nm_strvarray_get_strv (&self->interface_name, NULL));
|
||||
break;
|
||||
case PROP_KERNEL_COMMAND_LINE:
|
||||
g_value_set_boxed (value, nm_strvarray_get_strv (&self->kernel_command_line, NULL));
|
||||
break;
|
||||
case PROP_DRIVER:
|
||||
g_value_set_boxed (value, nm_strvarray_get_strv (&self->driver, NULL));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
|
@ -215,8 +529,13 @@ set_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_INTERFACE_NAME:
|
||||
g_ptr_array_unref (self->interface_name);
|
||||
self->interface_name = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
|
||||
nm_strvarray_set_strv (&self->interface_name, g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_KERNEL_COMMAND_LINE:
|
||||
nm_strvarray_set_strv (&self->kernel_command_line, g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_DRIVER:
|
||||
nm_strvarray_set_strv (&self->driver, g_value_get_boxed (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
|
@ -229,7 +548,6 @@ set_property (GObject *object, guint prop_id,
|
|||
static void
|
||||
nm_setting_match_init (NMSettingMatch *setting)
|
||||
{
|
||||
setting->interface_name = g_ptr_array_new_with_free_func (g_free);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -247,12 +565,65 @@ nm_setting_match_new (void)
|
|||
return (NMSetting *) g_object_new (NM_TYPE_SETTING_MATCH, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify (NMSetting *setting, NMConnection *connection, GError **error)
|
||||
{
|
||||
NMSettingMatch *self = NM_SETTING_MATCH (setting);
|
||||
guint i;
|
||||
|
||||
if (self->interface_name) {
|
||||
for (i = 0; i < self->interface_name->len; i++) {
|
||||
if (!nm_str_not_empty (g_array_index (self->interface_name, const char *, i))) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("is empty"));
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME,
|
||||
NM_SETTING_MATCH_INTERFACE_NAME);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self->kernel_command_line) {
|
||||
for (i = 0; i < self->kernel_command_line->len; i++) {
|
||||
if (!nm_str_not_empty (g_array_index (self->kernel_command_line, const char *, i))) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("is empty"));
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME,
|
||||
NM_SETTING_MATCH_KERNEL_COMMAND_LINE);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self->driver) {
|
||||
for (i = 0; i < self->driver->len; i++) {
|
||||
if (!nm_str_not_empty (g_array_index (self->driver, const char *, i))) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("is empty"));
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME,
|
||||
NM_SETTING_MATCH_DRIVER);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMSettingMatch *self = NM_SETTING_MATCH (object);
|
||||
|
||||
g_ptr_array_unref (self->interface_name);
|
||||
nm_clear_pointer (&self->interface_name, g_array_unref);
|
||||
nm_clear_pointer (&self->kernel_command_line, g_array_unref);
|
||||
nm_clear_pointer (&self->driver, g_array_unref);
|
||||
|
||||
G_OBJECT_CLASS (nm_setting_match_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -267,6 +638,8 @@ nm_setting_match_class_init (NMSettingMatchClass *klass)
|
|||
object_class->set_property = set_property;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
setting_class->verify = verify;
|
||||
|
||||
/**
|
||||
* NMSettingMatch:interface-name
|
||||
*
|
||||
|
|
@ -288,6 +661,45 @@ nm_setting_match_class_init (NMSettingMatchClass *klass)
|
|||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* NMSettingMatch:kernel-command-line
|
||||
*
|
||||
* A list of kernel command line arguments to match. This may be used to check
|
||||
* whether a specific kernel command line option is set (or if prefixed with
|
||||
* the exclamation mark unset). The argument must either be a single word, or
|
||||
* an assignment (i.e. two words, separated "="). In the former case the kernel
|
||||
* command line is searched for the word appearing as is, or as left hand side
|
||||
* of an assignment. In the latter case, the exact assignment is looked for
|
||||
* with right and left hand side matching.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
obj_properties[PROP_KERNEL_COMMAND_LINE] =
|
||||
g_param_spec_boxed (NM_SETTING_MATCH_KERNEL_COMMAND_LINE, "", "",
|
||||
G_TYPE_STRV,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE |
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* NMSettingMatch:driver
|
||||
*
|
||||
* A list of driver names to match. Each element is a shell wildcard pattern.
|
||||
* When an element is prefixed with exclamation mark (!) the condition is
|
||||
* inverted. A candidate driver name is considered matching when both these
|
||||
* conditions are satisfied: (a) any of the elements not prefixed with '!'
|
||||
* matches or there aren't such elements; (b) none of the elements prefixed
|
||||
* with '!' match.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
obj_properties[PROP_DRIVER] =
|
||||
g_param_spec_boxed (NM_SETTING_MATCH_DRIVER, "", "",
|
||||
G_TYPE_STRV,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE |
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
_nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_MATCH);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ G_BEGIN_DECLS
|
|||
#define NM_SETTING_MATCH_SETTING_NAME "match"
|
||||
|
||||
#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name"
|
||||
#define NM_SETTING_MATCH_KERNEL_COMMAND_LINE "kernel-command-line"
|
||||
#define NM_SETTING_MATCH_DRIVER "driver"
|
||||
|
||||
typedef struct _NMSettingMatchClass NMSettingMatchClass;
|
||||
|
||||
|
|
@ -49,6 +51,43 @@ NM_AVAILABLE_IN_1_14
|
|||
void nm_setting_match_clear_interface_names (NMSettingMatch *setting);
|
||||
NM_AVAILABLE_IN_1_14
|
||||
const char *const *nm_setting_match_get_interface_names (NMSettingMatch *setting, guint *length);
|
||||
|
||||
|
||||
NM_AVAILABLE_IN_1_26
|
||||
guint nm_setting_match_get_num_kernel_command_lines (NMSettingMatch *setting);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
const char *nm_setting_match_get_kernel_command_line (NMSettingMatch *setting, guint idx);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_remove_kernel_command_line (NMSettingMatch *setting, guint idx);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
gboolean nm_setting_match_remove_kernel_command_line_by_value (NMSettingMatch *setting,
|
||||
const char *kernel_command_line);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_add_kernel_command_line (NMSettingMatch *setting,
|
||||
const char *kernel_command_line);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_clear_kernel_command_lines (NMSettingMatch *setting);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
const char *const *nm_setting_match_get_kernel_command_lines (NMSettingMatch *setting, guint *length);
|
||||
|
||||
|
||||
NM_AVAILABLE_IN_1_26
|
||||
guint nm_setting_match_get_num_drivers (NMSettingMatch *setting);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
const char *nm_setting_match_get_driver (NMSettingMatch *setting, guint idx);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_remove_driver (NMSettingMatch *setting, guint idx);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
gboolean nm_setting_match_remove_driver_by_value (NMSettingMatch *setting,
|
||||
const char *driver);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_add_driver (NMSettingMatch *setting,
|
||||
const char *driver);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
void nm_setting_match_clear_drivers (NMSettingMatch *setting);
|
||||
NM_AVAILABLE_IN_1_26
|
||||
const char *const *nm_setting_match_get_drivers (NMSettingMatch *setting, guint *length);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_SETTING_MATCH_H */
|
||||
|
|
|
|||
|
|
@ -1708,4 +1708,18 @@ global:
|
|||
nm_setting_bridge_get_multicast_startup_query_count;
|
||||
nm_setting_bridge_get_multicast_startup_query_interval;
|
||||
nm_setting_connection_get_mud_url;
|
||||
nm_setting_match_add_driver;
|
||||
nm_setting_match_add_kernel_command_line;
|
||||
nm_setting_match_clear_drivers;
|
||||
nm_setting_match_clear_kernel_command_lines;
|
||||
nm_setting_match_get_driver;
|
||||
nm_setting_match_get_drivers;
|
||||
nm_setting_match_get_kernel_command_line;
|
||||
nm_setting_match_get_kernel_command_lines;
|
||||
nm_setting_match_get_num_drivers;
|
||||
nm_setting_match_get_num_kernel_command_lines;
|
||||
nm_setting_match_remove_driver;
|
||||
nm_setting_match_remove_driver_by_value;
|
||||
nm_setting_match_remove_kernel_command_line;
|
||||
nm_setting_match_remove_kernel_command_line_by_value;
|
||||
} libnm_1_24_0;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ libnm-core/nm-setting-ip4-config.c
|
|||
libnm-core/nm-setting-ip6-config.c
|
||||
libnm-core/nm-setting-macsec.c
|
||||
libnm-core/nm-setting-macvlan.c
|
||||
libnm-core/nm-setting-match.c
|
||||
libnm-core/nm-setting-olpc-mesh.c
|
||||
libnm-core/nm-setting-ovs-bridge.c
|
||||
libnm-core/nm-setting-ovs-interface.c
|
||||
|
|
|
|||
|
|
@ -4817,3 +4817,23 @@ nm_str_buf_append_printf (NMStrBuf *strbuf,
|
|||
|
||||
strbuf->_priv_len += (gsize) l;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_indirect_g_free:
|
||||
* @arg: a pointer to a pointer that is to be freed.
|
||||
*
|
||||
* This does the same as nm_clear_g_free(arg) (g_clear_pointer (arg, g_free)).
|
||||
* This is for example useful when you have a GArray with pointers and a
|
||||
* clear function to free them. g_array_set_clear_func()'s destroy notify
|
||||
* function gets a pointer to the array location, so we have to follow
|
||||
* the first pointer.
|
||||
*/
|
||||
void
|
||||
nm_indirect_g_free (gpointer arg)
|
||||
{
|
||||
gpointer *p = arg;
|
||||
|
||||
nm_clear_g_free (p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1435,6 +1435,22 @@ char *nm_utils_g_slist_strlist_join (const GSList *a, const char *separator);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint
|
||||
nm_g_array_len (const GArray *arr)
|
||||
{
|
||||
return arr ? arr->len : 0u;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint
|
||||
nm_g_ptr_array_len (const GPtrArray *arr)
|
||||
{
|
||||
return arr ? arr->len : 0u;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint
|
||||
nm_g_hash_table_size (GHashTable *hash)
|
||||
{
|
||||
|
|
@ -1848,6 +1864,8 @@ nm_utils_strdup_reset (char **dst, const char *src)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void nm_indirect_g_free (gpointer arg);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* nm_utils_get_next_realloc_size() is used to grow buffers exponentially, when
|
||||
|
|
@ -1887,4 +1905,52 @@ gboolean nm_utils_ifname_valid (const char* name,
|
|||
NMUtilsIfaceType type,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline GArray *
|
||||
nm_strvarray_ensure (GArray **p)
|
||||
{
|
||||
if (!*p) {
|
||||
*p = g_array_new (TRUE, FALSE, sizeof (char *));
|
||||
g_array_set_clear_func (*p, nm_indirect_g_free);
|
||||
}
|
||||
return *p;
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_strvarray_add (GArray *array, const char *str)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = g_strdup (str);
|
||||
g_array_append_val (array, s);
|
||||
}
|
||||
|
||||
static inline const char *const*
|
||||
nm_strvarray_get_strv (GArray **arr, guint *length)
|
||||
{
|
||||
if (!*arr) {
|
||||
NM_SET_OUT (length, 0);
|
||||
return (const char *const*) arr;
|
||||
}
|
||||
|
||||
NM_SET_OUT (length, (*arr)->len);
|
||||
return &g_array_index (*arr, const char *, 0);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_strvarray_set_strv (GArray **array, const char *const*strv)
|
||||
{
|
||||
gs_unref_array GArray *array_old = NULL;
|
||||
|
||||
array_old = g_steal_pointer (array);
|
||||
|
||||
if (!strv || !strv[0])
|
||||
return;
|
||||
|
||||
nm_strvarray_ensure (array);
|
||||
for (; strv[0]; strv++)
|
||||
nm_strvarray_add (*array, strv[0]);
|
||||
}
|
||||
|
||||
#endif /* __NM_SHARED_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -5999,7 +5999,6 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError **
|
|||
gs_free_error GError *local = NULL;
|
||||
gs_free char *conn_iface = NULL;
|
||||
NMDeviceClass *klass;
|
||||
const char *const *patterns;
|
||||
NMSettingMatch *s_match;
|
||||
|
||||
klass = NM_DEVICE_GET_CLASS (self);
|
||||
|
|
@ -6042,6 +6041,8 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError **
|
|||
s_match = (NMSettingMatch *) nm_connection_get_setting (connection,
|
||||
NM_TYPE_SETTING_MATCH);
|
||||
if (s_match) {
|
||||
const char *const *patterns;
|
||||
const char *device_driver;
|
||||
guint num_patterns = 0;
|
||||
|
||||
patterns = nm_setting_match_get_interface_names (s_match, &num_patterns);
|
||||
|
|
@ -6050,6 +6051,72 @@ check_connection_compatible (NMDevice *self, NMConnection *connection, GError **
|
|||
"device does not satisfy match.interface-name property");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
{
|
||||
const char *const*proc_cmdline;
|
||||
gboolean pos_patterns = FALSE;
|
||||
guint i;
|
||||
|
||||
patterns = nm_setting_match_get_kernel_command_lines (s_match, &num_patterns);
|
||||
proc_cmdline = nm_utils_proc_cmdline_split ();
|
||||
|
||||
for (i = 0; i < num_patterns; i++) {
|
||||
const char *patterns_i = patterns[i];
|
||||
const char *const*proc_cmdline_i;
|
||||
gboolean negative = FALSE;
|
||||
gboolean found = FALSE;
|
||||
const char *equal;
|
||||
|
||||
if (patterns_i[0] == '!') {
|
||||
++patterns_i;
|
||||
negative = TRUE;
|
||||
} else
|
||||
pos_patterns = TRUE;
|
||||
|
||||
equal = strchr (patterns_i, '=');
|
||||
|
||||
proc_cmdline_i = proc_cmdline;
|
||||
while (*proc_cmdline_i) {
|
||||
if (equal) {
|
||||
/* if pattern contains = compare full key=value */
|
||||
found = nm_streq (*proc_cmdline_i, patterns_i);
|
||||
} else {
|
||||
gsize l = strlen (patterns_i);
|
||||
|
||||
/* otherwise consider pattern as key only */
|
||||
if ( strncmp (*proc_cmdline_i, patterns_i, l) == 0
|
||||
&& NM_IN_SET ((*proc_cmdline_i)[l], '\0', '='))
|
||||
found = TRUE;
|
||||
}
|
||||
if ( found
|
||||
&& negative) {
|
||||
/* first negative match */
|
||||
nm_utils_error_set (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
||||
"device does not satisfy match.kernel-command-line property %s",
|
||||
patterns[i]);
|
||||
return FALSE;
|
||||
}
|
||||
proc_cmdline_i++;
|
||||
}
|
||||
|
||||
if ( pos_patterns
|
||||
&& !found) {
|
||||
/* positive patterns configured but no match */
|
||||
nm_utils_error_set (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
||||
"device does not satisfy any match.kernel-command-line property %s...",
|
||||
patterns[0]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
device_driver = nm_device_get_driver (self);
|
||||
patterns = nm_setting_match_get_drivers (s_match, &num_patterns);
|
||||
if (!nm_wildcard_match_check (device_driver, patterns, num_patterns)) {
|
||||
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
||||
"device does not satisfy match.driver property");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -1703,11 +1703,13 @@ nm_wildcard_match_check (const char *str,
|
|||
const char *const *patterns,
|
||||
guint num_patterns)
|
||||
{
|
||||
guint i, neg = 0;
|
||||
gsize i, neg = 0;
|
||||
|
||||
for (i = 0; i < num_patterns; i++) {
|
||||
if (patterns[i][0] == '!') {
|
||||
neg++;
|
||||
if (!str)
|
||||
continue;
|
||||
if (!fnmatch (patterns[i] + 1, str, 0))
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -1716,10 +1718,12 @@ nm_wildcard_match_check (const char *str,
|
|||
if (neg == num_patterns)
|
||||
return TRUE;
|
||||
|
||||
for (i = 0; i < num_patterns; i++) {
|
||||
if ( patterns[i][0] != '!'
|
||||
&& !fnmatch (patterns[i], str, 0))
|
||||
return TRUE;
|
||||
if (str) {
|
||||
for (i = 0; i < num_patterns; i++) {
|
||||
if ( patterns[i][0] != '!'
|
||||
&& !fnmatch (patterns[i], str, 0))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -1537,29 +1537,42 @@ make_user_setting (shvarFile *ifcfg)
|
|||
: NULL;
|
||||
}
|
||||
|
||||
static NMSetting *
|
||||
make_match_setting (shvarFile *ifcfg)
|
||||
{
|
||||
NMSettingMatch *s_match = NULL;
|
||||
gs_free const char **strv = NULL;
|
||||
gs_free char *value = NULL;
|
||||
const char *v;
|
||||
gsize i;
|
||||
|
||||
v = svGetValueStr (ifcfg, "MATCH_INTERFACE_NAME", &value);
|
||||
if (!v)
|
||||
return NULL;
|
||||
static void
|
||||
make_match_setting_prop (const char *v,
|
||||
NMSettingMatch **s_match,
|
||||
void (*add_fcn) (NMSettingMatch *s_match, const char *value))
|
||||
{
|
||||
gs_free const char **strv = NULL;
|
||||
gsize i;
|
||||
|
||||
strv = nm_utils_escaped_tokens_split (v, NM_ASCII_SPACES);
|
||||
if (strv) {
|
||||
for (i = 0; strv[i]; i++) {
|
||||
if (!s_match)
|
||||
s_match = (NMSettingMatch *) nm_setting_match_new ();
|
||||
nm_setting_match_add_interface_name (s_match, strv[i]);
|
||||
if (!(*s_match))
|
||||
*s_match = NM_SETTING_MATCH (nm_setting_match_new ());
|
||||
add_fcn (*s_match, strv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (NMSetting *) s_match;
|
||||
static NMSetting *
|
||||
make_match_setting (shvarFile *ifcfg)
|
||||
{
|
||||
NMSettingMatch *s_match = NULL;
|
||||
gs_free char *value_ifn = NULL;
|
||||
gs_free char *value_kcl = NULL;
|
||||
gs_free char *value_d = NULL;
|
||||
const char *v;
|
||||
|
||||
v = svGetValueStr (ifcfg, "MATCH_INTERFACE_NAME", &value_ifn);
|
||||
make_match_setting_prop(v, &s_match, nm_setting_match_add_interface_name);
|
||||
v = svGetValueStr (ifcfg, "MATCH_KERNEL_COMMAND_LINE", &value_kcl);
|
||||
make_match_setting_prop(v, &s_match, nm_setting_match_add_kernel_command_line);
|
||||
v = svGetValueStr (ifcfg, "MATCH_DRIVER", &value_d);
|
||||
make_match_setting_prop(v, &s_match, nm_setting_match_add_driver);
|
||||
|
||||
return NM_SETTING (s_match);
|
||||
}
|
||||
|
||||
static NMSetting *
|
||||
|
|
|
|||
|
|
@ -888,7 +888,9 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = {
|
|||
_KEY_TYPE ("MAC_ADDRESS_RANDOMIZATION", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MASTER", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MASTER_UUID", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MATCH_DRIVER", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MATCH_INTERFACE_NAME", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MATCH_KERNEL_COMMAND_LINE", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("MDNS", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
_KEY_TYPE ("METRIC", NMS_IFCFG_KEY_TYPE_IS_NUMBERED ),
|
||||
_KEY_TYPE ("MODE", NMS_IFCFG_KEY_TYPE_IS_PLAIN ),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
NMSIfcfgKeyTypeFlags key_flags;
|
||||
} NMSIfcfgKeyTypeInfo;
|
||||
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[233];
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[235];
|
||||
|
||||
const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info (const char *key, gssize *out_idx);
|
||||
|
||||
|
|
|
|||
|
|
@ -2374,36 +2374,50 @@ write_tc_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_match_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
||||
static void
|
||||
write_match_setting (NMConnection *connection, shvarFile *ifcfg)
|
||||
{
|
||||
NMSettingMatch *s_match;
|
||||
nm_auto_free_gstring GString *str = NULL;
|
||||
NMSettingMatch *s_match;
|
||||
guint i, num;
|
||||
const char *name;
|
||||
|
||||
s_match = (NMSettingMatch *) nm_connection_get_setting (connection, NM_TYPE_SETTING_MATCH);
|
||||
if (!s_match)
|
||||
return TRUE;
|
||||
return;
|
||||
|
||||
num = nm_setting_match_get_num_interface_names (s_match);
|
||||
for (i = 0; i < num; i++) {
|
||||
const char *name;
|
||||
|
||||
name = nm_setting_match_get_interface_name (s_match, i);
|
||||
if (!name || !name[0])
|
||||
continue;
|
||||
|
||||
if (!str)
|
||||
str = g_string_new ("");
|
||||
else
|
||||
g_string_append_c (str, ' ');
|
||||
nm_utils_escaped_tokens_escape_gstr (name, NM_ASCII_SPACES, str);
|
||||
num = nm_setting_match_get_num_drivers (s_match);
|
||||
if (num > 0) {
|
||||
nm_gstring_prepare (&str);
|
||||
for (i = 0; i < num; i++) {
|
||||
name = nm_setting_match_get_driver (s_match, i);
|
||||
nm_gstring_add_space_delimiter (str);
|
||||
nm_utils_escaped_tokens_escape_gstr (name, NM_ASCII_SPACES, str);
|
||||
}
|
||||
svSetValueStr (ifcfg, "MATCH_DRIVER", str->str);
|
||||
}
|
||||
|
||||
if (str)
|
||||
num = nm_setting_match_get_num_interface_names (s_match);
|
||||
if (num > 0) {
|
||||
nm_gstring_prepare (&str);
|
||||
for (i = 0; i < num; i++) {
|
||||
name = nm_setting_match_get_interface_name (s_match, i);
|
||||
nm_gstring_add_space_delimiter (str);
|
||||
nm_utils_escaped_tokens_escape_gstr (name, NM_ASCII_SPACES, str);
|
||||
}
|
||||
svSetValueStr (ifcfg, "MATCH_INTERFACE_NAME", str->str);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
num = nm_setting_match_get_num_kernel_command_lines (s_match);
|
||||
if (num > 0) {
|
||||
nm_gstring_prepare (&str);
|
||||
for (i = 0; i < num; i++) {
|
||||
name = nm_setting_match_get_kernel_command_line (s_match, i);
|
||||
nm_gstring_add_space_delimiter (str);
|
||||
nm_utils_escaped_tokens_escape_gstr (name, NM_ASCII_SPACES, str);
|
||||
}
|
||||
svSetValueStr (ifcfg, "MATCH_KERNEL_COMMAND_LINE", str->str);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -3163,8 +3177,7 @@ do_write_construct (NMConnection *connection,
|
|||
if (!write_user_setting (connection, ifcfg, error))
|
||||
return FALSE;
|
||||
|
||||
if (!write_match_setting (connection, ifcfg, error))
|
||||
return FALSE;
|
||||
write_match_setting (connection, ifcfg);
|
||||
|
||||
write_sriov_setting (connection, ifcfg);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
TYPE=Ethernet
|
||||
PROXY_METHOD=none
|
||||
BROWSER_ONLY=no
|
||||
MATCH_DRIVER="!virtio e1000e"
|
||||
MATCH_INTERFACE_NAME="ens* eth\\ 1? !veth*"
|
||||
MATCH_KERNEL_COMMAND_LINE=!ip=
|
||||
BOOTPROTO=dhcp
|
||||
DEFROUTE=yes
|
||||
IPV4_FAILURE_FATAL=no
|
||||
|
|
|
|||
|
|
@ -4687,6 +4687,9 @@ test_write_wired_match (void)
|
|||
nm_setting_match_add_interface_name (s_match, "ens*");
|
||||
nm_setting_match_add_interface_name (s_match, "eth 1?");
|
||||
nm_setting_match_add_interface_name (s_match, "!veth*");
|
||||
nm_setting_match_add_driver (s_match, "!virtio");
|
||||
nm_setting_match_add_driver (s_match, "e1000e");
|
||||
nm_setting_match_add_kernel_command_line (s_match, "!ip=");
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_match));
|
||||
|
||||
nmtst_assert_connection_verifies (connection);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue