summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-01-11 11:41:21 +0100
committerThomas Haller <thaller@redhat.com>2023-01-11 12:45:35 +0100
commitf79ecbd34aef33dbc470376e808395e9463ef55b (patch)
treea5f2bee93a3049824f8fdee85e6c23484589e65f
parent064fd6e6b05770246c4ccc132ff59791a016e8e7 (diff)
downloadNetworkManager-f79ecbd34aef33dbc470376e808395e9463ef55b.tar.gz
libnm: move verify() for OVS connection type to separate function
Will be used next.
-rw-r--r--src/libnm-core-impl/nm-setting-ovs-external-ids.c90
-rw-r--r--src/libnm-core-impl/nm-utils-private.h3
2 files changed, 56 insertions, 37 deletions
diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c
index 11c915a59d..d0f9104165 100644
--- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c
+++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c
@@ -118,6 +118,56 @@ nm_setting_ovs_external_ids_check_key(const char *key, GError **error)
return TRUE;
}
+gboolean
+_nm_setting_ovs_verify_connection_type(GType gtype, NMConnection *connection, GError **error)
+{
+ NMSettingConnection *s_con;
+ const char *type;
+ const char *slave_type;
+
+ nm_assert(!connection || NM_IS_CONNECTION(connection));
+ nm_assert(NM_IN_SET(gtype, NM_TYPE_SETTING_OVS_EXTERNAL_IDS));
+ nm_assert(!error || !*error);
+
+ if (!connection) {
+ /* We don't know. It's valid. */
+ return TRUE;
+ }
+
+ type = nm_connection_get_connection_type(connection);
+ if (!type) {
+ NMSetting *s_base;
+
+ s_base = _nm_connection_find_base_type_setting(connection);
+ if (s_base)
+ type = nm_setting_get_name(s_base);
+ }
+ if (NM_IN_STRSET(type,
+ NM_SETTING_OVS_BRIDGE_SETTING_NAME,
+ NM_SETTING_OVS_PORT_SETTING_NAME,
+ NM_SETTING_OVS_INTERFACE_SETTING_NAME))
+ return TRUE;
+
+ if ((s_con = nm_connection_get_setting_connection(connection))
+ && _nm_connection_detect_slave_type_full(s_con,
+ connection,
+ &slave_type,
+ NULL,
+ NULL,
+ NULL,
+ NULL)
+ && nm_streq0(slave_type, NM_SETTING_OVS_PORT_SETTING_NAME))
+ return TRUE;
+
+ g_set_error(error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("OVS %s can only be added to a profile of type OVS "
+ "bridge/port/interface or to OVS system interface"),
+ gtype == NM_TYPE_SETTING_OVS_EXTERNAL_IDS ? "external-ids" : "other-config");
+ return FALSE;
+}
+
/**
* nm_setting_ovs_external_ids_check_val:
* @val: (allow-none): the value to check
@@ -341,44 +391,10 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
- if (connection) {
- NMSettingConnection *s_con;
- const char *type;
- const char *slave_type;
-
- type = nm_connection_get_connection_type(connection);
- if (!type) {
- NMSetting *s_base;
-
- s_base = _nm_connection_find_base_type_setting(connection);
- if (s_base)
- type = nm_setting_get_name(s_base);
- }
- if (NM_IN_STRSET(type,
- NM_SETTING_OVS_BRIDGE_SETTING_NAME,
- NM_SETTING_OVS_PORT_SETTING_NAME,
- NM_SETTING_OVS_INTERFACE_SETTING_NAME))
- goto connection_type_is_good;
-
- if ((s_con = nm_connection_get_setting_connection(connection))
- && _nm_connection_detect_slave_type_full(s_con,
- connection,
- &slave_type,
- NULL,
- NULL,
- NULL,
- NULL)
- && nm_streq0(slave_type, NM_SETTING_OVS_PORT_SETTING_NAME))
- goto connection_type_is_good;
-
- g_set_error_literal(error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("OVS external IDs can only be added to a profile of type OVS "
- "bridge/port/interface or to OVS system interface"));
+ if (!_nm_setting_ovs_verify_connection_type(NM_TYPE_SETTING_OVS_EXTERNAL_IDS,
+ connection,
+ error))
return FALSE;
- }
-connection_type_is_good:
return TRUE;
}
diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h
index a89a466983..e2e1aff789 100644
--- a/src/libnm-core-impl/nm-utils-private.h
+++ b/src/libnm-core-impl/nm-utils-private.h
@@ -70,4 +70,7 @@ const char *const *nmtst_system_encodings_for_lang(const char *lang);
const char *const *nmtst_system_encodings_get_default(void);
const char *const *nmtst_system_encodings_get(void);
+gboolean
+_nm_setting_ovs_verify_connection_type(GType gtype, NMConnection *connection, GError **error);
+
#endif