diff options
author | Thomas Haller <thaller@redhat.com> | 2023-06-08 14:35:46 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-06-14 10:49:14 +0200 |
commit | cba8eb978492f3cc83cb8a854d526414851dc5e3 (patch) | |
tree | f3b6b7f8cf8cb5a0b40469a075a55c2391c0e200 | |
parent | 5b8e6c01a96c0cc29f7f933a195d75e4a5517919 (diff) |
core: add nm_match_spec_match_type_to_bool() helper to convert enum to boolean
All callers eventually want a boolean instead of a NMMatchSpecMatchType.
I think the NMMatchSpecMatchType enum still has value at the lower
layers, where the enum values are clearer (when reading the code). So
don't drop NMMatchSpecMatchType entirely.
However, let's add nm_match_spec_match_type_to_bool() to convert the
match-type to a boolean to avoid duplicating the code.
-rw-r--r-- | src/core/NetworkManagerUtils.c | 12 | ||||
-rw-r--r-- | src/core/NetworkManagerUtils.h | 2 | ||||
-rw-r--r-- | src/core/devices/nm-device.c | 11 | ||||
-rw-r--r-- | src/core/nm-core-utils.c | 14 | ||||
-rw-r--r-- | src/core/nm-core-utils.h | 2 |
5 files changed, 20 insertions, 21 deletions
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 972bcf0a19..9dac44502e 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -922,17 +922,7 @@ nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, NULL, NULL, match_dhcp_plugin); - - switch (m) { - case NM_MATCH_SPEC_MATCH: - return TRUE; - case NM_MATCH_SPEC_NEG_MATCH: - return FALSE; - case NM_MATCH_SPEC_NO_MATCH: - return no_match_value; - } - nm_assert_not_reached(); - return no_match_value; + return nm_match_spec_match_type_to_bool(m, no_match_value); } /*****************************************************************************/ diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h index c55e6255bc..514d1cc8da 100644 --- a/src/core/NetworkManagerUtils.h +++ b/src/core/NetworkManagerUtils.h @@ -89,6 +89,8 @@ NMConnection *nm_utils_match_connection(NMConnection *const *connections, NMUtilsMatchFilterFunc match_filter_func, gpointer match_filter_data); +/*****************************************************************************/ + int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, const char *match_device_type, const char *match_dhcp_plugin, diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 160963d8ae..352bd26e1c 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -17303,16 +17303,7 @@ nm_device_spec_match_list_full(NMDevice *self, const GSList *specs, int no_match klass->get_s390_subchannels ? klass->get_s390_subchannels(self) : NULL, nm_dhcp_manager_get_config(nm_dhcp_manager_get())); - switch (m) { - case NM_MATCH_SPEC_MATCH: - return TRUE; - case NM_MATCH_SPEC_NEG_MATCH: - return FALSE; - case NM_MATCH_SPEC_NO_MATCH: - return no_match_value; - } - nm_assert_not_reached(); - return no_match_value; + return nm_match_spec_match_type_to_bool(m, no_match_value); } guint diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index f12a731694..e6c4c8cbd6 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -1478,6 +1478,20 @@ nm_match_spec_device(const GSList *specs, return _match_result(has_except, has_not_except, has_match, has_match_except); } +int +nm_match_spec_match_type_to_bool(NMMatchSpecMatchType m, int no_match_value) +{ + switch (m) { + case NM_MATCH_SPEC_MATCH: + return TRUE; + case NM_MATCH_SPEC_NEG_MATCH: + return FALSE; + case NM_MATCH_SPEC_NO_MATCH: + return no_match_value; + } + return nm_assert_unreachable_val(no_match_value); +} + typedef struct { const char *uuid; const char *id; diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index 87d3559e19..bdcaa9b6d2 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -193,6 +193,8 @@ typedef enum { NM_MATCH_SPEC_NEG_MATCH = 2, } NMMatchSpecMatchType; +int nm_match_spec_match_type_to_bool(NMMatchSpecMatchType m, int no_match_value); + NMMatchSpecMatchType nm_match_spec_device(const GSList *specs, const char *interface_name, const char *device_type, |