diff options
| author | Michael Biebl <biebl@debian.org> | 2022-02-14 19:23:28 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2022-02-14 19:23:28 +0100 |
| commit | 2f94dba7385fd0e0ef19a06eb4a2fcf6c43d7946 (patch) | |
| tree | e2222f5577115985dd52044d2991253403cdd952 /src/core/devices/ovs | |
| parent | 88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (diff) | |
New upstream version 1.35.91 upstream/1.35.91
Diffstat (limited to 'src/core/devices/ovs')
| -rw-r--r-- | src/core/devices/ovs/nm-device-ovs-bridge.c | 28 | ||||
| -rw-r--r-- | src/core/devices/ovs/nm-device-ovs-interface.c | 100 | ||||
| -rw-r--r-- | src/core/devices/ovs/nm-device-ovs-port.c | 51 | ||||
| -rw-r--r-- | src/core/devices/ovs/nm-ovs-factory.c | 62 | ||||
| -rw-r--r-- | src/core/devices/ovs/nm-ovsdb.c | 339 | ||||
| -rw-r--r-- | src/core/devices/ovs/nm-ovsdb.h | 26 |
6 files changed, 321 insertions, 285 deletions
diff --git a/src/core/devices/ovs/nm-device-ovs-bridge.c b/src/core/devices/ovs/nm-device-ovs-bridge.c index 26a5ba00..683ada13 100644 --- a/src/core/devices/ovs/nm-device-ovs-bridge.c +++ b/src/core/devices/ovs/nm-device-ovs-bridge.c @@ -42,11 +42,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* The actual backing resources will be created on enslavement by the port * when it can identify the port and the bridge. */ @@ -66,13 +66,16 @@ get_generic_capabilities(NMDevice *device) return NM_DEVICE_CAP_IS_SOFTWARE; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) +{ + return FALSE; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - return NM_ACT_STAGE_RETURN_IP_FAIL; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static gboolean @@ -141,7 +144,7 @@ static void nm_device_ovs_bridge_class_init(NMDeviceOvsBridgeClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_ovs_bridge); @@ -154,7 +157,8 @@ nm_device_ovs_bridge_class_init(NMDeviceOvsBridgeClass *klass) device_class->create_and_realize = create_and_realize; device_class->unrealize = unrealize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; device_class->can_reapply_change_ovs_external_ids = TRUE; diff --git a/src/core/devices/ovs/nm-device-ovs-interface.c b/src/core/devices/ovs/nm-device-ovs-interface.c index 46a612ac..74707d24 100644 --- a/src/core/devices/ovs/nm-device-ovs-interface.c +++ b/src/core/devices/ovs/nm-device-ovs-interface.c @@ -49,11 +49,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* 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 @@ -71,7 +71,7 @@ get_generic_capabilities(NMDevice *device) static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); return nm_ovsdb_is_ready(priv->ovsdb); @@ -80,7 +80,7 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) static gboolean can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **specific_object) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); return nm_ovsdb_is_ready(priv->ovsdb); @@ -124,14 +124,19 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) if (!nm_device_hw_addr_set_cloned(device, nm_device_get_applied_connection(device), FALSE)) { - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_CONFIG_FAILED); + nm_device_devip_set_failed(device, AF_INET, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + nm_device_devip_set_failed(device, AF_INET6, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return; } nm_device_bring_up(device, TRUE, NULL); - nm_device_activate_schedule_stage3_ip_config_start(device); + + nm_device_devip_set_state(device, AF_INET, NM_DEVICE_IP_STATE_PENDING, NULL); + nm_device_devip_set_state(device, AF_INET6, NM_DEVICE_IP_STATE_PENDING, NULL); + nm_device_activate_schedule_stage3_ip_config(device, FALSE); + return; } + + nm_device_activate_schedule_stage2_device_config(device, FALSE); } static gboolean @@ -149,7 +154,7 @@ _is_internal_interface(NMDevice *device) static void set_platform_mtu_cb(GError *error, gpointer user_data) { - NMDevice * device = user_data; + NMDevice *device = user_data; NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); if (error && !g_error_matches(error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING)) { @@ -165,7 +170,7 @@ set_platform_mtu_cb(GError *error, gpointer user_data) static gboolean set_platform_mtu(NMDevice *device, guint32 mtu) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); /* @@ -188,31 +193,43 @@ set_platform_mtu(NMDevice *device, guint32 mtu) return NM_DEVICE_CLASS(nm_device_ovs_interface_parent_class)->set_platform_mtu(device, mtu); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); - NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(device); + return nm_device_get_ip_ifindex(device) > 0; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); - if (!_is_internal_interface(device)) - return NM_ACT_STAGE_RETURN_IP_FAIL; + if (!_is_internal_interface(device)) { + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); + return; + } + /* FIXME(l3cfg): we should create the IP ifindex before stage3 start. + * + * For now it's here because when the ovs-interface enters stage3, then it's added to the + * controller (ovs-port) and the entry is create in the ovsdb. Only after that the kernel + * link appears. + * + * This should change. */ if (nm_device_get_ip_ifindex(device) <= 0) { _LOGT(LOGD_DEVICE, "waiting for link to appear"); priv->waiting_for_interface = TRUE; - return NM_ACT_STAGE_RETURN_POSTPONE; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_PENDING, NULL); + return; } if (!nm_device_hw_addr_set_cloned(device, nm_device_get_applied_connection(device), FALSE)) { - *out_failure_reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED; - return NM_ACT_STAGE_RETURN_FAILURE; + nm_device_devip_set_failed(device, addr_family, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; } - return NM_DEVICE_CLASS(nm_device_ovs_interface_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static gboolean @@ -224,15 +241,15 @@ can_unmanaged_external_down(NMDevice *self) static void deactivate(NMDevice *device) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); priv->waiting_for_interface = FALSE; } typedef struct { - NMDeviceOvsInterface * self; - GCancellable * cancellable; + NMDeviceOvsInterface *self; + GCancellable *cancellable; NMDeviceDeactivateCallback callback; gpointer callback_user_data; gulong link_changed_id; @@ -258,14 +275,14 @@ deactivate_invoke_cb(DeactivateData *data, GError *error) } static void -deactivate_link_changed_cb(NMPlatform * platform, +deactivate_link_changed_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *info, int change_type_i, DeactivateData *data) { - NMDeviceOvsInterface * self = data->self; + NMDeviceOvsInterface *self = data->self; const NMPlatformSignalChangeType change_type = change_type_i; if (change_type == NM_PLATFORM_SIGNAL_REMOVED @@ -280,7 +297,7 @@ deactivate_link_changed_cb(NMPlatform * platform, static gboolean deactivate_link_timeout(gpointer user_data) { - DeactivateData * data = user_data; + DeactivateData *data = user_data; NMDeviceOvsInterface *self = data->self; _LOGT(LOGD_DEVICE, "deactivate: timeout waiting link removal"); @@ -300,7 +317,7 @@ deactivate_cancelled_cb(GCancellable *cancellable, gpointer user_data) static void deactivate_cb_on_idle(gpointer user_data, GCancellable *cancellable) { - DeactivateData *data = user_data; + DeactivateData *data = user_data; gs_free_error GError *cancelled_error = NULL; g_cancellable_set_error_if_cancelled(data->cancellable, &cancelled_error); @@ -308,14 +325,14 @@ deactivate_cb_on_idle(gpointer user_data, GCancellable *cancellable) } static void -deactivate_async(NMDevice * device, - GCancellable * cancellable, +deactivate_async(NMDevice *device, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer callback_user_data) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); - DeactivateData * data; + DeactivateData *data; _LOGT(LOGD_CORE, "deactivate: start async"); @@ -402,7 +419,7 @@ nm_device_ovs_interface_init(NMDeviceOvsInterface *self) static void dispose(GObject *object) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(object); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(object); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); if (priv->ovsdb) { @@ -420,9 +437,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_ovs_interface = { static void nm_device_ovs_interface_class_init(NMDeviceOvsInterfaceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->dispose = dispose; @@ -443,7 +460,8 @@ nm_device_ovs_interface_class_init(NMDeviceOvsInterfaceClass *klass) device_class->is_available = is_available; device_class->check_connection_compatible = check_connection_compatible; device_class->link_changed = link_changed; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->can_unmanaged_external_down = can_unmanaged_external_down; device_class->set_platform_mtu = set_platform_mtu; device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; diff --git a/src/core/devices/ovs/nm-device-ovs-port.c b/src/core/devices/ovs/nm-device-ovs-port.c index f11c5852..4419cfe9 100644 --- a/src/core/devices/ovs/nm-device-ovs-port.c +++ b/src/core/devices/ovs/nm-device-ovs-port.c @@ -41,11 +41,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* The port will be added to ovsdb when an interface is enslaved, * because there's no such thing like an empty port. */ @@ -59,13 +59,16 @@ get_generic_capabilities(NMDevice *device) return NM_DEVICE_CAP_IS_SOFTWARE; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) +{ + return FALSE; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - return NM_ACT_STAGE_RETURN_IP_FAIL; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static void @@ -87,10 +90,10 @@ add_iface_cb(GError *error, gpointer user_data) static gboolean enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { - NMDeviceOvsPort * self = NM_DEVICE_OVS_PORT(device); + NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT(device); NMActiveConnection *ac_port = NULL; NMActiveConnection *ac_bridge = NULL; - NMDevice * bridge_device; + NMDevice *bridge_device; if (!configure) return TRUE; @@ -143,18 +146,23 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT(device); + _LOGI(LOGD_DEVICE, "releasing ovs interface %s", nm_device_get_ip_iface(slave)); + + /* Even if the an interface's device has gone away (e.g. externally + * removed and thus we're called with configure=FALSE), we still need + * to make sure its OVSDB entry is gone. + */ + nm_ovsdb_del_interface(nm_ovsdb_get(), + nm_device_get_iface(slave), + del_iface_cb, + g_object_ref(slave)); + if (configure) { - _LOGI(LOGD_DEVICE, "releasing ovs interface %s", nm_device_get_ip_iface(slave)); - nm_ovsdb_del_interface(nm_ovsdb_get(), - nm_device_get_iface(slave), - del_iface_cb, - g_object_ref(slave)); /* Open VSwitch is going to delete this one. We must ignore what happens * next with the interface. */ if (NM_IS_DEVICE_OVS_INTERFACE(slave)) nm_device_update_from_platform_link(slave, NULL); - } else - _LOGI(LOGD_DEVICE, "ovs interface %s was released", nm_device_get_ip_iface(slave)); + } } /*****************************************************************************/ @@ -174,7 +182,7 @@ static void nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_ovs_port); @@ -186,7 +194,8 @@ nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass) device_class->get_type_description = get_type_description; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; device_class->can_reapply_change_ovs_external_ids = TRUE; diff --git a/src/core/devices/ovs/nm-ovs-factory.c b/src/core/devices/ovs/nm-ovs-factory.c index 6f5d8832..3ff0abf8 100644 --- a/src/core/devices/ovs/nm-ovs-factory.c +++ b/src/core/devices/ovs/nm-ovs-factory.c @@ -61,7 +61,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES( NM_SETTING_OVS_PORT_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { nm_manager_set_capability(NM_MANAGER_GET, NM_CAPABILITY_OVS); return g_object_new(NM_TYPE_OVS_FACTORY, NULL); @@ -106,14 +106,14 @@ new_device_from_type(const char *name, NMDeviceType device_type) } static void -ovsdb_device_added(NMOvsdb * ovsdb, - const char * name, +ovsdb_device_added(NMOvsdb *ovsdb, + const char *name, guint device_type_i, - const char * subtype, + const char *subtype, NMDeviceFactory *self) { const NMDeviceType device_type = device_type_i; - NMDevice * device; + NMDevice *device; if (device_type == NM_DEVICE_TYPE_OVS_INTERFACE && !NM_IN_STRSET(subtype, "internal", "patch")) { @@ -133,14 +133,14 @@ ovsdb_device_added(NMOvsdb * ovsdb, } static void -ovsdb_device_removed(NMOvsdb * ovsdb, - const char * name, +ovsdb_device_removed(NMOvsdb *ovsdb, + const char *name, guint device_type_i, - const char * subtype, + const char *subtype, NMDeviceFactory *self) { const NMDeviceType device_type = device_type_i; - NMDevice * device = NULL; + NMDevice *device = NULL; NMDeviceState device_state; gboolean is_system_interface = FALSE; @@ -149,8 +149,8 @@ ovsdb_device_removed(NMOvsdb * ovsdb, return; if (device_type == NM_DEVICE_TYPE_OVS_INTERFACE && nm_streq0(subtype, "system")) { - NMDevice * d; - const CList * list; + NMDevice *d; + const CList *list; NMSettingOvsInterface *s_ovs_int; /* The device associated to an OVS system interface can be of @@ -165,15 +165,6 @@ ovsdb_device_removed(NMOvsdb * ovsdb, continue; if (!nm_streq0(nm_setting_ovs_interface_get_interface_type(s_ovs_int), "system")) continue; - /* Failing the system interface device is almost always the right - * thing to do when the ovsdb entry is removed. However, to avoid - * that a late device-removed signal tears down a different, - * newly-activated connection, let's also check that we have a master. - * Or in alternative, that the device is assumed/external: in such - * case it's always fine to fail the device. - */ - if (!nm_device_get_master(d) && !nm_device_sys_iface_state_is_external_or_assume(d)) - continue; device = d; } @@ -195,22 +186,23 @@ ovsdb_device_removed(NMOvsdb * ovsdb, } /* OVS system interfaces still exist even without the ovsdb entry */ - if (!is_system_interface && device_state == NM_DEVICE_STATE_UNMANAGED) { + if (!is_system_interface + && (device_state == NM_DEVICE_STATE_UNMANAGED + || device_state == NM_DEVICE_STATE_UNAVAILABLE)) nm_device_unrealize(device, TRUE, NULL); - } } static void -ovsdb_interface_failed(NMOvsdb * ovsdb, - const char * name, - const char * connection_uuid, - const char * error, +ovsdb_interface_failed(NMOvsdb *ovsdb, + const char *name, + const char *connection_uuid, + const char *error, NMDeviceFactory *self) { - NMDevice * device = NULL; - NMSettingsConnection * connection = NULL; - NMConnection * c; - const char * type; + NMDevice *device = NULL; + NMSettingsConnection *connection = NULL; + NMConnection *c; + const char *type; NMSettingOvsInterface *s_ovs_int; gboolean is_patch = FALSE; gboolean ignore; @@ -280,14 +272,14 @@ start(NMDeviceFactory *self) } static NMDevice * -create_device(NMDeviceFactory * self, - const char * iface, +create_device(NMDeviceFactory *self, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { NMDeviceType device_type = NM_DEVICE_TYPE_UNKNOWN; - const char * connection_type = NULL; + const char *connection_type = NULL; if (g_strcmp0(iface, "ovs-system") == 0) { *out_ignore = TRUE; diff --git a/src/core/devices/ovs/nm-ovsdb.c b/src/core/devices/ovs/nm-ovsdb.c index e5673347..7c45e0e4 100644 --- a/src/core/devices/ovs/nm-ovsdb.c +++ b/src/core/devices/ovs/nm-ovsdb.c @@ -30,34 +30,34 @@ #endif typedef struct { - char * port_uuid; - char * name; - char * connection_uuid; + char *port_uuid; + char *name; + char *connection_uuid; GPtrArray *interfaces; /* interface uuids */ - GArray * external_ids; + GArray *external_ids; } OpenvswitchPort; typedef struct { - char * bridge_uuid; - char * name; - char * connection_uuid; + char *bridge_uuid; + char *name; + char *connection_uuid; GPtrArray *ports; /* port uuids */ - GArray * external_ids; + GArray *external_ids; } OpenvswitchBridge; typedef struct { - char * interface_uuid; - char * name; - char * type; - char * connection_uuid; + char *interface_uuid; + char *name; + char *type; + char *connection_uuid; GArray *external_ids; } OpenvswitchInterface; /*****************************************************************************/ typedef void (*OvsdbMethodCallback)(NMOvsdb *self, - json_t * response, - GError * error, + json_t *response, + GError *error, gpointer user_data); typedef enum { @@ -77,27 +77,27 @@ typedef union { NMConnection *bridge; NMConnection *port; NMConnection *interface; - NMDevice * bridge_device; - NMDevice * interface_device; + NMDevice *bridge_device; + NMDevice *interface_device; } add_interface; struct { char *ifname; } del_interface; struct { - char * ifname; + char *ifname; guint32 mtu; } set_interface_mtu; struct { NMDeviceType device_type; - char * ifname; - char * connection_uuid; - GHashTable * exid_old; - GHashTable * exid_new; + char *ifname; + char *connection_uuid; + GHashTable *exid_old; + GHashTable *exid_new; } set_external_ids; } OvsdbMethodPayload; typedef struct { - NMOvsdb * self; + NMOvsdb *self; CList calls_lst; guint64 call_id; OvsdbCommand command; @@ -120,11 +120,11 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct { GSocketConnection *conn; - GCancellable * conn_cancellable; + GCancellable *conn_cancellable; char buf[4096]; /* Input buffer */ size_t bufp; /* Last decoded byte in the input buffer. */ - GString * input; /* JSON stream waiting for decoding. */ - GString * output; /* JSON stream to be sent. */ + GString *input; /* JSON stream waiting for decoding. */ + GString *output; /* JSON stream to be sent. */ guint64 call_id_counter; CList calls_lst_head; @@ -132,7 +132,7 @@ typedef struct { GHashTable *interfaces; /* interface uuid => OpenvswitchInterface */ GHashTable *ports; /* port uuid => OpenvswitchPort */ GHashTable *bridges; /* bridge uuid => OpenvswitchBridge */ - char * db_uuid; + char *db_uuid; guint num_failures; guint num_pending_deletions; bool ready : 1; @@ -328,25 +328,25 @@ _free_interface(OpenvswitchInterface *ovs_interface) /*****************************************************************************/ static void -_signal_emit_device_added(NMOvsdb * self, - const char * name, +_signal_emit_device_added(NMOvsdb *self, + const char *name, NMDeviceType device_type, - const char * device_subtype) + const char *device_subtype) { g_signal_emit(self, signals[DEVICE_ADDED], 0, name, (guint) device_type, device_subtype); } static void -_signal_emit_device_removed(NMOvsdb * self, - const char * name, +_signal_emit_device_removed(NMOvsdb *self, + const char *name, NMDeviceType device_type, - const char * device_subtype) + const char *device_subtype) { g_signal_emit(self, signals[DEVICE_REMOVED], 0, name, (guint) device_type, device_subtype); } static void -_signal_emit_interface_failed(NMOvsdb * self, +_signal_emit_interface_failed(NMOvsdb *self, const char *name, const char *connection_uuid, const char *error) @@ -363,14 +363,14 @@ _signal_emit_interface_failed(NMOvsdb * self, * there's no command pending completion. */ static void -ovsdb_call_method(NMOvsdb * self, +ovsdb_call_method(NMOvsdb *self, OvsdbMethodCallback callback, gpointer user_data, gboolean add_first, OvsdbCommand command, const OvsdbMethodPayload *payload) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); OvsdbMethodCall *call; /* Ensure we're not unsynchronized before we queue the method call. */ @@ -653,11 +653,11 @@ _set_port_interfaces(json_t *params, const char *ifname, json_t *new_interfaces) static json_t * _j_create_external_ids_array_new(NMConnection *connection) { - json_t * array; - const char *const * external_ids = NULL; + json_t *array; + const char *const *external_ids = NULL; guint n_external_ids = 0; guint i; - const char * uuid; + const char *uuid; NMSettingOvsExternalIDs *s_exid; nm_assert(NM_IS_CONNECTION(connection)); @@ -688,10 +688,10 @@ _j_create_external_ids_array_update(const char *connection_uuid, GHashTable *exid_new) { GHashTableIter iter; - json_t * mutations; - json_t * array; - const char * key; - const char * val; + json_t *mutations; + json_t *array; + const char *key; + const char *val; nm_assert(connection_uuid); @@ -741,21 +741,24 @@ _j_create_external_ids_array_update(const char *connection_uuid, /** * _insert_interface: * - * Returns an commands that adds new interface from a given connection. + * Returns a command that adds new interface from a given connection. */ static void -_insert_interface(json_t * params, +_insert_interface(json_t *params, NMConnection *interface, - NMDevice * interface_device, - const char * cloned_mac) + NMDevice *interface_device, + const char *cloned_mac) { - const char * type = NULL; + const char *type = NULL; NMSettingOvsInterface *s_ovs_iface; - NMSettingOvsDpdk * s_ovs_dpdk; - NMSettingOvsPatch * s_ovs_patch; - const char * dpdk_devargs; - json_t * options = json_array(); - json_t * row; + NMSettingOvsDpdk *s_ovs_dpdk; + const char *devargs; + guint32 n_rxq; + char sbuf[64]; + json_t *dpdk_array; + NMSettingOvsPatch *s_ovs_patch; + json_t *options = json_array(); + json_t *row; guint32 mtu = 0; s_ovs_iface = nm_connection_get_setting_ovs_interface(interface); @@ -778,11 +781,21 @@ _insert_interface(json_t * params, s_ovs_patch = nm_connection_get_setting_ovs_patch(interface); if (s_ovs_dpdk) { - dpdk_devargs = nm_setting_ovs_dpdk_get_devargs(s_ovs_dpdk); - if (dpdk_devargs) - json_array_append_new(options, json_pack("[[s, s]]", "dpdk-devargs", dpdk_devargs)); - else - json_array_append_new(options, json_array()); + devargs = nm_setting_ovs_dpdk_get_devargs(s_ovs_dpdk); + n_rxq = nm_setting_ovs_dpdk_get_n_rxq(s_ovs_dpdk); + + dpdk_array = json_array(); + + if (devargs) + json_array_append_new(dpdk_array, json_pack("[s,s]", "dpdk-devargs", devargs)); + + if (n_rxq != 0) { + json_array_append_new(dpdk_array, + json_pack("[s,s]", "n_rxq", nm_sprintf_buf(sbuf, "%u", n_rxq))); + } + + json_array_append_new(options, dpdk_array); + } else if (s_ovs_patch) { json_array_append_new( options, @@ -828,13 +841,13 @@ static void _insert_port(json_t *params, NMConnection *port, json_t *new_interfaces) { NMSettingOvsPort *s_ovs_port; - const char * vlan_mode = NULL; + const char *vlan_mode = NULL; guint tag = 0; - const char * lacp = NULL; - const char * bond_mode = NULL; + const char *lacp = NULL; + const char *bond_mode = NULL; guint bond_updelay = 0; guint bond_downdelay = 0; - json_t * row; + json_t *row; s_ovs_port = nm_connection_get_setting_ovs_port(port); @@ -885,19 +898,19 @@ _insert_port(json_t *params, NMConnection *port, json_t *new_interfaces) * Returns an commands that adds new bridge from a given connection. */ static void -_insert_bridge(json_t * params, +_insert_bridge(json_t *params, NMConnection *bridge, - NMDevice * bridge_device, - json_t * new_ports, - const char * cloned_mac) + NMDevice *bridge_device, + json_t *new_ports, + const char *cloned_mac) { NMSettingOvsBridge *s_ovs_bridge; - const char * fail_mode = NULL; + const char *fail_mode = NULL; gboolean mcast_snooping_enable = FALSE; gboolean rstp_enable = FALSE; gboolean stp_enable = FALSE; - const char * datapath_type = NULL; - json_t * row; + const char *datapath_type = NULL; + json_t *row; s_ovs_bridge = nm_connection_get_setting_ovs_bridge(bridge); @@ -977,24 +990,24 @@ _inc_next_cfg(const char *db_uuid) * a parent @port and @bridge if needed. */ static void -_add_interface(NMOvsdb * self, - json_t * params, +_add_interface(NMOvsdb *self, + json_t *params, NMConnection *bridge, NMConnection *port, NMConnection *interface, - NMDevice * bridge_device, - NMDevice * interface_device) + NMDevice *bridge_device, + NMDevice *interface_device) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - GHashTableIter iter; - const char * port_uuid; - const char * interface_uuid; - const char * bridge_name; - const char * port_name; - const char * interface_name; - OpenvswitchBridge * ovs_bridge = NULL; - OpenvswitchPort * ovs_port = NULL; - OpenvswitchInterface *ovs_interface = NULL; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + GHashTableIter iter; + const char *port_uuid; + const char *interface_uuid; + const char *bridge_name; + const char *port_name; + const char *interface_name; + OpenvswitchBridge *ovs_bridge = NULL; + OpenvswitchPort *ovs_port = NULL; + OpenvswitchInterface *ovs_interface = NULL; nm_auto_decref_json json_t *bridges = NULL; nm_auto_decref_json json_t *new_bridges = NULL; nm_auto_decref_json json_t *ports = NULL; @@ -1003,9 +1016,9 @@ _add_interface(NMOvsdb * self, nm_auto_decref_json json_t *new_interfaces = NULL; gboolean has_interface = FALSE; gboolean interface_is_local; - gs_free char * bridge_cloned_mac = NULL; - gs_free char * interface_cloned_mac = NULL; - GError * error = NULL; + gs_free char *bridge_cloned_mac = NULL; + gs_free char *interface_cloned_mac = NULL; + GError *error = NULL; int pi; int ii; @@ -1162,13 +1175,13 @@ _add_interface(NMOvsdb * self, static void _delete_interface(NMOvsdb *self, json_t *params, const char *ifname) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - GHashTableIter iter; - char * port_uuid; - char * interface_uuid; - OpenvswitchBridge * ovs_bridge; - OpenvswitchPort * ovs_port; - OpenvswitchInterface *ovs_interface; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + GHashTableIter iter; + char *port_uuid; + char *interface_uuid; + OpenvswitchBridge *ovs_bridge; + OpenvswitchPort *ovs_port; + OpenvswitchInterface *ovs_interface; nm_auto_decref_json json_t *bridges = NULL; nm_auto_decref_json json_t *new_bridges = NULL; gboolean bridges_changed; @@ -1272,9 +1285,9 @@ _delete_interface(NMOvsdb *self, json_t *params, const char *ifname) static void ovsdb_next_command(NMOvsdb *self) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - OvsdbMethodCall * call; - char * cmd; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + OvsdbMethodCall *call; + char *cmd; nm_auto_decref_json json_t *msg = NULL; if (!priv->conn) @@ -1420,9 +1433,9 @@ static void _uuids_to_array_inplace(GPtrArray *array, const json_t *items) { const char *key; - json_t * value; + json_t *value; size_t index = 0; - json_t * set_value; + json_t *set_value; size_t set_index; while (index < json_array_size(items)) { @@ -1475,8 +1488,8 @@ _external_ids_extract(json_t *external_ids, GArray **out_array, const char **out array = json_array_get(external_ids, 1); json_array_foreach (array, index, value) { - const char * key = json_string_value(json_array_get(value, 0)); - const char * val = json_string_value(json_array_get(value, 1)); + const char *key = json_string_value(json_array_get(value, 0)); + const char *val = json_string_value(json_array_get(value, 1)); NMUtilsNamedValue *v; if (!key || !val) @@ -1559,20 +1572,20 @@ static void ovsdb_got_update(NMOvsdb *self, json_t *msg) { NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - json_t * ovs = NULL; - json_t * bridge = NULL; - json_t * port = NULL; - json_t * interface = NULL; - json_t * items; - json_t * external_ids; + json_t *ovs = NULL; + json_t *bridge = NULL; + json_t *port = NULL; + json_t *interface = NULL; + json_t *items; + json_t *external_ids; json_error_t json_error = { 0, }; - void * iter; + void *iter; const char *name; const char *key; const char *type; - json_t * value; + json_t *value; if (json_unpack_ex(msg, &json_error, @@ -1602,10 +1615,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) } json_object_foreach (interface, key, value) { - OpenvswitchInterface *ovs_interface; + OpenvswitchInterface *ovs_interface; gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - json_t * error = NULL; + const char *connection_uuid = NULL; + json_t *error = NULL; int r; r = json_unpack(value, @@ -1726,10 +1739,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) json_object_foreach (port, key, value) { gs_unref_ptrarray GPtrArray *interfaces = NULL; - OpenvswitchPort * ovs_port; - gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - int r; + OpenvswitchPort *ovs_port; + gs_unref_array GArray *external_ids_arr = NULL; + const char *connection_uuid = NULL; + int r; r = json_unpack(value, "{s:{s:s, s:o, s:o}}", @@ -1827,10 +1840,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) json_object_foreach (bridge, key, value) { gs_unref_ptrarray GPtrArray *ports = NULL; - OpenvswitchBridge * ovs_bridge; - gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - int r; + OpenvswitchBridge *ovs_bridge; + gs_unref_array GArray *external_ids_arr = NULL; + const char *connection_uuid = NULL; + int r; r = json_unpack(value, "{s:{s:s, s:o, s:o}}", @@ -1940,9 +1953,9 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) static void ovsdb_got_echo(NMOvsdb *self, json_int_t id, json_t *data) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - nm_auto_decref_json json_t *msg = NULL; - char * reply; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + nm_auto_decref_json json_t *msg = NULL; + char *reply; gboolean output_was_empty; output_was_empty = priv->output->len == 0; @@ -1969,12 +1982,12 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) json_error_t json_error = { 0, }; - json_t * json_id = NULL; + json_t *json_id = NULL; json_int_t id = (json_int_t) -1; const char *method = NULL; - json_t * params = NULL; - json_t * result = NULL; - json_t * error = NULL; + json_t *params = NULL; + json_t *result = NULL; + json_t *error = NULL; if (json_unpack_ex(msg, &json_error, @@ -2020,9 +2033,9 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) } if (id >= 0) { - OvsdbMethodCall *call; + OvsdbMethodCall *call; gs_free_error GError *local = NULL; - gs_free char * msg_as_str = NULL; + gs_free char *msg_as_str = NULL; /* This is a response to a method call. */ if (c_list_is_empty(&priv->calls_lst_head)) { @@ -2078,7 +2091,7 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) static size_t _json_callback(void *buffer, size_t buflen, void *user_data) { - NMOvsdb * self = NM_OVSDB(user_data); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); if (priv->bufp == priv->input->len) { @@ -2102,12 +2115,12 @@ _json_callback(void *buffer, size_t buflen, void *user_data) static void ovsdb_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMOvsdb * self = NM_OVSDB(user_data); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GInputStream * stream = G_INPUT_STREAM(source_object); - GError * error = NULL; + GInputStream *stream = G_INPUT_STREAM(source_object); + GError *error = NULL; gssize size; - json_t * msg; + json_t *msg; json_error_t json_error = { 0, }; @@ -2160,10 +2173,10 @@ ovsdb_read(NMOvsdb *self) static void ovsdb_write_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GOutputStream * stream = G_OUTPUT_STREAM(source_object); - NMOvsdb * self = NM_OVSDB(user_data); + GOutputStream *stream = G_OUTPUT_STREAM(source_object); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GError * error = NULL; + GError *error = NULL; gssize size; size = g_output_stream_write_finish(stream, res, &error); @@ -2188,7 +2201,7 @@ static void ovsdb_write(NMOvsdb *self) { NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GOutputStream * stream; + GOutputStream *stream; if (!priv->output->len) return; @@ -2221,7 +2234,7 @@ ovsdb_write(NMOvsdb *self) static void ovsdb_disconnect(NMOvsdb *self, gboolean retry, gboolean is_disposing) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); OvsdbMethodCall *call; nm_assert(!retry || !is_disposing); @@ -2278,8 +2291,8 @@ _check_ready(NMOvsdb *self) static void _del_initial_iface_cb(GError *error, gpointer user_data) { - NMOvsdb * self; - gs_free char * ifname = NULL; + NMOvsdb *self; + gs_free char *ifname = NULL; NMOvsdbPrivate *priv; nm_utils_user_data_unpack(user_data, &self, &ifname); @@ -2305,9 +2318,9 @@ _del_initial_iface_cb(GError *error, gpointer user_data) static void ovsdb_cleanup_initial_interfaces(NMOvsdb *self) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); const OpenvswitchInterface *interface; - NMUtilsUserData * data; + NMUtilsUserData *data; GHashTableIter iter; if (priv->ready || priv->num_pending_deletions != 0) @@ -2352,9 +2365,9 @@ _monitor_bridges_cb(NMOvsdb *self, json_t *result, GError *error, gpointer user_ static void _ovsdb_connect_complete_with_fd(NMOvsdb *self, int fd_take) { - NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); gs_unref_object GSocket *socket = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; socket = g_socket_new_from_fd(nm_steal_fd(&fd_take), &error); if (!socket) { @@ -2374,7 +2387,7 @@ static void _ovsdb_connect_priv_helper_cb(int fd_take, GError *error, gpointer user_data) { nm_auto_close int fd = fd_take; - NMOvsdb * self; + NMOvsdb *self; if (nm_utils_error_is_cancelled(error)) return; @@ -2394,9 +2407,9 @@ _ovsdb_connect_priv_helper_cb(int fd_take, GError *error, gpointer user_data) static void _ovsdb_connect_idle(gpointer user_data, GCancellable *cancellable) { - NMOvsdb * self; - NMOvsdbPrivate * priv; - nm_auto_close int fd = -1; + NMOvsdb *self; + NMOvsdbPrivate *priv; + nm_auto_close int fd = -1; gs_free_error GError *error = NULL; if (g_cancellable_is_cancelled(cancellable)) @@ -2468,11 +2481,11 @@ typedef struct { static void _transact_cb(NMOvsdb *self, json_t *result, GError *error, gpointer user_data) { - OvsdbCall * call = user_data; + OvsdbCall *call = user_data; const char *err; const char *err_details; size_t index; - json_t * value; + json_t *value; if (error) goto out; @@ -2516,12 +2529,12 @@ nm_ovsdb_is_ready(NMOvsdb *self) } void -nm_ovsdb_add_interface(NMOvsdb * self, - NMConnection * bridge, - NMConnection * port, - NMConnection * interface, - NMDevice * bridge_device, - NMDevice * interface_device, +nm_ovsdb_add_interface(NMOvsdb *self, + NMConnection *bridge, + NMConnection *port, + NMConnection *interface, + NMDevice *bridge_device, + NMDevice *interface_device, NMOvsdbCallback callback, gpointer user_data) { @@ -2538,8 +2551,8 @@ nm_ovsdb_add_interface(NMOvsdb * self, } void -nm_ovsdb_del_interface(NMOvsdb * self, - const char * ifname, +nm_ovsdb_del_interface(NMOvsdb *self, + const char *ifname, NMOvsdbCallback callback, gpointer user_data) { @@ -2552,8 +2565,8 @@ nm_ovsdb_del_interface(NMOvsdb * self, } void -nm_ovsdb_set_interface_mtu(NMOvsdb * self, - const char * ifname, +nm_ovsdb_set_interface_mtu(NMOvsdb *self, + const char *ifname, guint32 mtu, NMOvsdbCallback callback, gpointer user_data) @@ -2567,10 +2580,10 @@ nm_ovsdb_set_interface_mtu(NMOvsdb * self, } void -nm_ovsdb_set_external_ids(NMOvsdb * self, +nm_ovsdb_set_external_ids(NMOvsdb *self, NMDeviceType device_type, - const char * ifname, - const char * connection_uuid, + const char *ifname, + const char *connection_uuid, NMSettingOvsExternalIDs *s_exid_old, NMSettingOvsExternalIDs *s_exid_new) { @@ -2618,7 +2631,7 @@ nm_ovsdb_init(NMOvsdb *self) static void dispose(GObject *object) { - NMOvsdb * self = NM_OVSDB(object); + NMOvsdb *self = NM_OVSDB(object); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); ovsdb_disconnect(self, FALSE, TRUE); diff --git a/src/core/devices/ovs/nm-ovsdb.h b/src/core/devices/ovs/nm-ovsdb.h index d0b4d19d..a50db45a 100644 --- a/src/core/devices/ovs/nm-ovsdb.h +++ b/src/core/devices/ovs/nm-ovsdb.h @@ -27,32 +27,32 @@ NMOvsdb *nm_ovsdb_get(void); GType nm_ovsdb_get_type(void); -void nm_ovsdb_add_interface(NMOvsdb * self, - NMConnection * bridge, - NMConnection * port, - NMConnection * interface, - NMDevice * bridge_device, - NMDevice * interface_device, +void nm_ovsdb_add_interface(NMOvsdb *self, + NMConnection *bridge, + NMConnection *port, + NMConnection *interface, + NMDevice *bridge_device, + NMDevice *interface_device, NMOvsdbCallback callback, gpointer user_data); -void nm_ovsdb_del_interface(NMOvsdb * self, - const char * ifname, +void nm_ovsdb_del_interface(NMOvsdb *self, + const char *ifname, NMOvsdbCallback callback, gpointer user_data); -void nm_ovsdb_set_interface_mtu(NMOvsdb * self, - const char * ifname, +void nm_ovsdb_set_interface_mtu(NMOvsdb *self, + const char *ifname, guint32 mtu, NMOvsdbCallback callback, gpointer user_data); struct _NMSettingOvsExternalIDs; -void nm_ovsdb_set_external_ids(NMOvsdb * self, +void nm_ovsdb_set_external_ids(NMOvsdb *self, NMDeviceType device_type, - const char * ifname, - const char * connection_uuid, + const char *ifname, + const char *connection_uuid, struct _NMSettingOvsExternalIDs *s_exid_old, struct _NMSettingOvsExternalIDs *s_exid_new); |