libnm-core,cli: add VRF setting

Add new VRF setting and connection types to libnm-core and support
them in nmcli.
This commit is contained in:
Beniamino Galvani 2019-12-05 10:13:34 +01:00
parent 56e91b11a2
commit f4ced16791
17 changed files with 268 additions and 7 deletions

View file

@ -918,6 +918,7 @@ libnm_core_lib_h_pub_real = \
libnm-core/nm-setting-user.h \
libnm-core/nm-setting-vlan.h \
libnm-core/nm-setting-vpn.h \
libnm-core/nm-setting-vrf.h \
libnm-core/nm-setting-vxlan.h \
libnm-core/nm-setting-wifi-p2p.h \
libnm-core/nm-setting-wimax.h \
@ -990,6 +991,7 @@ libnm_core_lib_c_settings_real = \
libnm-core/nm-setting-user.c \
libnm-core/nm-setting-vlan.c \
libnm-core/nm-setting-vpn.c \
libnm-core/nm-setting-vrf.c \
libnm-core/nm-setting-vxlan.c \
libnm-core/nm-setting-wifi-p2p.c \
libnm-core/nm-setting-wimax.c \

View file

@ -855,6 +855,7 @@ const NmcMetaGenericInfo *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CO
NM_SETTING_MACSEC_SETTING_NAME"," \
NM_SETTING_MACVLAN_SETTING_NAME"," \
NM_SETTING_VXLAN_SETTING_NAME"," \
NM_SETTING_VRF_SETTING_NAME"," \
NM_SETTING_WPAN_SETTING_NAME","\
NM_SETTING_6LOWPAN_SETTING_NAME","\
NM_SETTING_WIREGUARD_SETTING_NAME","\

View file

@ -5127,7 +5127,8 @@ static const NMMetaPropertyInfo *const property_infos_CONNECTION[] = {
NM_SETTING_BRIDGE_SETTING_NAME,
NM_SETTING_OVS_BRIDGE_SETTING_NAME,
NM_SETTING_OVS_PORT_SETTING_NAME,
NM_SETTING_TEAM_SETTING_NAME),
NM_SETTING_TEAM_SETTING_NAME,
NM_SETTING_VRF_SETTING_NAME),
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES,
@ -6914,6 +6915,20 @@ static const NMMetaPropertyInfo *const property_infos_VPN[] = {
NULL
};
#undef _CURRENT_NM_META_SETTING_TYPE
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VRF
static const NMMetaPropertyInfo *const property_infos_VRF[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_VRF_TABLE,
.is_cli_option = TRUE,
.property_alias = "table",
.inf_flags = NM_META_PROPERTY_INF_FLAG_REQD,
.prompt = N_("Table [0]"),
.property_type = &_pt_gobject_int,
),
NULL
};
#undef _CURRENT_NM_META_SETTING_TYPE
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VXLAN
static const NMMetaPropertyInfo *const property_infos_VXLAN[] = {
@ -7698,6 +7713,7 @@ _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN)
#define SETTING_PRETTY_NAME_USER N_("User settings")
#define SETTING_PRETTY_NAME_VLAN N_("VLAN connection")
#define SETTING_PRETTY_NAME_VPN N_("VPN connection")
#define SETTING_PRETTY_NAME_VRF N_("VRF connection")
#define SETTING_PRETTY_NAME_VXLAN N_("VXLAN connection")
#define SETTING_PRETTY_NAME_WIFI_P2P N_("Wi-Fi P2P connection")
#define SETTING_PRETTY_NAME_WIMAX N_("WiMAX connection")
@ -7938,6 +7954,13 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
NM_META_SETTING_VALID_PART_ITEM (VPN, TRUE),
),
),
SETTING_INFO (VRF,
.valid_parts = NM_META_SETTING_VALID_PARTS (
NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE),
NM_META_SETTING_VALID_PART_ITEM (VRF, TRUE),
),
),
SETTING_INFO (VXLAN,
.valid_parts = NM_META_SETTING_VALID_PARTS (
NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE),
@ -8062,6 +8085,10 @@ nm_meta_setting_info_valid_parts_for_slave_type (const char *slave_type, const c
NM_SET_OUT (out_slave_name, "team-slave");
return valid_settings_slave_team;
}
if (nm_streq (slave_type, NM_SETTING_VRF_SETTING_NAME)) {
NM_SET_OUT (out_slave_name, "vrf-slave");
return valid_settings_noslave;
}
return NULL;
}

