summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2017-10-09 10:01:31 +0200
committerLubomir Rintel <lkundrak@v3.sk>2017-10-09 10:01:31 +0200
commite3390e770f3af683663766be435d67669d55e067 (patch)
tree1256e4f736ab337212e9c7095b0e67bb5ce3f67e
parentdc8d4fb24f09ed2eaa9e450248f3e2013eb78476 (diff)
downloadNetworkManager-e3390e770f3af683663766be435d67669d55e067.tar.gz
x
-rw-r--r--src/devices/openvswitch/nm-device-ovs-bridge.c221
-rw-r--r--src/devices/openvswitch/nm-device-ovs-interface.c5
-rw-r--r--src/devices/openvswitch/nm-device-ovs-port.c177
3 files changed, 27 insertions, 376 deletions
diff --git a/src/devices/openvswitch/nm-device-ovs-bridge.c b/src/devices/openvswitch/nm-device-ovs-bridge.c
index e792f49299..c3b2efd7ea 100644
--- a/src/devices/openvswitch/nm-device-ovs-bridge.c
+++ b/src/devices/openvswitch/nm-device-ovs-bridge.c
@@ -20,12 +20,13 @@
#include "nm-default.h"
#include "nm-device-ovs-bridge.h"
+#include "nm-device-ovs-port.h"
#include "nm-ovsdb.h"
#include "devices/nm-device-private.h"
+#include "nm-active-connection.h"
#include "nm-setting-connection.h"
#include "nm-setting-ovs-bridge.h"
-#include "nm-setting-ovs-port.h"
#include "introspection/org.freedesktop.NetworkManager.Device.OvsBridge.h"
@@ -46,40 +47,6 @@ G_DEFINE_TYPE (NMDeviceOvsBridge, nm_device_ovs_bridge, NM_TYPE_DEVICE)
/*****************************************************************************/
-static void
-link_changed (NMDevice *device, const NMPlatformLink *pllink)
-{
-#if 0
- NMDeviceOvsBridge *self = NM_DEVICE_OVS_BRIDGE (device);
-
- NM_DEVICE_CLASS (nm_device_ovs_bridge_parent_class)->link_changed (device, pllink);
-
- if (pllink && nm_device_get_state (device) == NM_DEVICE_STATE_CONFIG) {
- _LOGD (LOGD_DEVICE, "the link appeared, continuing activation");
- nm_device_activate_schedule_stage2_device_config (device);
- }
-#else
- g_printerr ("BRIDGE: LINK CHANGED\n");
-#endif
-}
-
-#if 0
-static void
-add_br_cb (GError *error, gpointer user_data)
-{
- NMDeviceOvsBridge *self = user_data;
-
- if (error) {
- _LOGW (LOGD_DEVICE, "%s", error->message);
- nm_device_state_changed (NM_DEVICE (self),
- NM_DEVICE_STATE_FAILED,
- NM_DEVICE_STATE_REASON_UNKNOWN);
- }
-
- g_object_unref (self);
-}
-#endif
-
static gboolean
create_and_realize (NMDevice *device,
NMConnection *connection,
@@ -87,68 +54,24 @@ create_and_realize (NMDevice *device,
const NMPlatformLink **out_plink,
GError **error)
{
-#if 0
- const char *connection_type;
-
- connection_type = nm_connection_get_connection_type (connection);
- g_return_val_if_fail (connection_type, FALSE);
-
- if (strcmp (connection_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME) == 0) {
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_ADD_BR,
- nm_device_get_iface (device), connection, NULL,
- add_br_cb, g_object_ref (device));
-
- /* We don't have a plink yet, since the device is eventually instantiated
- * by ovs-vswitchd asynchronously. Manager knows and manager is fine with that. */
- } else if (strcmp (connection_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- /* This doesn't really exist, not even in the ovsdb, until an interface is
- * enslaved. */
- } else {
- g_return_val_if_reached (FALSE);
- }
-#endif
- g_printerr ("BRIDGE: CREATE AND REALIZE\n");
+ /* The actual backing resources will be created on enslavement by the port
+ * when it can identify the port and the bridge. */
return TRUE;
}
-#if 0
-static void
-del_br_cb (GError *error, gpointer user_data)
-{
- NMDeviceOvsBridge *self = user_data;
-
- if (error) {
- _LOGW (LOGD_DEVICE, "%s", error->message);
- nm_device_state_changed (NM_DEVICE (self),
- NM_DEVICE_STATE_FAILED,
- NM_DEVICE_STATE_REASON_UNKNOWN);
- }
-
- g_object_unref (self);
-}
-#endif
-
static gboolean
unrealize (NMDevice *device, GError **error)
{
-#if 0
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_DEL_BR,
- nm_device_get_iface (device), NULL, NULL,
- del_br_cb, g_object_ref (device));
-#endif
- g_printerr ("BRIDGE: UNREALIZE\n");
-
return TRUE;
}
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *device)
{
- return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
+ return NM_DEVICE_CAP_IS_SOFTWARE;
}
-
static gboolean
check_connection_compatible (NMDevice *device, NMConnection *connection)
{
@@ -185,46 +108,14 @@ check_slave_connection_compatible (NMDevice *device, NMConnection *slave)
if (strcmp (slave_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME) == 0)
return TRUE;
- g_printerr ("BRIDGE: CHECK SLAVE COMPAT\n");
-
return FALSE;
}
-#if 0
-static NMActStageReturn
-act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
-{
-#if 0
- NMDeviceOvsBridge *self = NM_DEVICE_OVS_BRIDGE (device);
- NMConnection *applied_connection;
-
- applied_connection = nm_device_get_applied_connection (device);
- if ( applied_connection
- && strcmp (nm_connection_get_connection_type (applied_connection),
- NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- return NM_ACT_STAGE_RETURN_SUCCESS;
- }
-
- if (nm_device_get_ifindex (device)) {
- return NM_ACT_STAGE_RETURN_SUCCESS;
- } else {
- _LOGD (LOGD_DEVICE, "the link is not there, waiting for it to appear");
- return NM_ACT_STAGE_RETURN_POSTPONE;
- }
-#else
- g_printerr ("BRIDGE: ACT2\n");
- return NM_ACT_STAGE_RETURN_POSTPONE;
-// return NM_ACT_STAGE_RETURN_SUCCESS;
-#endif
-}
-#endif
-
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
- g_printerr ("BRIDGE: ACT3v4\n");
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
@@ -233,18 +124,16 @@ act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
- g_printerr ("BRIDGE: ACT3v6\n");
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
-#if 0
static void
add_iface_cb (GError *error, gpointer user_data)
{
NMDevice *slave = user_data;
if (error) {
- nm_log_warn (LOGD_DEVICE, "device %s could not be added to a ovs port: %s",
+ nm_log_warn (LOGD_DEVICE, "device %s could not be added to a ovs bridge: %s",
nm_device_get_iface (slave), error->message);
nm_device_state_changed (slave,
NM_DEVICE_STATE_FAILED,
@@ -255,84 +144,32 @@ add_iface_cb (GError *error, gpointer user_data)
}
static gboolean
-_get_bridge_port (NMDevice *device, NMDevice *slave, NMConnection *connection,
- NMDevice **bridge, NMDevice **port)
-{
- NMConnection *applied_connection;
- const char *device_type;
- const char *slave_type = NULL;
-
- if (!connection)
- connection = nm_device_get_applied_connection (slave);
- if (connection)
- slave_type = nm_connection_get_connection_type (connection);
-
- applied_connection = nm_device_get_applied_connection (device);
- if (!applied_connection)
- return FALSE;
- device_type = nm_connection_get_connection_type (applied_connection);
-
- /* Do nothing if we're just enslaving an empty port to a bridge. */
- if (g_strcmp0 (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- *bridge = NULL;
- *port = NULL;
- return g_strcmp0 (device_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME) == 0;
- }
-
- if (g_strcmp0 (device_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME) == 0) {
- *bridge = device;
- *port = slave;
- } else if (g_strcmp0 (device_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- *bridge = nm_device_get_master (device);
- *port = device;
- } else {
- g_return_val_if_reached (FALSE);
- }
-
- if (!*bridge)
- return FALSE;
-
- return TRUE;
-}
-#endif
-
-static gboolean
enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure)
{
-#if 0
- NMDevice *bridge = NULL;
- NMDevice *port = NULL;
-
if (!configure)
return TRUE;
- if (!_get_bridge_port (device, slave, connection, &bridge, &port))
- return FALSE;
-
- if (!bridge && !port)
- return TRUE;
-
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_ADD_IFACE,
- nm_device_get_iface (bridge),
- nm_device_get_applied_connection (port),
- nm_device_get_applied_connection (slave),
- add_iface_cb, g_object_ref (slave));
+ if (!NM_IS_DEVICE_OVS_PORT (slave)) {
+ /* As a convenience measure, we allow enslaving the interfaces
+ * directly to the bridge without an intermediate ovs-port.
+ * In that case, create a port just for the slave. */
+ nm_ovsdb_add_interface (nm_ovsdb_get (),
+ nm_device_get_applied_connection (device),
+ nm_device_get_applied_connection (slave),
+ nm_device_get_applied_connection (slave),
+ add_iface_cb, g_object_ref (device));
+ }
return TRUE;
-#else
- g_printerr ("BRIDGE: ENSLAVE SLAVE\n");
- return TRUE;
-#endif
}
-#if 0
static void
del_iface_cb (GError *error, gpointer user_data)
{
NMDevice *slave = user_data;
if (error) {
- nm_log_warn (LOGD_DEVICE, "device %s could not be removed from a ovs port: %s",
+ nm_log_warn (LOGD_DEVICE, "device %s could not be removed from a ovs bridge: %s",
nm_device_get_iface (slave), error->message);
nm_device_state_changed (slave,
NM_DEVICE_STATE_FAILED,
@@ -341,32 +178,18 @@ del_iface_cb (GError *error, gpointer user_data)
g_object_unref (slave);
}
-#endif
static void
release_slave (NMDevice *device, NMDevice *slave, gboolean configure)
{
-#if 0
- NMDevice *bridge = NULL;
- NMDevice *port = NULL;
-
if (!configure)
return;
- if (!_get_bridge_port (device, slave, NULL, &bridge, &port))
- return;
-
- if (!bridge && !port)
+ if (NM_IS_DEVICE_OVS_PORT (slave))
return;
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_DEL_IFACE,
- nm_device_get_iface (bridge),
- nm_device_get_applied_connection (port),
- nm_device_get_applied_connection (slave),
- del_iface_cb, g_object_ref (slave));
-#else
- g_printerr ("BRIDGE: RELEASE SLAVE\n");
-#endif
+ nm_ovsdb_del_interface (nm_ovsdb_get (), nm_device_get_iface (slave),
+ del_iface_cb, g_object_ref (slave));
}
/*****************************************************************************/
@@ -381,16 +204,12 @@ nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *klass)
{
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
-// NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_OVS_BRIDGE)
-
device_class->is_master = TRUE;
- device_class->link_changed = link_changed;
device_class->create_and_realize = create_and_realize;
device_class->unrealize = unrealize;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->check_connection_compatible = check_connection_compatible;
device_class->check_slave_connection_compatible = check_slave_connection_compatible;
-// device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->enslave_slave = enslave_slave;
diff --git a/src/devices/openvswitch/nm-device-ovs-interface.c b/src/devices/openvswitch/nm-device-ovs-interface.c
index fab1bde422..a6cc820c9c 100644
--- a/src/devices/openvswitch/nm-device-ovs-interface.c
+++ b/src/devices/openvswitch/nm-device-ovs-interface.c
@@ -54,8 +54,9 @@ create_and_realize (NMDevice *device,
const NMPlatformLink **out_plink,
GError **error)
{
- /* The actual backing resources will be created on enslavement by the port
- * when it can identify the port and the bridge. */
+ /* The actual backing resources will be created once an interface is
+ * added to a port of ours, since there can be neither an empty port nor
+ * an empty bridge. */
return TRUE;
}
diff --git a/src/devices/openvswitch/nm-device-ovs-port.c b/src/devices/openvswitch/nm-device-ovs-port.c
index 7537b31418..80ae4a59da 100644
--- a/src/devices/openvswitch/nm-device-ovs-port.c
+++ b/src/devices/openvswitch/nm-device-ovs-port.c
@@ -47,40 +47,6 @@ G_DEFINE_TYPE (NMDeviceOvsPort, nm_device_ovs_port, NM_TYPE_DEVICE)
/*****************************************************************************/
-static void
-link_changed (NMDevice *device, const NMPlatformLink *pllink)
-{
-#if 0
- NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT (device);
-
- NM_DEVICE_CLASS (nm_device_ovs_port_parent_class)->link_changed (device, pllink);
-
- if (pllink && nm_device_get_state (device) == NM_DEVICE_STATE_CONFIG) {
- _LOGD (LOGD_DEVICE, "the link appeared, continuing activation");
- nm_device_activate_schedule_stage2_device_config (device);
- }
-#else
- g_printerr ("PORT: LINK CHANGED\n");
-#endif
-}
-
-#if 0
-static void
-add_br_cb (GError *error, gpointer user_data)
-{
- NMDeviceOvsPort *self = user_data;
-
- if (error) {
- _LOGW (LOGD_DEVICE, "%s", error->message);
- nm_device_state_changed (NM_DEVICE (self),
- NM_DEVICE_STATE_FAILED,
- NM_DEVICE_STATE_REASON_UNKNOWN);
- }
-
- g_object_unref (self);
-}
-#endif
-
static gboolean
create_and_realize (NMDevice *device,
NMConnection *connection,
@@ -88,57 +54,8 @@ create_and_realize (NMDevice *device,
const NMPlatformLink **out_plink,
GError **error)
{
-#if 0
- const char *connection_type;
-
- connection_type = nm_connection_get_connection_type (connection);
- g_return_val_if_fail (connection_type, FALSE);
-
- if (strcmp (connection_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_ADD_BR,
- nm_device_get_iface (device), connection, NULL,
- add_br_cb, g_object_ref (device));
-
- /* We don't have a plink yet, since the device is eventually instantiated
- * by ovs-vswitchd asynchronously. Manager knows and manager is fine with that. */
- } else if (strcmp (connection_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- /* This doesn't really exist, not even in the ovsdb, until an interface is
- * enslaved. */
- } else {
- g_return_val_if_reached (FALSE);
- }
-#endif
- g_printerr ("PORT: CREATE AND REALIZE\n");
-
- return TRUE;
-}
-
-#if 0
-static void
-del_br_cb (GError *error, gpointer user_data)
-{
- NMDeviceOvsPort *self = user_data;
-
- if (error) {
- _LOGW (LOGD_DEVICE, "%s", error->message);
- nm_device_state_changed (NM_DEVICE (self),
- NM_DEVICE_STATE_FAILED,
- NM_DEVICE_STATE_REASON_UNKNOWN);
- }
-
- g_object_unref (self);
-}
-#endif
-
-static gboolean
-unrealize (NMDevice *device, GError **error)
-{
-#if 0
- nm_ovsdb_transact (nm_ovsdb_get (), NM_OVSDB_DEL_BR,
- nm_device_get_iface (device), NULL, NULL,
- del_br_cb, g_object_ref (device));
-#endif
- g_printerr ("PORT: UNREALIZE\n");
+ /* The port will be added to ovsdb when an interface is enslaved,
+ * because there's no such thing like an empty port. */
return TRUE;
}
@@ -146,7 +63,7 @@ unrealize (NMDevice *device, GError **error)
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *device)
{
- return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
+ return NM_DEVICE_CAP_IS_SOFTWARE;
}
@@ -186,8 +103,6 @@ check_slave_connection_compatible (NMDevice *device, NMConnection *slave)
if (strcmp (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0)
return TRUE;
-// g_printerr ("PORT: CHECK SLAVE COMPAT\n");
-
return FALSE;
}
@@ -196,7 +111,6 @@ act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
- g_printerr ("PORT: ACT3v4\n");
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
@@ -205,39 +119,9 @@ act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
- g_printerr ("PORT: ACT3v6\n");
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
-#if 0
-static NMActStageReturn
-act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
-{
-#if 0
- NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT (device);
- NMConnection *applied_connection;
-
- applied_connection = nm_device_get_applied_connection (device);
- if ( applied_connection
- && strcmp (nm_connection_get_connection_type (applied_connection),
- NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- return NM_ACT_STAGE_RETURN_SUCCESS;
- }
-
- if (nm_device_get_ifindex (device)) {
- return NM_ACT_STAGE_RETURN_SUCCESS;
- } else {
- _LOGD (LOGD_DEVICE, "the link is not there, waiting for it to appear");
- return NM_ACT_STAGE_RETURN_POSTPONE;
- }
-#else
- g_printerr ("PORT: ACT2\n");
- return NM_ACT_STAGE_RETURN_POSTPONE;
-#endif
-}
-#endif
-
-
static void
add_iface_cb (GError *error, gpointer user_data)
{
@@ -254,58 +138,12 @@ add_iface_cb (GError *error, gpointer user_data)
g_object_unref (slave);
}
-#if 0
-static gboolean
-_get_port_port (NMDevice *device, NMDevice *slave, NMConnection *connection,
- NMDevice **port, NMDevice **port)
-{
- NMConnection *applied_connection;
- const char *device_type;
- const char *slave_type = NULL;
-
- if (!connection)
- connection = nm_device_get_applied_connection (slave);
- if (connection)
- slave_type = nm_connection_get_connection_type (connection);
-
- applied_connection = nm_device_get_applied_connection (device);
- if (!applied_connection)
- return FALSE;
- device_type = nm_connection_get_connection_type (applied_connection);
-
- /* Do nothing if we're just enslaving an empty port to a port. */
- if (g_strcmp0 (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- *port = NULL;
- *port = NULL;
- return g_strcmp0 (device_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0;
- }
-
- if (g_strcmp0 (device_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- *port = device;
- *port = slave;
- } else if (g_strcmp0 (device_type, NM_SETTING_OVS_PORT_SETTING_NAME) == 0) {
- *port = nm_device_get_master (device);
- *port = device;
- } else {
- g_return_val_if_reached (FALSE);
- }
-
- if (!*port)
- return FALSE;
-
- return TRUE;
-}
-#endif
-
static gboolean
enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure)
{
NMActiveConnection *ac_port = NULL;
NMActiveConnection *ac_bridge = NULL;
- g_printerr ("PORT: ENSLAVE SLAVE\n");
-
-
if (!configure)
return TRUE;
@@ -319,7 +157,7 @@ enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboo
nm_active_connection_get_applied_connection (ac_bridge),
nm_device_get_applied_connection (device),
nm_device_get_applied_connection (slave),
- add_iface_cb, g_object_ref (device));
+ add_iface_cb, g_object_ref (slave));
return TRUE;
}
@@ -343,8 +181,6 @@ del_iface_cb (GError *error, gpointer user_data)
static void
release_slave (NMDevice *device, NMDevice *slave, gboolean configure)
{
- g_printerr ("PORT: RELEASE SLAVE\n");
-
if (!configure)
return;
@@ -364,16 +200,11 @@ nm_device_ovs_port_class_init (NMDeviceOvsPortClass *klass)
{
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
-// NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_OVS_PORT)
-
device_class->is_master = TRUE;
- device_class->link_changed = link_changed;
device_class->create_and_realize = create_and_realize;
- device_class->unrealize = unrealize;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->check_connection_compatible = check_connection_compatible;
device_class->check_slave_connection_compatible = check_slave_connection_compatible;
-// device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->enslave_slave = enslave_slave;