libnm-core: add ovs-patch setting

This commit is contained in:
Lubomir Rintel 2017-08-01 18:36:34 +02:00
parent 89c4732142
commit d4a7fe4679
10 changed files with 297 additions and 0 deletions

View file

@ -393,6 +393,7 @@ libnm_core_lib_h_pub_real = \
libnm-core/nm-setting-macsec.h \
libnm-core/nm-setting-macvlan.h \
libnm-core/nm-setting-olpc-mesh.h \
libnm-core/nm-setting-ovs-patch.h \
libnm-core/nm-setting-ppp.h \
libnm-core/nm-setting-pppoe.h \
libnm-core/nm-setting-proxy.h \
@ -474,6 +475,7 @@ libnm_core_lib_c_real = \
libnm-core/nm-setting-macsec.c \
libnm-core/nm-setting-macvlan.c \
libnm-core/nm-setting-olpc-mesh.c \
libnm-core/nm-setting-ovs-patch.c \
libnm-core/nm-setting-ppp.c \
libnm-core/nm-setting-pppoe.c \
libnm-core/nm-setting-proxy.c \

View file

@ -262,6 +262,8 @@
#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_OVS_PATCH_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".")
#define DESCRIBE_DOC_NM_SETTING_OVS_PATCH_PEER N_("Specifies the unicast destination IP address of a remote OpenVSwitch bridge port to connect to.")
#define DESCRIBE_DOC_NM_SETTING_PPP_BAUD N_("If non-zero, instruct pppd to set the serial port to the specified baudrate. This value should normally be left as 0 to automatically choose the speed.")
#define DESCRIBE_DOC_NM_SETTING_PPP_CRTSCTS N_("If TRUE, specify that pppd should set the serial port to use hardware flow control with RTS and CTS signals. This value should normally be set to FALSE.")
#define DESCRIBE_DOC_NM_SETTING_PPP_LCP_ECHO_FAILURE N_("If non-zero, instruct pppd to presume the connection to the peer has failed if the specified number of LCP echo-requests go unanswered by the peer. The \"lcp-echo-interval\" property must also be set to a non-zero value if this property is used.")

View file