View file

@ -354,6 +354,7 @@
#define DESCRIBE_DOC_NM_SETTING_VPN_SERVICE_TYPE N_("D-Bus service name of the VPN plugin that this setting uses to connect to its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc plugin.")
#define DESCRIBE_DOC_NM_SETTING_VPN_TIMEOUT N_("Timeout for the VPN service to establish the connection. Some services may take quite a long time to connect. Value of 0 means a default timeout, which is 60 seconds (unless overridden by vpn.timeout in configuration file). Values greater than zero mean timeout in seconds.")
#define DESCRIBE_DOC_NM_SETTING_VPN_USER_NAME N_("If the VPN connection requires a user name for authentication, that name should be provided here. If the connection is available to more than one user, and the VPN requires each user to supply a different name, then leave this property empty. If this property is empty, NetworkManager will automatically supply the username of the user which requested the VPN connection.")
#define DESCRIBE_DOC_NM_SETTING_VRF_TABLE N_("The routing table for this VRF.")
#define DESCRIBE_DOC_NM_SETTING_VXLAN_AGEING N_("Specifies the lifetime in seconds of FDB entries learnt by the kernel.")
#define DESCRIBE_DOC_NM_SETTING_VXLAN_DESTINATION_PORT N_("Specifies the UDP destination port to communicate to the remote VXLAN tunnel endpoint.")
#define DESCRIBE_DOC_NM_SETTING_VXLAN_ID N_("Specifies the VXLAN Network Identifier (or VXLAN Segment Identifier) to use.")

View file

@ -350,6 +350,7 @@ print ("NetworkManager version " + client.get_version())]]></programlisting></in
<xi:include href="xml/nm-setting-user.xml"/>
<xi:include href="xml/nm-setting-vlan.xml"/>
<xi:include href="xml/nm-setting-vpn.xml"/>
<xi:include href="xml/nm-setting-vrf.xml"/>
<xi:include href="xml/nm-setting-vxlan.xml"/>
<xi:include href="xml/nm-setting-wifi-p2p.xml"/>
<xi:include href="xml/nm-setting-wimax.xml"/>

View file

@ -56,6 +56,7 @@ libnm_core_headers = files(
'nm-setting-user.h',
'nm-setting-vlan.h',
'nm-setting-vpn.h',
'nm-setting-vrf.h',
'nm-setting-vxlan.h',
'nm-setting-wifi-p2p.h',
'nm-setting-wimax.h',
@ -150,6 +151,7 @@ libnm_core_settings_sources = files(
'nm-setting-user.c',
'nm-setting-vlan.c',
'nm-setting-vpn.c',
'nm-setting-vrf.c',
'nm-setting-vxlan.c',
'nm-setting-wifi-p2p.c',
'nm-setting-wimax.c',

View file

@ -887,6 +887,7 @@ static gboolean
_supports_addr_family (NMConnection *self, int family)
{
const char *connection_type = nm_connection_get_connection_type (self);
NMSettingConnection *s_con;
g_return_val_if_fail (connection_type, TRUE);
if (strcmp (connection_type, NM_SETTING_OVS_INTERFACE_SETTING_NAME) == 0)
@ -895,6 +896,9 @@ _supports_addr_family (NMConnection *self, int family)
return FALSE;
if (strcmp (connection_type, NM_SETTING_6LOWPAN_SETTING_NAME) == 0)
return family == AF_INET6 || family == AF_UNSPEC;
if ( (s_con = nm_connection_get_setting_connection (self))
&& (nm_streq0 (nm_setting_connection_get_slave_type (s_con), NM_SETTING_VRF_SETTING_NAME)))
return TRUE;
return !nm_setting_connection_get_master (nm_connection_get_setting_connection (self));
}
@ -2687,6 +2691,7 @@ nm_connection_is_virtual (NMConnection *connection)
NM_SETTING_TEAM_SETTING_NAME,
NM_SETTING_TUN_SETTING_NAME,
NM_SETTING_VLAN_SETTING_NAME,
NM_SETTING_VRF_SETTING_NAME,
NM_SETTING_VXLAN_SETTING_NAME,
NM_SETTING_WIREGUARD_SETTING_NAME))
return TRUE;

