mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
all: add 'match' setting
Add a new 'match' setting containing properties to match a connection to devices. At the moment only the interface-name property is present and, contrary to connection.interface-name, it allows the use of wildcards.
This commit is contained in:
parent
6a51d393b2
commit
9b9dce9486
|
@ -463,6 +463,7 @@ libnm_core_lib_h_pub_real = \
|
||||||
libnm-core/nm-setting-ip6-config.h \
|
libnm-core/nm-setting-ip6-config.h \
|
||||||
libnm-core/nm-setting-macsec.h \
|
libnm-core/nm-setting-macsec.h \
|
||||||
libnm-core/nm-setting-macvlan.h \
|
libnm-core/nm-setting-macvlan.h \
|
||||||
|
libnm-core/nm-setting-match.h \
|
||||||
libnm-core/nm-setting-olpc-mesh.h \
|
libnm-core/nm-setting-olpc-mesh.h \
|
||||||
libnm-core/nm-setting-ovs-bridge.h \
|
libnm-core/nm-setting-ovs-bridge.h \
|
||||||
libnm-core/nm-setting-ovs-interface.h \
|
libnm-core/nm-setting-ovs-interface.h \
|
||||||
|
@ -536,6 +537,7 @@ libnm_core_lib_c_settings_real = \
|
||||||
libnm-core/nm-setting-ip6-config.c \
|
libnm-core/nm-setting-ip6-config.c \
|
||||||
libnm-core/nm-setting-macsec.c \
|
libnm-core/nm-setting-macsec.c \
|
||||||
libnm-core/nm-setting-macvlan.c \
|
libnm-core/nm-setting-macvlan.c \
|
||||||
|
libnm-core/nm-setting-match.c \
|
||||||
libnm-core/nm-setting-olpc-mesh.c \
|
libnm-core/nm-setting-olpc-mesh.c \
|
||||||
libnm-core/nm-setting-ovs-bridge.c \
|
libnm-core/nm-setting-ovs-bridge.c \
|
||||||
libnm-core/nm-setting-ovs-interface.c \
|
libnm-core/nm-setting-ovs-interface.c \
|
||||||
|
|
|
@ -734,6 +734,7 @@ const NmcMetaGenericInfo *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CO
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\
|
#define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\
|
||||||
|
NM_SETTING_MATCH_SETTING_NAME","\
|
||||||
NM_SETTING_WIRED_SETTING_NAME","\
|
NM_SETTING_WIRED_SETTING_NAME","\
|
||||||
NM_SETTING_802_1X_SETTING_NAME","\
|
NM_SETTING_802_1X_SETTING_NAME","\
|
||||||
NM_SETTING_WIRELESS_SETTING_NAME","\
|
NM_SETTING_WIRELESS_SETTING_NAME","\
|
||||||
|
|
|
@ -3730,6 +3730,68 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_routes,
|
||||||
nm_setting_ip_config_remove_route,
|
nm_setting_ip_config_remove_route,
|
||||||
_validate_and_remove_ipv6_route)
|
_validate_and_remove_ipv6_route)
|
||||||
|
|
||||||
|
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;
|
||||||
|
gs_free char *to_free = NULL;
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
str = g_string_new ("");
|
||||||
|
else
|
||||||
|
g_string_append_c (str, ' ');
|
||||||
|
name = nm_setting_match_get_interface_name (s_match, i);
|
||||||
|
g_string_append (str, _nm_utils_escape_spaces (name, &to_free));
|
||||||
|
}
|
||||||
|
RETURN_STR_TO_FREE (g_string_free (str, FALSE));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_set_fcn_match_interface_name (ARGS_SET_FCN)
|
||||||
|
{
|
||||||
|
gs_free const char **strv = NULL;
|
||||||
|
gsize i;
|
||||||
|
|
||||||
|
nm_assert (!error || !*error);
|
||||||
|
|
||||||
|
strv = nm_utils_strsplit_set (value, " \t", TRUE);
|
||||||
|
if (strv) {
|
||||||
|
for (i = 0; strv[i]; i++) {
|
||||||
|
nm_setting_match_add_interface_name (NM_SETTING_MATCH (setting),
|
||||||
|
_nm_utils_unescape_spaces ((char *) strv[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_validate_and_remove_match_interface_name (NMSettingMatch *setting,
|
||||||
|
const char *interface_name,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
ret = nm_setting_match_remove_interface_name_by_value (setting, interface_name);
|
||||||
|
if (!ret)
|
||||||
|
g_set_error (error, 1, 0,
|
||||||
|
_("the property doesn't contain interface name '%s'"),
|
||||||
|
interface_name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_match_interface_name,
|
||||||
|
NM_SETTING_MATCH,
|
||||||
|
nm_setting_match_get_num_interface_names,
|
||||||
|
nm_setting_match_remove_interface_name,
|
||||||
|
_validate_and_remove_match_interface_name)
|
||||||
|
|
||||||
static gconstpointer
|
static gconstpointer
|
||||||
_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
|
_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
|
||||||
{
|
{
|
||||||
|
@ -6532,6 +6594,19 @@ static const NMMetaPropertyInfo *const property_infos_MACVLAN[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef _CURRENT_NM_META_SETTING_TYPE
|
||||||
|
#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_match_interface_name,
|
||||||
|
.remove_fcn = _remove_fcn_match_interface_name,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#undef _CURRENT_NM_META_SETTING_TYPE
|
#undef _CURRENT_NM_META_SETTING_TYPE
|
||||||
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OLPC_MESH
|
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OLPC_MESH
|
||||||
static const NMMetaPropertyInfo *const property_infos_OLPC_MESH[] = {
|
static const NMMetaPropertyInfo *const property_infos_OLPC_MESH[] = {
|
||||||
|
@ -7900,6 +7975,7 @@ _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN)
|
||||||
#define SETTING_PRETTY_NAME_IP_TUNNEL N_("IP-tunnel settings")
|
#define SETTING_PRETTY_NAME_IP_TUNNEL N_("IP-tunnel settings")
|
||||||
#define SETTING_PRETTY_NAME_MACSEC N_("MACsec connection")
|
#define SETTING_PRETTY_NAME_MACSEC N_("MACsec connection")
|
||||||
#define SETTING_PRETTY_NAME_MACVLAN N_("macvlan connection")
|
#define SETTING_PRETTY_NAME_MACVLAN N_("macvlan connection")
|
||||||
|
#define SETTING_PRETTY_NAME_MATCH N_("Match")
|
||||||
#define SETTING_PRETTY_NAME_OLPC_MESH N_("OLPC Mesh connection")
|
#define SETTING_PRETTY_NAME_OLPC_MESH N_("OLPC Mesh connection")
|
||||||
#define SETTING_PRETTY_NAME_OVS_BRIDGE N_("OpenVSwitch bridge settings")
|
#define SETTING_PRETTY_NAME_OVS_BRIDGE N_("OpenVSwitch bridge settings")
|
||||||
#define SETTING_PRETTY_NAME_OVS_INTERFACE N_("OpenVSwitch interface settings")
|
#define SETTING_PRETTY_NAME_OVS_INTERFACE N_("OpenVSwitch interface settings")
|
||||||
|
@ -8066,6 +8142,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
|
||||||
NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE),
|
NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SETTING_INFO (MATCH),
|
||||||
SETTING_INFO (OLPC_MESH,
|
SETTING_INFO (OLPC_MESH,
|
||||||
.alias = "olpc-mesh",
|
.alias = "olpc-mesh",
|
||||||
.valid_parts = NM_META_SETTING_VALID_PARTS (
|
.valid_parts = NM_META_SETTING_VALID_PARTS (
|
||||||
|
@ -8209,6 +8286,7 @@ const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static const NMMetaSettingValidPartItem *const valid_settings_noslave[] = {
|
static const NMMetaSettingValidPartItem *const valid_settings_noslave[] = {
|
||||||
|
NM_META_SETTING_VALID_PART_ITEM (MATCH, FALSE),
|
||||||
NM_META_SETTING_VALID_PART_ITEM (IP4_CONFIG, FALSE),
|
NM_META_SETTING_VALID_PART_ITEM (IP4_CONFIG, FALSE),
|
||||||
NM_META_SETTING_VALID_PART_ITEM (IP6_CONFIG, FALSE),
|
NM_META_SETTING_VALID_PART_ITEM (IP6_CONFIG, FALSE),
|
||||||
NM_META_SETTING_VALID_PART_ITEM (TC_CONFIG, FALSE),
|
NM_META_SETTING_VALID_PART_ITEM (TC_CONFIG, FALSE),
|
||||||
|
|
|
@ -249,6 +249,7 @@
|
||||||
#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_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_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_MACVLAN_TAP N_("Whether the interface should be a MACVTAP.")
|
||||||
|
#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_OVS_BRIDGE_FAIL_MODE N_("The bridge failure mode. One of \"secure\", \"standalone\" 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.")
|
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE N_("Enable or disable multicast snooping.")
|
||||||
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_RSTP_ENABLE N_("Enable or disable RSTP.")
|
#define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_RSTP_ENABLE N_("Enable or disable RSTP.")
|
||||||
|
|
|
@ -212,6 +212,7 @@ print ("NetworkManager version " + client.get_version())]]></programlisting></in
|
||||||
<xi:include href="xml/nm-setting-ip-tunnel.xml"/>
|
<xi:include href="xml/nm-setting-ip-tunnel.xml"/>
|
||||||
<xi:include href="xml/nm-setting-macsec.xml"/>
|
<xi:include href="xml/nm-setting-macsec.xml"/>
|
||||||
<xi:include href="xml/nm-setting-macvlan.xml"/>
|
<xi:include href="xml/nm-setting-macvlan.xml"/>
|
||||||
|
<xi:include href="xml/nm-setting-match.xml"/>
|
||||||
<xi:include href="xml/nm-setting-olpc-mesh.xml"/>
|
<xi:include href="xml/nm-setting-olpc-mesh.xml"/>
|
||||||
<xi:include href="xml/nm-setting-ovs-bridge.xml"/>
|
<xi:include href="xml/nm-setting-ovs-bridge.xml"/>
|
||||||
<xi:include href="xml/nm-setting-ovs-interface.xml"/>
|
<xi:include href="xml/nm-setting-ovs-interface.xml"/>
|
||||||
|
|
|
@ -25,6 +25,7 @@ libnm_core_headers = files(
|
||||||
'nm-setting-ip6-config.h',
|
'nm-setting-ip6-config.h',
|
||||||
'nm-setting-macsec.h',
|
'nm-setting-macsec.h',
|
||||||
'nm-setting-macvlan.h',
|
'nm-setting-macvlan.h',
|
||||||
|
'nm-setting-match.h',
|
||||||
'nm-setting-olpc-mesh.h',
|
'nm-setting-olpc-mesh.h',
|
||||||
'nm-setting-ovs-bridge.h',
|
'nm-setting-ovs-bridge.h',
|
||||||
'nm-setting-ovs-interface.h',
|
'nm-setting-ovs-interface.h',
|
||||||
|
@ -79,6 +80,7 @@ libnm_core_settings_sources = files(
|
||||||
'nm-setting-ip6-config.c',
|
'nm-setting-ip6-config.c',
|
||||||
'nm-setting-macsec.c',
|
'nm-setting-macsec.c',
|
||||||
'nm-setting-macvlan.c',
|
'nm-setting-macvlan.c',
|
||||||
|
'nm-setting-match.c',
|
||||||
'nm-setting-olpc-mesh.c',
|
'nm-setting-olpc-mesh.c',
|
||||||
'nm-setting-ovs-bridge.c',
|
'nm-setting-ovs-bridge.c',
|
||||||
'nm-setting-ovs-interface.c',
|
'nm-setting-ovs-interface.c',
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "nm-setting-ip6-config.h"
|
#include "nm-setting-ip6-config.h"
|
||||||
#include "nm-setting-macsec.h"
|
#include "nm-setting-macsec.h"
|
||||||
#include "nm-setting-macvlan.h"
|
#include "nm-setting-macvlan.h"
|
||||||
|
#include "nm-setting-match.h"
|
||||||
#include "nm-setting-olpc-mesh.h"
|
#include "nm-setting-olpc-mesh.h"
|
||||||
#include "nm-setting-ovs-bridge.h"
|
#include "nm-setting-ovs-bridge.h"
|
||||||
#include "nm-setting-ovs-interface.h"
|
#include "nm-setting-ovs-interface.h"
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct _NMSettingIP4Config NMSettingIP4Config;
|
||||||
typedef struct _NMSettingIP6Config NMSettingIP6Config;
|
typedef struct _NMSettingIP6Config NMSettingIP6Config;
|
||||||
typedef struct _NMSettingMacsec NMSettingMacsec;
|
typedef struct _NMSettingMacsec NMSettingMacsec;
|
||||||
typedef struct _NMSettingMacvlan NMSettingMacvlan;
|
typedef struct _NMSettingMacvlan NMSettingMacvlan;
|
||||||
|
typedef struct _NMSettingMatch NMSettingMatch;
|
||||||
typedef struct _NMSettingOlpcMesh NMSettingOlpcMesh;
|
typedef struct _NMSettingOlpcMesh NMSettingOlpcMesh;
|
||||||
typedef struct _NMSettingOvsBridge NMSettingOvsBridge;
|
typedef struct _NMSettingOvsBridge NMSettingOvsBridge;
|
||||||
typedef struct _NMSettingOvsInterface NMSettingOvsInterface;
|
typedef struct _NMSettingOvsInterface NMSettingOvsInterface;
|
||||||
|
|
295
libnm-core/nm-setting-match.c
Normal file
295
libnm-core/nm-setting-match.c
Normal file
|
@ -0,0 +1,295 @@
|
||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this program. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Copyright 2018 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nm-default.h"
|
||||||
|
|
||||||
|
#include "nm-setting-match.h"
|
||||||
|
#include "nm-setting-private.h"
|
||||||
|
#include "nm-utils-private.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:nm-setting-match
|
||||||
|
* @short_description: Properties to match a connection with a device.
|
||||||
|
* @include: nm-setting-match.h
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NMSettingMatch:
|
||||||
|
*
|
||||||
|
* Match settings.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
*/
|
||||||
|
struct _NMSettingMatch {
|
||||||
|
NMSetting parent;
|
||||||
|
GPtrArray *interface_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _NMSettingMatchClass {
|
||||||
|
NMSettingClass parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (NMSettingMatch, nm_setting_match, NM_TYPE_SETTING)
|
||||||
|
|
||||||
|
NM_GOBJECT_PROPERTIES_DEFINE (NMSettingMatch,
|
||||||
|
PROP_INTERFACE_NAME,
|
||||||
|
);
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_get_num_interface_names:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
*
|
||||||
|
* Returns: the number of configured interface names
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
guint
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_get_interface_name:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
* @idx: index number of the DNS search domain to return
|
||||||
|
*
|
||||||
|
* Returns: the interface name at index @idx
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
const char *
|
||||||
|
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);
|
||||||
|
|
||||||
|
return setting->interface_name->pdata[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_add_interface_name:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
* @interface_name: the interface name to add
|
||||||
|
*
|
||||||
|
* Adds a new interface name to the setting.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
nm_setting_match_add_interface_name (NMSettingMatch *setting,
|
||||||
|
const char *interface_name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (NM_IS_SETTING_MATCH (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));
|
||||||
|
_notify (setting, PROP_INTERFACE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_remove_interface_name:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
* @idx: index number of the interface name
|
||||||
|
*
|
||||||
|
* Removes the interface name at index @idx.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
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_ptr_array_remove_index (setting->interface_name, idx);
|
||||||
|
_notify (setting, PROP_INTERFACE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_remove_interface_name_by_value:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
* @interface_name: the interface name to remove
|
||||||
|
*
|
||||||
|
* Removes @interface_name.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the interface name was found and removed; %FALSE if it was not.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
gboolean
|
||||||
|
nm_setting_match_remove_interface_name_by_value (NMSettingMatch *setting,
|
||||||
|
const char *interface_name)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE);
|
||||||
|
g_return_val_if_fail (interface_name != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (interface_name[0] != '\0', 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);
|
||||||
|
_notify (setting, PROP_INTERFACE_NAME);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_clear_interface_names:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
*
|
||||||
|
* Removes all configured interface names.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
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);
|
||||||
|
_notify (setting, PROP_INTERFACE_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_get_interface_names:
|
||||||
|
* @setting: the #NMSettingMatch
|
||||||
|
*
|
||||||
|
* Returns all the interface names.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the configured interface names.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_property (GObject *object, guint prop_id,
|
||||||
|
GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
NMSettingMatch *self = NM_SETTING_MATCH (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_INTERFACE_NAME:
|
||||||
|
g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (self->interface_name));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_property (GObject *object, guint prop_id,
|
||||||
|
const GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
NMSettingMatch *self = NM_SETTING_MATCH (object);
|
||||||
|
|
||||||
|
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));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_setting_match_init (NMSettingMatch *setting)
|
||||||
|
{
|
||||||
|
setting->interface_name = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_setting_match_new:
|
||||||
|
*
|
||||||
|
* Creates a new #NMSettingMatch object with default values.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the new empty #NMSettingMatch object
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
NMSetting *
|
||||||
|
nm_setting_match_new (void)
|
||||||
|
{
|
||||||
|
return (NMSetting *) g_object_new (NM_TYPE_SETTING_MATCH, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
finalize (GObject *object)
|
||||||
|
{
|
||||||
|
NMSettingMatch *self = NM_SETTING_MATCH (object);
|
||||||
|
|
||||||
|
g_ptr_array_unref (self->interface_name);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (nm_setting_match_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_setting_match_class_init (NMSettingMatchClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
|
||||||
|
|
||||||
|
object_class->finalize = finalize;
|
||||||
|
object_class->get_property = get_property;
|
||||||
|
object_class->set_property = set_property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NMSettingMatch:interface-name
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Since: 1.14
|
||||||
|
**/
|
||||||
|
obj_properties[PROP_INTERFACE_NAME] =
|
||||||
|
g_param_spec_boxed (NM_SETTING_MATCH_INTERFACE_NAME, "", "",
|
||||||
|
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);
|
||||||
|
}
|
63
libnm-core/nm-setting-match.h
Normal file
63
libnm-core/nm-setting-match.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this program. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Copyright 2018 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NM_SETTING_MATCH_H
|
||||||
|
#define NM_SETTING_MATCH_H
|
||||||
|
|
||||||
|
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
|
||||||
|
#error "Only <NetworkManager.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "nm-setting.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define NM_TYPE_SETTING_MATCH (nm_setting_match_get_type ())
|
||||||
|
#define NM_SETTING_MATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_MATCH, NMSettingMatch))
|
||||||
|
#define NM_SETTING_MATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_MATCH, NMSettingMatchClass))
|
||||||
|
#define NM_IS_SETTING_MATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_MATCH))
|
||||||
|
#define NM_IS_SETTING_MATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_MATCH))
|
||||||
|
#define NM_SETTING_MATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_MATCH, NMSettingMatchClass))
|
||||||
|
|
||||||
|
#define NM_SETTING_MATCH_SETTING_NAME "match"
|
||||||
|
|
||||||
|
#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name"
|
||||||
|
|
||||||
|
typedef struct _NMSettingMatchClass NMSettingMatchClass;
|
||||||
|
|
||||||
|
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
GType nm_setting_match_get_type (void);
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
NMSetting *nm_setting_match_new (void);
|
||||||
|
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
guint nm_setting_match_get_num_interface_names (NMSettingMatch *setting);
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
const char *nm_setting_match_get_interface_name (NMSettingMatch *setting, int idx);
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
void nm_setting_match_remove_interface_name (NMSettingMatch *setting, int idx);
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
gboolean nm_setting_match_remove_interface_name_by_value (NMSettingMatch *setting,
|
||||||
|
const char *interface_name);
|
||||||
|
NM_AVAILABLE_IN_1_14
|
||||||
|
void nm_setting_match_add_interface_name (NMSettingMatch *setting,
|
||||||
|
const char *interface_name);
|
||||||
|
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);
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* NM_SETTING_MATCH_H */
|
|
@ -82,6 +82,7 @@
|
||||||
#include "nm-setting-ip-tunnel.h"
|
#include "nm-setting-ip-tunnel.h"
|
||||||
#include "nm-setting-macsec.h"
|
#include "nm-setting-macsec.h"
|
||||||
#include "nm-setting-macvlan.h"
|
#include "nm-setting-macvlan.h"
|
||||||
|
#include "nm-setting-match.h"
|
||||||
#include "nm-setting-olpc-mesh.h"
|
#include "nm-setting-olpc-mesh.h"
|
||||||
#include "nm-setting-ovs-bridge.h"
|
#include "nm-setting-ovs-bridge.h"
|
||||||
#include "nm-setting-ovs-interface.h"
|
#include "nm-setting-ovs-interface.h"
|
||||||
|
|
|
@ -1399,6 +1399,14 @@ global:
|
||||||
nm_setting_ethtool_get_type;
|
nm_setting_ethtool_get_type;
|
||||||
nm_setting_ethtool_new;
|
nm_setting_ethtool_new;
|
||||||
nm_setting_ethtool_set_feature;
|
nm_setting_ethtool_set_feature;
|
||||||
|
nm_setting_match_add_interface_name;
|
||||||
|
nm_setting_match_clear_interface_names;
|
||||||
|
nm_setting_match_get_interface_name;
|
||||||
|
nm_setting_match_get_interface_names;
|
||||||
|
nm_setting_match_get_num_interface_names;
|
||||||
|
nm_setting_match_get_type;
|
||||||
|
nm_setting_match_remove_interface_name;
|
||||||
|
nm_setting_match_remove_interface_name_by_value;
|
||||||
nm_setting_sriov_add_vf;
|
nm_setting_sriov_add_vf;
|
||||||
nm_setting_sriov_clear_vfs;
|
nm_setting_sriov_clear_vfs;
|
||||||
nm_setting_sriov_get_autoprobe_drivers;
|
nm_setting_sriov_get_autoprobe_drivers;
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "nm-setting-ip-tunnel.h"
|
#include "nm-setting-ip-tunnel.h"
|
||||||
#include "nm-setting-macsec.h"
|
#include "nm-setting-macsec.h"
|
||||||
#include "nm-setting-macvlan.h"
|
#include "nm-setting-macvlan.h"
|
||||||
|
#include "nm-setting-match.h"
|
||||||
#include "nm-setting-olpc-mesh.h"
|
#include "nm-setting-olpc-mesh.h"
|
||||||
#include "nm-setting-ovs-bridge.h"
|
#include "nm-setting-ovs-bridge.h"
|
||||||
#include "nm-setting-ovs-interface.h"
|
#include "nm-setting-ovs-interface.h"
|
||||||
|
@ -268,6 +269,12 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = {
|
||||||
.setting_name = NM_SETTING_MACVLAN_SETTING_NAME,
|
.setting_name = NM_SETTING_MACVLAN_SETTING_NAME,
|
||||||
.get_setting_gtype = nm_setting_macvlan_get_type,
|
.get_setting_gtype = nm_setting_macvlan_get_type,
|
||||||
},
|
},
|
||||||
|
[NM_META_SETTING_TYPE_MATCH] = {
|
||||||
|
.meta_type = NM_META_SETTING_TYPE_MATCH,
|
||||||
|
.setting_priority = NM_SETTING_PRIORITY_AUX,
|
||||||
|
.setting_name = NM_SETTING_MATCH_SETTING_NAME,
|
||||||
|
.get_setting_gtype = nm_setting_match_get_type,
|
||||||
|
},
|
||||||
[NM_META_SETTING_TYPE_OLPC_MESH] = {
|
[NM_META_SETTING_TYPE_OLPC_MESH] = {
|
||||||
.meta_type = NM_META_SETTING_TYPE_OLPC_MESH,
|
.meta_type = NM_META_SETTING_TYPE_OLPC_MESH,
|
||||||
.setting_priority = NM_SETTING_PRIORITY_HW_BASE,
|
.setting_priority = NM_SETTING_PRIORITY_HW_BASE,
|
||||||
|
|
|
@ -127,6 +127,7 @@ typedef enum {
|
||||||
NM_META_SETTING_TYPE_IP6_CONFIG,
|
NM_META_SETTING_TYPE_IP6_CONFIG,
|
||||||
NM_META_SETTING_TYPE_MACSEC,
|
NM_META_SETTING_TYPE_MACSEC,
|
||||||
NM_META_SETTING_TYPE_MACVLAN,
|
NM_META_SETTING_TYPE_MACVLAN,
|
||||||
|
NM_META_SETTING_TYPE_MATCH,
|
||||||
NM_META_SETTING_TYPE_OVS_BRIDGE,
|
NM_META_SETTING_TYPE_OVS_BRIDGE,
|
||||||
NM_META_SETTING_TYPE_OVS_INTERFACE,
|
NM_META_SETTING_TYPE_OVS_INTERFACE,
|
||||||
NM_META_SETTING_TYPE_OVS_PATCH,
|
NM_META_SETTING_TYPE_OVS_PATCH,
|
||||||
|
|
Loading…
Reference in a new issue