@ -2335,6 +2335,22 @@ nm_connection_get_setting_olpc_mesh (NMConnection *connection)
return _connection_get_setting_check (connection, NM_TYPE_SETTING_OLPC_MESH);
}
/**
* nm_connection_get_setting_ovs_patch:
* @connection: the #NMConnection
*
* A shortcut to return any #NMSettingOvsPatch the connection might contain.
*
* Returns: (transfer none): an #NMSettingOvsPatch if the connection contains one, otherwise %NULL
*
* Since: 1.10
**/
NMSettingOvsPatch *
nm_connection_get_setting_ovs_patch (NMConnection *connection)
{
return _connection_get_setting_check (connection, NM_TYPE_SETTING_OVS_PATCH);
}
/**
* nm_connection_get_setting_ppp:
* @connection: the #NMConnection

View file

@ -213,6 +213,8 @@ NMSettingMacsec * nm_connection_get_setting_macsec (NMConnec
NM_AVAILABLE_IN_1_2
NMSettingMacvlan * nm_connection_get_setting_macvlan (NMConnection *connection);
NMSettingOlpcMesh * nm_connection_get_setting_olpc_mesh (NMConnection *connection);
NM_AVAILABLE_IN_1_10
NMSettingOvsPatch * nm_connection_get_setting_ovs_patch (NMConnection *connection);
NMSettingPpp * nm_connection_get_setting_ppp (NMConnection *connection);
NMSettingPppoe * nm_connection_get_setting_pppoe (NMConnection *connection);
NM_AVAILABLE_IN_1_6

View file

@ -56,6 +56,7 @@
#include "nm-setting-macsec.h"
#include "nm-setting-macvlan.h"
#include "nm-setting-olpc-mesh.h"
#include "nm-setting-ovs-patch.h"
#include "nm-setting-ppp.h"
#include "nm-setting-pppoe.h"
#include "nm-setting-serial.h"

View file

@ -50,6 +50,7 @@ typedef struct _NMSettingIP6Config NMSettingIP6Config;
typedef struct _NMSettingMacsec NMSettingMacsec;
typedef struct _NMSettingMacvlan NMSettingMacvlan;
typedef struct _NMSettingOlpcMesh NMSettingOlpcMesh;
typedef struct _NMSettingOvsPatch NMSettingOvsPatch;
typedef struct _NMSettingPpp NMSettingPpp;
typedef struct _NMSettingPppoe NMSettingPppoe;
typedef struct _NMSettingSerial NMSettingSerial;

View file

@ -0,0 +1,215 @@
/* -*- 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2017 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-setting-ovs-patch.h"
#include "nm-connection-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-ovs-patch
* @short_description: Describes connection properties for OpenVSwitch patch interfaces.
*
* The #NMSettingOvsPatch object is a #NMSetting subclass that describes properties
* necessary for OpenVSwitch interfaces of type "patch".
**/
enum {
PROP_0,
PROP_PEER,
LAST_PROP
};
/**
* NMSettingOvsPatch:
*
* OvsPatch Link Settings
*/
struct _NMSettingOvsPatch {
NMSetting parent;
char *peer;
};
struct _NMSettingOvsPatchClass {
NMSettingClass parent;
};
G_DEFINE_TYPE_WITH_CODE (NMSettingOvsPatch, nm_setting_ovs_patch, NM_TYPE_SETTING,
_nm_register_setting (OVS_PATCH, NM_SETTING_PRIORITY_HW_BASE))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OVS_PATCH)
/*****************************************************************************/
/**
* nm_setting_ovs_patch_get_peer:
* @self: the #NMSettingOvsPatch
*
* Returns: the #NMSettingOvsPatch:peer property of the setting
*
* Since: 1.10
**/
const char *
nm_setting_ovs_patch_get_peer (NMSettingOvsPatch *self)
{
g_return_val_if_fail (NM_IS_SETTING_OVS_PATCH (self), NULL);
return self->peer;
}
/*****************************************************************************/
static int
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH (setting);
int family = AF_UNSPEC;
if (!_nm_connection_verify_required_interface_name (connection, error))
return FALSE;
if (!self->peer) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ",
NM_SETTING_OVS_PATCH_SETTING_NAME,
NM_SETTING_OVS_PATCH_PEER);
return FALSE;
}
if (nm_utils_ipaddr_valid (AF_INET, self->peer))
family = AF_INET;
else if (nm_utils_ipaddr_valid (AF_INET6, self->peer))
family = AF_INET6;
else {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid IP address"),
self->peer);
g_prefix_error (error, "%s.%s: ",
NM_SETTING_OVS_PATCH_SETTING_NAME,
NM_SETTING_OVS_PATCH_PEER);
return FALSE;
}
return TRUE;
}
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH (object);
switch (prop_id) {
case PROP_PEER:
g_value_set_string (value, self->peer);
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)
{
NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH (object);
switch (prop_id) {
case PROP_PEER:
g_free (self->peer);
self->peer = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_setting_ovs_patch_init (NMSettingOvsPatch *self)
{
}
/**
* nm_setting_ovs_patch_new:
*
* Creates a new #NMSettingOvsPatch object with default values.
*
* Returns: (transfer full): the new empty #NMSettingOvsPatch object
*
* Since: 1.10
**/
NMSetting *
nm_setting_ovs_patch_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_OVS_PATCH, NULL);
}
static void
finalize (GObject *object)
{
NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH (object);
g_free (self->peer);
G_OBJECT_CLASS (nm_setting_ovs_patch_parent_class)->finalize (object);
}
static void
nm_setting_ovs_patch_class_init (NMSettingOvsPatchClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/**
* NMSettingOvsPatch:peer:
*
* Specifies the unicast destination IP address of a remote OpenVSwitch
* bridge port to connect to.
*
* Since: 1.10
**/
g_object_class_install_property
(object_class, PROP_PEER,
g_param_spec_string (NM_SETTING_OVS_PATCH_PEER, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View file

@ -0,0 +1,54 @@
/*
* 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2017 Red Hat, Inc.
*/
#ifndef __NM_SETTING_OVS_PATCH_H__
#define __NM_SETTING_OVS_PATCH_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_OVS_PATCH (nm_setting_ovs_patch_get_type ())
#define NM_SETTING_OVS_PATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_OVS_PATCH, NMSettingOvsPatch))
#define NM_SETTING_OVS_PATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_OVS_PATCHCONFIG, NMSettingOvsPatchClass))
#define NM_IS_SETTING_OVS_PATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_OVS_PATCH))
#define NM_IS_SETTING_OVS_PATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_OVS_PATCH))
#define NM_SETTING_OVS_PATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_OVS_PATCH, NMSettingOvsPatchClass))
#define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch"
#define NM_SETTING_OVS_PATCH_PEER "peer"
typedef struct _NMSettingOvsPatchClass NMSettingOvsPatchClass;
NM_AVAILABLE_IN_1_10
GType nm_setting_ovs_patch_get_type (void);
NM_AVAILABLE_IN_1_10
NMSetting *nm_setting_ovs_patch_new (void);
NM_AVAILABLE_IN_1_10
const char *nm_setting_ovs_patch_get_peer (NMSettingOvsPatch *self);
G_END_DECLS
#endif /* __NM_SETTING_OVS_PATCH_H__ */

View file

@ -1190,6 +1190,9 @@ global:
nm_ip_route_equal_full;
nm_setting_bridge_get_group_forward_mask;
nm_setting_ip_config_get_route_table;
nm_setting_ovs_patch_get_peer;
nm_setting_ovs_patch_get_type;
nm_setting_ovs_patch_new;
nm_setting_pppoe_get_parent;
nm_setting_wireless_security_get_pmf;
nm_setting_wireless_security_get_wps_method;

View file

@ -75,6 +75,7 @@ libnm-core/nm-setting-ip-tunnel.c
libnm-core/nm-setting-macsec.c
libnm-core/nm-setting-macvlan.c
libnm-core/nm-setting-olpc-mesh.c
libnm-core/nm-setting-ovs-patch.c
libnm-core/nm-setting-ppp.c
libnm-core/nm-setting-pppoe.c
libnm-core/nm-setting-proxy.c