View file

@ -61,6 +61,7 @@
#include "nm-setting-tun.h"
#include "nm-setting-vlan.h"
#include "nm-setting-vpn.h"
#include "nm-setting-vrf.h"
#include "nm-setting-vxlan.h"
#include "nm-setting-wifi-p2p.h"
#include "nm-setting-wimax.h"

View file

@ -54,6 +54,7 @@ typedef struct _NMSettingTun NMSettingTun;
typedef struct _NMSettingUser NMSettingUser;
typedef struct _NMSettingVlan NMSettingVlan;
typedef struct _NMSettingVpn NMSettingVpn;
typedef struct _NMSettingVrf NMSettingVrf;
typedef struct _NMSettingVxlan NMSettingVxlan;
typedef struct _NMSettingWifiP2P NMSettingWifiP2P;
typedef struct _NMSettingWimax NMSettingWimax;

168
libnm-core/nm-setting-vrf.c Normal file
View file

@ -0,0 +1,168 @@
// SPDX-License-Identifier: LGPL-2.1+
#include "nm-default.h"
#include "nm-setting-vrf.h"
#include "nm-connection-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-vrf
* @short_description: Describes connection properties for vrf interfaces
*
* The #NMSettingVrf object is a #NMSetting subclass that describes properties
* necessary for connection to vrf devices
**/
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_TABLE,
);
/**
* NMSettingVrf:
*
* VRF settings.
*
* Since: 1.24
*/
struct _NMSettingVrf {
NMSetting parent;
guint32 table;
};
struct _NMSettingVrfClass {
NMSettingClass parent;
};
G_DEFINE_TYPE (NMSettingVrf, nm_setting_vrf, NM_TYPE_SETTING)
/*****************************************************************************/
/**
* nm_setting_vrf_get_table:
* @setting: the #NMSettingVrf
*
* Returns: the routing table for the VRF
*
* Since: 1.24
**/
guint32
nm_setting_vrf_get_table (NMSettingVrf *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VRF (setting), 0);
return setting->table;
}
/*****************************************************************************/
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingVrf *self = NM_SETTING_VRF (setting);
if (!_nm_connection_verify_required_interface_name (connection, error))
return FALSE;
if (self->table == 0) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("table cannot be zero"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_VRF_SETTING_NAME,
NM_SETTING_VRF_TABLE);
return FALSE;
}
return TRUE;
}
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingVrf *self = NM_SETTING_VRF (object);
switch (prop_id) {
case PROP_TABLE:
g_value_set_uint (value, self->table);
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)
{
NMSettingVrf *self = NM_SETTING_VRF (object);
switch (prop_id) {
case PROP_TABLE:
self->table = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_setting_vrf_init (NMSettingVrf *setting)
{
}
/**
* nm_setting_vrf_new:
*
* Creates a new #NMSettingVrf object with default values.
*
* Returns: (transfer full): the new empty #NMSettingVrf object
*
* Since: 1.24
**/
NMSetting *
nm_setting_vrf_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VRF, NULL);
}
static void
nm_setting_vrf_class_init (NMSettingVrfClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
setting_class->verify = verify;
/**
* NMSettingVrf:table:
*
* The routing table for this VRF.
*
* Since: 1.24
**/
obj_properties[PROP_TABLE] =
g_param_spec_uint (NM_SETTING_VRF_TABLE, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
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_VRF);
}

View file

@ -0,0 +1,36 @@
// SPDX-License-Identifier: LGPL-2.1+
#ifndef __NM_SETTING_VRF_H__
#define __NM_SETTING_VRF_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_VRF (nm_setting_vrf_get_type ())
#define NM_SETTING_VRF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_VRF, NMSettingVrf))
#define NM_SETTING_VRF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_VRFCONFIG, NMSettingVrfClass))
#define NM_IS_SETTING_VRF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_VRF))
#define NM_IS_SETTING_VRF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_VRF))
#define NM_SETTING_VRF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_VRF, NMSettingVrfClass))
#define NM_SETTING_VRF_SETTING_NAME "vrf"
#define NM_SETTING_VRF_TABLE "table"
typedef struct _NMSettingVrfClass NMSettingVrfClass;
NM_AVAILABLE_IN_1_24
GType nm_setting_vrf_get_type (void);
NM_AVAILABLE_IN_1_24
NMSetting *nm_setting_vrf_new (void);
NM_AVAILABLE_IN_1_24
guint32 nm_setting_vrf_get_table (NMSettingVrf *setting);
G_END_DECLS
#endif /* __NM_SETTING_VRF_H__ */

View file

@ -151,15 +151,18 @@ _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_t
if (!slave_type)
found = FALSE;
else if (!strcmp (slave_type, NM_SETTING_BOND_SETTING_NAME))
;
else if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
else if (NM_IN_STRSET (slave_type,
NM_SETTING_BOND_SETTING_NAME,
NM_SETTING_VRF_SETTING_NAME)) {
/* pass */
}
else if (nm_streq (slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
port_type = NM_SETTING_BRIDGE_PORT_SETTING_NAME;
else if (!strcmp (slave_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME))
else if (nm_streq (slave_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME))
port_type = NM_SETTING_OVS_PORT_SETTING_NAME;
else if (!strcmp (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME))
else if (nm_streq (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME))
port_type = NM_SETTING_OVS_INTERFACE_SETTING_NAME;
else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME))
else if (nm_streq (slave_type, NM_SETTING_TEAM_SETTING_NAME))
port_type = NM_SETTING_TEAM_PORT_SETTING_NAME;
else
found = FALSE;

View file

@ -88,6 +88,7 @@
#include "nm-setting-user.h"
#include "nm-setting-vlan.h"
#include "nm-setting-vpn.h"
#include "nm-setting-vrf.h"
#include "nm-setting-vxlan.h"
#include "nm-setting-wimax.h"
#include "nm-setting-wired.h"

View file

@ -1665,4 +1665,7 @@ global:
nm_client_get_permissions_state;
nm_client_instance_flags_get_type;
nm_object_get_client;
nm_setting_vrf_get_table;
nm_setting_vrf_get_type;
nm_setting_vrf_new;
} libnm_1_22_0;

View file

@ -90,6 +90,7 @@ libnm-core/nm-setting-team.c
libnm-core/nm-setting-tun.c
libnm-core/nm-setting-user.c
libnm-core/nm-setting-vlan.c
libnm-core/nm-setting-vrf.c
libnm-core/nm-setting-vpn.c
libnm-core/nm-setting-vxlan.c
libnm-core/nm-setting-wifi-p2p.c

View file

@ -46,6 +46,7 @@
#include "nm-setting-user.h"
#include "nm-setting-vlan.h"
#include "nm-setting-vpn.h"
#include "nm-setting-vrf.h"
#include "nm-setting-vxlan.h"
#include "nm-setting-wifi-p2p.h"
#include "nm-setting-wimax.h"
@ -387,6 +388,12 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = {
.setting_name = NM_SETTING_VPN_SETTING_NAME,
.get_setting_gtype = nm_setting_vpn_get_type,
},
[NM_META_SETTING_TYPE_VRF] = {
.meta_type = NM_META_SETTING_TYPE_VRF,
.setting_priority = NM_SETTING_PRIORITY_HW_BASE,
.setting_name = NM_SETTING_VRF_SETTING_NAME,
.get_setting_gtype = nm_setting_vrf_get_type,
},
[NM_META_SETTING_TYPE_VXLAN] = {
.meta_type = NM_META_SETTING_TYPE_VXLAN,
.setting_priority = NM_SETTING_PRIORITY_HW_BASE,

View file

@ -142,6 +142,7 @@ typedef enum {
NM_META_SETTING_TYPE_USER,
NM_META_SETTING_TYPE_VLAN,
NM_META_SETTING_TYPE_VPN,
NM_META_SETTING_TYPE_VRF,
NM_META_SETTING_TYPE_VXLAN,
NM_META_SETTING_TYPE_WIFI_P2P,
NM_META_SETTING_TYPE_WIMAX,