diff options
Diffstat (limited to 'clients/common')
| -rw-r--r-- | clients/common/nm-client-utils.c | 1382 | ||||
| -rw-r--r-- | clients/common/nm-client-utils.h | 55 | ||||
| -rw-r--r-- | clients/common/nm-meta-setting-access.c | 1017 | ||||
| -rw-r--r-- | clients/common/nm-meta-setting-access.h | 117 | ||||
| -rw-r--r-- | clients/common/nm-meta-setting-desc.c | 14589 | ||||
| -rw-r--r-- | clients/common/nm-meta-setting-desc.h | 729 | ||||
| -rw-r--r-- | clients/common/nm-polkit-listener.c | 1516 | ||||
| -rw-r--r-- | clients/common/nm-polkit-listener.h | 34 | ||||
| -rw-r--r-- | clients/common/nm-secret-agent-simple.c | 2224 | ||||
| -rw-r--r-- | clients/common/nm-secret-agent-simple.h | 58 | ||||
| -rw-r--r-- | clients/common/nm-vpn-helpers.c | 1500 | ||||
| -rw-r--r-- | clients/common/nm-vpn-helpers.h | 31 | ||||
| -rw-r--r-- | clients/common/qrcodegen.c | 1634 | ||||
| -rw-r--r-- | clients/common/qrcodegen.h | 149 | ||||
| -rw-r--r-- | clients/common/settings-docs.h | 42 | ||||
| -rw-r--r-- | clients/common/settings-docs.h.in | 42 | ||||
| -rw-r--r-- | clients/common/tests/test-clients-common.c | 564 | ||||
| -rw-r--r-- | clients/common/tests/test-libnm-core-aux.c | 424 |
18 files changed, 13217 insertions, 12890 deletions
diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index d3a02161..e3d3c46a 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2017 Red Hat, Inc. */ @@ -17,41 +17,36 @@ /*****************************************************************************/ static int -_nmc_objects_sort_by_path_cmp (gconstpointer pa, gconstpointer pb, gpointer user_data) +_nmc_objects_sort_by_path_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) { - NMObject *a = *((NMObject **) pa); - NMObject *b = *((NMObject **) pb); + NMObject *a = *((NMObject **) pa); + NMObject *b = *((NMObject **) pb); - NM_CMP_SELF (a, b); - NM_CMP_RETURN (nm_utils_dbus_path_cmp (nm_object_get_path (a), - nm_object_get_path (b))); - return 0; + NM_CMP_SELF(a, b); + NM_CMP_RETURN(nm_utils_dbus_path_cmp(nm_object_get_path(a), nm_object_get_path(b))); + return 0; } const NMObject ** -nmc_objects_sort_by_path (const NMObject *const* objs, gssize len) +nmc_objects_sort_by_path(const NMObject *const *objs, gssize len) { - const NMObject **arr; - gsize i, l; - - if (len < 0) - l = NM_PTRARRAY_LEN (objs); - else - l = len; - - arr = g_new (const NMObject *, l + 1); - for (i = 0; i < l; i++) - arr[i] = objs[i]; - arr[l] = NULL; - - if (l > 1) { - g_qsort_with_data (arr, - l, - sizeof (gpointer), - _nmc_objects_sort_by_path_cmp, - NULL); - } - return arr; + const NMObject **arr; + gsize i, l; + + if (len < 0) + l = NM_PTRARRAY_LEN(objs); + else + l = len; + + arr = g_new(const NMObject *, l + 1); + for (i = 0; i < l; i++) + arr[i] = objs[i]; + arr[l] = NULL; + + if (l > 1) { + g_qsort_with_data(arr, l, sizeof(gpointer), _nmc_objects_sort_by_path_cmp, NULL); + } + return arr; } /*****************************************************************************/ @@ -60,100 +55,117 @@ nmc_objects_sort_by_path (const NMObject *const* objs, gssize len) * If required, the resulting number is checked to be in the <min,max> range. */ static gboolean -nmc_string_to_uint_base (const char *str, - int base, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value) +nmc_string_to_uint_base(const char * str, + int base, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value) { - char *end; - unsigned long int tmp; - - if (!str || !str[0]) - return FALSE; - - /* FIXME: don't use this function, replace by _nm_utils_ascii_str_to_int64() */ - errno = 0; - tmp = strtoul (str, &end, base); - if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { - return FALSE; - } - *value = tmp; - return TRUE; + char * end; + unsigned long int tmp; + + if (!str || !str[0]) + return FALSE; + + /* FIXME: don't use this function, replace by _nm_utils_ascii_str_to_int64() */ + errno = 0; + tmp = strtoul(str, &end, base); + if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { + return FALSE; + } + *value = tmp; + return TRUE; } gboolean -nmc_string_to_uint (const char *str, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value) +nmc_string_to_uint(const char * str, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value) { - return nmc_string_to_uint_base (str, 10, range_check, min, max, value); + return nmc_string_to_uint_base(str, 10, range_check, min, max, value); } gboolean -nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error) +nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error) { - const char *s_true[] = { "true", "yes", "on", "1", NULL }; - const char *s_false[] = { "false", "no", "off", "0", NULL }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (g_strcmp0 (str, "o") == 0) { - g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by - * the user, the second %s a list of compatible values. - */ - _("'%s' is ambiguous (%s)"), str, "on x off"); - return FALSE; - } - - if (nmc_string_is_valid (str, s_true, NULL)) - *val_bool = TRUE; - else if (nmc_string_is_valid (str, s_false, NULL)) - *val_bool = FALSE; - else { - g_set_error (error, 1, 0, - _("'%s' is not valid; use [%s] or [%s]"), - str, "true, yes, on", "false, no, off"); - return FALSE; - } - return TRUE; + const char *s_true[] = {"true", "yes", "on", "1", NULL}; + const char *s_false[] = {"false", "no", "off", "0", NULL}; + + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (g_strcmp0(str, "o") == 0) { + g_set_error(error, + 1, + 0, + /* TRANSLATORS: the first %s is the partial value entered by + * the user, the second %s a list of compatible values. + */ + _("'%s' is ambiguous (%s)"), + str, + "on x off"); + return FALSE; + } + + if (nmc_string_is_valid(str, s_true, NULL)) + *val_bool = TRUE; + else if (nmc_string_is_valid(str, s_false, NULL)) + *val_bool = FALSE; + else { + g_set_error(error, + 1, + 0, + _("'%s' is not valid; use [%s] or [%s]"), + str, + "true, yes, on", + "false, no, off"); + return FALSE; + } + return TRUE; } gboolean -nmc_string_to_ternary (const char *str, NMTernary *val, GError **error) +nmc_string_to_ternary(const char *str, NMTernary *val, GError **error) { - const char *s_true[] = { "true", "yes", "on", NULL }; - const char *s_false[] = { "false", "no", "off", NULL }; - const char *s_unknown[] = { "unknown", NULL }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (g_strcmp0 (str, "o") == 0) { - g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by - * the user, the second %s a list of compatible values. - */ - _("'%s' is ambiguous (%s)"), str, "on x off"); - return FALSE; - } - - if (nmc_string_is_valid (str, s_true, NULL)) - *val = NM_TERNARY_TRUE; - else if (nmc_string_is_valid (str, s_false, NULL)) - *val = NM_TERNARY_FALSE; - else if (nmc_string_is_valid (str, s_unknown, NULL)) - *val = NM_TERNARY_DEFAULT; - else { - g_set_error (error, 1, 0, - _("'%s' is not valid; use [%s], [%s] or [%s]"), - str, "true, yes, on", "false, no, off", "unknown"); - return FALSE; - } - return TRUE; + const char *s_true[] = {"true", "yes", "on", NULL}; + const char *s_false[] = {"false", "no", "off", NULL}; + const char *s_unknown[] = {"unknown", NULL}; + + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (g_strcmp0(str, "o") == 0) { + g_set_error(error, + 1, + 0, + /* TRANSLATORS: the first %s is the partial value entered by + * the user, the second %s a list of compatible values. + */ + _("'%s' is ambiguous (%s)"), + str, + "on x off"); + return FALSE; + } + + if (nmc_string_is_valid(str, s_true, NULL)) + *val = NM_TERNARY_TRUE; + else if (nmc_string_is_valid(str, s_false, NULL)) + *val = NM_TERNARY_FALSE; + else if (nmc_string_is_valid(str, s_unknown, NULL)) + *val = NM_TERNARY_DEFAULT; + else { + g_set_error(error, + 1, + 0, + _("'%s' is not valid; use [%s], [%s] or [%s]"), + str, + "true, yes, on", + "false, no, off", + "unknown"); + return FALSE; + } + return TRUE; } /* @@ -163,349 +175,411 @@ nmc_string_to_ternary (const char *str, NMTernary *val, GError **error) * On failure: error->code : 0 - string not found; 1 - string is ambiguous */ const char * -nmc_string_is_valid (const char *input, const char **allowed, GError **error) +nmc_string_is_valid(const char *input, const char **allowed, GError **error) { - const char **p; - size_t input_ln, p_len; - const char *partial_match = NULL; - gboolean ambiguous = FALSE; - - g_return_val_if_fail (!error || !*error, NULL); - - if (!input || !*input) - goto finish; - - input_ln = strlen (input); - for (p = allowed; p && *p; p++) { - p_len = strlen (*p); - if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { - if (input_ln == p_len) - return *p; - if (!partial_match) - partial_match = *p; - else - ambiguous = TRUE; - } - } - - if (ambiguous) { - GString *candidates = g_string_new (""); - - for (p = allowed; *p; p++) { - if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { - if (candidates->len > 0) - g_string_append (candidates, ", "); - g_string_append (candidates, *p); - } - } - g_set_error (error, 1, 1, _("'%s' is ambiguous: %s"), - input, candidates->str); - g_string_free (candidates, TRUE); - return NULL; - } + const char **p; + size_t input_ln, p_len; + const char * partial_match = NULL; + gboolean ambiguous = FALSE; + + g_return_val_if_fail(!error || !*error, NULL); + + if (!input || !*input) + goto finish; + + input_ln = strlen(input); + for (p = allowed; p && *p; p++) { + p_len = strlen(*p); + if (g_ascii_strncasecmp(input, *p, input_ln) == 0) { + if (input_ln == p_len) + return *p; + if (!partial_match) + partial_match = *p; + else + ambiguous = TRUE; + } + } + + if (ambiguous) { + GString *candidates = g_string_new(""); + + for (p = allowed; *p; p++) { + if (g_ascii_strncasecmp(input, *p, input_ln) == 0) { + if (candidates->len > 0) + g_string_append(candidates, ", "); + g_string_append(candidates, *p); + } + } + g_set_error(error, 1, 1, _("'%s' is ambiguous: %s"), input, candidates->str); + g_string_free(candidates, TRUE); + return NULL; + } finish: - if (!partial_match) { - char *valid_vals = g_strjoinv (", ", (char **) allowed); + if (!partial_match) { + char *valid_vals = g_strjoinv(", ", (char **) allowed); - if (!input || !*input) - g_set_error (error, 1, 0, _("missing name, try one of [%s]"), valid_vals); - else - g_set_error (error, 1, 0, _("'%s' not among [%s]"), input, valid_vals); + if (!input || !*input) + g_set_error(error, 1, 0, _("missing name, try one of [%s]"), valid_vals); + else + g_set_error(error, 1, 0, _("'%s' not among [%s]"), input, valid_vals); - g_free (valid_vals); - } + g_free(valid_vals); + } - return partial_match; + return partial_match; } gboolean -matches (const char *cmd, const char *pattern) +matches(const char *cmd, const char *pattern) { - size_t len = strlen (cmd); - if (!len || len > strlen (pattern)) - return FALSE; - return memcmp (pattern, cmd, len) == 0; + size_t len = strlen(cmd); + if (!len || len > strlen(pattern)) + return FALSE; + return memcmp(pattern, cmd, len) == 0; } const char * -nmc_bond_validate_mode (const char *mode, GError **error) +nmc_bond_validate_mode(const char *mode, GError **error) { - unsigned long mode_int; - static const char *valid_modes[] = { "balance-rr", - "active-backup", - "balance-xor", - "broadcast", - "802.3ad", - "balance-tlb", - "balance-alb", - NULL }; - if (nmc_string_to_uint (mode, TRUE, 0, 6, &mode_int)) { - /* Translate bonding mode numbers to mode names: - * https://www.kernel.org/doc/Documentation/networking/bonding.txt - */ - return valid_modes[mode_int]; - } else - return nmc_string_is_valid (mode, valid_modes, error); + unsigned long mode_int; + static const char *valid_modes[] = {"balance-rr", + "active-backup", + "balance-xor", + "broadcast", + "802.3ad", + "balance-tlb", + "balance-alb", + NULL}; + if (nmc_string_to_uint(mode, TRUE, 0, 6, &mode_int)) { + /* Translate bonding mode numbers to mode names: + * https://www.kernel.org/doc/Documentation/networking/bonding.txt + */ + return valid_modes[mode_int]; + } else + return nmc_string_is_valid(mode, valid_modes, error); } -NM_UTILS_LOOKUP_STR_DEFINE (nmc_device_state_to_string, NMDeviceState, - NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_UNMANAGED, N_("unmanaged")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_UNAVAILABLE, N_("unavailable")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_DISCONNECTED, N_("disconnected")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_PREPARE, N_("connecting (prepare)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_CONFIG, N_("connecting (configuring)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_NEED_AUTH, N_("connecting (need authentication)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CONFIG, N_("connecting (getting IP configuration)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CHECK, N_("connecting (checking IP connectivity)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_SECONDARIES, N_("connecting (starting secondary connections)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_ACTIVATED, N_("connected")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_DEACTIVATING, N_("deactivating")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_FAILED, N_("connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_UNKNOWN, N_("unknown")), -) - -static -NM_UTILS_LOOKUP_STR_DEFINE (_device_state_to_string, NMDeviceState, - NM_UTILS_LOOKUP_DEFAULT (NULL), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_PREPARE, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_CONFIG, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_NEED_AUTH, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CONFIG, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CHECK, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_SECONDARIES, N_("connecting (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_ACTIVATED, N_("connected (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_DEACTIVATING, N_("deactivating (externally)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_FAILED, N_("deactivating (externally)")), - NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER (), -) +NM_UTILS_LOOKUP_STR_DEFINE( + nmc_device_state_to_string, + NMDeviceState, + NM_UTILS_LOOKUP_DEFAULT(N_("unknown")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_UNMANAGED, N_("unmanaged")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_UNAVAILABLE, N_("unavailable")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_DISCONNECTED, N_("disconnected")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_PREPARE, N_("connecting (prepare)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_CONFIG, N_("connecting (configuring)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_NEED_AUTH, N_("connecting (need authentication)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_IP_CONFIG, N_("connecting (getting IP configuration)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_IP_CHECK, N_("connecting (checking IP connectivity)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_SECONDARIES, + N_("connecting (starting secondary connections)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_ACTIVATED, N_("connected")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_DEACTIVATING, N_("deactivating")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_FAILED, N_("connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_UNKNOWN, N_("unknown")), ); + +static NM_UTILS_LOOKUP_STR_DEFINE( + _device_state_to_string, + NMDeviceState, + NM_UTILS_LOOKUP_DEFAULT(NULL), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_PREPARE, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_CONFIG, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_NEED_AUTH, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_IP_CONFIG, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_IP_CHECK, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_SECONDARIES, N_("connecting (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_ACTIVATED, N_("connected (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_DEACTIVATING, N_("deactivating (externally)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_FAILED, N_("deactivating (externally)")), + NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER(), ); const char * -nmc_device_state_to_string_with_external (NMDevice *device) +nmc_device_state_to_string_with_external(NMDevice *device) { - NMActiveConnection *ac; - NMDeviceState state; - const char *s; + NMActiveConnection *ac; + NMDeviceState state; + const char * s; - state = nm_device_get_state (device); + state = nm_device_get_state(device); - if ( (ac = nm_device_get_active_connection (device)) - && NM_FLAGS_HAS (nm_active_connection_get_state_flags (ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL) - && (s = _device_state_to_string (state))) - return s; + if ((ac = nm_device_get_active_connection(device)) + && NM_FLAGS_HAS(nm_active_connection_get_state_flags(ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL) + && (s = _device_state_to_string(state))) + return s; - return nmc_device_state_to_string (state); + return nmc_device_state_to_string(state); } -NM_UTILS_LOOKUP_STR_DEFINE (nmc_device_metered_to_string, NMMetered, - NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), - NM_UTILS_LOOKUP_ITEM (NM_METERED_YES, N_("yes")), - NM_UTILS_LOOKUP_ITEM (NM_METERED_NO, N_("no")), - NM_UTILS_LOOKUP_ITEM (NM_METERED_GUESS_YES, N_("yes (guessed)")), - NM_UTILS_LOOKUP_ITEM (NM_METERED_GUESS_NO, N_("no (guessed)")), - NM_UTILS_LOOKUP_ITEM (NM_METERED_UNKNOWN, N_("unknown")), -) - -NM_UTILS_LOOKUP_STR_DEFINE (nmc_device_reason_to_string, NMDeviceStateReason, - /* TRANSLATORS: Unknown reason for a device state change (NMDeviceStateReason) */ - NM_UTILS_LOOKUP_DEFAULT (N_("Unknown")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_NONE, N_("No reason given")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_UNKNOWN, N_("Unknown error")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_NOW_MANAGED, N_("Device is now managed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_NOW_UNMANAGED, N_("Device is now unmanaged")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_CONFIG_FAILED, N_("The device could not be readied for configuration")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, N_("IP configuration could not be reserved (no available address, timeout, etc.)")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED, N_("The IP configuration is no longer valid")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_NO_SECRETS, N_("Secrets were required, but not provided")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT, N_("802.1X supplicant disconnected")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED, N_("802.1X supplicant configuration failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED, N_("802.1X supplicant failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT, N_("802.1X supplicant took too long to authenticate")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PPP_START_FAILED, N_("PPP service failed to start")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PPP_DISCONNECT, N_("PPP service disconnected")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PPP_FAILED, N_("PPP failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_DHCP_START_FAILED, N_("DHCP client failed to start")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_DHCP_ERROR, N_("DHCP client error")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_DHCP_FAILED, N_("DHCP client failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SHARED_START_FAILED, N_("Shared connection service failed to start")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SHARED_FAILED, N_("Shared connection service failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED, N_("AutoIP service failed to start")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_ERROR, N_("AutoIP service error")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_FAILED, N_("AutoIP service failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_BUSY, N_("The line is busy")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE, N_("No dial tone")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER, N_("No carrier could be established")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT, N_("The dialing request timed out")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED, N_("The dialing attempt failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED, N_("Modem initialization failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_APN_FAILED, N_("Failed to select the specified APN")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING, N_("Not searching for networks")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED, N_("Network registration denied")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT, N_("Network registration timed out")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED, N_("Failed to register with the requested network")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED, N_("PIN check failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_FIRMWARE_MISSING, N_("Necessary firmware for the device may be missing")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_REMOVED, N_("The device was removed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SLEEPING, N_("NetworkManager went to sleep")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, N_("The device's active connection disappeared")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_USER_REQUESTED, N_("Device disconnected by user or client")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_CARRIER, N_("Carrier/link changed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, N_("The device's existing connection was assumed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, N_("The supplicant is now available")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND, N_("The modem could not be found")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_BT_FAILED, N_("The Bluetooth connection failed or timed out")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED, N_("GSM Modem's SIM card not inserted")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED, N_("GSM Modem's SIM PIN required")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED, N_("GSM Modem's SIM PUK required")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_WRONG, N_("GSM Modem's SIM wrong")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_INFINIBAND_MODE, N_("InfiniBand device does not support connected mode")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED, N_("A dependency of the connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_BR2684_FAILED, N_("A problem with the RFC 2684 Ethernet over ADSL bridge")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE, N_("ModemManager is unavailable")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SSID_NOT_FOUND, N_("The Wi-Fi network could not be found")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED, N_("A secondary connection of the base connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED, N_("DCB or FCoE setup failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED, N_("teamd control failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_FAILED, N_("Modem failed or no longer available")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_MODEM_AVAILABLE, N_("Modem now ready and available")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT, N_("SIM PIN was incorrect")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_NEW_ACTIVATION, N_("New connection activation was enqueued")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PARENT_CHANGED, N_("The device's parent changed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED, N_("The device parent's management changed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_OVSDB_FAILED, N_("Open vSwitch database connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE, N_("A duplicate IP address was detected")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED, N_("The selected IP method is not supported")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_SRIOV_CONFIGURATION_FAILED, N_("Failed to configure SR-IOV parameters")), - NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, N_("The Wi-Fi P2P peer could not be found")), -) - -NM_UTILS_LOOKUP_STR_DEFINE (nm_active_connection_state_reason_to_string, NMActiveConnectionStateReason, - /* TRANSLATORS: Unknown reason for a connection state change (NMActiveConnectionStateReason) */ - NM_UTILS_LOOKUP_DEFAULT (N_("Unknown")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, N_("Unknown reason")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_NONE, N_("The connection was disconnected")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, N_("Disconnected by user")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, N_("The base network connection was interrupted")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, N_("The VPN service stopped unexpectedly")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, N_("The VPN service returned invalid configuration")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, N_("The connection attempt timed out")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, N_("The VPN service did not start in time")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, N_("The VPN service failed to start")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, N_("No valid secrets")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED, N_("Invalid secrets")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED, N_("The connection was removed")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED, N_("Master connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED, N_("Could not create a software link")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED, N_("The device disappeared")), -) +NM_UTILS_LOOKUP_STR_DEFINE(nmc_device_metered_to_string, + NMMetered, + NM_UTILS_LOOKUP_DEFAULT(N_("unknown")), + NM_UTILS_LOOKUP_ITEM(NM_METERED_YES, N_("yes")), + NM_UTILS_LOOKUP_ITEM(NM_METERED_NO, N_("no")), + NM_UTILS_LOOKUP_ITEM(NM_METERED_GUESS_YES, N_("yes (guessed)")), + NM_UTILS_LOOKUP_ITEM(NM_METERED_GUESS_NO, N_("no (guessed)")), + NM_UTILS_LOOKUP_ITEM(NM_METERED_UNKNOWN, N_("unknown")), ); + +NM_UTILS_LOOKUP_STR_DEFINE( + nmc_device_reason_to_string, + NMDeviceStateReason, + /* TRANSLATORS: Unknown reason for a device state change (NMDeviceStateReason) */ + NM_UTILS_LOOKUP_DEFAULT(N_("Unknown")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NONE, N_("No reason given")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_UNKNOWN, N_("Unknown error")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NOW_MANAGED, N_("Device is now managed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NOW_UNMANAGED, N_("Device is now unmanaged")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_CONFIG_FAILED, + N_("The device could not be readied for configuration")), + NM_UTILS_LOOKUP_ITEM( + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, + N_("IP configuration could not be reserved (no available address, timeout, etc.)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED, + N_("The IP configuration is no longer valid")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NO_SECRETS, + N_("Secrets were required, but not provided")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT, + N_("802.1X supplicant disconnected")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED, + N_("802.1X supplicant configuration failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED, N_("802.1X supplicant failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT, + N_("802.1X supplicant took too long to authenticate")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PPP_START_FAILED, + N_("PPP service failed to start")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PPP_DISCONNECT, N_("PPP service disconnected")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PPP_FAILED, N_("PPP failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DHCP_START_FAILED, + N_("DHCP client failed to start")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DHCP_ERROR, N_("DHCP client error")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DHCP_FAILED, N_("DHCP client failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SHARED_START_FAILED, + N_("Shared connection service failed to start")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SHARED_FAILED, + N_("Shared connection service failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED, + N_("AutoIP service failed to start")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_ERROR, N_("AutoIP service error")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_FAILED, N_("AutoIP service failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_BUSY, N_("The line is busy")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE, N_("No dial tone")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER, + N_("No carrier could be established")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT, + N_("The dialing request timed out")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED, + N_("The dialing attempt failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED, + N_("Modem initialization failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_APN_FAILED, + N_("Failed to select the specified APN")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING, + N_("Not searching for networks")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED, + N_("Network registration denied")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT, + N_("Network registration timed out")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED, + N_("Failed to register with the requested network")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED, N_("PIN check failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_FIRMWARE_MISSING, + N_("Necessary firmware for the device may be missing")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_REMOVED, N_("The device was removed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SLEEPING, N_("NetworkManager went to sleep")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, + N_("The device's active connection disappeared")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_USER_REQUESTED, + N_("Device disconnected by user or client")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_CARRIER, N_("Carrier/link changed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, + N_("The device's existing connection was assumed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, + N_("The supplicant is now available")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND, + N_("The modem could not be found")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_BT_FAILED, + N_("The Bluetooth connection failed or timed out")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED, + N_("GSM Modem's SIM card not inserted")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED, + N_("GSM Modem's SIM PIN required")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED, + N_("GSM Modem's SIM PUK required")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_WRONG, N_("GSM Modem's SIM wrong")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_INFINIBAND_MODE, + N_("InfiniBand device does not support connected mode")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED, + N_("A dependency of the connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_BR2684_FAILED, + N_("A problem with the RFC 2684 Ethernet over ADSL bridge")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE, + N_("ModemManager is unavailable")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SSID_NOT_FOUND, + N_("The Wi-Fi network could not be found")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED, + N_("A secondary connection of the base connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED, N_("DCB or FCoE setup failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED, N_("teamd control failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_FAILED, + N_("Modem failed or no longer available")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_MODEM_AVAILABLE, + N_("Modem now ready and available")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT, N_("SIM PIN was incorrect")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NEW_ACTIVATION, + N_("New connection activation was enqueued")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PARENT_CHANGED, N_("The device's parent changed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED, + N_("The device parent's management changed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_OVSDB_FAILED, + N_("Open vSwitch database connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE, + N_("A duplicate IP address was detected")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED, + N_("The selected IP method is not supported")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_SRIOV_CONFIGURATION_FAILED, + N_("Failed to configure SR-IOV parameters")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, + N_("The Wi-Fi P2P peer could not be found")), ); + +NM_UTILS_LOOKUP_STR_DEFINE( + nm_active_connection_state_reason_to_string, + NMActiveConnectionStateReason, + /* TRANSLATORS: Unknown reason for a connection state change (NMActiveConnectionStateReason) */ + NM_UTILS_LOOKUP_DEFAULT(N_("Unknown")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, N_("Unknown reason")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_NONE, + N_("The connection was disconnected")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, + N_("Disconnected by user")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, + N_("The base network connection was interrupted")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, + N_("The VPN service stopped unexpectedly")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, + N_("The VPN service returned invalid configuration")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, + N_("The connection attempt timed out")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, + N_("The VPN service did not start in time")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + N_("The VPN service failed to start")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, N_("No valid secrets")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED, N_("Invalid secrets")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED, + N_("The connection was removed")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED, + N_("Master connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED, + N_("Could not create a software link")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED, + N_("The device disappeared")), ); NMActiveConnectionState -nmc_activation_get_effective_state (NMActiveConnection *active, - NMDevice *device, - const char **reason) +nmc_activation_get_effective_state(NMActiveConnection *active, + NMDevice * device, + const char ** reason) { - NMActiveConnectionState ac_state; - NMActiveConnectionStateReason ac_reason; - NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; - NMDeviceStateReason dev_reason = NM_DEVICE_STATE_REASON_UNKNOWN; - - g_return_val_if_fail (active, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); - g_return_val_if_fail (reason, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); - - *reason = NULL; - ac_reason = nm_active_connection_get_state_reason (active); - - if (device) { - dev_state = nm_device_get_state (device); - dev_reason = nm_device_get_state_reason (device); - } - - ac_state = nm_active_connection_get_state (active); - switch (ac_state) { - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: - if ( !device - || ac_reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED - || nm_device_get_active_connection (device) != active) { - /* (1) - * - we have no device, - * - or, @ac_reason is specific - * - or, @device no longer references the current @active - * >> we complete with @ac_reason. */ - *reason = gettext (nm_active_connection_state_reason_to_string (ac_reason)); - } else if ( dev_state <= NM_DEVICE_STATE_DISCONNECTED - || dev_state >= NM_DEVICE_STATE_FAILED) { - /* (2) - * - not (1) - * - and, the device is no longer in an activated state, - * >> we complete with @dev_reason. */ - *reason = gettext (nmc_device_reason_to_string (dev_reason)); - } else { - /* (3) - * we wait for the device go disconnect. We will get a better - * failure reason from the device (2). */ - return NM_ACTIVE_CONNECTION_STATE_UNKNOWN; - } - break; - case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: - /* activating master connection does not automatically activate any slaves, so their - * active connection state will not progress beyond ACTIVATING state. - * Monitor the device instead. */ - if ( device - && ( NM_IS_DEVICE_BOND (device) - || NM_IS_DEVICE_TEAM (device) - || NM_IS_DEVICE_BRIDGE (device)) - && dev_state >= NM_DEVICE_STATE_IP_CONFIG - && dev_state <= NM_DEVICE_STATE_ACTIVATED) { - *reason = "master waiting for slaves"; - return NM_ACTIVE_CONNECTION_STATE_ACTIVATED; - } - break; - default: - break; - } - - return ac_state; + NMActiveConnectionState ac_state; + NMActiveConnectionStateReason ac_reason; + NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; + NMDeviceStateReason dev_reason = NM_DEVICE_STATE_REASON_UNKNOWN; + + g_return_val_if_fail(active, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); + g_return_val_if_fail(reason, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); + + *reason = NULL; + ac_reason = nm_active_connection_get_state_reason(active); + + if (device) { + dev_state = nm_device_get_state(device); + dev_reason = nm_device_get_state_reason(device); + } + + ac_state = nm_active_connection_get_state(active); + switch (ac_state) { + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: + if (!device || ac_reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED + || nm_device_get_active_connection(device) != active) { + /* (1) + * - we have no device, + * - or, @ac_reason is specific + * - or, @device no longer references the current @active + * >> we complete with @ac_reason. */ + *reason = gettext(nm_active_connection_state_reason_to_string(ac_reason)); + } else if (dev_state <= NM_DEVICE_STATE_DISCONNECTED + || dev_state >= NM_DEVICE_STATE_FAILED) { + /* (2) + * - not (1) + * - and, the device is no longer in an activated state, + * >> we complete with @dev_reason. */ + *reason = gettext(nmc_device_reason_to_string(dev_reason)); + } else { + /* (3) + * we wait for the device go disconnect. We will get a better + * failure reason from the device (2). */ + return NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + } + break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + /* activating master connection does not automatically activate any slaves, so their + * active connection state will not progress beyond ACTIVATING state. + * Monitor the device instead. */ + if (device + && (NM_IS_DEVICE_BOND(device) || NM_IS_DEVICE_TEAM(device) + || NM_IS_DEVICE_BRIDGE(device)) + && dev_state >= NM_DEVICE_STATE_IP_CONFIG && dev_state <= NM_DEVICE_STATE_ACTIVATED) { + *reason = "master waiting for slaves"; + return NM_ACTIVE_CONNECTION_STATE_ACTIVATED; + } + break; + default: + break; + } + + return ac_state; } static gboolean -can_show_utf8 (void) +can_show_utf8(void) { - static gboolean can_show_utf8_set = FALSE; - static gboolean can_show_utf8 = TRUE; - char *locale_str; - - if (G_LIKELY (can_show_utf8_set)) - return can_show_utf8; - - if (!g_get_charset (NULL)) { - /* Non-UTF-8 locale */ - locale_str = g_locale_from_utf8 ("\342\226\202\342\226\204\342\226\206\342\226\210", -1, NULL, NULL, NULL); - if (locale_str) - g_free (locale_str); - else - can_show_utf8 = FALSE; - } - - return can_show_utf8; + static gboolean can_show_utf8_set = FALSE; + static gboolean can_show_utf8 = TRUE; + char * locale_str; + + if (G_LIKELY(can_show_utf8_set)) + return can_show_utf8; + + if (!g_get_charset(NULL)) { + /* Non-UTF-8 locale */ + locale_str = g_locale_from_utf8("\342\226\202\342\226\204\342\226\206\342\226\210", + -1, + NULL, + NULL, + NULL); + if (locale_str) + g_free(locale_str); + else + can_show_utf8 = FALSE; + } + + return can_show_utf8; } - static gboolean -can_show_graphics (void) +can_show_graphics(void) { - static gboolean can_show_graphics_set = FALSE; - static gboolean can_show_graphics = TRUE; + static gboolean can_show_graphics_set = FALSE; + static gboolean can_show_graphics = TRUE; - if (G_LIKELY (can_show_graphics_set)) - return can_show_graphics; + if (G_LIKELY(can_show_graphics_set)) + return can_show_graphics; - can_show_graphics = can_show_utf8 (); + can_show_graphics = can_show_utf8(); - /* The linux console font typically doesn't have characters we need */ - if (g_strcmp0 (g_getenv ("TERM"), "linux") == 0) - can_show_graphics = FALSE; + /* The linux console font typically doesn't have characters we need */ + if (g_strcmp0(g_getenv("TERM"), "linux") == 0) + can_show_graphics = FALSE; - return can_show_graphics; + return can_show_graphics; } /** @@ -515,26 +589,26 @@ can_show_graphics (void) * Converts @strength into a 4-character-wide graphical representation of * strength suitable for printing to stdout. If the current locale and terminal * support it, this will use unicode graphics characters to represent - * "bars". Otherwise it will use 0 to 4 asterisks. + * "bars". Otherwise, it will use 0 to 4 asterisks. * * Returns: the graphical representation of the access point strength */ const char * -nmc_wifi_strength_bars (guint8 strength) +nmc_wifi_strength_bars(guint8 strength) { - if (!can_show_graphics ()) - return nm_utils_wifi_strength_bars (strength); - - if (strength > 80) - return /* ▂▄▆█ */ "\342\226\202\342\226\204\342\226\206\342\226\210"; - else if (strength > 55) - return /* â–‚â–„â–†_ */ "\342\226\202\342\226\204\342\226\206_"; - else if (strength > 30) - return /* â–‚â–„__ */ "\342\226\202\342\226\204__"; - else if (strength > 5) - return /* â–‚___ */ "\342\226\202___"; - else - return /* ____ */ "____"; + if (!can_show_graphics()) + return nm_utils_wifi_strength_bars(strength); + + if (strength > 80) + return /* ▂▄▆█ */ "\342\226\202\342\226\204\342\226\206\342\226\210"; + else if (strength > 55) + return /* â–‚â–„â–†_ */ "\342\226\202\342\226\204\342\226\206_"; + else if (strength > 30) + return /* â–‚â–„__ */ "\342\226\202\342\226\204__"; + else if (strength > 5) + return /* â–‚___ */ "\342\226\202___"; + else + return /* ____ */ "____"; } /** @@ -543,12 +617,12 @@ nmc_wifi_strength_bars (guint8 strength) * Returns: the string substituted when hiding actual password glyphs */ const char * -nmc_password_subst_char (void) +nmc_password_subst_char(void) { - if (can_show_graphics ()) - return "\u2022"; /* Bullet */ - else - return "*"; + if (can_show_graphics()) + return "\u2022"; /* Bullet */ + else + return "*"; } /* @@ -566,60 +640,59 @@ NM_PRAGMA_WARNING_REENABLE #pragma GCC visibility pop void -nmc_print_qrcode (const char *str) +nmc_print_qrcode(const char *str) { - uint8_t tempBuffer[qrcodegen_BUFFER_LEN_FOR_VERSION (qrcodegen_VERSION_MAX)]; - uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION (qrcodegen_VERSION_MAX)]; - gboolean term_linux; - int size; - int x; - int y; - - term_linux = g_strcmp0 (g_getenv ("TERM"), "linux") == 0; - if (!term_linux && !can_show_graphics ()) - return; - - if (!qrcodegen_encodeText (str, - tempBuffer, - qrcode, - qrcodegen_Ecc_LOW, - qrcodegen_VERSION_MIN, - qrcodegen_VERSION_MAX, - qrcodegen_Mask_AUTO, - FALSE)) { - return; - } - - size = qrcodegen_getSize (qrcode); - - g_print ("\n"); - - if (term_linux) { - /* G1 alternate character set on Linux console. */ - for (y = -1; y < size + 1; y += 1) { - g_print (" \033[37;40;1m\016"); - for (x = -1; x < size + 1; x++) { - g_print ( qrcodegen_getModule (qrcode, x, y) - ? " " : "\060\060"); - } - g_print ("\017\033[0m\n"); - } - } else { - /* UTF-8 */ - for (y = -2; y < size + 2; y += 2) { - g_print (" \033[37;40m"); - for (x = -2; x < size + 2; x++) { - bool top = qrcodegen_getModule (qrcode, x, y); - bool bottom = qrcodegen_getModule (qrcode, x, y + 1); - if (top) { - g_print (bottom ? " " : "\u2584"); - } else { - g_print (bottom ? "\u2580" : "\u2588"); - } - } - g_print ("\033[0m\n"); - } - } + uint8_t tempBuffer[qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)]; + uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)]; + gboolean term_linux; + int size; + int x; + int y; + + term_linux = g_strcmp0(g_getenv("TERM"), "linux") == 0; + if (!term_linux && !can_show_graphics()) + return; + + if (!qrcodegen_encodeText(str, + tempBuffer, + qrcode, + qrcodegen_Ecc_LOW, + qrcodegen_VERSION_MIN, + qrcodegen_VERSION_MAX, + qrcodegen_Mask_AUTO, + FALSE)) { + return; + } + + size = qrcodegen_getSize(qrcode); + + g_print("\n"); + + if (term_linux) { + /* G1 alternate character set on Linux console. */ + for (y = -1; y < size + 1; y += 1) { + g_print(" \033[37;40;1m\016"); + for (x = -1; x < size + 1; x++) { + g_print(qrcodegen_getModule(qrcode, x, y) ? " " : "\060\060"); + } + g_print("\017\033[0m\n"); + } + } else { + /* UTF-8 */ + for (y = -2; y < size + 2; y += 2) { + g_print(" \033[37;40m"); + for (x = -2; x < size + 2; x++) { + bool top = qrcodegen_getModule(qrcode, x, y); + bool bottom = qrcodegen_getModule(qrcode, x, y + 1); + if (top) { + g_print(bottom ? " " : "\u2584"); + } else { + g_print(bottom ? "\u2580" : "\u2588"); + } + } + g_print("\033[0m\n"); + } + } } /** @@ -638,173 +711,176 @@ nmc_print_qrcode (const char *str) * Returns: (transfer full): hash table with parsed passwords, or %NULL on an error */ GHashTable * -nmc_utils_read_passwd_file (const char *passwd_file, - gssize *out_error_line, - GError **error) +nmc_utils_read_passwd_file(const char *passwd_file, gssize *out_error_line, GError **error) { - nm_auto_clear_secret_ptr NMSecretPtr contents = { 0 }; - - NM_SET_OUT (out_error_line, -1); - - if (!passwd_file) - return g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret); - - if (!nm_utils_file_get_contents (-1, - passwd_file, - 1024*1024, - NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET, - &contents.str, - &contents.len, - NULL, - error)) - return NULL; - - return nmc_utils_parse_passwd_file (contents.str, out_error_line, error); + nm_auto_clear_secret_ptr NMSecretPtr contents = {0}; + + NM_SET_OUT(out_error_line, -1); + + if (!passwd_file) + return g_hash_table_new_full(nm_str_hash, + g_str_equal, + g_free, + (GDestroyNotify) nm_free_secret); + + if (!nm_utils_file_get_contents(-1, + passwd_file, + 1024 * 1024, + NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET, + &contents.str, + &contents.len, + NULL, + error)) + return NULL; + + return nmc_utils_parse_passwd_file(contents.str, out_error_line, error); } GHashTable * -nmc_utils_parse_passwd_file (char *contents /* will be modified */, - gssize *out_error_line, - GError **error) +nmc_utils_parse_passwd_file(char * contents /* will be modified */, + gssize * out_error_line, + GError **error) { - gs_unref_hashtable GHashTable *pwds_hash = NULL; - const char *contents_str; - gsize contents_line; - - pwds_hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret); - - NM_SET_OUT (out_error_line, -1); - - contents_str = contents; - contents_line = 0; - while (contents_str[0]) { - nm_auto_free_secret char *l_hash_key = NULL; - nm_auto_free_secret char *l_hash_val = NULL; - const char *l_content_line; - const char *l_setting; - const char *l_prop; - const char *l_val; - const char *s; - gsize l_hash_val_len; - - /* consume first line. As line delimiters we accept "\r\n", "\n", and "\r". */ - l_content_line = contents_str; - s = l_content_line; - while (!NM_IN_SET (s[0], '\0', '\r', '\n')) - s++; - if (s[0] != '\0') { - if ( s[0] == '\r' - && s[1] == '\n') { - ((char *) s)[0] = '\0'; - s += 2; - } else { - ((char *) s)[0] = '\0'; - s += 1; - } - } - contents_str = s; - contents_line++; - - l_content_line = nm_str_skip_leading_spaces (l_content_line); - if (NM_IN_SET (l_content_line[0], '\0', '#')) { - /* a comment or empty line. Ignore. */ - continue; - } - - l_setting = l_content_line; - - s = l_setting; - while (!NM_IN_SET (s[0], '\0', ':', '=')) - s++; - if (s[0] == '\0') { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("missing colon for \"<setting>.<property>:<secret>\" format")); - return NULL; - } - ((char *) s)[0] = '\0'; - s++; - - l_val = s; - - g_strchomp ((char *) l_setting); - - nm_assert (nm_str_is_stripped (l_setting)); - - s = strchr (l_setting, '.'); - if (!s) { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("missing dot for \"<setting>.<property>:<secret>\" format")); - return NULL; - } else if (s == l_setting) { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("missing setting for \"<setting>.<property>:<secret>\" format")); - return NULL; - } - ((char *) s)[0] = '\0'; - s++; - - l_prop = s; - if (l_prop[0] == '\0') { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("missing property for \"<setting>.<property>:<secret>\" format")); - return NULL; - } - - /* Accept wifi-sec or wifi instead of cumbersome '802-11-wireless-security' */ - if (NM_IN_STRSET (l_setting, "wifi-sec", "wifi")) - l_setting = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME; - - if (nm_setting_lookup_type (l_setting) == G_TYPE_INVALID) { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("invalid setting name")); - return NULL; - } - - if ( nm_streq (l_setting, "vpn") - && NM_STR_HAS_PREFIX (l_prop, "secret.")) { - /* in 1.12.0, we wrongly required the VPN secrets to be named - * "vpn.secret". It should be "vpn.secrets". Work around it - * (rh#1628833). */ - l_hash_key = g_strdup_printf ("vpn.secrets.%s", &l_prop[NM_STRLEN ("secret.")]); - } else - l_hash_key = g_strdup_printf ("%s.%s", l_setting, l_prop); - - if (!g_utf8_validate (l_hash_key, -1, NULL)) { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("property name is not UTF-8")); - return NULL; - } - - /* Support backslash escaping in the secret value. We strip non-escaped leading/trailing whitespaces. */ - s = nm_utils_buf_utf8safe_unescape (l_val, NM_UTILS_STR_UTF8_SAFE_UNESCAPE_STRIP_SPACES, &l_hash_val_len, (gpointer *) &l_hash_val); - if (!l_hash_val) - l_hash_val = g_strdup (s); - - if (!g_utf8_validate (l_hash_val, -1, NULL)) { - /* In some cases it might make sense to support binary secrets (like the WPA-PSK which has no - * defined encoding. However, all API that follows can only handle UTF-8, and no mechanism - * to escape the secrets. Reject non-UTF-8 early. */ - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("secret is not UTF-8")); - return NULL; - } - - if (strlen (l_hash_val) != l_hash_val_len) { - NM_SET_OUT (out_error_line, contents_line); - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("secret is not UTF-8")); - return NULL; - } - - g_hash_table_insert (pwds_hash, g_steal_pointer (&l_hash_key), g_steal_pointer (&l_hash_val)); - } - - return g_steal_pointer (&pwds_hash); + gs_unref_hashtable GHashTable *pwds_hash = NULL; + const char * contents_str; + gsize contents_line; + + pwds_hash = + g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, (GDestroyNotify) nm_free_secret); + + NM_SET_OUT(out_error_line, -1); + + contents_str = contents; + contents_line = 0; + while (contents_str[0]) { + nm_auto_free_secret char *l_hash_key = NULL; + nm_auto_free_secret char *l_hash_val = NULL; + const char * l_content_line; + const char * l_setting; + const char * l_prop; + const char * l_val; + const char * s; + gsize l_hash_val_len; + + /* consume first line. As line delimiters we accept "\r\n", "\n", and "\r". */ + l_content_line = contents_str; + s = l_content_line; + while (!NM_IN_SET(s[0], '\0', '\r', '\n')) + s++; + if (s[0] != '\0') { + if (s[0] == '\r' && s[1] == '\n') { + ((char *) s)[0] = '\0'; + s += 2; + } else { + ((char *) s)[0] = '\0'; + s += 1; + } + } + contents_str = s; + contents_line++; + + l_content_line = nm_str_skip_leading_spaces(l_content_line); + if (NM_IN_SET(l_content_line[0], '\0', '#')) { + /* a comment or empty line. Ignore. */ + continue; + } + + l_setting = l_content_line; + + s = l_setting; + while (!NM_IN_SET(s[0], '\0', ':', '=')) + s++; + if (s[0] == '\0') { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + _("missing colon for \"<setting>.<property>:<secret>\" format")); + return NULL; + } + ((char *) s)[0] = '\0'; + s++; + + l_val = s; + + g_strchomp((char *) l_setting); + + nm_assert(nm_str_is_stripped(l_setting)); + + s = strchr(l_setting, '.'); + if (!s) { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + _("missing dot for \"<setting>.<property>:<secret>\" format")); + return NULL; + } else if (s == l_setting) { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + _("missing setting for \"<setting>.<property>:<secret>\" format")); + return NULL; + } + ((char *) s)[0] = '\0'; + s++; + + l_prop = s; + if (l_prop[0] == '\0') { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + _("missing property for \"<setting>.<property>:<secret>\" format")); + return NULL; + } + + /* Accept wifi-sec or wifi instead of cumbersome '802-11-wireless-security' */ + if (NM_IN_STRSET(l_setting, "wifi-sec", "wifi")) + l_setting = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME; + + if (nm_setting_lookup_type(l_setting) == G_TYPE_INVALID) { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, _("invalid setting name")); + return NULL; + } + + if (nm_streq(l_setting, "vpn") && NM_STR_HAS_PREFIX(l_prop, "secret.")) { + /* in 1.12.0, we wrongly required the VPN secrets to be named + * "vpn.secret". It should be "vpn.secrets". Work around it + * (rh#1628833). */ + l_hash_key = g_strdup_printf("vpn.secrets.%s", &l_prop[NM_STRLEN("secret.")]); + } else + l_hash_key = g_strdup_printf("%s.%s", l_setting, l_prop); + + if (!g_utf8_validate(l_hash_key, -1, NULL)) { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, _("property name is not UTF-8")); + return NULL; + } + + /* Support backslash escaping in the secret value. We strip non-escaped leading/trailing whitespaces. */ + s = nm_utils_buf_utf8safe_unescape(l_val, + NM_UTILS_STR_UTF8_SAFE_UNESCAPE_STRIP_SPACES, + &l_hash_val_len, + (gpointer *) &l_hash_val); + if (!l_hash_val) + l_hash_val = g_strdup(s); + + if (!g_utf8_validate(l_hash_val, -1, NULL)) { + /* In some cases it might make sense to support binary secrets (like the WPA-PSK which has no + * defined encoding. However, all API that follows can only handle UTF-8, and no mechanism + * to escape the secrets. Reject non-UTF-8 early. */ + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, _("secret is not UTF-8")); + return NULL; + } + + if (strlen(l_hash_val) != l_hash_val_len) { + NM_SET_OUT(out_error_line, contents_line); + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, _("secret is not UTF-8")); + return NULL; + } + + g_hash_table_insert(pwds_hash, g_steal_pointer(&l_hash_key), g_steal_pointer(&l_hash_val)); + } + + return g_steal_pointer(&pwds_hash); } diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index 28eac457..540177a7 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2017 Red Hat, Inc. */ @@ -11,46 +11,43 @@ #include "nm-device.h" #include "nm-libnm-core-intern/nm-libnm-core-utils.h" -const NMObject **nmc_objects_sort_by_path (const NMObject *const*objs, gssize len); +const NMObject **nmc_objects_sort_by_path(const NMObject *const *objs, gssize len); -const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); +const char *nmc_string_is_valid(const char *input, const char **allowed, GError **error); -gboolean nmc_string_to_uint (const char *str, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value); -gboolean nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error); -gboolean nmc_string_to_ternary (const char *str, NMTernary *val, GError **error); +gboolean nmc_string_to_uint(const char * str, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value); +gboolean nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error); +gboolean nmc_string_to_ternary(const char *str, NMTernary *val, GError **error); -gboolean matches (const char *cmd, const char *pattern); +gboolean matches(const char *cmd, const char *pattern); /* FIXME: don't expose this function on its own, at least not from this file. */ -const char *nmc_bond_validate_mode (const char *mode, GError **error); +const char *nmc_bond_validate_mode(const char *mode, GError **error); -const char *nmc_device_state_to_string_with_external (NMDevice *device); +const char *nmc_device_state_to_string_with_external(NMDevice *device); -const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason); -const char *nmc_device_state_to_string (NMDeviceState state); -const char *nmc_device_reason_to_string (NMDeviceStateReason reason); -const char *nmc_device_metered_to_string (NMMetered value); +const char *nm_active_connection_state_reason_to_string(NMActiveConnectionStateReason reason); +const char *nmc_device_state_to_string(NMDeviceState state); +const char *nmc_device_reason_to_string(NMDeviceStateReason reason); +const char *nmc_device_metered_to_string(NMMetered value); -NMActiveConnectionState nmc_activation_get_effective_state (NMActiveConnection *active, - NMDevice *device, - const char **reason); +NMActiveConnectionState nmc_activation_get_effective_state(NMActiveConnection *active, + NMDevice * device, + const char ** reason); -const char *nmc_wifi_strength_bars (guint8 strength); +const char *nmc_wifi_strength_bars(guint8 strength); -const char *nmc_password_subst_char (void); +const char *nmc_password_subst_char(void); -void nmc_print_qrcode (const char *str); +void nmc_print_qrcode(const char *str); -GHashTable *nmc_utils_parse_passwd_file (char *contents, - gssize *out_error_line, - GError **error); +GHashTable *nmc_utils_parse_passwd_file(char *contents, gssize *out_error_line, GError **error); -GHashTable *nmc_utils_read_passwd_file (const char *passwd_file, - gssize *out_error_line, - GError **error); +GHashTable * +nmc_utils_read_passwd_file(const char *passwd_file, gssize *out_error_line, GError **error); #endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index 1167b555..2278078e 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2017 Red Hat, Inc. */ @@ -10,623 +10,644 @@ /*****************************************************************************/ static const NMMetaSettingInfoEditor * -_get_meta_setting_info_editor_from_msi (const NMMetaSettingInfo *meta_setting_info) +_get_meta_setting_info_editor_from_msi(const NMMetaSettingInfo *meta_setting_info) { - const NMMetaSettingInfoEditor *setting_info; + const NMMetaSettingInfoEditor *setting_info; - if (!meta_setting_info) - return NULL; + if (!meta_setting_info) + return NULL; - nm_assert (meta_setting_info->get_setting_gtype); - nm_assert (meta_setting_info->meta_type < G_N_ELEMENTS (nm_meta_setting_infos_editor)); + nm_assert(meta_setting_info->get_setting_gtype); + nm_assert(meta_setting_info->meta_type < G_N_ELEMENTS(nm_meta_setting_infos_editor)); - setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; + setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; - nm_assert (setting_info->general == meta_setting_info); - return setting_info; + nm_assert(setting_info->general == meta_setting_info); + return setting_info; } const NMMetaSettingInfoEditor * -nm_meta_setting_info_editor_find_by_name (const char *setting_name, gboolean use_alias) +nm_meta_setting_info_editor_find_by_name(const char *setting_name, gboolean use_alias) { - const NMMetaSettingInfoEditor *setting_info; - guint i; - - g_return_val_if_fail (setting_name, NULL); - - setting_info = _get_meta_setting_info_editor_from_msi (nm_meta_setting_infos_by_name (setting_name)); - if (!setting_info && use_alias) { - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - if (nm_streq0 (nm_meta_setting_infos_editor[i].alias, setting_name)) { - setting_info = &nm_meta_setting_infos_editor[i]; - break; - } - } - } - - return setting_info; + const NMMetaSettingInfoEditor *setting_info; + guint i; + + g_return_val_if_fail(setting_name, NULL); + + setting_info = + _get_meta_setting_info_editor_from_msi(nm_meta_setting_infos_by_name(setting_name)); + if (!setting_info && use_alias) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + if (nm_streq0(nm_meta_setting_infos_editor[i].alias, setting_name)) { + setting_info = &nm_meta_setting_infos_editor[i]; + break; + } + } + } + + return setting_info; } const NMMetaSettingInfoEditor * -nm_meta_setting_info_editor_find_by_gtype (GType gtype) +nm_meta_setting_info_editor_find_by_gtype(GType gtype) { - return _get_meta_setting_info_editor_from_msi (nm_meta_setting_infos_by_gtype (gtype)); + return _get_meta_setting_info_editor_from_msi(nm_meta_setting_infos_by_gtype(gtype)); } const NMMetaSettingInfoEditor * -nm_meta_setting_info_editor_find_by_setting (NMSetting *setting) +nm_meta_setting_info_editor_find_by_setting(NMSetting *setting) { - const NMMetaSettingInfoEditor *setting_info; + const NMMetaSettingInfoEditor *setting_info; - g_return_val_if_fail (NM_IS_SETTING (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING(setting), NULL); - setting_info = nm_meta_setting_info_editor_find_by_gtype (G_OBJECT_TYPE (setting)); + setting_info = nm_meta_setting_info_editor_find_by_gtype(G_OBJECT_TYPE(setting)); - nm_assert (setting_info); - nm_assert (G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ())); - return setting_info; + nm_assert(setting_info); + nm_assert(G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_info->general->get_setting_gtype())); + return setting_info; } /*****************************************************************************/ const NMMetaPropertyInfo * -nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info, const char *property_name) +nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info, + const char * property_name) { - guint i; + guint i; - g_return_val_if_fail (setting_info, NULL); - g_return_val_if_fail (property_name, NULL); + g_return_val_if_fail(setting_info, NULL); + g_return_val_if_fail(property_name, NULL); - for (i = 0; i < setting_info->properties_num; i++) { - nm_assert (setting_info->properties[i]->property_name); - nm_assert (setting_info->properties[i]->setting_info == setting_info); - if (nm_streq (setting_info->properties[i]->property_name, property_name)) - return setting_info->properties[i]; - } + for (i = 0; i < setting_info->properties_num; i++) { + nm_assert(setting_info->properties[i]->property_name); + nm_assert(setting_info->properties[i]->setting_info == setting_info); + if (nm_streq(setting_info->properties[i]->property_name, property_name)) + return setting_info->properties[i]; + } - return NULL; + return NULL; } gboolean -nm_meta_setting_info_editor_has_secrets (const NMMetaSettingInfoEditor *setting_info) +nm_meta_setting_info_editor_has_secrets(const NMMetaSettingInfoEditor *setting_info) { - guint i; + guint i; - if (!setting_info) - return FALSE; + if (!setting_info) + return FALSE; - for (i = 0; i < setting_info->properties_num; i++) { - if (setting_info->properties[i]->is_secret) - return TRUE; - } + for (i = 0; i < setting_info->properties_num; i++) { + if (setting_info->properties[i]->is_secret) + return TRUE; + } - return FALSE; + return FALSE; } const NMMetaPropertyInfo * -nm_meta_property_info_find_by_name (const char *setting_name, const char *property_name) +nm_meta_property_info_find_by_name(const char *setting_name, const char *property_name) { - const NMMetaSettingInfoEditor *setting_info; - const NMMetaPropertyInfo *property_info; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo * property_info; - setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE); - if (!setting_info) - return NULL; + setting_info = nm_meta_setting_info_editor_find_by_name(setting_name, FALSE); + if (!setting_info) + return NULL; - property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name); - if (!property_info) - return NULL; + property_info = nm_meta_setting_info_editor_get_property_info(setting_info, property_name); + if (!property_info) + return NULL; - nm_assert (property_info->setting_info == setting_info); + nm_assert(property_info->setting_info == setting_info); - return property_info; + return property_info; } const NMMetaPropertyInfo * -nm_meta_property_info_find_by_setting (NMSetting *setting, const char *property_name) +nm_meta_property_info_find_by_setting(NMSetting *setting, const char *property_name) { - const NMMetaSettingInfoEditor *setting_info; - const NMMetaPropertyInfo *property_info; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo * property_info; - setting_info = nm_meta_setting_info_editor_find_by_setting (setting); - if (!setting_info) - return NULL; - property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name); - if (!property_info) - return NULL; + setting_info = nm_meta_setting_info_editor_find_by_setting(setting); + if (!setting_info) + return NULL; + property_info = nm_meta_setting_info_editor_get_property_info(setting_info, property_name); + if (!property_info) + return NULL; - nm_assert (property_info->setting_info == setting_info); - nm_assert (property_info == nm_meta_property_info_find_by_name (nm_setting_get_name (setting), property_name)); + nm_assert(property_info->setting_info == setting_info); + nm_assert(property_info + == nm_meta_property_info_find_by_name(nm_setting_get_name(setting), property_name)); - return property_info; + return property_info; } NMSetting * -nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_info, - NMMetaAccessorSettingInitType init_type) +nm_meta_setting_info_editor_new_setting(const NMMetaSettingInfoEditor *setting_info, + NMMetaAccessorSettingInitType init_type) { - NMSetting *setting; + NMSetting *setting; - g_return_val_if_fail (setting_info, NULL); + g_return_val_if_fail(setting_info, NULL); - setting = g_object_new (setting_info->general->get_setting_gtype (), NULL); + setting = g_object_new(setting_info->general->get_setting_gtype(), NULL); - if ( setting_info->setting_init_fcn - && init_type != NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT) { - setting_info->setting_init_fcn (setting_info, - setting, - init_type); - } + if (setting_info->setting_init_fcn && init_type != NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT) { + setting_info->setting_init_fcn(setting_info, setting, init_type); + } - return setting; + return setting; } /*****************************************************************************/ -const NMMetaSettingInfoEditor *const* -nm_meta_setting_infos_editor_p (void) +const NMMetaSettingInfoEditor *const * +nm_meta_setting_infos_editor_p(void) { - static const NMMetaSettingInfoEditor *cache[_NM_META_SETTING_TYPE_NUM + 1] = { NULL }; - guint i; - - if (G_UNLIKELY (!cache[0])) { - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) - cache[i] = &nm_meta_setting_infos_editor[i]; - } - return cache; + static const NMMetaSettingInfoEditor *cache[_NM_META_SETTING_TYPE_NUM + 1] = {NULL}; + guint i; + + if (G_UNLIKELY(!cache[0])) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + cache[i] = &nm_meta_setting_infos_editor[i]; + } + return cache; } /*****************************************************************************/ const char * -nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header) +nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_info, gboolean for_header) { - const char *n; - - nm_assert (abstract_info); - nm_assert (abstract_info->meta_type); - nm_assert (abstract_info->meta_type->get_name); - n = abstract_info->meta_type->get_name (abstract_info, for_header); - nm_assert (n && n[0]); - return n; + const char *n; + + nm_assert(abstract_info); + nm_assert(abstract_info->meta_type); + nm_assert(abstract_info->meta_type->get_name); + n = abstract_info->meta_type->get_name(abstract_info, for_header); + nm_assert(n && n[0]); + return n; } -const NMMetaAbstractInfo *const* -nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info, - guint *out_len, - gpointer *nested_to_free) +const NMMetaAbstractInfo *const * +nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info, + guint * out_len, + gpointer * nested_to_free) { - const NMMetaAbstractInfo *const*nested; - guint l = 0; - gs_free gpointer f = NULL; - - nm_assert (abstract_info); - nm_assert (abstract_info->meta_type); - nm_assert (nested_to_free && !*nested_to_free); - - if (abstract_info->meta_type->get_nested) { - nested = abstract_info->meta_type->get_nested (abstract_info, &l, &f); - nm_assert (NM_PTRARRAY_LEN (nested) == l); - nm_assert (!f || nested == f); - if (nested && nested[0]) { - NM_SET_OUT (out_len, l); - *nested_to_free = g_steal_pointer (&f); - return nested; - } - } - NM_SET_OUT (out_len, 0); - return NULL; + const NMMetaAbstractInfo *const *nested; + guint l = 0; + gs_free gpointer f = NULL; + + nm_assert(abstract_info); + nm_assert(abstract_info->meta_type); + nm_assert(nested_to_free && !*nested_to_free); + + if (abstract_info->meta_type->get_nested) { + nested = abstract_info->meta_type->get_nested(abstract_info, &l, &f); + nm_assert(NM_PTRARRAY_LEN(nested) == l); + nm_assert(!f || nested == f); + if (nested && nested[0]) { + NM_SET_OUT(out_len, l); + *nested_to_free = g_steal_pointer(&f); + return nested; + } + } + NM_SET_OUT(out_len, 0); + return NULL; } gconstpointer -nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - gpointer target, - gpointer target_data, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free) +nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + gpointer target, + gpointer target_data, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free) { - nm_assert (abstract_info); - nm_assert (abstract_info->meta_type); - nm_assert (!out_to_free || !*out_to_free); - nm_assert (out_flags); - - *out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE; - NM_SET_OUT (out_is_default, FALSE); - - if (!abstract_info->meta_type->get_fcn) - g_return_val_if_reached (NULL); - - return abstract_info->meta_type->get_fcn (abstract_info, - environment, - environment_user_data, - target, - target_data, - get_type, - get_flags, - out_flags, - out_is_default, - out_to_free); + nm_assert(abstract_info); + nm_assert(abstract_info->meta_type); + nm_assert(!out_to_free || !*out_to_free); + nm_assert(out_flags); + + *out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE; + NM_SET_OUT(out_is_default, FALSE); + + if (!abstract_info->meta_type->get_fcn) + g_return_val_if_reached(NULL); + + return abstract_info->meta_type->get_fcn(abstract_info, + environment, + environment_user_data, + target, + target_data, + get_type, + get_flags, + out_flags, + out_is_default, + out_to_free); } -const char *const* -nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NMMetaOperationContext *operation_context, - const char *text, - gboolean *out_complete_filename, - char ***out_to_free) +const char *const * +nm_meta_abstract_info_complete(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + const NMMetaOperationContext *operation_context, + const char * text, + gboolean * out_complete_filename, + char *** out_to_free) { - const char *const*values; - gsize i, j, text_len; - - nm_assert (abstract_info); - nm_assert (abstract_info->meta_type); - nm_assert (out_to_free && !*out_to_free); - - *out_to_free = NULL; - - if (!abstract_info->meta_type->complete_fcn) - return NULL; - - values = abstract_info->meta_type->complete_fcn (abstract_info, - environment, - environment_user_data, - operation_context, - text, - out_complete_filename, - out_to_free); - - nm_assert (!*out_to_free || values == (const char *const*) *out_to_free); - - if (!values) - return NULL; - - if (!values[0]) { - nm_clear_g_free (out_to_free); - return NULL; - } - - if (!text || !text[0]) - return values; - - /* for convenience, we allow the complete_fcn() implementations to - * ignore "text". We filter out invalid matches here. */ - - text_len = strlen (text); - - if (*out_to_free) { - char **v = *out_to_free; - - for (i = 0, j = 0; v[i]; i++) { - if (strncmp (v[i], text, text_len) != 0) { - g_free (v[i]); - continue; - } - v[j++] = v[i]; - } - if (j) - v[j++] = NULL; - else { - g_free (v); - *out_to_free = v = NULL; - } - return (const char *const*) v; - } else { - const char *const*v = values; - char **r; - - for (i = 0, j = 0; v[i]; i++) { - if (strncmp (v[i], text, text_len) != 0) - continue; - j++; - } - if (j == i) - return values; - else if (!j) - return NULL; - - r = g_new (char *, j + 1); - v = values; - for (i = 0, j = 0; v[i]; i++) { - if (strncmp (v[i], text, text_len) != 0) - continue; - r[j++] = g_strdup (v[i]); - } - r[j++] = NULL; - return (const char *const*) (*out_to_free = r); - } + const char *const *values; + gsize i, j, text_len; + + nm_assert(abstract_info); + nm_assert(abstract_info->meta_type); + nm_assert(out_to_free && !*out_to_free); + + *out_to_free = NULL; + + if (!abstract_info->meta_type->complete_fcn) + return NULL; + + values = abstract_info->meta_type->complete_fcn(abstract_info, + environment, + environment_user_data, + operation_context, + text, + out_complete_filename, + out_to_free); + + nm_assert(!*out_to_free || values == (const char *const *) *out_to_free); + + if (!values) + return NULL; + + if (!values[0]) { + nm_clear_g_free(out_to_free); + return NULL; + } + + if (!text || !text[0]) + return values; + + /* for convenience, we allow the complete_fcn() implementations to + * ignore "text". We filter out invalid matches here. */ + + text_len = strlen(text); + + if (*out_to_free) { + char **v = *out_to_free; + + for (i = 0, j = 0; v[i]; i++) { + if (strncmp(v[i], text, text_len) != 0) { + g_free(v[i]); + continue; + } + v[j++] = v[i]; + } + if (j) + v[j++] = NULL; + else { + g_free(v); + *out_to_free = v = NULL; + } + return (const char *const *) v; + } else { + const char *const *v = values; + char ** r; + + for (i = 0, j = 0; v[i]; i++) { + if (strncmp(v[i], text, text_len) != 0) + continue; + j++; + } + if (j == i) + return values; + else if (!j) + return NULL; + + r = g_new(char *, j + 1); + v = values; + for (i = 0, j = 0; v[i]; i++) { + if (strncmp(v[i], text, text_len) != 0) + continue; + r[j++] = g_strdup(v[i]); + } + r[j++] = NULL; + return (const char *const *) (*out_to_free = r); + } } /*****************************************************************************/ char * -nm_meta_abstract_info_get_nested_names_str (const NMMetaAbstractInfo *abstract_info, const char *name_prefix) +nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info, + const char * name_prefix) { - gs_free gpointer nested_to_free = NULL; - const NMMetaAbstractInfo *const*nested; + gs_free gpointer nested_to_free = NULL; + const NMMetaAbstractInfo *const *nested; - nested = nm_meta_abstract_info_get_nested (abstract_info, NULL, &nested_to_free); - if (!nested) - return NULL; + nested = nm_meta_abstract_info_get_nested(abstract_info, NULL, &nested_to_free); + if (!nested) + return NULL; - if (!name_prefix) - name_prefix = nm_meta_abstract_info_get_name (abstract_info, FALSE); + if (!name_prefix) + name_prefix = nm_meta_abstract_info_get_name(abstract_info, FALSE); - return nm_meta_abstract_infos_get_names_str (nested, name_prefix); + return nm_meta_abstract_infos_get_names_str(nested, name_prefix); } char * -nm_meta_abstract_infos_get_names_str (const NMMetaAbstractInfo *const*fields_array, const char *name_prefix) +nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array, + const char * name_prefix) { - GString *str; - guint i; - - if (!fields_array || !fields_array[0]) - return NULL; - - str = g_string_sized_new (128); - for (i = 0; fields_array[i]; i++) { - if (str->len > 0) - g_string_append_c (str, ','); - if (name_prefix) { - g_string_append (str, name_prefix); - g_string_append_c (str, '.'); - } - g_string_append (str, nm_meta_abstract_info_get_name (fields_array[i], FALSE)); - } - return g_string_free (str, FALSE); + GString *str; + guint i; + + if (!fields_array || !fields_array[0]) + return NULL; + + str = g_string_sized_new(128); + for (i = 0; fields_array[i]; i++) { + if (str->len > 0) + g_string_append_c(str, ','); + if (name_prefix) { + g_string_append(str, name_prefix); + g_string_append_c(str, '.'); + } + g_string_append(str, nm_meta_abstract_info_get_name(fields_array[i], FALSE)); + } + return g_string_free(str, FALSE); } /*****************************************************************************/ typedef struct { - guint idx; - gsize self_offset_plus_1; - gsize sub_offset_plus_1; + guint idx; + gsize self_offset_plus_1; + gsize sub_offset_plus_1; } OutputSelectionItem; static NMMetaSelectionResultList * -_output_selection_pack (const NMMetaAbstractInfo *const* fields_array, - GArray *array, - GString *str) +_output_selection_pack(const NMMetaAbstractInfo *const *fields_array, GArray *array, GString *str) { - NMMetaSelectionResultList *result; - guint i; - guint len; - - len = array ? array->len : 0; - - /* re-organize the collected output data in one buffer that can be freed using - * g_free(). This makes allocation more complicated, but saves us from special - * handling for free. */ - result = g_malloc0 (sizeof (NMMetaSelectionResultList) + (len * sizeof (NMMetaSelectionItem)) + (str ? str->len : 0)); - *((guint *) &result->num) = len; - if (len > 0) { - char *pdata = &((char *) result)[sizeof (NMMetaSelectionResultList) + (len * sizeof (NMMetaSelectionItem))]; - - if (str) - memcpy (pdata, str->str, str->len); - for (i = 0; i < len; i++) { - const OutputSelectionItem *a = &g_array_index (array, OutputSelectionItem, i); - NMMetaSelectionItem *p = (NMMetaSelectionItem *) &result->items[i]; - - p->info = fields_array[a->idx]; - p->idx = a->idx; - if (a->self_offset_plus_1 > 0) - p->self_selection = &pdata[a->self_offset_plus_1 - 1]; - if (a->sub_offset_plus_1 > 0) - p->sub_selection = &pdata[a->sub_offset_plus_1 - 1]; - } - } - - return result; + NMMetaSelectionResultList *result; + guint i; + guint len; + + len = array ? array->len : 0; + + /* re-organize the collected output data in one buffer that can be freed using + * g_free(). This makes allocation more complicated, but saves us from special + * handling for free. */ + result = g_malloc0(sizeof(NMMetaSelectionResultList) + (len * sizeof(NMMetaSelectionItem)) + + (str ? str->len : 0)); + *((guint *) &result->num) = len; + if (len > 0) { + char *pdata = + &((char *) + result)[sizeof(NMMetaSelectionResultList) + (len * sizeof(NMMetaSelectionItem))]; + + if (str) + memcpy(pdata, str->str, str->len); + for (i = 0; i < len; i++) { + const OutputSelectionItem *a = &g_array_index(array, OutputSelectionItem, i); + NMMetaSelectionItem * p = (NMMetaSelectionItem *) &result->items[i]; + + p->info = fields_array[a->idx]; + p->idx = a->idx; + if (a->self_offset_plus_1 > 0) + p->self_selection = &pdata[a->self_offset_plus_1 - 1]; + if (a->sub_offset_plus_1 > 0) + p->sub_selection = &pdata[a->sub_offset_plus_1 - 1]; + } + } + + return result; } static gboolean -_output_selection_select_one (const NMMetaAbstractInfo *const* fields_array, - const char *fields_prefix, - const char *fields_str, - gboolean validate_nested, - GArray **p_array, - GString **p_str, - GError **error) +_output_selection_select_one(const NMMetaAbstractInfo *const *fields_array, + const char * fields_prefix, + const char * fields_str, + gboolean validate_nested, + GArray ** p_array, + GString ** p_str, + GError ** error) { - guint i, j; - const char *i_name; - const char *right; - gboolean found = FALSE; - const NMMetaAbstractInfo *fields_array_failure = NULL; - gs_free char *fields_str_clone = NULL; - - nm_assert (fields_str); - nm_assert (p_array); - nm_assert (p_str); - nm_assert (!error || !*error); - - right = strchr (fields_str, '.'); - if (right) { - fields_str_clone = g_strdup (fields_str); - fields_str_clone[right - fields_str] = '\0'; - i_name = fields_str_clone; - right = &fields_str_clone[right - fields_str + 1]; - } else - i_name = fields_str; - - if (!fields_array) - goto not_found; - - for (i = 0; fields_array[i]; i++) { - const NMMetaAbstractInfo *fi = fields_array[i]; - const NMMetaAbstractInfo *const*nested; - gs_free gpointer nested_to_free = NULL; - - if (g_ascii_strcasecmp (i_name, nm_meta_abstract_info_get_name (fi, FALSE)) != 0) - continue; - - if (!right || !validate_nested) { - found = TRUE; - break; - } - - nested = nm_meta_abstract_info_get_nested (fi, NULL, &nested_to_free); - if (nested) { - for (j = 0; nested[j]; nested++) { - if (g_ascii_strcasecmp (right, nm_meta_abstract_info_get_name (nested[j], FALSE)) == 0) { - found = TRUE; - break; - } - } - } - fields_array_failure = fields_array[i]; - break; - } - - if (!found) { + guint i, j; + const char * i_name; + const char * right; + gboolean found = FALSE; + const NMMetaAbstractInfo *fields_array_failure = NULL; + gs_free char * fields_str_clone = NULL; + + nm_assert(fields_str); + nm_assert(p_array); + nm_assert(p_str); + nm_assert(!error || !*error); + + right = strchr(fields_str, '.'); + if (right) { + fields_str_clone = g_strdup(fields_str); + fields_str_clone[right - fields_str] = '\0'; + i_name = fields_str_clone; + right = &fields_str_clone[right - fields_str + 1]; + } else + i_name = fields_str; + + if (!fields_array) + goto not_found; + + for (i = 0; fields_array[i]; i++) { + const NMMetaAbstractInfo * fi = fields_array[i]; + const NMMetaAbstractInfo *const *nested; + gs_free gpointer nested_to_free = NULL; + + if (g_ascii_strcasecmp(i_name, nm_meta_abstract_info_get_name(fi, FALSE)) != 0) + continue; + + if (!right || !validate_nested) { + found = TRUE; + break; + } + + nested = nm_meta_abstract_info_get_nested(fi, NULL, &nested_to_free); + if (nested) { + for (j = 0; nested[j]; nested++) { + if (g_ascii_strcasecmp(right, nm_meta_abstract_info_get_name(nested[j], FALSE)) + == 0) { + found = TRUE; + break; + } + } + } + fields_array_failure = fields_array[i]; + break; + } + + if (!found) { not_found: - if ( !right - && !fields_prefix - && ( !g_ascii_strcasecmp (i_name, "all") - || !g_ascii_strcasecmp (i_name, "common"))) - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, _("field '%s' has to be alone"), i_name); - else { - gs_free char *allowed_fields = NULL; - - if (fields_array_failure) { - gs_free char *p = NULL; - - if (fields_prefix) { - p = g_strdup_printf ("%s.%s", fields_prefix, - nm_meta_abstract_info_get_name (fields_array_failure, FALSE)); - } - allowed_fields = nm_meta_abstract_info_get_nested_names_str (fields_array_failure, p); - } else - allowed_fields = nm_meta_abstract_infos_get_names_str (fields_array, NULL); - - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, _("invalid field '%s%s%s%s%s'; %s%s%s"), - fields_prefix ?: "", fields_prefix ? "." : "", - i_name, right ? "." : "", right ?: "", - NM_PRINT_FMT_QUOTED (allowed_fields, "allowed fields: ", allowed_fields, "", "no fields")); - } - return FALSE; - } - - { - GString *str; - OutputSelectionItem s = { - .idx = i, - }; - - if (!*p_str) - *p_str = g_string_sized_new (64); - str = *p_str; - - s.self_offset_plus_1 = str->len + 1; - if (fields_prefix) { - g_string_append (str, fields_prefix); - g_string_append_c (str, '.'); - } - g_string_append_len (str, i_name, strlen (i_name) + 1); - - if (right) { - s.sub_offset_plus_1 = str->len + 1; - g_string_append_len (str, right, strlen (right) + 1); - } - - if (!*p_array) - *p_array = g_array_new (FALSE, FALSE, sizeof (OutputSelectionItem)); - g_array_append_val (*p_array, s); - } - - return TRUE; + if (!right && !fields_prefix + && (!g_ascii_strcasecmp(i_name, "all") || !g_ascii_strcasecmp(i_name, "common"))) + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_UNKNOWN, + _("field '%s' has to be alone"), + i_name); + else { + gs_free char *allowed_fields = NULL; + + if (fields_array_failure) { + gs_free char *p = NULL; + + if (fields_prefix) { + p = g_strdup_printf( + "%s.%s", + fields_prefix, + nm_meta_abstract_info_get_name(fields_array_failure, FALSE)); + } + allowed_fields = + nm_meta_abstract_info_get_nested_names_str(fields_array_failure, p); + } else + allowed_fields = nm_meta_abstract_infos_get_names_str(fields_array, NULL); + + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_UNKNOWN, + _("invalid field '%s%s%s%s%s'; %s%s%s"), + fields_prefix ?: "", + fields_prefix ? "." : "", + i_name, + right ? "." : "", + right ?: "", + NM_PRINT_FMT_QUOTED(allowed_fields, + "allowed fields: ", + allowed_fields, + "", + "no fields")); + } + return FALSE; + } + + { + GString * str; + OutputSelectionItem s = { + .idx = i, + }; + + if (!*p_str) + *p_str = g_string_sized_new(64); + str = *p_str; + + s.self_offset_plus_1 = str->len + 1; + if (fields_prefix) { + g_string_append(str, fields_prefix); + g_string_append_c(str, '.'); + } + g_string_append_len(str, i_name, strlen(i_name) + 1); + + if (right) { + s.sub_offset_plus_1 = str->len + 1; + g_string_append_len(str, right, strlen(right) + 1); + } + + if (!*p_array) + *p_array = g_array_new(FALSE, FALSE, sizeof(OutputSelectionItem)); + g_array_append_val(*p_array, s); + } + + return TRUE; } NMMetaSelectionResultList * -nm_meta_selection_create_all (const NMMetaAbstractInfo *const* fields_array) +nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array) { - gs_unref_array GArray *array = NULL; - guint i; + gs_unref_array GArray *array = NULL; + guint i; - if (fields_array) { - array = g_array_new (FALSE, FALSE, sizeof (OutputSelectionItem)); - for (i = 0; fields_array[i]; i++) { - OutputSelectionItem s = { - .idx = i, - }; + if (fields_array) { + array = g_array_new(FALSE, FALSE, sizeof(OutputSelectionItem)); + for (i = 0; fields_array[i]; i++) { + OutputSelectionItem s = { + .idx = i, + }; - g_array_append_val (array, s); - } - } + g_array_append_val(array, s); + } + } - return _output_selection_pack (fields_array, array, NULL); + return _output_selection_pack(fields_array, array, NULL); } NMMetaSelectionResultList * -nm_meta_selection_create_parse_one (const NMMetaAbstractInfo *const* fields_array, - const char *fields_prefix, - const char *fields_str, /* one field selector (contains no commas) and is already stripped of spaces. */ - gboolean validate_nested, - GError **error) +nm_meta_selection_create_parse_one( + const NMMetaAbstractInfo *const *fields_array, + const char * fields_prefix, + const char * + fields_str, /* one field selector (contains no commas) and is already stripped of spaces. */ + gboolean validate_nested, + GError **error) { - gs_unref_array GArray *array = NULL; - nm_auto_free_gstring GString *str = NULL; - - g_return_val_if_fail (!error || !*error, NULL); - nm_assert (fields_str && !strchr (fields_str, ',')); - - if (!_output_selection_select_one (fields_array, - fields_prefix, - fields_str, - validate_nested, - &array, - &str, - error)) - return NULL; - return _output_selection_pack (fields_array, array, str); - + gs_unref_array GArray *array = NULL; + nm_auto_free_gstring GString *str = NULL; + + g_return_val_if_fail(!error || !*error, NULL); + nm_assert(fields_str && !strchr(fields_str, ',')); + + if (!_output_selection_select_one(fields_array, + fields_prefix, + fields_str, + validate_nested, + &array, + &str, + error)) + return NULL; + return _output_selection_pack(fields_array, array, str); } NMMetaSelectionResultList * -nm_meta_selection_create_parse_list (const NMMetaAbstractInfo *const* fields_array, - const char *fields_str, /* a comma separated list of selectors */ - gboolean validate_nested, - GError **error) +nm_meta_selection_create_parse_list( + const NMMetaAbstractInfo *const *fields_array, + const char * fields_str, /* a comma separated list of selectors */ + gboolean validate_nested, + GError ** error) { - gs_unref_array GArray *array = NULL; - nm_auto_free_gstring GString *str = NULL; - gs_free char *fields_str_clone = NULL; - char *fields_str_cur; - char *fields_str_next; - - g_return_val_if_fail (!error || !*error, NULL); - - if (!fields_str) - return nm_meta_selection_create_all (fields_array); - - fields_str_clone = g_strdup (fields_str); - for (fields_str_cur = fields_str_clone; fields_str_cur; fields_str_cur = fields_str_next) { - fields_str_cur = nm_str_skip_leading_spaces (fields_str_cur); - fields_str_next = strchr (fields_str_cur, ','); - if (fields_str_next) - *fields_str_next++ = '\0'; - - g_strchomp (fields_str_cur); - if (!fields_str_cur[0]) - continue; - if (!_output_selection_select_one (fields_array, - NULL, - fields_str_cur, - validate_nested, - &array, - &str, - error)) - return NULL; - } - - return _output_selection_pack (fields_array, array, str); + gs_unref_array GArray *array = NULL; + nm_auto_free_gstring GString *str = NULL; + gs_free char * fields_str_clone = NULL; + char * fields_str_cur; + char * fields_str_next; + + g_return_val_if_fail(!error || !*error, NULL); + + if (!fields_str) + return nm_meta_selection_create_all(fields_array); + + fields_str_clone = g_strdup(fields_str); + for (fields_str_cur = fields_str_clone; fields_str_cur; fields_str_cur = fields_str_next) { + fields_str_cur = nm_str_skip_leading_spaces(fields_str_cur); + fields_str_next = strchr(fields_str_cur, ','); + if (fields_str_next) + *fields_str_next++ = '\0'; + + g_strchomp(fields_str_cur); + if (!fields_str_cur[0]) + continue; + if (!_output_selection_select_one(fields_array, + NULL, + fields_str_cur, + validate_nested, + &array, + &str, + error)) + return NULL; + } + + return _output_selection_pack(fields_array, array, str); } diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h index 543b51fc..f5218bc4 100644 --- a/clients/common/nm-meta-setting-access.h +++ b/clients/common/nm-meta-setting-access.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2017 Red Hat, Inc. */ @@ -11,81 +11,90 @@ /*****************************************************************************/ -NMSetting *nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_info, - NMMetaAccessorSettingInitType init_type); +NMSetting *nm_meta_setting_info_editor_new_setting(const NMMetaSettingInfoEditor *setting_info, + NMMetaAccessorSettingInitType init_type); -const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name (const char *setting_name, gboolean use_alias); -const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype (GType gtype); -const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting (NMSetting *setting); +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name(const char *setting_name, + gboolean use_alias); +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype(GType gtype); +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting(NMSetting *setting); -const NMMetaPropertyInfo *nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info, - const char *property_name); -const NMMetaPropertyInfo *nm_meta_property_info_find_by_name (const char *setting_name, - const char *property_name); -const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting (NMSetting *setting, - const char *property_name); +const NMMetaPropertyInfo * +nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info, + const char * property_name); +const NMMetaPropertyInfo *nm_meta_property_info_find_by_name(const char *setting_name, + const char *property_name); +const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting(NMSetting * setting, + const char *property_name); -gboolean nm_meta_setting_info_editor_has_secrets (const NMMetaSettingInfoEditor *setting_info); +gboolean nm_meta_setting_info_editor_has_secrets(const NMMetaSettingInfoEditor *setting_info); /*****************************************************************************/ -const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void); +const NMMetaSettingInfoEditor *const *nm_meta_setting_infos_editor_p(void); /*****************************************************************************/ -const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header); - -const NMMetaAbstractInfo *const*nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info, - guint *out_len, - gpointer *nested_to_free); - -gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - gpointer target, - gpointer target_data, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free); - -const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, +const char *nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_info, + gboolean for_header); + +const NMMetaAbstractInfo *const * +nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info, + guint * out_len, + gpointer * nested_to_free); + +gconstpointer nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + gpointer target, + gpointer target_data, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free); + +const char *const *nm_meta_abstract_info_complete(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char *text, + const char * text, gboolean *out_complete_filename, - char ***out_to_free); + char *** out_to_free); /*****************************************************************************/ -char *nm_meta_abstract_info_get_nested_names_str (const NMMetaAbstractInfo *abstract_info, const char *name_prefix); -char *nm_meta_abstract_infos_get_names_str (const NMMetaAbstractInfo *const*fields_array, const char *name_prefix); +char *nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info, + const char * name_prefix); +char *nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array, + const char * name_prefix); /*****************************************************************************/ typedef struct { - const NMMetaAbstractInfo *info; - const char *self_selection; - const char *sub_selection; - guint idx; + const NMMetaAbstractInfo *info; + const char * self_selection; + const char * sub_selection; + guint idx; } NMMetaSelectionItem; typedef struct { - const guint num; - const NMMetaSelectionItem items[]; + const guint num; + const NMMetaSelectionItem items[]; } NMMetaSelectionResultList; -NMMetaSelectionResultList *nm_meta_selection_create_all (const NMMetaAbstractInfo *const* fields_array); -NMMetaSelectionResultList *nm_meta_selection_create_parse_one (const NMMetaAbstractInfo *const* fields_array, - const char *fields_prefix, - const char *fields_str, - gboolean validate_nested, - GError **error); -NMMetaSelectionResultList *nm_meta_selection_create_parse_list (const NMMetaAbstractInfo *const* fields_array, - const char *fields_str, - gboolean validate_nested, - GError **error); +NMMetaSelectionResultList * +nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array); +NMMetaSelectionResultList * +nm_meta_selection_create_parse_one(const NMMetaAbstractInfo *const *fields_array, + const char * fields_prefix, + const char * fields_str, + gboolean validate_nested, + GError ** error); +NMMetaSelectionResultList * +nm_meta_selection_create_parse_list(const NMMetaAbstractInfo *const *fields_array, + const char * fields_str, + gboolean validate_nested, + GError ** error); #endif /* _NM_META_SETTING_ACCESS_H__ */ diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 2ac91b41..cdb3084a 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2018 Red Hat, Inc. */ @@ -22,406 +22,403 @@ /*****************************************************************************/ -static char *secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type); +static char *secret_flags_to_string(guint32 flags, NMMetaAccessorGetType get_type); -#define ALL_SECRET_FLAGS \ - (NM_SETTING_SECRET_FLAG_NONE | \ - NM_SETTING_SECRET_FLAG_AGENT_OWNED | \ - NM_SETTING_SECRET_FLAG_NOT_SAVED | \ - NM_SETTING_SECRET_FLAG_NOT_REQUIRED) +#define ALL_SECRET_FLAGS \ + (NM_SETTING_SECRET_FLAG_NONE | NM_SETTING_SECRET_FLAG_AGENT_OWNED \ + | NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED) /*****************************************************************************/ static GType -_gobject_property_get_gtype (GObject *gobject, const char *property_name) +_gobject_property_get_gtype(GObject *gobject, const char *property_name) { - GParamSpec *param_spec; + GParamSpec *param_spec; - param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (gobject), property_name); - if (param_spec) - return param_spec->value_type; - g_return_val_if_reached (G_TYPE_INVALID); + param_spec = g_object_class_find_property(G_OBJECT_GET_CLASS(gobject), property_name); + if (param_spec) + return param_spec->value_type; + g_return_val_if_reached(G_TYPE_INVALID); } static GType -_gtype_property_get_gtype (GType gtype, const char *property_name) +_gtype_property_get_gtype(GType gtype, const char *property_name) { - /* given @gtype, a type for a GObject, lookup the property @property_name - * and return its value_type. */ - if (G_TYPE_IS_CLASSED (gtype)) { - GParamSpec *param_spec; - nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref (gtype); + /* given @gtype, a type for a GObject, lookup the property @property_name + * and return its value_type. */ + if (G_TYPE_IS_CLASSED(gtype)) { + GParamSpec * param_spec; + nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref(gtype); - if (G_IS_OBJECT_CLASS (gtypeclass)) { - param_spec = g_object_class_find_property (G_OBJECT_CLASS (gtypeclass), property_name); - if (param_spec) - return param_spec->value_type; - } - } - g_return_val_if_reached (G_TYPE_INVALID); + if (G_IS_OBJECT_CLASS(gtypeclass)) { + param_spec = g_object_class_find_property(G_OBJECT_CLASS(gtypeclass), property_name); + if (param_spec) + return param_spec->value_type; + } + } + g_return_val_if_reached(G_TYPE_INVALID); } /*****************************************************************************/ static char * -bytes_to_string (GBytes *bytes) +bytes_to_string(GBytes *bytes) { - const guint8 *data; - gsize len; + const guint8 *data; + gsize len; - if (!bytes) - return NULL; + if (!bytes) + return NULL; - data = g_bytes_get_data (bytes, &len); - return nm_utils_bin2hexstr_full (data, - len, - '\0', - TRUE, - NULL); + data = g_bytes_get_data(bytes, &len); + return nm_utils_bin2hexstr_full(data, len, '\0', TRUE, NULL); } /*****************************************************************************/ static int -_int64_cmp_desc (gconstpointer a, - gconstpointer b, - gpointer user_data) +_int64_cmp_desc(gconstpointer a, gconstpointer b, gpointer user_data) { - NM_CMP_DIRECT (*((const gint64 *) b), *((const gint64 *) a)); - return 0; + NM_CMP_DIRECT(*((const gint64 *) b), *((const gint64 *) a)); + return 0; } static gint64 * -_value_str_as_index_list (const char *value, gsize *out_len) -{ - gs_free char *str_clone_free = NULL; - gboolean str_cloned = FALSE; - char *str; - gsize i, j; - gsize n_alloc; - gsize len; - gs_free gint64 *arr = NULL; - - *out_len = 0; - - if (!value) - return NULL; - - str = (char *) value; - n_alloc = 0; - len = 0; - while (TRUE) { - gint64 i64; - const char *s; - gsize good; - - good = strcspn (str, ","NM_ASCII_SPACES); - if (good == 0) { - if (str[0] == '\0') - break; - str++; - continue; - } - if (str[good] == '\0') { - s = str; - str += good; - } else { - if (!str_cloned) { - str_cloned = TRUE; - str = nm_strndup_a (200, str, strlen (str), &str_clone_free); - } - s = str; - str[good] = '\0'; - str += good + 1; - } - - i64 = _nm_utils_ascii_str_to_int64 (s, 10, 0, G_MAXINT64, -1); - if (i64 == -1) - return NULL; - - if (len >= n_alloc) { - if (n_alloc > 0) { - n_alloc = n_alloc * 2; - arr = g_realloc (arr, n_alloc * sizeof (gint64)); - } else { - n_alloc = 4; - arr = g_new (gint64, n_alloc); - } - } - arr[len++] = i64; - } - - if (len > 1) { - /* sort the list of indexes descendingly, and drop duplicates. */ - g_qsort_with_data (arr, - len, - sizeof (gint64), - _int64_cmp_desc, - NULL); - j = 1; - for (i = 1; i < len; i++) { - nm_assert (arr[i - 1] >= arr[i]); - if (arr[i - 1] > arr[i]) - arr[j++] = arr[i]; - } - len = j; - } - - *out_len = len; - return g_steal_pointer (&arr); +_value_str_as_index_list(const char *value, gsize *out_len) +{ + gs_free char *str_clone_free = NULL; + gboolean str_cloned = FALSE; + char * str; + gsize i, j; + gsize n_alloc; + gsize len; + gs_free gint64 *arr = NULL; + + *out_len = 0; + + if (!value) + return NULL; + + str = (char *) value; + n_alloc = 0; + len = 0; + while (TRUE) { + gint64 i64; + const char *s; + gsize good; + + good = strcspn(str, "," NM_ASCII_SPACES); + if (good == 0) { + if (str[0] == '\0') + break; + str++; + continue; + } + if (str[good] == '\0') { + s = str; + str += good; + } else { + if (!str_cloned) { + str_cloned = TRUE; + str = nm_strndup_a(200, str, strlen(str), &str_clone_free); + } + s = str; + str[good] = '\0'; + str += good + 1; + } + + i64 = _nm_utils_ascii_str_to_int64(s, 10, 0, G_MAXINT64, -1); + if (i64 == -1) + return NULL; + + if (len >= n_alloc) { + if (n_alloc > 0) { + n_alloc = n_alloc * 2; + arr = g_realloc(arr, n_alloc * sizeof(gint64)); + } else { + n_alloc = 4; + arr = g_new(gint64, n_alloc); + } + } + arr[len++] = i64; + } + + if (len > 1) { + /* sort the list of indexes descendingly, and drop duplicates. */ + g_qsort_with_data(arr, len, sizeof(gint64), _int64_cmp_desc, NULL); + j = 1; + for (i = 1; i < len; i++) { + nm_assert(arr[i - 1] >= arr[i]); + if (arr[i - 1] > arr[i]) + arr[j++] = arr[i]; + } + len = j; + } + + *out_len = len; + return g_steal_pointer(&arr); } #define ESCAPED_TOKENS_WITH_SPACES_DELIMTER ' ' -#define ESCAPED_TOKENS_WITH_SPACES_DELIMTERS NM_ASCII_SPACES"," +#define ESCAPED_TOKENS_WITH_SPACES_DELIMTERS NM_ASCII_SPACES "," -#define ESCAPED_TOKENS_DELIMITER ',' -#define ESCAPED_TOKENS_DELIMITERS "," +#define ESCAPED_TOKENS_DELIMITER ',' +#define ESCAPED_TOKENS_DELIMITERS "," typedef enum { - VALUE_STRSPLIT_MODE_OBJLIST, - VALUE_STRSPLIT_MODE_MULTILIST, - VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, - VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES, + VALUE_STRSPLIT_MODE_OBJLIST, + VALUE_STRSPLIT_MODE_MULTILIST, + VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, + VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES, } ValueStrsplitMode; static const char ** -_value_strsplit (const char *value, - ValueStrsplitMode split_mode, - gsize *out_len) -{ - gs_free const char **strv = NULL; - - /* FIXME: some modes should support backslash escaping. - * In particular, to distinguish from _value_str_as_index_list(), which - * does not accept '\\'. */ - - /* note that all modes remove empty tokens (",", "a,,b", ",,"). */ - switch (split_mode) { - case VALUE_STRSPLIT_MODE_OBJLIST: - strv = nm_utils_strsplit_set_full (value, - ESCAPED_TOKENS_DELIMITERS, - NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP); - break; - case VALUE_STRSPLIT_MODE_MULTILIST: - strv = nm_utils_strsplit_set_full (value, - ESCAPED_TOKENS_WITH_SPACES_DELIMTERS, - NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP); - break; - case VALUE_STRSPLIT_MODE_ESCAPED_TOKENS: - strv = nm_utils_escaped_tokens_split (value, ESCAPED_TOKENS_DELIMITERS); - break; - case VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES: - strv = nm_utils_escaped_tokens_split (value, ESCAPED_TOKENS_WITH_SPACES_DELIMTERS); - break; - } - - NM_SET_OUT (out_len, NM_PTRARRAY_LEN (strv)); - return g_steal_pointer (&strv); +_value_strsplit(const char *value, ValueStrsplitMode split_mode, gsize *out_len) +{ + gs_free const char **strv = NULL; + + /* FIXME: some modes should support backslash escaping. + * In particular, to distinguish from _value_str_as_index_list(), which + * does not accept '\\'. */ + + /* note that all modes remove empty tokens (",", "a,,b", ",,"). */ + switch (split_mode) { + case VALUE_STRSPLIT_MODE_OBJLIST: + strv = nm_utils_strsplit_set_full(value, + ESCAPED_TOKENS_DELIMITERS, + NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP); + break; + case VALUE_STRSPLIT_MODE_MULTILIST: + strv = nm_utils_strsplit_set_full(value, + ESCAPED_TOKENS_WITH_SPACES_DELIMTERS, + NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP); + break; + case VALUE_STRSPLIT_MODE_ESCAPED_TOKENS: + strv = nm_utils_escaped_tokens_split(value, ESCAPED_TOKENS_DELIMITERS); + break; + case VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES: + strv = nm_utils_escaped_tokens_split(value, ESCAPED_TOKENS_WITH_SPACES_DELIMTERS); + break; + } + + NM_SET_OUT(out_len, NM_PTRARRAY_LEN(strv)); + return g_steal_pointer(&strv); } static gboolean -_value_strsplit_assert_unsplitable (const char *str) +_value_strsplit_assert_unsplitable(const char *str) { #if NM_MORE_ASSERTS > 5 - gs_free const char **strv_test = NULL; - gsize j, l; - - /* Assert that we cannot split the token and that it - * has no unescaped delimiters. */ - - strv_test = _value_strsplit (str, - VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, - NULL); - nm_assert (NM_PTRARRAY_LEN (strv_test) == 1); - - for (j = 0; str[j] != '\0'; ) { - if (str[j] == '\\') { - j++; - nm_assert (str[j] != '\0'); - } else - nm_assert (!NM_IN_SET (str[j], '\0', ',')); - j++; - } - l = j; - nm_assert ( !g_ascii_isspace (str[l - 1]) - || ( l >= 2 - && str[l - 2] == '\\')); + gs_free const char **strv_test = NULL; + gsize j, l; + + /* Assert that we cannot split the token and that it + * has no unescaped delimiters. */ + + strv_test = _value_strsplit(str, VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, NULL); + nm_assert(NM_PTRARRAY_LEN(strv_test) == 1); + + for (j = 0; str[j] != '\0';) { + if (str[j] == '\\') { + j++; + nm_assert(str[j] != '\0'); + } else + nm_assert(!NM_IN_SET(str[j], '\0', ',')); + j++; + } + l = j; + nm_assert(!g_ascii_isspace(str[l - 1]) || (l >= 2 && str[l - 2] == '\\')); #endif - return TRUE; + return TRUE; } static NMIPAddress * -_parse_ip_address (int family, const char *address, GError **error) -{ - gs_free char *ip_str = NULL; - const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; - NMIPAddress *addr; - char *plen; - int prefix; - GError *local = NULL; - - g_return_val_if_fail (address, NULL); - g_return_val_if_fail (!error || !*error, NULL); - - ip_str = g_strstrip (g_strdup (address)); - - prefix = MAX_PREFIX; - - plen = strchr (ip_str, '/'); - if (plen) { - *plen++ = '\0'; - if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 1, MAX_PREFIX, -1)) == -1) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid prefix '%s'; <1-%d> allowed"), plen, MAX_PREFIX); - return NULL; - } - } - - addr = nm_ip_address_new (family, ip_str, prefix, &local); - if (!addr) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid IP address: %s"), local->message); - g_clear_error (&local); - } - return addr; +_parse_ip_address(int family, const char *address, GError **error) +{ + gs_free char *ip_str = NULL; + const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; + NMIPAddress * addr; + char * plen; + int prefix; + GError * local = NULL; + + g_return_val_if_fail(address, NULL); + g_return_val_if_fail(!error || !*error, NULL); + + ip_str = g_strstrip(g_strdup(address)); + + prefix = MAX_PREFIX; + + plen = strchr(ip_str, '/'); + if (plen) { + *plen++ = '\0'; + if ((prefix = _nm_utils_ascii_str_to_int64(plen, 10, 1, MAX_PREFIX, -1)) == -1) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid prefix '%s'; <1-%d> allowed"), + plen, + MAX_PREFIX); + return NULL; + } + } + + addr = nm_ip_address_new(family, ip_str, prefix, &local); + if (!addr) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid IP address: %s"), + local->message); + g_clear_error(&local); + } + return addr; } static NMIPRoute * -_parse_ip_route (int family, - const char *str, - GError **error) -{ - const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; - const char *next_hop = NULL; - int prefix; - NMIPRoute *route = NULL; - GError *local = NULL; - gint64 metric = -1; - guint i; - gs_free const char **routev = NULL; - gs_free char *str_clean_free = NULL; - const char *str_clean; - gs_free char *dest_clone = NULL; - const char *dest; - const char *plen; - gs_unref_hashtable GHashTable *attrs = NULL; -#define ROUTE_SYNTAX _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] ...]'") - - nm_assert (NM_IN_SET (family, AF_INET, AF_INET6)); - nm_assert (str); - nm_assert (!error || !*error); - - str_clean = nm_strstrip_avoid_copy_a (300, str, &str_clean_free); - routev = nm_utils_strsplit_set (str_clean, " \t"); - if (!routev) { - g_set_error (error, 1, 0, - "'%s' is not valid. %s", - str, ROUTE_SYNTAX); - return NULL; - } - - dest = routev[0]; - plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) { - dest_clone = g_strdup (dest); - plen = &dest_clone[plen - dest]; - dest = dest_clone; - *((char *) plen) = '\0'; - plen++; - } - prefix = MAX_PREFIX; - if (plen) { - if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 0, MAX_PREFIX, -1)) == -1) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid prefix '%s'; <1-%d> allowed"), - plen, MAX_PREFIX); - return NULL; - } - } - - for (i = 1; routev[i]; i++) { - gint64 tmp64; - - if (nm_utils_ipaddr_is_valid (family, routev[i])) { - if (metric != -1 || attrs) { - g_set_error (error, 1, 0, _("the next hop ('%s') must be first"), routev[i]); - return NULL; - } - next_hop = routev[i]; - } else if ((tmp64 = _nm_utils_ascii_str_to_int64 (routev[i], 10, 0, G_MAXUINT32, -1)) != -1) { - if (attrs) { - g_set_error (error, 1, 0, _("the metric ('%s') must be before attributes"), routev[i]); - return NULL; - } - metric = tmp64; - } else if (strchr (routev[i], '=')) { - GHashTableIter iter; - char *iter_key; - GVariant *iter_value; - gs_unref_hashtable GHashTable *tmp_attrs = NULL; - - tmp_attrs = nm_utils_parse_variant_attributes (routev[i], ' ', '=', FALSE, - nm_ip_route_get_variant_attribute_spec(), - error); - if (!tmp_attrs) { - g_prefix_error (error, "invalid option '%s': ", routev[i]); - return NULL; - } - - if (!attrs) { - attrs = g_hash_table_new_full (nm_str_hash, - g_str_equal, - g_free, - (GDestroyNotify) g_variant_unref); - } - - g_hash_table_iter_init (&iter, tmp_attrs); - while (g_hash_table_iter_next (&iter, (gpointer *) &iter_key, (gpointer *) &iter_value)) { - - /* need to sink the reference, because nm_utils_parse_variant_attributes() returns - * floating refs. */ - g_variant_ref_sink (iter_value); - - if (!nm_ip_route_attribute_validate (iter_key, iter_value, family, NULL, error)) { - g_prefix_error (error, "%s: ", iter_key); - return NULL; - } - g_hash_table_insert (attrs, iter_key, iter_value); - g_hash_table_iter_steal (&iter); - } - } else { - g_set_error (error, 1, 0, "%s", ROUTE_SYNTAX); - return NULL; - } - } - - route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local); - if (!route) { - g_set_error (error, 1, 0, - _("invalid route: %s. %s"), local->message, ROUTE_SYNTAX); - g_clear_error (&local); - return NULL; - } - - if (attrs) { - GHashTableIter iter; - char *name; - GVariant *variant; - - g_hash_table_iter_init (&iter, attrs); - while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) - nm_ip_route_set_attribute (route, name, variant); - } - - return route; +_parse_ip_route(int family, const char *str, GError **error) +{ + const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; + const char * next_hop = NULL; + int prefix; + NMIPRoute * route = NULL; + GError * local = NULL; + gint64 metric = -1; + guint i; + gs_free const char **routev = NULL; + gs_free char * str_clean_free = NULL; + const char * str_clean; + gs_free char * dest_clone = NULL; + const char * dest; + const char * plen; + gs_unref_hashtable GHashTable *attrs = NULL; +#define ROUTE_SYNTAX \ + _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] " \ + "...]'") + + nm_assert(NM_IN_SET(family, AF_INET, AF_INET6)); + nm_assert(str); + nm_assert(!error || !*error); + + str_clean = nm_strstrip_avoid_copy_a(300, str, &str_clean_free); + routev = nm_utils_strsplit_set(str_clean, " \t"); + if (!routev) { + g_set_error(error, 1, 0, "'%s' is not valid. %s", str, ROUTE_SYNTAX); + return NULL; + } + + dest = routev[0]; + plen = strchr(dest, '/'); /* prefix delimiter */ + if (plen) { + dest_clone = g_strdup(dest); + plen = &dest_clone[plen - dest]; + dest = dest_clone; + *((char *) plen) = '\0'; + plen++; + } + prefix = MAX_PREFIX; + if (plen) { + if ((prefix = _nm_utils_ascii_str_to_int64(plen, 10, 0, MAX_PREFIX, -1)) == -1) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid prefix '%s'; <1-%d> allowed"), + plen, + MAX_PREFIX); + return NULL; + } + } + + for (i = 1; routev[i]; i++) { + gint64 tmp64; + + if (nm_utils_ipaddr_is_valid(family, routev[i])) { + if (metric != -1 || attrs) { + g_set_error(error, 1, 0, _("the next hop ('%s') must be first"), routev[i]); + return NULL; + } + next_hop = routev[i]; + } else if ((tmp64 = _nm_utils_ascii_str_to_int64(routev[i], 10, 0, G_MAXUINT32, -1)) + != -1) { + if (attrs) { + g_set_error(error, + 1, + 0, + _("the metric ('%s') must be before attributes"), + routev[i]); + return NULL; + } + metric = tmp64; + } else if (strchr(routev[i], '=')) { + GHashTableIter iter; + char * iter_key; + GVariant * iter_value; + gs_unref_hashtable GHashTable *tmp_attrs = NULL; + + tmp_attrs = nm_utils_parse_variant_attributes(routev[i], + ' ', + '=', + FALSE, + nm_ip_route_get_variant_attribute_spec(), + error); + if (!tmp_attrs) { + g_prefix_error(error, "invalid option '%s': ", routev[i]); + return NULL; + } + + if (!attrs) { + attrs = g_hash_table_new_full(nm_str_hash, + g_str_equal, + g_free, + (GDestroyNotify) g_variant_unref); + } + + g_hash_table_iter_init(&iter, tmp_attrs); + while ( + g_hash_table_iter_next(&iter, (gpointer *) &iter_key, (gpointer *) &iter_value)) { + /* need to sink the reference, because nm_utils_parse_variant_attributes() returns + * floating refs. */ + g_variant_ref_sink(iter_value); + + if (!nm_ip_route_attribute_validate(iter_key, iter_value, family, NULL, error)) { + g_prefix_error(error, "%s: ", iter_key); + return NULL; + } + g_hash_table_insert(attrs, iter_key, iter_value); + g_hash_table_iter_steal(&iter); + } + } else { + g_set_error(error, 1, 0, "%s", ROUTE_SYNTAX); + return NULL; + } + } + + route = nm_ip_route_new(family, dest, prefix, next_hop, metric, &local); + if (!route) { + g_set_error(error, 1, 0, _("invalid route: %s. %s"), local->message, ROUTE_SYNTAX); + g_clear_error(&local); + return NULL; + } + + if (attrs) { + GHashTableIter iter; + char * name; + GVariant * variant; + + g_hash_table_iter_init(&iter, attrs); + while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &variant)) + nm_ip_route_set_attribute(route, name, variant); + } + + return route; } /*****************************************************************************/ /* Max priority values from libnm-core/nm-setting-vlan.c */ #define MAX_SKB_PRIO G_MAXUINT32 -#define MAX_8021P_PRIO 7 /* Max 802.1p priority */ +#define MAX_8021P_PRIO 7 /* Max 802.1p priority */ /* * nmc_proxy_check_script: @@ -435,68 +432,74 @@ _parse_ip_route (int family, * Returns: %TRUE if the script is valid, %FALSE if it is invalid */ static gboolean -nmc_proxy_check_script (const char *script, char **out_script, GError **error) -{ - enum { - _PAC_SCRIPT_TYPE_GUESS, - _PAC_SCRIPT_TYPE_FILE, - _PAC_SCRIPT_TYPE_JSON, - } desired_type = _PAC_SCRIPT_TYPE_GUESS; - const char *filename = NULL; - size_t c_len = 0; - gs_free char *script_clone = NULL; - - *out_script = NULL; - - if (!script || !script[0]) - return TRUE; - - if (g_str_has_prefix (script, "file://")) { - script += NM_STRLEN ("file://"); - desired_type = _PAC_SCRIPT_TYPE_FILE; - } else if (g_str_has_prefix (script, "js://")) { - script += NM_STRLEN ("js://"); - desired_type = _PAC_SCRIPT_TYPE_JSON; - } - - if (NM_IN_SET (desired_type, _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_GUESS)) { - gs_free char *contents = NULL; - - if (!g_file_get_contents (script, &contents, &c_len, NULL)) { - if (desired_type == _PAC_SCRIPT_TYPE_FILE) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("cannot read pac-script from file '%s'"), - script); - return FALSE; - } - } else { - if (c_len != strlen (contents)) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("file '%s' contains non-valid utf-8"), - script); - return FALSE; - } - filename = script; - script = script_clone = g_steal_pointer (&contents); - } - } - - if ( !strstr (script, "FindProxyForURL") - || !g_utf8_validate (script, -1, NULL)) { - if (filename) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' does not contain a valid PAC Script"), filename); - } else { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("Not a valid PAC Script")); - } - return FALSE; - } - - *out_script = (script == script_clone) - ? g_steal_pointer (&script_clone) - : g_strdup (script); - return TRUE; +nmc_proxy_check_script(const char *script, char **out_script, GError **error) +{ + enum { + _PAC_SCRIPT_TYPE_GUESS, + _PAC_SCRIPT_TYPE_FILE, + _PAC_SCRIPT_TYPE_JSON, + } desired_type = _PAC_SCRIPT_TYPE_GUESS; + const char * filename = NULL; + size_t c_len = 0; + gs_free char *script_clone = NULL; + + *out_script = NULL; + + if (!script || !script[0]) + return TRUE; + + if (g_str_has_prefix(script, "file://")) { + script += NM_STRLEN("file://"); + desired_type = _PAC_SCRIPT_TYPE_FILE; + } else if (g_str_has_prefix(script, "js://")) { + script += NM_STRLEN("js://"); + desired_type = _PAC_SCRIPT_TYPE_JSON; + } + + if (NM_IN_SET(desired_type, _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_GUESS)) { + gs_free char *contents = NULL; + + if (!g_file_get_contents(script, &contents, &c_len, NULL)) { + if (desired_type == _PAC_SCRIPT_TYPE_FILE) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("cannot read pac-script from file '%s'"), + script); + return FALSE; + } + } else { + if (c_len != strlen(contents)) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("file '%s' contains non-valid utf-8"), + script); + return FALSE; + } + filename = script; + script = script_clone = g_steal_pointer(&contents); + } + } + + if (!strstr(script, "FindProxyForURL") || !g_utf8_validate(script, -1, NULL)) { + if (filename) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' does not contain a valid PAC Script"), + filename); + } else { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("Not a valid PAC Script")); + } + return FALSE; + } + + *out_script = (script == script_clone) ? g_steal_pointer(&script_clone) : g_strdup(script); + return TRUE; } /* @@ -512,3926 +515,3979 @@ nmc_proxy_check_script (const char *script, char **out_script, GError **error) * Returns: %TRUE if the config is valid, %FALSE if it is invalid */ static gboolean -nmc_team_check_config (const char *config, char **out_config, GError **error) -{ - enum { - _TEAM_CONFIG_TYPE_GUESS, - _TEAM_CONFIG_TYPE_FILE, - _TEAM_CONFIG_TYPE_JSON, - } desired_type = _TEAM_CONFIG_TYPE_GUESS; - size_t c_len = 0; - gs_free char *config_clone = NULL; - - *out_config = NULL; - - if (!config || !config[0]) - return TRUE; - - if (g_str_has_prefix (config, "file://")) { - config += NM_STRLEN ("file://"); - desired_type = _TEAM_CONFIG_TYPE_FILE; - } else if (g_str_has_prefix (config, "json://")) { - config += NM_STRLEN ("json://"); - desired_type = _TEAM_CONFIG_TYPE_JSON; - } - - if (NM_IN_SET (desired_type, _TEAM_CONFIG_TYPE_FILE, _TEAM_CONFIG_TYPE_GUESS)) { - gs_free char *contents = NULL; - - if (!g_file_get_contents (config, &contents, &c_len, NULL)) { - if (desired_type == _TEAM_CONFIG_TYPE_FILE) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("cannot read team config from file '%s'"), - config); - return FALSE; - } - } else { - if (c_len != strlen (contents)) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("team config file '%s' contains non-valid utf-8"), - config); - return FALSE; - } - config = config_clone = g_steal_pointer (&contents); - } - } - - *out_config = (config == config_clone) - ? g_steal_pointer (&config_clone) - : g_strdup (config); - return TRUE; +nmc_team_check_config(const char *config, char **out_config, GError **error) +{ + enum { + _TEAM_CONFIG_TYPE_GUESS, + _TEAM_CONFIG_TYPE_FILE, + _TEAM_CONFIG_TYPE_JSON, + } desired_type = _TEAM_CONFIG_TYPE_GUESS; + size_t c_len = 0; + gs_free char *config_clone = NULL; + + *out_config = NULL; + + if (!config || !config[0]) + return TRUE; + + if (g_str_has_prefix(config, "file://")) { + config += NM_STRLEN("file://"); + desired_type = _TEAM_CONFIG_TYPE_FILE; + } else if (g_str_has_prefix(config, "json://")) { + config += NM_STRLEN("json://"); + desired_type = _TEAM_CONFIG_TYPE_JSON; + } + + if (NM_IN_SET(desired_type, _TEAM_CONFIG_TYPE_FILE, _TEAM_CONFIG_TYPE_GUESS)) { + gs_free char *contents = NULL; + + if (!g_file_get_contents(config, &contents, &c_len, NULL)) { + if (desired_type == _TEAM_CONFIG_TYPE_FILE) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("cannot read team config from file '%s'"), + config); + return FALSE; + } + } else { + if (c_len != strlen(contents)) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("team config file '%s' contains non-valid utf-8"), + config); + return FALSE; + } + config = config_clone = g_steal_pointer(&contents); + } + } + + *out_config = (config == config_clone) ? g_steal_pointer(&config_clone) : g_strdup(config); + return TRUE; } static const char * -_get_text_hidden (NMMetaAccessorGetType get_type) +_get_text_hidden(NMMetaAccessorGetType get_type) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - return _(NM_META_TEXT_HIDDEN); - return NM_META_TEXT_HIDDEN; + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _(NM_META_TEXT_HIDDEN); + return NM_META_TEXT_HIDDEN; } /*****************************************************************************/ -G_GNUC_PRINTF (4, 5) +G_GNUC_PRINTF(4, 5) static void -_env_warn_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMMetaEnvWarnLevel warn_level, - const char *fmt_l10n, - ...) +_env_warn_fcn(const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMMetaEnvWarnLevel warn_level, + const char * fmt_l10n, + ...) { - va_list ap; + va_list ap; - if (!environment || !environment->warn_fcn) - return; + if (!environment || !environment->warn_fcn) + return; - va_start (ap, fmt_l10n); - environment->warn_fcn (environment, - environment_user_data, - warn_level, - fmt_l10n, - ap); - va_end (ap); + va_start(ap, fmt_l10n); + environment->warn_fcn(environment, environment_user_data, warn_level, fmt_l10n, ap); + va_end(ap); } /*****************************************************************************/ -#define ARGS_DESCRIBE_FCN \ - const NMMetaPropertyInfo *property_info, char **out_to_free +#define ARGS_DESCRIBE_FCN const NMMetaPropertyInfo *property_info, char **out_to_free -#define ARGS_GET_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, gboolean *out_is_default, gpointer *out_to_free +#define ARGS_GET_FCN \ + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, \ + gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, \ + NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, \ + gboolean *out_is_default, gpointer *out_to_free -#define ARGS_SET_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorModifier modifier, const char *value, GError **error +#define ARGS_SET_FCN \ + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, \ + gpointer environment_user_data, NMSetting *setting, NMMetaAccessorModifier modifier, \ + const char *value, GError **error -#define ARGS_REMOVE_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, GError **error +#define ARGS_REMOVE_FCN \ + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, \ + gpointer environment_user_data, NMSetting *setting, const char *value, GError **error -#define ARGS_COMPLETE_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, const char *text, gboolean *out_complete_filename, char ***out_to_free +#define ARGS_COMPLETE_FCN \ + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, \ + gpointer environment_user_data, const NMMetaOperationContext *operation_context, \ + const char *text, gboolean *out_complete_filename, char ***out_to_free -#define ARGS_VALUES_FCN \ - const NMMetaPropertyInfo *property_info, char ***out_to_free +#define ARGS_VALUES_FCN const NMMetaPropertyInfo *property_info, char ***out_to_free -#define ARGS_SETTING_INIT_FCN \ - const NMMetaSettingInfoEditor *setting_info, NMSetting *setting, NMMetaAccessorSettingInitType init_type +#define ARGS_SETTING_INIT_FCN \ + const NMMetaSettingInfoEditor *setting_info, NMSetting *setting, \ + NMMetaAccessorSettingInitType init_type -static gboolean _set_fcn_optionlist (ARGS_SET_FCN); +static gboolean _set_fcn_optionlist(ARGS_SET_FCN); static gboolean -_SET_FCN_DO_RESET_DEFAULT (const NMMetaPropertyInfo *property_info, NMMetaAccessorModifier modifier, const char *value) +_SET_FCN_DO_RESET_DEFAULT(const NMMetaPropertyInfo *property_info, + NMMetaAccessorModifier modifier, + const char * value) { - nm_assert (property_info); - nm_assert (!property_info->property_type->set_supports_remove); - nm_assert (NM_IN_SET (modifier, NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD)); - nm_assert ( value - || modifier == NM_META_ACCESSOR_MODIFIER_SET); + nm_assert(property_info); + nm_assert(!property_info->property_type->set_supports_remove); + nm_assert(NM_IN_SET(modifier, NM_META_ACCESSOR_MODIFIER_SET, NM_META_ACCESSOR_MODIFIER_ADD)); + nm_assert(value || modifier == NM_META_ACCESSOR_MODIFIER_SET); - return value == NULL; + return value == NULL; } static gboolean -_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (const NMMetaPropertyInfo *property_info, NMMetaAccessorModifier modifier, const char *value) +_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(const NMMetaPropertyInfo *property_info, + NMMetaAccessorModifier modifier, + const char * value) { - nm_assert (property_info); - nm_assert (property_info->property_type->set_supports_remove); - nm_assert (NM_IN_SET (modifier, NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD, - NM_META_ACCESSOR_MODIFIER_DEL)); - nm_assert ( value - || modifier == NM_META_ACCESSOR_MODIFIER_SET); + nm_assert(property_info); + nm_assert(property_info->property_type->set_supports_remove); + nm_assert(NM_IN_SET(modifier, + NM_META_ACCESSOR_MODIFIER_SET, + NM_META_ACCESSOR_MODIFIER_ADD, + NM_META_ACCESSOR_MODIFIER_DEL)); + nm_assert(value || modifier == NM_META_ACCESSOR_MODIFIER_SET); - return value == NULL; + return value == NULL; } static gboolean -_SET_FCN_DO_SET_ALL (NMMetaAccessorModifier modifier, const char *value) +_SET_FCN_DO_SET_ALL(NMMetaAccessorModifier modifier, const char *value) { - nm_assert (NM_IN_SET (modifier, NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD, - NM_META_ACCESSOR_MODIFIER_DEL)); - nm_assert (value); + nm_assert(NM_IN_SET(modifier, + NM_META_ACCESSOR_MODIFIER_SET, + NM_META_ACCESSOR_MODIFIER_ADD, + NM_META_ACCESSOR_MODIFIER_DEL)); + nm_assert(value); - return modifier == NM_META_ACCESSOR_MODIFIER_SET; + return modifier == NM_META_ACCESSOR_MODIFIER_SET; } static gboolean -_SET_FCN_DO_REMOVE (NMMetaAccessorModifier modifier, const char *value) -{ - nm_assert (NM_IN_SET (modifier, NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD, - NM_META_ACCESSOR_MODIFIER_DEL)); - nm_assert (value); - - return modifier == NM_META_ACCESSOR_MODIFIER_DEL; -} - -#define RETURN_UNSUPPORTED_GET_TYPE() \ - G_STMT_START { \ - if (!NM_IN_SET (get_type, \ - NM_META_ACCESSOR_GET_TYPE_PARSABLE, \ - NM_META_ACCESSOR_GET_TYPE_PRETTY)) { \ - nm_assert_not_reached (); \ - return NULL; \ - } \ - } G_STMT_END; - -#define RETURN_STR_TO_FREE(val) \ - G_STMT_START { \ - char *_val = (val); \ - \ - return ((*(out_to_free)) = _val); \ - } G_STMT_END - -#define RETURN_STR_TEMPORARY(val) \ - G_STMT_START { \ - const char *_val = (val); \ - \ - if (_val == NULL) \ - return NULL; \ - if (_val[0] == '\0') \ - return ""; \ - return ((*(out_to_free)) = g_strdup (_val)); \ - } G_STMT_END +_SET_FCN_DO_REMOVE(NMMetaAccessorModifier modifier, const char *value) +{ + nm_assert(NM_IN_SET(modifier, + NM_META_ACCESSOR_MODIFIER_SET, + NM_META_ACCESSOR_MODIFIER_ADD, + NM_META_ACCESSOR_MODIFIER_DEL)); + nm_assert(value); + + return modifier == NM_META_ACCESSOR_MODIFIER_DEL; +} + +#define RETURN_UNSUPPORTED_GET_TYPE() \ + G_STMT_START \ + { \ + if (!NM_IN_SET(get_type, \ + NM_META_ACCESSOR_GET_TYPE_PARSABLE, \ + NM_META_ACCESSOR_GET_TYPE_PRETTY)) { \ + nm_assert_not_reached(); \ + return NULL; \ + } \ + } \ + G_STMT_END; + +#define RETURN_STR_TO_FREE(val) \ + G_STMT_START \ + { \ + char *_val = (val); \ + \ + return ((*(out_to_free)) = _val); \ + } \ + G_STMT_END + +#define RETURN_STR_TEMPORARY(val) \ + G_STMT_START \ + { \ + const char *_val = (val); \ + \ + if (_val == NULL) \ + return NULL; \ + if (_val[0] == '\0') \ + return ""; \ + return ((*(out_to_free)) = g_strdup(_val)); \ + } \ + G_STMT_END static gboolean -_gobject_property_is_default (NMSetting *setting, const char *prop_name) +_gobject_property_is_default(NMSetting *setting, const char *prop_name) { - nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec *pspec; - GHashTable *ht; - char **strv; + nm_auto_unset_gvalue GValue v = G_VALUE_INIT; + GParamSpec * pspec; + GHashTable * ht; + char ** strv; - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), - prop_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), prop_name); + if (!G_IS_PARAM_SPEC(pspec)) + g_return_val_if_reached(FALSE); - g_value_init (&v, pspec->value_type); - g_object_get_property (G_OBJECT (setting), prop_name, &v); + g_value_init(&v, pspec->value_type); + g_object_get_property(G_OBJECT(setting), prop_name, &v); - if (pspec->value_type == G_TYPE_STRV) { - strv = g_value_get_boxed (&v); - return !strv || !strv[0]; - } else if (pspec->value_type == G_TYPE_HASH_TABLE) { - ht = g_value_get_boxed (&v); - return !ht || !g_hash_table_size (ht); - } + if (pspec->value_type == G_TYPE_STRV) { + strv = g_value_get_boxed(&v); + return !strv || !strv[0]; + } else if (pspec->value_type == G_TYPE_HASH_TABLE) { + ht = g_value_get_boxed(&v); + return !ht || !g_hash_table_size(ht); + } - return g_param_value_defaults (pspec, &v); + return g_param_value_defaults(pspec, &v); } static gboolean -_gobject_property_reset (NMSetting *setting, - const char *prop_name, - gboolean reset_default) +_gobject_property_reset(NMSetting *setting, const char *prop_name, gboolean reset_default) { - nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec *pspec; + nm_auto_unset_gvalue GValue v = G_VALUE_INIT; + GParamSpec * pspec; - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), - prop_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), prop_name); + if (!G_IS_PARAM_SPEC(pspec)) + g_return_val_if_reached(FALSE); - g_value_init (&v, pspec->value_type); - if (reset_default) - g_param_value_set_default (pspec, &v); - g_object_set_property (G_OBJECT (setting), prop_name, &v); - return TRUE; + g_value_init(&v, pspec->value_type); + if (reset_default) + g_param_value_set_default(pspec, &v); + g_object_set_property(G_OBJECT(setting), prop_name, &v); + return TRUE; } static gboolean -_gobject_property_reset_default (NMSetting *setting, const char *prop_name) +_gobject_property_reset_default(NMSetting *setting, const char *prop_name) { - return _gobject_property_reset (setting, prop_name, TRUE); + return _gobject_property_reset(setting, prop_name, TRUE); } static const char * -_coerce_str_emptyunset (NMMetaAccessorGetType get_type, - gboolean is_default, - const char *cstr, - char **out_str) -{ - nm_assert (out_str && !*out_str); - nm_assert ( (!is_default && cstr && cstr[0] != '\0') - || NM_IN_STRSET (cstr, NULL, "")); - - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) { - if ( !cstr - || cstr[0] == '\0') { - if (is_default) - return ""; - else - return "\"\""; - } - nm_assert (!is_default); - return (*out_str = g_strdup_printf ("\"%s\"", cstr)); - } - - /* we coerce NULL/"" to either "" or " ". */ - if ( !cstr - || cstr[0] == '\0') { - if (is_default) - return ""; - else - return " "; - } - nm_assert (!is_default); - return cstr; -} - -#define RETURN_STR_EMPTYUNSET(get_type, is_default, cstr) \ - G_STMT_START { \ - char *_str = NULL; \ - const char *_cstr; \ - \ - _cstr = _coerce_str_emptyunset ((get_type), (is_default), (cstr), &_str); \ - if (_str) \ - RETURN_STR_TO_FREE (_str); \ - RETURN_STR_TEMPORARY (_cstr); \ - } G_STMT_END +_coerce_str_emptyunset(NMMetaAccessorGetType get_type, + gboolean is_default, + const char * cstr, + char ** out_str) +{ + nm_assert(out_str && !*out_str); + nm_assert((!is_default && cstr && cstr[0] != '\0') || NM_IN_STRSET(cstr, NULL, "")); + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) { + if (!cstr || cstr[0] == '\0') { + if (is_default) + return ""; + else + return "\"\""; + } + nm_assert(!is_default); + return (*out_str = g_strdup_printf("\"%s\"", cstr)); + } + + /* we coerce NULL/"" to either "" or " ". */ + if (!cstr || cstr[0] == '\0') { + if (is_default) + return ""; + else + return " "; + } + nm_assert(!is_default); + return cstr; +} + +#define RETURN_STR_EMPTYUNSET(get_type, is_default, cstr) \ + G_STMT_START \ + { \ + char * _str = NULL; \ + const char *_cstr; \ + \ + _cstr = _coerce_str_emptyunset((get_type), (is_default), (cstr), &_str); \ + if (_str) \ + RETURN_STR_TO_FREE(_str); \ + RETURN_STR_TEMPORARY(_cstr); \ + } \ + G_STMT_END static gboolean -_is_default (const NMMetaPropertyInfo *property_info, - NMSetting *setting) -{ - if ( property_info->property_typ_data - && property_info->property_typ_data->is_default_fcn) - return !!(property_info->property_typ_data->is_default_fcn (setting)); - - return _gobject_property_is_default (setting, property_info->property_name); - -} - -static gconstpointer -_get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, - NMSetting *setting, - NMMetaAccessorGetType get_type, - gboolean handle_emptyunset, - gboolean *out_is_default, - gpointer *out_to_free) -{ - const char *cstr; - GType gtype_prop; - nm_auto_unset_gvalue GValue val = G_VALUE_INIT; - gboolean is_default; - gboolean glib_handles_str_transform; - - RETURN_UNSUPPORTED_GET_TYPE (); - - is_default = _is_default (property_info, setting); - - NM_SET_OUT (out_is_default, is_default); - - gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); - - glib_handles_str_transform = !NM_IN_SET (gtype_prop, G_TYPE_BOOLEAN, - G_TYPE_STRV, - G_TYPE_BYTES, - G_TYPE_HASH_TABLE); - - if (glib_handles_str_transform) { - /* We rely on the type convertion of the gobject property to string. */ - g_value_init (&val, G_TYPE_STRING); - } else - g_value_init (&val, gtype_prop); - - g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); - - /* Currently only one particular property asks us to "handle_emptyunset". - * So, don't implement it (yet) for the other types, where it's unneeded. */ - nm_assert ( !handle_emptyunset - || ( gtype_prop == G_TYPE_STRV - && !glib_handles_str_transform)); - - if (gtype_prop == G_TYPE_STRING) { - nm_assert (glib_handles_str_transform); - nm_assert (!handle_emptyunset); - if ( property_info->property_typ_data - && property_info->property_typ_data->subtype.gobject_string.handle_emptyunset) { - /* This string property can both be empty and NULL. We need to - * signal them differently. */ - cstr = g_value_get_string (&val); - nm_assert ((!!is_default) == (cstr == NULL)); - RETURN_STR_EMPTYUNSET (get_type, is_default, NULL); - } - } - - if (glib_handles_str_transform) - RETURN_STR_TEMPORARY (g_value_get_string (&val)); - - if (gtype_prop == G_TYPE_BOOLEAN) { - gboolean b; - - b = g_value_get_boolean (&val); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - cstr = b ? _("yes") : _("no"); - else - cstr = b ? "yes" : "no"; - return cstr; - } - - if (gtype_prop == G_TYPE_STRV) { - const char *const*strv; - - strv = g_value_get_boxed (&val); - if (strv && strv[0]) - RETURN_STR_TO_FREE (g_strjoinv (",", (char **) strv)); - - if (handle_emptyunset) { - /* we need to express empty lists from unset lists differently. */ - RETURN_STR_EMPTYUNSET (get_type, is_default, NULL); - } - - return ""; - } - - if (gtype_prop == G_TYPE_BYTES) { - char *str; - - str = bytes_to_string (g_value_get_boxed (&val)); - NM_SET_OUT (out_is_default, !str || !str[0]); - RETURN_STR_TO_FREE (str); - } - - if (gtype_prop == G_TYPE_HASH_TABLE) { - GHashTable *strdict; - gs_free const char **keys = NULL; - GString *str; - gsize i; - - nm_assert ( property_info->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_WIRED] - && NM_IN_STRSET (property_info->property_name, NM_SETTING_WIRED_S390_OPTIONS)); - nm_assert (property_info->property_type->set_fcn == _set_fcn_optionlist); - - strdict = g_value_get_boxed (&val); - keys = nm_utils_strdict_get_keys (strdict, TRUE, NULL); - if (!keys) - return NULL; - - str = g_string_new (NULL); - for (i = 0; keys[i]; i++) { - const char *key = keys[i]; - const char *v = g_hash_table_lookup (strdict, key); - gs_free char *escaped_key = NULL; - gs_free char *escaped_val = NULL; - - if (str->len > 0) - g_string_append_c (str, ','); - g_string_append (str, nm_utils_escaped_tokens_options_escape_key (key, &escaped_key)); - g_string_append_c (str, '='); - g_string_append (str, nm_utils_escaped_tokens_options_escape_val (v, &escaped_val)); - } - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); - } - - nm_assert_not_reached (); - return NULL; -} - -static gconstpointer -_get_fcn_gobject (ARGS_GET_FCN) -{ - return _get_fcn_gobject_impl (property_info, setting, get_type, FALSE, out_is_default, out_to_free); -} - -static gconstpointer -_get_fcn_gobject_int (ARGS_GET_FCN) -{ - GParamSpec *pspec; - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - gboolean is_uint64 = FALSE; - NMMetaSignUnsignInt64 v; - guint base = 10; - const NMMetaUtilsIntValueInfo *value_infos; - char *return_str; - - RETURN_UNSUPPORTED_GET_TYPE (); - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), property_info->property_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); - - g_value_init (&gval, pspec->value_type); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); - switch (pspec->value_type) { - case G_TYPE_INT: - v.i64 = g_value_get_int (&gval); - break; - case G_TYPE_UINT: - v.u64 = g_value_get_uint (&gval); - is_uint64 = TRUE; - break; - case G_TYPE_INT64: - v.i64 = g_value_get_int64 (&gval); - break; - case G_TYPE_UINT64: - v.u64 = g_value_get_uint64 (&gval); - is_uint64 = TRUE; - break; - default: - g_return_val_if_reached (NULL); - break; - } - - if ( property_info->property_typ_data - && property_info->property_typ_data->subtype.gobject_int.base > 0) { - base = property_info->property_typ_data->subtype.gobject_int.base; - } - - switch (base) { - case 10: - if (is_uint64) - return_str = g_strdup_printf ("%"G_GUINT64_FORMAT, v.u64); - else - return_str = g_strdup_printf ("%"G_GINT64_FORMAT, v.i64); - break; - case 16: - if (is_uint64) - return_str = g_strdup_printf ("0x%"G_GINT64_MODIFIER"x", v.u64); - else - return_str = g_strdup_printf ("0x%"G_GINT64_MODIFIER"x", (guint64) v.i64); - break; - default: - return_str = NULL; - g_assert_not_reached (); - } - - if ( get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY - && property_info->property_typ_data - && (value_infos = property_info->property_typ_data->subtype.gobject_int.value_infos)) { - for (; value_infos->nick; value_infos++) { - if ( ( is_uint64 && value_infos->value.u64 == v.u64) - || (!is_uint64 && value_infos->value.i64 == v.i64)) { - gs_free char *old_str = return_str; - - return_str = g_strdup_printf ("%s (%s)", old_str, value_infos->nick); - break; - } - } - } - - RETURN_STR_TO_FREE (return_str); -} - -static gconstpointer -_get_fcn_gobject_mtu (ARGS_GET_FCN) -{ - guint32 mtu; - - RETURN_UNSUPPORTED_GET_TYPE (); - - if ( !property_info->property_typ_data - || !property_info->property_typ_data->subtype.mtu.get_fcn) - return _get_fcn_gobject_impl (property_info, setting, get_type, FALSE, out_is_default, out_to_free); - - mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting); - if (mtu == 0) { - NM_SET_OUT (out_is_default, TRUE); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - return _("auto"); - return "auto"; - } - RETURN_STR_TO_FREE (g_strdup_printf ("%u", (unsigned) mtu)); -} - -static gconstpointer -_get_fcn_gobject_secret_flags (ARGS_GET_FCN) +_is_default(const NMMetaPropertyInfo *property_info, NMSetting *setting) { - guint v; - GValue val = G_VALUE_INIT; + if (property_info->property_typ_data && property_info->property_typ_data->is_default_fcn) + return !!(property_info->property_typ_data->is_default_fcn(setting)); - RETURN_UNSUPPORTED_GET_TYPE (); - - g_value_init (&val, G_TYPE_UINT); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); - v = g_value_get_uint (&val); - g_value_unset (&val); - RETURN_STR_TO_FREE (secret_flags_to_string (v, get_type)); + return _gobject_property_is_default(setting, property_info->property_name); } static gconstpointer -_get_fcn_gobject_enum (ARGS_GET_FCN) -{ - GType gtype = 0; - nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; - nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; - const struct _NMUtilsEnumValueInfo *value_infos = NULL; - gboolean has_gtype = FALSE; - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - gint64 v; - gboolean format_numeric = FALSE; - gboolean format_numeric_hex = FALSE; - gboolean format_numeric_hex_unknown = FALSE; - gboolean format_text = FALSE; - gboolean format_text_l10n = FALSE; - gs_free char *s = NULL; - char s_numeric[64]; - GParamSpec *pspec; - - RETURN_UNSUPPORTED_GET_TYPE (); - - if (property_info->property_typ_data) { - if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { - gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); - has_gtype = TRUE; - } - } - - if ( property_info->property_typ_data - && get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY - && NM_FLAGS_ANY (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N)) { - format_numeric_hex = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX); - format_numeric = format_numeric_hex || NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC); - format_text_l10n = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N); - format_text = format_text_l10n || NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT); - } else if ( property_info->property_typ_data - && get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY - && NM_FLAGS_ANY (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT)) { - format_numeric_hex = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX); - format_numeric = format_numeric && NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC); - format_text = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT); - } else if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) { - /* by default, output in format "%u (%s)" (with hex for flags and l10n). */ - format_numeric = TRUE; - format_numeric_hex_unknown = TRUE; - format_text = TRUE; - format_text_l10n = TRUE; - } else { - /* by default, output only numeric (with hex for flags). */ - format_numeric = TRUE; - format_numeric_hex_unknown = TRUE; - } - - nm_assert (format_text || format_numeric); - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_info->property_name); - g_return_val_if_fail (pspec, NULL); - - g_value_init (&gval, pspec->value_type); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); - - if ( pspec->value_type == G_TYPE_INT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_ENUM_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_INT) { - if (!has_gtype) - g_return_val_if_reached (NULL); - v = g_value_get_int (&gval); - } else - v = g_value_get_enum (&gval); - } else if ( pspec->value_type == G_TYPE_UINT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_FLAGS_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_UINT) { - if (!has_gtype) - g_return_val_if_reached (NULL); - v = g_value_get_uint (&gval); - } else - v = g_value_get_flags (&gval); - } else - g_return_val_if_reached (NULL); - - if (!has_gtype) { - gtype = pspec->value_type; - gtype_class = g_steal_pointer (>ype_prop_class); - } - - nm_assert (({ - nm_auto_unref_gtypeclass GTypeClass *t = NULL; - - ( G_TYPE_IS_CLASSED (gtype) - && (t = g_type_class_ref (gtype)) - && (G_IS_ENUM_CLASS (t) || G_IS_FLAGS_CLASS (t))); - })); - - if (format_numeric && !format_text) { - s = format_numeric_hex - || ( format_numeric_hex_unknown - && !G_IS_ENUM_CLASS (gtype_class ?: (gtype_class = g_type_class_ref (gtype)))) - ? g_strdup_printf ("0x%"G_GINT64_MODIFIER"x", v) - : g_strdup_printf ("%"G_GINT64_FORMAT, v); - RETURN_STR_TO_FREE (g_steal_pointer (&s)); - } - - /* the gobject_enum.value_infos are currently ignored for the getter. They - * only declare additional aliases for the setter. */ - - if (property_info->property_typ_data) - value_infos = property_info->property_typ_data->subtype.gobject_enum.value_infos_get; - s = _nm_utils_enum_to_str_full (gtype, (int) v, ", ", value_infos); - - if (!format_numeric) - RETURN_STR_TO_FREE (g_steal_pointer (&s)); - - if ( format_numeric_hex - || ( format_numeric_hex_unknown - && !G_IS_ENUM_CLASS (gtype_class ?: (gtype_class = g_type_class_ref (gtype))))) - nm_sprintf_buf (s_numeric, "0x%"G_GINT64_MODIFIER"x", v); - else - nm_sprintf_buf (s_numeric, "%"G_GINT64_FORMAT, v); - - if (nm_streq0 (s, s_numeric)) - RETURN_STR_TO_FREE (g_steal_pointer (&s)); - - if (format_text_l10n) - RETURN_STR_TO_FREE (g_strdup_printf (_("%s (%s)"), s_numeric, s)); - else - RETURN_STR_TO_FREE (g_strdup_printf ("%s (%s)", s_numeric, s)); +_get_fcn_gobject_impl(const NMMetaPropertyInfo *property_info, + NMSetting * setting, + NMMetaAccessorGetType get_type, + gboolean handle_emptyunset, + gboolean * out_is_default, + gpointer * out_to_free) +{ + const char * cstr; + GType gtype_prop; + nm_auto_unset_gvalue GValue val = G_VALUE_INIT; + gboolean is_default; + gboolean glib_handles_str_transform; + + RETURN_UNSUPPORTED_GET_TYPE(); + + is_default = _is_default(property_info, setting); + + NM_SET_OUT(out_is_default, is_default); + + gtype_prop = _gobject_property_get_gtype(G_OBJECT(setting), property_info->property_name); + + glib_handles_str_transform = + !NM_IN_SET(gtype_prop, G_TYPE_BOOLEAN, G_TYPE_STRV, G_TYPE_BYTES, G_TYPE_HASH_TABLE); + + if (glib_handles_str_transform) { + /* We rely on the type conversion of the gobject property to string. */ + g_value_init(&val, G_TYPE_STRING); + } else + g_value_init(&val, gtype_prop); + + g_object_get_property(G_OBJECT(setting), property_info->property_name, &val); + + /* Currently, only one particular property asks us to "handle_emptyunset". + * So, don't implement it (yet) for the other types, where it's unneeded. */ + nm_assert(!handle_emptyunset || (gtype_prop == G_TYPE_STRV && !glib_handles_str_transform)); + + if (gtype_prop == G_TYPE_STRING) { + nm_assert(glib_handles_str_transform); + nm_assert(!handle_emptyunset); + if (property_info->property_typ_data + && property_info->property_typ_data->subtype.gobject_string.handle_emptyunset) { + /* This string property can both be empty and NULL. We need to + * signal them differently. */ + cstr = g_value_get_string(&val); + nm_assert((!!is_default) == (cstr == NULL)); + RETURN_STR_EMPTYUNSET(get_type, is_default, NULL); + } + } + + if (glib_handles_str_transform) + RETURN_STR_TEMPORARY(g_value_get_string(&val)); + + if (gtype_prop == G_TYPE_BOOLEAN) { + gboolean b; + + b = g_value_get_boolean(&val); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + cstr = b ? _("yes") : _("no"); + else + cstr = b ? "yes" : "no"; + return cstr; + } + + if (gtype_prop == G_TYPE_STRV) { + const char *const *strv; + + strv = g_value_get_boxed(&val); + if (strv && strv[0]) + RETURN_STR_TO_FREE(g_strjoinv(",", (char **) strv)); + + if (handle_emptyunset) { + /* we need to express empty lists from unset lists differently. */ + RETURN_STR_EMPTYUNSET(get_type, is_default, NULL); + } + + return ""; + } + + if (gtype_prop == G_TYPE_BYTES) { + char *str; + + str = bytes_to_string(g_value_get_boxed(&val)); + NM_SET_OUT(out_is_default, !str || !str[0]); + RETURN_STR_TO_FREE(str); + } + + if (gtype_prop == G_TYPE_HASH_TABLE) { + GHashTable * strdict; + gs_free const char **keys = NULL; + GString * str; + gsize i; + + nm_assert(property_info->setting_info + == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_WIRED] + && NM_IN_STRSET(property_info->property_name, NM_SETTING_WIRED_S390_OPTIONS)); + nm_assert(property_info->property_type->set_fcn == _set_fcn_optionlist); + + strdict = g_value_get_boxed(&val); + keys = nm_utils_strdict_get_keys(strdict, TRUE, NULL); + if (!keys) + return NULL; + + str = g_string_new(NULL); + for (i = 0; keys[i]; i++) { + const char * key = keys[i]; + const char * v = g_hash_table_lookup(strdict, key); + gs_free char *escaped_key = NULL; + gs_free char *escaped_val = NULL; + + if (str->len > 0) + g_string_append_c(str, ','); + g_string_append(str, nm_utils_escaped_tokens_options_escape_key(key, &escaped_key)); + g_string_append_c(str, '='); + g_string_append(str, nm_utils_escaped_tokens_options_escape_val(v, &escaped_val)); + } + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); + } + + nm_assert_not_reached(); + return NULL; +} + +static gconstpointer _get_fcn_gobject(ARGS_GET_FCN) +{ + return _get_fcn_gobject_impl(property_info, + setting, + get_type, + FALSE, + out_is_default, + out_to_free); +} + +static gconstpointer _get_fcn_gobject_int(ARGS_GET_FCN) +{ + GParamSpec * pspec; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + gboolean is_uint64 = FALSE; + NMMetaSignUnsignInt64 v; + guint base = 10; + const NMMetaUtilsIntValueInfo *value_infos; + char * return_str; + + RETURN_UNSUPPORTED_GET_TYPE(); + + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), + property_info->property_name); + if (!G_IS_PARAM_SPEC(pspec)) + g_return_val_if_reached(FALSE); + + g_value_init(&gval, pspec->value_type); + g_object_get_property(G_OBJECT(setting), property_info->property_name, &gval); + NM_SET_OUT(out_is_default, g_param_value_defaults(pspec, &gval)); + switch (pspec->value_type) { + case G_TYPE_INT: + v.i64 = g_value_get_int(&gval); + break; + case G_TYPE_UINT: + v.u64 = g_value_get_uint(&gval); + is_uint64 = TRUE; + break; + case G_TYPE_INT64: + v.i64 = g_value_get_int64(&gval); + break; + case G_TYPE_UINT64: + v.u64 = g_value_get_uint64(&gval); + is_uint64 = TRUE; + break; + default: + g_return_val_if_reached(NULL); + break; + } + + if (property_info->property_typ_data + && property_info->property_typ_data->subtype.gobject_int.base > 0) { + base = property_info->property_typ_data->subtype.gobject_int.base; + } + + switch (base) { + case 10: + if (is_uint64) + return_str = g_strdup_printf("%" G_GUINT64_FORMAT, v.u64); + else + return_str = g_strdup_printf("%" G_GINT64_FORMAT, v.i64); + break; + case 16: + if (is_uint64) + return_str = g_strdup_printf("0x%" G_GINT64_MODIFIER "x", v.u64); + else + return_str = g_strdup_printf("0x%" G_GINT64_MODIFIER "x", (guint64) v.i64); + break; + default: + return_str = NULL; + g_assert_not_reached(); + } + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY && property_info->property_typ_data + && (value_infos = property_info->property_typ_data->subtype.gobject_int.value_infos)) { + for (; value_infos->nick; value_infos++) { + if ((is_uint64 && value_infos->value.u64 == v.u64) + || (!is_uint64 && value_infos->value.i64 == v.i64)) { + gs_free char *old_str = return_str; + + return_str = g_strdup_printf("%s (%s)", old_str, value_infos->nick); + break; + } + } + } + + RETURN_STR_TO_FREE(return_str); +} + +static gconstpointer _get_fcn_gobject_mtu(ARGS_GET_FCN) +{ + guint32 mtu; + + RETURN_UNSUPPORTED_GET_TYPE(); + + if (!property_info->property_typ_data || !property_info->property_typ_data->subtype.mtu.get_fcn) + return _get_fcn_gobject_impl(property_info, + setting, + get_type, + FALSE, + out_is_default, + out_to_free); + + mtu = property_info->property_typ_data->subtype.mtu.get_fcn(setting); + if (mtu == 0) { + NM_SET_OUT(out_is_default, TRUE); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _("auto"); + return "auto"; + } + RETURN_STR_TO_FREE(g_strdup_printf("%u", (unsigned) mtu)); +} + +static gconstpointer _get_fcn_gobject_secret_flags(ARGS_GET_FCN) +{ + guint v; + GValue val = G_VALUE_INIT; + + RETURN_UNSUPPORTED_GET_TYPE(); + + g_value_init(&val, G_TYPE_UINT); + g_object_get_property(G_OBJECT(setting), property_info->property_name, &val); + v = g_value_get_uint(&val); + g_value_unset(&val); + RETURN_STR_TO_FREE(secret_flags_to_string(v, get_type)); +} + +static gconstpointer _get_fcn_gobject_enum(ARGS_GET_FCN) +{ + GType gtype = 0; + nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; + nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; + const struct _NMUtilsEnumValueInfo * value_infos = NULL; + gboolean has_gtype = FALSE; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + gint64 v; + gboolean format_numeric = FALSE; + gboolean format_numeric_hex = FALSE; + gboolean format_numeric_hex_unknown = FALSE; + gboolean format_text = FALSE; + gboolean format_text_l10n = FALSE; + gs_free char * s = NULL; + char s_numeric[64]; + GParamSpec * pspec; + + RETURN_UNSUPPORTED_GET_TYPE(); + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype(); + has_gtype = TRUE; + } + } + + if (property_info->property_typ_data && get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY + && NM_FLAGS_ANY(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N)) { + format_numeric_hex = NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX); + format_numeric = format_numeric_hex + || NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC); + format_text_l10n = NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N); + format_text = format_text_l10n + || NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT); + } else if (property_info->property_typ_data && get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY + && NM_FLAGS_ANY(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT)) { + format_numeric_hex = NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX); + format_numeric = format_numeric + && NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC); + format_text = NM_FLAGS_HAS(property_info->property_typ_data->typ_flags, + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT); + } else if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) { + /* by default, output in format "%u (%s)" (with hex for flags and l10n). */ + format_numeric = TRUE; + format_numeric_hex_unknown = TRUE; + format_text = TRUE; + format_text_l10n = TRUE; + } else { + /* by default, output only numeric (with hex for flags). */ + format_numeric = TRUE; + format_numeric_hex_unknown = TRUE; + } + + nm_assert(format_text || format_numeric); + + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(setting), property_info->property_name); + g_return_val_if_fail(pspec, NULL); + + g_value_init(&gval, pspec->value_type); + g_object_get_property(G_OBJECT(setting), property_info->property_name, &gval); + NM_SET_OUT(out_is_default, g_param_value_defaults(pspec, &gval)); + + if (pspec->value_type == G_TYPE_INT + || (G_TYPE_IS_CLASSED(pspec->value_type) + && G_IS_ENUM_CLASS( + (gtype_prop_class ?: (gtype_prop_class = g_type_class_ref(pspec->value_type)))))) { + if (pspec->value_type == G_TYPE_INT) { + if (!has_gtype) + g_return_val_if_reached(NULL); + v = g_value_get_int(&gval); + } else + v = g_value_get_enum(&gval); + } else if (pspec->value_type == G_TYPE_UINT + || (G_TYPE_IS_CLASSED(pspec->value_type) + && G_IS_FLAGS_CLASS( + (gtype_prop_class + ?: (gtype_prop_class = g_type_class_ref(pspec->value_type)))))) { + if (pspec->value_type == G_TYPE_UINT) { + if (!has_gtype) + g_return_val_if_reached(NULL); + v = g_value_get_uint(&gval); + } else + v = g_value_get_flags(&gval); + } else + g_return_val_if_reached(NULL); + + if (!has_gtype) { + gtype = pspec->value_type; + gtype_class = g_steal_pointer(>ype_prop_class); + } + + nm_assert(({ + nm_auto_unref_gtypeclass GTypeClass *t = NULL; + + (G_TYPE_IS_CLASSED(gtype) && (t = g_type_class_ref(gtype)) + && (G_IS_ENUM_CLASS(t) || G_IS_FLAGS_CLASS(t))); + })); + + if (format_numeric && !format_text) { + s = format_numeric_hex + || (format_numeric_hex_unknown + && !G_IS_ENUM_CLASS(gtype_class ?: (gtype_class = g_type_class_ref(gtype)))) + ? g_strdup_printf("0x%" G_GINT64_MODIFIER "x", v) + : g_strdup_printf("%" G_GINT64_FORMAT, v); + RETURN_STR_TO_FREE(g_steal_pointer(&s)); + } + + /* the gobject_enum.value_infos are currently ignored for the getter. They + * only declare additional aliases for the setter. */ + + if (property_info->property_typ_data) + value_infos = property_info->property_typ_data->subtype.gobject_enum.value_infos_get; + s = _nm_utils_enum_to_str_full(gtype, (int) v, ", ", value_infos); + + if (!format_numeric) + RETURN_STR_TO_FREE(g_steal_pointer(&s)); + + if (format_numeric_hex + || (format_numeric_hex_unknown + && !G_IS_ENUM_CLASS(gtype_class ?: (gtype_class = g_type_class_ref(gtype))))) + nm_sprintf_buf(s_numeric, "0x%" G_GINT64_MODIFIER "x", v); + else + nm_sprintf_buf(s_numeric, "%" G_GINT64_FORMAT, v); + + if (nm_streq0(s, s_numeric)) + RETURN_STR_TO_FREE(g_steal_pointer(&s)); + + if (format_text_l10n) + RETURN_STR_TO_FREE(g_strdup_printf(_("%s (%s)"), s_numeric, s)); + else + RETURN_STR_TO_FREE(g_strdup_printf("%s (%s)", s_numeric, s)); } /*****************************************************************************/ -static gboolean -_set_fcn_gobject_string (ARGS_SET_FCN) -{ - gs_free char *to_free = NULL; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - if (property_info->property_typ_data) { - if (property_info->property_typ_data->subtype.gobject_string.handle_emptyunset) { - if ( value - && value[0] - && NM_STRCHAR_ALL (value, ch, ch == ' ')) { - /* this string property can both be %NULL and empty. To express that, we coerce - * a value of all whitespaces to dropping the first whitespace. That means, - * " " gives "", " " gives " ", and so on. - * - * This way the user can set the string value to "" (meaning NULL) and to - * " " (meaning ""), and any other string. - * - * This is and non-obvious escaping mechanism. But out of all the possible - * solutions, it seems the most sensible one. */ - value++; - } - } - if (property_info->property_typ_data->subtype.gobject_string.validate_fcn) { - value = property_info->property_typ_data->subtype.gobject_string.validate_fcn (value, &to_free, error); - if (!value) - return FALSE; - } else if (property_info->property_typ_data->values_static) { - value = nmc_string_is_valid (value, - (const char **) property_info->property_typ_data->values_static, - error); - if (!value) - return FALSE; - } - } - g_object_set (setting, property_info->property_name, value, NULL); - return TRUE; -} - -static gboolean -_set_fcn_gobject_bool (ARGS_SET_FCN) -{ - gboolean val_bool; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - if (!nmc_string_to_bool (value, &val_bool, error)) - return FALSE; - - g_object_set (setting, property_info->property_name, val_bool, NULL); - return TRUE; -} - -static gboolean -_set_fcn_gobject_int (ARGS_SET_FCN) -{ - int errsv; - const GParamSpec *pspec; - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - gboolean is_uint64; - NMMetaSignUnsignInt64 v; - gboolean has_minmax = FALSE; - NMMetaSignUnsignInt64 min = { 0 }; - NMMetaSignUnsignInt64 max = { 0 }; - guint base = 10; - const NMMetaUtilsIntValueInfo *value_infos; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), property_info->property_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); - - is_uint64 = NM_IN_SET (pspec->value_type, G_TYPE_UINT, G_TYPE_UINT64); - - if (property_info->property_typ_data) { - if ( value - && (value_infos = property_info->property_typ_data->subtype.gobject_int.value_infos)) { - gs_free char *vv_free = NULL; - const char *vv; - - vv = nm_strstrip_avoid_copy_a (300, value, &vv_free); - for (; value_infos->nick; value_infos++) { - if (nm_streq (value_infos->nick, vv)) { - v = value_infos->value; - goto have_value_from_nick; - } - } - } - - if (property_info->property_typ_data->subtype.gobject_int.base > 0) - base = property_info->property_typ_data->subtype.gobject_int.base; - - if ( ( is_uint64 - && ( property_info->property_typ_data->subtype.gobject_int.min.u64 - || property_info->property_typ_data->subtype.gobject_int.max.u64)) - || ( !is_uint64 - && ( property_info->property_typ_data->subtype.gobject_int.min.i64 - || property_info->property_typ_data->subtype.gobject_int.max.i64))) { - min = property_info->property_typ_data->subtype.gobject_int.min; - max = property_info->property_typ_data->subtype.gobject_int.max; - has_minmax = TRUE; - } - } - - if (!has_minmax) { - switch (pspec->value_type) { - case G_TYPE_INT: - { - const GParamSpecInt *p = (GParamSpecInt *) pspec; - - min.i64 = p->minimum; - max.i64 = p->maximum; - } - break; - case G_TYPE_UINT: - { - const GParamSpecUInt *p = (GParamSpecUInt *) pspec; - - min.u64 = p->minimum; - max.u64 = p->maximum; - } - break; - case G_TYPE_INT64: - { - const GParamSpecInt64 *p = (GParamSpecInt64 *) pspec; - - min.i64 = p->minimum; - max.i64 = p->maximum; - } - break; - case G_TYPE_UINT64: - { - const GParamSpecUInt64 *p = (GParamSpecUInt64 *) pspec; - - min.u64 = p->minimum; - max.u64 = p->maximum; - } - break; - default: - g_return_val_if_reached (FALSE); - } - } - - if (is_uint64) - v.u64 = _nm_utils_ascii_str_to_uint64 (value, base, min.u64, max.u64, 0); - else - v.i64 = _nm_utils_ascii_str_to_int64 (value, base, min.i64, max.i64, 0); - - if ((errsv = errno) != 0) { - if (errsv == ERANGE) { - if (is_uint64) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is out of range [%"G_GUINT64_FORMAT", %"G_GUINT64_FORMAT"]"), - value, min.u64, max.u64); - } else { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is out of range [%"G_GINT64_FORMAT", %"G_GINT64_FORMAT"]"), - value, min.i64, max.i64); - } - } else { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is not a valid number"), value); - } - return FALSE; - } +static gboolean _set_fcn_gobject_string(ARGS_SET_FCN) +{ + gs_free char *to_free = NULL; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_string.handle_emptyunset) { + if (value && value[0] && NM_STRCHAR_ALL(value, ch, ch == ' ')) { + /* this string property can both be %NULL and empty. To express that, we coerce + * a value of all whitespaces to dropping the first whitespace. That means, + * " " gives "", " " gives " ", and so on. + * + * This way the user can set the string value to "" (meaning NULL) and to + * " " (meaning ""), and any other string. + * + * This is and non-obvious escaping mechanism. But out of all the possible + * solutions, it seems the most sensible one. */ + value++; + } + } + if (property_info->property_typ_data->subtype.gobject_string.validate_fcn) { + value = property_info->property_typ_data->subtype.gobject_string.validate_fcn(value, + &to_free, + error); + if (!value) + return FALSE; + } else if (property_info->property_typ_data->values_static) { + value = + nmc_string_is_valid(value, + (const char **) property_info->property_typ_data->values_static, + error); + if (!value) + return FALSE; + } + } + g_object_set(setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean _set_fcn_gobject_bool(ARGS_SET_FCN) +{ + gboolean val_bool; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + if (!nmc_string_to_bool(value, &val_bool, error)) + return FALSE; + + g_object_set(setting, property_info->property_name, val_bool, NULL); + return TRUE; +} + +static gboolean _set_fcn_gobject_int(ARGS_SET_FCN) +{ + int errsv; + const GParamSpec * pspec; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + gboolean is_uint64; + NMMetaSignUnsignInt64 v; + gboolean has_minmax = FALSE; + NMMetaSignUnsignInt64 min = {0}; + NMMetaSignUnsignInt64 max = {0}; + guint base = 10; + const NMMetaUtilsIntValueInfo *value_infos; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), + property_info->property_name); + if (!G_IS_PARAM_SPEC(pspec)) + g_return_val_if_reached(FALSE); + + is_uint64 = NM_IN_SET(pspec->value_type, G_TYPE_UINT, G_TYPE_UINT64); + + if (property_info->property_typ_data) { + if (value + && (value_infos = property_info->property_typ_data->subtype.gobject_int.value_infos)) { + gs_free char *vv_free = NULL; + const char * vv; + + vv = nm_strstrip_avoid_copy_a(300, value, &vv_free); + for (; value_infos->nick; value_infos++) { + if (nm_streq(value_infos->nick, vv)) { + v = value_infos->value; + goto have_value_from_nick; + } + } + } + + if (property_info->property_typ_data->subtype.gobject_int.base > 0) + base = property_info->property_typ_data->subtype.gobject_int.base; + + if ((is_uint64 + && (property_info->property_typ_data->subtype.gobject_int.min.u64 + || property_info->property_typ_data->subtype.gobject_int.max.u64)) + || (!is_uint64 + && (property_info->property_typ_data->subtype.gobject_int.min.i64 + || property_info->property_typ_data->subtype.gobject_int.max.i64))) { + min = property_info->property_typ_data->subtype.gobject_int.min; + max = property_info->property_typ_data->subtype.gobject_int.max; + has_minmax = TRUE; + } + } + + if (!has_minmax) { + switch (pspec->value_type) { + case G_TYPE_INT: + { + const GParamSpecInt *p = (GParamSpecInt *) pspec; + + min.i64 = p->minimum; + max.i64 = p->maximum; + } break; + case G_TYPE_UINT: + { + const GParamSpecUInt *p = (GParamSpecUInt *) pspec; + + min.u64 = p->minimum; + max.u64 = p->maximum; + } break; + case G_TYPE_INT64: + { + const GParamSpecInt64 *p = (GParamSpecInt64 *) pspec; + + min.i64 = p->minimum; + max.i64 = p->maximum; + } break; + case G_TYPE_UINT64: + { + const GParamSpecUInt64 *p = (GParamSpecUInt64 *) pspec; + + min.u64 = p->minimum; + max.u64 = p->maximum; + } break; + default: + g_return_val_if_reached(FALSE); + } + } + + if (is_uint64) + v.u64 = _nm_utils_ascii_str_to_uint64(value, base, min.u64, max.u64, 0); + else + v.i64 = _nm_utils_ascii_str_to_int64(value, base, min.i64, max.i64, 0); + + if ((errsv = errno) != 0) { + if (errsv == ERANGE) { + if (is_uint64) { + g_set_error( + error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is out of range [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT "]"), + value, + min.u64, + max.u64); + } else { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is out of range [%" G_GINT64_FORMAT ", %" G_GINT64_FORMAT "]"), + value, + min.i64, + max.i64); + } + } else { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is not a valid number"), + value); + } + return FALSE; + } have_value_from_nick: - g_value_init (&gval, pspec->value_type); - switch (pspec->value_type) { - case G_TYPE_INT: - g_value_set_int (&gval, v.i64); - break; - case G_TYPE_UINT: - g_value_set_uint (&gval, v.u64); - break; - case G_TYPE_INT64: - g_value_set_int64 (&gval, v.i64); - break; - case G_TYPE_UINT64: - g_value_set_uint64 (&gval, v.u64); - break; - default: - g_return_val_if_reached (FALSE); - break; - } - - /* Validate the number according to the property spec */ - if (!nm_g_object_set_property (G_OBJECT (setting), - property_info->property_name, - &gval, - error)) - g_return_val_if_reached (FALSE); - - return TRUE; -} - -static gboolean -_set_fcn_gobject_mtu (ARGS_SET_FCN) -{ - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - const GParamSpec *pspec; - gint64 v; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - if (nm_streq (value, "auto")) - value = "0"; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), - property_info->property_name); - if (!pspec || pspec->value_type != G_TYPE_UINT) - g_return_val_if_reached (FALSE); - - v = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); - if (v < 0) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is out of range [0, %u]"), value, (unsigned) G_MAXUINT32); - return FALSE; - } - - g_value_init (&gval, pspec->value_type); - g_value_set_uint (&gval, v); - - if (!nm_g_object_set_property (G_OBJECT (setting), - property_info->property_name, - &gval, - error)) - g_return_val_if_reached (FALSE); - - return TRUE; + g_value_init(&gval, pspec->value_type); + switch (pspec->value_type) { + case G_TYPE_INT: + g_value_set_int(&gval, v.i64); + break; + case G_TYPE_UINT: + g_value_set_uint(&gval, v.u64); + break; + case G_TYPE_INT64: + g_value_set_int64(&gval, v.i64); + break; + case G_TYPE_UINT64: + g_value_set_uint64(&gval, v.u64); + break; + default: + g_return_val_if_reached(FALSE); + break; + } + + /* Validate the number according to the property spec */ + if (!nm_g_object_set_property(G_OBJECT(setting), property_info->property_name, &gval, error)) + g_return_val_if_reached(FALSE); + + return TRUE; +} + +static gboolean _set_fcn_gobject_mtu(ARGS_SET_FCN) +{ + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + const GParamSpec * pspec; + gint64 v; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + if (nm_streq(value, "auto")) + value = "0"; + + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), + property_info->property_name); + if (!pspec || pspec->value_type != G_TYPE_UINT) + g_return_val_if_reached(FALSE); + + v = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT32, -1); + if (v < 0) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is out of range [0, %u]"), + value, + (unsigned) G_MAXUINT32); + return FALSE; + } + + g_value_init(&gval, pspec->value_type); + g_value_set_uint(&gval, v); + + if (!nm_g_object_set_property(G_OBJECT(setting), property_info->property_name, &gval, error)) + g_return_val_if_reached(FALSE); + + return TRUE; } /* Ideally we'll be able to get this from a public header. */ #ifndef IEEE802154_ADDR_LEN -#define IEEE802154_ADDR_LEN 8 + #define IEEE802154_ADDR_LEN 8 #endif -static gboolean -_set_fcn_gobject_mac (ARGS_SET_FCN) -{ - NMMetaPropertyTypeMacMode mode; - gboolean valid; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - if (property_info->property_typ_data) - mode = property_info->property_typ_data->subtype.mac.mode; - else - mode = NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT; - - if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND) { - valid = nm_utils_hwaddr_valid (value, INFINIBAND_ALEN); - } else if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_WPAN) { - valid = nm_utils_hwaddr_valid (value, IEEE802154_ADDR_LEN); - } else { - valid = nm_utils_hwaddr_valid (value, ETH_ALEN) - || ( mode == NM_META_PROPERTY_TYPE_MAC_MODE_CLONED - && NM_CLONED_MAC_IS_SPECIAL (value)); - } - - if (!valid) { - g_set_error (error, 1, 0, _("'%s' is not a valid Ethernet MAC"), value); - return FALSE; - } - - g_object_set (setting, property_info->property_name, value, NULL); - return TRUE; -} - -static gboolean -_set_fcn_gobject_enum (ARGS_SET_FCN) -{ - GType gtype = 0; - GType gtype_prop; - gboolean has_gtype = FALSE; - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; - nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; - gboolean is_flags; - int v; - - if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - if (property_info->property_typ_data) { - if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { - gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); - has_gtype = TRUE; - } - } - - gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); - - if ( has_gtype - && NM_IN_SET (gtype_prop, - G_TYPE_INT, - G_TYPE_UINT) - && G_TYPE_IS_CLASSED (gtype) - && (gtype_prop_class = g_type_class_ref (gtype)) - && ( (is_flags = G_IS_FLAGS_CLASS (gtype_prop_class)) - || G_IS_ENUM_CLASS (gtype_prop_class))) { - /* valid */ - } else if ( !has_gtype - && G_TYPE_IS_CLASSED (gtype_prop) - && (gtype_prop_class = g_type_class_ref (gtype_prop)) - && ( (is_flags = G_IS_FLAGS_CLASS (gtype_prop_class)) - || G_IS_ENUM_CLASS (gtype_prop_class))) { - gtype = gtype_prop; - } else - g_return_val_if_reached (FALSE); - - if (!_nm_utils_enum_from_str_full (gtype, value, &v, NULL, - property_info->property_typ_data - ? property_info->property_typ_data->subtype.gobject_enum.value_infos - : NULL)) - goto fail; - - if ( property_info->property_typ_data - && property_info->property_typ_data->subtype.gobject_enum.pre_set_notify) { - property_info->property_typ_data->subtype.gobject_enum.pre_set_notify (property_info, - environment, - environment_user_data, - setting, - v); - } - - gtype_class = g_type_class_ref (gtype); - - if ( G_IS_FLAGS_CLASS (gtype_class) - && !_SET_FCN_DO_SET_ALL (modifier, value)) { - nm_auto_unset_gvalue GValue int_value = { }; - guint v_flag; - - g_value_init (&int_value, G_TYPE_UINT); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &int_value); - v_flag = g_value_get_uint (&int_value); - - if (_SET_FCN_DO_REMOVE (modifier, value)) - v = (int) (v_flag & ~((guint) v)); - else - v = (int) (v_flag | ((guint) v)); - } - - g_value_init (&gval, gtype_prop); - if (gtype_prop == G_TYPE_INT) - g_value_set_int (&gval, v); - else if (gtype_prop == G_TYPE_UINT) - g_value_set_uint (&gval, v); - else if (is_flags) { - nm_assert (G_IS_FLAGS_CLASS (gtype_prop_class)); - g_value_set_flags (&gval, v); - } else { - nm_assert (G_IS_ENUM_CLASS (gtype_prop_class)); - g_value_set_enum (&gval, v); - } - - if (!nm_g_object_set_property (G_OBJECT (setting), property_info->property_name, &gval, NULL)) - goto fail; - - return TRUE; +static gboolean _set_fcn_gobject_mac(ARGS_SET_FCN) +{ + NMMetaPropertyTypeMacMode mode; + gboolean valid; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + if (property_info->property_typ_data) + mode = property_info->property_typ_data->subtype.mac.mode; + else + mode = NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT; + + if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND) { + valid = nm_utils_hwaddr_valid(value, INFINIBAND_ALEN); + } else if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_WPAN) { + valid = nm_utils_hwaddr_valid(value, IEEE802154_ADDR_LEN); + } else { + valid = + nm_utils_hwaddr_valid(value, ETH_ALEN) + || (mode == NM_META_PROPERTY_TYPE_MAC_MODE_CLONED && NM_CLONED_MAC_IS_SPECIAL(value)); + } + + if (!valid) { + g_set_error(error, 1, 0, _("'%s' is not a valid Ethernet MAC"), value); + return FALSE; + } + + g_object_set(setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean _set_fcn_gobject_enum(ARGS_SET_FCN) +{ + GType gtype = 0; + GType gtype_prop; + gboolean has_gtype = FALSE; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; + nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; + gboolean is_flags; + int v; + + if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype(); + has_gtype = TRUE; + } + } + + gtype_prop = _gobject_property_get_gtype(G_OBJECT(setting), property_info->property_name); + + if (has_gtype && NM_IN_SET(gtype_prop, G_TYPE_INT, G_TYPE_UINT) && G_TYPE_IS_CLASSED(gtype) + && (gtype_prop_class = g_type_class_ref(gtype)) + && ((is_flags = G_IS_FLAGS_CLASS(gtype_prop_class)) || G_IS_ENUM_CLASS(gtype_prop_class))) { + /* valid */ + } else if (!has_gtype && G_TYPE_IS_CLASSED(gtype_prop) + && (gtype_prop_class = g_type_class_ref(gtype_prop)) + && ((is_flags = G_IS_FLAGS_CLASS(gtype_prop_class)) + || G_IS_ENUM_CLASS(gtype_prop_class))) { + gtype = gtype_prop; + } else + g_return_val_if_reached(FALSE); + + if (!_nm_utils_enum_from_str_full( + gtype, + value, + &v, + NULL, + property_info->property_typ_data + ? property_info->property_typ_data->subtype.gobject_enum.value_infos + : NULL)) + goto fail; + + if (property_info->property_typ_data + && property_info->property_typ_data->subtype.gobject_enum.pre_set_notify) { + property_info->property_typ_data->subtype.gobject_enum.pre_set_notify(property_info, + environment, + environment_user_data, + setting, + v); + } + + gtype_class = g_type_class_ref(gtype); + + if (G_IS_FLAGS_CLASS(gtype_class) && !_SET_FCN_DO_SET_ALL(modifier, value)) { + nm_auto_unset_gvalue GValue int_value = {}; + guint v_flag; + + g_value_init(&int_value, G_TYPE_UINT); + g_object_get_property(G_OBJECT(setting), property_info->property_name, &int_value); + v_flag = g_value_get_uint(&int_value); + + if (_SET_FCN_DO_REMOVE(modifier, value)) + v = (int) (v_flag & ~((guint) v)); + else + v = (int) (v_flag | ((guint) v)); + } + + g_value_init(&gval, gtype_prop); + if (gtype_prop == G_TYPE_INT) + g_value_set_int(&gval, v); + else if (gtype_prop == G_TYPE_UINT) + g_value_set_uint(&gval, v); + else if (is_flags) { + nm_assert(G_IS_FLAGS_CLASS(gtype_prop_class)); + g_value_set_flags(&gval, v); + } else { + nm_assert(G_IS_ENUM_CLASS(gtype_prop_class)); + g_value_set_enum(&gval, v); + } + + if (!nm_g_object_set_property(G_OBJECT(setting), property_info->property_name, &gval, NULL)) + goto fail; + + return TRUE; fail: - if (error) { - gs_free const char **valid_all = NULL; - gs_free const char *valid_str = NULL; - gboolean has_minmax = FALSE; - int min = G_MININT; - int max = G_MAXINT; - - if (property_info->property_typ_data) { - if ( property_info->property_typ_data->subtype.gobject_enum.min - || property_info->property_typ_data->subtype.gobject_enum.max) { - min = property_info->property_typ_data->subtype.gobject_enum.min; - max = property_info->property_typ_data->subtype.gobject_enum.max; - has_minmax = TRUE; - } - } - - if (!has_minmax && is_flags) { - min = 0; - max = (int) G_MAXUINT; - } - - valid_all = nm_utils_enum_get_values (gtype, min, max); - valid_str = g_strjoinv (",", (char **) valid_all); - if (is_flags) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid option '%s', use a combination of [%s]"), - value, - valid_str); - } else { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid option '%s', use one of [%s]"), - value, - valid_str); - } - } - return FALSE; + if (error) { + gs_free const char **valid_all = NULL; + gs_free const char * valid_str = NULL; + gboolean has_minmax = FALSE; + int min = G_MININT; + int max = G_MAXINT; + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.min + || property_info->property_typ_data->subtype.gobject_enum.max) { + min = property_info->property_typ_data->subtype.gobject_enum.min; + max = property_info->property_typ_data->subtype.gobject_enum.max; + has_minmax = TRUE; + } + } + + if (!has_minmax && is_flags) { + min = 0; + max = (int) G_MAXUINT; + } + + valid_all = nm_utils_enum_get_values(gtype, min, max); + valid_str = g_strjoinv(",", (char **) valid_all); + if (is_flags) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid option '%s', use a combination of [%s]"), + value, + valid_str); + } else { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid option '%s', use one of [%s]"), + value, + valid_str); + } + } + return FALSE; } /*****************************************************************************/ -static const char *const* -_values_fcn_gobject_enum (ARGS_VALUES_FCN) -{ - GType gtype = 0; - gboolean has_gtype = FALSE; - gboolean has_minmax = FALSE; - int min = G_MININT; - int max = G_MAXINT; - char **v; - - if (property_info->property_typ_data) { - if ( property_info->property_typ_data->subtype.gobject_enum.min - || property_info->property_typ_data->subtype.gobject_enum.max) { - min = property_info->property_typ_data->subtype.gobject_enum.min; - max = property_info->property_typ_data->subtype.gobject_enum.max; - has_minmax = TRUE; - } - if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { - gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); - has_gtype = TRUE; - } - } - - if (!has_gtype) { - gtype = _gtype_property_get_gtype (property_info->setting_info->general->get_setting_gtype (), - property_info->property_name); - } - - if ( !has_minmax - && G_TYPE_IS_CLASSED (gtype)) { - nm_auto_unref_gtypeclass GTypeClass *class = NULL; - - class = g_type_class_ref (gtype); - if (G_IS_FLAGS_CLASS (class)) { - min = 0; - max = (int) G_MAXUINT; - } - } - - /* the gobject_enum.value_infos are currently ignored for the list of - * values. They only declare additional (hidden) aliases for the setter. */ - - v = nm_utils_strv_make_deep_copied (nm_utils_enum_get_values (gtype, min, max)); - return (const char *const*) (*out_to_free = v); +static const char *const *_values_fcn_gobject_enum(ARGS_VALUES_FCN) +{ + GType gtype = 0; + gboolean has_gtype = FALSE; + gboolean has_minmax = FALSE; + int min = G_MININT; + int max = G_MAXINT; + char ** v; + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.min + || property_info->property_typ_data->subtype.gobject_enum.max) { + min = property_info->property_typ_data->subtype.gobject_enum.min; + max = property_info->property_typ_data->subtype.gobject_enum.max; + has_minmax = TRUE; + } + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype(); + has_gtype = TRUE; + } + } + + if (!has_gtype) { + gtype = _gtype_property_get_gtype(property_info->setting_info->general->get_setting_gtype(), + property_info->property_name); + } + + if (!has_minmax && G_TYPE_IS_CLASSED(gtype)) { + nm_auto_unref_gtypeclass GTypeClass *class = NULL; + + class = g_type_class_ref(gtype); + if (G_IS_FLAGS_CLASS(class)) { + min = 0; + max = (int) G_MAXUINT; + } + } + + /* the gobject_enum.value_infos are currently ignored for the list of + * values. They only declare additional (hidden) aliases for the setter. */ + + v = nm_utils_strv_make_deep_copied(nm_utils_enum_get_values(gtype, min, max)); + return (const char *const *) (*out_to_free = v); } /*****************************************************************************/ -static const char *const* -_complete_fcn_gobject_bool (ARGS_COMPLETE_FCN) +static const char *const *_complete_fcn_gobject_bool(ARGS_COMPLETE_FCN) { - static const char *const v[] = { - "true", - "false", - "on", - "off", - "1", - "0", - "yes", - "no", - NULL, - }; + static const char *const v[] = { + "true", + "false", + "on", + "off", + "1", + "0", + "yes", + "no", + NULL, + }; - if (!text || !text[0]) - return &v[6]; - return v; + if (!text || !text[0]) + return &v[6]; + return v; } -static const char *const* -_complete_fcn_gobject_devices (ARGS_COMPLETE_FCN) +static const char *const *_complete_fcn_gobject_devices(ARGS_COMPLETE_FCN) { - NMDevice *const*devices = NULL; - guint i, j; - guint len = 0; - char **ifnames; + NMDevice *const *devices = NULL; + guint i, j; + guint len = 0; + char ** ifnames; - if ( environment - && environment->get_nm_devices) { - devices = environment->get_nm_devices (environment, - environment_user_data, - &len); - } + if (environment && environment->get_nm_devices) { + devices = environment->get_nm_devices(environment, environment_user_data, &len); + } - if (len == 0) - return NULL; + if (len == 0) + return NULL; - ifnames = g_new (char *, len + 1); - for (i = 0, j = 0; i < len; i++) { - const char *ifname; + ifnames = g_new(char *, len + 1); + for (i = 0, j = 0; i < len; i++) { + const char *ifname; - nm_assert (NM_IS_DEVICE (devices[i])); + nm_assert(NM_IS_DEVICE(devices[i])); - ifname = nm_device_get_iface (devices[i]); - if (ifname) - ifnames[j++] = g_strdup (ifname); - } - ifnames[j++] = NULL; + ifname = nm_device_get_iface(devices[i]); + if (ifname) + ifnames[j++] = g_strdup(ifname); + } + ifnames[j++] = NULL; - *out_to_free = ifnames; - return (const char *const*) ifnames; + *out_to_free = ifnames; + return (const char *const *) ifnames; } /*****************************************************************************/ static char * -wep_key_type_to_string (NMWepKeyType type) +wep_key_type_to_string(NMWepKeyType type) { - switch (type) { - case NM_WEP_KEY_TYPE_KEY: - return g_strdup_printf (_("%d (key)"), type); - case NM_WEP_KEY_TYPE_PASSPHRASE: - return g_strdup_printf (_("%d (passphrase)"), type); - case NM_WEP_KEY_TYPE_UNKNOWN: - default: - return g_strdup_printf (_("%d (unknown)"), type); - } + switch (type) { + case NM_WEP_KEY_TYPE_KEY: + return g_strdup_printf(_("%d (key)"), type); + case NM_WEP_KEY_TYPE_PASSPHRASE: + return g_strdup_printf(_("%d (passphrase)"), type); + case NM_WEP_KEY_TYPE_UNKNOWN: + default: + return g_strdup_printf(_("%d (unknown)"), type); + } } static char * -vlan_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) +vlan_flags_to_string(guint32 flags, NMMetaAccessorGetType get_type) { - GString *flag_str; + GString *flag_str; - if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) - return g_strdup_printf ("%u", flags); + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf("%u", flags); - if (flags == 0) - return g_strdup (_("0 (NONE)")); + if (flags == 0) + return g_strdup(_("0 (NONE)")); - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%d (", flags); + flag_str = g_string_new(NULL); + g_string_printf(flag_str, "%d (", flags); - if (flags & NM_VLAN_FLAG_REORDER_HEADERS) - g_string_append (flag_str, _("REORDER_HEADERS, ")); - if (flags & NM_VLAN_FLAG_GVRP) - g_string_append (flag_str, _("GVRP, ")); - if (flags & NM_VLAN_FLAG_LOOSE_BINDING) - g_string_append (flag_str, _("LOOSE_BINDING, ")); - if (flags & NM_VLAN_FLAG_MVRP) - g_string_append (flag_str, _("MVRP, ")); + if (flags & NM_VLAN_FLAG_REORDER_HEADERS) + g_string_append(flag_str, _("REORDER_HEADERS, ")); + if (flags & NM_VLAN_FLAG_GVRP) + g_string_append(flag_str, _("GVRP, ")); + if (flags & NM_VLAN_FLAG_LOOSE_BINDING) + g_string_append(flag_str, _("LOOSE_BINDING, ")); + if (flags & NM_VLAN_FLAG_MVRP) + g_string_append(flag_str, _("MVRP, ")); - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + if (flag_str->str[flag_str->len - 1] == '(') + g_string_append(flag_str, _("unknown")); + else + g_string_truncate(flag_str, flag_str->len - 2); /* chop off trailing ', ' */ - g_string_append_c (flag_str, ')'); + g_string_append_c(flag_str, ')'); - return g_string_free (flag_str, FALSE); + return g_string_free(flag_str, FALSE); } static char * -secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) +secret_flags_to_string(guint32 flags, NMMetaAccessorGetType get_type) { - GString *flag_str; + GString *flag_str; - if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) - return g_strdup_printf ("%u", flags); + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf("%u", flags); - if (flags == 0) - return g_strdup (_("0 (none)")); + if (flags == 0) + return g_strdup(_("0 (none)")); - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%u (", flags); + flag_str = g_string_new(NULL); + g_string_printf(flag_str, "%u (", flags); - if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) - g_string_append (flag_str, _("agent-owned, ")); - if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) - g_string_append (flag_str, _("not saved, ")); - if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) - g_string_append (flag_str, _("not required, ")); + if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) + g_string_append(flag_str, _("agent-owned, ")); + if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) + g_string_append(flag_str, _("not saved, ")); + if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) + g_string_append(flag_str, _("not required, ")); - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + if (flag_str->str[flag_str->len - 1] == '(') + g_string_append(flag_str, _("unknown")); + else + g_string_truncate(flag_str, flag_str->len - 2); /* chop off trailing ', ' */ - g_string_append_c (flag_str, ')'); + g_string_append_c(flag_str, ')'); - return g_string_free (flag_str, FALSE); + return g_string_free(flag_str, FALSE); } static const char * -_multilist_do_validate (const NMMetaPropertyInfo *property_info, - NMSetting *setting, - const char *item, - GError **error) -{ - if (property_info->property_typ_data->values_static) { - nm_assert (!property_info->property_typ_data->subtype.multilist.validate_fcn); - return nmc_string_is_valid (item, - (const char **) property_info->property_typ_data->values_static, - error); - } - if (property_info->property_typ_data->subtype.multilist.validate_fcn) { - return property_info->property_typ_data->subtype.multilist.validate_fcn (item, - error); - } - if (property_info->property_typ_data->subtype.multilist.validate2_fcn) { - return property_info->property_typ_data->subtype.multilist.validate2_fcn (setting, - item, - error); - } - - return item; -} - -static gconstpointer -_get_fcn_multilist (ARGS_GET_FCN) -{ - return _get_fcn_gobject_impl (property_info, - setting, - get_type, - property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn != NULL, - out_is_default, - out_to_free); +_multilist_do_validate(const NMMetaPropertyInfo *property_info, + NMSetting * setting, + const char * item, + GError ** error) +{ + if (property_info->property_typ_data->values_static) { + nm_assert(!property_info->property_typ_data->subtype.multilist.validate_fcn); + return nmc_string_is_valid(item, + (const char **) property_info->property_typ_data->values_static, + error); + } + if (property_info->property_typ_data->subtype.multilist.validate_fcn) { + return property_info->property_typ_data->subtype.multilist.validate_fcn(item, error); + } + if (property_info->property_typ_data->subtype.multilist.validate2_fcn) { + return property_info->property_typ_data->subtype.multilist.validate2_fcn(setting, + item, + error); + } + + return item; +} + +static gconstpointer _get_fcn_multilist(ARGS_GET_FCN) +{ + return _get_fcn_gobject_impl( + property_info, + setting, + get_type, + property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn != NULL, + out_is_default, + out_to_free); } static gboolean -_multilist_clear_property (const NMMetaPropertyInfo *property_info, - NMSetting *setting, - gboolean is_set /* or else set default */) -{ - if (property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn) { - property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn (setting, is_set); - return TRUE; - } - if (property_info->property_typ_data->subtype.multilist.clear_all_fcn) { - property_info->property_typ_data->subtype.multilist.clear_all_fcn (setting); - return TRUE; - } - return _gobject_property_reset (setting, property_info->property_name, FALSE); -} - -static gboolean -_set_fcn_multilist (ARGS_SET_FCN) -{ - gs_free const char **strv = NULL; - gsize i, j, nstrv; - - if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (property_info, modifier, value)) - return _multilist_clear_property (property_info, setting, FALSE); - - if ( _SET_FCN_DO_REMOVE (modifier, value) - && ( property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32 - || property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s - || property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u)) { - gs_free gint64 *indexes = NULL; - - indexes = _value_str_as_index_list (value, &nstrv); - if (indexes) { - gint64 num; - - if (property_info->property_typ_data->subtype.multilist.get_num_fcn_u32) - num = property_info->property_typ_data->subtype.multilist.get_num_fcn_u32 (setting); - else - num = property_info->property_typ_data->subtype.multilist.get_num_fcn_u (setting); - for (i = 0; i < nstrv; i++) { - gint64 idx = indexes[i]; - - if (idx >= num) - continue; - - if (property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32) - property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32 (setting, idx); - else if (property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s) - property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s (setting, idx); - else - property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u (setting, idx); - } - return TRUE; - } - } - - if ( _SET_FCN_DO_SET_ALL (modifier, value) - && property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn - && value[0] == '\0') - return _multilist_clear_property (property_info, setting, FALSE); - - strv = _value_strsplit (value, - property_info->property_typ_data->subtype.multilist.strsplit_plain - ? VALUE_STRSPLIT_MODE_MULTILIST - : ( property_info->property_typ_data->subtype.multilist.strsplit_with_spaces - ? VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES - : VALUE_STRSPLIT_MODE_ESCAPED_TOKENS), - &nstrv); - - j = 0; - for (i = 0; i < nstrv; i++) { - const char *item = strv[i]; - - item = _multilist_do_validate (property_info, - setting, - item, - error); - if (!item) - return FALSE; - strv[j++] = item; - } - nstrv = j; - - if (_SET_FCN_DO_SET_ALL (modifier, value)) - _multilist_clear_property (property_info, setting, TRUE); - else if ( property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn - && _is_default (property_info, setting)) { - /* the property is already the default. But we hav here a '+' / '-' modifier, so - * that always makes it non-default (empty) first. */ - _multilist_clear_property (property_info, setting, TRUE); - } - - for (i = 0; i < nstrv; i++) { - if (_SET_FCN_DO_REMOVE (modifier, value)) { - property_info->property_typ_data->subtype.multilist.remove_by_value_fcn (setting, - strv[i]); - } else { - if (property_info->property_typ_data->subtype.multilist.add2_fcn) - property_info->property_typ_data->subtype.multilist.add2_fcn (setting, strv[i]); - else - property_info->property_typ_data->subtype.multilist.add_fcn (setting, strv[i]); - } - } - return TRUE; -} - -static gboolean -_set_fcn_optionlist (ARGS_SET_FCN) -{ - gs_free const char **strv = NULL; - gs_free const char **strv_val = NULL; - gsize strv_len; - gsize i, nstrv; - - nm_assert (!error || !*error); - - if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - nstrv = 0; - strv = nm_utils_escaped_tokens_options_split_list (value); - if (strv) { - strv_len = NM_PTRARRAY_LEN (strv); - - strv_val = g_new (const char *, strv_len); - for (i = 0; strv[i]; i++) { - const char *opt_name; - const char *opt_value; - - nm_utils_escaped_tokens_options_split ((char *) strv[i], &opt_name, &opt_value); - - if ( property_info->property_type->values_fcn - || property_info->property_typ_data->values_static) { - gs_strfreev char **valid_options_to_free = NULL; - const char *const*valid_options; - - if (property_info->property_type->values_fcn) - valid_options = property_info->property_type->values_fcn (property_info, &valid_options_to_free); - else - valid_options = property_info->property_typ_data->values_static; - - opt_name = nmc_string_is_valid (opt_name, (const char **) valid_options, error); - if (!opt_name) - return FALSE; - } - - if (opt_value) { - if (_SET_FCN_DO_REMOVE (modifier, value)) - opt_value = NULL; - } else { - if (!_SET_FCN_DO_REMOVE (modifier, value)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is not valid; use <option>=<value>"), - opt_name); - return FALSE; - } - } - - if ( opt_value - && opt_value[0] == '\0' - && property_info->property_typ_data->subtype.optionlist.no_empty_value) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("cannot set empty \"%s\" option"), - opt_name); - return FALSE; - } - - strv[nstrv] = opt_name; - strv_val[nstrv] = opt_value; - nstrv++; - } - } - - if (_SET_FCN_DO_SET_ALL (modifier, value)) - _gobject_property_reset (setting, property_info->property_name, FALSE); - - for (i = 0; i < nstrv; i++) { - if (!property_info->property_typ_data->subtype.optionlist.set_fcn (setting, - strv[i], - strv_val[i], - error)) - return FALSE; - } - - return TRUE; +_multilist_clear_property(const NMMetaPropertyInfo *property_info, + NMSetting * setting, + gboolean is_set /* or else set default */) +{ + if (property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn) { + property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn(setting, is_set); + return TRUE; + } + if (property_info->property_typ_data->subtype.multilist.clear_all_fcn) { + property_info->property_typ_data->subtype.multilist.clear_all_fcn(setting); + return TRUE; + } + return _gobject_property_reset(setting, property_info->property_name, FALSE); +} + +static gboolean _set_fcn_multilist(ARGS_SET_FCN) +{ + gs_free const char **strv = NULL; + gsize i, j, nstrv; + + if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(property_info, modifier, value)) + return _multilist_clear_property(property_info, setting, FALSE); + + if (_SET_FCN_DO_REMOVE(modifier, value) + && (property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32 + || property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s + || property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u)) { + gs_free gint64 *indexes = NULL; + + indexes = _value_str_as_index_list(value, &nstrv); + if (indexes) { + gint64 num; + + if (property_info->property_typ_data->subtype.multilist.get_num_fcn_u32) + num = property_info->property_typ_data->subtype.multilist.get_num_fcn_u32(setting); + else + num = property_info->property_typ_data->subtype.multilist.get_num_fcn_u(setting); + for (i = 0; i < nstrv; i++) { + gint64 idx = indexes[i]; + + if (idx >= num) + continue; + + if (property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32) + property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u32( + setting, + idx); + else if (property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s) + property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_s(setting, + idx); + else + property_info->property_typ_data->subtype.multilist.remove_by_idx_fcn_u(setting, + idx); + } + return TRUE; + } + } + + if (_SET_FCN_DO_SET_ALL(modifier, value) + && property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn + && value[0] == '\0') + return _multilist_clear_property(property_info, setting, FALSE); + + strv = _value_strsplit( + value, + property_info->property_typ_data->subtype.multilist.strsplit_plain + ? VALUE_STRSPLIT_MODE_MULTILIST + : (property_info->property_typ_data->subtype.multilist.strsplit_with_spaces + ? VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES + : VALUE_STRSPLIT_MODE_ESCAPED_TOKENS), + &nstrv); + + j = 0; + for (i = 0; i < nstrv; i++) { + const char *item = strv[i]; + + item = _multilist_do_validate(property_info, setting, item, error); + if (!item) + return FALSE; + strv[j++] = item; + } + nstrv = j; + + if (_SET_FCN_DO_SET_ALL(modifier, value)) + _multilist_clear_property(property_info, setting, TRUE); + else if (property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn + && _is_default(property_info, setting)) { + /* the property is already the default. But we hav here a '+' / '-' modifier, so + * that always makes it non-default (empty) first. */ + _multilist_clear_property(property_info, setting, TRUE); + } + + for (i = 0; i < nstrv; i++) { + if (_SET_FCN_DO_REMOVE(modifier, value)) { + property_info->property_typ_data->subtype.multilist.remove_by_value_fcn(setting, + strv[i]); + } else { + if (property_info->property_typ_data->subtype.multilist.add2_fcn) + property_info->property_typ_data->subtype.multilist.add2_fcn(setting, strv[i]); + else + property_info->property_typ_data->subtype.multilist.add_fcn(setting, strv[i]); + } + } + return TRUE; +} + +static gboolean _set_fcn_optionlist(ARGS_SET_FCN) +{ + gs_free const char **strv = NULL; + gs_free const char **strv_val = NULL; + gsize strv_len; + gsize i, nstrv; + + nm_assert(!error || !*error); + + if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + nstrv = 0; + strv = nm_utils_escaped_tokens_options_split_list(value); + if (strv) { + strv_len = NM_PTRARRAY_LEN(strv); + + strv_val = g_new(const char *, strv_len); + for (i = 0; strv[i]; i++) { + const char *opt_name; + const char *opt_value; + + nm_utils_escaped_tokens_options_split((char *) strv[i], &opt_name, &opt_value); + + if (property_info->property_type->values_fcn + || property_info->property_typ_data->values_static) { + gs_strfreev char **valid_options_to_free = NULL; + const char *const *valid_options; + + if (property_info->property_type->values_fcn) + valid_options = + property_info->property_type->values_fcn(property_info, + &valid_options_to_free); + else + valid_options = property_info->property_typ_data->values_static; + + opt_name = nmc_string_is_valid(opt_name, (const char **) valid_options, error); + if (!opt_name) + return FALSE; + } + + if (opt_value) { + if (_SET_FCN_DO_REMOVE(modifier, value)) + opt_value = NULL; + } else { + if (!_SET_FCN_DO_REMOVE(modifier, value)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is not valid; use <option>=<value>"), + opt_name); + return FALSE; + } + } + + if (opt_value && opt_value[0] == '\0' + && property_info->property_typ_data->subtype.optionlist.no_empty_value) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("cannot set empty \"%s\" option"), + opt_name); + return FALSE; + } + + strv[nstrv] = opt_name; + strv_val[nstrv] = opt_value; + nstrv++; + } + } + + if (_SET_FCN_DO_SET_ALL(modifier, value)) + _gobject_property_reset(setting, property_info->property_name, FALSE); + + for (i = 0; i < nstrv; i++) { + if (!property_info->property_typ_data->subtype.optionlist.set_fcn(setting, + strv[i], + strv_val[i], + error)) + return FALSE; + } + + return TRUE; } static char * -flag_values_to_string (GFlagsValue *array, guint n) +flag_values_to_string(GFlagsValue *array, guint n) { - GString *str; - guint i; + GString *str; + guint i; - str = g_string_new (NULL); - for (i = 0; i < n; i++) - g_string_append_printf (str, "%u, ", array[i].value); - if (str->len) - g_string_truncate (str, str->len-2); /* chop off trailing ', ' */ - return g_string_free (str, FALSE); + str = g_string_new(NULL); + for (i = 0; i < n; i++) + g_string_append_printf(str, "%u, ", array[i].value); + if (str->len) + g_string_truncate(str, str->len - 2); /* chop off trailing ', ' */ + return g_string_free(str, FALSE); } static gboolean -validate_flags (NMSetting *setting, const char* prop, guint val, GError **error) +validate_flags(NMSetting *setting, const char *prop, guint val, GError **error) { - GParamSpec *pspec; - GValue value = G_VALUE_INIT; - gboolean success = TRUE; + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); - g_assert (G_IS_PARAM_SPEC (pspec)); + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), prop); + g_assert(G_IS_PARAM_SPEC(pspec)); - g_value_init (&value, pspec->value_type); - g_value_set_flags (&value, val); + g_value_init(&value, pspec->value_type); + g_value_set_flags(&value, val); - if (g_param_value_validate (pspec, &value)) { - GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec; - gs_free char *flag_values = NULL; + if (g_param_value_validate(pspec, &value)) { + GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec; + gs_free char * flag_values = NULL; - flag_values = flag_values_to_string (pspec_flags->flags_class->values, - pspec_flags->flags_class->n_values); + flag_values = flag_values_to_string(pspec_flags->flags_class->values, + pspec_flags->flags_class->n_values); - g_set_error (error, 1, 0, _("'%u' flags are not valid; use combination of %s"), - val, flag_values); - success = FALSE; - } - g_value_unset (&value); - return success; + g_set_error(error, + 1, + 0, + _("'%u' flags are not valid; use combination of %s"), + val, + flag_values); + success = FALSE; + } + g_value_unset(&value); + return success; } -static gboolean -_set_fcn_gobject_flags (ARGS_SET_FCN) +static gboolean _set_fcn_gobject_flags(ARGS_SET_FCN) { - unsigned long val_int; + unsigned long val_int; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!nmc_string_to_uint (value, TRUE, 0, G_MAXUINT, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); - return FALSE; - } + if (!nmc_string_to_uint(value, TRUE, 0, G_MAXUINT, &val_int)) { + g_set_error(error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); + return FALSE; + } - /* Validate the flags according to the property spec */ - if (!validate_flags (setting, property_info->property_name, (guint) val_int, error)) - return FALSE; + /* Validate the flags according to the property spec */ + if (!validate_flags(setting, property_info->property_name, (guint) val_int, error)) + return FALSE; - g_object_set (setting, property_info->property_name, (guint) val_int, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, (guint) val_int, NULL); + return TRUE; } -static gboolean -_set_fcn_gobject_ssid (ARGS_SET_FCN) +static gboolean _set_fcn_gobject_ssid(ARGS_SET_FCN) { - gs_unref_bytes GBytes *ssid = NULL; + gs_unref_bytes GBytes *ssid = NULL; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (strlen (value) > 32) { - g_set_error (error, 1, 0, _("'%s' is not valid"), value); - return FALSE; - } + if (strlen(value) > 32) { + g_set_error(error, 1, 0, _("'%s' is not valid"), value); + return FALSE; + } - ssid = g_bytes_new (value, strlen (value)); - g_object_set (setting, property_info->property_name, ssid, NULL); - return TRUE; + ssid = g_bytes_new(value, strlen(value)); + g_object_set(setting, property_info->property_name, ssid, NULL); + return TRUE; } -static gboolean -_set_fcn_gobject_ifname (ARGS_SET_FCN) +static gboolean _set_fcn_gobject_ifname(ARGS_SET_FCN) { - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - g_object_set (setting, property_info->property_name, value, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, value, NULL); + return TRUE; } -static gboolean -_set_fcn_vpn_service_type (ARGS_SET_FCN) +static gboolean _set_fcn_vpn_service_type(ARGS_SET_FCN) { - gs_free char *service_name = NULL; + gs_free char *service_name = NULL; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - service_name = nm_vpn_plugin_info_list_find_service_type (nm_vpn_get_plugin_infos (), value); - g_object_set (setting, property_info->property_name, service_name ?: value, NULL); - return TRUE; + service_name = nm_vpn_plugin_info_list_find_service_type(nm_vpn_get_plugin_infos(), value); + g_object_set(setting, property_info->property_name, service_name ?: value, NULL); + return TRUE; } -static const char *const* -_complete_fcn_vpn_service_type (ARGS_COMPLETE_FCN) +static const char *const *_complete_fcn_vpn_service_type(ARGS_COMPLETE_FCN) { - gsize i, j; - char **values; + gsize i, j; + char **values; - values = nm_vpn_plugin_info_list_get_service_types (nm_vpn_get_plugin_infos (), FALSE, TRUE); - if (!values) - return NULL; + values = nm_vpn_plugin_info_list_get_service_types(nm_vpn_get_plugin_infos(), FALSE, TRUE); + if (!values) + return NULL; - if (!text || !*text) { - /* If the prompt text is empty or contains no '.', - * filter out full names. */ - for (i = 0, j = 0; values[i]; i++) { - if (strchr (values[i], '.')) { - g_free (values[i]); - continue; - } + if (!text || !*text) { + /* If the prompt text is empty or contains no '.', + * filter out full names. */ + for (i = 0, j = 0; values[i]; i++) { + if (strchr(values[i], '.')) { + g_free(values[i]); + continue; + } - if (i != j) - values[j] = values[i]; - j++; - } - if (j) - values[j++] = NULL; - else { - g_free (values); - values = NULL; - } - } - return (const char *const*) (*out_to_free = values); + if (i != j) + values[j] = values[i]; + j++; + } + if (j) + values[j++] = NULL; + else { + g_free(values); + values = NULL; + } + } + return (const char *const *) (*out_to_free = values); } static const char * -_multilist_validate_fcn_is_domain (const char *domain, GError **error) +_multilist_validate_fcn_is_domain(const char *domain, GError **error) { - //FIXME: implement - return domain; + //FIXME: implement + return domain; } -static gboolean -_set_fcn_gobject_bytes (ARGS_SET_FCN) -{ - gs_free char *val_strip_free = NULL; - gs_free const char **strv = NULL; - const char *val_strip; - const char **iter; - gs_unref_bytes GBytes *bytes = NULL; - GByteArray *array; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - val_strip = nm_strstrip_avoid_copy_a (300, value, &val_strip_free); - - /* First try hex string in the format of AAbbCCDd */ - bytes = nm_utils_hexstr2bin (val_strip); - if (bytes) - goto done; - - if ( !property_info->property_typ_data - || !property_info->property_typ_data->subtype.gobject_bytes.legacy_format) { - if (value && value[0]) { - g_set_error_literal (error, 1, 0, _("not a valid hex-string")); - return FALSE; - } - /* accept the empty word to reset the property to %NULL. */ - goto done; - } - - /* Otherwise, consider the following format: AA b 0xCc D */ - strv = nm_utils_strsplit_set (value, " \t"); - array = g_byte_array_sized_new (NM_PTRARRAY_LEN (strv)); - for (iter = strv; iter && *iter; iter++) { - int v; - guint8 v8; - - v = _nm_utils_ascii_str_to_int64 (*iter, 16, 0, 255, -1); - if (v == -1) { - g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter); - g_byte_array_free (array, TRUE); - return FALSE; - } - v8 = v; - g_byte_array_append (array, &v8, 1); - } - bytes = g_byte_array_free_to_bytes (array); +static const char * +_multilist_validate_fcn_is_ipv4_addr_or_subnet(const char *value, GError **error) +{ + if (!nm_utils_parse_inaddr_prefix_bin(AF_INET, value, NULL, NULL, NULL)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid IPv4 or subnet \"%s\""), + value); + return NULL; + } + + return value; +} + +static gboolean _set_fcn_gobject_bytes(ARGS_SET_FCN) +{ + gs_free char * val_strip_free = NULL; + gs_free const char **strv = NULL; + const char * val_strip; + const char ** iter; + gs_unref_bytes GBytes *bytes = NULL; + GByteArray * array; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + val_strip = nm_strstrip_avoid_copy_a(300, value, &val_strip_free); + + /* First try hex string in the format of AAbbCCDd */ + bytes = nm_utils_hexstr2bin(val_strip); + if (bytes) + goto done; + + if (!property_info->property_typ_data + || !property_info->property_typ_data->subtype.gobject_bytes.legacy_format) { + if (value && value[0]) { + g_set_error_literal(error, 1, 0, _("not a valid hex-string")); + return FALSE; + } + /* accept the empty word to reset the property to %NULL. */ + goto done; + } + + /* Otherwise, consider the following format: AA b 0xCc D */ + strv = nm_utils_strsplit_set(value, " \t"); + array = g_byte_array_sized_new(NM_PTRARRAY_LEN(strv)); + for (iter = strv; iter && *iter; iter++) { + int v; + guint8 v8; + + v = _nm_utils_ascii_str_to_int64(*iter, 16, 0, 255, -1); + if (v == -1) { + g_set_error(error, 1, 0, _("'%s' is not a valid hex character"), *iter); + g_byte_array_free(array, TRUE); + return FALSE; + } + v8 = v; + g_byte_array_append(array, &v8, 1); + } + bytes = g_byte_array_free_to_bytes(array); done: - g_object_set (setting, property_info->property_name, bytes, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, bytes, NULL); + return TRUE; } /*****************************************************************************/ -static gconstpointer -_get_fcn_cert_8021x (ARGS_GET_FCN) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - const NMSetting8021xSchemeVtable *vtable; - char *str = NULL; +static gconstpointer _get_fcn_cert_8021x(ARGS_GET_FCN) +{ + NMSetting8021x * s_8021X = NM_SETTING_802_1X(setting); + const NMSetting8021xSchemeVtable *vtable; + char * str = NULL; + + RETURN_UNSUPPORTED_GET_TYPE(); + + vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x + .scheme_type]; + + switch (vtable->scheme_func(s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) + return _get_text_hidden(get_type); + str = bytes_to_string(vtable->blob_func(s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + str = g_strdup(vtable->path_func(s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + str = g_strdup(vtable->uri_func(s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + NM_SET_OUT(out_is_default, !str || !str[0]); + RETURN_STR_TO_FREE(str); +} + +static gboolean _set_fcn_cert_8021x(ARGS_SET_FCN) +{ + gs_free char * value_to_free = NULL; + NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_PATH; + const NMSetting8021xSchemeVtable *vtable; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + value = nm_strstrip_avoid_copy_a(300, value, &value_to_free); + + if (strncmp(value, + NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11, + NM_STRLEN(NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) + == 0) + scheme = NM_SETTING_802_1X_CK_SCHEME_PKCS11; + else if (strncmp(value, + NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, + NM_STRLEN(NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) + == 0) + value += NM_STRLEN(NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH); + + vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x + .scheme_type]; + + if (vtable->is_secret) { + nm_auto_free_secret char *password_free = NULL; + gs_free const char ** strv = NULL; + const char * password; + const char * path; + gsize len; + + strv = nm_utils_escaped_tokens_split(value, NM_ASCII_SPACES); + len = NM_PTRARRAY_LEN(strv); + if (len > 2) { + g_set_error_literal(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("too many arguments. Please only specify a private key file and " + "optionally a password")); + return FALSE; + } + + path = len > 0 ? strv[0] : NULL; + if (len == 2) { + password = strv[1]; + } else { + password_free = g_strdup(vtable->passwd_func(NM_SETTING_802_1X(setting))); + password = password_free; + } + + return vtable + ->set_private_key_func(NM_SETTING_802_1X(setting), path, password, scheme, NULL, error); + } else { + return vtable->set_cert_func(NM_SETTING_802_1X(setting), value, scheme, NULL, error); + } +} + +static const char *const *_complete_fcn_cert_8021x(ARGS_COMPLETE_FCN) +{ + const NMSetting8021xSchemeVtable *vtable; + + vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x + .scheme_type]; + + if (vtable->is_secret) { + gs_free const char **strv = NULL; + + strv = nm_utils_escaped_tokens_split(text, NM_ASCII_SPACES); + /* don't try to complete the password */ + if (NM_PTRARRAY_LEN(strv) > 1) + return NULL; + } + + NM_SET_OUT(out_complete_filename, TRUE); + return NULL; +} + +static gconstpointer _get_fcn_bond_options(ARGS_GET_FCN) +{ + NMSettingBond *s_bond = NM_SETTING_BOND(setting); + GString * str; + guint32 i, len; + + RETURN_UNSUPPORTED_GET_TYPE(); + + str = g_string_new(NULL); + len = nm_setting_bond_get_num_options(s_bond); + for (i = 0; i < len; i++) { + const char * key; + const char * val; + gs_free char *val_tmp = NULL; + char * p; + gs_free char *escaped_key = NULL; + gs_free char *escaped_val = NULL; - RETURN_UNSUPPORTED_GET_TYPE (); - - vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x.scheme_type]; - - switch (vtable->scheme_func (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) - return _get_text_hidden (get_type); - str = bytes_to_string (vtable->blob_func (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - str = g_strdup (vtable->path_func (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - str = g_strdup (vtable->uri_func (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - NM_SET_OUT (out_is_default, !str || !str[0]); - RETURN_STR_TO_FREE (str); -} - -static gboolean -_set_fcn_cert_8021x (ARGS_SET_FCN) -{ - gs_free char *value_to_free = NULL; - NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_PATH; - const NMSetting8021xSchemeVtable *vtable; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - value = nm_strstrip_avoid_copy_a (300, value, &value_to_free); - - if (strncmp (value, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) == 0) - scheme = NM_SETTING_802_1X_CK_SCHEME_PKCS11; - else if (strncmp (value, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) == 0) - value += NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH); - - vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x.scheme_type]; - - if (vtable->is_secret) { - nm_auto_free_secret char *password_free = NULL; - gs_free const char **strv = NULL; - const char *password; - const char *path; - gsize len; - - strv = nm_utils_escaped_tokens_split (value, NM_ASCII_SPACES); - len = NM_PTRARRAY_LEN (strv); - if (len > 2) { - g_set_error_literal (error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_INVALID_ARGUMENT, - _("too many arguments. Please only specify a private key file and optionally a password")); - return FALSE; - } - - path = len > 0 ? strv[0] : NULL; - if (len == 2) { - password = strv[1]; - } else { - password_free = g_strdup (vtable->passwd_func (NM_SETTING_802_1X (setting))); - password = password_free; - } - - return vtable->set_private_key_func (NM_SETTING_802_1X (setting), - path, - password, - scheme, - NULL, - error); - } else { - return vtable->set_cert_func (NM_SETTING_802_1X (setting), - value, - scheme, - NULL, - error); - } -} - -static const char *const* -_complete_fcn_cert_8021x (ARGS_COMPLETE_FCN) -{ - const NMSetting8021xSchemeVtable *vtable; - - vtable = &nm_setting_8021x_scheme_vtable[property_info->property_typ_data->subtype.cert_8021x.scheme_type]; - - if (vtable->is_secret) { - gs_free const char **strv = NULL; - - strv = nm_utils_escaped_tokens_split (text, NM_ASCII_SPACES); - /* don't try to complete the password */ - if (NM_PTRARRAY_LEN (strv) > 1) - return NULL; - } - - NM_SET_OUT (out_complete_filename, TRUE); - return NULL; -} - -static gconstpointer -_get_fcn_bond_options (ARGS_GET_FCN) -{ - NMSettingBond *s_bond = NM_SETTING_BOND (setting); - GString *str; - guint32 i, len; - - RETURN_UNSUPPORTED_GET_TYPE (); - - str = g_string_new (NULL); - len = nm_setting_bond_get_num_options (s_bond); - for (i = 0; i < len; i++) { - const char *key; - const char *val; - gs_free char *val_tmp = NULL; - char *p; - gs_free char *escaped_key = NULL; - gs_free char *escaped_val = NULL; - - nm_setting_bond_get_option (s_bond, i, &key, &val); - - if (nm_streq (key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { - val_tmp = g_strdup (val); - for (p = val_tmp; p && *p; p++) { - if (*p == ',') - *p = ' '; - } - val = val_tmp; - } - - if (str->len > 0u) - g_string_append_c (str, ','); - g_string_append (str, nm_utils_escaped_tokens_options_escape_key (key, &escaped_key)); - g_string_append_c (str, '='); - g_string_append (str, nm_utils_escaped_tokens_options_escape_val (val, &escaped_val)); - } - - NM_SET_OUT (out_is_default, str->len == 0); - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + nm_setting_bond_get_option(s_bond, i, &key, &val); + + if (nm_streq(key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { + val_tmp = g_strdup(val); + for (p = val_tmp; p && *p; p++) { + if (*p == ',') + *p = ' '; + } + val = val_tmp; + } + + if (str->len > 0u) + g_string_append_c(str, ','); + g_string_append(str, nm_utils_escaped_tokens_options_escape_key(key, &escaped_key)); + g_string_append_c(str, '='); + g_string_append(str, nm_utils_escaped_tokens_options_escape_val(val, &escaped_val)); + } + + NM_SET_OUT(out_is_default, str->len == 0); + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } gboolean -_nm_meta_setting_bond_add_option (NMSetting *setting, - const char *name, - const char *value, - GError **error) -{ - gs_free char *tmp_value = NULL; - char *p; - - if ( !value - || !value[0]) { - if (!nm_setting_bond_remove_option (NM_SETTING_BOND (setting), name)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("failed to unset bond option \"%s\""), - name); - return FALSE; - } - return TRUE; - } - - if (nm_streq (name, NM_SETTING_BOND_OPTION_MODE)) { - value = nmc_bond_validate_mode (value, error); - if (!value) - return FALSE; - } else if (nm_streq (name, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { - value = tmp_value = g_strdup (value); - for (p = tmp_value; p && *p; p++) - if (*p == ' ') - *p = ','; - } - - if (!nm_setting_bond_add_option (NM_SETTING_BOND (setting), name, value)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("failed to set bond option \"%s\""), - name); - return FALSE; - } - - if (nm_streq (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)) { - if (_nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT, 0) > 0) - _nm_setting_bond_remove_options_miimon (NM_SETTING_BOND (setting)); - } else if (nm_streq (name, NM_SETTING_BOND_OPTION_MIIMON)) { - if (_nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT, 0) > 0) - _nm_setting_bond_remove_options_arp_interval (NM_SETTING_BOND (setting)); - } - - return TRUE; -} - -static const char * -_describe_fcn_bond_options (ARGS_DESCRIBE_FCN) -{ - gs_free char *options_str = NULL; - const char **valid_options; - char *s; +_nm_meta_setting_bond_add_option(NMSetting * setting, + const char *name, + const char *value, + GError ** error) +{ + NMSettingBond *s_bond = NM_SETTING_BOND(setting); + gs_free char * tmp_value = NULL; + const char * val2; + char * p; + + if (!value || !value[0]) { + if (!nm_setting_bond_remove_option(s_bond, name)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("failed to unset bond option \"%s\""), + name); + return FALSE; + } + return TRUE; + } + + if (nm_streq(name, NM_SETTING_BOND_OPTION_MODE)) { + value = nmc_bond_validate_mode(value, error); + if (!value) + return FALSE; + } else if (nm_streq(name, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { + value = tmp_value = g_strdup(value); + for (p = tmp_value; p && *p; p++) + if (*p == ' ') + *p = ','; + } + + if (!nm_setting_bond_add_option(s_bond, name, value)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("failed to set bond option \"%s\""), + name); + return FALSE; + } + + if (nm_streq(name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)) { + if (_nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXINT, 0) > 0) + _nm_setting_bond_remove_options_miimon(s_bond); + } else if (nm_streq(name, NM_SETTING_BOND_OPTION_MIIMON)) { + if (_nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXINT, 0) > 0) + _nm_setting_bond_remove_options_arp_interval(s_bond); + } else if (nm_streq(name, NM_SETTING_BOND_OPTION_PRIMARY)) { + if ((val2 = nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE)) + && !nm_streq(val2, value)) { + /* "active_slave" option is deprecated and an alias for "primary". When + * setting "primary" to a different value, remove the deprecated "active_slave" + * setting. + * + * If we wouldn't do this, then the profile would work as requested, but ignoring + * the (redundant, differing) "active_slave" option. That is confusing, thus clean + * it up. */ + nm_setting_bond_remove_option(s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE); + } + } else if (nm_streq(name, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE)) { + if ((val2 = nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_PRIMARY)) + && !nm_streq(val2, value)) { + /* "active_slave" is a deprecated alias for "primary". NetworkManager will ignore + * "active_slave" if "primary" is set, we thus need to coerce the primary option + * too. */ + nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_PRIMARY, value); + } + } + + return TRUE; +} + +static const char *_describe_fcn_bond_options(ARGS_DESCRIBE_FCN) +{ + gs_free char *options_str = NULL; + const char ** valid_options; + char * s; + + valid_options = nm_setting_bond_get_valid_options(NULL); + options_str = g_strjoinv(", ", (char **) valid_options); + + s = g_strdup_printf(_("Enter a list of bonding options formatted as:\n" + " option = <value>, option = <value>,... \n" + "Valid options are: %s\n" + "'mode' can be provided as a name or a number:\n" + "balance-rr = 0\n" + "active-backup = 1\n" + "balance-xor = 2\n" + "broadcast = 3\n" + "802.3ad = 4\n" + "balance-tlb = 5\n" + "balance-alb = 6\n\n" + "Example: mode=2,miimon=120\n"), + options_str); + return (*out_to_free = s); +} + +static const char *const *_values_fcn_bond_options(ARGS_VALUES_FCN) +{ + return nm_setting_bond_get_valid_options(NULL); +} + +static gconstpointer _get_fcn_connection_permissions(ARGS_GET_FCN) +{ + NMSettingConnection *s_con = NM_SETTING_CONNECTION(setting); + GString * perm = NULL; + const char * perm_item; + const char * perm_type; + guint i, n; + + RETURN_UNSUPPORTED_GET_TYPE(); + + n = nm_setting_connection_get_num_permissions(s_con); + for (i = 0; i < n; i++) { + if (!nm_setting_connection_get_permission(s_con, i, &perm_type, &perm_item, NULL)) + continue; + if (!nm_streq(perm_type, NM_SETTINGS_CONNECTION_PERMISSION_USER)) + continue; + + if (!perm) + perm = g_string_new(NULL); + else + g_string_append_c(perm, ','); + g_string_append_printf(perm, NM_SETTINGS_CONNECTION_PERMISSION_USER_PREFIX "%s", perm_item); + } + + NM_SET_OUT(out_is_default, !perm); + + if (perm) + RETURN_STR_TO_FREE(g_string_free(perm, FALSE)); + + return NULL; +} + +static gboolean _set_fcn_connection_type(ARGS_SET_FCN) +{ + gs_free char *uuid = NULL; + + if (nm_setting_connection_get_uuid(NM_SETTING_CONNECTION(setting))) { + /* Don't allow setting type unless the connection is brand new. + * Just because it's a bad idea and the user wouldn't probably want that. + * No technical reason, really. + * Also, using uuid to see if the connection is brand new is a bit + * hacky: we can not see if the type is already set, because + * nmc_setting_set_property() is called only after the property + * we're setting (type) has been removed. */ + g_set_error(error, 1, 0, _("Can not change the connection type")); + return FALSE; + } + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) { + g_object_set(G_OBJECT(setting), property_info->property_name, NULL, NULL); + return TRUE; + } - valid_options = nm_setting_bond_get_valid_options (NULL); - options_str = g_strjoinv (", ", (char **) valid_options); + uuid = nm_utils_uuid_generate(); + g_object_set(G_OBJECT(setting), NM_SETTING_CONNECTION_UUID, uuid, NULL); - s = g_strdup_printf (_("Enter a list of bonding options formatted as:\n" - " option = <value>, option = <value>,... \n" - "Valid options are: %s\n" - "'mode' can be provided as a name or a number:\n" - "balance-rr = 0\n" - "active-backup = 1\n" - "balance-xor = 2\n" - "broadcast = 3\n" - "802.3ad = 4\n" - "balance-tlb = 5\n" - "balance-alb = 6\n\n" - "Example: mode=2,miimon=120\n"), options_str); - return (*out_to_free = s); + g_object_set(G_OBJECT(setting), property_info->property_name, value, NULL); + return TRUE; } -static const char *const* -_values_fcn_bond_options (ARGS_VALUES_FCN) +static const char *const *_complete_fcn_connection_type(ARGS_COMPLETE_FCN) { - return nm_setting_bond_get_valid_options (NULL); -} + guint i, j; + char ** result; + gsize text_len; + const char *slave_types[] = {"bond-slave", "bridge-slave", "team-slave"}; -static gconstpointer -_get_fcn_connection_permissions (ARGS_GET_FCN) -{ - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - GString *perm = NULL; - const char *perm_item; - const char *perm_type; - guint i, n; + result = g_new(char *, _NM_META_SETTING_TYPE_NUM * 2 + G_N_ELEMENTS(slave_types) + 1); - RETURN_UNSUPPORTED_GET_TYPE (); + text_len = text ? strlen(text) : 0; - n = nm_setting_connection_get_num_permissions (s_con); - for (i = 0; i < n; i++) { - if (!nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL)) - continue; + for (i = 0, j = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[i]; + const char * v; - if (!perm) - perm = g_string_new (NULL); - else - g_string_append_c (perm, ','); - g_string_append_printf (perm, "%s:%s", perm_type, perm_item); - } + if (!setting_info->valid_parts) + continue; - NM_SET_OUT (out_is_default, !perm); + v = setting_info->alias; + if (v) { + if (!text || strncmp(text, v, text_len) == 0) + result[j++] = g_strdup(v); + } + v = setting_info->general->setting_name; + if (!text || strncmp(text, v, text_len) == 0) + result[j++] = g_strdup(v); + } + for (i = 0; i < G_N_ELEMENTS(slave_types); i++) { + const char *v = slave_types[i]; - if (perm) - RETURN_STR_TO_FREE (g_string_free (perm, FALSE)); + if (!text || strncmp(text, v, text_len) == 0) + result[j++] = g_strdup(v); + } + if (j) + result[j++] = NULL; + else { + g_free(result); + result = NULL; + } - return NULL; + return (const char *const *) (*out_to_free = result); } -static gboolean -_set_fcn_connection_type (ARGS_SET_FCN) -{ - gs_free char *uuid = NULL; - - if (nm_setting_connection_get_uuid (NM_SETTING_CONNECTION (setting))) { - /* Don't allow setting type unless the connection is brand new. - * Just because it's a bad idea and the user wouldn't probably want that. - * No technical reason, really. - * Also, using uuid to see if the connection is brand new is a bit - * hacky: we can not see if the type is already set, because - * nmc_setting_set_property() is called only after the property - * we're setting (type) has been removed. */ - g_set_error (error, 1, 0, _("Can not change the connection type")); - return FALSE; - } - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) { - g_object_set (G_OBJECT (setting), property_info->property_name, NULL, NULL); - return TRUE; - } - - uuid = nm_utils_uuid_generate (); - g_object_set (G_OBJECT (setting), - NM_SETTING_CONNECTION_UUID, uuid, - NULL); - - g_object_set (G_OBJECT (setting), property_info->property_name, value, NULL); - return TRUE; -} - -static const char *const* -_complete_fcn_connection_type (ARGS_COMPLETE_FCN) -{ - guint i, j; - char **result; - gsize text_len; - const char *slave_types[] = {"bond-slave", "bridge-slave", "team-slave"}; - - result = g_new (char *, _NM_META_SETTING_TYPE_NUM * 2 + G_N_ELEMENTS (slave_types) + 1); - - text_len = text ? strlen (text) : 0; - - for (i = 0, j = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[i]; - const char *v; - - if (!setting_info->valid_parts) - continue; - - v = setting_info->alias; - if (v) { - if (!text || strncmp (text, v, text_len) == 0) - result[j++] = g_strdup (v); - } - v = setting_info->general->setting_name; - if (!text || strncmp (text, v, text_len) == 0) - result[j++] = g_strdup (v); - } - for (i = 0; i < G_N_ELEMENTS (slave_types); i++) { - const char *v = slave_types[i]; - - if (!text || strncmp (text, v, text_len) == 0) - result[j++] = g_strdup (v); - } - if (j) - result[j++] = NULL; - else { - g_free (result); - result = NULL; - } - - return (const char *const*) (*out_to_free = result); -} - -#define PERM_USER_PREFIX "user:" - static const char * -_sanitize_connection_permission_user (const char *perm) +_sanitize_connection_permission_user(const char *perm) { - if (NM_STR_HAS_PREFIX (perm, PERM_USER_PREFIX)) - perm += NM_STRLEN (PERM_USER_PREFIX); - - if (perm[0] == '\0') - return NULL; - if (!g_utf8_validate (perm, -1, NULL)) - return NULL; - - return perm; + if (NM_STR_HAS_PREFIX(perm, NM_SETTINGS_CONNECTION_PERMISSION_USER_PREFIX)) + perm += NM_STRLEN(NM_SETTINGS_CONNECTION_PERMISSION_USER_PREFIX); + if (!nm_settings_connection_validate_permission_user(perm, -1)) + return NULL; + return perm; } static const char * -_multilist_validate2_fcn_connection_permissions (NMSetting *setting, - const char *item, - GError **error) +_multilist_validate2_fcn_connection_permissions(NMSetting * setting, + const char *item, + GError ** error) { - if (!_sanitize_connection_permission_user (item)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid permission \"%s\""), - item); - return NULL; - } - return item; + if (!_sanitize_connection_permission_user(item)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid permission \"%s\""), + item); + return NULL; + } + return item; } static gboolean -_multilist_set_fcn_connection_permissions (NMSetting *setting, - const char *item) +_multilist_set_fcn_connection_permissions(NMSetting *setting, const char *item) { - item = _sanitize_connection_permission_user (item); - nm_setting_connection_add_permission (NM_SETTING_CONNECTION (setting), "user", item, NULL); - return TRUE; + item = _sanitize_connection_permission_user(item); + if (!item) + return FALSE; + if (!nm_setting_connection_add_permission(NM_SETTING_CONNECTION(setting), + NM_SETTINGS_CONNECTION_PERMISSION_USER, + item, + NULL)) + nm_assert_not_reached(); + return TRUE; } static gboolean -_multilist_remove_by_value_fcn_connection_permissions (NMSetting *setting, - const char *item) -{ - const char *sanitized; - - sanitized = _sanitize_connection_permission_user (item); - nm_setting_connection_remove_permission_by_value (NM_SETTING_CONNECTION (setting), "user", sanitized ?: item, NULL); - return TRUE; -} - -static const char *const* -_complete_fcn_connection_master (ARGS_COMPLETE_FCN) -{ - NMRemoteConnection *const*connections = NULL; - guint len = 0; - guint i, j; - char **result; - NMSettingConnection *s_con; - const char *expected_type = NULL; - gsize text_len; - - if ( environment - && environment->get_nm_connections) { - connections = environment->get_nm_connections (environment, - environment_user_data, - &len); - } - if (!len) - return NULL; - - if ( (!text || !*text) - && operation_context - && operation_context->connection) { - /* if we have no text yet, initially only complete for matching - * slave-type. */ - s_con = nm_connection_get_setting_connection (operation_context->connection); - if (s_con) - expected_type = nm_setting_connection_get_slave_type (s_con); - } - - text_len = text ? strlen (text) : 0; - - result = g_new (char *, (2 * len) + 1); - for (i = 0, j = 0; i < len; i++) { - const char *v; - - s_con = nm_connection_get_setting_connection (NM_CONNECTION (connections[i])); - if (!s_con) - continue; - - if ( expected_type - && !nm_streq0 (nm_setting_connection_get_connection_type (s_con), - expected_type)) - continue; - - if (text && text[0]) { - /* if we have text, also complete for the UUID. */ - v = nm_setting_connection_get_uuid (s_con); - if (v && (!text || strncmp (text, v, text_len) == 0)) - result[j++] = g_strdup (v); - } - - v = nm_setting_connection_get_interface_name (s_con); - if (v && (!text || strncmp (text, v, text_len) == 0)) - result[j++] = g_strdup (v); - } - if (j) - result[j++] = NULL; - else { - g_free (result); - result = NULL; - } - - return (const char *const*) (*out_to_free = result); +_multilist_remove_by_value_fcn_connection_permissions(NMSetting *setting, const char *item) +{ + item = _sanitize_connection_permission_user(item); + if (!item) + return FALSE; + nm_setting_connection_remove_permission_by_value(NM_SETTING_CONNECTION(setting), + NM_SETTINGS_CONNECTION_PERMISSION_USER, + item, + NULL); + return TRUE; +} + +static const char *const *_complete_fcn_connection_master(ARGS_COMPLETE_FCN) +{ + NMRemoteConnection *const *connections = NULL; + guint len = 0; + guint i, j; + char ** result; + NMSettingConnection * s_con; + const char * expected_type = NULL; + gsize text_len; + + if (environment && environment->get_nm_connections) { + connections = environment->get_nm_connections(environment, environment_user_data, &len); + } + if (!len) + return NULL; + + if ((!text || !*text) && operation_context && operation_context->connection) { + /* if we have no text yet, initially only complete for matching + * slave-type. */ + s_con = nm_connection_get_setting_connection(operation_context->connection); + if (s_con) + expected_type = nm_setting_connection_get_slave_type(s_con); + } + + text_len = text ? strlen(text) : 0; + + result = g_new(char *, (2 * len) + 1); + for (i = 0, j = 0; i < len; i++) { + const char *v; + + s_con = nm_connection_get_setting_connection(NM_CONNECTION(connections[i])); + if (!s_con) + continue; + + if (expected_type + && !nm_streq0(nm_setting_connection_get_connection_type(s_con), expected_type)) + continue; + + if (text && text[0]) { + /* if we have text, also complete for the UUID. */ + v = nm_setting_connection_get_uuid(s_con); + if (v && (!text || strncmp(text, v, text_len) == 0)) + result[j++] = g_strdup(v); + } + + v = nm_setting_connection_get_interface_name(s_con); + if (v && (!text || strncmp(text, v, text_len) == 0)) + result[j++] = g_strdup(v); + } + if (j) + result[j++] = NULL; + else { + g_free(result); + result = NULL; + } + + return (const char *const *) (*out_to_free = result); } static const char * -_multilist_validate2_fcn_uuid (NMSetting *setting, - const char *item, - GError **error) +_multilist_validate2_fcn_uuid(NMSetting *setting, const char *item, GError **error) { - if (!nm_utils_is_uuid (item)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("the value '%s' is not a valid UUID"), - item); - return NULL; - } + if (!nm_utils_is_uuid(item)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("the value '%s' is not a valid UUID"), + item); + return NULL; + } - return item; + return item; } -static gconstpointer -_get_fcn_connection_metered (ARGS_GET_FCN) +static gconstpointer _get_fcn_connection_metered(ARGS_GET_FCN) { - NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); - const char *s; + NMSettingConnection *s_conn = NM_SETTING_CONNECTION(setting); + const char * s; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - switch (nm_setting_connection_get_metered (s_conn)) { - case NM_METERED_YES: - s = N_("yes"); - break; - case NM_METERED_NO: - s = N_("no"); - break; - case NM_METERED_UNKNOWN: - default: - NM_SET_OUT (out_is_default, TRUE); - s = N_("unknown"); - break; - } + switch (nm_setting_connection_get_metered(s_conn)) { + case NM_METERED_YES: + s = N_("yes"); + break; + case NM_METERED_NO: + s = N_("no"); + break; + case NM_METERED_UNKNOWN: + default: + NM_SET_OUT(out_is_default, TRUE); + s = N_("unknown"); + break; + } - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - return _(s); - return s; + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _(s); + return s; } -static gboolean -_set_fcn_connection_metered (ARGS_SET_FCN) +static gboolean _set_fcn_connection_metered(ARGS_SET_FCN) { - NMMetered metered; - NMTernary ts_val; + NMMetered metered; + NMTernary ts_val; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!nmc_string_to_ternary (value, &ts_val, error)) - return FALSE; + if (!nmc_string_to_ternary(value, &ts_val, error)) + return FALSE; - switch (ts_val) { - case NM_TERNARY_TRUE: - metered = NM_METERED_YES; - break; - case NM_TERNARY_FALSE: - metered = NM_METERED_NO; - break; - case NM_TERNARY_DEFAULT: - metered = NM_METERED_UNKNOWN; - break; - default: - g_assert_not_reached(); - } + switch (ts_val) { + case NM_TERNARY_TRUE: + metered = NM_METERED_YES; + break; + case NM_TERNARY_FALSE: + metered = NM_METERED_NO; + break; + case NM_TERNARY_DEFAULT: + metered = NM_METERED_UNKNOWN; + break; + default: + g_assert_not_reached(); + } - g_object_set (setting, property_info->property_name, metered, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, metered, NULL); + return TRUE; } static char * -dcb_flags_to_string (NMSettingDcbFlags flags) +dcb_flags_to_string(NMSettingDcbFlags flags) { - GString *flag_str; + GString *flag_str; - if (flags == 0) - return g_strdup (_("0 (disabled)")); + if (flags == 0) + return g_strdup(_("0 (disabled)")); - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%d (", flags); + flag_str = g_string_new(NULL); + g_string_printf(flag_str, "%d (", flags); - if (flags & NM_SETTING_DCB_FLAG_ENABLE) - g_string_append (flag_str, _("enabled, ")); - if (flags & NM_SETTING_DCB_FLAG_ADVERTISE) - g_string_append (flag_str, _("advertise, ")); - if (flags & NM_SETTING_DCB_FLAG_WILLING) - g_string_append (flag_str, _("willing, ")); + if (flags & NM_SETTING_DCB_FLAG_ENABLE) + g_string_append(flag_str, _("enabled, ")); + if (flags & NM_SETTING_DCB_FLAG_ADVERTISE) + g_string_append(flag_str, _("advertise, ")); + if (flags & NM_SETTING_DCB_FLAG_WILLING) + g_string_append(flag_str, _("willing, ")); - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + if (flag_str->str[flag_str->len - 1] == '(') + g_string_append(flag_str, _("unknown")); + else + g_string_truncate(flag_str, flag_str->len - 2); /* chop off trailing ', ' */ - g_string_append_c (flag_str, ')'); + g_string_append_c(flag_str, ')'); - return g_string_free (flag_str, FALSE); + return g_string_free(flag_str, FALSE); } -static gconstpointer -_get_fcn_dcb (ARGS_GET_FCN) +static gconstpointer _get_fcn_dcb(ARGS_GET_FCN) { - NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); - GString *str; - guint i; + NMSettingDcb *s_dcb = NM_SETTING_DCB(setting); + GString * str; + guint i; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - str = g_string_new (NULL); - for (i = 0; i < 8; i++) { - guint v; + str = g_string_new(NULL); + for (i = 0; i < 8; i++) { + guint v; - v = property_info->property_typ_data->subtype.dcb.get_fcn (s_dcb, i); + v = property_info->property_typ_data->subtype.dcb.get_fcn(s_dcb, i); - if (i > 0) - g_string_append_c (str, ','); - g_string_append_printf (str, "%u", v); - } + if (i > 0) + g_string_append_c(str, ','); + g_string_append_printf(str, "%u", v); + } - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } -#define DCB_ALL_FLAGS (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) +#define DCB_ALL_FLAGS \ + (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) -static gconstpointer -_get_fcn_dcb_flags (ARGS_GET_FCN) +static gconstpointer _get_fcn_dcb_flags(ARGS_GET_FCN) { - nm_auto_unset_gvalue GValue val = G_VALUE_INIT; - guint v; + nm_auto_unset_gvalue GValue val = G_VALUE_INIT; + guint v; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - g_value_init (&val, G_TYPE_UINT); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); - v = g_value_get_uint (&val); + g_value_init(&val, G_TYPE_UINT); + g_object_get_property(G_OBJECT(setting), property_info->property_name, &val); + v = g_value_get_uint(&val); - RETURN_STR_TO_FREE (dcb_flags_to_string (v)); + RETURN_STR_TO_FREE(dcb_flags_to_string(v)); } -static gboolean -_set_fcn_dcb_flags (ARGS_SET_FCN) -{ - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - long int t; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); - - /* Check for overall hex numeric value */ - t = _nm_utils_ascii_str_to_int64 (value, 0, 0, DCB_ALL_FLAGS, -1); - if (t != -1) - flags = (guint) t; - else { - gs_free const char **strv = NULL; - const char *const*iter; - - /* Check for individual flag numbers */ - strv = nm_utils_strsplit_set (value, " \t,"); - for (iter = strv; iter && *iter; iter++) { - t = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, DCB_ALL_FLAGS, -1); - - if ( g_ascii_strcasecmp (*iter, "enable") == 0 - || g_ascii_strcasecmp (*iter, "enabled") == 0 - || t == NM_SETTING_DCB_FLAG_ENABLE) - flags |= NM_SETTING_DCB_FLAG_ENABLE; - else if ( g_ascii_strcasecmp (*iter, "advertise") == 0 - || t == NM_SETTING_DCB_FLAG_ADVERTISE) - flags |= NM_SETTING_DCB_FLAG_ADVERTISE; - else if ( g_ascii_strcasecmp (*iter, "willing") == 0 - || t == NM_SETTING_DCB_FLAG_WILLING) - flags |= NM_SETTING_DCB_FLAG_WILLING; - else if ( g_ascii_strcasecmp (*iter, "disable") == 0 - || g_ascii_strcasecmp (*iter, "disabled") == 0 - || t == 0) { - /* pass */ - } else { - g_set_error (error, 1, 0, _("'%s' is not a valid DCB flag"), *iter); - return FALSE; - } - } - } - - /* Validate the flags according to the property spec */ - if (!validate_flags (setting, property_info->property_name, (guint) flags, error)) - return FALSE; - - g_object_set (setting, property_info->property_name, (guint) flags, NULL); - return TRUE; +static gboolean _set_fcn_dcb_flags(ARGS_SET_FCN) +{ + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + long int t; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + /* Check for overall hex numeric value */ + t = _nm_utils_ascii_str_to_int64(value, 0, 0, DCB_ALL_FLAGS, -1); + if (t != -1) + flags = (guint) t; + else { + gs_free const char **strv = NULL; + const char *const * iter; + + /* Check for individual flag numbers */ + strv = nm_utils_strsplit_set(value, " \t,"); + for (iter = strv; iter && *iter; iter++) { + t = _nm_utils_ascii_str_to_int64(*iter, 0, 0, DCB_ALL_FLAGS, -1); + + if (g_ascii_strcasecmp(*iter, "enable") == 0 + || g_ascii_strcasecmp(*iter, "enabled") == 0 || t == NM_SETTING_DCB_FLAG_ENABLE) + flags |= NM_SETTING_DCB_FLAG_ENABLE; + else if (g_ascii_strcasecmp(*iter, "advertise") == 0 + || t == NM_SETTING_DCB_FLAG_ADVERTISE) + flags |= NM_SETTING_DCB_FLAG_ADVERTISE; + else if (g_ascii_strcasecmp(*iter, "willing") == 0 || t == NM_SETTING_DCB_FLAG_WILLING) + flags |= NM_SETTING_DCB_FLAG_WILLING; + else if (g_ascii_strcasecmp(*iter, "disable") == 0 + || g_ascii_strcasecmp(*iter, "disabled") == 0 || t == 0) { + /* pass */ + } else { + g_set_error(error, 1, 0, _("'%s' is not a valid DCB flag"), *iter); + return FALSE; + } + } + } + + /* Validate the flags according to the property spec */ + if (!validate_flags(setting, property_info->property_name, (guint) flags, error)) + return FALSE; + + g_object_set(setting, property_info->property_name, (guint) flags, NULL); + return TRUE; } static gboolean -dcb_parse_uint_array (const char *val, - guint max, - guint other, - guint out_array[static 8], - GError **error) -{ - gs_free const char **items = NULL; - const char *const*iter; - gsize i; - - items = nm_utils_strsplit_set_with_empty (val, ","); - if (NM_PTRARRAY_LEN (items) != 8) { - g_set_error_literal (error, 1, 0, _("must contain 8 comma-separated numbers")); - return FALSE; - } - - i = 0; - for (iter = items; *iter; iter++) { - gint64 num; - - num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ?: max, -1); - - /* If number is greater than 'max' it must equal 'other' */ - if ( num == -1 - || (other && (num > max) && (num != other))) { - if (other) { - g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive) or %u"), - *iter, max, other); - } else { - g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive)"), - *iter, max); - } - return FALSE; - } - nm_assert (i < 8); - out_array[i++] = (guint) num; - } - - return TRUE; +dcb_parse_uint_array(const char *val, + guint max, + guint other, + guint out_array[static 8], + GError ** error) +{ + gs_free const char **items = NULL; + const char *const * iter; + gsize i; + + items = nm_utils_strsplit_set_with_empty(val, ","); + if (NM_PTRARRAY_LEN(items) != 8) { + g_set_error_literal(error, 1, 0, _("must contain 8 comma-separated numbers")); + return FALSE; + } + + i = 0; + for (iter = items; *iter; iter++) { + gint64 num; + + num = _nm_utils_ascii_str_to_int64(*iter, 10, 0, other ?: max, -1); + + /* If number is greater than 'max' it must equal 'other' */ + if (num == -1 || (other && (num > max) && (num != other))) { + if (other) { + g_set_error(error, + 1, + 0, + _("'%s' not a number between 0 and %u (inclusive) or %u"), + *iter, + max, + other); + } else { + g_set_error(error, + 1, + 0, + _("'%s' not a number between 0 and %u (inclusive)"), + *iter, + max); + } + return FALSE; + } + nm_assert(i < 8); + out_array[i++] = (guint) num; + } + + return TRUE; } static void -dcb_check_feature_enabled (const NMMetaEnvironment *environment, gpointer *environment_user_data, NMSettingDcb *s_dcb, const char *flags_prop) +dcb_check_feature_enabled(const NMMetaEnvironment *environment, + gpointer * environment_user_data, + NMSettingDcb * s_dcb, + const char * flags_prop) { - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - g_object_get (s_dcb, flags_prop, &flags, NULL); - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - _env_warn_fcn (environment, environment_user_data, - NM_META_ENV_WARN_LEVEL_WARN, - N_("changes will have no effect until '%s' includes 1 (enabled)"), - flags_prop); - } + g_object_get(s_dcb, flags_prop, &flags, NULL); + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + _env_warn_fcn(environment, + environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_("changes will have no effect until '%s' includes 1 (enabled)"), + flags_prop); + } } -static gboolean -_set_fcn_dcb (ARGS_SET_FCN) +static gboolean _set_fcn_dcb(ARGS_SET_FCN) { - guint i = 0; - guint nums[8] = { 0, }; + guint i = 0; + guint nums[8] = { + 0, + }; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!dcb_parse_uint_array (value, - property_info->property_typ_data->subtype.dcb.max, - property_info->property_typ_data->subtype.dcb.other, - nums, - error)) - return FALSE; + if (!dcb_parse_uint_array(value, + property_info->property_typ_data->subtype.dcb.max, + property_info->property_typ_data->subtype.dcb.other, + nums, + error)) + return FALSE; - if (property_info->property_typ_data->subtype.dcb.is_percent) { - guint sum = 0; + if (property_info->property_typ_data->subtype.dcb.is_percent) { + guint sum = 0; - for (i = 0; i < 8; i++) { - sum += nums[i]; - if (nums[i] > 100 || sum > 100) - break; - } - if (sum != 100) { - g_set_error_literal (error, 1, 0, _("bandwidth percentages must total 100%%")); - return FALSE; - } - } + for (i = 0; i < 8; i++) { + sum += nums[i]; + if (nums[i] > 100 || sum > 100) + break; + } + if (sum != 100) { + g_set_error_literal(error, 1, 0, _("bandwidth percentages must total 100%%")); + return FALSE; + } + } - for (i = 0; i < 8; i++) - property_info->property_typ_data->subtype.dcb.set_fcn (NM_SETTING_DCB (setting), i, nums[i]); + for (i = 0; i < 8; i++) + property_info->property_typ_data->subtype.dcb.set_fcn(NM_SETTING_DCB(setting), i, nums[i]); - dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; + dcb_check_feature_enabled(environment, + environment_user_data, + NM_SETTING_DCB(setting), + NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; } -static gconstpointer -_get_fcn_dcb_bool (ARGS_GET_FCN) +static gconstpointer _get_fcn_dcb_bool(ARGS_GET_FCN) { - NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); - GString *str; - guint i; + NMSettingDcb *s_dcb = NM_SETTING_DCB(setting); + GString * str; + guint i; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - str = g_string_new (NULL); - for (i = 0; i < 8; i++) { - gboolean v; + str = g_string_new(NULL); + for (i = 0; i < 8; i++) { + gboolean v; - v = property_info->property_typ_data->subtype.dcb_bool.get_fcn (s_dcb, i); + v = property_info->property_typ_data->subtype.dcb_bool.get_fcn(s_dcb, i); - if (i > 0) - g_string_append_c (str, ','); - g_string_append_c (str, v ? '1': '0'); - } + if (i > 0) + g_string_append_c(str, ','); + g_string_append_c(str, v ? '1' : '0'); + } - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } -static gboolean -_set_fcn_dcb_bool (ARGS_SET_FCN) +static gboolean _set_fcn_dcb_bool(ARGS_SET_FCN) { - guint i = 0; - guint nums[8] = { 0, }; + guint i = 0; + guint nums[8] = { + 0, + }; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!dcb_parse_uint_array (value, 1, 0, nums, error)) - return FALSE; + if (!dcb_parse_uint_array(value, 1, 0, nums, error)) + return FALSE; - for (i = 0; i < 8; i++) { - property_info->property_typ_data->subtype.dcb_bool.set_fcn (NM_SETTING_DCB (setting), - i, - !!nums[i]); - } + for (i = 0; i < 8; i++) { + property_info->property_typ_data->subtype.dcb_bool.set_fcn(NM_SETTING_DCB(setting), + i, + !!nums[i]); + } - dcb_check_feature_enabled (environment, - environment_user_data, - NM_SETTING_DCB (setting), - ( property_info->property_typ_data->subtype.dcb_bool.with_flow_control_flags - ? NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS - : NM_SETTING_DCB_PRIORITY_GROUP_FLAGS)); - return TRUE; + dcb_check_feature_enabled( + environment, + environment_user_data, + NM_SETTING_DCB(setting), + (property_info->property_typ_data->subtype.dcb_bool.with_flow_control_flags + ? NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS + : NM_SETTING_DCB_PRIORITY_GROUP_FLAGS)); + return TRUE; } -static gboolean -_set_fcn_gsm_sim_operator_id (ARGS_SET_FCN) +static gboolean _set_fcn_gsm_sim_operator_id(ARGS_SET_FCN) { - const char *p = value; + const char *p = value; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!NM_IN_SET (strlen (value), 5, 6)) { - g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); - return FALSE; - } + if (!NM_IN_SET(strlen(value), 5, 6)) { + g_set_error_literal(error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); + return FALSE; + } - while (p && *p) { - if (!g_ascii_isdigit (*p++)) { - g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); - return FALSE; - } - } - g_object_set (G_OBJECT (setting), - NM_SETTING_GSM_SIM_OPERATOR_ID, - value, - NULL); - return TRUE; + while (p && *p) { + if (!g_ascii_isdigit(*p++)) { + g_set_error_literal(error, + 1, + 0, + _("SIM operator ID must be a 5 or 6 number MCCMNC code")); + return FALSE; + } + } + g_object_set(G_OBJECT(setting), NM_SETTING_GSM_SIM_OPERATOR_ID, value, NULL); + return TRUE; } -static gboolean -_set_fcn_infiniband_p_key (ARGS_SET_FCN) +static gboolean _set_fcn_infiniband_p_key(ARGS_SET_FCN) { - gint64 p_key; + gint64 p_key; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (nm_streq (value, "default")) - p_key = -1; - else { - p_key = _nm_utils_ascii_str_to_int64 (value, 0, -1, G_MAXUINT16, -2); - if (p_key == -2) { - g_set_error (error, 1, 0, _("'%s' is not a valid IBoIP P_Key"), value); - return FALSE; - } - } + if (nm_streq(value, "default")) + p_key = -1; + else { + p_key = _nm_utils_ascii_str_to_int64(value, 0, -1, G_MAXUINT16, -2); + if (p_key == -2) { + g_set_error(error, 1, 0, _("'%s' is not a valid IBoIP P_Key"), value); + return FALSE; + } + } - g_object_set (setting, property_info->property_name, (int) p_key, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, (int) p_key, NULL); + return TRUE; } -static gconstpointer -_get_fcn_infiniband_p_key (ARGS_GET_FCN) +static gconstpointer _get_fcn_infiniband_p_key(ARGS_GET_FCN) { - NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); - int p_key; + NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND(setting); + int p_key; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - p_key = nm_setting_infiniband_get_p_key (s_infiniband); - if (p_key == -1) { - NM_SET_OUT (out_is_default, TRUE); - if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) - return "default"; - else - return _("default"); - } + p_key = nm_setting_infiniband_get_p_key(s_infiniband); + if (p_key == -1) { + NM_SET_OUT(out_is_default, TRUE); + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return "default"; + else + return _("default"); + } - RETURN_STR_TO_FREE (g_strdup_printf ("0x%04x", p_key)); + RETURN_STR_TO_FREE(g_strdup_printf("0x%04x", p_key)); } -static gconstpointer -_get_fcn_objlist (ARGS_GET_FCN) -{ - GString *str = NULL; - guint num; - guint idx; - - RETURN_UNSUPPORTED_GET_TYPE (); - - num = property_info->property_typ_data->subtype.objlist.get_num_fcn (setting); - - for (idx = 0; idx < num; idx++) { - gsize start_offset; - - if (!str) - str = g_string_new (NULL); - else if (str->len > 0) { - if ( get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY - && property_info->property_typ_data->subtype.objlist.delimit_pretty_with_semicolon) - g_string_append (str, "; "); - else { - G_STATIC_ASSERT_EXPR (ESCAPED_TOKENS_DELIMITER == ','); - g_string_append (str, ", "); - } - } - - start_offset = str->len; - - property_info->property_typ_data->subtype.objlist.obj_to_str_fcn (get_type, - setting, - idx, - str); - - if (start_offset == str->len) { - /* nothing was appended. Remove the delimiter again. */ - nm_assert_not_reached (); - if (str->len > 0) - g_string_truncate (str, str->len - 2); - continue; - } - - nm_assert (start_offset < str->len); - nm_assert (strlen (str->str) == str->len); - nm_assert ( property_info->property_typ_data->subtype.objlist.strsplit_plain - || get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY - || _value_strsplit_assert_unsplitable (&str->str[start_offset])); - } - - NM_SET_OUT (out_is_default, num == 0); - if (str) - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); - return NULL; -} - -static void -_objlist_obj_to_str_fcn_ip_config_addresses (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +static gconstpointer _get_fcn_objlist(ARGS_GET_FCN) { - NMIPAddress *obj; + GString *str = NULL; + guint num; + guint idx; - obj = nm_setting_ip_config_get_address (NM_SETTING_IP_CONFIG (setting), - idx); - g_string_append_printf (str, - "%s/%u", - nm_ip_address_get_address (obj), - nm_ip_address_get_prefix (obj)); -} + RETURN_UNSUPPORTED_GET_TYPE(); -static void -_objlist_obj_to_str_fcn_ip_config_routes (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) -{ - NMIPRoute *route; - gs_free char *attr_str = NULL; - gs_strfreev char **attr_names = NULL; - gs_unref_hashtable GHashTable *hash = g_hash_table_new (nm_str_hash, g_str_equal); - int j; - - route = nm_setting_ip_config_get_route (NM_SETTING_IP_CONFIG (setting), idx); - - attr_names = nm_ip_route_get_attribute_names (route); - for (j = 0; attr_names && attr_names[j]; j++) { - g_hash_table_insert (hash, attr_names[j], - nm_ip_route_get_attribute (route, attr_names[j])); - } - - attr_str = nm_utils_format_variant_attributes (hash, ' ', '='); - - if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) { - g_string_append_printf (str, "%s/%u", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route)); - - if (nm_ip_route_get_next_hop (route)) - g_string_append_printf (str, " %s", nm_ip_route_get_next_hop (route)); - if (nm_ip_route_get_metric (route) != -1) - g_string_append_printf (str, " %u", (guint32) nm_ip_route_get_metric (route)); - if (attr_str) - g_string_append_printf (str, " %s", attr_str); - } else { - g_string_append (str, "{ "); - - g_string_append_printf (str, "ip = %s/%u", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route)); - - if (nm_ip_route_get_next_hop (route)) { - g_string_append_printf (str, ", nh = %s", - nm_ip_route_get_next_hop (route)); - } - - if (nm_ip_route_get_metric (route) != -1) - g_string_append_printf (str, ", mt = %u", (guint32) nm_ip_route_get_metric (route)); - if (attr_str) - g_string_append_printf (str, " %s", attr_str); - - g_string_append (str, " }"); - } -} + num = property_info->property_typ_data->subtype.objlist.get_num_fcn(setting); -static gboolean -_set_fcn_ip_config_method (ARGS_SET_FCN) -{ - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + for (idx = 0; idx < num; idx++) { + gsize start_offset; + + if (!str) + str = g_string_new(NULL); + else if (str->len > 0) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY + && property_info->property_typ_data->subtype.objlist.delimit_pretty_with_semicolon) + g_string_append(str, "; "); + else { + G_STATIC_ASSERT_EXPR(ESCAPED_TOKENS_DELIMITER == ','); + g_string_append(str, ", "); + } + } - /* Silently accept "static" and convert to "manual" */ - if ( strlen (value) > 1 - && matches (value, "static")) { - if (nm_setting_ip_config_get_addr_family (NM_SETTING_IP_CONFIG (setting)) == AF_INET) - value = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - else - value = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - } + start_offset = str->len; - value = nmc_string_is_valid (value, - (const char **) property_info->property_typ_data->values_static, - error); - if (!value) - return FALSE; + property_info->property_typ_data->subtype.objlist.obj_to_str_fcn(get_type, + setting, + idx, + str); - g_object_set (setting, property_info->property_name, value, NULL); - return TRUE; + if (start_offset == str->len) { + /* nothing was appended. Remove the delimiter again. */ + nm_assert_not_reached(); + if (str->len > 0) + g_string_truncate(str, str->len - 2); + continue; + } + + nm_assert(start_offset < str->len); + nm_assert(strlen(str->str) == str->len); + nm_assert(property_info->property_typ_data->subtype.objlist.strsplit_plain + || get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY + || _value_strsplit_assert_unsplitable(&str->str[start_offset])); + } + + NM_SET_OUT(out_is_default, num == 0); + if (str) + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); + return NULL; } -static const char * -_multilist_validate2_fcn_ip_config_dns (NMSetting *setting, - const char *value, - GError **error) +static void +_objlist_obj_to_str_fcn_ip_config_addresses(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - int addr_family = nm_setting_ip_config_get_addr_family (NM_SETTING_IP_CONFIG (setting)); + NMIPAddress *obj; - if (!nm_utils_parse_inaddr (addr_family, value, NULL)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid IPv%c address '%s'"), - nm_utils_addr_family_to_char (addr_family), - value); - return NULL; - } + obj = nm_setting_ip_config_get_address(NM_SETTING_IP_CONFIG(setting), idx); + g_string_append_printf(str, + "%s/%u", + nm_ip_address_get_address(obj), + nm_ip_address_get_prefix(obj)); +} - return value; +static void +_objlist_obj_to_str_fcn_ip_config_routes(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) +{ + NMIPRoute * route; + gs_free char * attr_str = NULL; + gs_strfreev char **attr_names = NULL; + gs_unref_hashtable GHashTable *hash = g_hash_table_new(nm_str_hash, g_str_equal); + int j; + + route = nm_setting_ip_config_get_route(NM_SETTING_IP_CONFIG(setting), idx); + + attr_names = nm_ip_route_get_attribute_names(route); + for (j = 0; attr_names && attr_names[j]; j++) { + g_hash_table_insert(hash, attr_names[j], nm_ip_route_get_attribute(route, attr_names[j])); + } + + attr_str = nm_utils_format_variant_attributes(hash, ' ', '='); + + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) { + g_string_append_printf(str, + "%s/%u", + nm_ip_route_get_dest(route), + nm_ip_route_get_prefix(route)); + + if (nm_ip_route_get_next_hop(route)) + g_string_append_printf(str, " %s", nm_ip_route_get_next_hop(route)); + if (nm_ip_route_get_metric(route) != -1) + g_string_append_printf(str, " %u", (guint32) nm_ip_route_get_metric(route)); + if (attr_str) + g_string_append_printf(str, " %s", attr_str); + } else { + g_string_append(str, "{ "); + + g_string_append_printf(str, + "ip = %s/%u", + nm_ip_route_get_dest(route), + nm_ip_route_get_prefix(route)); + + if (nm_ip_route_get_next_hop(route)) { + g_string_append_printf(str, ", nh = %s", nm_ip_route_get_next_hop(route)); + } + + if (nm_ip_route_get_metric(route) != -1) + g_string_append_printf(str, ", mt = %u", (guint32) nm_ip_route_get_metric(route)); + if (attr_str) + g_string_append_printf(str, " %s", attr_str); + + g_string_append(str, " }"); + } +} + +static gboolean _set_fcn_ip_config_method(ARGS_SET_FCN) +{ + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); + + /* Silently accept "static" and convert to "manual" */ + if (strlen(value) > 1 && matches(value, "static")) { + if (nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)) == AF_INET) + value = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; + else + value = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + } + + value = nmc_string_is_valid(value, + (const char **) property_info->property_typ_data->values_static, + error); + if (!value) + return FALSE; + + g_object_set(setting, property_info->property_name, value, NULL); + return TRUE; } -static gboolean -_multilist_add_fcn_ip_config_dns_options (NMSetting *setting, - const char *item) +static const char * +_multilist_validate2_fcn_ip_config_dns(NMSetting *setting, const char *value, GError **error) { - NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); + int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); + + if (!nm_utils_parse_inaddr(addr_family, value, NULL)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid IPv%c address '%s'"), + nm_utils_addr_family_to_char(addr_family), + value); + return NULL; + } - if (!nm_setting_ip_config_add_dns_option (s_ip, item)) { - /* maybe it failed, because the element already existed. *sigh*. */ - nm_setting_ip_config_remove_dns_option_by_value (s_ip, item); - return nm_setting_ip_config_add_dns_option (s_ip, item); - } - return TRUE; + return value; } static gboolean -_set_fcn_objlist (ARGS_SET_FCN) -{ - gs_free const char **strv = NULL; - gsize i, nstrv; - - if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (property_info, modifier, value)) { - if (property_info->property_typ_data->subtype.objlist.clear_all_fcn) { - property_info->property_typ_data->subtype.objlist.clear_all_fcn (setting); - return TRUE; - } - return _gobject_property_reset_default (setting, property_info->property_name); - } - - if ( _SET_FCN_DO_REMOVE (modifier, value) - && ( property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u - || property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_s)) { - gs_free gint64 *indexes = NULL; - - indexes = _value_str_as_index_list (value, &nstrv); - if (indexes) { - gint64 num; - - num = property_info->property_typ_data->subtype.objlist.get_num_fcn (setting); - for (i = 0; i < nstrv; i++) { - gint64 idx = indexes[i]; - - if (idx >= num) - continue; - if (property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u) - property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u (setting, idx); - else - property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_s (setting, idx); - } - return TRUE; - } - } - - strv = _value_strsplit (value, - property_info->property_typ_data->subtype.objlist.strsplit_plain - ? VALUE_STRSPLIT_MODE_OBJLIST - : VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, - &nstrv); - - if (_SET_FCN_DO_SET_ALL (modifier, value)) { - if (property_info->property_typ_data->subtype.objlist.clear_all_fcn) - property_info->property_typ_data->subtype.objlist.clear_all_fcn (setting); - else - _gobject_property_reset (setting, property_info->property_name, FALSE); - } - - for (i = 0; i < nstrv; i++) { - /* FIXME: there is the problem here that set_fcn() might succed on the first item - * (modifying it), and fail to parse the second one. - * - * Optimally, we would first parse all input strings before starting the - * modify the setting. The setting should only be modified if (and only if) - * the entire operation succeeds to set all items. - * - * Currently, in interactive mode this leads to odd behavior. - * - * This does not only affect objlist.set_fcn() or _pt_objlist properties. - * E.g. we also call _gobject_property_reset() before validating the input. */ - if (!property_info->property_typ_data->subtype.objlist.set_fcn (setting, - !_SET_FCN_DO_REMOVE (modifier, value), - strv[i], - error)) - return FALSE; - } - return TRUE; +_multilist_add_fcn_ip_config_dns_options(NMSetting *setting, const char *item) +{ + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); + + if (!nm_setting_ip_config_add_dns_option(s_ip, item)) { + /* maybe it failed, because the element already existed. *sigh*. */ + nm_setting_ip_config_remove_dns_option_by_value(s_ip, item); + return nm_setting_ip_config_add_dns_option(s_ip, item); + } + return TRUE; +} + +static gboolean _set_fcn_objlist(ARGS_SET_FCN) +{ + gs_free const char **strv = NULL; + gsize i, nstrv; + + if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(property_info, modifier, value)) { + if (property_info->property_typ_data->subtype.objlist.clear_all_fcn) { + property_info->property_typ_data->subtype.objlist.clear_all_fcn(setting); + return TRUE; + } + return _gobject_property_reset_default(setting, property_info->property_name); + } + + if (_SET_FCN_DO_REMOVE(modifier, value) + && (property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u + || property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_s)) { + gs_free gint64 *indexes = NULL; + + indexes = _value_str_as_index_list(value, &nstrv); + if (indexes) { + gint64 num; + + num = property_info->property_typ_data->subtype.objlist.get_num_fcn(setting); + for (i = 0; i < nstrv; i++) { + gint64 idx = indexes[i]; + + if (idx >= num) + continue; + if (property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u) + property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_u(setting, + idx); + else + property_info->property_typ_data->subtype.objlist.remove_by_idx_fcn_s(setting, + idx); + } + return TRUE; + } + } + + strv = _value_strsplit(value, + property_info->property_typ_data->subtype.objlist.strsplit_plain + ? VALUE_STRSPLIT_MODE_OBJLIST + : VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, + &nstrv); + + if (_SET_FCN_DO_SET_ALL(modifier, value)) { + if (property_info->property_typ_data->subtype.objlist.clear_all_fcn) + property_info->property_typ_data->subtype.objlist.clear_all_fcn(setting); + else + _gobject_property_reset(setting, property_info->property_name, FALSE); + } + + for (i = 0; i < nstrv; i++) { + /* FIXME: there is the problem here that set_fcn() might succeed on the first item + * (modifying it), and fail to parse the second one. + * + * Optimally, we would first parse all input strings before starting the + * modify the setting. The setting should only be modified if (and only if) + * the entire operation succeeds to set all items. + * + * Currently, in interactive mode this leads to odd behavior. + * + * This does not only affect objlist.set_fcn() or _pt_objlist properties. + * E.g. we also call _gobject_property_reset() before validating the input. */ + if (!property_info->property_typ_data->subtype.objlist + .set_fcn(setting, !_SET_FCN_DO_REMOVE(modifier, value), strv[i], error)) + return FALSE; + } + return TRUE; } static gboolean -_objlist_set_fcn_ip_config_addresses (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) +_objlist_set_fcn_ip_config_addresses(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) { - int addr_family = nm_setting_ip_config_get_addr_family (NM_SETTING_IP_CONFIG (setting)); - nm_auto_unref_ip_address NMIPAddress *addr = NULL; + int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); + nm_auto_unref_ip_address NMIPAddress *addr = NULL; - addr = _parse_ip_address (addr_family, value, error); - if (!addr) - return FALSE; - if (do_add) - nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), addr); - else - nm_setting_ip_config_remove_address_by_value (NM_SETTING_IP_CONFIG (setting), addr); - return TRUE; + addr = _parse_ip_address(addr_family, value, error); + if (!addr) + return FALSE; + if (do_add) + nm_setting_ip_config_add_address(NM_SETTING_IP_CONFIG(setting), addr); + else + nm_setting_ip_config_remove_address_by_value(NM_SETTING_IP_CONFIG(setting), addr); + return TRUE; } -static gboolean -_set_fcn_ip_config_gateway (ARGS_SET_FCN) +static gboolean _set_fcn_ip_config_gateway(ARGS_SET_FCN) { - gs_free char *value_to_free = NULL; - int addr_family = nm_setting_ip_config_get_addr_family (NM_SETTING_IP_CONFIG (setting)); + gs_free char *value_to_free = NULL; + int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - value = nm_strstrip_avoid_copy_a (300, value, &value_to_free); + value = nm_strstrip_avoid_copy_a(300, value, &value_to_free); - if (!nm_utils_ipaddr_is_valid (addr_family, value)) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid gateway address '%s'"), - value); - return FALSE; - } + if (!nm_utils_ipaddr_is_valid(addr_family, value)) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid gateway address '%s'"), + value); + return FALSE; + } - /* Since commit c1907a218a6b6bfe8175eb6ed87a523aaabc69ae, having a gateway and never-default=yes - * will be normalized away. That means, when we set a gateway, we also want to unset never-default, - * otherwise the operation gets silently reverted. */ - g_object_set (setting, - property_info->property_name, value, - NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, - NULL); - return TRUE; + /* Since commit c1907a218a6b6bfe8175eb6ed87a523aaabc69ae, having a gateway and never-default=yes + * will be normalized away. That means, when we set a gateway, we also want to unset never-default, + * otherwise the operation gets silently reverted. */ + g_object_set(setting, + property_info->property_name, + value, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, + FALSE, + NULL); + return TRUE; } static gboolean -_objlist_set_fcn_ip_config_routes (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) +_objlist_set_fcn_ip_config_routes(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) { - int addr_family = nm_setting_ip_config_get_addr_family (NM_SETTING_IP_CONFIG (setting)); - nm_auto_unref_ip_route NMIPRoute *route = NULL; + int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); + nm_auto_unref_ip_route NMIPRoute *route = NULL; - route = _parse_ip_route (addr_family, value, error); - if (!route) - return FALSE; - if (do_add) - nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), route); - else - nm_setting_ip_config_remove_route_by_value (NM_SETTING_IP_CONFIG (setting), route); - return TRUE; + route = _parse_ip_route(addr_family, value, error); + if (!route) + return FALSE; + if (do_add) + nm_setting_ip_config_add_route(NM_SETTING_IP_CONFIG(setting), route); + else + nm_setting_ip_config_remove_route_by_value(NM_SETTING_IP_CONFIG(setting), route); + return TRUE; } static gboolean -_is_default_func_ip_config_dns_options (NMSetting *setting) +_is_default_func_ip_config_dns_options(NMSetting *setting) { - return !nm_setting_ip_config_has_dns_options (NM_SETTING_IP_CONFIG (setting)); + return !nm_setting_ip_config_has_dns_options(NM_SETTING_IP_CONFIG(setting)); } static void -_objlist_obj_to_str_fcn_ip_config_routing_rules (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_ip_config_routing_rules(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - NMIPRoutingRule *rule; - gs_free char *s = NULL; + NMIPRoutingRule *rule; + gs_free char * s = NULL; - rule = nm_setting_ip_config_get_routing_rule (NM_SETTING_IP_CONFIG (setting), idx); - s = nm_ip_routing_rule_to_string (rule, - NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE, - NULL, - NULL); - if (s) - nm_utils_escaped_tokens_escape_gstr (s, ESCAPED_TOKENS_DELIMITERS, str); + rule = nm_setting_ip_config_get_routing_rule(NM_SETTING_IP_CONFIG(setting), idx); + s = nm_ip_routing_rule_to_string(rule, NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE, NULL, NULL); + if (s) + nm_utils_escaped_tokens_escape_gstr(s, ESCAPED_TOKENS_DELIMITERS, str); } static gboolean -_objlist_set_fcn_ip_config_routing_rules (NMSetting *setting, - gboolean do_add, - const char *str, - GError **error) -{ - NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); - nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; - guint i, n; - - rule = nm_ip_routing_rule_from_string (str, - ( NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE - | ( NM_IS_SETTING_IP4_CONFIG (setting) - ? NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET - : NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6)), - NULL, - error); - if (!rule) - return FALSE; - - /* also for @do_add, we first always search whether such a rule already exist - * and remove the first occurrence. - * - * The effect is, that we don't add multiple times the same rule, - * and that if the rule already exists, it gets moved to the end (append). - */ - n = nm_setting_ip_config_get_num_routing_rules (s_ip); - for (i = 0; i < n; i++) { - NMIPRoutingRule *rr; - - rr = nm_setting_ip_config_get_routing_rule (s_ip, i); - if (nm_ip_routing_rule_cmp (rule, rr) == 0) { - nm_setting_ip_config_remove_routing_rule (s_ip, i); - break; - } - } - if (do_add) - nm_setting_ip_config_add_routing_rule (s_ip, rule); - return TRUE; +_objlist_set_fcn_ip_config_routing_rules(NMSetting * setting, + gboolean do_add, + const char *str, + GError ** error) +{ + NMSettingIPConfig * s_ip = NM_SETTING_IP_CONFIG(setting); + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + guint i, n; + + rule = nm_ip_routing_rule_from_string( + str, + (NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE + | (NM_IS_SETTING_IP4_CONFIG(setting) ? NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET + : NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6)), + NULL, + error); + if (!rule) + return FALSE; + + /* also for @do_add, we first always search whether such a rule already exist + * and remove the first occurrence. + * + * The effect is, that we don't add multiple times the same rule, + * and that if the rule already exists, it gets moved to the end (append). + */ + n = nm_setting_ip_config_get_num_routing_rules(s_ip); + for (i = 0; i < n; i++) { + NMIPRoutingRule *rr; + + rr = nm_setting_ip_config_get_routing_rule(s_ip, i); + if (nm_ip_routing_rule_cmp(rule, rr) == 0) { + nm_setting_ip_config_remove_routing_rule(s_ip, i); + break; + } + } + if (do_add) + nm_setting_ip_config_add_routing_rule(s_ip, rule); + return TRUE; +} + +static guint +_multilist_get_num_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig *setting) +{ + guint num; + + nm_setting_ip_config_get_dhcp_reject_servers(setting, &num); + + return num; } -static gconstpointer -_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN) +static gboolean +_multilist_remove_by_value_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig *setting, + const char * item) +{ + const char *const *strv; + guint num; + gssize idx; + + strv = nm_setting_ip_config_get_dhcp_reject_servers(setting, &num); + idx = nm_utils_strv_find_first((char **) strv, num, item); + if (idx >= 0) + nm_setting_ip_config_remove_dhcp_reject_server(setting, idx); + return TRUE; +} + +static gconstpointer _get_fcn_olpc_mesh_ssid(ARGS_GET_FCN) { - NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting); - GBytes *ssid; - char *ssid_str = NULL; + NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH(setting); + GBytes * ssid; + char * ssid_str = NULL; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - ssid = nm_setting_olpc_mesh_get_ssid (s_olpc_mesh); - if (ssid) { - ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - } + ssid = nm_setting_olpc_mesh_get_ssid(s_olpc_mesh); + if (ssid) { + ssid_str = nm_utils_ssid_to_utf8(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid)); + } - NM_SET_OUT (out_is_default, !ssid_str); - RETURN_STR_TO_FREE (ssid_str); + NM_SET_OUT(out_is_default, !ssid_str); + RETURN_STR_TO_FREE(ssid_str); } -static gboolean -_set_fcn_olpc_mesh_channel (ARGS_SET_FCN) +static gboolean _set_fcn_olpc_mesh_channel(ARGS_SET_FCN) { - unsigned long chan_int; + unsigned long chan_int; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!nmc_string_to_uint (value, TRUE, 1, 13, &chan_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid channel; use <1-13>"), value); - return FALSE; - } - g_object_set (setting, property_info->property_name, chan_int, NULL); - return TRUE; + if (!nmc_string_to_uint(value, TRUE, 1, 13, &chan_int)) { + g_set_error(error, 1, 0, _("'%s' is not a valid channel; use <1-13>"), value); + return FALSE; + } + g_object_set(setting, property_info->property_name, chan_int, NULL); + return TRUE; } static const char * -_validate_fcn_proxy_pac_script (const char *value, char **out_to_free, GError **error) +_validate_fcn_proxy_pac_script(const char *value, char **out_to_free, GError **error) { - char *script = NULL; + char *script = NULL; - if (!nmc_proxy_check_script (value, &script, error)) - return NULL; - RETURN_STR_TO_FREE (script); + if (!nmc_proxy_check_script(value, &script, error)) + return NULL; + RETURN_STR_TO_FREE(script); } static void -_objlist_obj_to_str_fcn_sriov_vfs (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_sriov_vfs(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - gs_free char *s = NULL; - NMSriovVF *vf; + gs_free char *s = NULL; + NMSriovVF * vf; - vf = nm_setting_sriov_get_vf (NM_SETTING_SRIOV (setting), idx); - s = nm_utils_sriov_vf_to_str (vf, FALSE, NULL); - if (s) - g_string_append (str, s); + vf = nm_setting_sriov_get_vf(NM_SETTING_SRIOV(setting), idx); + s = nm_utils_sriov_vf_to_str(vf, FALSE, NULL); + if (s) + g_string_append(str, s); } static void -_objlist_obj_to_str_fcn_tc_config_qdiscs (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_tc_config_qdiscs(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - gs_free char *s = NULL; - NMTCQdisc *qdisc; + gs_free char *s = NULL; + NMTCQdisc * qdisc; - qdisc = nm_setting_tc_config_get_qdisc (NM_SETTING_TC_CONFIG (setting), idx); - s = nm_utils_tc_qdisc_to_str (qdisc, NULL); - if (s) - g_string_append (str, s); + qdisc = nm_setting_tc_config_get_qdisc(NM_SETTING_TC_CONFIG(setting), idx); + s = nm_utils_tc_qdisc_to_str(qdisc, NULL); + if (s) + g_string_append(str, s); } static void -_objlist_obj_to_str_fcn_bridge_vlans (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_bridge_vlans(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - gs_free char *s = NULL; - NMBridgeVlan *vlan; + gs_free char *s = NULL; + NMBridgeVlan *vlan; - if (NM_IS_SETTING_BRIDGE (setting)) - vlan = nm_setting_bridge_get_vlan (NM_SETTING_BRIDGE (setting), idx); - else - vlan = nm_setting_bridge_port_get_vlan (NM_SETTING_BRIDGE_PORT (setting), idx); + if (NM_IS_SETTING_BRIDGE(setting)) + vlan = nm_setting_bridge_get_vlan(NM_SETTING_BRIDGE(setting), idx); + else + vlan = nm_setting_bridge_port_get_vlan(NM_SETTING_BRIDGE_PORT(setting), idx); - s = nm_bridge_vlan_to_str (vlan, NULL); - if (s) - nm_utils_escaped_tokens_escape_gstr_assert (s, ESCAPED_TOKENS_DELIMITERS, str); + s = nm_bridge_vlan_to_str(vlan, NULL); + if (s) + nm_utils_escaped_tokens_escape_gstr_assert(s, ESCAPED_TOKENS_DELIMITERS, str); } static gboolean -_objlist_set_fcn_sriov_vfs (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) -{ - nm_auto_unref_sriov_vf NMSriovVF *vf = NULL; - gs_free_error GError *local = NULL; - - vf = nm_utils_sriov_vf_from_str (value, &local); - if (!vf) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - "%s. %s", - local->message, - _("The valid syntax is: vf [attribute=value]... [,vf [attribute=value]...]")); - return FALSE; - } - if (do_add) - nm_setting_sriov_add_vf (NM_SETTING_SRIOV (setting), vf); - else - nm_setting_sriov_remove_vf_by_index (NM_SETTING_SRIOV (setting), nm_sriov_vf_get_index (vf)); - return TRUE; +_objlist_set_fcn_sriov_vfs(NMSetting *setting, gboolean do_add, const char *value, GError **error) +{ + nm_auto_unref_sriov_vf NMSriovVF *vf = NULL; + gs_free_error GError *local = NULL; + + vf = nm_utils_sriov_vf_from_str(value, &local); + if (!vf) { + nm_utils_error_set( + error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "%s. %s", + local->message, + _("The valid syntax is: vf [attribute=value]... [,vf [attribute=value]...]")); + return FALSE; + } + if (do_add) + nm_setting_sriov_add_vf(NM_SETTING_SRIOV(setting), vf); + else + nm_setting_sriov_remove_vf_by_index(NM_SETTING_SRIOV(setting), nm_sriov_vf_get_index(vf)); + return TRUE; } static gboolean -_objlist_set_fcn_tc_config_qdiscs (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) -{ - nm_auto_unref_tc_qdisc NMTCQdisc *tc_qdisc = NULL; - gs_free_error GError *local = NULL; - - tc_qdisc = nm_utils_tc_qdisc_from_str (value, &local); - if (!tc_qdisc) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - "%s. %s", - local->message, - _("The valid syntax is: '[root | parent <handle>] [handle <handle>] <kind>'")); - return FALSE; - } - if (do_add) - nm_setting_tc_config_add_qdisc (NM_SETTING_TC_CONFIG (setting), tc_qdisc); - else - nm_setting_tc_config_remove_qdisc_by_value (NM_SETTING_TC_CONFIG (setting), tc_qdisc); - return TRUE; +_objlist_set_fcn_tc_config_qdiscs(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) +{ + nm_auto_unref_tc_qdisc NMTCQdisc *tc_qdisc = NULL; + gs_free_error GError *local = NULL; + + tc_qdisc = nm_utils_tc_qdisc_from_str(value, &local); + if (!tc_qdisc) { + nm_utils_error_set( + error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "%s. %s", + local->message, + _("The valid syntax is: '[root | parent <handle>] [handle <handle>] <kind>'")); + return FALSE; + } + if (do_add) + nm_setting_tc_config_add_qdisc(NM_SETTING_TC_CONFIG(setting), tc_qdisc); + else + nm_setting_tc_config_remove_qdisc_by_value(NM_SETTING_TC_CONFIG(setting), tc_qdisc); + return TRUE; } static gboolean -_objlist_set_fcn_bridge_vlans (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) -{ - nm_auto_unref_bridge_vlan NMBridgeVlan *vlan = NULL; - gs_free_error GError *local = NULL; - guint16 vid_start, vid_end; - - vlan = nm_bridge_vlan_from_str (value, &local); - if (!vlan) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - "%s. %s", - local->message, - _("The valid syntax is: '<vid>[-<vid>] [pvid] [untagged]'")); - return FALSE; - } - - if (NM_IS_SETTING_BRIDGE (setting)) { - if (do_add) - nm_setting_bridge_add_vlan (NM_SETTING_BRIDGE (setting), vlan); - else { - nm_bridge_vlan_get_vid_range (vlan, &vid_start, &vid_end); - nm_setting_bridge_remove_vlan_by_vid (NM_SETTING_BRIDGE (setting), - vid_start, vid_end); - } - } else { - if (do_add) - nm_setting_bridge_port_add_vlan (NM_SETTING_BRIDGE_PORT (setting), vlan); - else { - nm_bridge_vlan_get_vid_range (vlan, &vid_start, &vid_end); - nm_setting_bridge_port_remove_vlan_by_vid (NM_SETTING_BRIDGE_PORT (setting), - vid_start, - vid_end); - } - } - - return TRUE; +_objlist_set_fcn_bridge_vlans(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) +{ + nm_auto_unref_bridge_vlan NMBridgeVlan *vlan = NULL; + gs_free_error GError *local = NULL; + guint16 vid_start, vid_end; + + vlan = nm_bridge_vlan_from_str(value, &local); + if (!vlan) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "%s. %s", + local->message, + _("The valid syntax is: '<vid>[-<vid>] [pvid] [untagged]'")); + return FALSE; + } + + if (NM_IS_SETTING_BRIDGE(setting)) { + if (do_add) + nm_setting_bridge_add_vlan(NM_SETTING_BRIDGE(setting), vlan); + else { + nm_bridge_vlan_get_vid_range(vlan, &vid_start, &vid_end); + nm_setting_bridge_remove_vlan_by_vid(NM_SETTING_BRIDGE(setting), vid_start, vid_end); + } + } else { + if (do_add) + nm_setting_bridge_port_add_vlan(NM_SETTING_BRIDGE_PORT(setting), vlan); + else { + nm_bridge_vlan_get_vid_range(vlan, &vid_start, &vid_end); + nm_setting_bridge_port_remove_vlan_by_vid(NM_SETTING_BRIDGE_PORT(setting), + vid_start, + vid_end); + } + } + + return TRUE; } static void -_objlist_obj_to_str_fcn_tc_config_tfilters (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_tc_config_tfilters(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - NMTCTfilter *tfilter; - gs_free char *s = NULL; + NMTCTfilter * tfilter; + gs_free char *s = NULL; - tfilter = nm_setting_tc_config_get_tfilter (NM_SETTING_TC_CONFIG (setting), idx); - s = nm_utils_tc_tfilter_to_str (tfilter, NULL); - if (s) - g_string_append (str, s); + tfilter = nm_setting_tc_config_get_tfilter(NM_SETTING_TC_CONFIG(setting), idx); + s = nm_utils_tc_tfilter_to_str(tfilter, NULL); + if (s) + g_string_append(str, s); } static gboolean -_objlist_set_fcn_tc_config_tfilters (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) -{ - gs_free_error GError *local = NULL; - nm_auto_unref_tc_tfilter NMTCTfilter *tc_tfilter = NULL; - - tc_tfilter = nm_utils_tc_tfilter_from_str (value, &local); - if (!tc_tfilter) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - "%s. %s", - local->message, - _("The valid syntax is: '[root | parent <handle>] [handle <handle>] <kind>'")); - return FALSE; - } - if (do_add) - nm_setting_tc_config_add_tfilter (NM_SETTING_TC_CONFIG (setting), tc_tfilter); - else - nm_setting_tc_config_remove_tfilter_by_value (NM_SETTING_TC_CONFIG (setting), tc_tfilter); - return TRUE; +_objlist_set_fcn_tc_config_tfilters(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) +{ + gs_free_error GError * local = NULL; + nm_auto_unref_tc_tfilter NMTCTfilter *tc_tfilter = NULL; + + tc_tfilter = nm_utils_tc_tfilter_from_str(value, &local); + if (!tc_tfilter) { + nm_utils_error_set( + error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + "%s. %s", + local->message, + _("The valid syntax is: '[root | parent <handle>] [handle <handle>] <kind>'")); + return FALSE; + } + if (do_add) + nm_setting_tc_config_add_tfilter(NM_SETTING_TC_CONFIG(setting), tc_tfilter); + else + nm_setting_tc_config_remove_tfilter_by_value(NM_SETTING_TC_CONFIG(setting), tc_tfilter); + return TRUE; } static const char * -_validate_fcn_team_config (const char *value, char **out_to_free, GError **error) +_validate_fcn_team_config(const char *value, char **out_to_free, GError **error) { - char *json = NULL; + char *json = NULL; - if (!nmc_team_check_config (value, &json, error)) - return NULL; - RETURN_STR_TO_FREE (json); + if (!nmc_team_check_config(value, &json, error)) + return NULL; + RETURN_STR_TO_FREE(json); } static void -_objlist_obj_to_str_fcn_team_link_watchers (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str) +_objlist_obj_to_str_fcn_team_link_watchers(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str) { - NMTeamLinkWatcher *watcher; - gs_free char *s = NULL; + NMTeamLinkWatcher *watcher; + gs_free char * s = NULL; - if (NM_IS_SETTING_TEAM (setting)) - watcher = nm_setting_team_get_link_watcher (NM_SETTING_TEAM (setting), idx); - else - watcher = nm_setting_team_port_get_link_watcher (NM_SETTING_TEAM_PORT (setting), idx); + if (NM_IS_SETTING_TEAM(setting)) + watcher = nm_setting_team_get_link_watcher(NM_SETTING_TEAM(setting), idx); + else + watcher = nm_setting_team_port_get_link_watcher(NM_SETTING_TEAM_PORT(setting), idx); - s = nm_utils_team_link_watcher_to_string (watcher); - if (s) - nm_utils_escaped_tokens_escape_gstr (s, ESCAPED_TOKENS_DELIMITERS, str); + s = nm_utils_team_link_watcher_to_string(watcher); + if (s) + nm_utils_escaped_tokens_escape_gstr(s, ESCAPED_TOKENS_DELIMITERS, str); } static gboolean -_objlist_set_fcn_team_link_watchers (NMSetting *setting, - gboolean do_add, - const char *value, - GError **error) -{ - nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher = NULL; - - watcher = nm_utils_team_link_watcher_from_string (value, error); - if (!watcher) - return FALSE; - if (NM_IS_SETTING_TEAM (setting)) { - if (do_add) - nm_setting_team_add_link_watcher (NM_SETTING_TEAM (setting), watcher); - else - nm_setting_team_remove_link_watcher_by_value (NM_SETTING_TEAM (setting), watcher); - } else { - if (do_add) - nm_setting_team_port_add_link_watcher (NM_SETTING_TEAM_PORT (setting), watcher); - else - nm_setting_team_port_remove_link_watcher_by_value (NM_SETTING_TEAM_PORT (setting), watcher); - } - return TRUE; +_objlist_set_fcn_team_link_watchers(NMSetting * setting, + gboolean do_add, + const char *value, + GError ** error) +{ + nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher = NULL; + + watcher = nm_utils_team_link_watcher_from_string(value, error); + if (!watcher) + return FALSE; + if (NM_IS_SETTING_TEAM(setting)) { + if (do_add) + nm_setting_team_add_link_watcher(NM_SETTING_TEAM(setting), watcher); + else + nm_setting_team_remove_link_watcher_by_value(NM_SETTING_TEAM(setting), watcher); + } else { + if (do_add) + nm_setting_team_port_add_link_watcher(NM_SETTING_TEAM_PORT(setting), watcher); + else + nm_setting_team_port_remove_link_watcher_by_value(NM_SETTING_TEAM_PORT(setting), + watcher); + } + return TRUE; } -static gconstpointer -_get_fcn_vlan_flags (ARGS_GET_FCN) +static gconstpointer _get_fcn_vlan_flags(ARGS_GET_FCN) { - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - guint32 flags; + NMSettingVlan *s_vlan = NM_SETTING_VLAN(setting); + guint32 flags; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - flags = nm_setting_vlan_get_flags (s_vlan); - NM_SET_OUT (out_is_default, flags == 0); - RETURN_STR_TO_FREE (vlan_flags_to_string (flags, get_type)); + flags = nm_setting_vlan_get_flags(s_vlan); + NM_SET_OUT(out_is_default, flags == 0); + RETURN_STR_TO_FREE(vlan_flags_to_string(flags, get_type)); } static NMVlanPriorityMap -_vlan_priority_map_type_from_property_info (const NMMetaPropertyInfo *property_info) +_vlan_priority_map_type_from_property_info(const NMMetaPropertyInfo *property_info) { - nm_assert (property_info); - nm_assert (property_info->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VLAN]); - nm_assert (NM_IN_STRSET (property_info->property_name, NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, - NM_SETTING_VLAN_EGRESS_PRIORITY_MAP)); + nm_assert(property_info); + nm_assert(property_info->setting_info + == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VLAN]); + nm_assert(NM_IN_STRSET(property_info->property_name, + NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, + NM_SETTING_VLAN_EGRESS_PRIORITY_MAP)); - return nm_streq (property_info->property_name, NM_SETTING_VLAN_INGRESS_PRIORITY_MAP) - ? NM_VLAN_INGRESS_MAP - : NM_VLAN_EGRESS_MAP; + return nm_streq(property_info->property_name, NM_SETTING_VLAN_INGRESS_PRIORITY_MAP) + ? NM_VLAN_INGRESS_MAP + : NM_VLAN_EGRESS_MAP; } -static gconstpointer -_get_fcn_vlan_xgress_priority_map (ARGS_GET_FCN) +static gconstpointer _get_fcn_vlan_xgress_priority_map(ARGS_GET_FCN) { - NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info (property_info); - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - GString *str = NULL; - gint32 i, num; + NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info(property_info); + NMSettingVlan * s_vlan = NM_SETTING_VLAN(setting); + GString * str = NULL; + gint32 i, num; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - num = nm_setting_vlan_get_num_priorities (s_vlan, map_type); - for (i = 0; i < num; i++) { - guint32 from, to; + num = nm_setting_vlan_get_num_priorities(s_vlan, map_type); + for (i = 0; i < num; i++) { + guint32 from, to; - if (!nm_setting_vlan_get_priority (s_vlan, map_type, i, &from, &to)) - continue; + if (!nm_setting_vlan_get_priority(s_vlan, map_type, i, &from, &to)) + continue; - if (!str) - str = g_string_new (NULL); - else - g_string_append_c (str, ESCAPED_TOKENS_WITH_SPACES_DELIMTER); - g_string_append_printf (str, "%d:%d", from, to); - } + if (!str) + str = g_string_new(NULL); + else + g_string_append_c(str, ESCAPED_TOKENS_WITH_SPACES_DELIMTER); + g_string_append_printf(str, "%d:%d", from, to); + } - NM_SET_OUT (out_is_default, num == 0); - if (!str) - return NULL; - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + NM_SET_OUT(out_is_default, num == 0); + if (!str) + return NULL; + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } -static gboolean -_set_fcn_vlan_xgress_priority_map (ARGS_SET_FCN) -{ - NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info (property_info); - gs_free const char **prio_map = NULL; - gsize i, len; - - if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE (property_info, modifier, value)) { - nm_setting_vlan_clear_priorities (NM_SETTING_VLAN (setting), map_type); - return TRUE; - } - - prio_map = _value_strsplit (value, VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES, &len); - - for (i = 0; i < len; i++) { - if (!nm_utils_vlan_priority_map_parse_str (map_type, - prio_map[i], - _SET_FCN_DO_REMOVE (modifier, value), - NULL, - NULL, - NULL)) { - g_set_error (error, 1, 0, _("invalid priority map '%s'"), prio_map[i]); - return FALSE; - } - } - - if (_SET_FCN_DO_SET_ALL (modifier, value)) - nm_setting_vlan_clear_priorities (NM_SETTING_VLAN (setting), map_type); - - for (i = 0; i < len; i++) { - if (_SET_FCN_DO_REMOVE (modifier, value)) { - nm_setting_vlan_remove_priority_str_by_value (NM_SETTING_VLAN (setting), - map_type, - prio_map[i]); - } else { - nm_setting_vlan_add_priority_str (NM_SETTING_VLAN (setting), - map_type, - prio_map[i]); - } - } - return TRUE; +static gboolean _set_fcn_vlan_xgress_priority_map(ARGS_SET_FCN) +{ + NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info(property_info); + gs_free const char **prio_map = NULL; + gsize i, len; + + if (_SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(property_info, modifier, value)) { + nm_setting_vlan_clear_priorities(NM_SETTING_VLAN(setting), map_type); + return TRUE; + } + + prio_map = _value_strsplit(value, VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES, &len); + + for (i = 0; i < len; i++) { + if (!nm_utils_vlan_priority_map_parse_str(map_type, + prio_map[i], + _SET_FCN_DO_REMOVE(modifier, value), + NULL, + NULL, + NULL)) { + g_set_error(error, 1, 0, _("invalid priority map '%s'"), prio_map[i]); + return FALSE; + } + } + + if (_SET_FCN_DO_SET_ALL(modifier, value)) + nm_setting_vlan_clear_priorities(NM_SETTING_VLAN(setting), map_type); + + for (i = 0; i < len; i++) { + if (_SET_FCN_DO_REMOVE(modifier, value)) { + nm_setting_vlan_remove_priority_str_by_value(NM_SETTING_VLAN(setting), + map_type, + prio_map[i]); + } else { + nm_setting_vlan_add_priority_str(NM_SETTING_VLAN(setting), map_type, prio_map[i]); + } + } + return TRUE; } static void -_vpn_options_callback (const char *key, const char *val, gpointer user_data) +_vpn_options_callback(const char *key, const char *val, gpointer user_data) { - GString *str = user_data; - gs_free char *escaped_key = NULL; - gs_free char *escaped_val = NULL; + GString * str = user_data; + gs_free char *escaped_key = NULL; + gs_free char *escaped_val = NULL; - if (str->len > 0u) - g_string_append (str, ", "); + if (str->len > 0u) + g_string_append(str, ", "); - g_string_append (str, nm_utils_escaped_tokens_options_escape_key (key, &escaped_key)); - g_string_append (str, " = "); - g_string_append (str, nm_utils_escaped_tokens_options_escape_val (val, &escaped_val)); + g_string_append(str, nm_utils_escaped_tokens_options_escape_key(key, &escaped_key)); + g_string_append(str, " = "); + g_string_append(str, nm_utils_escaped_tokens_options_escape_val(val, &escaped_val)); } -static gconstpointer -_get_fcn_vpn_options (ARGS_GET_FCN) +static gconstpointer _get_fcn_vpn_options(ARGS_GET_FCN) { - NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); - GString *str; + NMSettingVpn *s_vpn = NM_SETTING_VPN(setting); + GString * str; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - str = g_string_new (NULL); - if (nm_streq (property_info->property_name, NM_SETTING_VPN_SECRETS)) - nm_setting_vpn_foreach_secret (s_vpn, _vpn_options_callback, str); - else - nm_setting_vpn_foreach_data_item (s_vpn, _vpn_options_callback, str); - NM_SET_OUT (out_is_default, str->len == 0); - RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + str = g_string_new(NULL); + if (nm_streq(property_info->property_name, NM_SETTING_VPN_SECRETS)) + nm_setting_vpn_foreach_secret(s_vpn, _vpn_options_callback, str); + else + nm_setting_vpn_foreach_data_item(s_vpn, _vpn_options_callback, str); + NM_SET_OUT(out_is_default, str->len == 0); + RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } static gboolean -_optionlist_set_fcn_vpn_data (NMSetting *setting, - const char *option, - const char *value, - GError **error) +_optionlist_set_fcn_vpn_data(NMSetting * setting, + const char *option, + const char *value, + GError ** error) { - if (value) - nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), option, value); - else - nm_setting_vpn_remove_data_item (NM_SETTING_VPN (setting), option); - return TRUE; + if (value) + nm_setting_vpn_add_data_item(NM_SETTING_VPN(setting), option, value); + else + nm_setting_vpn_remove_data_item(NM_SETTING_VPN(setting), option); + return TRUE; } static gboolean -_optionlist_set_fcn_vpn_secrets (NMSetting *setting, - const char *option, - const char *value, - GError **error) +_optionlist_set_fcn_vpn_secrets(NMSetting * setting, + const char *option, + const char *value, + GError ** error) { - if (value) - nm_setting_vpn_add_secret (NM_SETTING_VPN (setting), option, value); - else - nm_setting_vpn_remove_secret (NM_SETTING_VPN (setting), option); - return TRUE; + if (value) + nm_setting_vpn_add_secret(NM_SETTING_VPN(setting), option, value); + else + nm_setting_vpn_remove_secret(NM_SETTING_VPN(setting), option); + return TRUE; } -static gboolean -_set_fcn_wired_s390_subchannels (ARGS_SET_FCN) +static gboolean _set_fcn_wired_s390_subchannels(ARGS_SET_FCN) { - gs_free const char **strv = NULL; - gsize len; + gs_free const char **strv = NULL; + gsize len; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - strv = nm_utils_strsplit_set (value, " ,\t"); - len = NM_PTRARRAY_LEN (strv); - if (len != 2 && len != 3) { - g_set_error (error, 1, 0, _("'%s' is not valid; 2 or 3 strings should be provided"), - value); - return FALSE; - } + strv = nm_utils_strsplit_set(value, " ,\t"); + len = NM_PTRARRAY_LEN(strv); + if (len != 2 && len != 3) { + g_set_error(error, 1, 0, _("'%s' is not valid; 2 or 3 strings should be provided"), value); + return FALSE; + } - g_object_set (setting, property_info->property_name, strv, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, strv, NULL); + return TRUE; } static gboolean -_optionlist_set_fcn_wired_s390_options (NMSetting *setting, - const char *name, - const char *value, - GError **error) +_optionlist_set_fcn_wired_s390_options(NMSetting * setting, + const char *name, + const char *value, + GError ** error) { - if (value) - nm_setting_wired_add_s390_option (NM_SETTING_WIRED (setting), name, value); - else - nm_setting_wired_remove_s390_option (NM_SETTING_WIRED (setting), name); - return TRUE; + if (value) + nm_setting_wired_add_s390_option(NM_SETTING_WIRED(setting), name, value); + else + nm_setting_wired_remove_s390_option(NM_SETTING_WIRED(setting), name); + return TRUE; } -static const char *const* -_values_fcn_wired_s390_options (ARGS_VALUES_FCN) +static const char *const *_values_fcn_wired_s390_options(ARGS_VALUES_FCN) { - return nm_setting_wired_get_valid_s390_options (NULL); + return nm_setting_wired_get_valid_s390_options(NULL); } -static const char * -_describe_fcn_wired_s390_options (ARGS_DESCRIBE_FCN) +static const char *_describe_fcn_wired_s390_options(ARGS_DESCRIBE_FCN) { - gs_free char *options_str = NULL; - const char **valid_options; - char *s; + gs_free char *options_str = NULL; + const char ** valid_options; + char * s; - valid_options = nm_setting_wired_get_valid_s390_options (NULL); + valid_options = nm_setting_wired_get_valid_s390_options(NULL); - options_str = g_strjoinv (", ", (char **) valid_options); + options_str = g_strjoinv(", ", (char **) valid_options); - s = g_strdup_printf (_("Enter a list of S/390 options formatted as:\n" - " option = <value>, option = <value>,...\n" - "Valid options are: %s\n"), - options_str); - return (*out_to_free = s); + s = g_strdup_printf(_("Enter a list of S/390 options formatted as:\n" + " option = <value>, option = <value>,...\n" + "Valid options are: %s\n"), + options_str); + return (*out_to_free = s); } -static gconstpointer -_get_fcn_wireless_ssid (ARGS_GET_FCN) +static gconstpointer _get_fcn_wireless_ssid(ARGS_GET_FCN) { - NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); - GBytes *ssid; - char *ssid_str = NULL; + NMSettingWireless *s_wireless = NM_SETTING_WIRELESS(setting); + GBytes * ssid; + char * ssid_str = NULL; - RETURN_UNSUPPORTED_GET_TYPE (); + RETURN_UNSUPPORTED_GET_TYPE(); - ssid = nm_setting_wireless_get_ssid (s_wireless); - if (ssid) { - ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - } + ssid = nm_setting_wireless_get_ssid(s_wireless); + if (ssid) { + ssid_str = nm_utils_ssid_to_utf8(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid)); + } - NM_SET_OUT (out_is_default, !ssid_str || !ssid_str[0]); - RETURN_STR_TO_FREE (ssid_str); + NM_SET_OUT(out_is_default, !ssid_str || !ssid_str[0]); + RETURN_STR_TO_FREE(ssid_str); } -static gboolean -_set_fcn_wireless_channel (ARGS_SET_FCN) +static gboolean _set_fcn_wireless_channel(ARGS_SET_FCN) { - unsigned long chan_int; + unsigned long chan_int; - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - return _gobject_property_reset_default (setting, property_info->property_name); + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + return _gobject_property_reset_default(setting, property_info->property_name); - if (!nmc_string_to_uint (value, FALSE, 0, 0, &chan_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid channel"), value); - return FALSE; - } + if (!nmc_string_to_uint(value, FALSE, 0, 0, &chan_int)) { + g_set_error(error, 1, 0, _("'%s' is not a valid channel"), value); + return FALSE; + } - if ( !nm_utils_wifi_is_channel_valid (chan_int, "a") - && !nm_utils_wifi_is_channel_valid (chan_int, "bg")) { - g_set_error (error, 1, 0, _("'%ld' is not a valid channel"), chan_int); - return FALSE; - } + if (!nm_utils_wifi_is_channel_valid(chan_int, "a") + && !nm_utils_wifi_is_channel_valid(chan_int, "bg")) { + g_set_error(error, 1, 0, _("'%ld' is not a valid channel"), chan_int); + return FALSE; + } - g_object_set (setting, property_info->property_name, chan_int, NULL); - return TRUE; + g_object_set(setting, property_info->property_name, chan_int, NULL); + return TRUE; } static const char * -_multilist_validate2_fcn_mac_addr (NMSetting *setting, - const char *item, - GError **error) -{ - guint8 buf[ETH_ALEN]; - - if (!nm_utils_hwaddr_aton (item, buf, ETH_ALEN)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is not a valid MAC address"), item); - return NULL; - } - - return item; -} - -static gconstpointer -_get_fcn_wireless_security_wep_key (ARGS_GET_FCN) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - char *key; - guint index; - - RETURN_UNSUPPORTED_GET_TYPE (); - - nm_assert (g_str_has_prefix (property_info->property_name, "wep-key")); - nm_assert (NM_IN_SET (property_info->property_name[7], '0', '1', '2', '3')); - nm_assert (property_info->property_name[8] == '\0'); - - index = property_info->property_name[7] - '0'; - - key = g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, index)); - NM_SET_OUT (out_is_default, !key); - RETURN_STR_TO_FREE (key); -} - -static gboolean -_set_fcn_wireless_wep_key (ARGS_SET_FCN) -{ - NMWepKeyType guessed_type = NM_WEP_KEY_TYPE_UNKNOWN; - NMWepKeyType type; - guint32 prev_idx, idx; - - nm_assert (!error || !*error); - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) { - g_object_set (setting, property_info->property_name, NULL, NULL); - return TRUE; - } - - /* Get currently set type */ - type = nm_setting_wireless_security_get_wep_key_type (NM_SETTING_WIRELESS_SECURITY (setting)); - - /* Guess key type */ - if (nm_utils_wep_key_valid (value, NM_WEP_KEY_TYPE_KEY)) - guessed_type = NM_WEP_KEY_TYPE_KEY; - else if (nm_utils_wep_key_valid (value, NM_WEP_KEY_TYPE_PASSPHRASE)) - guessed_type = NM_WEP_KEY_TYPE_PASSPHRASE; - - if (guessed_type == NM_WEP_KEY_TYPE_UNKNOWN) { - g_set_error (error, 1, 0, _("'%s' is not valid"), value); - return FALSE; - } - - if (type != NM_WEP_KEY_TYPE_UNKNOWN && type != guessed_type) { - if (nm_utils_wep_key_valid (value, type)) - guessed_type = type; - else { - g_set_error (error, 1, 0, - _("'%s' not compatible with %s '%s', please change the key or set the right %s first."), - value, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, wep_key_type_to_string (type), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); - return FALSE; - } - } - prev_idx = nm_setting_wireless_security_get_wep_tx_keyidx (NM_SETTING_WIRELESS_SECURITY (setting)); - idx = property_info->property_name[strlen (property_info->property_name) - 1] - '0'; - _env_warn_fcn (environment, environment_user_data, - NM_META_ENV_WARN_LEVEL_INFO, - N_("WEP key is guessed to be of '%s'"), - wep_key_type_to_string (guessed_type)); - if (idx != prev_idx) { - _env_warn_fcn (environment, environment_user_data, - NM_META_ENV_WARN_LEVEL_INFO, - N_("WEP key index set to '%d'"), - idx); - } - - g_object_set (setting, property_info->property_name, value, NULL); - g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, guessed_type, NULL); - if (idx != prev_idx) - g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, idx, NULL); - return TRUE; +_multilist_validate2_fcn_mac_addr(NMSetting *setting, const char *item, GError **error) +{ + guint8 buf[ETH_ALEN]; + + if (!nm_utils_hwaddr_aton(item, buf, ETH_ALEN)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is not a valid MAC address"), + item); + return NULL; + } + + return item; +} + +static gconstpointer _get_fcn_wireless_security_wep_key(ARGS_GET_FCN) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY(setting); + char * key; + guint index; + + RETURN_UNSUPPORTED_GET_TYPE(); + + nm_assert(g_str_has_prefix(property_info->property_name, "wep-key")); + nm_assert(NM_IN_SET(property_info->property_name[7], '0', '1', '2', '3')); + nm_assert(property_info->property_name[8] == '\0'); + + index = property_info->property_name[7] - '0'; + + key = g_strdup(nm_setting_wireless_security_get_wep_key(s_wireless_sec, index)); + NM_SET_OUT(out_is_default, !key); + RETURN_STR_TO_FREE(key); +} + +static gboolean _set_fcn_wireless_wep_key(ARGS_SET_FCN) +{ + NMWepKeyType guessed_type = NM_WEP_KEY_TYPE_UNKNOWN; + NMWepKeyType type; + guint32 prev_idx, idx; + + nm_assert(!error || !*error); + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) { + g_object_set(setting, property_info->property_name, NULL, NULL); + return TRUE; + } + + /* Get currently set type */ + type = nm_setting_wireless_security_get_wep_key_type(NM_SETTING_WIRELESS_SECURITY(setting)); + + /* Guess key type */ + if (nm_utils_wep_key_valid(value, NM_WEP_KEY_TYPE_KEY)) + guessed_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid(value, NM_WEP_KEY_TYPE_PASSPHRASE)) + guessed_type = NM_WEP_KEY_TYPE_PASSPHRASE; + + if (guessed_type == NM_WEP_KEY_TYPE_UNKNOWN) { + g_set_error(error, 1, 0, _("'%s' is not valid"), value); + return FALSE; + } + + if (type != NM_WEP_KEY_TYPE_UNKNOWN && type != guessed_type) { + if (nm_utils_wep_key_valid(value, type)) + guessed_type = type; + else { + g_set_error(error, + 1, + 0, + _("'%s' not compatible with %s '%s', please change the key or set the " + "right %s first."), + value, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + wep_key_type_to_string(type), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); + return FALSE; + } + } + prev_idx = + nm_setting_wireless_security_get_wep_tx_keyidx(NM_SETTING_WIRELESS_SECURITY(setting)); + idx = property_info->property_name[strlen(property_info->property_name) - 1] - '0'; + _env_warn_fcn(environment, + environment_user_data, + NM_META_ENV_WARN_LEVEL_INFO, + N_("WEP key is guessed to be of '%s'"), + wep_key_type_to_string(guessed_type)); + if (idx != prev_idx) { + _env_warn_fcn(environment, + environment_user_data, + NM_META_ENV_WARN_LEVEL_INFO, + N_("WEP key index set to '%d'"), + idx); + } + + g_object_set(setting, property_info->property_name, value, NULL); + g_object_set(setting, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, guessed_type, NULL); + if (idx != prev_idx) + g_object_set(setting, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, idx, NULL); + return TRUE; } static void -_gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type (const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMSetting *setting, - int value) -{ - guint i; - const char *key; - const char *keynames[] = { - NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, - }; - - /* Check type compatibility with set keys */ - if (!NM_IN_SET (value, - NM_WEP_KEY_TYPE_UNKNOWN, - NM_WEP_KEY_TYPE_KEY, - NM_WEP_KEY_TYPE_PASSPHRASE)) - return; - - for (i = 0; i < 4; i++) { - key = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), i); - if (key && !nm_utils_wep_key_valid (key, value)) { - _env_warn_fcn (environment, environment_user_data, - NM_META_ENV_WARN_LEVEL_WARN, - N_("'%s' is not compatible with '%s' type, please change or delete the key."), - keynames[i], wep_key_type_to_string (value)); - } - } +_gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type( + const NMMetaPropertyInfo *property_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + NMSetting * setting, + int value) +{ + guint i; + const char *key; + const char *keynames[] = { + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, + }; + + /* Check type compatibility with set keys */ + if (!NM_IN_SET(value, NM_WEP_KEY_TYPE_UNKNOWN, NM_WEP_KEY_TYPE_KEY, NM_WEP_KEY_TYPE_PASSPHRASE)) + return; + + for (i = 0; i < 4; i++) { + key = nm_setting_wireless_security_get_wep_key(NM_SETTING_WIRELESS_SECURITY(setting), i); + if (key && !nm_utils_wep_key_valid(key, value)) { + _env_warn_fcn( + environment, + environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_("'%s' is not compatible with '%s' type, please change or delete the key."), + keynames[i], + wep_key_type_to_string(value)); + } + } } /*****************************************************************************/ -static gconstpointer -_get_fcn_ethtool (ARGS_GET_FCN) -{ - NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; - const char *s; - guint32 u32; - gboolean b; - - RETURN_UNSUPPORTED_GET_TYPE (); - - if ( nm_ethtool_id_is_coalesce (ethtool_id) - || nm_ethtool_id_is_ring (ethtool_id)) { - if (!nm_setting_option_get_uint32 (setting, - nm_ethtool_data[ethtool_id]->optname, - &u32)) { - NM_SET_OUT (out_is_default, TRUE); - return NULL; - } - - RETURN_STR_TO_FREE (nm_strdup_int (u32)); - } - - nm_assert (nm_ethtool_id_is_feature (ethtool_id)); - - if (!nm_setting_option_get_boolean (setting, - nm_ethtool_data[ethtool_id]->optname, - &b)) { - NM_SET_OUT (out_is_default, TRUE); - return NULL; - } - - s = b - ? N_("on") - : N_("off"); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - s = gettext (s); - return s; -} - -static gboolean -_set_fcn_ethtool (ARGS_SET_FCN) -{ - NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; - gs_free char *value_to_free = NULL; - gint64 i64; - gboolean b; - - if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value)) - goto do_unset; - - if ( nm_ethtool_id_is_coalesce (ethtool_id) - || nm_ethtool_id_is_ring (ethtool_id)) { - - i64 = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); - if (i64 == -1) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is out of range [%"G_GUINT32_FORMAT", %"G_GUINT32_FORMAT"]"), - value, 0, G_MAXUINT32); - return FALSE; - } - - nm_setting_option_set_uint32 (setting, - nm_ethtool_data[ethtool_id]->optname, - i64); - return TRUE; - } - - nm_assert (nm_ethtool_id_is_feature (ethtool_id)); - - value = nm_strstrip_avoid_copy_a (300, value, &value_to_free); - if (NM_IN_STRSET (value, "1", "yes", "true", "on")) - b = TRUE; - else if (NM_IN_STRSET (value, "0", "no", "false", "off")) - b = FALSE; - else if (NM_IN_STRSET (value, "", "ignore", "default")) - goto do_unset; - else { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("'%s' is not valid; use 'on', 'off', or 'ignore'"), - value); - return FALSE; - } - - nm_setting_option_set_boolean (setting, - nm_ethtool_data[ethtool_id]->optname, - b); - return TRUE; +static gconstpointer _get_fcn_ethtool(ARGS_GET_FCN) +{ + NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; + const char *s; + guint32 u32; + gboolean b; + + RETURN_UNSUPPORTED_GET_TYPE(); + + if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id)) { + if (!nm_setting_option_get_uint32(setting, nm_ethtool_data[ethtool_id]->optname, &u32)) { + NM_SET_OUT(out_is_default, TRUE); + return NULL; + } + + RETURN_STR_TO_FREE(nm_strdup_int(u32)); + } + + nm_assert(nm_ethtool_id_is_feature(ethtool_id)); + + if (!nm_setting_option_get_boolean(setting, nm_ethtool_data[ethtool_id]->optname, &b)) { + NM_SET_OUT(out_is_default, TRUE); + return NULL; + } + + s = b ? N_("on") : N_("off"); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + s = gettext(s); + return s; +} + +static gboolean _set_fcn_ethtool(ARGS_SET_FCN) +{ + NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; + gs_free char *value_to_free = NULL; + gint64 i64; + gboolean b; + + if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) + goto do_unset; + + if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id)) { + i64 = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT32, -1); + if (i64 == -1) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is out of range [%" G_GUINT32_FORMAT ", %" G_GUINT32_FORMAT "]"), + value, + 0, + G_MAXUINT32); + return FALSE; + } + + nm_setting_option_set_uint32(setting, nm_ethtool_data[ethtool_id]->optname, i64); + return TRUE; + } + + nm_assert(nm_ethtool_id_is_feature(ethtool_id)); + + value = nm_strstrip_avoid_copy_a(300, value, &value_to_free); + if (NM_IN_STRSET(value, "1", "yes", "true", "on")) + b = TRUE; + else if (NM_IN_STRSET(value, "0", "no", "false", "off")) + b = FALSE; + else if (NM_IN_STRSET(value, "", "ignore", "default")) + goto do_unset; + else { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' is not valid; use 'on', 'off', or 'ignore'"), + value); + return FALSE; + } + + nm_setting_option_set_boolean(setting, nm_ethtool_data[ethtool_id]->optname, b); + return TRUE; do_unset: - nm_setting_option_set (setting, - nm_ethtool_data[ethtool_id]->optname, - NULL); - return TRUE; -} - -static const char *const* -_complete_fcn_ethtool (ARGS_COMPLETE_FCN) -{ - static const char *const v[] = { - "true", - "false", - "1", - "0", - "yes", - "no", - "default", - "on", - "off", - "ignore", - NULL, - }; - NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; - - if (nm_ethtool_id_is_feature (ethtool_id)) { - if (!text || !text[0]) - return &v[7]; - return v; - } - return NULL; + nm_setting_option_set(setting, nm_ethtool_data[ethtool_id]->optname, NULL); + return TRUE; +} + +static const char *const *_complete_fcn_ethtool(ARGS_COMPLETE_FCN) +{ + static const char *const v[] = { + "true", + "false", + "1", + "0", + "yes", + "no", + "default", + "on", + "off", + "ignore", + NULL, + }; + NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; + + if (nm_ethtool_id_is_feature(ethtool_id)) { + if (!text || !text[0]) + return &v[7]; + return v; + } + return NULL; } /*****************************************************************************/ +/* clang-format off */ + static const NMMetaPropertyInfo property_info_BOND_OPTIONS; #define NESTED_PROPERTY_INFO_BOND(...) \ - .parent_info = &property_info_BOND_OPTIONS, \ - .base = { \ - .meta_type = &nm_meta_type_nested_property_info, \ - .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_BOND], \ - __VA_ARGS__ \ - } + .parent_info = &property_info_BOND_OPTIONS, \ + .base = { \ + .meta_type = &nm_meta_type_nested_property_info, \ + .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_BOND], \ + __VA_ARGS__ \ + } static const NMMetaNestedPropertyInfo meta_nested_property_infos_bond[] = { - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "mode", - .prompt = NM_META_TEXT_PROMPT_BOND_MODE, - .def_hint = "[balance-rr]", - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "primary", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding primary interface [none]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - /* this is a virtual property, only needed during "ask" mode. */ - .prompt = N_("Bonding monitoring mode"), - .def_hint = NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES, - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "miimon", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding miimon [100]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "downdelay", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding downdelay [0]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "updelay", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding updelay [0]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "arp-interval", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding arp-interval [0]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "arp-ip-target", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("Bonding arp-ip-target [none]"), - ) - }, - { - NESTED_PROPERTY_INFO_BOND ( - .property_name = NM_SETTING_BOND_OPTIONS, - .property_alias = "lacp-rate", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = N_("LACP rate ('slow' or 'fast') [slow]"), - ) - }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "mode", + .prompt = NM_META_TEXT_PROMPT_BOND_MODE, + .def_hint = "[balance-rr]", + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "primary", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding primary interface [none]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + /* this is a virtual property, only needed during "ask" mode. */ + .prompt = N_("Bonding monitoring mode"), + .def_hint = NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES, + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "miimon", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding miimon [100]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "downdelay", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding downdelay [0]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "updelay", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding updelay [0]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "arp-interval", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding arp-interval [0]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "arp-ip-target", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("Bonding arp-ip-target [none]"), + ) + }, + { + NESTED_PROPERTY_INFO_BOND ( + .property_name = NM_SETTING_BOND_OPTIONS, + .property_alias = "lacp-rate", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = N_("LACP rate ('slow' or 'fast') [slow]"), + ) + }, }; const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond = { - .nested = meta_nested_property_infos_bond, - .nested_len = G_N_ELEMENTS (meta_nested_property_infos_bond), + .nested = meta_nested_property_infos_bond, + .nested_len = G_N_ELEMENTS (meta_nested_property_infos_bond), }; /*****************************************************************************/ #define DEFINE_PROPERTY_TYPE(...) \ - (&((NMMetaPropertyType) { __VA_ARGS__ } )) + (&((NMMetaPropertyType) { __VA_ARGS__ } )) #define DEFINE_PROPERTY_TYP_DATA(...) \ - (&((NMMetaPropertyTypData) { __VA_ARGS__ } )) + (&((NMMetaPropertyTypData) { __VA_ARGS__ } )) #define PROPERTY_TYP_DATA_SUBTYPE(stype, ...) \ - .subtype = { \ - .stype = { __VA_ARGS__ }, \ - } + .subtype = { \ + .stype = { __VA_ARGS__ }, \ + } #define DEFINE_PROPERTY_TYP_DATA_SUBTYPE(stype, ...) \ - DEFINE_PROPERTY_TYP_DATA ( \ - PROPERTY_TYP_DATA_SUBTYPE (stype, __VA_ARGS__), \ - ) + DEFINE_PROPERTY_TYP_DATA ( \ + PROPERTY_TYP_DATA_SUBTYPE (stype, __VA_ARGS__), \ + ) static const NMMetaPropertyType _pt_gobject_readonly = { - .get_fcn = _get_fcn_gobject, + .get_fcn = _get_fcn_gobject, }; static const NMMetaPropertyType _pt_gobject_string = { - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_string, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_string, }; static const NMMetaPropertyType _pt_gobject_bool = { - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_bool, - .complete_fcn = _complete_fcn_gobject_bool, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_bool, + .complete_fcn = _complete_fcn_gobject_bool, }; static const NMMetaPropertyType _pt_gobject_int = { - .get_fcn = _get_fcn_gobject_int, - .set_fcn = _set_fcn_gobject_int, + .get_fcn = _get_fcn_gobject_int, + .set_fcn = _set_fcn_gobject_int, }; static const NMMetaPropertyType _pt_gobject_mtu = { - .get_fcn = _get_fcn_gobject_mtu, - .set_fcn = _set_fcn_gobject_mtu, + .get_fcn = _get_fcn_gobject_mtu, + .set_fcn = _set_fcn_gobject_mtu, }; static const NMMetaPropertyType _pt_gobject_bytes = { - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_bytes, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_bytes, }; static const NMMetaPropertyType _pt_gobject_mac = { - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_mac, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_mac, }; static const NMMetaPropertyType _pt_gobject_secret_flags = { - .get_fcn = _get_fcn_gobject_secret_flags, - .set_fcn = _set_fcn_gobject_enum, - .values_fcn = _values_fcn_gobject_enum, - .set_supports_remove = TRUE, + .get_fcn = _get_fcn_gobject_secret_flags, + .set_fcn = _set_fcn_gobject_enum, + .values_fcn = _values_fcn_gobject_enum, + .set_supports_remove = TRUE, }; static const NMMetaPropertyType _pt_gobject_enum = { - .get_fcn = _get_fcn_gobject_enum, - .set_fcn = _set_fcn_gobject_enum, - .values_fcn = _values_fcn_gobject_enum, - .set_supports_remove = TRUE, + .get_fcn = _get_fcn_gobject_enum, + .set_fcn = _set_fcn_gobject_enum, + .values_fcn = _values_fcn_gobject_enum, + .set_supports_remove = TRUE, }; static const NMMetaPropertyType _pt_gobject_devices = { - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_string, - .complete_fcn = _complete_fcn_gobject_devices, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_string, + .complete_fcn = _complete_fcn_gobject_devices, }; static const NMMetaPropertyType _pt_dcb_flags = { - .get_fcn = _get_fcn_dcb_flags, - .set_fcn = _set_fcn_dcb_flags, + .get_fcn = _get_fcn_dcb_flags, + .set_fcn = _set_fcn_dcb_flags, }; static const NMMetaPropertyType _pt_dcb_bool = { - .get_fcn = _get_fcn_dcb_bool, - .set_fcn = _set_fcn_dcb_bool, + .get_fcn = _get_fcn_dcb_bool, + .set_fcn = _set_fcn_dcb_bool, }; static const NMMetaPropertyType _pt_dcb = { - .get_fcn = _get_fcn_dcb, - .set_fcn = _set_fcn_dcb, + .get_fcn = _get_fcn_dcb, + .set_fcn = _set_fcn_dcb, }; static const NMMetaPropertyType _pt_cert_8021x = { - .get_fcn = _get_fcn_cert_8021x, - .set_fcn = _set_fcn_cert_8021x, - .complete_fcn = _complete_fcn_cert_8021x, + .get_fcn = _get_fcn_cert_8021x, + .set_fcn = _set_fcn_cert_8021x, + .complete_fcn = _complete_fcn_cert_8021x, }; static const NMMetaPropertyType _pt_ethtool = { - .get_fcn = _get_fcn_ethtool, - .set_fcn = _set_fcn_ethtool, - .complete_fcn = _complete_fcn_ethtool, + .get_fcn = _get_fcn_ethtool, + .set_fcn = _set_fcn_ethtool, + .complete_fcn = _complete_fcn_ethtool, }; static const NMMetaPropertyType _pt_multilist = { - .get_fcn = _get_fcn_multilist, - .set_fcn = _set_fcn_multilist, - .set_supports_remove = TRUE, + .get_fcn = _get_fcn_multilist, + .set_fcn = _set_fcn_multilist, + .set_supports_remove = TRUE, }; static const NMMetaPropertyType _pt_objlist = { - .get_fcn = _get_fcn_objlist, - .set_fcn = _set_fcn_objlist, - .set_supports_remove = TRUE, + .get_fcn = _get_fcn_objlist, + .set_fcn = _set_fcn_objlist, + .set_supports_remove = TRUE, }; #define MULTILIST_GET_NUM_FCN_U32(type, func) (((func) == ((guint32 (*) (type * )) (func))) ? ((guint32 (*) (NMSetting * )) (func)) : NULL) @@ -4456,52 +4512,52 @@ static const NMMetaPropertyType _pt_objlist = { /*****************************************************************************/ #define PROPERTY_INFO_INIT(name, doc, ...) \ - { \ - .meta_type = &nm_meta_type_property_info, \ - .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ - .property_name = name, \ - .describe_doc = doc, \ - __VA_ARGS__ \ - } + { \ + .meta_type = &nm_meta_type_property_info, \ + .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ + .property_name = name, \ + .describe_doc = doc, \ + __VA_ARGS__ \ + } #define PROPERTY_INFO(name, doc, ...) \ - (&((const NMMetaPropertyInfo) PROPERTY_INFO_INIT (name, doc, __VA_ARGS__))) + (&((const NMMetaPropertyInfo) PROPERTY_INFO_INIT (name, doc, __VA_ARGS__))) #define PROPERTY_INFO_WITH_DESC(name, ...) \ - PROPERTY_INFO (name, DESCRIBE_DOC_##name, ##__VA_ARGS__) + PROPERTY_INFO (name, DESCRIBE_DOC_##name, ##__VA_ARGS__) #define ENUM_VALUE_INFOS(...) (((const NMUtilsEnumValueInfo []) { __VA_ARGS__ { .nick = NULL, }, })) #define INT_VALUE_INFOS(...) (((const NMMetaUtilsIntValueInfo []) { __VA_ARGS__ { .nick = NULL, }, })) #define MTU_GET_FCN(type, func) \ - /* macro that returns @func as const (guint32(*)(NMSetting*)) type, but checks - * that the actual type is (guint32(*)(type *)). */ \ - ((guint32 (*) (NMSetting *)) ((sizeof (func == ((guint32 (*) (type *)) func))) ? func : func) ) + /* macro that returns @func as const (guint32(*)(NMSetting*)) type, but checks + * that the actual type is (guint32(*)(type *)). */ \ + ((guint32 (*) (NMSetting *)) ((sizeof (func == ((guint32 (*) (type *)) func))) ? func : func) ) #define TEAM_DESCRIBE_MESSAGE \ - N_("nmcli can accepts both direct JSON configuration data and a file name containing " \ - "the configuration. In the latter case the file is read and the contents is put " \ - "into this property.\n\n" \ - "Examples: set team.config " \ - "{ \"device\": \"team0\", \"runner\": {\"name\": \"roundrobin\"}, \"ports\": {\"eth1\": {}, \"eth2\": {}} }\n" \ - " set team.config /etc/my-team.conf\n") + N_("nmcli can accepts both direct JSON configuration data and a file name containing " \ + "the configuration. In the latter case the file is read and the contents is put " \ + "into this property.\n\n" \ + "Examples: set team.config " \ + "{ \"device\": \"team0\", \"runner\": {\"name\": \"roundrobin\"}, \"ports\": {\"eth1\": {}, \"eth2\": {}} }\n" \ + " set team.config /etc/my-team.conf\n") #define TEAM_LINK_WATCHERS_DESCRIBE_MESSAGE \ - N_("Enter a list of link watchers formatted as dictionaries where the keys " \ - "are teamd properties. Dictionary pairs are in the form: key=value and pairs " \ - "are separated by ' '. Dictionaries are separated with ','.\n" \ - "The keys allowed/required in the dictionary change on the basis of the link " \ - "watcher type, while the only property common to all the link watchers is " \ - " 'name'*, which defines the link watcher to be specified.\n\n" \ - "Properties available for the 'ethtool' link watcher:\n" \ - " 'delay-up', 'delay-down'\n\n" \ - "Properties available for the 'nsna_ping' link watcher:\n" \ - " 'init-wait', 'interval', 'missed-max', 'target-host'*\n\n" \ - "Properties available for the 'arp_ping' include all the ones for 'nsna_ping' and:\n" \ - " 'source-host'*, 'validate-active', 'validate-inactive', 'send-always'.\n\n" \ - "Properties flagged with a '*' are mandatory.\n\n" \ - "Example:\n" \ - " name=arp_ping source-host=172.16.1.1 target-host=172.16.1.254, name=ethtool delay-up=3\n") + N_("Enter a list of link watchers formatted as dictionaries where the keys " \ + "are teamd properties. Dictionary pairs are in the form: key=value and pairs " \ + "are separated by ' '. Dictionaries are separated with ','.\n" \ + "The keys allowed/required in the dictionary change on the basis of the link " \ + "watcher type, while the only property common to all the link watchers is " \ + " 'name'*, which defines the link watcher to be specified.\n\n" \ + "Properties available for the 'ethtool' link watcher:\n" \ + " 'delay-up', 'delay-down'\n\n" \ + "Properties available for the 'nsna_ping' link watcher:\n" \ + " 'init-wait', 'interval', 'missed-max', 'target-host'*\n\n" \ + "Properties available for the 'arp_ping' include all the ones for 'nsna_ping' and:\n" \ + " 'source-host'*, 'validate-active', 'validate-inactive', 'send-always'.\n\n" \ + "Properties flagged with a '*' are mandatory.\n\n" \ + "Example:\n" \ + " name=arp_ping source-host=172.16.1.1 target-host=172.16.1.254, name=ethtool delay-up=3\n") #define DEFINE_DCB_PROPRITY_PROPERTY_TYPE \ .property_type = &_pt_gobject_int, \ @@ -4532,3201 +4588,3220 @@ static const NMMetaPropertyTypData _ptd_gobject_int_timeout = { #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_6LOWPAN static const NMMetaPropertyInfo *const property_infos_6LOWPAN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_6LOWPAN_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("IEEE 802.15.4 (WPAN) parent device or connection UUID"), - .property_type = &_pt_gobject_string, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_6LOWPAN_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("IEEE 802.15.4 (WPAN) parent device or connection UUID"), + .property_type = &_pt_gobject_string, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_802_1X static const NMMetaPropertyInfo *const property_infos_802_1X[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_OPTIONAL, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_EAP, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_eap_methods), - .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_eap_method), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_eap_method), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_eap_method_by_value), - .strsplit_plain = TRUE, - ), - .values_static = NM_MAKE_STRV ("leap", "md5", "tls", "peap", "ttls", "sim", "fast", "pwd"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_IDENTITY, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_ANONYMOUS_IDENTITY, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PAC_FILE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT, - .describe_message = - N_("Enter file path to CA certificate (optionally prefixed with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/cacert.crt\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_PATH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_SUBJECT_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_ALTSUBJECT_MATCHES, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_altsubject_matches), - .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_altsubject_match), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_altsubject_match), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_altsubject_match_by_value), - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_DOMAIN_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT, - .describe_message = - N_("Enter file path to client certificate (optionally prefixed with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/jara.crt\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_PEAPVER, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("0", "1"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_PEAPLABEL, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("0", "1"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("0", "1", "2", "3"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_802_1x_auth_flags_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_AUTH, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", "tls"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_AUTHEAP, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("md5", "mschapv2", "otp", "gtc", "tls"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT, - .describe_message = - N_("Enter file path to CA certificate for inner authentication (optionally prefixed\n" - "with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/ca-zweite-phase.crt\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_PATH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_phase2_altsubject_matches), - .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_phase2_altsubject_match), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_phase2_altsubject_match), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_phase2_altsubject_match_by_value), - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_DOMAIN_MATCH, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT, - .describe_message = - N_("Enter file path to client certificate for inner authentication (optionally prefixed\n" - "with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/jara-zweite-phase.crt\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_RAW, - .is_secret = TRUE, - .describe_message = - N_("Enter bytes as a list of hexadecimal values.\n" - "Two formats are accepted:\n" - "(a) a string of hexadecimal digits, where each two digits represent one byte\n" - "(b) space-separated list of bytes written as hexadecimal digits " - "(with optional 0x/0X prefix, and optional leading 0).\n\n" - "Examples: ab0455a6ea3a74C2\n" - " ab 4 55 0xa6 ea 3a 74 C2\n"), - .property_type = &_pt_gobject_bytes, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_bytes, - .legacy_format = TRUE, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_RAW_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY, - .describe_message = - N_("Enter path to a private key and the key password (if not set yet):\n" - " [file://]<file path> [<password>]\n" - "Note that nmcli does not support specifying private key as raw blob data.\n" - "Example: /home/cimrman/jara-priv-key Dardanely\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, - .describe_message = - N_("Enter path to a private key and the key password (if not set yet):\n" - " [file://]<file path> [<password>]\n" - "Note that nmcli does not support specifying private key as raw blob data.\n" - "Example: /home/cimrman/jara-priv-key Dardanely\n"), - .property_type = &_pt_cert_8021x, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, - .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PIN, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PIN_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_SYSTEM_CA_CERTS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_AUTH_TIMEOUT, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_OPTIONAL, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_EAP, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_eap_methods), + .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_eap_method), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_eap_method), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_eap_method_by_value), + .strsplit_plain = TRUE, + ), + .values_static = NM_MAKE_STRV ("leap", "md5", "tls", "peap", "ttls", "sim", "fast", "pwd"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_IDENTITY, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_ANONYMOUS_IDENTITY, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PAC_FILE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT, + .describe_message = + N_("Enter file path to CA certificate (optionally prefixed with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/cacert.crt\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CA_PATH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_SUBJECT_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_ALTSUBJECT_MATCHES, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_altsubject_matches), + .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_altsubject_match), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_altsubject_match), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_altsubject_match_by_value), + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_DOMAIN_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT, + .describe_message = + N_("Enter file path to client certificate (optionally prefixed with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/jara.crt\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_PEAPVER, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("0", "1"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_PEAPLABEL, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("0", "1"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("0", "1", "2", "3"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_802_1x_auth_flags_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_AUTH, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", "tls"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_AUTHEAP, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("md5", "mschapv2", "otp", "gtc", "tls"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT, + .describe_message = + N_("Enter file path to CA certificate for inner authentication (optionally prefixed\n" + "with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/ca-zweite-phase.crt\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CA_PATH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSetting8021x, nm_setting_802_1x_get_num_phase2_altsubject_matches), + .add_fcn = MULTILIST_ADD_FCN (NMSetting8021x, nm_setting_802_1x_add_phase2_altsubject_match), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSetting8021x, nm_setting_802_1x_remove_phase2_altsubject_match), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSetting8021x, nm_setting_802_1x_remove_phase2_altsubject_match_by_value), + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_DOMAIN_MATCH, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT, + .describe_message = + N_("Enter file path to client certificate for inner authentication (optionally prefixed\n" + "with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/jara-zweite-phase.crt\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_RAW, + .is_secret = TRUE, + .describe_message = + N_("Enter bytes as a list of hexadecimal values.\n" + "Two formats are accepted:\n" + "(a) a string of hexadecimal digits, where each two digits represent one byte\n" + "(b) space-separated list of bytes written as hexadecimal digits " + "(with optional 0x/0X prefix, and optional leading 0).\n\n" + "Examples: ab0455a6ea3a74C2\n" + " ab 4 55 0xa6 ea 3a 74 C2\n"), + .property_type = &_pt_gobject_bytes, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_bytes, + .legacy_format = TRUE, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_RAW_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY, + .describe_message = + N_("Enter path to a private key and the key password (if not set yet):\n" + " [file://]<file path> [<password>]\n" + "Note that nmcli does not support specifying private key as raw blob data.\n" + "Example: /home/cimrman/jara-priv-key Dardanely\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, + .describe_message = + N_("Enter path to a private key and the key password (if not set yet):\n" + " [file://]<file path> [<password>]\n" + "Note that nmcli does not support specifying private key as raw blob data.\n" + "Example: /home/cimrman/jara-priv-key Dardanely\n"), + .property_type = &_pt_cert_8021x, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (cert_8021x, + .scheme_type = NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PIN, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PIN_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_SYSTEM_CA_CERTS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_AUTH_TIMEOUT, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_ADSL static const NMMetaPropertyInfo *const property_infos_ADSL[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_USERNAME, - .is_cli_option = TRUE, - .property_alias = "username", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("Username"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PASSWORD, - .is_cli_option = TRUE, - .property_alias = "password", - .prompt = N_("Password [none]"), - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PROTOCOL, - .is_cli_option = TRUE, - .property_alias = "protocol", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_ADSL_PROTO, - .def_hint = NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_ADSL_PROTOCOL_PPPOA, - NM_SETTING_ADSL_PROTOCOL_PPPOE, - NM_SETTING_ADSL_PROTOCOL_IPOATM), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_ENCAPSULATION, - .is_cli_option = TRUE, - .property_alias = "encapsulation", - .prompt = NM_META_TEXT_PROMPT_ADSL_ENCAP, - .def_hint = NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_ADSL_ENCAPSULATION_VCMUX, - NM_SETTING_ADSL_ENCAPSULATION_LLC), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_VPI, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_VCI, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_USERNAME, + .is_cli_option = TRUE, + .property_alias = "username", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("Username"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PASSWORD, + .is_cli_option = TRUE, + .property_alias = "password", + .prompt = N_("Password [none]"), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_PROTOCOL, + .is_cli_option = TRUE, + .property_alias = "protocol", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_ADSL_PROTO, + .def_hint = NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_ADSL_PROTOCOL_PPPOA, + NM_SETTING_ADSL_PROTOCOL_PPPOE, + NM_SETTING_ADSL_PROTOCOL_IPOATM), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_ENCAPSULATION, + .is_cli_option = TRUE, + .property_alias = "encapsulation", + .prompt = NM_META_TEXT_PROMPT_ADSL_ENCAP, + .def_hint = NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_ADSL_ENCAPSULATION_VCMUX, + NM_SETTING_ADSL_ENCAPSULATION_LLC), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_VPI, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_VCI, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BLUETOOTH static const NMMetaPropertyInfo *const property_infos_BLUETOOTH[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_BDADDR, - .is_cli_option = TRUE, - .property_alias = "addr", - .prompt = N_("Bluetooth device address"), - .property_type = &_pt_gobject_mac, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_TYPE, - .is_cli_option = TRUE, - .property_alias = "bt-type", - .prompt = NM_META_TEXT_PROMPT_BT_TYPE, - .def_hint = NM_META_TEXT_PROMPT_BT_TYPE_CHOICES, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_BLUETOOTH_TYPE_DUN, - NM_SETTING_BLUETOOTH_TYPE_PANU, - NM_SETTING_BLUETOOTH_TYPE_NAP), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_BDADDR, + .is_cli_option = TRUE, + .property_alias = "addr", + .prompt = N_("Bluetooth device address"), + .property_type = &_pt_gobject_mac, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_TYPE, + .is_cli_option = TRUE, + .property_alias = "bt-type", + .prompt = NM_META_TEXT_PROMPT_BT_TYPE, + .def_hint = NM_META_TEXT_PROMPT_BT_TYPE_CHOICES, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_BLUETOOTH_TYPE_DUN, + NM_SETTING_BLUETOOTH_TYPE_PANU, + NM_SETTING_BLUETOOTH_TYPE_NAP), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BOND static const NMMetaPropertyInfo property_info_BOND_OPTIONS = - PROPERTY_INFO_INIT (NM_SETTING_BOND_OPTIONS, DESCRIBE_DOC_NM_SETTING_BOND_OPTIONS, - .property_type = DEFINE_PROPERTY_TYPE ( - .describe_fcn = _describe_fcn_bond_options, - .get_fcn = _get_fcn_bond_options, - .set_fcn = _set_fcn_optionlist, - .set_supports_remove = TRUE, - .values_fcn = _values_fcn_bond_options, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (optionlist, - .set_fcn = _nm_meta_setting_bond_add_option, - ), - .nested = &nm_meta_property_typ_data_bond, - ), - ); + PROPERTY_INFO_INIT (NM_SETTING_BOND_OPTIONS, DESCRIBE_DOC_NM_SETTING_BOND_OPTIONS, + .property_type = DEFINE_PROPERTY_TYPE ( + .describe_fcn = _describe_fcn_bond_options, + .get_fcn = _get_fcn_bond_options, + .set_fcn = _set_fcn_optionlist, + .set_supports_remove = TRUE, + .values_fcn = _values_fcn_bond_options, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (optionlist, + .set_fcn = _nm_meta_setting_bond_add_option, + ), + .nested = &nm_meta_property_typ_data_bond, + ), + ); static const NMMetaPropertyInfo *const property_infos_BOND[] = { - &property_info_BOND_OPTIONS, - NULL + &property_info_BOND_OPTIONS, + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - .property_type = &_pt_gobject_mac, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_STP, - .is_cli_option = TRUE, - .property_alias = "stp", - .prompt = N_("Enable STP [no]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PRIORITY, - .is_cli_option = TRUE, - .property_alias = "priority", - .prompt = N_("STP priority [32768]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_FORWARD_DELAY, - .is_cli_option = TRUE, - .property_alias = "forward-delay", - .prompt = N_("Forward delay [15]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_HELLO_TIME, - .is_cli_option = TRUE, - .property_alias = "hello-time", - .prompt = N_("Hello time [2]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAX_AGE, - .is_cli_option = TRUE, - .property_alias = "max-age", - .prompt = N_("Max age [20]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_AGEING_TIME, - .is_cli_option = TRUE, - .property_alias = "ageing-time", - .prompt = N_("MAC address ageing time [300]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_ADDRESS, - .property_type = &_pt_gobject_mac, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, - .is_cli_option = TRUE, - .property_alias = "group-forward-mask", - .prompt = N_("Group forward mask [0]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_HASH_MAX, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_LAST_MEMBER_COUNT, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERIER, - .property_type = &_pt_gobject_bool, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERIER_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, - .property_type = &_pt_gobject_bool, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_SNOOPING, - .is_cli_option = TRUE, - .property_alias = "multicast-snooping", - .prompt = N_("Enable IGMP snooping [no]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL, - .property_type = &_pt_gobject_int, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_ROUTER, - .property_type = &_pt_gobject_string, - .hide_if_default = TRUE, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("auto", - "disabled", - "enabled"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_FILTERING, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, - .property_type = &_pt_gobject_bool, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_PROTOCOL, - .property_type = &_pt_gobject_string, - .hide_if_default = TRUE, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("802.1Q", - "802.1ad"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLANS, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingBridge, nm_setting_bridge_get_num_vlans), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingBridge, nm_setting_bridge_clear_vlans), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_bridge_vlans, - .set_fcn = _objlist_set_fcn_bridge_vlans, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + .property_type = &_pt_gobject_mac, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_STP, + .is_cli_option = TRUE, + .property_alias = "stp", + .prompt = N_("Enable STP [no]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PRIORITY, + .is_cli_option = TRUE, + .property_alias = "priority", + .prompt = N_("STP priority [32768]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_FORWARD_DELAY, + .is_cli_option = TRUE, + .property_alias = "forward-delay", + .prompt = N_("Forward delay [15]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_HELLO_TIME, + .is_cli_option = TRUE, + .property_alias = "hello-time", + .prompt = N_("Hello time [2]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAX_AGE, + .is_cli_option = TRUE, + .property_alias = "max-age", + .prompt = N_("Max age [20]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_AGEING_TIME, + .is_cli_option = TRUE, + .property_alias = "ageing-time", + .prompt = N_("MAC address ageing time [300]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_ADDRESS, + .property_type = &_pt_gobject_mac, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, + .is_cli_option = TRUE, + .property_alias = "group-forward-mask", + .prompt = N_("Group forward mask [0]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_HASH_MAX, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_LAST_MEMBER_COUNT, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERIER, + .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERIER_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, + .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_SNOOPING, + .is_cli_option = TRUE, + .property_alias = "multicast-snooping", + .prompt = N_("Enable IGMP snooping [no]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL, + .property_type = &_pt_gobject_int, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MULTICAST_ROUTER, + .property_type = &_pt_gobject_string, + .hide_if_default = TRUE, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("auto", + "disabled", + "enabled"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_FILTERING, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, + .property_type = &_pt_gobject_bool, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_PROTOCOL, + .property_type = &_pt_gobject_string, + .hide_if_default = TRUE, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("802.1Q", + "802.1ad"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLANS, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingBridge, nm_setting_bridge_get_num_vlans), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingBridge, nm_setting_bridge_clear_vlans), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_bridge_vlans, + .set_fcn = _objlist_set_fcn_bridge_vlans, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE_PORT static const NMMetaPropertyInfo *const property_infos_BRIDGE_PORT[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PRIORITY, - .is_cli_option = TRUE, - .property_alias = "priority", - .prompt = N_("Bridge port priority [32]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PATH_COST, - .is_cli_option = TRUE, - .property_alias = "path-cost", - .prompt = N_("Bridge port STP path cost [100]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, - .is_cli_option = TRUE, - .property_alias = "hairpin", - .prompt = N_("Hairpin [no]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_VLANS, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingBridgePort, nm_setting_bridge_port_get_num_vlans), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingBridgePort, nm_setting_bridge_port_clear_vlans), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_bridge_vlans, - .set_fcn = _objlist_set_fcn_bridge_vlans, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PRIORITY, + .is_cli_option = TRUE, + .property_alias = "priority", + .prompt = N_("Bridge port priority [32]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PATH_COST, + .is_cli_option = TRUE, + .property_alias = "path-cost", + .prompt = N_("Bridge port STP path cost [100]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, + .is_cli_option = TRUE, + .property_alias = "hairpin", + .prompt = N_("Hairpin [no]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_VLANS, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingBridgePort, nm_setting_bridge_port_get_num_vlans), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingBridgePort, nm_setting_bridge_port_clear_vlans), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_bridge_vlans, + .set_fcn = _objlist_set_fcn_bridge_vlans, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CDMA static const NMMetaPropertyInfo *const property_infos_CDMA[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_NUMBER, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_USERNAME, - .is_cli_option = TRUE, - .property_alias = "user", - .prompt = N_("Username [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_PASSWORD, - .is_cli_option = TRUE, - .property_alias = "password", - .prompt = N_("Password [none]"), - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_MTU, - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingCdma, nm_setting_cdma_get_mtu), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_NUMBER, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_USERNAME, + .is_cli_option = TRUE, + .property_alias = "user", + .prompt = N_("Username [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_PASSWORD, + .is_cli_option = TRUE, + .property_alias = "password", + .prompt = N_("Password [none]"), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_MTU, + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingCdma, nm_setting_cdma_get_mtu), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CONNECTION static const NMMetaPropertyInfo *const property_infos_CONNECTION[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ID, - .is_cli_option = TRUE, - .property_alias = "con-name", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_UUID, - .property_type = DEFINE_PROPERTY_TYPE ( .get_fcn = _get_fcn_gobject ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_STABLE_ID, - .property_type = &_pt_gobject_string, - ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ID, + .is_cli_option = TRUE, + .property_alias = "con-name", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_UUID, + .property_type = DEFINE_PROPERTY_TYPE ( .get_fcn = _get_fcn_gobject ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_STABLE_ID, + .property_type = &_pt_gobject_string, + ), [_NM_META_PROPERTY_TYPE_CONNECTION_TYPE] = - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TYPE, - .is_cli_option = TRUE, - .property_alias = "type", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_CON_TYPE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_connection_type, - .complete_fcn = _complete_fcn_connection_type, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_INTERFACE_NAME, - .is_cli_option = TRUE, - .property_alias = "ifname", - .prompt = NM_META_TEXT_PROMPT_IFNAME, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_ifname, - .complete_fcn = _complete_fcn_gobject_devices, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT, - .is_cli_option = TRUE, - .property_alias = "autoconnect", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "default", - }, - { - .value.i64 = 0, - .nick = "forever", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MULTI_CONNECT, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_connection_multi_connect_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTH_RETRIES, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TIMESTAMP, - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_READ_ONLY, - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_PERMISSIONS, - .describe_message = - N_("Enter a list of user permissions. This is a list of user names formatted as:\n" - " [user:]<user name 1>, [user:]<user name 2>,...\n" - "The items can be separated by commas or spaces.\n\n" - "Example: alice bob charlie\n"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_connection_permissions, - .set_fcn = _set_fcn_multilist, - .set_supports_remove = TRUE, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingConnection, nm_setting_connection_get_num_permissions), - .add_fcn = _multilist_set_fcn_connection_permissions, - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingConnection, nm_setting_connection_remove_permission), - .remove_by_value_fcn = _multilist_remove_by_value_fcn_connection_permissions, - .validate2_fcn = _multilist_validate2_fcn_connection_permissions, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ZONE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MASTER, - .is_cli_option = TRUE, - .property_alias = "master", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .prompt = NM_META_TEXT_PROMPT_MASTER, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_string, - .complete_fcn = _complete_fcn_connection_master, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_SLAVE_TYPE, - .is_cli_option = TRUE, - .property_alias = "slave-type", - .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_BOND_SETTING_NAME, - NM_SETTING_BRIDGE_SETTING_NAME, - NM_SETTING_OVS_BRIDGE_SETTING_NAME, - NM_SETTING_OVS_PORT_SETTING_NAME, - NM_SETTING_TEAM_SETTING_NAME, - NM_SETTING_VRF_SETTING_NAME), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, - .property_type = &_pt_gobject_enum, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_SECONDARIES, - .describe_message = - N_("Enter secondary connections that should be activated when this connection is\n" - "activated. Connections can be specified either by UUID or ID (name). nmcli\n" - "transparently translates names to UUIDs. Note that NetworkManager only supports\n" - "VPNs as secondary connections at the moment.\n" - "The items can be separated by commas or spaces.\n\n" - "Example: private-openvpn, fe6ba5d8-c2fc-4aae-b2e3-97efddd8d9a7\n"), - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingConnection, nm_setting_connection_get_num_secondaries), - .add_fcn = MULTILIST_ADD_FCN (NMSettingConnection, nm_setting_connection_add_secondary), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingConnection, nm_setting_connection_remove_secondary), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingConnection, nm_setting_connection_remove_secondary_by_value), - .validate2_fcn = _multilist_validate2_fcn_uuid, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_METERED, - .describe_message = - N_("Enter a value which indicates whether the connection is subject to a data\n" - "quota, usage costs or other limitations. Accepted options are:\n" - "'true','yes','on' to set the connection as metered\n" - "'false','no','off' to set the connection as not metered\n" - "'unknown' to let NetworkManager choose a value using some heuristics\n"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_connection_metered, - .set_fcn = _set_fcn_connection_metered, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("yes", "no", "unknown"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_LLDP, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_connection_lldp_get_type, - .value_infos = ENUM_VALUE_INFOS ( - { - .value = NM_SETTING_CONNECTION_LLDP_ENABLE_RX, - .nick = "enable", - }, - ), - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MDNS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_connection_mdns_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_LLMNR, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_connection_llmnr_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MUD_URL, - .property_type = &_pt_gobject_string, - .hide_if_default = TRUE, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TYPE, + .is_cli_option = TRUE, + .property_alias = "type", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_CON_TYPE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_connection_type, + .complete_fcn = _complete_fcn_connection_type, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_INTERFACE_NAME, + .is_cli_option = TRUE, + .property_alias = "ifname", + .prompt = NM_META_TEXT_PROMPT_IFNAME, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_ifname, + .complete_fcn = _complete_fcn_gobject_devices, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT, + .is_cli_option = TRUE, + .property_alias = "autoconnect", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "default", + }, + { + .value.i64 = 0, + .nick = "forever", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MULTI_CONNECT, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_connection_multi_connect_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTH_RETRIES, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TIMESTAMP, + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_READ_ONLY, + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_PERMISSIONS, + .describe_message = + N_("Enter a list of user permissions. This is a list of user names formatted as:\n" + " [user:]<user name 1>, [user:]<user name 2>,...\n" + "The items can be separated by commas or spaces.\n\n" + "Example: alice bob charlie\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_permissions, + .set_fcn = _set_fcn_multilist, + .set_supports_remove = TRUE, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingConnection, nm_setting_connection_get_num_permissions), + .add_fcn = _multilist_set_fcn_connection_permissions, + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingConnection, nm_setting_connection_remove_permission), + .remove_by_value_fcn = _multilist_remove_by_value_fcn_connection_permissions, + .validate2_fcn = _multilist_validate2_fcn_connection_permissions, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ZONE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MASTER, + .is_cli_option = TRUE, + .property_alias = "master", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .prompt = NM_META_TEXT_PROMPT_MASTER, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_string, + .complete_fcn = _complete_fcn_connection_master, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_SLAVE_TYPE, + .is_cli_option = TRUE, + .property_alias = "slave-type", + .inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_BOND_SETTING_NAME, + NM_SETTING_BRIDGE_SETTING_NAME, + NM_SETTING_OVS_BRIDGE_SETTING_NAME, + NM_SETTING_OVS_PORT_SETTING_NAME, + NM_SETTING_TEAM_SETTING_NAME, + NM_SETTING_VRF_SETTING_NAME), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, + .property_type = &_pt_gobject_enum, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_SECONDARIES, + .describe_message = + N_("Enter secondary connections that should be activated when this connection is\n" + "activated. Connections can be specified either by UUID or ID (name). nmcli\n" + "transparently translates names to UUIDs. Note that NetworkManager only supports\n" + "VPNs as secondary connections at the moment.\n" + "The items can be separated by commas or spaces.\n\n" + "Example: private-openvpn, fe6ba5d8-c2fc-4aae-b2e3-97efddd8d9a7\n"), + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingConnection, nm_setting_connection_get_num_secondaries), + .add_fcn = MULTILIST_ADD_FCN (NMSettingConnection, nm_setting_connection_add_secondary), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingConnection, nm_setting_connection_remove_secondary), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingConnection, nm_setting_connection_remove_secondary_by_value), + .validate2_fcn = _multilist_validate2_fcn_uuid, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_METERED, + .describe_message = + N_("Enter a value which indicates whether the connection is subject to a data\n" + "quota, usage costs or other limitations. Accepted options are:\n" + "'true','yes','on' to set the connection as metered\n" + "'false','no','off' to set the connection as not metered\n" + "'unknown' to let NetworkManager choose a value using some heuristics\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_metered, + .set_fcn = _set_fcn_connection_metered, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("yes", "no", "unknown"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_LLDP, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_lldp_get_type, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_CONNECTION_LLDP_ENABLE_RX, + .nick = "enable", + }, + ), + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MDNS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_mdns_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_LLMNR, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_llmnr_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MUD_URL, + .property_type = &_pt_gobject_string, + .hide_if_default = TRUE, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_DCB static const NMMetaPropertyInfo *const property_infos_DCB[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_FLAGS, - .property_type = &_pt_dcb_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_PRIORITY, - DEFINE_DCB_PROPRITY_PROPERTY_TYPE - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_MODE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_DCB_FCOE_MODE_FABRIC, - NM_SETTING_DCB_FCOE_MODE_VN2VN), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_ISCSI_FLAGS, - .property_type = &_pt_dcb_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_ISCSI_PRIORITY, - DEFINE_DCB_PROPRITY_PROPERTY_TYPE - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FIP_FLAGS, - .property_type = &_pt_dcb_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FIP_PRIORITY, - DEFINE_DCB_PROPRITY_PROPERTY_TYPE - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, - .property_type = &_pt_dcb_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, - .property_type = &_pt_dcb_bool, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb_bool, - .get_fcn = nm_setting_dcb_get_priority_flow_control, - .set_fcn = nm_setting_dcb_set_priority_flow_control, - .with_flow_control_flags = TRUE, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, - .property_type = &_pt_dcb_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_ID, - .property_type = &_pt_dcb, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, - .get_fcn = nm_setting_dcb_get_priority_group_id, - .set_fcn = nm_setting_dcb_set_priority_group_id, - .max = 7, - .other = 15, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, - .property_type = &_pt_dcb, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, - .get_fcn = nm_setting_dcb_get_priority_group_bandwidth, - .set_fcn = nm_setting_dcb_set_priority_group_bandwidth, - .max = 100, - .other = 0, - .is_percent = TRUE, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_BANDWIDTH, - .property_type = &_pt_dcb, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, - .get_fcn = nm_setting_dcb_get_priority_bandwidth, - .set_fcn = nm_setting_dcb_set_priority_bandwidth, - .max = 100, - .other = 0, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, - .property_type = &_pt_dcb_bool, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb_bool, - .get_fcn = nm_setting_dcb_get_priority_strict_bandwidth, - .set_fcn = nm_setting_dcb_set_priority_strict_bandwidth, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, - .property_type = &_pt_dcb, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, - .get_fcn = nm_setting_dcb_get_priority_traffic_class, - .set_fcn = nm_setting_dcb_set_priority_traffic_class, - .max = 7, - .other = 0, - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_FLAGS, + .property_type = &_pt_dcb_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_PRIORITY, + DEFINE_DCB_PROPRITY_PROPERTY_TYPE + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_MODE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_DCB_FCOE_MODE_FABRIC, + NM_SETTING_DCB_FCOE_MODE_VN2VN), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_ISCSI_FLAGS, + .property_type = &_pt_dcb_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_ISCSI_PRIORITY, + DEFINE_DCB_PROPRITY_PROPERTY_TYPE + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FIP_FLAGS, + .property_type = &_pt_dcb_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FIP_PRIORITY, + DEFINE_DCB_PROPRITY_PROPERTY_TYPE + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, + .property_type = &_pt_dcb_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, + .property_type = &_pt_dcb_bool, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb_bool, + .get_fcn = nm_setting_dcb_get_priority_flow_control, + .set_fcn = nm_setting_dcb_set_priority_flow_control, + .with_flow_control_flags = TRUE, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, + .property_type = &_pt_dcb_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_ID, + .property_type = &_pt_dcb, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, + .get_fcn = nm_setting_dcb_get_priority_group_id, + .set_fcn = nm_setting_dcb_set_priority_group_id, + .max = 7, + .other = 15, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, + .property_type = &_pt_dcb, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, + .get_fcn = nm_setting_dcb_get_priority_group_bandwidth, + .set_fcn = nm_setting_dcb_set_priority_group_bandwidth, + .max = 100, + .other = 0, + .is_percent = TRUE, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_BANDWIDTH, + .property_type = &_pt_dcb, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, + .get_fcn = nm_setting_dcb_get_priority_bandwidth, + .set_fcn = nm_setting_dcb_set_priority_bandwidth, + .max = 100, + .other = 0, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, + .property_type = &_pt_dcb_bool, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb_bool, + .get_fcn = nm_setting_dcb_get_priority_strict_bandwidth, + .set_fcn = nm_setting_dcb_set_priority_strict_bandwidth, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, + .property_type = &_pt_dcb, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (dcb, + .get_fcn = nm_setting_dcb_get_priority_traffic_class, + .set_fcn = nm_setting_dcb_set_priority_traffic_class, + .max = 7, + .other = 0, + ), + ), + NULL }; #define PROPERTY_INFO_ETHTOOL(xname) \ - PROPERTY_INFO (NM_ETHTOOL_OPTNAME_##xname, NULL, \ - .property_type = &_pt_ethtool, \ - .hide_if_default = TRUE, \ - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (ethtool, \ - .ethtool_id = NM_ETHTOOL_ID_##xname, \ - ), \ - ) + PROPERTY_INFO (NM_ETHTOOL_OPTNAME_##xname, NULL, \ + .property_type = &_pt_ethtool, \ + .hide_if_default = TRUE, \ + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (ethtool, \ + .ethtool_id = NM_ETHTOOL_ID_##xname, \ + ), \ + ) #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_ETHTOOL static const NMMetaPropertyInfo *const property_infos_ETHTOOL[] = { - PROPERTY_INFO_ETHTOOL (FEATURE_ESP_HW_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_ESP_TX_CSUM_HW_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_FCOE_MTU), - PROPERTY_INFO_ETHTOOL (FEATURE_GRO), - PROPERTY_INFO_ETHTOOL (FEATURE_GSO), - PROPERTY_INFO_ETHTOOL (FEATURE_HIGHDMA), - PROPERTY_INFO_ETHTOOL (FEATURE_HW_TC_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_L2_FWD_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_LOOPBACK), - PROPERTY_INFO_ETHTOOL (FEATURE_LRO), - PROPERTY_INFO_ETHTOOL (FEATURE_NTUPLE), - PROPERTY_INFO_ETHTOOL (FEATURE_RX), - PROPERTY_INFO_ETHTOOL (FEATURE_RXHASH), - PROPERTY_INFO_ETHTOOL (FEATURE_RXVLAN), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_ALL), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_FCS), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_GRO_HW), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_UDP_TUNNEL_PORT_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_FILTER), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_STAG_FILTER), - PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_STAG_HW_PARSE), - PROPERTY_INFO_ETHTOOL (FEATURE_SG), - PROPERTY_INFO_ETHTOOL (FEATURE_TLS_HW_RECORD), - PROPERTY_INFO_ETHTOOL (FEATURE_TLS_HW_TX_OFFLOAD), - PROPERTY_INFO_ETHTOOL (FEATURE_TSO), - PROPERTY_INFO_ETHTOOL (FEATURE_TX), - PROPERTY_INFO_ETHTOOL (FEATURE_TXVLAN), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_FCOE_CRC), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IPV4), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IPV6), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IP_GENERIC), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_SCTP), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_ESP_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_FCOE_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_GRE_CSUM_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_GRE_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_GSO_PARTIAL), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_GSO_ROBUST), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_IPXIP4_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_IPXIP6_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_NOCACHE_COPY), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCATTER_GATHER), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCATTER_GATHER_FRAGLIST), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCTP_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP6_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_ECN_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_MANGLEID_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_TNL_CSUM_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_TNL_SEGMENTATION), - PROPERTY_INFO_ETHTOOL (FEATURE_TX_VLAN_STAG_HW_INSERT), - PROPERTY_INFO_ETHTOOL (COALESCE_ADAPTIVE_RX), - PROPERTY_INFO_ETHTOOL (COALESCE_ADAPTIVE_TX), - PROPERTY_INFO_ETHTOOL (COALESCE_PKT_RATE_HIGH), - PROPERTY_INFO_ETHTOOL (COALESCE_PKT_RATE_LOW), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_IRQ), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_HIGH), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_LOW), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_IRQ), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_HIGH), - PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_LOW), - PROPERTY_INFO_ETHTOOL (COALESCE_SAMPLE_INTERVAL), - PROPERTY_INFO_ETHTOOL (COALESCE_STATS_BLOCK_USECS), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_IRQ), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_HIGH), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_LOW), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_IRQ), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_HIGH), - PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_LOW), - PROPERTY_INFO_ETHTOOL (RING_RX), - PROPERTY_INFO_ETHTOOL (RING_RX_JUMBO), - PROPERTY_INFO_ETHTOOL (RING_RX_MINI), - PROPERTY_INFO_ETHTOOL (RING_TX), - NULL, + PROPERTY_INFO_ETHTOOL (FEATURE_ESP_HW_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_ESP_TX_CSUM_HW_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_FCOE_MTU), + PROPERTY_INFO_ETHTOOL (FEATURE_GRO), + PROPERTY_INFO_ETHTOOL (FEATURE_GSO), + PROPERTY_INFO_ETHTOOL (FEATURE_HIGHDMA), + PROPERTY_INFO_ETHTOOL (FEATURE_HW_TC_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_L2_FWD_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_LOOPBACK), + PROPERTY_INFO_ETHTOOL (FEATURE_LRO), + PROPERTY_INFO_ETHTOOL (FEATURE_NTUPLE), + PROPERTY_INFO_ETHTOOL (FEATURE_RX), + PROPERTY_INFO_ETHTOOL (FEATURE_RXHASH), + PROPERTY_INFO_ETHTOOL (FEATURE_RXVLAN), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_ALL), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_FCS), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_GRO_HW), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_UDP_TUNNEL_PORT_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_FILTER), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_STAG_FILTER), + PROPERTY_INFO_ETHTOOL (FEATURE_RX_VLAN_STAG_HW_PARSE), + PROPERTY_INFO_ETHTOOL (FEATURE_SG), + PROPERTY_INFO_ETHTOOL (FEATURE_TLS_HW_RECORD), + PROPERTY_INFO_ETHTOOL (FEATURE_TLS_HW_TX_OFFLOAD), + PROPERTY_INFO_ETHTOOL (FEATURE_TSO), + PROPERTY_INFO_ETHTOOL (FEATURE_TX), + PROPERTY_INFO_ETHTOOL (FEATURE_TXVLAN), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_FCOE_CRC), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IPV4), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IPV6), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_IP_GENERIC), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_CHECKSUM_SCTP), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_ESP_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_FCOE_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_GRE_CSUM_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_GRE_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_GSO_PARTIAL), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_GSO_ROBUST), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_IPXIP4_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_IPXIP6_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_NOCACHE_COPY), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCATTER_GATHER), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCATTER_GATHER_FRAGLIST), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_SCTP_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP6_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_ECN_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_MANGLEID_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_TCP_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_TNL_CSUM_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_UDP_TNL_SEGMENTATION), + PROPERTY_INFO_ETHTOOL (FEATURE_TX_VLAN_STAG_HW_INSERT), + PROPERTY_INFO_ETHTOOL (COALESCE_ADAPTIVE_RX), + PROPERTY_INFO_ETHTOOL (COALESCE_ADAPTIVE_TX), + PROPERTY_INFO_ETHTOOL (COALESCE_PKT_RATE_HIGH), + PROPERTY_INFO_ETHTOOL (COALESCE_PKT_RATE_LOW), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_IRQ), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_HIGH), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_FRAMES_LOW), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_IRQ), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_HIGH), + PROPERTY_INFO_ETHTOOL (COALESCE_RX_USECS_LOW), + PROPERTY_INFO_ETHTOOL (COALESCE_SAMPLE_INTERVAL), + PROPERTY_INFO_ETHTOOL (COALESCE_STATS_BLOCK_USECS), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_IRQ), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_HIGH), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_FRAMES_LOW), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_IRQ), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_HIGH), + PROPERTY_INFO_ETHTOOL (COALESCE_TX_USECS_LOW), + PROPERTY_INFO_ETHTOOL (RING_RX), + PROPERTY_INFO_ETHTOOL (RING_RX_JUMBO), + PROPERTY_INFO_ETHTOOL (RING_RX_MINI), + PROPERTY_INFO_ETHTOOL (RING_TX), + NULL, }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_GSM static const NMMetaPropertyInfo *const property_infos_GSM[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_AUTO_CONFIG, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NUMBER, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_USERNAME, - .is_cli_option = TRUE, - .property_alias = "user", - .prompt = N_("Username [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PASSWORD, - .is_cli_option = TRUE, - .property_alias = "password", - .prompt = N_("Password [none]"), - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_APN, - .is_cli_option = TRUE, - .property_alias = "apn", - .prompt = N_("APN"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NETWORK_ID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PIN, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PIN_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_HOME_ONLY, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_DEVICE_ID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_SIM_ID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_SIM_OPERATOR_ID, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gsm_sim_operator_id, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_MTU, - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingGsm, nm_setting_gsm_get_mtu), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_AUTO_CONFIG, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NUMBER, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_USERNAME, + .is_cli_option = TRUE, + .property_alias = "user", + .prompt = N_("Username [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PASSWORD, + .is_cli_option = TRUE, + .property_alias = "password", + .prompt = N_("Password [none]"), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_APN, + .is_cli_option = TRUE, + .property_alias = "apn", + .prompt = N_("APN"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NETWORK_ID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PIN, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_PIN_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_HOME_ONLY, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_DEVICE_ID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_SIM_ID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_SIM_OPERATOR_ID, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gsm_sim_operator_id, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_MTU, + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingGsm, nm_setting_gsm_get_mtu), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_INFINIBAND static const NMMetaPropertyInfo *const property_infos_INFINIBAND[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - .property_type = &_pt_gobject_mac, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, - .mode = NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MTU, - .is_cli_option = TRUE, - .property_alias = "mtu", - .prompt = N_("MTU [auto]"), - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingInfiniband, nm_setting_infiniband_get_mtu), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_TRANSPORT_MODE, - .is_cli_option = TRUE, - .property_alias = "transport-mode", - .prompt = NM_META_TEXT_PROMPT_IB_MODE, - .def_hint = NM_META_TEXT_PROMPT_IB_MODE_CHOICES, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("datagram", "connected"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_P_KEY, - .is_cli_option = TRUE, - .property_alias = "p-key", - .prompt = N_("P_KEY [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_infiniband_p_key, - .set_fcn = _set_fcn_infiniband_p_key, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_PARENT, - .is_cli_option = TRUE, - .property_alias = "parent", - .prompt = N_("Parent interface [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_gobject_ifname, - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MTU, + .is_cli_option = TRUE, + .property_alias = "mtu", + .prompt = N_("MTU [auto]"), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingInfiniband, nm_setting_infiniband_get_mtu), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_TRANSPORT_MODE, + .is_cli_option = TRUE, + .property_alias = "transport-mode", + .prompt = NM_META_TEXT_PROMPT_IB_MODE, + .def_hint = NM_META_TEXT_PROMPT_IB_MODE_CHOICES, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("datagram", "connected"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_P_KEY, + .is_cli_option = TRUE, + .property_alias = "p-key", + .prompt = N_("P_KEY [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_infiniband_p_key, + .set_fcn = _set_fcn_infiniband_p_key, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_PARENT, + .is_cli_option = TRUE, + .property_alias = "parent", + .prompt = N_("Parent interface [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_ifname, + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP4_CONFIG static const NMMetaPropertyInfo *const property_infos_IP4_CONFIG[] = { - PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_ip_config_method, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_METHOD_SHARED, - NM_SETTING_IP4_CONFIG_METHOD_DISABLED), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS, - .describe_message = - N_("Enter a list of IPv4 addresses of DNS servers.\n\n" - "Example: 8.8.8.8, 8.8.4.4\n"), - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns), - .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns), - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_by_value), - .validate2_fcn = _multilist_validate2_fcn_ip_config_dns, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_SEARCH, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_searches), - .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns_search), - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search_by_value), - .validate_fcn = _multilist_validate_fcn_is_domain, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_OPTIONS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_options), - .add_fcn = _multilist_add_fcn_ip_config_dns_options, - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option_by_value), - .clear_emptyunset_fcn = MULTILIST_CLEAR_EMPTYUNSET_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_dns_options), - .strsplit_plain = TRUE, - ), - .is_default_fcn = _is_default_func_ip_config_dns_options, - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ADDRESSES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES, - .is_cli_option = TRUE, - .property_alias = "ip4", - .inf_flags = NM_META_PROPERTY_INF_FLAG_MULTI, - .prompt = N_("IPv4 address (IP[/plen]) [none]"), - .describe_message = - N_("Enter a list of IPv4 addresses formatted as:\n" - " ip[/prefix], ip[/prefix],...\n" - "Missing prefix is regarded as prefix of 32.\n\n" - "Example: 192.168.1.5/24, 10.0.0.11/24\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_addresses), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_addresses), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_addresses, - .set_fcn = _objlist_set_fcn_ip_config_addresses, - .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_address), - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_GATEWAY, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY, - .is_cli_option = TRUE, - .property_alias = "gw4", - .prompt = N_("IPv4 gateway [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_ip_config_gateway, - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES, - .describe_message = - N_("Enter a list of IPv4 routes formatted as:\n" - " ip[/prefix] [next-hop] [metric],...\n\n" - "Missing prefix is regarded as a prefix of 32.\n" - "Missing next-hop is regarded as 0.0.0.0.\n" - "Missing metric means default (NM/kernel will set a default value).\n\n" - "Examples: 192.168.2.0/24 192.168.2.1 3, 10.1.0.0/16 10.0.0.254\n" - " 10.1.2.0/24\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routes), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routes), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routes, - .set_fcn = _objlist_set_fcn_ip_config_routes, - .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_route), - .delimit_pretty_with_semicolon = TRUE, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_METRIC, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_METRIC, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_TABLE, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_TABLE, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = 0, - .nick = "unspec", - }, - { - .value.i64 = 254, - .nick = "main", - }, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTING_RULES, NULL, - .describe_message = - N_("Enter a list of IPv4 routing rules formatted as:\n" - " priority [prio] [from [src]] [to [dst]], ,...\n" - "\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routing_rules), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routing_rules), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routing_rules, - .set_fcn = _objlist_set_fcn_ip_config_routing_rules, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingIPConfig, nm_setting_ip_config_remove_routing_rule), - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT, - .property_type = &_pt_gobject_int, - .property_typ_data = &_ptd_gobject_int_timeout, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_FQDN, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_dhcp_hostname_flags_get_type, - ), - ) - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_MAY_FAIL, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DAD_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "default", - }, - { - .value.i64 = 0, - .nick = "off", - }, - ), - ), - ), - NULL + PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip_config_method, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP4_CONFIG_METHOD_SHARED, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS, + .describe_message = + N_("Enter a list of IPv4 addresses of DNS servers.\n\n" + "Example: 8.8.8.8, 8.8.4.4\n"), + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns), + .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns), + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_by_value), + .validate2_fcn = _multilist_validate2_fcn_ip_config_dns, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_SEARCH, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_searches), + .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns_search), + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search_by_value), + .validate_fcn = _multilist_validate_fcn_is_domain, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_OPTIONS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_options), + .add_fcn = _multilist_add_fcn_ip_config_dns_options, + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option_by_value), + .clear_emptyunset_fcn = MULTILIST_CLEAR_EMPTYUNSET_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_dns_options), + .strsplit_plain = TRUE, + ), + .is_default_fcn = _is_default_func_ip_config_dns_options, + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ADDRESSES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES, + .is_cli_option = TRUE, + .property_alias = "ip4", + .inf_flags = NM_META_PROPERTY_INF_FLAG_MULTI, + .prompt = N_("IPv4 address (IP[/plen]) [none]"), + .describe_message = + N_("Enter a list of IPv4 addresses formatted as:\n" + " ip[/prefix], ip[/prefix],...\n" + "Missing prefix is regarded as prefix of 32.\n\n" + "Example: 192.168.1.5/24, 10.0.0.11/24\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_addresses), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_addresses), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_addresses, + .set_fcn = _objlist_set_fcn_ip_config_addresses, + .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_address), + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_GATEWAY, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY, + .is_cli_option = TRUE, + .property_alias = "gw4", + .prompt = N_("IPv4 gateway [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip_config_gateway, + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES, + .describe_message = + N_("Enter a list of IPv4 routes formatted as:\n" + " ip[/prefix] [next-hop] [metric],...\n\n" + "Missing prefix is regarded as a prefix of 32.\n" + "Missing next-hop is regarded as 0.0.0.0.\n" + "Missing metric means default (NM/kernel will set a default value).\n\n" + "Examples: 192.168.2.0/24 192.168.2.1 3, 10.1.0.0/16 10.0.0.254\n" + " 10.1.2.0/24\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routes), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routes), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routes, + .set_fcn = _objlist_set_fcn_ip_config_routes, + .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_route), + .delimit_pretty_with_semicolon = TRUE, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_METRIC, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_METRIC, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_TABLE, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_TABLE, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = 0, + .nick = "unspec", + }, + { + .value.i64 = 254, + .nick = "main", + }, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTING_RULES, NULL, + .describe_message = + N_("Enter a list of IPv4 routing rules formatted as:\n" + " priority [prio] [from [src]] [to [dst]], ,...\n" + "\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routing_rules), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routing_rules), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routing_rules, + .set_fcn = _objlist_set_fcn_ip_config_routing_rules, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingIPConfig, nm_setting_ip_config_remove_routing_rule), + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT, + .property_type = &_pt_gobject_int, + .property_typ_data = &_ptd_gobject_int_timeout, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_FQDN, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_dhcp_hostname_flags_get_type, + ), + ) + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_MAY_FAIL, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DAD_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "default", + }, + { + .value.i64 = 0, + .nick = "off", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_REJECT_SERVERS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_REJECT_SERVERS, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, _multilist_get_num_fcn_ip_config_dhcp_reject_servers), + .add2_fcn = MULTILIST_ADD2_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dhcp_reject_server), + .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingIPConfig, nm_setting_ip_config_remove_dhcp_reject_server), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, _multilist_remove_by_value_fcn_ip_config_dhcp_reject_servers), + .validate_fcn = _multilist_validate_fcn_is_ipv4_addr_or_subnet, + .strsplit_plain = TRUE, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP6_CONFIG static const NMMetaPropertyInfo *const property_infos_IP6_CONFIG[] = { - PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_METHOD, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_ip_config_method, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_DHCP, - NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP6_CONFIG_METHOD_MANUAL, - NM_SETTING_IP6_CONFIG_METHOD_SHARED, - NM_SETTING_IP6_CONFIG_METHOD_DISABLED), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS, - .describe_message = - N_("Enter a list of IPv6 addresses of DNS servers. If the IPv6 " - "configuration method is 'auto' these DNS servers are appended " - "to those (if any) returned by automatic configuration. DNS " - "servers cannot be used with the 'shared' or 'link-local' IPv6 " - "configuration methods, as there is no upstream network. In " - "all other IPv6 configuration methods, these DNS " - "servers are used as the only DNS servers for this connection.\n\n" - "Example: 2607:f0d0:1002:51::4, 2607:f0d0:1002:51::1\n"), - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns), - .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns), - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_by_value), - .validate2_fcn = _multilist_validate2_fcn_ip_config_dns, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_SEARCH, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_searches), - .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns_search), - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search_by_value), - .validate_fcn = _multilist_validate_fcn_is_domain, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_OPTIONS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_options), - .add_fcn = _multilist_add_fcn_ip_config_dns_options, - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option_by_value), - .clear_emptyunset_fcn = MULTILIST_CLEAR_EMPTYUNSET_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_dns_options), - .strsplit_plain = TRUE, - ), - .is_default_fcn = _is_default_func_ip_config_dns_options, - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ADDRESSES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES, - .is_cli_option = TRUE, - .property_alias = "ip6", - .inf_flags = NM_META_PROPERTY_INF_FLAG_MULTI, - .prompt = N_("IPv6 address (IP[/plen]) [none]"), - .describe_message = - N_("Enter a list of IPv6 addresses formatted as:\n" - " ip[/prefix], ip[/prefix],...\n" - "Missing prefix is regarded as prefix of 128.\n\n" - "Example: 2607:f0d0:1002:51::4/64, 1050:0:0:0:5:600:300c:326b\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_addresses), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_addresses), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_addresses, - .set_fcn = _objlist_set_fcn_ip_config_addresses, - .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_address), - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_GATEWAY, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY, - .is_cli_option = TRUE, - .property_alias = "gw6", - .prompt = N_("IPv6 gateway [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_ip_config_gateway, - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTES, - .describe_message = - N_("Enter a list of IPv6 routes formatted as:\n" - " ip[/prefix] [next-hop] [metric],...\n\n" - "Missing prefix is regarded as a prefix of 128.\n" - "Missing next-hop is regarded as \"::\".\n" - "Missing metric means default (NM/kernel will set a default value).\n\n" - "Examples: 2001:db8:beef:2::/64 2001:db8:beef::2, 2001:db8:beef:3::/64 2001:db8:beef::3 2\n" - " abbe::/64 55\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routes), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routes), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routes, - .set_fcn = _objlist_set_fcn_ip_config_routes, - .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_route), - .delimit_pretty_with_semicolon = TRUE, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_METRIC, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_METRIC, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_TABLE, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_TABLE, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = 0, - .nick = "unspec", - }, - { - .value.i64 = 254, - .nick = "main", - }, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTING_RULES, NULL, - .describe_message = - N_("Enter a list of IPv6 routing rules formatted as:\n" - " priority [prio] [from [src]] [to [dst]], ,...\n" - "\n"), - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routing_rules), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routing_rules), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routing_rules, - .set_fcn = _objlist_set_fcn_ip_config_routing_rules, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingIPConfig, nm_setting_ip_config_remove_routing_rule), - ), - ), - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_MAY_FAIL, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_MAY_FAIL, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .value_infos_get = ENUM_VALUE_INFOS ( - { - .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR, - .nick = "enabled, prefer public IP", - }, - { - .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, - .nick = "enabled, prefer temporary IP", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_ip6_config_addr_gen_mode_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO (NM_SETTING_IP6_CONFIG_RA_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_RA_TIMEOUT, - .property_type = &_pt_gobject_int, - .property_typ_data = &_ptd_gobject_int_timeout, - ), - PROPERTY_INFO (NM_SETTING_IP6_CONFIG_DHCP_DUID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT, - .property_type = &_pt_gobject_int, - .property_typ_data = &_ptd_gobject_int_timeout, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_dhcp_hostname_flags_get_type, - ), - ) - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_TOKEN, - .property_type = &_pt_gobject_string, - ), - NULL + PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_METHOD, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip_config_method, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_DHCP, + NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP6_CONFIG_METHOD_SHARED, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS, + .describe_message = + N_("Enter a list of IPv6 addresses of DNS servers. If the IPv6 " + "configuration method is 'auto' these DNS servers are appended " + "to those (if any) returned by automatic configuration. DNS " + "servers cannot be used with the 'shared' or 'link-local' IPv6 " + "configuration methods, as there is no upstream network. In " + "all other IPv6 configuration methods, these DNS " + "servers are used as the only DNS servers for this connection.\n\n" + "Example: 2607:f0d0:1002:51::4, 2607:f0d0:1002:51::1\n"), + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns), + .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns), + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_by_value), + .validate2_fcn = _multilist_validate2_fcn_ip_config_dns, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_SEARCH, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_searches), + .add_fcn = MULTILIST_ADD_FCN (NMSettingIPConfig, nm_setting_ip_config_add_dns_search), + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_search_by_value), + .validate_fcn = _multilist_validate_fcn_is_domain, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_OPTIONS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingIPConfig, nm_setting_ip_config_get_num_dns_options), + .add_fcn = _multilist_add_fcn_ip_config_dns_options, + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingIPConfig, nm_setting_ip_config_remove_dns_option_by_value), + .clear_emptyunset_fcn = MULTILIST_CLEAR_EMPTYUNSET_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_dns_options), + .strsplit_plain = TRUE, + ), + .is_default_fcn = _is_default_func_ip_config_dns_options, + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ADDRESSES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES, + .is_cli_option = TRUE, + .property_alias = "ip6", + .inf_flags = NM_META_PROPERTY_INF_FLAG_MULTI, + .prompt = N_("IPv6 address (IP[/plen]) [none]"), + .describe_message = + N_("Enter a list of IPv6 addresses formatted as:\n" + " ip[/prefix], ip[/prefix],...\n" + "Missing prefix is regarded as prefix of 128.\n\n" + "Example: 2607:f0d0:1002:51::4/64, 1050:0:0:0:5:600:300c:326b\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_addresses), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_addresses), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_addresses, + .set_fcn = _objlist_set_fcn_ip_config_addresses, + .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_address), + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_GATEWAY, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY, + .is_cli_option = TRUE, + .property_alias = "gw6", + .prompt = N_("IPv6 gateway [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip_config_gateway, + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTES, + .describe_message = + N_("Enter a list of IPv6 routes formatted as:\n" + " ip[/prefix] [next-hop] [metric],...\n\n" + "Missing prefix is regarded as a prefix of 128.\n" + "Missing next-hop is regarded as \"::\".\n" + "Missing metric means default (NM/kernel will set a default value).\n\n" + "Examples: 2001:db8:beef:2::/64 2001:db8:beef::2, 2001:db8:beef:3::/64 2001:db8:beef::3 2\n" + " abbe::/64 55\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routes), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routes), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routes, + .set_fcn = _objlist_set_fcn_ip_config_routes, + .remove_by_idx_fcn_s = OBJLIST_REMOVE_BY_IDX_FCN_S (NMSettingIPConfig, nm_setting_ip_config_remove_route), + .delimit_pretty_with_semicolon = TRUE, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_METRIC, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_METRIC, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTE_TABLE, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_TABLE, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = 0, + .nick = "unspec", + }, + { + .value.i64 = 254, + .nick = "main", + }, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_ROUTING_RULES, NULL, + .describe_message = + N_("Enter a list of IPv6 routing rules formatted as:\n" + " priority [prio] [from [src]] [to [dst]], ,...\n" + "\n"), + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingIPConfig, nm_setting_ip_config_get_num_routing_rules), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingIPConfig, nm_setting_ip_config_clear_routing_rules), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_ip_config_routing_rules, + .set_fcn = _objlist_set_fcn_ip_config_routing_rules, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingIPConfig, nm_setting_ip_config_remove_routing_rule), + ), + ), + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_MAY_FAIL, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_MAY_FAIL, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .value_infos_get = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR, + .nick = "enabled, prefer public IP", + }, + { + .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + .nick = "enabled, prefer temporary IP", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_ip6_config_addr_gen_mode_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO (NM_SETTING_IP6_CONFIG_RA_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_RA_TIMEOUT, + .property_type = &_pt_gobject_int, + .property_typ_data = &_ptd_gobject_int_timeout, + ), + PROPERTY_INFO (NM_SETTING_IP6_CONFIG_DHCP_DUID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT, + .property_type = &_pt_gobject_int, + .property_typ_data = &_ptd_gobject_int_timeout, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_dhcp_hostname_flags_get_type, + ), + ) + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_TOKEN, + .property_type = &_pt_gobject_string, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP_TUNNEL static const NMMetaPropertyInfo *const property_infos_IP_TUNNEL[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MODE, - .is_cli_option = TRUE, - .property_alias = "mode", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_IP_TUNNEL_MODE, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_ip_tunnel_mode_get_type, - .min = NM_IP_TUNNEL_MODE_UNKNOWN + 1, - .max = G_MAXINT, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .prompt = N_("Parent device [none]"), - .property_type = &_pt_gobject_devices, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_LOCAL, - .is_cli_option = TRUE, - .property_alias = "local", - .prompt = N_("Local endpoint [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_REMOTE, - .is_cli_option = TRUE, - .property_alias = "remote", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("Remote"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_TTL, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_TOS, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_INPUT_KEY, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_OUTPUT_KEY, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_FLOW_LABEL, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MTU, - .property_type = &_pt_gobject_mtu, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_FLAGS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_ip_tunnel_flags_get_type, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MODE, + .is_cli_option = TRUE, + .property_alias = "mode", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_IP_TUNNEL_MODE, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_ip_tunnel_mode_get_type, + .min = NM_IP_TUNNEL_MODE_UNKNOWN + 1, + .max = G_MAXINT, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .prompt = N_("Parent device [none]"), + .property_type = &_pt_gobject_devices, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_LOCAL, + .is_cli_option = TRUE, + .property_alias = "local", + .prompt = N_("Local endpoint [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_REMOTE, + .is_cli_option = TRUE, + .property_alias = "remote", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("Remote"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_TTL, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_TOS, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_INPUT_KEY, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_OUTPUT_KEY, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_FLOW_LABEL, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MTU, + .property_type = &_pt_gobject_mtu, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_FLAGS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_ip_tunnel_flags_get_type, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACSEC static const NMMetaPropertyInfo *const property_infos_MACSEC[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("MACsec parent device or connection UUID"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MODE, - .is_cli_option = TRUE, - .property_alias = "mode", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_MACSEC_MODE, - .def_hint = NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_macsec_mode_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_ENCRYPT, - .is_cli_option = TRUE, - .property_alias = "encrypt", - .prompt = N_("Enable encryption [yes]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CAK, - .is_cli_option = TRUE, - .property_alias = "cak", - .prompt = N_("MKA CAK"), - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CAK_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CKN, - .is_cli_option = TRUE, - .property_alias = "ckn", - .prompt = N_("MKA_CKN"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PORT, - .is_cli_option = TRUE, - .property_alias = "port", - .prompt = N_("SCI port [1]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_VALIDATION, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_macsec_validation_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_SEND_SCI, - .property_type = &_pt_gobject_bool, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("MACsec parent device or connection UUID"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MODE, + .is_cli_option = TRUE, + .property_alias = "mode", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_MACSEC_MODE, + .def_hint = NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macsec_mode_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_ENCRYPT, + .is_cli_option = TRUE, + .property_alias = "encrypt", + .prompt = N_("Enable encryption [yes]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CAK, + .is_cli_option = TRUE, + .property_alias = "cak", + .prompt = N_("MKA CAK"), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CAK_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_MKA_CKN, + .is_cli_option = TRUE, + .property_alias = "ckn", + .prompt = N_("MKA_CKN"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PORT, + .is_cli_option = TRUE, + .property_alias = "port", + .prompt = N_("SCI port [1]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_VALIDATION, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macsec_validation_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_SEND_SCI, + .property_type = &_pt_gobject_bool, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACVLAN static const NMMetaPropertyInfo *const property_infos_MACVLAN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("MACVLAN parent device or connection UUID"), - .property_type = &_pt_gobject_devices, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_MODE, - .is_cli_option = TRUE, - .property_alias = "mode", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_MACVLAN_MODE, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_macvlan_mode_get_type, - .min = NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, - .max = G_MAXINT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PROMISCUOUS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_TAP, - .is_cli_option = TRUE, - .property_alias = "tap", - .prompt = N_("Tap [no]"), - .property_type = &_pt_gobject_bool, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("MACVLAN parent device or connection UUID"), + .property_type = &_pt_gobject_devices, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_MODE, + .is_cli_option = TRUE, + .property_alias = "mode", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_MACVLAN_MODE, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macvlan_mode_get_type, + .min = NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, + .max = G_MAXINT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PROMISCUOUS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_TAP, + .is_cli_option = TRUE, + .property_alias = "tap", + .prompt = N_("Tap [no]"), + .property_type = &_pt_gobject_bool, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MATCH static const NMMetaPropertyInfo *const property_infos_MATCH[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_INTERFACE_NAME, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_interface_names), - .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_interface_name), - .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingMatch, nm_setting_match_remove_interface_name), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_interface_name_by_value), - .strsplit_with_spaces = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_KERNEL_COMMAND_LINE, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_kernel_command_lines), - .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_kernel_command_line), - .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_kernel_command_line), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_kernel_command_line_by_value), - .strsplit_with_spaces = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_DRIVER, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_drivers), - .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_driver), - .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_driver), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_driver_by_value), - .strsplit_with_spaces = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_PATH, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_paths), - .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_path), - .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_path), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_path_by_value), - .strsplit_with_spaces = TRUE, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_INTERFACE_NAME, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_interface_names), + .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_interface_name), + .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingMatch, nm_setting_match_remove_interface_name), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_interface_name_by_value), + .strsplit_with_spaces = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_KERNEL_COMMAND_LINE, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_kernel_command_lines), + .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_kernel_command_line), + .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_kernel_command_line), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_kernel_command_line_by_value), + .strsplit_with_spaces = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_DRIVER, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_drivers), + .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_driver), + .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_driver), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_driver_by_value), + .strsplit_with_spaces = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_PATH, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_paths), + .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_path), + .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingMatch, nm_setting_match_remove_path), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_path_by_value), + .strsplit_with_spaces = TRUE, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OLPC_MESH static const NMMetaPropertyInfo *const property_infos_OLPC_MESH[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_SSID, - .is_cli_option = TRUE, - .property_alias = "ssid", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("SSID"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_olpc_mesh_ssid, - .set_fcn = _set_fcn_gobject_ssid, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_CHANNEL, - .is_cli_option = TRUE, - .property_alias = "channel", - .prompt = N_("OLPC Mesh channel [1]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_olpc_mesh_channel, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "dhcp-anycast", - .prompt = N_("DHCP anycast MAC address [none]"), - .property_type = &_pt_gobject_mac, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_SSID, + .is_cli_option = TRUE, + .property_alias = "ssid", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("SSID"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_olpc_mesh_ssid, + .set_fcn = _set_fcn_gobject_ssid, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_CHANNEL, + .is_cli_option = TRUE, + .property_alias = "channel", + .prompt = N_("OLPC Mesh channel [1]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_olpc_mesh_channel, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "dhcp-anycast", + .prompt = N_("DHCP anycast MAC address [none]"), + .property_type = &_pt_gobject_mac, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OVS_BRIDGE static const NMMetaPropertyInfo *const property_infos_OVS_BRIDGE[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_FAIL_MODE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("secure", "standalone"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_STP_ENABLE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_DATAPATH_TYPE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("system", "netdev"), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_FAIL_MODE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("secure", "standalone"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_STP_ENABLE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_BRIDGE_DATAPATH_TYPE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("system", "netdev"), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OVS_DPDK static const NMMetaPropertyInfo *const property_infos_OVS_DPDK[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_DPDK_DEVARGS, - .property_type = &_pt_gobject_string, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_DPDK_DEVARGS, + .property_type = &_pt_gobject_string, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OVS_INTERFACE static const NMMetaPropertyInfo *const property_infos_OVS_INTERFACE[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_INTERFACE_TYPE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("internal", "system", "patch", "dpdk"), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_INTERFACE_TYPE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("internal", "system", "patch", "dpdk"), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OVS_PATCH static const NMMetaPropertyInfo *const property_infos_OVS_PATCH[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PATCH_PEER, - .property_type = &_pt_gobject_string, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PATCH_PEER, + .property_type = &_pt_gobject_string, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OVS_PORT static const NMMetaPropertyInfo *const property_infos_OVS_PORT[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_VLAN_MODE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("access", "native-tagged", "native-untagged", "trunk"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_TAG, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_LACP, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("active", "off", "passive"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_MODE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("active-backup", "balance-slb", "balance-tcp"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_UPDELAY, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_DOWNDELAY, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_VLAN_MODE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("access", "native-tagged", "native-untagged", "trunk"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_TAG, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_LACP, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("active", "off", "passive"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_MODE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("active-backup", "balance-slb", "balance-tcp"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_UPDELAY, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_PORT_BOND_DOWNDELAY, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPP static const NMMetaPropertyInfo *const property_infos_PPP[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOAUTH, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_EAP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_PAP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_CHAP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_MSCHAP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_MSCHAPV2, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOBSDCOMP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NODEFLATE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NO_VJ_COMP, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REQUIRE_MPPE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REQUIRE_MPPE_128, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MPPE_STATEFUL, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_CRTSCTS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_BAUD, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MRU, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MTU, - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingPpp, nm_setting_ppp_get_mtu), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_LCP_ECHO_FAILURE, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_LCP_ECHO_INTERVAL, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOAUTH, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_EAP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_PAP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_CHAP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_MSCHAP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REFUSE_MSCHAPV2, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOBSDCOMP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NODEFLATE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NO_VJ_COMP, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REQUIRE_MPPE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_REQUIRE_MPPE_128, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MPPE_STATEFUL, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_CRTSCTS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_BAUD, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MRU, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_MTU, + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingPpp, nm_setting_ppp_get_mtu), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_LCP_ECHO_FAILURE, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_LCP_ECHO_INTERVAL, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPPOE static const NMMetaPropertyInfo *const property_infos_PPPOE[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PARENT, - .is_cli_option = TRUE, - .property_alias = "parent", - .prompt = N_("PPPoE parent device"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_SERVICE, - .is_cli_option = TRUE, - .property_alias = "service", - .prompt = N_("Service [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_USERNAME, - .is_cli_option = TRUE, - .property_alias = "username", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("PPPoE username"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PASSWORD, - .is_cli_option = TRUE, - .property_alias = "password", - .prompt = N_("Password [none]"), - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PARENT, + .is_cli_option = TRUE, + .property_alias = "parent", + .prompt = N_("PPPoE parent device"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_SERVICE, + .is_cli_option = TRUE, + .property_alias = "service", + .prompt = N_("Service [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_USERNAME, + .is_cli_option = TRUE, + .property_alias = "username", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("PPPoE username"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PASSWORD, + .is_cli_option = TRUE, + .property_alias = "password", + .prompt = N_("Password [none]"), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PROXY static const NMMetaPropertyInfo *const property_infos_PROXY[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_METHOD, - .is_cli_option = TRUE, - .property_alias = "method", - .prompt = NM_META_TEXT_PROMPT_PROXY_METHOD, - .def_hint = NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_proxy_method_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_BROWSER_ONLY, - .is_cli_option = TRUE, - .property_alias = "browser-only", - .prompt = N_("Browser only [no]"), - .property_type = &_pt_gobject_bool - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_PAC_URL, - .is_cli_option = TRUE, - .property_alias = "pac-url", - .prompt = N_("PAC URL"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_PAC_SCRIPT, - .is_cli_option = TRUE, - .property_alias = "pac-script", - .prompt = N_("PAC script"), - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, - .validate_fcn = _validate_fcn_proxy_pac_script, - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_METHOD, + .is_cli_option = TRUE, + .property_alias = "method", + .prompt = NM_META_TEXT_PROMPT_PROXY_METHOD, + .def_hint = NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_proxy_method_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_BROWSER_ONLY, + .is_cli_option = TRUE, + .property_alias = "browser-only", + .prompt = N_("Browser only [no]"), + .property_type = &_pt_gobject_bool + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_PAC_URL, + .is_cli_option = TRUE, + .property_alias = "pac-url", + .prompt = N_("PAC URL"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_PAC_SCRIPT, + .is_cli_option = TRUE, + .property_alias = "pac-script", + .prompt = N_("PAC script"), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, + .validate_fcn = _validate_fcn_proxy_pac_script, + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_SERIAL static const NMMetaPropertyInfo *const property_infos_SERIAL[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BAUD, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BITS, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_PARITY, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .value_infos = ENUM_VALUE_INFOS ( - { - .value = NM_SETTING_SERIAL_PARITY_EVEN, - .nick = "E", - }, - { - .value = NM_SETTING_SERIAL_PARITY_EVEN, - .nick = "e", - }, - { - .value = NM_SETTING_SERIAL_PARITY_ODD, - .nick = "O", - }, - { - .value = NM_SETTING_SERIAL_PARITY_ODD, - .nick = "o", - }, - { - .value = NM_SETTING_SERIAL_PARITY_NONE, - .nick = "N", - }, - { - .value = NM_SETTING_SERIAL_PARITY_NONE, - .nick = "n", - }, - ), - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_STOPBITS, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_SEND_DELAY, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BAUD, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BITS, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_PARITY, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_SERIAL_PARITY_EVEN, + .nick = "E", + }, + { + .value = NM_SETTING_SERIAL_PARITY_EVEN, + .nick = "e", + }, + { + .value = NM_SETTING_SERIAL_PARITY_ODD, + .nick = "O", + }, + { + .value = NM_SETTING_SERIAL_PARITY_ODD, + .nick = "o", + }, + { + .value = NM_SETTING_SERIAL_PARITY_NONE, + .nick = "N", + }, + { + .value = NM_SETTING_SERIAL_PARITY_NONE, + .nick = "n", + }, + ), + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_STOPBITS, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_SEND_DELAY, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_SRIOV static const NMMetaPropertyInfo *const property_infos_SRIOV[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_TOTAL_VFS, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_VFS, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingSriov, nm_setting_sriov_get_num_vfs), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingSriov, nm_setting_sriov_clear_vfs), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_sriov_vfs, - .set_fcn = _objlist_set_fcn_sriov_vfs, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, - .property_type = &_pt_gobject_enum, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_TOTAL_VFS, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_VFS, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingSriov, nm_setting_sriov_get_num_vfs), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingSriov, nm_setting_sriov_clear_vfs), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_sriov_vfs, + .set_fcn = _objlist_set_fcn_sriov_vfs, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, + .property_type = &_pt_gobject_enum, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TC_CONFIG static const NMMetaPropertyInfo *const property_infos_TC_CONFIG[] = { - PROPERTY_INFO (NM_SETTING_TC_CONFIG_QDISCS, DESCRIBE_DOC_NM_SETTING_TC_CONFIG_QDISCS, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTCConfig, nm_setting_tc_config_get_num_qdiscs), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingTCConfig, nm_setting_tc_config_clear_qdiscs), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_tc_config_qdiscs, - .set_fcn = _objlist_set_fcn_tc_config_qdiscs, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTCConfig, nm_setting_tc_config_remove_qdisc), - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO (NM_SETTING_TC_CONFIG_TFILTERS, DESCRIBE_DOC_NM_SETTING_TC_CONFIG_TFILTERS, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTCConfig, nm_setting_tc_config_get_num_tfilters), - .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingTCConfig, nm_setting_tc_config_clear_tfilters), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_tc_config_tfilters, - .set_fcn = _objlist_set_fcn_tc_config_tfilters, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTCConfig, nm_setting_tc_config_remove_tfilter), - .strsplit_plain = TRUE, - ), - ), - ), - NULL + PROPERTY_INFO (NM_SETTING_TC_CONFIG_QDISCS, DESCRIBE_DOC_NM_SETTING_TC_CONFIG_QDISCS, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTCConfig, nm_setting_tc_config_get_num_qdiscs), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingTCConfig, nm_setting_tc_config_clear_qdiscs), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_tc_config_qdiscs, + .set_fcn = _objlist_set_fcn_tc_config_qdiscs, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTCConfig, nm_setting_tc_config_remove_qdisc), + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO (NM_SETTING_TC_CONFIG_TFILTERS, DESCRIBE_DOC_NM_SETTING_TC_CONFIG_TFILTERS, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTCConfig, nm_setting_tc_config_get_num_tfilters), + .clear_all_fcn = OBJLIST_CLEAR_ALL_FCN (NMSettingTCConfig, nm_setting_tc_config_clear_tfilters), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_tc_config_tfilters, + .set_fcn = _objlist_set_fcn_tc_config_tfilters, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTCConfig, nm_setting_tc_config_remove_tfilter), + .strsplit_plain = TRUE, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM static const NMMetaPropertyInfo *const property_infos_TEAM[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_CONFIG, - .is_cli_option = TRUE, - .property_alias = "config", - .prompt = N_("Team JSON configuration [none]"), - .describe_message = TEAM_DESCRIBE_MESSAGE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, - .validate_fcn = _validate_fcn_team_config, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_NOTIFY_PEERS_COUNT, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "disabled", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_NOTIFY_PEERS_INTERVAL, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_MCAST_REJOIN_COUNT, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "disabled", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_MCAST_REJOIN_INTERVAL, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_BROADCAST, - NM_SETTING_TEAM_RUNNER_ROUNDROBIN, - NM_SETTING_TEAM_RUNNER_RANDOM, - NM_SETTING_TEAM_RUNNER_ACTIVEBACKUP, - NM_SETTING_TEAM_RUNNER_LOADBALANCE, - NM_SETTING_TEAM_RUNNER_LACP), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_HWADDR_POLICY, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_SAME_ALL, - NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_BY_ACTIVE, - NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_ONLY_ACTIVE), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_HASH, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingTeam, nm_setting_team_get_num_runner_tx_hash), - .add_fcn = MULTILIST_ADD_FCN (NMSettingTeam, nm_setting_team_add_runner_tx_hash), - .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingTeam, nm_setting_team_remove_runner_tx_hash), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingTeam, nm_setting_team_remove_runner_tx_hash_by_value), - .strsplit_plain = TRUE, - ), - .values_static = NM_MAKE_STRV ("eth", "vlan", "ipv4", "ipv6", "ip", - "l3", "tcp", "udp", "sctp", "l4"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_BALANCER, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("basic"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_ACTIVE, - .property_type = & _pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_FAST_RATE, - .property_type = & _pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_SYS_PRIO, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = NM_SETTING_TEAM_RUNNER_SYS_PRIO_DEFAULT, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_MIN_PORTS, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 1, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_LACP_PRIO, - NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_LACP_PRIO_STABLE, - NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_BANDWIDTH, - NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_COUNT, - NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_PORT_CONFIG), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_LINK_WATCHERS, - .describe_message = TEAM_LINK_WATCHERS_DESCRIBE_MESSAGE, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTeam, nm_setting_team_get_num_link_watchers), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_team_link_watchers, - .set_fcn = _objlist_set_fcn_team_link_watchers, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTeam, nm_setting_team_remove_link_watcher), - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_CONFIG, + .is_cli_option = TRUE, + .property_alias = "config", + .prompt = N_("Team JSON configuration [none]"), + .describe_message = TEAM_DESCRIBE_MESSAGE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, + .validate_fcn = _validate_fcn_team_config, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_NOTIFY_PEERS_COUNT, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "disabled", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_NOTIFY_PEERS_INTERVAL, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_MCAST_REJOIN_COUNT, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "disabled", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_MCAST_REJOIN_INTERVAL, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_BROADCAST, + NM_SETTING_TEAM_RUNNER_ROUNDROBIN, + NM_SETTING_TEAM_RUNNER_RANDOM, + NM_SETTING_TEAM_RUNNER_ACTIVEBACKUP, + NM_SETTING_TEAM_RUNNER_LOADBALANCE, + NM_SETTING_TEAM_RUNNER_LACP), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_HWADDR_POLICY, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_SAME_ALL, + NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_BY_ACTIVE, + NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_ONLY_ACTIVE), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_HASH, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingTeam, nm_setting_team_get_num_runner_tx_hash), + .add_fcn = MULTILIST_ADD_FCN (NMSettingTeam, nm_setting_team_add_runner_tx_hash), + .remove_by_idx_fcn_u = MULTILIST_REMOVE_BY_IDX_FCN_U (NMSettingTeam, nm_setting_team_remove_runner_tx_hash), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingTeam, nm_setting_team_remove_runner_tx_hash_by_value), + .strsplit_plain = TRUE, + ), + .values_static = NM_MAKE_STRV ("eth", "vlan", "ipv4", "ipv6", "ip", + "l3", "tcp", "udp", "sctp", "l4"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_BALANCER, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("basic"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_ACTIVE, + .property_type = & _pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_FAST_RATE, + .property_type = & _pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_SYS_PRIO, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = NM_SETTING_TEAM_RUNNER_SYS_PRIO_DEFAULT, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_MIN_PORTS, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 1, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_LACP_PRIO, + NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_LACP_PRIO_STABLE, + NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_BANDWIDTH, + NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_COUNT, + NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_PORT_CONFIG), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_LINK_WATCHERS, + .describe_message = TEAM_LINK_WATCHERS_DESCRIBE_MESSAGE, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTeam, nm_setting_team_get_num_link_watchers), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_team_link_watchers, + .set_fcn = _objlist_set_fcn_team_link_watchers, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTeam, nm_setting_team_remove_link_watcher), + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM_PORT static const NMMetaPropertyInfo *const property_infos_TEAM_PORT[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_CONFIG, - .is_cli_option = TRUE, - .property_alias = "config", - .prompt = N_("Team JSON configuration [none]"), - .describe_message = TEAM_DESCRIBE_MESSAGE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, - .validate_fcn = _validate_fcn_team_config, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_QUEUE_ID, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_PRIO, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = 0, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_STICKY, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LACP_PRIO, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = NM_SETTING_TEAM_PORT_LACP_PRIO_DEFAULT, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LACP_KEY, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = -1, - .nick = "unset", - }, - { - .value.i64 = 0, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LINK_WATCHERS, - .describe_message = TEAM_LINK_WATCHERS_DESCRIBE_MESSAGE, - .property_type = &_pt_objlist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (objlist, - .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTeamPort, nm_setting_team_port_get_num_link_watchers), - .obj_to_str_fcn = _objlist_obj_to_str_fcn_team_link_watchers, - .set_fcn = _objlist_set_fcn_team_link_watchers, - .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTeamPort, nm_setting_team_port_remove_link_watcher), - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_CONFIG, + .is_cli_option = TRUE, + .property_alias = "config", + .prompt = N_("Team JSON configuration [none]"), + .describe_message = TEAM_DESCRIBE_MESSAGE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, + .validate_fcn = _validate_fcn_team_config, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_QUEUE_ID, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_PRIO, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = 0, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_STICKY, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LACP_PRIO, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = NM_SETTING_TEAM_PORT_LACP_PRIO_DEFAULT, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LACP_KEY, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = -1, + .nick = "unset", + }, + { + .value.i64 = 0, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_LINK_WATCHERS, + .describe_message = TEAM_LINK_WATCHERS_DESCRIBE_MESSAGE, + .property_type = &_pt_objlist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (objlist, + .get_num_fcn = OBJLIST_GET_NUM_FCN (NMSettingTeamPort, nm_setting_team_port_get_num_link_watchers), + .obj_to_str_fcn = _objlist_obj_to_str_fcn_team_link_watchers, + .set_fcn = _objlist_set_fcn_team_link_watchers, + .remove_by_idx_fcn_u = OBJLIST_REMOVE_BY_IDX_FCN_U (NMSettingTeamPort, nm_setting_team_port_remove_link_watcher), + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TUN static const NMMetaPropertyInfo *const property_infos_TUN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MODE, - .is_cli_option = TRUE, - .property_alias = "mode", - .prompt = NM_META_TEXT_PROMPT_TUN_MODE, - .def_hint = NM_META_TEXT_PROMPT_TUN_MODE_CHOICES, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_tun_mode_get_type, - .min = NM_SETTING_TUN_MODE_UNKNOWN + 1, - .max = G_MAXINT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_OWNER, - .is_cli_option = TRUE, - .property_alias = "owner", - .prompt = N_("User ID [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_GROUP, - .is_cli_option = TRUE, - .property_alias = "group", - .prompt = N_("Group ID [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_PI, - .is_cli_option = TRUE, - .property_alias = "pi", - .prompt = N_("Enable PI [no]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_VNET_HDR, - .is_cli_option = TRUE, - .property_alias = "vnet-hdr", - .prompt = N_("Enable VNET header [no]"), - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MULTI_QUEUE, - .is_cli_option = TRUE, - .property_alias = "multi-queue", - .prompt = N_("Enable multi queue [no]"), - .property_type = &_pt_gobject_bool, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MODE, + .is_cli_option = TRUE, + .property_alias = "mode", + .prompt = NM_META_TEXT_PROMPT_TUN_MODE, + .def_hint = NM_META_TEXT_PROMPT_TUN_MODE_CHOICES, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_tun_mode_get_type, + .min = NM_SETTING_TUN_MODE_UNKNOWN + 1, + .max = G_MAXINT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_OWNER, + .is_cli_option = TRUE, + .property_alias = "owner", + .prompt = N_("User ID [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_GROUP, + .is_cli_option = TRUE, + .property_alias = "group", + .prompt = N_("Group ID [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_PI, + .is_cli_option = TRUE, + .property_alias = "pi", + .prompt = N_("Enable PI [no]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_VNET_HDR, + .is_cli_option = TRUE, + .property_alias = "vnet-hdr", + .prompt = N_("Enable VNET header [no]"), + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MULTI_QUEUE, + .is_cli_option = TRUE, + .property_alias = "multi-queue", + .prompt = N_("Enable multi queue [no]"), + .property_type = &_pt_gobject_bool, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VLAN static const NMMetaPropertyInfo *const property_infos_VLAN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("VLAN parent device or connection UUID"), - .property_type = &_pt_gobject_devices, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_ID, - .is_cli_option = TRUE, - .property_alias = "id", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("VLAN ID (<0-4094>)"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_FLAGS, - .is_cli_option = TRUE, - .property_alias = "flags", - .prompt = N_("VLAN flags (<0-7>) [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_vlan_flags, - .set_fcn = _set_fcn_gobject_flags, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, - .is_cli_option = TRUE, - .property_alias = "ingress", - .prompt = N_("Ingress priority maps [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_vlan_xgress_priority_map, - .set_fcn = _set_fcn_vlan_xgress_priority_map, - .set_supports_remove = TRUE, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, - .is_cli_option = TRUE, - .property_alias = "egress", - .prompt = N_("Egress priority maps [none]"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_vlan_xgress_priority_map, - .set_fcn = _set_fcn_vlan_xgress_priority_map, - .set_supports_remove = TRUE, - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("VLAN parent device or connection UUID"), + .property_type = &_pt_gobject_devices, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_ID, + .is_cli_option = TRUE, + .property_alias = "id", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("VLAN ID (<0-4094>)"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_FLAGS, + .is_cli_option = TRUE, + .property_alias = "flags", + .prompt = N_("VLAN flags (<0-7>) [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_flags, + .set_fcn = _set_fcn_gobject_flags, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, + .is_cli_option = TRUE, + .property_alias = "ingress", + .prompt = N_("Ingress priority maps [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_xgress_priority_map, + .set_fcn = _set_fcn_vlan_xgress_priority_map, + .set_supports_remove = TRUE, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, + .is_cli_option = TRUE, + .property_alias = "egress", + .prompt = N_("Egress priority maps [none]"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_xgress_priority_map, + .set_fcn = _set_fcn_vlan_xgress_priority_map, + .set_supports_remove = TRUE, + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VPN static const NMMetaPropertyInfo *const property_infos_VPN[] = { [_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE] = - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SERVICE_TYPE, - .is_cli_option = TRUE, - .property_alias = "vpn-type", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_VPN_TYPE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_vpn_service_type, - .complete_fcn = _complete_fcn_vpn_service_type, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_USER_NAME, - .is_cli_option = TRUE, - .property_alias = "user", - .prompt = N_("Username [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_DATA, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_vpn_options, - .set_fcn = _set_fcn_optionlist, - .set_supports_remove = TRUE, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, - .set_fcn = _optionlist_set_fcn_vpn_data, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SECRETS, - .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_vpn_options, - .set_fcn = _set_fcn_optionlist, - .set_supports_remove = TRUE, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, - .set_fcn = _optionlist_set_fcn_vpn_secrets, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_PERSISTENT, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_TIMEOUT, - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SERVICE_TYPE, + .is_cli_option = TRUE, + .property_alias = "vpn-type", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_VPN_TYPE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_vpn_service_type, + .complete_fcn = _complete_fcn_vpn_service_type, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_USER_NAME, + .is_cli_option = TRUE, + .property_alias = "user", + .prompt = N_("Username [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_DATA, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vpn_options, + .set_fcn = _set_fcn_optionlist, + .set_supports_remove = TRUE, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, + .set_fcn = _optionlist_set_fcn_vpn_data, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SECRETS, + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vpn_options, + .set_fcn = _set_fcn_optionlist, + .set_supports_remove = TRUE, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, + .set_fcn = _optionlist_set_fcn_vpn_secrets, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_PERSISTENT, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_TIMEOUT, + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VRF static const NMMetaPropertyInfo *const property_infos_VRF[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_VRF_TABLE, - .is_cli_option = TRUE, - .property_alias = "table", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("Table [0]"), - .property_type = &_pt_gobject_int, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_VRF_TABLE, + .is_cli_option = TRUE, + .property_alias = "table", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("Table [0]"), + .property_type = &_pt_gobject_int, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VXLAN static const NMMetaPropertyInfo *const property_infos_VXLAN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PARENT, - .is_cli_option = TRUE, - .property_alias = "dev", - .prompt = N_("Parent device [none]"), - .property_type = &_pt_gobject_devices, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_ID, - .is_cli_option = TRUE, - .property_alias = "id", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("VXLAN ID"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LOCAL, - .is_cli_option = TRUE, - .property_alias = "local", - .prompt = N_("Local address [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_REMOTE, - .is_cli_option = TRUE, - .property_alias = "remote", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("Remote"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_SOURCE_PORT_MIN, - .is_cli_option = TRUE, - .property_alias = "source-port-min", - .prompt = N_("Minimum source port [0]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_SOURCE_PORT_MAX, - .is_cli_option = TRUE, - .property_alias = "source-port-max", - .prompt = N_("Maximum source port [0]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_DESTINATION_PORT, - .is_cli_option = TRUE, - .property_alias = "destination-port", - .prompt = N_("Destination port [8472]"), - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_TOS, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_TTL, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_AGEING, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LIMIT, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LEARNING, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PROXY, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_RSC, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_L2_MISS, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_L3_MISS, - .property_type = &_pt_gobject_bool, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PARENT, + .is_cli_option = TRUE, + .property_alias = "dev", + .prompt = N_("Parent device [none]"), + .property_type = &_pt_gobject_devices, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_ID, + .is_cli_option = TRUE, + .property_alias = "id", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("VXLAN ID"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LOCAL, + .is_cli_option = TRUE, + .property_alias = "local", + .prompt = N_("Local address [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_REMOTE, + .is_cli_option = TRUE, + .property_alias = "remote", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("Remote"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_SOURCE_PORT_MIN, + .is_cli_option = TRUE, + .property_alias = "source-port-min", + .prompt = N_("Minimum source port [0]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_SOURCE_PORT_MAX, + .is_cli_option = TRUE, + .property_alias = "source-port-max", + .prompt = N_("Maximum source port [0]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_DESTINATION_PORT, + .is_cli_option = TRUE, + .property_alias = "destination-port", + .prompt = N_("Destination port [8472]"), + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_TOS, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_TTL, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_AGEING, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LIMIT, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_LEARNING, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PROXY, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_RSC, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_L2_MISS, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_L3_MISS, + .property_type = &_pt_gobject_bool, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIFI_P2P static const NMMetaPropertyInfo *const property_infos_WIFI_P2P[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_PEER, - .is_cli_option = TRUE, - .property_alias = "peer", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("Peer"), - .property_type = &_pt_gobject_mac, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_WPS_METHOD, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_security_wps_method_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_WFD_IES, - .property_type = &_pt_gobject_bytes, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_PEER, + .is_cli_option = TRUE, + .property_alias = "peer", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("Peer"), + .property_type = &_pt_gobject_mac, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_WPS_METHOD, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_security_wps_method_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIFI_P2P_WFD_IES, + .property_type = &_pt_gobject_bytes, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIMAX static const NMMetaPropertyInfo *const property_infos_WIMAX[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_NETWORK_NAME, - .is_cli_option = TRUE, - .property_alias = "nsp", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("WiMAX NSP name"), - .property_type = &_pt_gobject_mac, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_NETWORK_NAME, + .is_cli_option = TRUE, + .property_alias = "nsp", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("WiMAX NSP name"), + .property_type = &_pt_gobject_mac, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRED static const NMMetaPropertyInfo *const property_infos_WIRED[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_PORT, - /* Do not allow setting 'port' for now. It is not implemented in - * NM core, nor in ifcfg-rh plugin. Enable this when it gets done. - * wired_valid_ports[] = { "tp", "aui", "bnc", "mii", NULL }; - */ - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_SPEED, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_DUPLEX, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("half", "full"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_AUTO_NEGOTIATE, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - .property_type = &_pt_gobject_mac, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_CLONED_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "cloned-mac", - .prompt = N_("Cloned MAC [none]"), - .property_type = &_pt_gobject_mac, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, - .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWired, nm_setting_wired_get_num_mac_blacklist_items), - .add_fcn = MULTILIST_ADD_FCN (NMSettingWired, nm_setting_wired_add_mac_blacklist_item), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWired, nm_setting_wired_remove_mac_blacklist_item), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWired, nm_setting_wired_remove_mac_blacklist_item_by_value), - .validate2_fcn = _multilist_validate2_fcn_mac_addr, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MTU, - .is_cli_option = TRUE, - .property_alias = "mtu", - .prompt = N_("MTU [auto]"), - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingWired, nm_setting_wired_get_mtu), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_SUBCHANNELS, - .describe_message = - N_("Enter a list of subchannels (comma or space separated).\n\n" - "Example: 0.0.0e20 0.0.0e21 0.0.0e22\n"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_wired_s390_subchannels, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_NETTYPE, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("qeth", "lcs", "ctc"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_OPTIONS, - .property_type = DEFINE_PROPERTY_TYPE ( - .describe_fcn = _describe_fcn_wired_s390_options, - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_optionlist, - .set_supports_remove = TRUE, - .values_fcn = _values_fcn_wired_s390_options, - ), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, - .set_fcn = _optionlist_set_fcn_wired_s390_options, - .no_empty_value = TRUE, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_WAKE_ON_LAN, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wired_wake_on_lan_get_type, - .value_infos = ENUM_VALUE_INFOS ( - { - .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, - .nick = "none", - }, - { - .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, - .nick = "disable", - }, - { - .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, - .nick = "disabled", - }, - ), - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, - .property_type = &_pt_gobject_mac, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_PORT, + /* Do not allow setting 'port' for now. It is not implemented in + * NM core, nor in ifcfg-rh plugin. Enable this when it gets done. + * wired_valid_ports[] = { "tp", "aui", "bnc", "mii", NULL }; + */ + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_SPEED, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_DUPLEX, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("half", "full"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_AUTO_NEGOTIATE, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + .property_type = &_pt_gobject_mac, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_CLONED_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "cloned-mac", + .prompt = N_("Cloned MAC [none]"), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWired, nm_setting_wired_get_num_mac_blacklist_items), + .add_fcn = MULTILIST_ADD_FCN (NMSettingWired, nm_setting_wired_add_mac_blacklist_item), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWired, nm_setting_wired_remove_mac_blacklist_item), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWired, nm_setting_wired_remove_mac_blacklist_item_by_value), + .validate2_fcn = _multilist_validate2_fcn_mac_addr, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_MTU, + .is_cli_option = TRUE, + .property_alias = "mtu", + .prompt = N_("MTU [auto]"), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingWired, nm_setting_wired_get_mtu), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_SUBCHANNELS, + .describe_message = + N_("Enter a list of subchannels (comma or space separated).\n\n" + "Example: 0.0.0e20 0.0.0e21 0.0.0e22\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wired_s390_subchannels, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_NETTYPE, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("qeth", "lcs", "ctc"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_S390_OPTIONS, + .property_type = DEFINE_PROPERTY_TYPE ( + .describe_fcn = _describe_fcn_wired_s390_options, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_optionlist, + .set_supports_remove = TRUE, + .values_fcn = _values_fcn_wired_s390_options, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (optionlist, + .set_fcn = _optionlist_set_fcn_wired_s390_options, + .no_empty_value = TRUE, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_WAKE_ON_LAN, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wired_wake_on_lan_get_type, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, + .nick = "none", + }, + { + .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, + .nick = "disable", + }, + { + .value = NM_SETTING_WIRED_WAKE_ON_LAN_NONE, + .nick = "disabled", + }, + ), + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, + .property_type = &_pt_gobject_mac, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIREGUARD static const NMMetaPropertyInfo *const property_infos_WIREGUARD[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PRIVATE_KEY, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_LISTEN_PORT, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_FWMARK, - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ - .base = 16, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PEER_ROUTES, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_MTU, - .property_type = &_pt_gobject_mtu, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE, - .property_type = &_pt_gobject_enum, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE, - .property_type = &_pt_gobject_enum, - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PRIVATE_KEY, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_LISTEN_PORT, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_FWMARK, + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ + .base = 16, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PEER_ROUTES, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_MTU, + .property_type = &_pt_gobject_mtu, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE, + .property_type = &_pt_gobject_enum, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE, + .property_type = &_pt_gobject_enum, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS static const NMMetaPropertyInfo *const property_infos_WIRELESS[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SSID, - .is_cli_option = TRUE, - .property_alias = "ssid", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = N_("SSID"), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_ssid, - .set_fcn = _set_fcn_gobject_ssid, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MODE, - .is_cli_option = TRUE, - .property_alias = "mode", - .prompt = NM_META_TEXT_PROMPT_WIFI_MODE, - .def_hint = NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV (NM_SETTING_WIRELESS_MODE_INFRA, - NM_SETTING_WIRELESS_MODE_ADHOC, - NM_SETTING_WIRELESS_MODE_AP, - NM_SETTING_WIRELESS_MODE_MESH), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_BAND, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("a", "bg"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_CHANNEL, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_wireless_channel, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_BSSID, - .property_type = &_pt_gobject_mac, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_RATE, - /* Do not allow setting 'rate'. It is not implemented in NM core. */ - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_TX_POWER, - /* Do not allow setting 'tx-power'. It is not implemented in NM core. */ - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS, - .property_type = &_pt_gobject_mac, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "cloned-mac", - .prompt = N_("Cloned MAC [none]"), - .property_type = &_pt_gobject_mac, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, - .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWireless, nm_setting_wireless_get_num_mac_blacklist_items), - .add_fcn = MULTILIST_ADD_FCN (NMSettingWireless, nm_setting_wireless_add_mac_blacklist_item), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWireless, nm_setting_wireless_remove_mac_blacklist_item), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWireless, nm_setting_wireless_remove_mac_blacklist_item_by_value), - .validate2_fcn = _multilist_validate2_fcn_mac_addr, - .strsplit_plain = TRUE, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_mac_randomization_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MTU, - .is_cli_option = TRUE, - .property_alias = "mtu", - .prompt = N_("MTU [auto]"), - .property_type = &_pt_gobject_mtu, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, - .get_fcn = MTU_GET_FCN (NMSettingWireless, nm_setting_wireless_get_mtu), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SEEN_BSSIDS, - .property_type = &_pt_gobject_readonly, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_HIDDEN, - .property_type = &_pt_gobject_bool, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_POWERSAVE, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_powersave_get_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_WAKE_ON_WLAN, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_wake_on_wlan_get_type, - .value_infos = ENUM_VALUE_INFOS ( - { - .value = NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE, - .nick = "disabled", - }, - ), - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SSID, + .is_cli_option = TRUE, + .property_alias = "ssid", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = N_("SSID"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_ssid, + .set_fcn = _set_fcn_gobject_ssid, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MODE, + .is_cli_option = TRUE, + .property_alias = "mode", + .prompt = NM_META_TEXT_PROMPT_WIFI_MODE, + .def_hint = NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV (NM_SETTING_WIRELESS_MODE_INFRA, + NM_SETTING_WIRELESS_MODE_ADHOC, + NM_SETTING_WIRELESS_MODE_AP, + NM_SETTING_WIRELESS_MODE_MESH), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_BAND, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("a", "bg"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_CHANNEL, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_channel, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_BSSID, + .property_type = &_pt_gobject_mac, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_RATE, + /* Do not allow setting 'rate'. It is not implemented in NM core. */ + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_TX_POWER, + /* Do not allow setting 'tx-power'. It is not implemented in NM core. */ + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS, + .property_type = &_pt_gobject_mac, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "cloned-mac", + .prompt = N_("Cloned MAC [none]"), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWireless, nm_setting_wireless_get_num_mac_blacklist_items), + .add_fcn = MULTILIST_ADD_FCN (NMSettingWireless, nm_setting_wireless_add_mac_blacklist_item), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWireless, nm_setting_wireless_remove_mac_blacklist_item), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWireless, nm_setting_wireless_remove_mac_blacklist_item_by_value), + .validate2_fcn = _multilist_validate2_fcn_mac_addr, + .strsplit_plain = TRUE, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_mac_randomization_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_MTU, + .is_cli_option = TRUE, + .property_alias = "mtu", + .prompt = N_("MTU [auto]"), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingWireless, nm_setting_wireless_get_mtu), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SEEN_BSSIDS, + .property_type = &_pt_gobject_readonly, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_HIDDEN, + .property_type = &_pt_gobject_bool, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_POWERSAVE, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_powersave_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_WAKE_ON_WLAN, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_wake_on_wlan_get_type, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE, + .nick = "disabled", + }, + ), + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_AP_ISOLATION, + .property_type = &_pt_gobject_enum, + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS_SECURITY static const NMMetaPropertyInfo *const property_infos_WIRELESS_SECURITY[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("none", "ieee8021x", "wpa-psk", "wpa-eap", "sae", "owe"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, - .property_type = &_pt_gobject_int, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, - .property_type = &_pt_gobject_string, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = NM_MAKE_STRV ("open", "shared", "leap"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PROTO, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_protos), - .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_proto), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_proto), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_proto_by_value), - .strsplit_plain = TRUE, - ), - .values_static = NM_MAKE_STRV ("wpa", "rsn"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PAIRWISE, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_pairwise), - .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_pairwise), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_pairwise), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_pairwise_by_value), - .strsplit_plain = TRUE, - ), - .values_static = NM_MAKE_STRV ("tkip", "ccmp"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_GROUP, - .property_type = &_pt_multilist, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (multilist, - .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_groups), - .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_group), - .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_group), - .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_group_by_value), - .strsplit_plain = TRUE, - ), - .values_static = NM_MAKE_STRV ("wep40", "wep104", "tkip", "ccmp"), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PMF, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_security_pmf_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, - .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key, - .set_fcn = _set_fcn_wireless_wep_key, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, - .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key, - .set_fcn = _set_fcn_wireless_wep_key, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, - .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key, - .set_fcn = _set_fcn_wireless_wep_key, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, - .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key, - .set_fcn = _set_fcn_wireless_wep_key, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, - .describe_message = - N_("Enter the type of WEP keys. The accepted values are: " - "0 or unknown, 1 or key, and 2 or passphrase.\n"), - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .pre_set_notify = _gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type, - ), - .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT - | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, - .is_secret = TRUE, - .property_type = &_pt_gobject_string, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, - .property_type = &_pt_gobject_secret_flags, - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WPS_METHOD, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_security_wps_method_get_type, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_FILS, - .property_type = &_pt_gobject_enum, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, - .get_gtype = nm_setting_wireless_security_fils_get_type, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("none", "ieee8021x", "wpa-psk", "wpa-eap", "sae", "owe"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + .property_type = &_pt_gobject_int, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("open", "shared", "leap"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PROTO, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_protos), + .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_proto), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_proto), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_proto_by_value), + .strsplit_plain = TRUE, + ), + .values_static = NM_MAKE_STRV ("wpa", "rsn"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PAIRWISE, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_pairwise), + .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_pairwise), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_pairwise), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_pairwise_by_value), + .strsplit_plain = TRUE, + ), + .values_static = NM_MAKE_STRV ("tkip", "ccmp"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_GROUP, + .property_type = &_pt_multilist, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (multilist, + .get_num_fcn_u32 = MULTILIST_GET_NUM_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_get_num_groups), + .add_fcn = MULTILIST_ADD_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_add_group), + .remove_by_idx_fcn_u32 = MULTILIST_REMOVE_BY_IDX_FCN_U32 (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_group), + .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingWirelessSecurity, nm_setting_wireless_security_remove_group_by_value), + .strsplit_plain = TRUE, + ), + .values_static = NM_MAKE_STRV ("wep40", "wep104", "tkip", "ccmp"), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PMF, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_security_pmf_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key, + .set_fcn = _set_fcn_wireless_wep_key, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key, + .set_fcn = _set_fcn_wireless_wep_key, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key, + .set_fcn = _set_fcn_wireless_wep_key, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key, + .set_fcn = _set_fcn_wireless_wep_key, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + .describe_message = + N_("Enter the type of WEP keys. The accepted values are: " + "0 or unknown, 1 or key, and 2 or passphrase.\n"), + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .pre_set_notify = _gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, + .property_type = &_pt_gobject_secret_flags, + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WPS_METHOD, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_security_wps_method_get_type, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_FILS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_security_fils_get_type, + ), + ), + ), + NULL }; #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WPAN static const NMMetaPropertyInfo *const property_infos_WPAN[] = { - PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_MAC_ADDRESS, - .property_type = &_pt_gobject_mac, - .is_cli_option = TRUE, - .property_alias = "mac", - .prompt = N_("MAC [none]"), - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, - .mode = NM_META_PROPERTY_TYPE_MAC_MODE_WPAN, - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_SHORT_ADDRESS, - .is_cli_option = TRUE, - .property_alias = "short-addr", - .prompt = N_("Short address (<0x0000-0xffff>)"), - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ - .base = 16, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = G_MAXUINT16, - .nick = "unset", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_PAN_ID, - .is_cli_option = TRUE, - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .property_alias = "pan-id", - .prompt = N_("PAN Identifier (<0x0000-0xffff>)"), - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ - .base = 16, - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = G_MAXUINT16, - .nick = "unset", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_PAGE, - .is_cli_option = TRUE, - .property_alias = "page", - .prompt = N_("Page (<default|0-31>)"), - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = NM_SETTING_WPAN_PAGE_DEFAULT, - .nick = "default", - }, - ), - ), - ), - PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_CHANNEL, - .is_cli_option = TRUE, - .property_alias = "channel", - .prompt = N_("Channel (<default|0-26>)"), - .property_type = &_pt_gobject_int, - .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ - .value_infos = INT_VALUE_INFOS ( - { - .value.i64 = NM_SETTING_WPAN_CHANNEL_DEFAULT, - .nick = "default", - }, - ), - ), - ), - NULL + PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_MAC_ADDRESS, + .property_type = &_pt_gobject_mac, + .is_cli_option = TRUE, + .property_alias = "mac", + .prompt = N_("MAC [none]"), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_WPAN, + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_SHORT_ADDRESS, + .is_cli_option = TRUE, + .property_alias = "short-addr", + .prompt = N_("Short address (<0x0000-0xffff>)"), + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ + .base = 16, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = G_MAXUINT16, + .nick = "unset", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_PAN_ID, + .is_cli_option = TRUE, + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .property_alias = "pan-id", + .prompt = N_("PAN Identifier (<0x0000-0xffff>)"), + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ + .base = 16, + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = G_MAXUINT16, + .nick = "unset", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_PAGE, + .is_cli_option = TRUE, + .property_alias = "page", + .prompt = N_("Page (<default|0-31>)"), + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = NM_SETTING_WPAN_PAGE_DEFAULT, + .nick = "default", + }, + ), + ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WPAN_CHANNEL, + .is_cli_option = TRUE, + .property_alias = "channel", + .prompt = N_("Channel (<default|0-26>)"), + .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ + .value_infos = INT_VALUE_INFOS ( + { + .value.i64 = NM_SETTING_WPAN_CHANNEL_DEFAULT, + .nick = "default", + }, + ), + ), + ), + NULL }; /*****************************************************************************/ @@ -7734,118 +7809,118 @@ static const NMMetaPropertyInfo *const property_infos_WPAN[] = { static void _setting_init_fcn_adsl (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - /* Initialize a protocol */ - g_object_set (NM_SETTING_ADSL (setting), - NM_SETTING_ADSL_PROTOCOL, NM_SETTING_ADSL_PROTOCOL_PPPOE, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + /* Initialize a protocol */ + g_object_set (NM_SETTING_ADSL (setting), + NM_SETTING_ADSL_PROTOCOL, NM_SETTING_ADSL_PROTOCOL_PPPOE, + NULL); + } } static void _setting_init_fcn_cdma (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - /* Initialize 'number' so that 'cdma' is valid */ - g_object_set (NM_SETTING_CDMA (setting), - NM_SETTING_CDMA_NUMBER, "#777", - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + /* Initialize 'number' so that 'cdma' is valid */ + g_object_set (NM_SETTING_CDMA (setting), + NM_SETTING_CDMA_NUMBER, "#777", + NULL); + } } static void _setting_init_fcn_gsm (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - /* Initialize 'apn' so that 'gsm' is valid */ - g_object_set (NM_SETTING_GSM (setting), - NM_SETTING_GSM_APN, "internet", - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + /* Initialize 'apn' so that 'gsm' is valid */ + g_object_set (NM_SETTING_GSM (setting), + NM_SETTING_GSM_APN, "internet", + NULL); + } } static void _setting_init_fcn_infiniband (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - /* Initialize 'transport-mode' so that 'infiniband' is valid */ - g_object_set (NM_SETTING_INFINIBAND (setting), - NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + /* Initialize 'transport-mode' so that 'infiniband' is valid */ + g_object_set (NM_SETTING_INFINIBAND (setting), + NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", + NULL); + } } static void _setting_init_fcn_ip4_config (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (NM_SETTING_IP_CONFIG (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (NM_SETTING_IP_CONFIG (setting), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + } } static void _setting_init_fcn_ip6_config (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (NM_SETTING_IP_CONFIG (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (NM_SETTING_IP_CONFIG (setting), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + } } static void _setting_init_fcn_olpc_mesh (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (NM_SETTING_OLPC_MESH (setting), - NM_SETTING_OLPC_MESH_CHANNEL, 1, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (NM_SETTING_OLPC_MESH (setting), + NM_SETTING_OLPC_MESH_CHANNEL, 1, + NULL); + } } static void _setting_init_fcn_proxy (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (NM_SETTING_PROXY (setting), - NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (NM_SETTING_PROXY (setting), + NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE, + NULL); + } } static void _setting_init_fcn_tun (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (NM_SETTING_TUN (setting), - NM_SETTING_TUN_MODE, NM_SETTING_TUN_MODE_TUN, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (NM_SETTING_TUN (setting), + NM_SETTING_TUN_MODE, NM_SETTING_TUN_MODE_TUN, + NULL); + } } static void _setting_init_fcn_vlan (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - g_object_set (setting, - NM_SETTING_VLAN_ID, 1, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + g_object_set (setting, + NM_SETTING_VLAN_ID, 1, + NULL); + } } static void _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN) { - if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { - /* For Wi-Fi set mode to "infrastructure". Even though mode == NULL - * is regarded as "infrastructure", explicit value makes no doubts. - */ - g_object_set (NM_SETTING_WIRELESS (setting), - NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, - NULL); - } + if (init_type == NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI) { + /* For Wi-Fi set mode to "infrastructure". Even though mode == NULL + * is regarded as "infrastructure", explicit value makes no doubts. + */ + g_object_set (NM_SETTING_WIRELESS (setting), + NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, + NULL); + } } /*****************************************************************************/ @@ -7900,544 +7975,536 @@ _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN) #define SETTING_PRETTY_NAME_WPAN N_("WPAN settings") #define NM_META_SETTING_VALID_PARTS(...) \ - ((const NMMetaSettingValidPartItem *const[]) { __VA_ARGS__ NULL }) + ((const NMMetaSettingValidPartItem *const[]) { __VA_ARGS__ NULL }) #define NM_META_SETTING_VALID_PART_ITEM(type, mand) \ - (&((const NMMetaSettingValidPartItem) { \ - .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_##type], \ - .mandatory = mand, \ - })) + (&((const NMMetaSettingValidPartItem) { \ + .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_##type], \ + .mandatory = mand, \ + })) const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { #define SETTING_INFO_EMPTY(type, ...) \ - [NM_META_SETTING_TYPE_##type] = { \ - .meta_type = &nm_meta_type_setting_info_editor, \ - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ - .pretty_name = SETTING_PRETTY_NAME_##type, \ - __VA_ARGS__ \ - } + [NM_META_SETTING_TYPE_##type] = { \ + .meta_type = &nm_meta_type_setting_info_editor, \ + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ + .pretty_name = SETTING_PRETTY_NAME_##type, \ + __VA_ARGS__ \ + } #define SETTING_INFO(type, ...) \ - [NM_META_SETTING_TYPE_##type] = { \ - .meta_type = &nm_meta_type_setting_info_editor, \ - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ - .properties = property_infos_##type, \ - .properties_num = G_N_ELEMENTS (property_infos_##type) - 1, \ - .pretty_name = SETTING_PRETTY_NAME_##type, \ - __VA_ARGS__ \ - } - SETTING_INFO (6LOWPAN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (6LOWPAN, TRUE), - ), - ), - SETTING_INFO (802_1X), - SETTING_INFO (ADSL, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (ADSL, TRUE), - ), - .setting_init_fcn = _setting_init_fcn_adsl, - ), - SETTING_INFO (BLUETOOTH, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (BLUETOOTH, TRUE), - NM_META_SETTING_VALID_PART_ITEM (BRIDGE, FALSE), - NM_META_SETTING_VALID_PART_ITEM (GSM, FALSE), - NM_META_SETTING_VALID_PART_ITEM (CDMA, FALSE), - ), - ), - SETTING_INFO (BOND, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (BOND, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (BRIDGE, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (BRIDGE, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (BRIDGE_PORT), - SETTING_INFO (CDMA, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (CDMA, TRUE), - NM_META_SETTING_VALID_PART_ITEM (SERIAL, FALSE), - NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_cdma, - ), - SETTING_INFO (CONNECTION), - SETTING_INFO (DCB), - SETTING_INFO (ETHTOOL), - SETTING_INFO_EMPTY (DUMMY, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (DUMMY, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO_EMPTY (GENERIC, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (GENERIC, TRUE), - ), - ), - SETTING_INFO (GSM, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (GSM, TRUE), - NM_META_SETTING_VALID_PART_ITEM (SERIAL, FALSE), - NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_gsm, - ), - SETTING_INFO (INFINIBAND, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (INFINIBAND, TRUE), - NM_META_SETTING_VALID_PART_ITEM (SRIOV, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_infiniband, - ), - SETTING_INFO (IP4_CONFIG, - .setting_init_fcn = _setting_init_fcn_ip4_config, - ), - SETTING_INFO (IP6_CONFIG, - .setting_init_fcn = _setting_init_fcn_ip6_config, - ), - SETTING_INFO (IP_TUNNEL, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (IP_TUNNEL, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (MACSEC, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (MACSEC, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (MACVLAN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (MACVLAN, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (MATCH), - SETTING_INFO (OLPC_MESH, - .alias = "olpc-mesh", - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (OLPC_MESH, TRUE), - ), - .setting_init_fcn = _setting_init_fcn_olpc_mesh, - ), - SETTING_INFO (OVS_BRIDGE, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (OVS_BRIDGE, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - ), - ), - SETTING_INFO (OVS_DPDK), - SETTING_INFO (OVS_INTERFACE, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (OVS_INTERFACE, TRUE), - NM_META_SETTING_VALID_PART_ITEM (OVS_DPDK, FALSE), - NM_META_SETTING_VALID_PART_ITEM (OVS_PATCH, FALSE), - NM_META_SETTING_VALID_PART_ITEM (IP4_CONFIG, FALSE), - NM_META_SETTING_VALID_PART_ITEM (IP6_CONFIG, FALSE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (OVS_PATCH), - SETTING_INFO (OVS_PORT, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (OVS_PORT, TRUE), - ), - ), - SETTING_INFO (PPPOE, - /* PPPoE is a base connection type from historical reasons. - * See libnm-core/nm-setting.c:_nm_setting_is_base_type() - */ - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (PPPOE, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, TRUE), - NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), - NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (PPP), - SETTING_INFO (PROXY, - .setting_init_fcn = _setting_init_fcn_proxy, - ), - SETTING_INFO (SERIAL), - SETTING_INFO (SRIOV), - SETTING_INFO (TC_CONFIG), - SETTING_INFO (TEAM, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (TEAM, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (TEAM_PORT), - SETTING_INFO (TUN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (TUN, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_tun, - ), - SETTING_INFO_EMPTY (USER), - SETTING_INFO (VLAN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (VLAN, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_vlan, - ), - SETTING_INFO (VPN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (VPN, TRUE), - ), - ), - SETTING_INFO (VRF, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (VRF, TRUE), - ), - ), - - SETTING_INFO (VXLAN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (VXLAN, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (WIFI_P2P, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIFI_P2P, TRUE), - ), - ), - SETTING_INFO (WIMAX, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIMAX, TRUE), - ), - ), - SETTING_INFO (WIRED, - .alias = "ethernet", - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRED, TRUE), - NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), - NM_META_SETTING_VALID_PART_ITEM (DCB, FALSE), - NM_META_SETTING_VALID_PART_ITEM (SRIOV, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - ), - SETTING_INFO (WIREGUARD, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIREGUARD, TRUE), - ), - ), - SETTING_INFO (WIRELESS, - .alias = "wifi", - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRELESS, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WIRELESS_SECURITY, FALSE), - NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), - NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), - ), - .setting_init_fcn = _setting_init_fcn_wireless, - ), - SETTING_INFO (WIRELESS_SECURITY, - .alias = "wifi-sec", - ), - SETTING_INFO (WPAN, - .valid_parts = NM_META_SETTING_VALID_PARTS ( - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NM_META_SETTING_VALID_PART_ITEM (WPAN, TRUE), - ), - ), + [NM_META_SETTING_TYPE_##type] = { \ + .meta_type = &nm_meta_type_setting_info_editor, \ + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ + .properties = property_infos_##type, \ + .properties_num = G_N_ELEMENTS (property_infos_##type) - 1, \ + .pretty_name = SETTING_PRETTY_NAME_##type, \ + __VA_ARGS__ \ + } + SETTING_INFO (6LOWPAN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (6LOWPAN, TRUE), + ), + ), + SETTING_INFO (802_1X), + SETTING_INFO (ADSL, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (ADSL, TRUE), + ), + .setting_init_fcn = _setting_init_fcn_adsl, + ), + SETTING_INFO (BLUETOOTH, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (BLUETOOTH, TRUE), + NM_META_SETTING_VALID_PART_ITEM (BRIDGE, FALSE), + NM_META_SETTING_VALID_PART_ITEM (GSM, FALSE), + NM_META_SETTING_VALID_PART_ITEM (CDMA, FALSE), + ), + ), + SETTING_INFO (BOND, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (BOND, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (BRIDGE, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (BRIDGE, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (BRIDGE_PORT), + SETTING_INFO (CDMA, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (CDMA, TRUE), + NM_META_SETTING_VALID_PART_ITEM (SERIAL, FALSE), + NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_cdma, + ), + SETTING_INFO (CONNECTION), + SETTING_INFO (DCB), + SETTING_INFO (ETHTOOL), + SETTING_INFO_EMPTY (DUMMY, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (DUMMY, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO_EMPTY (GENERIC, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (GENERIC, TRUE), + ), + ), + SETTING_INFO (GSM, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (GSM, TRUE), + NM_META_SETTING_VALID_PART_ITEM (SERIAL, FALSE), + NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_gsm, + ), + SETTING_INFO (INFINIBAND, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (INFINIBAND, TRUE), + NM_META_SETTING_VALID_PART_ITEM (SRIOV, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_infiniband, + ), + SETTING_INFO (IP4_CONFIG, + .setting_init_fcn = _setting_init_fcn_ip4_config, + ), + SETTING_INFO (IP6_CONFIG, + .setting_init_fcn = _setting_init_fcn_ip6_config, + ), + SETTING_INFO (IP_TUNNEL, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (IP_TUNNEL, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (MACSEC, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (MACSEC, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (MACVLAN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (MACVLAN, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (MATCH), + SETTING_INFO (OLPC_MESH, + .alias = "olpc-mesh", + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (OLPC_MESH, TRUE), + ), + .setting_init_fcn = _setting_init_fcn_olpc_mesh, + ), + SETTING_INFO (OVS_BRIDGE, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (OVS_BRIDGE, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + ), + ), + SETTING_INFO (OVS_DPDK), + SETTING_INFO (OVS_INTERFACE, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (OVS_INTERFACE, TRUE), + NM_META_SETTING_VALID_PART_ITEM (OVS_DPDK, FALSE), + NM_META_SETTING_VALID_PART_ITEM (OVS_PATCH, FALSE), + NM_META_SETTING_VALID_PART_ITEM (IP4_CONFIG, FALSE), + NM_META_SETTING_VALID_PART_ITEM (IP6_CONFIG, FALSE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (OVS_PATCH), + SETTING_INFO (OVS_PORT, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (OVS_PORT, TRUE), + ), + ), + SETTING_INFO (PPPOE, + /* PPPoE is a base connection type from historical reasons. + * See libnm-core/nm-setting.c:_nm_setting_is_base_type() + */ + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (PPPOE, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, TRUE), + NM_META_SETTING_VALID_PART_ITEM (PPP, FALSE), + NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (PPP), + SETTING_INFO (PROXY, + .setting_init_fcn = _setting_init_fcn_proxy, + ), + SETTING_INFO (SERIAL), + SETTING_INFO (SRIOV), + SETTING_INFO (TC_CONFIG), + SETTING_INFO (TEAM, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (TEAM, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (TEAM_PORT), + SETTING_INFO (TUN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (TUN, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_tun, + ), + SETTING_INFO_EMPTY (USER), + SETTING_INFO (VLAN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (VLAN, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_vlan, + ), + SETTING_INFO (VPN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (VPN, TRUE), + ), + ), + SETTING_INFO (VRF, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (VRF, TRUE), + ), + ), + + SETTING_INFO (VXLAN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (VXLAN, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (WIFI_P2P, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIFI_P2P, TRUE), + ), + ), + SETTING_INFO (WIMAX, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIMAX, TRUE), + ), + ), + SETTING_INFO (WIRED, + .alias = "ethernet", + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRED, TRUE), + NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), + NM_META_SETTING_VALID_PART_ITEM (DCB, FALSE), + NM_META_SETTING_VALID_PART_ITEM (SRIOV, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + ), + SETTING_INFO (WIREGUARD, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIREGUARD, TRUE), + ), + ), + SETTING_INFO (WIRELESS, + .alias = "wifi", + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRELESS, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WIRELESS_SECURITY, FALSE), + NM_META_SETTING_VALID_PART_ITEM (802_1X, FALSE), + NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), + ), + .setting_init_fcn = _setting_init_fcn_wireless, + ), + SETTING_INFO (WIRELESS_SECURITY, + .alias = "wifi-sec", + ), + SETTING_INFO (WPAN, + .valid_parts = NM_META_SETTING_VALID_PARTS ( + NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), + NM_META_SETTING_VALID_PART_ITEM (WPAN, TRUE), + ), + ), }; +/* clang-format on */ + /*****************************************************************************/ const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default[] = { - NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), - NULL -}; + NM_META_SETTING_VALID_PART_ITEM(CONNECTION, TRUE), + NULL}; /*****************************************************************************/ static const NMMetaSettingValidPartItem *const valid_settings_noslave[] = { - NM_META_SETTING_VALID_PART_ITEM (MATCH, FALSE), - NM_META_SETTING_VALID_PART_ITEM (IP4_CONFIG, FALSE), - NM_META_SETTING_VALID_PART_ITEM (IP6_CONFIG, FALSE), - NM_META_SETTING_VALID_PART_ITEM (TC_CONFIG, FALSE), - NM_META_SETTING_VALID_PART_ITEM (PROXY, FALSE), - NULL, + NM_META_SETTING_VALID_PART_ITEM(MATCH, FALSE), + NM_META_SETTING_VALID_PART_ITEM(IP4_CONFIG, FALSE), + NM_META_SETTING_VALID_PART_ITEM(IP6_CONFIG, FALSE), + NM_META_SETTING_VALID_PART_ITEM(TC_CONFIG, FALSE), + NM_META_SETTING_VALID_PART_ITEM(PROXY, FALSE), + NULL, }; static const NMMetaSettingValidPartItem *const valid_settings_slave_bridge[] = { - NM_META_SETTING_VALID_PART_ITEM (BRIDGE_PORT, TRUE), - NULL, + NM_META_SETTING_VALID_PART_ITEM(BRIDGE_PORT, TRUE), + NULL, }; static const NMMetaSettingValidPartItem *const valid_settings_slave_ovs_bridge[] = { - NM_META_SETTING_VALID_PART_ITEM (OVS_PORT, FALSE), - NULL, + NM_META_SETTING_VALID_PART_ITEM(OVS_PORT, FALSE), + NULL, }; static const NMMetaSettingValidPartItem *const valid_settings_slave_ovs_port[] = { - NM_META_SETTING_VALID_PART_ITEM (OVS_INTERFACE, FALSE), - NULL, + NM_META_SETTING_VALID_PART_ITEM(OVS_INTERFACE, FALSE), + NULL, }; static const NMMetaSettingValidPartItem *const valid_settings_slave_team[] = { - NM_META_SETTING_VALID_PART_ITEM (TEAM_PORT, TRUE), - NULL, + NM_META_SETTING_VALID_PART_ITEM(TEAM_PORT, TRUE), + NULL, }; -const NMMetaSettingValidPartItem *const* -nm_meta_setting_info_valid_parts_for_slave_type (const char *slave_type, const char **out_slave_name) -{ - if (!slave_type) { - NM_SET_OUT (out_slave_name, NULL); - return valid_settings_noslave; - } - if (nm_streq (slave_type, NM_SETTING_BOND_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "bond-slave"); - return NM_PTRARRAY_EMPTY (const NMMetaSettingValidPartItem *); - } - if (nm_streq (slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "bridge-slave"); - return valid_settings_slave_bridge; - } - if (nm_streq (slave_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "ovs-slave"); - return valid_settings_slave_ovs_bridge; - } - if (nm_streq (slave_type, NM_SETTING_OVS_PORT_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "ovs-slave"); - return valid_settings_slave_ovs_port; - } - if (nm_streq (slave_type, NM_SETTING_TEAM_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "team-slave"); - return valid_settings_slave_team; - } - if (nm_streq (slave_type, NM_SETTING_VRF_SETTING_NAME)) { - NM_SET_OUT (out_slave_name, "vrf-slave"); - return valid_settings_noslave; - } - return NULL; +const NMMetaSettingValidPartItem *const * +nm_meta_setting_info_valid_parts_for_slave_type(const char *slave_type, const char **out_slave_name) +{ + if (!slave_type) { + NM_SET_OUT(out_slave_name, NULL); + return valid_settings_noslave; + } + if (nm_streq(slave_type, NM_SETTING_BOND_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "bond-slave"); + return NM_PTRARRAY_EMPTY(const NMMetaSettingValidPartItem *); + } + if (nm_streq(slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "bridge-slave"); + return valid_settings_slave_bridge; + } + if (nm_streq(slave_type, NM_SETTING_OVS_BRIDGE_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "ovs-slave"); + return valid_settings_slave_ovs_bridge; + } + if (nm_streq(slave_type, NM_SETTING_OVS_PORT_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "ovs-slave"); + return valid_settings_slave_ovs_port; + } + if (nm_streq(slave_type, NM_SETTING_TEAM_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "team-slave"); + return valid_settings_slave_team; + } + if (nm_streq(slave_type, NM_SETTING_VRF_SETTING_NAME)) { + NM_SET_OUT(out_slave_name, "vrf-slave"); + return valid_settings_noslave; + } + return NULL; } /*****************************************************************************/ static const char * -_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header) +_meta_type_setting_info_editor_get_name(const NMMetaAbstractInfo *abstract_info, + gboolean for_header) { - if (for_header) - return N_("name"); - return ((const NMMetaSettingInfoEditor *) abstract_info)->general->setting_name; + if (for_header) + return N_("name"); + return ((const NMMetaSettingInfoEditor *) abstract_info)->general->setting_name; } static const char * -_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header) +_meta_type_property_info_get_name(const NMMetaAbstractInfo *abstract_info, gboolean for_header) { - return ((const NMMetaPropertyInfo *) abstract_info)->property_name; + return ((const NMMetaPropertyInfo *) abstract_info)->property_name; } static gconstpointer -_meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - gpointer target, - gpointer target_data, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free) +_meta_type_setting_info_editor_get_fcn(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + gpointer target, + gpointer target_data, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free) { - const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info; + const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info; - nm_assert (!out_to_free || !*out_to_free); - nm_assert (out_flags && !*out_flags); - nm_assert (!target_data); + nm_assert(!out_to_free || !*out_to_free); + nm_assert(out_flags && !*out_flags); + nm_assert(!target_data); - if (!NM_IN_SET (get_type, - NM_META_ACCESSOR_GET_TYPE_PARSABLE, - NM_META_ACCESSOR_GET_TYPE_PRETTY)) - return NULL; + if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PARSABLE, NM_META_ACCESSOR_GET_TYPE_PRETTY)) + return NULL; - nm_assert (out_to_free); + nm_assert(out_to_free); - return info->general->setting_name; + return info->general->setting_name; } static gconstpointer -_meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - gpointer target, - gpointer target_data, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free) +_meta_type_property_info_get_fcn(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + gpointer target, + gpointer target_data, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free) { - const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; - gboolean is_default_local = FALSE; - gconstpointer r; - - nm_assert (!out_to_free || !*out_to_free); - nm_assert (out_flags && !*out_flags); + const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; + gboolean is_default_local = FALSE; + gconstpointer r; - if (!NM_IN_SET (get_type, - NM_META_ACCESSOR_GET_TYPE_PARSABLE, - NM_META_ACCESSOR_GET_TYPE_PRETTY)) - return NULL; + nm_assert(!out_to_free || !*out_to_free); + nm_assert(out_flags && !*out_flags); - nm_assert (out_to_free); + if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PARSABLE, NM_META_ACCESSOR_GET_TYPE_PRETTY)) + return NULL; - if ( info->is_secret - && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) { - NM_SET_OUT (out_is_default, TRUE); - return _get_text_hidden (get_type); - } + nm_assert(out_to_free); - if ( info->hide_if_default - && !out_is_default) - out_is_default = &is_default_local; + if (info->is_secret && !NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) { + NM_SET_OUT(out_is_default, TRUE); + return _get_text_hidden(get_type); + } - r = info->property_type->get_fcn (info, - environment, - environment_user_data, - target, - get_type, - get_flags, - out_flags, - out_is_default, - out_to_free); + if (info->hide_if_default && !out_is_default) + out_is_default = &is_default_local; - if ( info->hide_if_default - && *out_is_default) - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE; + r = info->property_type->get_fcn(info, + environment, + environment_user_data, + target, + get_type, + get_flags, + out_flags, + out_is_default, + out_to_free); - return r; + if (info->hide_if_default && *out_is_default) + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE; + return r; } -static const NMMetaAbstractInfo *const* -_meta_type_setting_info_editor_get_nested (const NMMetaAbstractInfo *abstract_info, - guint *out_len, - gpointer *out_to_free) +static const NMMetaAbstractInfo *const * +_meta_type_setting_info_editor_get_nested(const NMMetaAbstractInfo *abstract_info, + guint * out_len, + gpointer * out_to_free) { - const NMMetaSettingInfoEditor *info; + const NMMetaSettingInfoEditor *info; - info = (const NMMetaSettingInfoEditor *) abstract_info; + info = (const NMMetaSettingInfoEditor *) abstract_info; - NM_SET_OUT (out_len, info->properties_num); - return (const NMMetaAbstractInfo *const*) info->properties; + NM_SET_OUT(out_len, info->properties_num); + return (const NMMetaAbstractInfo *const *) info->properties; } -static const NMMetaAbstractInfo *const* -_meta_type_property_info_get_nested (const NMMetaAbstractInfo *abstract_info, - guint *out_len, - gpointer *out_to_free) +static const NMMetaAbstractInfo *const * +_meta_type_property_info_get_nested(const NMMetaAbstractInfo *abstract_info, + guint * out_len, + gpointer * out_to_free) { - NM_SET_OUT (out_len, 0); - return NULL; + NM_SET_OUT(out_len, 0); + return NULL; } -static const char *const* -_meta_type_property_info_complete_fcn (const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NMMetaOperationContext *operation_context, - const char *text, - gboolean *out_complete_filename, - char ***out_to_free) +static const char *const * +_meta_type_property_info_complete_fcn(const NMMetaAbstractInfo * abstract_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + const NMMetaOperationContext *operation_context, + const char * text, + gboolean * out_complete_filename, + char *** out_to_free) { - const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; + const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; - nm_assert (out_to_free && !*out_to_free); + nm_assert(out_to_free && !*out_to_free); - if (info->property_type->complete_fcn) { - return info->property_type->complete_fcn (info, - environment, - environment_user_data, - operation_context, - text, - out_complete_filename, - out_to_free); - } + if (info->property_type->complete_fcn) { + return info->property_type->complete_fcn(info, + environment, + environment_user_data, + operation_context, + text, + out_complete_filename, + out_to_free); + } - if (info->property_type->values_fcn) { - return info->property_type->values_fcn (info, - out_to_free); - } + if (info->property_type->values_fcn) { + return info->property_type->values_fcn(info, out_to_free); + } - if ( info->property_typ_data - && info->property_typ_data->values_static) - return info->property_typ_data->values_static; + if (info->property_typ_data && info->property_typ_data->values_static) + return info->property_typ_data->values_static; - return NULL; + return NULL; } const NMMetaType nm_meta_type_setting_info_editor = { - .type_name = "setting_info_editor", - .get_name = _meta_type_setting_info_editor_get_name, - .get_nested = _meta_type_setting_info_editor_get_nested, - .get_fcn = _meta_type_setting_info_editor_get_fcn, + .type_name = "setting_info_editor", + .get_name = _meta_type_setting_info_editor_get_name, + .get_nested = _meta_type_setting_info_editor_get_nested, + .get_fcn = _meta_type_setting_info_editor_get_fcn, }; const NMMetaType nm_meta_type_property_info = { - .type_name = "property_info", - .get_name = _meta_type_property_info_get_name, - .get_nested = _meta_type_property_info_get_nested, - .get_fcn = _meta_type_property_info_get_fcn, - .complete_fcn = _meta_type_property_info_complete_fcn, + .type_name = "property_info", + .get_name = _meta_type_property_info_get_name, + .get_nested = _meta_type_property_info_get_nested, + .get_fcn = _meta_type_property_info_get_fcn, + .complete_fcn = _meta_type_property_info_complete_fcn, }; const NMMetaType nm_meta_type_nested_property_info = { - .type_name = "nested_property_info", + .type_name = "nested_property_info", }; diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index 68c03d05..3afd7686 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2018 Red Hat, Inc. */ @@ -15,157 +15,170 @@ struct _NMDevice; #define NM_META_TEXT_HIDDEN N_("<hidden>") #define NM_META_TEXT_PROMPT_ADSL_PROTO N_("Protocol") -#define NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES "(" NM_SETTING_ADSL_PROTOCOL_PPPOA "/" NM_SETTING_ADSL_PROTOCOL_PPPOE "/" NM_SETTING_ADSL_PROTOCOL_IPOATM ")" +#define NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES \ + "(" NM_SETTING_ADSL_PROTOCOL_PPPOA "/" NM_SETTING_ADSL_PROTOCOL_PPPOE \ + "/" NM_SETTING_ADSL_PROTOCOL_IPOATM ")" #define NM_META_TEXT_PROMPT_ADSL_ENCAP N_("ADSL encapsulation") -#define NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES "(" NM_SETTING_ADSL_ENCAPSULATION_VCMUX "/" NM_SETTING_ADSL_ENCAPSULATION_LLC ") [none]" +#define NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES \ + "(" NM_SETTING_ADSL_ENCAPSULATION_VCMUX "/" NM_SETTING_ADSL_ENCAPSULATION_LLC ") [none]" -#define NM_META_TEXT_PROMPT_CON_TYPE N_("Connection type") -#define NM_META_TEXT_PROMPT_IFNAME N_("Interface name [*]") -#define NM_META_TEXT_PROMPT_VPN_TYPE N_("VPN type") -#define NM_META_TEXT_PROMPT_MASTER N_("Master") +#define NM_META_TEXT_PROMPT_CON_TYPE N_("Connection type") +#define NM_META_TEXT_PROMPT_IFNAME N_("Interface name [*]") +#define NM_META_TEXT_PROMPT_VPN_TYPE N_("VPN type") +#define NM_META_TEXT_PROMPT_MASTER N_("Master") -#define NM_META_TEXT_PROMPT_IB_MODE N_("Transport mode") +#define NM_META_TEXT_PROMPT_IB_MODE N_("Transport mode") #define NM_META_TEXT_WORD_DATAGRAM "datagram" #define NM_META_TEXT_WORD_CONNECTED "connected" -#define NM_META_TEXT_PROMPT_IB_MODE_CHOICES "(" NM_META_TEXT_WORD_DATAGRAM "/" NM_META_TEXT_WORD_CONNECTED ") [" NM_META_TEXT_WORD_DATAGRAM "]" +#define NM_META_TEXT_PROMPT_IB_MODE_CHOICES \ + "(" NM_META_TEXT_WORD_DATAGRAM "/" NM_META_TEXT_WORD_CONNECTED \ + ") [" NM_META_TEXT_WORD_DATAGRAM "]" #define NM_META_TEXT_PROMPT_BT_TYPE N_("Bluetooth type") #define NM_META_TEXT_WORD_PANU "panu" #define NM_META_TEXT_WORD_NAP "nap" #define NM_META_TEXT_WORD_DUN_GSM "dun-gsm" #define NM_META_TEXT_WORD_DUN_CDMA "dun-cdma" -#define NM_META_TEXT_PROMPT_BT_TYPE_CHOICES "(" NM_META_TEXT_WORD_PANU "/" NM_META_TEXT_WORD_NAP "/" NM_META_TEXT_WORD_DUN_GSM "/" NM_META_TEXT_WORD_DUN_CDMA ") [" NM_META_TEXT_WORD_PANU "]" +#define NM_META_TEXT_PROMPT_BT_TYPE_CHOICES \ + "(" NM_META_TEXT_WORD_PANU "/" NM_META_TEXT_WORD_NAP "/" NM_META_TEXT_WORD_DUN_GSM \ + "/" NM_META_TEXT_WORD_DUN_CDMA ") [" NM_META_TEXT_WORD_PANU "]" #define NM_META_TEXT_PROMPT_BOND_MODE N_("Bonding mode") #define NM_META_TEXT_PROMPT_BOND_MON_MODE N_("Bonding monitoring mode") -#define NM_META_TEXT_WORD_MIIMON "miimon" -#define NM_META_TEXT_WORD_ARP "arp" -#define NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES "(" NM_META_TEXT_WORD_MIIMON "/" NM_META_TEXT_WORD_ARP ") [" NM_META_TEXT_WORD_MIIMON "]" +#define NM_META_TEXT_WORD_MIIMON "miimon" +#define NM_META_TEXT_WORD_ARP "arp" +#define NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES \ + "(" NM_META_TEXT_WORD_MIIMON "/" NM_META_TEXT_WORD_ARP ") [" NM_META_TEXT_WORD_MIIMON "]" #define NM_META_TEXT_PROMPT_WIFI_MODE N_("Wi-Fi mode") -#define NM_META_TEXT_WORD_INFRA "infrastructure" -#define NM_META_TEXT_WORD_AP "ap" -#define NM_META_TEXT_WORD_ADHOC "adhoc" -#define NM_META_TEXT_WORD_MESH "mesh" -#define NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES "(" NM_META_TEXT_WORD_INFRA "/" NM_META_TEXT_WORD_AP "/" NM_META_TEXT_WORD_ADHOC "/" NM_META_TEXT_WORD_MESH ") [" NM_META_TEXT_WORD_INFRA "]" +#define NM_META_TEXT_WORD_INFRA "infrastructure" +#define NM_META_TEXT_WORD_AP "ap" +#define NM_META_TEXT_WORD_ADHOC "adhoc" +#define NM_META_TEXT_WORD_MESH "mesh" +#define NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES \ + "(" NM_META_TEXT_WORD_INFRA "/" NM_META_TEXT_WORD_AP "/" NM_META_TEXT_WORD_ADHOC \ + "/" NM_META_TEXT_WORD_MESH ") [" NM_META_TEXT_WORD_INFRA "]" #define NM_META_TEXT_PROMPT_TUN_MODE N_("Tun mode") -#define NM_META_TEXT_WORD_TUN "tun" -#define NM_META_TEXT_WORD_TAP "tap" -#define NM_META_TEXT_PROMPT_TUN_MODE_CHOICES "(" NM_META_TEXT_WORD_TUN "/" NM_META_TEXT_WORD_TAP ") [" NM_META_TEXT_WORD_TUN "]" +#define NM_META_TEXT_WORD_TUN "tun" +#define NM_META_TEXT_WORD_TAP "tap" +#define NM_META_TEXT_PROMPT_TUN_MODE_CHOICES \ + "(" NM_META_TEXT_WORD_TUN "/" NM_META_TEXT_WORD_TAP ") [" NM_META_TEXT_WORD_TUN "]" #define NM_META_TEXT_PROMPT_IP_TUNNEL_MODE N_("IP Tunnel mode") #define NM_META_TEXT_PROMPT_MACVLAN_MODE N_("MACVLAN mode") #define NM_META_TEXT_PROMPT_MACSEC_MODE N_("MACsec mode") -#define NM_META_TEXT_WORD_PSK "psk" -#define NM_META_TEXT_WORD_EAP "eap" -#define NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES "(" NM_META_TEXT_WORD_PSK "/" NM_META_TEXT_WORD_EAP ")" +#define NM_META_TEXT_WORD_PSK "psk" +#define NM_META_TEXT_WORD_EAP "eap" +#define NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES \ + "(" NM_META_TEXT_WORD_PSK "/" NM_META_TEXT_WORD_EAP ")" #define NM_META_TEXT_PROMPT_PROXY_METHOD N_("Proxy method") -#define NM_META_TEXT_WORD_NONE "none" -#define NM_META_TEXT_WORD_AUTO "auto" -#define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES "(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]" +#define NM_META_TEXT_WORD_NONE "none" +#define NM_META_TEXT_WORD_AUTO "auto" +#define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES \ + "(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]" typedef enum { - NM_META_COLOR_NONE = 0, - NM_META_COLOR_CONNECTION_ACTIVATED, - NM_META_COLOR_CONNECTION_ACTIVATING, - NM_META_COLOR_CONNECTION_DISCONNECTING, - NM_META_COLOR_CONNECTION_INVISIBLE, - NM_META_COLOR_CONNECTION_EXTERNAL, - NM_META_COLOR_CONNECTION_UNKNOWN, - NM_META_COLOR_CONNECTIVITY_FULL, - NM_META_COLOR_CONNECTIVITY_LIMITED, - NM_META_COLOR_CONNECTIVITY_NONE, - NM_META_COLOR_CONNECTIVITY_PORTAL, - NM_META_COLOR_CONNECTIVITY_UNKNOWN, - NM_META_COLOR_DEVICE_ACTIVATED, - NM_META_COLOR_DEVICE_ACTIVATING, - NM_META_COLOR_DEVICE_DISCONNECTED, - NM_META_COLOR_DEVICE_FIRMWARE_MISSING, - NM_META_COLOR_DEVICE_PLUGIN_MISSING, - NM_META_COLOR_DEVICE_UNAVAILABLE, - NM_META_COLOR_DEVICE_DISABLED, - NM_META_COLOR_DEVICE_EXTERNAL, - NM_META_COLOR_DEVICE_UNKNOWN, - NM_META_COLOR_MANAGER_RUNNING, - NM_META_COLOR_MANAGER_STARTING, - NM_META_COLOR_MANAGER_STOPPED, - NM_META_COLOR_PERMISSION_AUTH, - NM_META_COLOR_PERMISSION_NO, - NM_META_COLOR_PERMISSION_UNKNOWN, - NM_META_COLOR_PERMISSION_YES, - NM_META_COLOR_PROMPT, - NM_META_COLOR_STATE_ASLEEP, - NM_META_COLOR_STATE_CONNECTED_GLOBAL, - NM_META_COLOR_STATE_CONNECTED_LOCAL, - NM_META_COLOR_STATE_CONNECTED_SITE, - NM_META_COLOR_STATE_CONNECTING, - NM_META_COLOR_STATE_DISCONNECTED, - NM_META_COLOR_STATE_DISCONNECTING, - NM_META_COLOR_STATE_UNKNOWN, - NM_META_COLOR_WIFI_SIGNAL_EXCELLENT, - NM_META_COLOR_WIFI_SIGNAL_FAIR, - NM_META_COLOR_WIFI_SIGNAL_GOOD, - NM_META_COLOR_WIFI_SIGNAL_POOR, - NM_META_COLOR_WIFI_SIGNAL_UNKNOWN, - NM_META_COLOR_DISABLED, - NM_META_COLOR_ENABLED, - _NM_META_COLOR_NUM + NM_META_COLOR_NONE = 0, + NM_META_COLOR_CONNECTION_ACTIVATED, + NM_META_COLOR_CONNECTION_ACTIVATING, + NM_META_COLOR_CONNECTION_DISCONNECTING, + NM_META_COLOR_CONNECTION_INVISIBLE, + NM_META_COLOR_CONNECTION_EXTERNAL, + NM_META_COLOR_CONNECTION_UNKNOWN, + NM_META_COLOR_CONNECTIVITY_FULL, + NM_META_COLOR_CONNECTIVITY_LIMITED, + NM_META_COLOR_CONNECTIVITY_NONE, + NM_META_COLOR_CONNECTIVITY_PORTAL, + NM_META_COLOR_CONNECTIVITY_UNKNOWN, + NM_META_COLOR_DEVICE_ACTIVATED, + NM_META_COLOR_DEVICE_ACTIVATING, + NM_META_COLOR_DEVICE_DISCONNECTED, + NM_META_COLOR_DEVICE_FIRMWARE_MISSING, + NM_META_COLOR_DEVICE_PLUGIN_MISSING, + NM_META_COLOR_DEVICE_UNAVAILABLE, + NM_META_COLOR_DEVICE_DISABLED, + NM_META_COLOR_DEVICE_EXTERNAL, + NM_META_COLOR_DEVICE_UNKNOWN, + NM_META_COLOR_MANAGER_RUNNING, + NM_META_COLOR_MANAGER_STARTING, + NM_META_COLOR_MANAGER_STOPPED, + NM_META_COLOR_PERMISSION_AUTH, + NM_META_COLOR_PERMISSION_NO, + NM_META_COLOR_PERMISSION_UNKNOWN, + NM_META_COLOR_PERMISSION_YES, + NM_META_COLOR_PROMPT, + NM_META_COLOR_STATE_ASLEEP, + NM_META_COLOR_STATE_CONNECTED_GLOBAL, + NM_META_COLOR_STATE_CONNECTED_LOCAL, + NM_META_COLOR_STATE_CONNECTED_SITE, + NM_META_COLOR_STATE_CONNECTING, + NM_META_COLOR_STATE_DISCONNECTED, + NM_META_COLOR_STATE_DISCONNECTING, + NM_META_COLOR_STATE_UNKNOWN, + NM_META_COLOR_WIFI_SIGNAL_EXCELLENT, + NM_META_COLOR_WIFI_SIGNAL_FAIR, + NM_META_COLOR_WIFI_SIGNAL_GOOD, + NM_META_COLOR_WIFI_SIGNAL_POOR, + NM_META_COLOR_WIFI_SIGNAL_UNKNOWN, + NM_META_COLOR_DISABLED, + NM_META_COLOR_ENABLED, + _NM_META_COLOR_NUM } NMMetaColor; typedef enum { - NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD, - NM_META_ACCESSOR_MODIFIER_DEL, + NM_META_ACCESSOR_MODIFIER_SET, + NM_META_ACCESSOR_MODIFIER_ADD, + NM_META_ACCESSOR_MODIFIER_DEL, } NMMetaAccessorModifier; typedef enum { - NM_META_ACCESSOR_GET_TYPE_PRETTY, - NM_META_ACCESSOR_GET_TYPE_PARSABLE, - NM_META_ACCESSOR_GET_TYPE_COLOR, + NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE, + NM_META_ACCESSOR_GET_TYPE_COLOR, } NMMetaAccessorGetType; typedef enum { - NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT, - NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI, + NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT, + NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI, } NMMetaAccessorSettingInitType; typedef enum { - NM_META_ACCESSOR_GET_FLAGS_NONE = 0, - NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0), - NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1), + NM_META_ACCESSOR_GET_FLAGS_NONE = 0, + NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0), + NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1), } NMMetaAccessorGetFlags; typedef enum { - NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0, - NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0), + NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0, + NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0), - /* the property allows to be hidden, if and only if, it's value is set to the - * default. This should only be set by new properties, to preserve behavior - * of old properties, which were always printed. */ - NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE = (1LL << 1), + /* the property allows to be hidden, if and only if, it's value is set to the + * default. This should only be set by new properties, to preserve behavior + * of old properties, which were always printed. */ + NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE = (1LL << 1), } NMMetaAccessorGetOutFlags; typedef enum { - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N = (1LL << 3), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC = (1LL << 4), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX = (1LL << 5), - NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT = (1LL << 6), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N = (1LL << 3), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC = (1LL << 4), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX = (1LL << 5), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT = (1LL << 6), } NMMetaPropertyTypFlags; typedef enum { - NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT, - NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, - NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, - NM_META_PROPERTY_TYPE_MAC_MODE_WPAN, + NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT, + NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, + NM_META_PROPERTY_TYPE_MAC_MODE_WPAN, } NMMetaPropertyTypeMacMode; typedef struct _NMMetaEnvironment NMMetaEnvironment; @@ -183,282 +196,274 @@ typedef struct _NMMetaPropertyTypDataNested NMMetaPropertyTypDataNested; * This command actually violates layering, and should be considered * a hack. In the future, try to replace its use. */ struct _NMMetaOperationContext { - NMConnection *connection; + NMConnection *connection; }; struct _NMMetaPropertyType { - - /* should return a translated string */ - const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info, - char **out_to_free); - - gconstpointer (*get_fcn) (const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMSetting *setting, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free); - gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMSetting *setting, - NMMetaAccessorModifier modifier, - const char *value, - GError **error); - - const char *const*(*values_fcn) (const NMMetaPropertyInfo *property_info, - char ***out_to_free); - - const char *const*(*complete_fcn) (const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NMMetaOperationContext *operation_context, - const char *text, - gboolean *out_complete_filename, - char ***out_to_free); - - /* Whether set_fcn() supports the '-' modifier. That is, whether the property - * is a list type. */ - bool set_supports_remove:1; + /* should return a translated string */ + const char *(*describe_fcn)(const NMMetaPropertyInfo *property_info, char **out_to_free); + + gconstpointer (*get_fcn)(const NMMetaPropertyInfo * property_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + NMSetting * setting, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free); + gboolean (*set_fcn)(const NMMetaPropertyInfo *property_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + NMSetting * setting, + NMMetaAccessorModifier modifier, + const char * value, + GError ** error); + + const char *const *(*values_fcn)(const NMMetaPropertyInfo *property_info, char ***out_to_free); + + const char *const *(*complete_fcn)(const NMMetaPropertyInfo * property_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + const NMMetaOperationContext *operation_context, + const char * text, + gboolean * out_complete_filename, + char *** out_to_free); + + /* Whether set_fcn() supports the '-' modifier. That is, whether the property + * is a list type. */ + bool set_supports_remove : 1; }; struct _NMUtilsEnumValueInfo; typedef union { - gint64 i64; - guint64 u64; + gint64 i64; + guint64 u64; } NMMetaSignUnsignInt64; typedef struct { - const char *nick; - NMMetaSignUnsignInt64 value; + const char * nick; + NMMetaSignUnsignInt64 value; } NMMetaUtilsIntValueInfo; struct _NMMetaPropertyTypData { - union { - struct { - GType (*get_gtype) (void); - int min; - int max; - const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */ - const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */ - void (*pre_set_notify) (const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMSetting *setting, - int value); - } gobject_enum; - struct { - NMMetaSignUnsignInt64 min; - NMMetaSignUnsignInt64 max; - guint base; - const NMMetaUtilsIntValueInfo *value_infos; - } gobject_int; - struct { - const char *(*validate_fcn) (const char *value, char **out_to_free, GError **error); - bool handle_emptyunset:1; - } gobject_string; - struct { - bool legacy_format:1; - } gobject_bytes; - struct { - guint32 (*get_num_fcn_u32) (NMSetting *setting); - guint (*get_num_fcn_u) (NMSetting *setting); - void (*clear_all_fcn) (NMSetting *setting); - - /* some multilist properties distinguish between an empty list and - * and unset. If this function pointer is set, certain behaviors come - * into action to handle that. */ - void (*clear_emptyunset_fcn) (NMSetting *setting, - gboolean is_set /* or else set default */); - - gboolean (*add_fcn) (NMSetting *setting, - const char *item); - void (*add2_fcn) (NMSetting *setting, - const char *item); - const char *(*validate_fcn) (const char *item, GError **error); - const char *(*validate2_fcn) (NMSetting *setting, const char *item, GError **error); - void (*remove_by_idx_fcn_u32) (NMSetting *setting, guint32 idx); - void (*remove_by_idx_fcn_u) (NMSetting *setting, guint idx); - void (*remove_by_idx_fcn_s) (NMSetting *setting, int idx); - gboolean (*remove_by_value_fcn) (NMSetting *setting, const char *item); - bool strsplit_plain:1; - bool strsplit_with_spaces:1; - } multilist; - struct { - guint (*get_num_fcn) (NMSetting *setting); - void (*obj_to_str_fcn) (NMMetaAccessorGetType get_type, - NMSetting *setting, - guint idx, - GString *str); - gboolean (*set_fcn) (NMSetting *setting, - gboolean do_add /* or else remove. */, - const char *value, - GError **error); - void (*clear_all_fcn) (NMSetting *setting); - void (*remove_by_idx_fcn_u) (NMSetting *setting, guint idx); - void (*remove_by_idx_fcn_s) (NMSetting *setting, int idx); - bool delimit_pretty_with_semicolon:1; - bool strsplit_plain:1; - } objlist; - struct { - gboolean (*set_fcn) (NMSetting *setting, - const char *option, - const char *value, - GError **error); - bool no_empty_value:1; - } optionlist; - struct { - guint32 (*get_fcn) (NMSetting *setting); - } mtu; - struct { - NMSetting8021xSchemeType scheme_type; - } cert_8021x; - struct { - NMMetaPropertyTypeMacMode mode; - } mac; - struct { - guint (*get_fcn) (NMSettingDcb *setting, - guint user_priority); - void (*set_fcn) (NMSettingDcb *setting, - guint id, - guint value); - guint max; - guint other; - bool is_percent:1; - } dcb; - struct { - gboolean (*get_fcn) (NMSettingDcb *s_dcb, - guint priority); - void (*set_fcn) (NMSettingDcb *setting, - guint user_priority, - gboolean enabled); - bool with_flow_control_flags:1; - } dcb_bool; - struct { - NMEthtoolID ethtool_id; - } ethtool; - } subtype; - gboolean (*is_default_fcn) (NMSetting *setting); - const char *const*values_static; - const NMMetaPropertyTypDataNested *nested; - NMMetaPropertyTypFlags typ_flags; + union { + struct { + GType (*get_gtype)(void); + int min; + int max; + const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */ + const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */ + void (*pre_set_notify)(const NMMetaPropertyInfo *property_info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + NMSetting * setting, + int value); + } gobject_enum; + struct { + NMMetaSignUnsignInt64 min; + NMMetaSignUnsignInt64 max; + guint base; + const NMMetaUtilsIntValueInfo *value_infos; + } gobject_int; + struct { + const char *(*validate_fcn)(const char *value, char **out_to_free, GError **error); + bool handle_emptyunset : 1; + } gobject_string; + struct { + bool legacy_format : 1; + } gobject_bytes; + struct { + guint32 (*get_num_fcn_u32)(NMSetting *setting); + guint (*get_num_fcn_u)(NMSetting *setting); + void (*clear_all_fcn)(NMSetting *setting); + + /* some multilist properties distinguish between an empty list and + * and unset. If this function pointer is set, certain behaviors come + * into action to handle that. */ + void (*clear_emptyunset_fcn)(NMSetting *setting, + gboolean is_set /* or else set default */); + + gboolean (*add_fcn)(NMSetting *setting, const char *item); + void (*add2_fcn)(NMSetting *setting, const char *item); + const char *(*validate_fcn)(const char *item, GError **error); + const char *(*validate2_fcn)(NMSetting *setting, const char *item, GError **error); + void (*remove_by_idx_fcn_u32)(NMSetting *setting, guint32 idx); + void (*remove_by_idx_fcn_u)(NMSetting *setting, guint idx); + void (*remove_by_idx_fcn_s)(NMSetting *setting, int idx); + gboolean (*remove_by_value_fcn)(NMSetting *setting, const char *item); + bool strsplit_plain : 1; + bool strsplit_with_spaces : 1; + } multilist; + struct { + guint (*get_num_fcn)(NMSetting *setting); + void (*obj_to_str_fcn)(NMMetaAccessorGetType get_type, + NMSetting * setting, + guint idx, + GString * str); + gboolean (*set_fcn)(NMSetting * setting, + gboolean do_add /* or else remove. */, + const char *value, + GError ** error); + void (*clear_all_fcn)(NMSetting *setting); + void (*remove_by_idx_fcn_u)(NMSetting *setting, guint idx); + void (*remove_by_idx_fcn_s)(NMSetting *setting, int idx); + bool delimit_pretty_with_semicolon : 1; + bool strsplit_plain : 1; + } objlist; + struct { + gboolean (*set_fcn)(NMSetting * setting, + const char *option, + const char *value, + GError ** error); + bool no_empty_value : 1; + } optionlist; + struct { + guint32 (*get_fcn)(NMSetting *setting); + } mtu; + struct { + NMSetting8021xSchemeType scheme_type; + } cert_8021x; + struct { + NMMetaPropertyTypeMacMode mode; + } mac; + struct { + guint (*get_fcn)(NMSettingDcb *setting, guint user_priority); + void (*set_fcn)(NMSettingDcb *setting, guint id, guint value); + guint max; + guint other; + bool is_percent : 1; + } dcb; + struct { + gboolean (*get_fcn)(NMSettingDcb *s_dcb, guint priority); + void (*set_fcn)(NMSettingDcb *setting, guint user_priority, gboolean enabled); + bool with_flow_control_flags : 1; + } dcb_bool; + struct { + NMEthtoolID ethtool_id; + } ethtool; + } subtype; + gboolean (*is_default_fcn)(NMSetting *setting); + const char *const * values_static; + const NMMetaPropertyTypDataNested *nested; + NMMetaPropertyTypFlags typ_flags; }; typedef enum { - NM_META_PROPERTY_INF_FLAG_NONE = 0x00, - NM_META_PROPERTY_INF_FLAG_REQD = 0x01, /* Don't ask to ask. */ - NM_META_PROPERTY_INF_FLAG_DONT_ASK = 0x02, /* Don't ask interactively by default */ - NM_META_PROPERTY_INF_FLAG_MULTI = 0x04, /* Ask multiple times, do an append instead of set. */ + NM_META_PROPERTY_INF_FLAG_NONE = 0x00, + NM_META_PROPERTY_INF_FLAG_REQD = 0x01, /* Don't ask to ask. */ + NM_META_PROPERTY_INF_FLAG_DONT_ASK = 0x02, /* Don't ask interactively by default */ + NM_META_PROPERTY_INF_FLAG_MULTI = 0x04, /* Ask multiple times, do an append instead of set. */ } NMMetaPropertyInfFlags; enum { - _NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0, - _NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 3, + _NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0, + _NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 3, }; -#define nm_meta_property_info_connection_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE]) -#define nm_meta_property_info_vpn_service_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN].properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE]) +#define nm_meta_property_info_connection_type \ + (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION] \ + .properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE]) +#define nm_meta_property_info_vpn_service_type \ + (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN] \ + .properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE]) struct _NMMetaPropertyInfo { - union { - NMObjBaseInst parent; - const NMMetaType *meta_type; - }; + union { + NMObjBaseInst parent; + const NMMetaType *meta_type; + }; - const NMMetaSettingInfoEditor *setting_info; + const NMMetaSettingInfoEditor *setting_info; - const char *property_name; + const char *property_name; - const char *property_alias; + const char *property_alias; - NMMetaPropertyInfFlags inf_flags; - bool is_secret:1; + NMMetaPropertyInfFlags inf_flags; + bool is_secret : 1; - bool is_cli_option:1; - bool hide_if_default:1; + bool is_cli_option : 1; + bool hide_if_default : 1; - const char *prompt; + const char *prompt; - const char *def_hint; + const char *def_hint; - const char *describe_doc; + const char *describe_doc; - /* a non-translated but translatable static description (marked with N_()). */ - const char *describe_message; + /* a non-translated but translatable static description (marked with N_()). */ + const char *describe_message; - const NMMetaPropertyType *property_type; - const NMMetaPropertyTypData *property_typ_data; + const NMMetaPropertyType * property_type; + const NMMetaPropertyTypData *property_typ_data; }; typedef struct _NMMetaSettingValidPartItem { - const NMMetaSettingInfoEditor *setting_info; - bool mandatory; + const NMMetaSettingInfoEditor *setting_info; + bool mandatory; } NMMetaSettingValidPartItem; struct _NMMetaSettingInfoEditor { - union { - NMObjBaseInst parent; - const NMMetaType *meta_type; - }; - const NMMetaSettingInfo *general; - const char *alias; - const char *pretty_name; - const NMMetaPropertyInfo *const*properties; - guint properties_num; - - /* a NMConnection has a main type (connection.type), which is a - * main NMSetting instance. Depending on the type, a connection - * may have a list of other allowed settings. - * - * For example, a connection of type "vlan" may have settings - * of type "connection", "vlan", and "wired". - * - * Some setting types a not a main type (NMSettingProxy). They - * don't have valid_settings but are usually referenced by other - * settings to be valid for them. */ - const NMMetaSettingValidPartItem *const*valid_parts; - - void (*setting_init_fcn) (const NMMetaSettingInfoEditor *setting_info, - NMSetting *setting, - NMMetaAccessorSettingInitType init_type); + union { + NMObjBaseInst parent; + const NMMetaType *meta_type; + }; + const NMMetaSettingInfo * general; + const char * alias; + const char * pretty_name; + const NMMetaPropertyInfo *const *properties; + guint properties_num; + + /* a NMConnection has a main type (connection.type), which is a + * main NMSetting instance. Depending on the type, a connection + * may have a list of other allowed settings. + * + * For example, a connection of type "vlan" may have settings + * of type "connection", "vlan", and "wired". + * + * Some setting types a not a main type (NMSettingProxy). They + * don't have valid_settings but are usually referenced by other + * settings to be valid for them. */ + const NMMetaSettingValidPartItem *const *valid_parts; + + void (*setting_init_fcn)(const NMMetaSettingInfoEditor *setting_info, + NMSetting * setting, + NMMetaAccessorSettingInitType init_type); }; struct _NMMetaType { - NMObjBaseClass parent; - const char *type_name; - const char *(*get_name) (const NMMetaAbstractInfo *abstract_info, - gboolean for_header); - const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info, - guint *out_len, - gpointer *out_to_free); - gconstpointer (*get_fcn) (const NMMetaAbstractInfo *info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - gpointer target, - gpointer target_data, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, - gpointer *out_to_free); - const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info, - const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NMMetaOperationContext *operation_context, - const char *text, - gboolean *out_complete_filename, - char ***out_to_free); + NMObjBaseClass parent; + const char * type_name; + const char *(*get_name)(const NMMetaAbstractInfo *abstract_info, gboolean for_header); + const NMMetaAbstractInfo *const *(*get_nested)(const NMMetaAbstractInfo *abstract_info, + guint * out_len, + gpointer * out_to_free); + gconstpointer (*get_fcn)(const NMMetaAbstractInfo * info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + gpointer target, + gpointer target_data, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + NMMetaAccessorGetOutFlags *out_flags, + gboolean * out_is_default, + gpointer * out_to_free); + const char *const *(*complete_fcn)(const NMMetaAbstractInfo * info, + const NMMetaEnvironment * environment, + gpointer environment_user_data, + const NMMetaOperationContext *operation_context, + const char * text, + gboolean * out_complete_filename, + char *** out_to_free); }; struct _NMMetaAbstractInfo { - union { - NMObjBaseInst parent; - const NMMetaType *meta_type; - }; + union { + NMObjBaseInst parent; + const NMMetaType *meta_type; + }; }; extern const NMMetaType nm_meta_type_setting_info_editor; @@ -468,13 +473,15 @@ extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTI extern const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default[]; -const NMMetaSettingValidPartItem *const*nm_meta_setting_info_valid_parts_for_slave_type (const char *slave_type, const char **out_slave_name); +const NMMetaSettingValidPartItem *const * +nm_meta_setting_info_valid_parts_for_slave_type(const char * slave_type, + const char **out_slave_name); /*****************************************************************************/ typedef enum { - NM_META_ENV_WARN_LEVEL_INFO, - NM_META_ENV_WARN_LEVEL_WARN, + NM_META_ENV_WARN_LEVEL_INFO, + NM_META_ENV_WARN_LEVEL_WARN, } NMMetaEnvWarnLevel; /* the settings-meta data is supposed to be independent of an actual client @@ -482,21 +489,21 @@ typedef enum { * The meta-data handlers may call back to the environment with certain * actions. */ struct _NMMetaEnvironment { - - void (*warn_fcn) (const NMMetaEnvironment *environment, - gpointer environment_user_data, - NMMetaEnvWarnLevel warn_level, - const char *fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */ - va_list ap); - - struct _NMDevice *const*(*get_nm_devices) (const NMMetaEnvironment *environment, - gpointer environment_user_data, - guint *out_len); - - struct _NMRemoteConnection *const*(*get_nm_connections) (const NMMetaEnvironment *environment, - gpointer environment_user_data, - guint *out_len); - + void (*warn_fcn)( + const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMMetaEnvWarnLevel warn_level, + const char * + fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */ + va_list ap); + + struct _NMDevice *const *(*get_nm_devices)(const NMMetaEnvironment *environment, + gpointer environment_user_data, + guint * out_len); + + struct _NMRemoteConnection *const *(*get_nm_connections)(const NMMetaEnvironment *environment, + gpointer environment_user_data, + guint * out_len); }; /*****************************************************************************/ @@ -507,27 +514,27 @@ struct _NMMetaEnvironment { extern const NMMetaType nm_meta_type_nested_property_info; -struct _NMMetaNestedPropertyInfo { - union { - const NMMetaType *meta_type; - NMMetaPropertyInfo base; - }; - const NMMetaPropertyInfo *parent_info; +struct _NMMetaNestedPropertyInfo { + union { + const NMMetaType * meta_type; + NMMetaPropertyInfo base; + }; + const NMMetaPropertyInfo *parent_info; }; -struct _NMMetaPropertyTypDataNested { - const NMMetaNestedPropertyInfo *nested; - guint nested_len; +struct _NMMetaPropertyTypDataNested { + const NMMetaNestedPropertyInfo *nested; + guint nested_len; }; extern const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond; /*****************************************************************************/ -gboolean _nm_meta_setting_bond_add_option (NMSetting *setting, - const char *name, - const char *value, - GError **error); +gboolean _nm_meta_setting_bond_add_option(NMSetting * setting, + const char *name, + const char *value, + GError ** error); /*****************************************************************************/ diff --git a/clients/common/nm-polkit-listener.c b/clients/common/nm-polkit-listener.c index ace205e8..c40d8f65 100644 --- a/clients/common/nm-polkit-listener.c +++ b/clients/common/nm-polkit-listener.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2014 Red Hat, Inc. */ @@ -33,847 +33,776 @@ #include "nm-libnm-core-intern/nm-auth-subject.h" #include "c-list/src/c-list.h" -#define LOGIND_BUS_NAME "org.freedesktop.login1" -#define POLKIT_BUS_NAME "org.freedesktop.PolicyKit1" +#define LOGIND_BUS_NAME "org.freedesktop.login1" +#define POLKIT_BUS_NAME "org.freedesktop.PolicyKit1" -#define POLKIT_AUTHORITY_OBJ_PATH "/org/freedesktop/PolicyKit1/Authority" -#define POLKIT_AUTHORITY_IFACE_NAME "org.freedesktop.PolicyKit1.Authority" +#define POLKIT_AUTHORITY_OBJ_PATH "/org/freedesktop/PolicyKit1/Authority" +#define POLKIT_AUTHORITY_IFACE_NAME "org.freedesktop.PolicyKit1.Authority" -#define POLKIT_AGENT_OBJ_PATH "/org/freedesktop/PolicyKit1/AuthenticationAgent" -#define POLKIT_AGENT_DBUS_INTERFACE "org.freedesktop.PolicyKit1.AuthenticationAgent" +#define POLKIT_AGENT_OBJ_PATH "/org/freedesktop/PolicyKit1/AuthenticationAgent" +#define POLKIT_AGENT_DBUS_INTERFACE "org.freedesktop.PolicyKit1.AuthenticationAgent" -#define LOGIND_OBJ_PATH "/org/freedesktop/login1" -#define LOGIND_MANAGER_INTERFACE "org.freedesktop.login1.Manager" +#define LOGIND_OBJ_PATH "/org/freedesktop/login1" +#define LOGIND_MANAGER_INTERFACE "org.freedesktop.login1.Manager" -#define NM_POLKIT_LISTENER_DBUS_CONNECTION "dbus-connection" -#define NM_POLKIT_LISTENER_SESSION_AGENT "session-agent" +#define NM_POLKIT_LISTENER_DBUS_CONNECTION "dbus-connection" +#define NM_POLKIT_LISTENER_SESSION_AGENT "session-agent" -#define POLKIT_DBUS_ERROR_FAILED "org.freedesktop.PolicyKit1.Error.Failed" +#define POLKIT_DBUS_ERROR_FAILED "org.freedesktop.PolicyKit1.Error.Failed" /*****************************************************************************/ -enum { - REGISTERED, - REQUEST_SYNC, - ERROR, - LAST_SIGNAL -}; +enum { REGISTERED, REQUEST_SYNC, ERROR, LAST_SIGNAL }; -static guint signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL] = {0}; struct _NMPolkitListener { - GObject parent; - GDBusConnection *dbus_connection; - char *name_owner; - GCancellable *cancellable; - GMainContext *main_context; - CList request_lst_head; - guint pk_auth_agent_reg_id; - guint name_owner_changed_id; - bool session_agent:1; + GObject parent; + GDBusConnection *dbus_connection; + char * name_owner; + GCancellable * cancellable; + GMainContext * main_context; + CList request_lst_head; + guint pk_auth_agent_reg_id; + guint name_owner_changed_id; + bool session_agent : 1; }; struct _NMPolkitListenerClass { - GObjectClass parent; + GObjectClass parent; }; -G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, G_TYPE_OBJECT); +G_DEFINE_TYPE(NMPolkitListener, nm_polkit_listener, G_TYPE_OBJECT); /*****************************************************************************/ typedef struct { - CList request_lst; - - NMPolkitListener *listener; - GSource *child_stdout_watch_source; - GSource *child_stdin_watch_source; - GDBusMethodInvocation *dbus_invocation; - char *action_id; - char *message; - char *username; - char *cookie; - NMStrBuf in_buffer; - NMStrBuf out_buffer; - gsize out_buffer_offset; - - int child_stdout; - int child_stdin; - - bool request_any_response:1; - bool request_is_completed:1; + CList request_lst; + + NMPolkitListener * listener; + GSource * child_stdout_watch_source; + GSource * child_stdin_watch_source; + GDBusMethodInvocation *dbus_invocation; + char * action_id; + char * message; + char * username; + char * cookie; + NMStrBuf in_buffer; + NMStrBuf out_buffer; + gsize out_buffer_offset; + + int child_stdout; + int child_stdin; + + bool request_any_response : 1; + bool request_is_completed : 1; } AuthRequest; -static const GDBusInterfaceInfo interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT ( - POLKIT_AGENT_DBUS_INTERFACE, - .methods = NM_DEFINE_GDBUS_METHOD_INFOS ( - NM_DEFINE_GDBUS_METHOD_INFO ( - "BeginAuthentication", - .in_args = NM_DEFINE_GDBUS_ARG_INFOS ( - NM_DEFINE_GDBUS_ARG_INFO ("action_id", "s"), - NM_DEFINE_GDBUS_ARG_INFO ("message", "s"), - NM_DEFINE_GDBUS_ARG_INFO ("icon_name", "s"), - NM_DEFINE_GDBUS_ARG_INFO ("details", "a{ss}"), - NM_DEFINE_GDBUS_ARG_INFO ("cookie", "s"), - NM_DEFINE_GDBUS_ARG_INFO ("identities", "a(sa{sv})"), - ), - ), - NM_DEFINE_GDBUS_METHOD_INFO ( - "CancelAuthentication", - .in_args = NM_DEFINE_GDBUS_ARG_INFOS ( - NM_DEFINE_GDBUS_ARG_INFO ("cookie", "s"), - ), - ), - ), -); +static const GDBusInterfaceInfo interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( + POLKIT_AGENT_DBUS_INTERFACE, + .methods = NM_DEFINE_GDBUS_METHOD_INFOS( + NM_DEFINE_GDBUS_METHOD_INFO("BeginAuthentication", + .in_args = NM_DEFINE_GDBUS_ARG_INFOS( + NM_DEFINE_GDBUS_ARG_INFO("action_id", "s"), + NM_DEFINE_GDBUS_ARG_INFO("message", "s"), + NM_DEFINE_GDBUS_ARG_INFO("icon_name", "s"), + NM_DEFINE_GDBUS_ARG_INFO("details", "a{ss}"), + NM_DEFINE_GDBUS_ARG_INFO("cookie", "s"), + NM_DEFINE_GDBUS_ARG_INFO("identities", "a(sa{sv})"), ), ), + NM_DEFINE_GDBUS_METHOD_INFO("CancelAuthentication", + .in_args = NM_DEFINE_GDBUS_ARG_INFOS( + NM_DEFINE_GDBUS_ARG_INFO("cookie", "s"), ), ), ), ); static void -auth_request_complete (AuthRequest *request, gboolean success) +auth_request_complete(AuthRequest *request, gboolean success) { - c_list_unlink (&request->request_lst); - - if (success) - g_dbus_method_invocation_return_value (request->dbus_invocation, NULL); - else { - g_dbus_method_invocation_return_dbus_error (request->dbus_invocation, - POLKIT_DBUS_ERROR_FAILED, - ""); - } - - nm_clear_g_free (&request->action_id); - nm_clear_g_free (&request->message); - nm_clear_g_free (&request->username); - nm_clear_g_free (&request->cookie); - nm_clear_g_source_inst (&request->child_stdout_watch_source); - nm_clear_g_source_inst (&request->child_stdin_watch_source); - - nm_str_buf_destroy (&request->in_buffer); - nm_str_buf_destroy (&request->out_buffer); - - if (request->child_stdout != -1) { - nm_close (request->child_stdout); - request->child_stdout = -1; - } - - if (request->child_stdin != -1) { - nm_close (request->child_stdin); - request->child_stdin = -1; - } - - nm_g_slice_free (request); + c_list_unlink(&request->request_lst); + + if (success) + g_dbus_method_invocation_return_value(request->dbus_invocation, NULL); + else { + g_dbus_method_invocation_return_dbus_error(request->dbus_invocation, + POLKIT_DBUS_ERROR_FAILED, + ""); + } + + nm_clear_g_free(&request->action_id); + nm_clear_g_free(&request->message); + nm_clear_g_free(&request->username); + nm_clear_g_free(&request->cookie); + nm_clear_g_source_inst(&request->child_stdout_watch_source); + nm_clear_g_source_inst(&request->child_stdin_watch_source); + + nm_str_buf_destroy(&request->in_buffer); + nm_str_buf_destroy(&request->out_buffer); + + if (request->child_stdout != -1) { + nm_close(request->child_stdout); + request->child_stdout = -1; + } + + if (request->child_stdin != -1) { + nm_close(request->child_stdin); + request->child_stdin = -1; + } + + nm_g_slice_free(request); } static gboolean -uid_to_name (uid_t uid, - const char **out_name) +uid_to_name(uid_t uid, gboolean *out_cached, char **out_name) { - const struct passwd *passwd; - - if (*out_name) - return TRUE; - - passwd = getpwuid (uid); - if ( !passwd - || !passwd->pw_name) - return FALSE; - - *out_name = passwd->pw_name; - return TRUE; + if (!*out_cached) { + *out_cached = TRUE; + *out_name = nm_utils_uid_to_name(uid); + } + return !!(*out_name); } static char * -choose_identity (GVariant *identities) +choose_identity(GVariant *identities) { - GVariantIter identity_iter; - GVariant *details_tmp; - const char *kind; - gs_free char *username_first = NULL; - gs_free char *username_root = NULL; - const char *user; - - /* Choose identity. First try current user, then root, and else - * take the first one we find. */ - - user = getenv ("USER"); - - g_variant_iter_init (&identity_iter, identities); - while (g_variant_iter_next (&identity_iter, "(&s@a{sv})", &kind, &details_tmp)) { - gs_unref_variant GVariant *details = g_steal_pointer (&details_tmp); - - if (nm_streq (kind, "unix-user")) { - gs_unref_variant GVariant *v = NULL; - - v = g_variant_lookup_value (details, "uid", G_VARIANT_TYPE_UINT32); - if (v) { - guint32 uid = g_variant_get_uint32 (v); - const char *u = NULL; - - if (user) { - if (!uid_to_name (uid, &u)) - continue; - if (nm_streq (u, user)) - return g_strdup (user); - } - if ( !username_root - && uid == 0) { - if (!uid_to_name (uid, &u)) - continue; - username_root = g_strdup (u); - if (!user) - break; - } - if ( !username_root - && !username_first) { - if (!uid_to_name (uid, &u)) - continue; - username_first = g_strdup (u); - } - } - } - } - - if (username_root) - return g_steal_pointer (&username_root); - - if (username_first) - return g_steal_pointer (&username_first); - - return NULL; + GVariantIter identity_iter; + GVariant * details_tmp; + const char * kind; + gs_free char *username_first = NULL; + gs_free char *username_root = NULL; + const char * user; + + /* Choose identity. First try current user, then root, and else + * take the first one we find. */ + + user = getenv("USER"); + + g_variant_iter_init(&identity_iter, identities); + while (g_variant_iter_next(&identity_iter, "(&s@a{sv})", &kind, &details_tmp)) { + gs_unref_variant GVariant *details = g_steal_pointer(&details_tmp); + + if (nm_streq(kind, "unix-user")) { + gs_unref_variant GVariant *v = NULL; + + v = g_variant_lookup_value(details, "uid", G_VARIANT_TYPE_UINT32); + if (v) { + guint32 uid = g_variant_get_uint32(v); + gs_free char *u = NULL; + gboolean cached = FALSE; + + if (user) { + if (!uid_to_name(uid, &cached, &u)) + continue; + if (nm_streq(u, user)) + return g_steal_pointer(&u); + } + if (!username_root && uid == 0) { + if (!uid_to_name(uid, &cached, &u)) + continue; + username_root = g_strdup(u); + if (!user) + break; + } + if (!username_root && !username_first) { + if (!uid_to_name(uid, &cached, &u)) + continue; + username_first = g_strdup(u); + } + } + } + } + + if (username_root) + return g_steal_pointer(&username_root); + + if (username_first) + return g_steal_pointer(&username_first); + + return NULL; } static void -agent_register_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +agent_register_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMPolkitListener *listener = NM_POLKIT_LISTENER (user_data); - GDBusConnection *dbus_connection = G_DBUS_CONNECTION (source_object); - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; - - ret = g_dbus_connection_call_finish (dbus_connection, - res, - &error); - - if (nm_utils_error_is_cancelled (error)) { - return; - } - - if (ret) { - g_signal_emit (listener, - signals[REGISTERED], - 0); - } else { - g_signal_emit (listener, - signals[ERROR], - 0, - error->message); - } + NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); + GDBusConnection * dbus_connection = G_DBUS_CONNECTION(source_object); + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; + + ret = g_dbus_connection_call_finish(dbus_connection, res, &error); + + if (nm_utils_error_is_cancelled(error)) { + return; + } + + if (ret) { + g_signal_emit(listener, signals[REGISTERED], 0); + } else { + g_signal_emit(listener, signals[ERROR], 0, error->message); + } } static void -agent_register (NMPolkitListener *self, const char *session_id) +agent_register(NMPolkitListener *self, const char *session_id) { - const char *locale = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - GVariant *subject_variant = NULL; - - locale = g_getenv ("LANG"); - if (locale == NULL) { - locale = "en_US.UTF-8"; - } - - if (self->session_agent) { - subject = nm_auth_subject_new_unix_session (session_id); - } else { - subject = nm_auth_subject_new_unix_process_self (); - } - subject_variant = nm_auth_subject_unix_to_polkit_gvariant (subject); - - g_dbus_connection_call (self->dbus_connection, - self->name_owner, - POLKIT_AUTHORITY_OBJ_PATH, - POLKIT_AUTHORITY_IFACE_NAME, - "RegisterAuthenticationAgent", - g_variant_new ("(@(sa{sv})ss)", - subject_variant, - locale, - POLKIT_AGENT_OBJ_PATH), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - self->cancellable, - agent_register_cb, - self); + const char * locale = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + GVariant * subject_variant = NULL; + + locale = g_getenv("LANG"); + if (locale == NULL) { + locale = "en_US.UTF-8"; + } + + if (self->session_agent) { + subject = nm_auth_subject_new_unix_session(session_id); + } else { + subject = nm_auth_subject_new_unix_process_self(); + } + subject_variant = nm_auth_subject_unix_to_polkit_gvariant(subject); + + g_dbus_connection_call( + self->dbus_connection, + self->name_owner, + POLKIT_AUTHORITY_OBJ_PATH, + POLKIT_AUTHORITY_IFACE_NAME, + "RegisterAuthenticationAgent", + g_variant_new("(@(sa{sv})ss)", subject_variant, locale, POLKIT_AGENT_OBJ_PATH), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + self->cancellable, + agent_register_cb, + self); } static void -agent_unregister (NMPolkitListener *self) +agent_unregister(NMPolkitListener *self) { - gs_unref_object NMAuthSubject *subject = NULL; - GVariant *subject_variant = NULL; - - subject = nm_auth_subject_new_unix_process_self (); - subject_variant = nm_auth_subject_unix_to_polkit_gvariant (subject); - - g_dbus_connection_call (self->dbus_connection, - self->name_owner, - POLKIT_AUTHORITY_OBJ_PATH, - POLKIT_AUTHORITY_IFACE_NAME, - "UnregisterAuthenticationAgent", - g_variant_new ("(@(sa{sv})s)", - subject_variant, - POLKIT_AGENT_OBJ_PATH), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - self); + gs_unref_object NMAuthSubject *subject = NULL; + GVariant * subject_variant = NULL; + + subject = nm_auth_subject_new_unix_process_self(); + subject_variant = nm_auth_subject_unix_to_polkit_gvariant(subject); + + g_dbus_connection_call(self->dbus_connection, + self->name_owner, + POLKIT_AUTHORITY_OBJ_PATH, + POLKIT_AUTHORITY_IFACE_NAME, + "UnregisterAuthenticationAgent", + g_variant_new("(@(sa{sv})s)", subject_variant, POLKIT_AGENT_OBJ_PATH), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + self); } static void -retrieve_session_id_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +retrieve_session_id_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMPolkitListener *listener = NM_POLKIT_LISTENER (user_data); - char *session_id; - guint32 session_uid; - nm_auto_free_variant_iter GVariantIter *iter = NULL; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - gs_free char *err_str = NULL; - uid_t uid = getuid (); - - ret = g_dbus_connection_call_finish (listener->dbus_connection, - res, - &error); - - if (nm_utils_error_is_cancelled (error)) { - return; - } - - if (ret) { - g_variant_get_child (ret, 0, "a(susso)", &iter); - - while (g_variant_iter_next (iter, "(&su@s@s@o)", - &session_id, - &session_uid, - NULL, NULL, NULL)) { - if (session_uid == uid) { - agent_register (listener, session_id); - return; - } - } - err_str = g_strdup_printf (_("Could not find any session id for uid %d"), uid); - } else { - err_str = g_strdup_printf (_("Could not retrieve session id: %s"), - error->message); - } - - g_signal_emit (listener, - signals[ERROR], - 0, - err_str); + NMPolkitListener * listener = NM_POLKIT_LISTENER(user_data); + char * session_id; + guint32 session_uid; + nm_auto_free_variant_iter GVariantIter *iter = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + gs_free char * err_str = NULL; + uid_t uid = getuid(); + + ret = g_dbus_connection_call_finish(listener->dbus_connection, res, &error); + + if (nm_utils_error_is_cancelled(error)) { + return; + } + + if (ret) { + g_variant_get_child(ret, 0, "a(susso)", &iter); + + while ( + g_variant_iter_next(iter, "(&su@s@s@o)", &session_id, &session_uid, NULL, NULL, NULL)) { + if (session_uid == uid) { + agent_register(listener, session_id); + return; + } + } + err_str = g_strdup_printf(_("Could not find any session id for uid %d"), uid); + } else { + err_str = g_strdup_printf(_("Could not retrieve session id: %s"), error->message); + } + + g_signal_emit(listener, signals[ERROR], 0, err_str); } static void -retrieve_session_id (NMPolkitListener *self) +retrieve_session_id(NMPolkitListener *self) { - g_dbus_connection_call (self->dbus_connection, - LOGIND_BUS_NAME, - LOGIND_OBJ_PATH, - LOGIND_MANAGER_INTERFACE, - "ListSessions", - NULL, - G_VARIANT_TYPE ("(a(susso))"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->cancellable, - retrieve_session_id_cb, - self); + g_dbus_connection_call(self->dbus_connection, + LOGIND_BUS_NAME, + LOGIND_OBJ_PATH, + LOGIND_MANAGER_INTERFACE, + "ListSessions", + NULL, + G_VARIANT_TYPE("(a(susso))"), + G_DBUS_CALL_FLAGS_NONE, + -1, + self->cancellable, + retrieve_session_id_cb, + self); } static gboolean -io_watch_can_write (int fd, - GIOCondition condition, - gpointer user_data) +io_watch_can_write(int fd, GIOCondition condition, gpointer user_data) { - AuthRequest *request = user_data; - gssize n_written; + AuthRequest *request = user_data; + gssize n_written; - if (NM_FLAGS_ANY (condition, (G_IO_HUP | G_IO_ERR))) - goto done; + if (NM_FLAGS_ANY(condition, (G_IO_HUP | G_IO_ERR))) + goto done; - n_written = write (request->child_stdin, - &((nm_str_buf_get_str_unsafe (&request->out_buffer))[request->out_buffer_offset]), - request->out_buffer.len - request->out_buffer_offset); + n_written = + write(request->child_stdin, + &((nm_str_buf_get_str_unsafe(&request->out_buffer))[request->out_buffer_offset]), + request->out_buffer.len - request->out_buffer_offset); - if ( n_written < 0 - && errno != EAGAIN) - goto done; + if (n_written < 0 && errno != EAGAIN) + goto done; - if (n_written > 0) { - if ((gsize) n_written >= (request->out_buffer.len - request->out_buffer_offset)) { - nm_assert ((gsize) n_written == (request->out_buffer.len - request->out_buffer_offset)); - goto done; - } - request->out_buffer_offset += (gsize) n_written; - } + if (n_written > 0) { + if ((gsize) n_written >= (request->out_buffer.len - request->out_buffer_offset)) { + nm_assert((gsize) n_written == (request->out_buffer.len - request->out_buffer_offset)); + goto done; + } + request->out_buffer_offset += (gsize) n_written; + } - return G_SOURCE_CONTINUE; + return G_SOURCE_CONTINUE; done: - nm_str_buf_set_size (&request->out_buffer, 0, TRUE, FALSE); - request->out_buffer_offset = 0; - nm_clear_g_source_inst (&request->child_stdin_watch_source); + nm_str_buf_set_size(&request->out_buffer, 0, TRUE, FALSE); + request->out_buffer_offset = 0; + nm_clear_g_source_inst(&request->child_stdin_watch_source); - if (request->request_is_completed) - auth_request_complete (request, TRUE); + if (request->request_is_completed) + auth_request_complete(request, TRUE); - return G_SOURCE_CONTINUE; + return G_SOURCE_CONTINUE; } static void -queue_string_to_helper (AuthRequest *request, const char *response) +queue_string_to_helper(AuthRequest *request, const char *response) { - g_return_if_fail (response); - - if (!nm_str_buf_is_initalized (&request->out_buffer)) - nm_str_buf_init (&request->out_buffer, strlen (response) + 2u, TRUE); - - nm_str_buf_append (&request->out_buffer, response); - nm_str_buf_ensure_trailing_c (&request->out_buffer, '\n'); - - if (!request->child_stdin_watch_source) { - request->child_stdin_watch_source = nm_g_unix_fd_source_new (request->child_stdin, - G_IO_OUT | G_IO_ERR | G_IO_HUP, - G_PRIORITY_DEFAULT, - io_watch_can_write, - request, - NULL); - g_source_attach (request->child_stdin_watch_source, - request->listener->main_context); - } + g_return_if_fail(response); + + if (!nm_str_buf_is_initalized(&request->out_buffer)) + nm_str_buf_init(&request->out_buffer, strlen(response) + 2u, TRUE); + + nm_str_buf_append(&request->out_buffer, response); + nm_str_buf_ensure_trailing_c(&request->out_buffer, '\n'); + + if (!request->child_stdin_watch_source) { + request->child_stdin_watch_source = nm_g_unix_fd_source_new(request->child_stdin, + G_IO_OUT | G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + io_watch_can_write, + request, + NULL); + g_source_attach(request->child_stdin_watch_source, request->listener->main_context); + } } static gboolean -io_watch_have_data (int fd, - GIOCondition condition, - gpointer user_data) +io_watch_have_data(int fd, GIOCondition condition, gpointer user_data) { - AuthRequest *request = user_data; - gboolean auth_result; - gssize n_read; - - if (NM_FLAGS_ANY (condition, G_IO_HUP | G_IO_ERR)) - n_read = -EIO; - else - n_read = nm_utils_fd_read (fd, &request->in_buffer); - - if (n_read <= 0) { - if (n_read == -EAGAIN) { - /* wait longer. */ - return G_SOURCE_CONTINUE; - } - - /* Either an error or EOF happened. The data we parsed so far was not relevant. - * Regardless of what we still have unprocessed in the receive buffers, we are done. - * - * We would expect that the other side completed with SUCCESS or FAILURE. Apparently - * it didn't. If we had any good request, we assume success. */ - auth_result = request->request_any_response; - goto out; - } - - while (TRUE) { - char *line_terminator; - const char *line; - - line = nm_str_buf_get_str (&request->in_buffer); - line_terminator = (char *) strchr (line, '\n'); - if (!line_terminator) { - /* We don't have a complete line. Wait longer. */ - return G_SOURCE_CONTINUE; - } - line_terminator[0] = '\0'; - - if ( NM_STR_HAS_PREFIX (line, "PAM_PROMPT_ECHO_OFF ") - || NM_STR_HAS_PREFIX (line, "PAM_PROMPT_ECHO_ON ")) { - nm_auto_free_secret char *response = NULL; - - /* FIXME(cli-async): emit signal and wait for response (blocking) */ - g_signal_emit (request->listener, - signals[REQUEST_SYNC], - 0, - request->action_id, - request->message, - request->username, - &response); - - if (response) { - queue_string_to_helper (request, response); - request->request_any_response = TRUE; - goto erase_line; - } - auth_result = FALSE; - } else if (nm_streq (line, "SUCCESS")) - auth_result = TRUE; - else if (nm_streq (line, "FAILURE")) - auth_result = FALSE; - else if ( NM_STR_HAS_PREFIX (line, "PAM_ERROR_MSG ") - || NM_STR_HAS_PREFIX (line, "PAM_TEXT_INFO ")) { - /* ignore. */ - goto erase_line; - } else { - /* unknown command. Fail. */ - auth_result = FALSE; - } - - break; + AuthRequest *request = user_data; + gboolean auth_result; + gssize n_read; + + if (NM_FLAGS_ANY(condition, G_IO_HUP | G_IO_ERR)) + n_read = -EIO; + else + n_read = nm_utils_fd_read(fd, &request->in_buffer); + + if (n_read <= 0) { + if (n_read == -EAGAIN) { + /* wait longer. */ + return G_SOURCE_CONTINUE; + } + + /* Either an error or EOF happened. The data we parsed so far was not relevant. + * Regardless of what we still have unprocessed in the receive buffers, we are done. + * + * We would expect that the other side completed with SUCCESS or FAILURE. Apparently + * it didn't. If we had any good request, we assume success. */ + auth_result = request->request_any_response; + goto out; + } + + while (TRUE) { + char * line_terminator; + const char *line; + + line = nm_str_buf_get_str(&request->in_buffer); + line_terminator = (char *) strchr(line, '\n'); + if (!line_terminator) { + /* We don't have a complete line. Wait longer. */ + return G_SOURCE_CONTINUE; + } + line_terminator[0] = '\0'; + + if (NM_STR_HAS_PREFIX(line, "PAM_PROMPT_ECHO_OFF ") + || NM_STR_HAS_PREFIX(line, "PAM_PROMPT_ECHO_ON ")) { + nm_auto_free_secret char *response = NULL; + + /* FIXME(cli-async): emit signal and wait for response (blocking) */ + g_signal_emit(request->listener, + signals[REQUEST_SYNC], + 0, + request->action_id, + request->message, + request->username, + &response); + + if (response) { + queue_string_to_helper(request, response); + request->request_any_response = TRUE; + goto erase_line; + } + auth_result = FALSE; + } else if (nm_streq(line, "SUCCESS")) + auth_result = TRUE; + else if (nm_streq(line, "FAILURE")) + auth_result = FALSE; + else if (NM_STR_HAS_PREFIX(line, "PAM_ERROR_MSG ") + || NM_STR_HAS_PREFIX(line, "PAM_TEXT_INFO ")) { + /* ignore. */ + goto erase_line; + } else { + /* unknown command. Fail. */ + auth_result = FALSE; + } + + break; erase_line: - nm_str_buf_erase (&request->in_buffer, 0, line_terminator - line + 1u, TRUE); - } + nm_str_buf_erase(&request->in_buffer, 0, line_terminator - line + 1u, TRUE); + } out: - request->request_is_completed = TRUE; - nm_clear_g_source_inst (&request->child_stdout_watch_source); - if ( auth_result - && request->child_stdin_watch_source) { - /* we need to wait for the buffer to send the response. */ - } else - auth_request_complete (request, auth_result); - - return G_SOURCE_CONTINUE; + request->request_is_completed = TRUE; + nm_clear_g_source_inst(&request->child_stdout_watch_source); + if (auth_result && request->child_stdin_watch_source) { + /* we need to wait for the buffer to send the response. */ + } else + auth_request_complete(request, auth_result); + + return G_SOURCE_CONTINUE; } static void -begin_authentication (AuthRequest *request) +begin_authentication(AuthRequest *request) { - int fd_flags; - const char *helper_argv[] = { - POLKIT_PACKAGE_PREFIX "/lib/polkit-1/polkit-agent-helper-1", - request->username, - NULL, - }; - - if (!request->username) { - auth_request_complete (request, FALSE); - return; - } - - if (!g_spawn_async_with_pipes (NULL, - (char **) helper_argv, - NULL, - G_SPAWN_STDERR_TO_DEV_NULL, - NULL, - NULL, - NULL, - &request->child_stdin, - &request->child_stdout, - NULL, - NULL)) { - /* not findind the PolicyKit setuid helper is a critical error */ - request->child_stdin = -1; - request->child_stdout = -1; - g_signal_emit (request->listener, - signals[ERROR], - 0, - "The PolicyKit setuid helper 'polkit-agent-helper-1' has not been found"); - - auth_request_complete (request, FALSE); - return; - } - - fd_flags = fcntl (request->child_stdin, F_GETFD, 0); - fcntl (request->child_stdin, F_SETFL, fd_flags | O_NONBLOCK); - - fd_flags = fcntl (request->child_stdout, F_GETFD, 0); - fcntl (request->child_stdout, F_SETFL, fd_flags | O_NONBLOCK); - - request->child_stdout_watch_source = nm_g_unix_fd_source_new (request->child_stdout, - G_IO_IN | G_IO_ERR | G_IO_HUP, - G_PRIORITY_DEFAULT, - io_watch_have_data, - request, - NULL); - g_source_attach (request->child_stdout_watch_source, - request->listener->main_context); - - /* Write the cookie on stdin so it can't be seen by other processes */ - queue_string_to_helper (request, request->cookie); - - return; + int fd_flags; + const char *helper_argv[] = { + POLKIT_PACKAGE_PREFIX "/lib/polkit-1/polkit-agent-helper-1", + request->username, + NULL, + }; + + if (!request->username) { + auth_request_complete(request, FALSE); + return; + } + + if (!g_spawn_async_with_pipes(NULL, + (char **) helper_argv, + NULL, + G_SPAWN_STDERR_TO_DEV_NULL, + NULL, + NULL, + NULL, + &request->child_stdin, + &request->child_stdout, + NULL, + NULL)) { + /* not findind the PolicyKit setuid helper is a critical error */ + request->child_stdin = -1; + request->child_stdout = -1; + g_signal_emit(request->listener, + signals[ERROR], + 0, + "The PolicyKit setuid helper 'polkit-agent-helper-1' has not been found"); + + auth_request_complete(request, FALSE); + return; + } + + fd_flags = fcntl(request->child_stdin, F_GETFD, 0); + fcntl(request->child_stdin, F_SETFL, fd_flags | O_NONBLOCK); + + fd_flags = fcntl(request->child_stdout, F_GETFD, 0); + fcntl(request->child_stdout, F_SETFL, fd_flags | O_NONBLOCK); + + request->child_stdout_watch_source = nm_g_unix_fd_source_new(request->child_stdout, + G_IO_IN | G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + io_watch_have_data, + request, + NULL); + g_source_attach(request->child_stdout_watch_source, request->listener->main_context); + + /* Write the cookie on stdin so it can't be seen by other processes */ + queue_string_to_helper(request, request->cookie); + + return; } -static AuthRequest* -get_request (NMPolkitListener *listener, - const char *cookie) +static AuthRequest * +get_request(NMPolkitListener *listener, const char *cookie) { - AuthRequest *request; - - c_list_for_each_entry (request, &listener->request_lst_head, request_lst) { - if (nm_streq0 (cookie, request->cookie)) { - return request; - } - } - return NULL; + AuthRequest *request; + + c_list_for_each_entry (request, &listener->request_lst_head, request_lst) { + if (nm_streq0(cookie, request->cookie)) { + return request; + } + } + return NULL; } -static AuthRequest* -create_request (NMPolkitListener *listener, - GDBusMethodInvocation *invocation, - const char *action_id, - const char *message, - char *username_take, - const char *cookie) +static AuthRequest * +create_request(NMPolkitListener * listener, + GDBusMethodInvocation *invocation, + const char * action_id, + const char * message, + char * username_take, + const char * cookie) { - AuthRequest *request; - - request = g_slice_new (AuthRequest); - *request = (AuthRequest) { - .listener = listener, - .dbus_invocation = invocation, - .action_id = g_strdup (action_id), - .message = g_strdup (message), - .username = g_steal_pointer (&username_take), - .cookie = g_strdup (cookie), - .request_any_response = FALSE, - .request_is_completed = FALSE, - }; - - nm_str_buf_init (&request->in_buffer, NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE); - - c_list_link_tail (&listener->request_lst_head, &request->request_lst); - return request; + AuthRequest *request; + + request = g_slice_new(AuthRequest); + *request = (AuthRequest){ + .listener = listener, + .dbus_invocation = invocation, + .action_id = g_strdup(action_id), + .message = g_strdup(message), + .username = g_steal_pointer(&username_take), + .cookie = g_strdup(cookie), + .request_any_response = FALSE, + .request_is_completed = FALSE, + }; + + nm_str_buf_init(&request->in_buffer, NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE); + + c_list_link_tail(&listener->request_lst_head, &request->request_lst); + return request; } static void -dbus_method_call_cb (GDBusConnection *connection, - const char *sender, - const char *object_path, - const char *interface_name, - const char *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) +dbus_method_call_cb(GDBusConnection * connection, + const char * sender, + const char * object_path, + const char * interface_name, + const char * method_name, + GVariant * parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) { - NMPolkitListener *listener = NM_POLKIT_LISTENER (user_data); - const char *action_id; - const char *message; - const char *cookie; - AuthRequest *request; - gs_unref_variant GVariant *identities_gvariant = NULL; - - if (nm_streq (method_name, "BeginAuthentication")) { - g_variant_get (parameters, - "(&s&s&s@a{ss}&s@a(sa{sv}))", - &action_id, - &message, - NULL, - NULL, - &cookie, - &identities_gvariant); - - request = create_request (listener, - invocation, - action_id, - message, - choose_identity (identities_gvariant), - cookie); - begin_authentication (request); - return; - } - - if (nm_streq (method_name, "CancelAuthentication")) { - g_variant_get (parameters, - "&s", - &cookie); - request = get_request (listener, cookie); - - if (!request) { - gs_free char *msg = NULL; - - msg = g_strdup_printf ("No pending authentication request for cookie '%s'", - cookie); - g_dbus_method_invocation_return_dbus_error (invocation, - POLKIT_DBUS_ERROR_FAILED, - msg); - return; - } - - /* Complete a cancelled request with success. */ - auth_request_complete (request, TRUE); - return; - } - - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_UNKNOWN_METHOD, - "Unknown method %s", - method_name); + NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); + const char * action_id; + const char * message; + const char * cookie; + AuthRequest * request; + gs_unref_variant GVariant *identities_gvariant = NULL; + + if (nm_streq(method_name, "BeginAuthentication")) { + g_variant_get(parameters, + "(&s&s&s@a{ss}&s@a(sa{sv}))", + &action_id, + &message, + NULL, + NULL, + &cookie, + &identities_gvariant); + + request = create_request(listener, + invocation, + action_id, + message, + choose_identity(identities_gvariant), + cookie); + begin_authentication(request); + return; + } + + if (nm_streq(method_name, "CancelAuthentication")) { + g_variant_get(parameters, "&s", &cookie); + request = get_request(listener, cookie); + + if (!request) { + gs_free char *msg = NULL; + + msg = g_strdup_printf("No pending authentication request for cookie '%s'", cookie); + g_dbus_method_invocation_return_dbus_error(invocation, POLKIT_DBUS_ERROR_FAILED, msg); + return; + } + + /* Complete a cancelled request with success. */ + auth_request_complete(request, TRUE); + return; + } + + g_dbus_method_invocation_return_error(invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_UNKNOWN_METHOD, + "Unknown method %s", + method_name); } static gboolean -export_dbus_iface (NMPolkitListener *self, GError **error) +export_dbus_iface(NMPolkitListener *self, GError **error) { - GDBusInterfaceVTable interface_vtable = { - .method_call = dbus_method_call_cb, - .set_property = NULL, - .get_property = NULL, - }; - - g_return_val_if_fail (NM_IS_POLKIT_LISTENER (self), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* Agent listener iface has been exported already */ - if (self->pk_auth_agent_reg_id) { - return TRUE; - } - - self->pk_auth_agent_reg_id = - g_dbus_connection_register_object (self->dbus_connection, - POLKIT_AGENT_OBJ_PATH, - (GDBusInterfaceInfo*) &interface_info, - &interface_vtable, - self, - NULL, - error); - if (!self->pk_auth_agent_reg_id) { - g_signal_emit (self, - signals[ERROR], - 0, - "Could not register as a PolicyKit Authentication Agent"); - } - return self->pk_auth_agent_reg_id; + GDBusInterfaceVTable interface_vtable = { + .method_call = dbus_method_call_cb, + .set_property = NULL, + .get_property = NULL, + }; + + g_return_val_if_fail(NM_IS_POLKIT_LISTENER(self), FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* Agent listener iface has been exported already */ + if (self->pk_auth_agent_reg_id) { + return TRUE; + } + + self->pk_auth_agent_reg_id = + g_dbus_connection_register_object(self->dbus_connection, + POLKIT_AGENT_OBJ_PATH, + (GDBusInterfaceInfo *) &interface_info, + &interface_vtable, + self, + NULL, + error); + if (!self->pk_auth_agent_reg_id) { + g_signal_emit(self, + signals[ERROR], + 0, + "Could not register as a PolicyKit Authentication Agent"); + } + return self->pk_auth_agent_reg_id; } static void -name_owner_changed (NMPolkitListener *self, - const char *name_owner) +name_owner_changed(NMPolkitListener *self, const char *name_owner) { - gs_free_error GError *error = NULL; - - name_owner = nm_str_not_empty (name_owner); - - if (nm_streq0 (self->name_owner, name_owner)) { - return; - } - - g_free (self->name_owner); - self->name_owner = g_strdup (name_owner); - - if (!self->name_owner) { - return; - } - - if (export_dbus_iface (self, &error)) { - if (self->session_agent) { - retrieve_session_id (self); - } else { - agent_register (self, NULL); - } - } else { - g_signal_emit (self, - signals[ERROR], - 0, - "Could not export the PolicyKit Authentication Agent DBus interface"); - } + gs_free_error GError *error = NULL; + + name_owner = nm_str_not_empty(name_owner); + + if (nm_streq0(self->name_owner, name_owner)) { + return; + } + + g_free(self->name_owner); + self->name_owner = g_strdup(name_owner); + + if (!self->name_owner) { + return; + } + + if (export_dbus_iface(self, &error)) { + if (self->session_agent) { + retrieve_session_id(self); + } else { + agent_register(self, NULL); + } + } else { + g_signal_emit(self, + signals[ERROR], + 0, + "Could not export the PolicyKit Authentication Agent DBus interface"); + } } static void -name_owner_changed_cb (GDBusConnection *connection, - const char *sender_name, - const char *object_path, - const char *interface_name, - const char *signal_name, - GVariant *parameters, - gpointer user_data) +name_owner_changed_cb(GDBusConnection *connection, + const char * sender_name, + const char * object_path, + const char * interface_name, + const char * signal_name, + GVariant * parameters, + gpointer user_data) { - NMPolkitListener *self = user_data; - const char *new_owner; + NMPolkitListener *self = user_data; + const char * new_owner; - if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sss)"))) { - return; - } + if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { + return; + } - g_variant_get (parameters, - "(&s&s&s)", - NULL, - NULL, - &new_owner); + g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_owner); - name_owner_changed (self, new_owner); + name_owner_changed(self, new_owner); } static void -get_name_owner_cb (const char *name_owner, - GError *error, - gpointer user_data) +get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) { - if (!name_owner && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - return; - } - name_owner_changed (user_data, name_owner); + if (!name_owner && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + return; + } + name_owner_changed(user_data, name_owner); } /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE (NMPolkitListener, - PROP_DBUS_CONNECTION, - PROP_SESSION_AGENT, -); +NM_GOBJECT_PROPERTIES_DEFINE(NMPolkitListener, PROP_DBUS_CONNECTION, PROP_SESSION_AGENT, ); static void -set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMPolkitListener *self = NM_POLKIT_LISTENER (object); - - switch (prop_id) { - case PROP_DBUS_CONNECTION: - self->dbus_connection = g_value_dup_object (value); - break; - case PROP_SESSION_AGENT: - self->session_agent = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + NMPolkitListener *self = NM_POLKIT_LISTENER(object); + + switch (prop_id) { + case PROP_DBUS_CONNECTION: + self->dbus_connection = g_value_dup_object(value); + break; + case PROP_SESSION_AGENT: + self->session_agent = g_value_get_boolean(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void -nm_polkit_listener_init (NMPolkitListener *self) +nm_polkit_listener_init(NMPolkitListener *self) { - c_list_init (&self->request_lst_head); - self->main_context = g_main_context_ref_thread_default (); + c_list_init(&self->request_lst_head); + self->main_context = g_main_context_ref_thread_default(); } static void -constructed (GObject *object) +constructed(GObject *object) { - NMPolkitListener *self = NM_POLKIT_LISTENER (object); + NMPolkitListener *self = NM_POLKIT_LISTENER(object); - self->cancellable = g_cancellable_new (); + self->cancellable = g_cancellable_new(); - self->name_owner_changed_id = - nm_dbus_connection_signal_subscribe_name_owner_changed (self->dbus_connection, - POLKIT_BUS_NAME, - name_owner_changed_cb, - self, - NULL); + self->name_owner_changed_id = + nm_dbus_connection_signal_subscribe_name_owner_changed(self->dbus_connection, + POLKIT_BUS_NAME, + name_owner_changed_cb, + self, + NULL); - nm_dbus_connection_call_get_name_owner (self->dbus_connection, - POLKIT_BUS_NAME, - -1, - self->cancellable, - get_name_owner_cb, - self); + nm_dbus_connection_call_get_name_owner(self->dbus_connection, + POLKIT_BUS_NAME, + -1, + self->cancellable, + get_name_owner_cb, + self); - G_OBJECT_CLASS (nm_polkit_listener_parent_class)->constructed (object); + G_OBJECT_CLASS(nm_polkit_listener_parent_class)->constructed(object); } /** @@ -886,101 +815,96 @@ constructed (GObject *object) * Returns: a new #NMPolkitListener */ NMPolkitListener * -nm_polkit_listener_new (GDBusConnection *dbus_connection, gboolean session_agent) +nm_polkit_listener_new(GDBusConnection *dbus_connection, gboolean session_agent) { - return g_object_new (NM_TYPE_POLKIT_LISTENER, - NM_POLKIT_LISTENER_DBUS_CONNECTION, dbus_connection, - NM_POLKIT_LISTENER_SESSION_AGENT, session_agent, - NULL); + return g_object_new(NM_TYPE_POLKIT_LISTENER, + NM_POLKIT_LISTENER_DBUS_CONNECTION, + dbus_connection, + NM_POLKIT_LISTENER_SESSION_AGENT, + session_agent, + NULL); } static void -dispose (GObject *object) +dispose(GObject *object) { - NMPolkitListener *self = NM_POLKIT_LISTENER (object); - AuthRequest *request; + NMPolkitListener *self = NM_POLKIT_LISTENER(object); + AuthRequest * request; - nm_clear_g_cancellable (&self->cancellable); + nm_clear_g_cancellable(&self->cancellable); - while ((request = c_list_first_entry (&self->request_lst_head, AuthRequest, request_lst))) - auth_request_complete (request, FALSE); + while ((request = c_list_first_entry(&self->request_lst_head, AuthRequest, request_lst))) + auth_request_complete(request, FALSE); - if (self->dbus_connection) { - nm_clear_g_dbus_connection_signal (self->dbus_connection, - &self->name_owner_changed_id); - g_dbus_connection_unregister_object (self->dbus_connection, - self->pk_auth_agent_reg_id); - agent_unregister (self); - nm_clear_g_free (&self->name_owner); - g_clear_object (&self->dbus_connection); - } + if (self->dbus_connection) { + nm_clear_g_dbus_connection_signal(self->dbus_connection, &self->name_owner_changed_id); + g_dbus_connection_unregister_object(self->dbus_connection, self->pk_auth_agent_reg_id); + agent_unregister(self); + nm_clear_g_free(&self->name_owner); + g_clear_object(&self->dbus_connection); + } - nm_clear_pointer (&self->main_context, g_main_context_unref); + nm_clear_pointer(&self->main_context, g_main_context_unref); - G_OBJECT_CLASS (nm_polkit_listener_parent_class)->dispose (object); + G_OBJECT_CLASS(nm_polkit_listener_parent_class)->dispose(object); } static void -nm_polkit_listener_class_init (NMPolkitListenerClass *klass) +nm_polkit_listener_class_init(NMPolkitListenerClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = set_property; - object_class->constructed = constructed; - object_class->dispose = dispose; - - obj_properties[PROP_DBUS_CONNECTION] = - g_param_spec_object (NM_POLKIT_LISTENER_DBUS_CONNECTION, "", "", - G_TYPE_DBUS_CONNECTION, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_SESSION_AGENT] = - g_param_spec_boolean (NM_POLKIT_LISTENER_SESSION_AGENT, "", "", - FALSE, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, - _PROPERTY_ENUMS_LAST, - obj_properties); - - signals[REQUEST_SYNC] = - g_signal_new (NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC, - NM_TYPE_POLKIT_LISTENER, - G_SIGNAL_RUN_LAST, - 0, - NULL, - NULL, - NULL, - G_TYPE_STRING, - 3, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); - - signals[REGISTERED] = - g_signal_new (NM_POLKIT_LISTENER_SIGNAL_REGISTERED, - NM_TYPE_POLKIT_LISTENER, - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 0); - - signals[ERROR] = - g_signal_new (NM_POLKIT_LISTENER_SIGNAL_ERROR, - NM_TYPE_POLKIT_LISTENER, - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 1, - G_TYPE_STRING); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->set_property = set_property; + object_class->constructed = constructed; + object_class->dispose = dispose; + + obj_properties[PROP_DBUS_CONNECTION] = + g_param_spec_object(NM_POLKIT_LISTENER_DBUS_CONNECTION, + "", + "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_SESSION_AGENT] = + g_param_spec_boolean(NM_POLKIT_LISTENER_SESSION_AGENT, + "", + "", + FALSE, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + signals[REQUEST_SYNC] = g_signal_new(NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC, + NM_TYPE_POLKIT_LISTENER, + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + NULL, + G_TYPE_STRING, + 3, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING); + + signals[REGISTERED] = g_signal_new(NM_POLKIT_LISTENER_SIGNAL_REGISTERED, + NM_TYPE_POLKIT_LISTENER, + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 0); + + signals[ERROR] = g_signal_new(NM_POLKIT_LISTENER_SIGNAL_ERROR, + NM_TYPE_POLKIT_LISTENER, + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 1, + G_TYPE_STRING); } diff --git a/clients/common/nm-polkit-listener.h b/clients/common/nm-polkit-listener.h index c14d5932..efd24888 100644 --- a/clients/common/nm-polkit-listener.h +++ b/clients/common/nm-polkit-listener.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2014 Red Hat, Inc. */ @@ -6,24 +6,28 @@ #ifndef __NM_POLKIT_LISTENER_H__ #define __NM_POLKIT_LISTENER_H__ -#define NM_POLKIT_LISTENER_SIGNAL_REGISTERED "registered" -#define NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC "request-sync" -#define NM_POLKIT_LISTENER_SIGNAL_AUTH_SUCCESS "auth-success" -#define NM_POLKIT_LISTENER_SIGNAL_AUTH_FAILURE "auth-failure" -#define NM_POLKIT_LISTENER_SIGNAL_ERROR "error" +#define NM_POLKIT_LISTENER_SIGNAL_REGISTERED "registered" +#define NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC "request-sync" +#define NM_POLKIT_LISTENER_SIGNAL_AUTH_SUCCESS "auth-success" +#define NM_POLKIT_LISTENER_SIGNAL_AUTH_FAILURE "auth-failure" +#define NM_POLKIT_LISTENER_SIGNAL_ERROR "error" -typedef struct _NMPolkitListener NMPolkitListener; +typedef struct _NMPolkitListener NMPolkitListener; typedef struct _NMPolkitListenerClass NMPolkitListenerClass; -#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type ()) -#define NM_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener)) -#define NM_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass)) -#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_POLKIT_LISTENER)) -#define NM_IS_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_POLKIT_LISTENER)) -#define NM_POLKIT_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass)) +#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type()) +#define NM_POLKIT_LISTENER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener)) +#define NM_POLKIT_LISTENER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass)) +#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_POLKIT_LISTENER)) +#define NM_IS_POLKIT_LISTENER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_POLKIT_LISTENER)) +#define NM_POLKIT_LISTENER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass)) -GType nm_polkit_listener_get_type (void); +GType nm_polkit_listener_get_type(void); -NMPolkitListener *nm_polkit_listener_new (GDBusConnection *dbus_connection, gboolean session_agent); +NMPolkitListener *nm_polkit_listener_new(GDBusConnection *dbus_connection, gboolean session_agent); #endif /* __NM_POLKIT_LISTENER_H__ */ diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 53217e6f..4aed136f 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2011 - 2015 Red Hat, Inc. * Copyright (C) 2011 Giovanni Campagna <scampa.giovanni@gmail.com> @@ -30,83 +30,84 @@ /*****************************************************************************/ typedef struct { - char *request_id; + char *request_id; - NMSecretAgentSimple *self; + NMSecretAgentSimple *self; - NMConnection *connection; - const char *setting_name; - char **hints; - NMSecretAgentOldGetSecretsFunc callback; - gpointer callback_data; - GCancellable *cancellable; - NMSecretAgentGetSecretsFlags flags; + NMConnection * connection; + const char * setting_name; + char ** hints; + NMSecretAgentOldGetSecretsFunc callback; + gpointer callback_data; + GCancellable * cancellable; + NMSecretAgentGetSecretsFlags flags; } RequestData; enum { - REQUEST_SECRETS, + REQUEST_SECRETS, - LAST_SIGNAL + LAST_SIGNAL }; -static guint signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL] = {0}; typedef struct { - GHashTable *requests; + GHashTable *requests; - char *path; - gboolean enabled; + char * path; + gboolean enabled; } NMSecretAgentSimplePrivate; struct _NMSecretAgentSimple { - NMSecretAgentOld parent; - NMSecretAgentSimplePrivate _priv; + NMSecretAgentOld parent; + NMSecretAgentSimplePrivate _priv; }; struct _NMSecretAgentSimpleClass { - NMSecretAgentOldClass parent; + NMSecretAgentOldClass parent; }; -G_DEFINE_TYPE (NMSecretAgentSimple, nm_secret_agent_simple, NM_TYPE_SECRET_AGENT_OLD) +G_DEFINE_TYPE(NMSecretAgentSimple, nm_secret_agent_simple, NM_TYPE_SECRET_AGENT_OLD) -#define NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSecretAgentSimple, NM_IS_SECRET_AGENT_SIMPLE, NMSecretAgentOld) +#define NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self) \ + _NM_GET_PRIVATE(self, NMSecretAgentSimple, NM_IS_SECRET_AGENT_SIMPLE, NMSecretAgentOld) /*****************************************************************************/ static void -_request_data_free (gpointer data) +_request_data_free(gpointer data) { - RequestData *request = data; + RequestData *request = data; - g_free (request->request_id); - nm_clear_g_cancellable (&request->cancellable); - g_object_unref (request->connection); - g_strfreev (request->hints); + g_free(request->request_id); + nm_clear_g_cancellable(&request->cancellable); + g_object_unref(request->connection); + g_strfreev(request->hints); - g_slice_free (RequestData, request); + g_slice_free(RequestData, request); } static void -_request_data_complete (RequestData *request, - GVariant *secrets, - GError *error, - GHashTableIter *iter_to_remove) +_request_data_complete(RequestData * request, + GVariant * secrets, + GError * error, + GHashTableIter *iter_to_remove) { - NMSecretAgentSimple *self = request->self; - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); + NMSecretAgentSimple * self = request->self; + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); - nm_assert ((secrets != NULL) != (error != NULL)); + nm_assert((secrets != NULL) != (error != NULL)); - request->callback (NM_SECRET_AGENT_OLD (request->self), - request->connection, - secrets, - error, - request->callback_data); + request->callback(NM_SECRET_AGENT_OLD(request->self), + request->connection, + secrets, + error, + request->callback_data); - if (iter_to_remove) - g_hash_table_iter_remove (iter_to_remove); - else - g_hash_table_remove (priv->requests, request); + if (iter_to_remove) + g_hash_table_iter_remove(iter_to_remove); + else + g_hash_table_remove(priv->requests, request); } /*****************************************************************************/ @@ -122,935 +123,959 @@ _request_data_complete (RequestData *request, */ typedef struct { - NMSecretAgentSimpleSecret base; - NMSetting *setting; - char *property; + NMSecretAgentSimpleSecret base; + NMSetting * setting; + char * property; } SecretReal; static void -_secret_real_free (NMSecretAgentSimpleSecret *secret) +_secret_real_free(NMSecretAgentSimpleSecret *secret) { - SecretReal *real = (SecretReal *)secret; + SecretReal *real = (SecretReal *) secret; - g_free ((char *) secret->pretty_name); - g_free ((char *) secret->entry_id); - nm_free_secret (secret->value); - g_free ((char *) secret->vpn_type); - g_free (real->property); - g_clear_object (&real->setting); + g_free((char *) secret->pretty_name); + g_free((char *) secret->entry_id); + nm_free_secret(secret->value); + g_free((char *) secret->vpn_type); + g_free(real->property); + g_clear_object(&real->setting); - g_slice_free (SecretReal, real); + g_slice_free(SecretReal, real); } static NMSecretAgentSimpleSecret * -_secret_real_new_plain (NMSecretAgentSecretType secret_type, - const char *pretty_name, - NMSetting *setting, - const char *property) +_secret_real_new_plain(NMSecretAgentSecretType secret_type, + const char * pretty_name, + NMSetting * setting, + const char * property) { - SecretReal *real; - gs_free char *value= NULL; - - nm_assert (property); - nm_assert (NM_IS_SETTING (setting)); - nm_assert (NM_IN_SET (secret_type, NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, NM_SECRET_AGENT_SECRET_TYPE_SECRET)); - nm_assert (g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property)); - nm_assert ((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) == nm_setting_get_secret_flags (setting, property, NULL, NULL)); - - g_object_get (setting, property, &value, NULL); - - real = g_slice_new (SecretReal); - *real = (SecretReal) { - .base.secret_type = secret_type, - .base.pretty_name = g_strdup (pretty_name), - .base.entry_id = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), property), - .base.value = g_steal_pointer (&value), - .base.is_secret = (secret_type != NM_SECRET_AGENT_SECRET_TYPE_PROPERTY), - .setting = g_object_ref (setting), - .property = g_strdup (property), - }; - return &real->base; + SecretReal * real; + gs_free char *value = NULL; + + nm_assert(property); + nm_assert(NM_IS_SETTING(setting)); + nm_assert(NM_IN_SET(secret_type, + NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + NM_SECRET_AGENT_SECRET_TYPE_SECRET)); + nm_assert(g_object_class_find_property(G_OBJECT_GET_CLASS(setting), property)); + nm_assert((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) + == nm_setting_get_secret_flags(setting, property, NULL, NULL)); + + g_object_get(setting, property, &value, NULL); + + real = g_slice_new(SecretReal); + *real = (SecretReal){ + .base.secret_type = secret_type, + .base.pretty_name = g_strdup(pretty_name), + .base.entry_id = g_strdup_printf("%s.%s", nm_setting_get_name(setting), property), + .base.value = g_steal_pointer(&value), + .base.is_secret = (secret_type != NM_SECRET_AGENT_SECRET_TYPE_PROPERTY), + .setting = g_object_ref(setting), + .property = g_strdup(property), + }; + return &real->base; } static NMSecretAgentSimpleSecret * -_secret_real_new_vpn_secret (const char *pretty_name, - NMSetting *setting, - const char *property, - const char *vpn_type) +_secret_real_new_vpn_secret(const char *pretty_name, + NMSetting * setting, + const char *property, + const char *vpn_type) { - SecretReal *real; - const char *value; - - nm_assert (property); - nm_assert (NM_IS_SETTING_VPN (setting)); - nm_assert (vpn_type); - - value = nm_setting_vpn_get_secret (NM_SETTING_VPN (setting), property); - - real = g_slice_new (SecretReal); - *real = (SecretReal) { - .base.secret_type = NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, - .base.pretty_name = g_strdup (pretty_name), - .base.entry_id = g_strdup_printf ("%s%s", NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS, property), - .base.value = g_strdup (value), - .base.is_secret = TRUE, - .base.vpn_type = g_strdup (vpn_type), - .setting = g_object_ref (setting), - .property = g_strdup (property), - }; - return &real->base; + SecretReal *real; + const char *value; + + nm_assert(property); + nm_assert(NM_IS_SETTING_VPN(setting)); + nm_assert(vpn_type); + + value = nm_setting_vpn_get_secret(NM_SETTING_VPN(setting), property); + + real = g_slice_new(SecretReal); + *real = (SecretReal){ + .base.secret_type = NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, + .base.pretty_name = g_strdup(pretty_name), + .base.entry_id = + g_strdup_printf("%s%s", NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS, property), + .base.value = g_strdup(value), + .base.is_secret = TRUE, + .base.vpn_type = g_strdup(vpn_type), + .setting = g_object_ref(setting), + .property = g_strdup(property), + }; + return &real->base; } static NMSecretAgentSimpleSecret * -_secret_real_new_wireguard_peer_psk (NMSettingWireGuard *s_wg, - const char *public_key, - const char *preshared_key) +_secret_real_new_wireguard_peer_psk(NMSettingWireGuard *s_wg, + const char * public_key, + const char * preshared_key) { - SecretReal *real; - - nm_assert (NM_IS_SETTING_WIREGUARD (s_wg)); - nm_assert (public_key); - - real = g_slice_new (SecretReal); - *real = (SecretReal) { - .base.secret_type = NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK, - .base.pretty_name = g_strdup_printf (_("Preshared-key for %s"), - public_key), - .base.entry_id = g_strdup_printf (NM_SETTING_WIREGUARD_SETTING_NAME"."NM_SETTING_WIREGUARD_PEERS".%s."NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY, - public_key), - .base.value = g_strdup (preshared_key), - .base.is_secret = TRUE, - .base.no_prompt_entry_id = TRUE, - .setting = NM_SETTING (g_object_ref (s_wg)), - .property = g_strdup (public_key), - }; - return &real->base; + SecretReal *real; + + nm_assert(NM_IS_SETTING_WIREGUARD(s_wg)); + nm_assert(public_key); + + real = g_slice_new(SecretReal); + *real = (SecretReal){ + .base.secret_type = NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK, + .base.pretty_name = g_strdup_printf(_("Preshared-key for %s"), public_key), + .base.entry_id = g_strdup_printf(NM_SETTING_WIREGUARD_SETTING_NAME + "." NM_SETTING_WIREGUARD_PEERS + ".%s." NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY, + public_key), + .base.value = g_strdup(preshared_key), + .base.is_secret = TRUE, + .base.no_prompt_entry_id = TRUE, + .setting = NM_SETTING(g_object_ref(s_wg)), + .property = g_strdup(public_key), + }; + return &real->base; } /*****************************************************************************/ static gboolean -add_8021x_secrets (RequestData *request, - GPtrArray *secrets) +add_8021x_secrets(RequestData *request, GPtrArray *secrets) { - NMSetting8021x *s_8021x = nm_connection_get_setting_802_1x (request->connection); - const char *eap_method; - NMSecretAgentSimpleSecret *secret; - - /* If hints are given, then always ask for what the hints require */ - if (request->hints && request->hints[0]) { - char **iter; - - for (iter = request->hints; *iter; iter++) { - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _(*iter), - NM_SETTING (s_8021x), - *iter); - g_ptr_array_add (secrets, secret); - } - - return TRUE; - } - - eap_method = nm_setting_802_1x_get_eap_method (s_8021x, 0); - if (!eap_method) - return FALSE; - - if (NM_IN_STRSET (eap_method, "md5", - "leap", - "ttls", - "peap")) { - /* TTLS and PEAP are actually much more complicated, but this complication - * is not visible here since we only care about phase2 authentication - * (and don't even care of which one) - */ - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, - _("Username"), - NM_SETTING (s_8021x), - NM_SETTING_802_1X_IDENTITY); - g_ptr_array_add (secrets, secret); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_8021x), - NM_SETTING_802_1X_PASSWORD); - g_ptr_array_add (secrets, secret); - return TRUE; - } - - if (nm_streq (eap_method, "tls")) { - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, - _("Identity"), - NM_SETTING (s_8021x), - NM_SETTING_802_1X_IDENTITY); - g_ptr_array_add (secrets, secret); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Private key password"), - NM_SETTING (s_8021x), - NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD); - g_ptr_array_add (secrets, secret); - return TRUE; - } - - return FALSE; + NMSetting8021x * s_8021x = nm_connection_get_setting_802_1x(request->connection); + const char * eap_method; + NMSecretAgentSimpleSecret *secret; + + /* If hints are given, then always ask for what the hints require */ + if (request->hints && request->hints[0]) { + char **iter; + + for (iter = request->hints; *iter; iter++) { + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _(*iter), + NM_SETTING(s_8021x), + *iter); + g_ptr_array_add(secrets, secret); + } + + return TRUE; + } + + eap_method = nm_setting_802_1x_get_eap_method(s_8021x, 0); + if (!eap_method) + return FALSE; + + if (NM_IN_STRSET(eap_method, "md5", "leap", "ttls", "peap")) { + /* TTLS and PEAP are actually much more complicated, but this complication + * is not visible here since we only care about phase2 authentication + * (and don't even care of which one) + */ + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Username"), + NM_SETTING(s_8021x), + NM_SETTING_802_1X_IDENTITY); + g_ptr_array_add(secrets, secret); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_8021x), + NM_SETTING_802_1X_PASSWORD); + g_ptr_array_add(secrets, secret); + return TRUE; + } + + if (nm_streq(eap_method, "tls")) { + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Identity"), + NM_SETTING(s_8021x), + NM_SETTING_802_1X_IDENTITY); + g_ptr_array_add(secrets, secret); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Private key password"), + NM_SETTING(s_8021x), + NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD); + g_ptr_array_add(secrets, secret); + return TRUE; + } + + return FALSE; } static gboolean -add_wireless_secrets (RequestData *request, - GPtrArray *secrets) +add_wireless_secrets(RequestData *request, GPtrArray *secrets) { - NMSettingWirelessSecurity *s_wsec = nm_connection_get_setting_wireless_security (request->connection); - const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); - NMSecretAgentSimpleSecret *secret; - - if (!key_mgmt || nm_streq (key_mgmt, "owe")) - return FALSE; - - if (NM_IN_STRSET (key_mgmt, "wpa-psk", "sae")) { - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_wsec), - NM_SETTING_WIRELESS_SECURITY_PSK); - g_ptr_array_add (secrets, secret); - return TRUE; - } - - if (nm_streq (key_mgmt, "none")) { - guint32 index; - char key[100]; - - index = nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Key"), - NM_SETTING (s_wsec), - nm_sprintf_buf (key, "wep-key%u", (guint) index)); - g_ptr_array_add (secrets, secret); - return TRUE; - } - - if (nm_streq (key_mgmt, "iee8021x")) { - if (nm_streq0 (nm_setting_wireless_security_get_auth_alg (s_wsec), "leap")) { - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_wsec), - NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); - g_ptr_array_add (secrets, secret); - return TRUE; - } else - return add_8021x_secrets (request, secrets); - } - - if (nm_streq (key_mgmt, "wpa-eap")) - return add_8021x_secrets (request, secrets); - - return FALSE; + NMSettingWirelessSecurity *s_wsec = + nm_connection_get_setting_wireless_security(request->connection); + const char * key_mgmt = nm_setting_wireless_security_get_key_mgmt(s_wsec); + NMSecretAgentSimpleSecret *secret; + + if (!key_mgmt || nm_streq(key_mgmt, "owe")) + return FALSE; + + if (NM_IN_STRSET(key_mgmt, "wpa-psk", "sae")) { + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_wsec), + NM_SETTING_WIRELESS_SECURITY_PSK); + g_ptr_array_add(secrets, secret); + return TRUE; + } + + if (nm_streq(key_mgmt, "none")) { + guint32 index; + char key[100]; + + index = nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Key"), + NM_SETTING(s_wsec), + nm_sprintf_buf(key, "wep-key%u", (guint) index)); + g_ptr_array_add(secrets, secret); + return TRUE; + } + + if (nm_streq(key_mgmt, "iee8021x")) { + if (nm_streq0(nm_setting_wireless_security_get_auth_alg(s_wsec), "leap")) { + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_wsec), + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); + g_ptr_array_add(secrets, secret); + return TRUE; + } else + return add_8021x_secrets(request, secrets); + } + + if (nm_streq(key_mgmt, "wpa-eap")) + return add_8021x_secrets(request, secrets); + + return FALSE; } static gboolean -add_pppoe_secrets (RequestData *request, - GPtrArray *secrets) +add_pppoe_secrets(RequestData *request, GPtrArray *secrets) { - NMSettingPppoe *s_pppoe = nm_connection_get_setting_pppoe (request->connection); - NMSecretAgentSimpleSecret *secret; - - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, - _("Username"), - NM_SETTING (s_pppoe), - NM_SETTING_PPPOE_USERNAME); - g_ptr_array_add (secrets, secret); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, - _("Service"), - NM_SETTING (s_pppoe), - NM_SETTING_PPPOE_SERVICE); - g_ptr_array_add (secrets, secret); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_pppoe), - NM_SETTING_PPPOE_PASSWORD); - g_ptr_array_add (secrets, secret); - return TRUE; + NMSettingPppoe * s_pppoe = nm_connection_get_setting_pppoe(request->connection); + NMSecretAgentSimpleSecret *secret; + + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Username"), + NM_SETTING(s_pppoe), + NM_SETTING_PPPOE_USERNAME); + g_ptr_array_add(secrets, secret); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Service"), + NM_SETTING(s_pppoe), + NM_SETTING_PPPOE_SERVICE); + g_ptr_array_add(secrets, secret); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_pppoe), + NM_SETTING_PPPOE_PASSWORD); + g_ptr_array_add(secrets, secret); + return TRUE; } static NMSettingSecretFlags -get_vpn_secret_flags (NMSettingVpn *s_vpn, const char *secret_name) +get_vpn_secret_flags(NMSettingVpn *s_vpn, const char *secret_name) { - NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - GHashTable *vpn_data; + NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; + GHashTable * vpn_data; - g_object_get (s_vpn, NM_SETTING_VPN_DATA, &vpn_data, NULL); - nm_vpn_service_plugin_get_secret_flags (vpn_data, secret_name, &flags); - g_hash_table_unref (vpn_data); + g_object_get(s_vpn, NM_SETTING_VPN_DATA, &vpn_data, NULL); + nm_vpn_service_plugin_get_secret_flags(vpn_data, secret_name, &flags); + g_hash_table_unref(vpn_data); - return flags; + return flags; } static void -add_vpn_secret_helper (GPtrArray *secrets, NMSettingVpn *s_vpn, const char *name, const char *ui_name) +add_vpn_secret_helper(GPtrArray * secrets, + NMSettingVpn *s_vpn, + const char * name, + const char * ui_name) { - NMSecretAgentSimpleSecret *secret; - NMSettingSecretFlags flags; - int i; - - flags = get_vpn_secret_flags (s_vpn, name); - if ( flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED - || flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) { - secret = _secret_real_new_vpn_secret (ui_name, - NM_SETTING (s_vpn), - name, - nm_setting_vpn_get_service_type (s_vpn)); - - /* Check for duplicates */ - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *s = secrets->pdata[i]; - - if ( s->secret_type == secret->secret_type - && nm_streq0 (s->vpn_type, secret->vpn_type) - && nm_streq0 (s->entry_id, secret->entry_id)) { - _secret_real_free (secret); - return; - } - } - - g_ptr_array_add (secrets, secret); - } + NMSecretAgentSimpleSecret *secret; + NMSettingSecretFlags flags; + int i; + + flags = get_vpn_secret_flags(s_vpn, name); + if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED || flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) { + secret = _secret_real_new_vpn_secret(ui_name, + NM_SETTING(s_vpn), + name, + nm_setting_vpn_get_service_type(s_vpn)); + + /* Check for duplicates */ + for (i = 0; i < secrets->len; i++) { + NMSecretAgentSimpleSecret *s = secrets->pdata[i]; + + if (s->secret_type == secret->secret_type && nm_streq0(s->vpn_type, secret->vpn_type) + && nm_streq0(s->entry_id, secret->entry_id)) { + _secret_real_free(secret); + return; + } + } + + g_ptr_array_add(secrets, secret); + } } #define VPN_MSG_TAG "x-vpn-message:" static gboolean -add_vpn_secrets (RequestData *request, - GPtrArray *secrets, - char **msg) +add_vpn_secrets(RequestData *request, GPtrArray *secrets, char **msg) { - NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (request->connection); - const NmcVpnPasswordName *p; - const char *vpn_msg = NULL; - char **iter; - - /* If hints are given, then always ask for what the hints require */ - if (request->hints) { - for (iter = request->hints; *iter; iter++) { - if (!vpn_msg && g_str_has_prefix (*iter, VPN_MSG_TAG)) - vpn_msg = &(*iter)[NM_STRLEN (VPN_MSG_TAG)]; - else - add_vpn_secret_helper (secrets, s_vpn, *iter, *iter); - } - } - - NM_SET_OUT (msg, g_strdup (vpn_msg)); - - /* Now add what client thinks might be required, because hints may be empty or incomplete */ - p = nm_vpn_get_secret_names (nm_setting_vpn_get_service_type (s_vpn)); - while (p && p->name) { - add_vpn_secret_helper (secrets, s_vpn, p->name, _(p->ui_name)); - p++; - } - - return TRUE; + NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + const NmcVpnPasswordName *p; + const char * vpn_msg = NULL; + char ** iter; + + /* If hints are given, then always ask for what the hints require */ + if (request->hints) { + for (iter = request->hints; *iter; iter++) { + if (!vpn_msg && g_str_has_prefix(*iter, VPN_MSG_TAG)) + vpn_msg = &(*iter)[NM_STRLEN(VPN_MSG_TAG)]; + else + add_vpn_secret_helper(secrets, s_vpn, *iter, *iter); + } + } + + NM_SET_OUT(msg, g_strdup(vpn_msg)); + + /* Now add what client thinks might be required, because hints may be empty or incomplete */ + p = nm_vpn_get_secret_names(nm_setting_vpn_get_service_type(s_vpn)); + while (p && p->name) { + add_vpn_secret_helper(secrets, s_vpn, p->name, _(p->ui_name)); + p++; + } + + return TRUE; } static gboolean -add_wireguard_secrets (RequestData *request, - GPtrArray *secrets, - char **msg, - GError **error) +add_wireguard_secrets(RequestData *request, GPtrArray *secrets, char **msg, GError **error) { - NMSettingWireGuard *s_wg; - NMSecretAgentSimpleSecret *secret; - guint i; - - s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (request->connection, NM_TYPE_SETTING_WIREGUARD)); - if (!s_wg) { - g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Cannot service a WireGuard secrets request %s for a connection without WireGuard settings", - request->request_id); - return FALSE; - } - - if ( !request->hints - || !request->hints[0] - || g_strv_contains (NM_CAST_STRV_CC (request->hints), NM_SETTING_WIREGUARD_PRIVATE_KEY)) { - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("WireGuard private-key"), - NM_SETTING (s_wg), - NM_SETTING_WIREGUARD_PRIVATE_KEY); - g_ptr_array_add (secrets, secret); - } - - if (request->hints) { - - for (i = 0; request->hints[i]; i++) { - NMWireGuardPeer *peer; - const char *name = request->hints[i]; - gs_free char *public_key = NULL; - - if (nm_streq (name, NM_SETTING_WIREGUARD_PRIVATE_KEY)) - continue; - - if (NM_STR_HAS_PREFIX (name, NM_SETTING_WIREGUARD_PEERS".")) { - const char *tmp; - - tmp = &name[NM_STRLEN (NM_SETTING_WIREGUARD_PEERS".")]; - if (NM_STR_HAS_SUFFIX (tmp, "."NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)) { - public_key = g_strndup (tmp, - strlen (tmp) - NM_STRLEN ("."NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)); - } - } - - if (!public_key) - continue; - - peer = nm_setting_wireguard_get_peer_by_public_key (s_wg, public_key, NULL); - - g_ptr_array_add (secrets, _secret_real_new_wireguard_peer_psk (s_wg, - ( peer - ? nm_wireguard_peer_get_public_key (peer) - : public_key), - ( peer - ? nm_wireguard_peer_get_preshared_key (peer) - : NULL))); - } - } - - *msg = g_strdup_printf (_("Secrets are required to connect WireGuard VPN '%s'"), - nm_connection_get_id (request->connection)); - return TRUE; + NMSettingWireGuard * s_wg; + NMSecretAgentSimpleSecret *secret; + guint i; + + s_wg = NM_SETTING_WIREGUARD( + nm_connection_get_setting(request->connection, NM_TYPE_SETTING_WIREGUARD)); + if (!s_wg) { + g_set_error(error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Cannot service a WireGuard secrets request %s for a connection without " + "WireGuard settings", + request->request_id); + return FALSE; + } + + if (!request->hints || !request->hints[0] + || g_strv_contains(NM_CAST_STRV_CC(request->hints), NM_SETTING_WIREGUARD_PRIVATE_KEY)) { + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("WireGuard private-key"), + NM_SETTING(s_wg), + NM_SETTING_WIREGUARD_PRIVATE_KEY); + g_ptr_array_add(secrets, secret); + } + + if (request->hints) { + for (i = 0; request->hints[i]; i++) { + NMWireGuardPeer *peer; + const char * name = request->hints[i]; + gs_free char * public_key = NULL; + + if (nm_streq(name, NM_SETTING_WIREGUARD_PRIVATE_KEY)) + continue; + + if (NM_STR_HAS_PREFIX(name, NM_SETTING_WIREGUARD_PEERS ".")) { + const char *tmp; + + tmp = &name[NM_STRLEN(NM_SETTING_WIREGUARD_PEERS ".")]; + if (NM_STR_HAS_SUFFIX(tmp, "." NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)) { + public_key = g_strndup( + tmp, + strlen(tmp) - NM_STRLEN("." NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)); + } + } + + if (!public_key) + continue; + + peer = nm_setting_wireguard_get_peer_by_public_key(s_wg, public_key, NULL); + + g_ptr_array_add(secrets, + _secret_real_new_wireguard_peer_psk( + s_wg, + (peer ? nm_wireguard_peer_get_public_key(peer) : public_key), + (peer ? nm_wireguard_peer_get_preshared_key(peer) : NULL))); + } + } + + *msg = g_strdup_printf(_("Secrets are required to connect WireGuard VPN '%s'"), + nm_connection_get_id(request->connection)); + return TRUE; } typedef struct { - GPid auth_dialog_pid; - GString *auth_dialog_response; - RequestData *request; - GPtrArray *secrets; - GCancellable *cancellable; - gulong cancellable_id; - guint child_watch_id; - GInputStream *input_stream; - GOutputStream *output_stream; - char read_buf[5]; + GPid auth_dialog_pid; + GString * auth_dialog_response; + RequestData * request; + GPtrArray * secrets; + GCancellable * cancellable; + gulong cancellable_id; + guint child_watch_id; + GInputStream * input_stream; + GOutputStream *output_stream; + char read_buf[5]; } AuthDialogData; static void -_auth_dialog_data_free (AuthDialogData *data) +_auth_dialog_data_free(AuthDialogData *data) { - nm_clear_g_signal_handler (data->cancellable, &data->cancellable_id); - g_clear_object (&data->cancellable); - nm_clear_g_source (&data->child_watch_id); - g_ptr_array_unref (data->secrets); - g_spawn_close_pid (data->auth_dialog_pid); - g_string_free (data->auth_dialog_response, TRUE); - g_object_unref (data->input_stream); - g_object_unref (data->output_stream); - g_slice_free (AuthDialogData, data); + nm_clear_g_signal_handler(data->cancellable, &data->cancellable_id); + g_clear_object(&data->cancellable); + nm_clear_g_source(&data->child_watch_id); + g_ptr_array_unref(data->secrets); + g_spawn_close_pid(data->auth_dialog_pid); + g_string_free(data->auth_dialog_response, TRUE); + g_object_unref(data->input_stream); + g_object_unref(data->output_stream); + g_slice_free(AuthDialogData, data); } static void -_auth_dialog_exited (GPid pid, int status, gpointer user_data) +_auth_dialog_exited(GPid pid, int status, gpointer user_data) { - AuthDialogData *data = user_data; - RequestData *request = data->request; - GPtrArray *secrets = data->secrets; - NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (request->connection); - gs_unref_keyfile GKeyFile *keyfile = NULL; - gs_strfreev char **groups = NULL; - gs_free char *title = NULL; - gs_free char *message = NULL; - int i; - gs_free_error GError *error = NULL; - - data->child_watch_id = 0; - - nm_clear_g_cancellable_disconnect (data->cancellable, &data->cancellable_id); - - if (status != 0) { - g_set_error (&error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Auth dialog failed with error code %d\n", status); - goto out; - } - - keyfile = g_key_file_new (); - if (!g_key_file_load_from_data (keyfile, - data->auth_dialog_response->str, - data->auth_dialog_response->len, G_KEY_FILE_NONE, - &error)) { - goto out; - } - - groups = g_key_file_get_groups (keyfile, NULL); - if (!nm_streq0 (groups[0], "VPN Plugin UI")) { - g_set_error (&error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Expected [VPN Plugin UI] in auth dialog response"); - goto out; - } - - title = g_key_file_get_string (keyfile, "VPN Plugin UI", "Title", &error); - if (!title) - goto out; - - message = g_key_file_get_string (keyfile, "VPN Plugin UI", "Description", &error); - if (!message) - goto out; - - for (i = 1; groups[i]; i++) { - gs_free char *pretty_name = NULL; - - if (!g_key_file_get_boolean (keyfile, groups[i], "IsSecret", NULL)) - continue; - if (!g_key_file_get_boolean (keyfile, groups[i], "ShouldAsk", NULL)) - continue; - - pretty_name = g_key_file_get_string (keyfile, groups[i], "Label", NULL); - g_ptr_array_add (secrets, _secret_real_new_vpn_secret (pretty_name, - NM_SETTING (s_vpn), - groups[i], - nm_setting_vpn_get_service_type (s_vpn))); - } + AuthDialogData * data = user_data; + RequestData * request = data->request; + GPtrArray * secrets = data->secrets; + NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + gs_strfreev char ** groups = NULL; + gs_free char * title = NULL; + gs_free char * message = NULL; + int i; + gs_free_error GError *error = NULL; + + data->child_watch_id = 0; + + nm_clear_g_cancellable_disconnect(data->cancellable, &data->cancellable_id); + + if (status != 0) { + g_set_error(&error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Auth dialog failed with error code %d\n", + status); + goto out; + } + + keyfile = g_key_file_new(); + if (!g_key_file_load_from_data(keyfile, + data->auth_dialog_response->str, + data->auth_dialog_response->len, + G_KEY_FILE_NONE, + &error)) { + goto out; + } + + groups = g_key_file_get_groups(keyfile, NULL); + if (!nm_streq0(groups[0], "VPN Plugin UI")) { + g_set_error(&error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Expected [VPN Plugin UI] in auth dialog response"); + goto out; + } + + title = g_key_file_get_string(keyfile, "VPN Plugin UI", "Title", &error); + if (!title) + goto out; + + message = g_key_file_get_string(keyfile, "VPN Plugin UI", "Description", &error); + if (!message) + goto out; + + for (i = 1; groups[i]; i++) { + gs_free char *pretty_name = NULL; + + if (!g_key_file_get_boolean(keyfile, groups[i], "IsSecret", NULL)) + continue; + if (!g_key_file_get_boolean(keyfile, groups[i], "ShouldAsk", NULL)) + continue; + + pretty_name = g_key_file_get_string(keyfile, groups[i], "Label", NULL); + g_ptr_array_add(secrets, + _secret_real_new_vpn_secret(pretty_name, + NM_SETTING(s_vpn), + groups[i], + nm_setting_vpn_get_service_type(s_vpn))); + } out: - /* Try to fall back to the hardwired VPN support if the auth dialog fails. - * We may eventually get rid of the whole hardwired secrets handling at some point, - * when the auth helpers are goode enough.. */ - if (error && add_vpn_secrets (request, secrets, &message)) { - g_clear_error (&error); - if (!message) { - message = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); - } - } - - if (error) - _request_data_complete (request, NULL, error, NULL); - else { - g_signal_emit (request->self, signals[REQUEST_SECRETS], 0, - request->request_id, title, message, secrets); - } - - _auth_dialog_data_free (data); + /* Try to fall back to the hardwired VPN support if the auth dialog fails. + * We may eventually get rid of the whole hardwired secrets handling at some point, + * when the auth helpers are goode enough.. */ + if (error && add_vpn_secrets(request, secrets, &message)) { + g_clear_error(&error); + if (!message) { + message = g_strdup_printf(_("A password is required to connect to '%s'."), + nm_connection_get_id(request->connection)); + } + } + + if (error) + _request_data_complete(request, NULL, error, NULL); + else { + g_signal_emit(request->self, + signals[REQUEST_SECRETS], + 0, + request->request_id, + title, + message, + secrets); + } + + _auth_dialog_data_free(data); } static void -_request_cancelled (GObject *object, gpointer user_data) +_request_cancelled(GObject *object, gpointer user_data) { - _auth_dialog_data_free (user_data); + _auth_dialog_data_free(user_data); } static void -_auth_dialog_read_done (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +_auth_dialog_read_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GInputStream *auth_dialog_out = G_INPUT_STREAM (source_object); - AuthDialogData *data = user_data; - gssize read_size; - gs_free_error GError *error = NULL; - - read_size = g_input_stream_read_finish (auth_dialog_out, res, &error); - switch (read_size) { - case -1: - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - _request_data_complete (data->request, NULL, error, NULL); - _auth_dialog_data_free (data); - break; - case 0: - /* Done reading. Let's wait for the auth dialog to exit so that we're able to collect the status. - * Remember we can be cancelled in between. */ - data->child_watch_id = g_child_watch_add (data->auth_dialog_pid, _auth_dialog_exited, data); - data->cancellable = g_object_ref (data->request->cancellable); - data->cancellable_id = g_cancellable_connect (data->cancellable, - G_CALLBACK (_request_cancelled), data, NULL); - break; - default: - g_string_append_len (data->auth_dialog_response, data->read_buf, read_size); - g_input_stream_read_async (auth_dialog_out, - data->read_buf, - sizeof (data->read_buf), - G_PRIORITY_DEFAULT, - NULL, - _auth_dialog_read_done, - data); - return; - } - - g_input_stream_close (auth_dialog_out, NULL, NULL); + GInputStream * auth_dialog_out = G_INPUT_STREAM(source_object); + AuthDialogData *data = user_data; + gssize read_size; + gs_free_error GError *error = NULL; + + read_size = g_input_stream_read_finish(auth_dialog_out, res, &error); + switch (read_size) { + case -1: + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + _request_data_complete(data->request, NULL, error, NULL); + _auth_dialog_data_free(data); + break; + case 0: + /* Done reading. Let's wait for the auth dialog to exit so that we're able to collect the status. + * Remember we can be cancelled in between. */ + data->child_watch_id = g_child_watch_add(data->auth_dialog_pid, _auth_dialog_exited, data); + data->cancellable = g_object_ref(data->request->cancellable); + data->cancellable_id = + g_cancellable_connect(data->cancellable, G_CALLBACK(_request_cancelled), data, NULL); + break; + default: + g_string_append_len(data->auth_dialog_response, data->read_buf, read_size); + g_input_stream_read_async(auth_dialog_out, + data->read_buf, + sizeof(data->read_buf), + G_PRIORITY_DEFAULT, + NULL, + _auth_dialog_read_done, + data); + return; + } + + g_input_stream_close(auth_dialog_out, NULL, NULL); } static void -_auth_dialog_write_done (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +_auth_dialog_write_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GOutputStream *auth_dialog_out = G_OUTPUT_STREAM (source_object); - _nm_unused gs_free char *auth_dialog_request_free = user_data; + GOutputStream *auth_dialog_out = G_OUTPUT_STREAM(source_object); + _nm_unused gs_free char *auth_dialog_request_free = user_data; - /* We don't care about write errors. If there are any problems, the - * reader shall notice. */ - g_output_stream_write_finish (auth_dialog_out, res, NULL); - g_output_stream_close (auth_dialog_out, NULL, NULL); + /* We don't care about write errors. If there are any problems, the + * reader shall notice. */ + g_output_stream_write_finish(auth_dialog_out, res, NULL); + g_output_stream_close(auth_dialog_out, NULL, NULL); } static void -_add_to_string (GString *string, const char *key, const char *value) +_add_to_string(GString *string, const char *key, const char *value) { - gs_strfreev char **lines = NULL; - int i; + gs_strfreev char **lines = NULL; + int i; - lines = g_strsplit (value, "\n", -1); + lines = g_strsplit(value, "\n", -1); - g_string_append (string, key); - for (i = 0; lines[i]; i++) { - g_string_append_c (string, '='); - g_string_append (string, lines[i]); - g_string_append_c (string, '\n'); - } + g_string_append(string, key); + for (i = 0; lines[i]; i++) { + g_string_append_c(string, '='); + g_string_append(string, lines[i]); + g_string_append_c(string, '\n'); + } } static void -_add_data_item_to_string (const char *key, const char *value, gpointer user_data) +_add_data_item_to_string(const char *key, const char *value, gpointer user_data) { - GString *string = user_data; + GString *string = user_data; - _add_to_string (string, "DATA_KEY", key); - _add_to_string (string, "DATA_VAL", value); - g_string_append_c (string, '\n'); + _add_to_string(string, "DATA_KEY", key); + _add_to_string(string, "DATA_VAL", value); + g_string_append_c(string, '\n'); } static void -_add_secret_to_string (const char *key, const char *value, gpointer user_data) +_add_secret_to_string(const char *key, const char *value, gpointer user_data) { - GString *string = user_data; + GString *string = user_data; - _add_to_string (string, "SECRET_KEY", key); - _add_to_string (string, "SECRET_VAL", value); - g_string_append_c (string, '\n'); + _add_to_string(string, "SECRET_KEY", key); + _add_to_string(string, "SECRET_VAL", value); + g_string_append_c(string, '\n'); } static gboolean -try_spawn_vpn_auth_helper (RequestData *request, - GPtrArray *secrets) +try_spawn_vpn_auth_helper(RequestData *request, GPtrArray *secrets) { - NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (request->connection); - gs_unref_ptrarray GPtrArray *auth_dialog_argv = NULL; - NMVpnPluginInfo *plugin_info; - const char *s; - GPid auth_dialog_pid; - int auth_dialog_in_fd; - int auth_dialog_out_fd; - GOutputStream *auth_dialog_in; - GInputStream *auth_dialog_out; - GError *error = NULL; - GString *auth_dialog_request; - char *auth_dialog_request_str; - gsize auth_dialog_request_len; - AuthDialogData *data; - int i; - - plugin_info = nm_vpn_plugin_info_list_find_by_service (nm_vpn_get_plugin_infos (), - nm_setting_vpn_get_service_type (s_vpn)); - if (!plugin_info) - return FALSE; - - s = nm_vpn_plugin_info_lookup_property (plugin_info, "GNOME", "supports-external-ui-mode"); - if (!_nm_utils_ascii_str_to_bool (s, FALSE)) - return FALSE; - - auth_dialog_argv = g_ptr_array_new (); - - s = nm_vpn_plugin_info_lookup_property (plugin_info, "GNOME", "auth-dialog"); - g_return_val_if_fail (s, FALSE); - g_ptr_array_add (auth_dialog_argv, (gpointer) s); - - g_ptr_array_add (auth_dialog_argv, "-u"); - g_ptr_array_add (auth_dialog_argv, (gpointer) nm_connection_get_uuid (request->connection)); - g_ptr_array_add (auth_dialog_argv, "-n"); - g_ptr_array_add (auth_dialog_argv, (gpointer) nm_connection_get_id (request->connection)); - g_ptr_array_add (auth_dialog_argv, "-s"); - g_ptr_array_add (auth_dialog_argv, (gpointer) nm_setting_vpn_get_service_type (s_vpn)); - g_ptr_array_add (auth_dialog_argv, "--external-ui-mode"); - g_ptr_array_add (auth_dialog_argv, "-i"); - - if (request->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) - g_ptr_array_add (auth_dialog_argv, "-r"); - - s = nm_vpn_plugin_info_lookup_property (plugin_info, "GNOME", "supports-hints"); - if (_nm_utils_ascii_str_to_bool (s, FALSE)) { - for (i = 0; request->hints[i]; i++) { - g_ptr_array_add (auth_dialog_argv, "-t"); - g_ptr_array_add (auth_dialog_argv, request->hints[i]); - } - } - - g_ptr_array_add (auth_dialog_argv, NULL); - if (!g_spawn_async_with_pipes (NULL, (char **) auth_dialog_argv->pdata, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, - &auth_dialog_pid, - &auth_dialog_in_fd, - &auth_dialog_out_fd, - NULL, - &error)) { - g_warning ("Failed to spawn the auth dialog%s\n", error->message); - return FALSE; - } - - auth_dialog_in = g_unix_output_stream_new (auth_dialog_in_fd, TRUE); - auth_dialog_out = g_unix_input_stream_new (auth_dialog_out_fd, TRUE); - - auth_dialog_request = g_string_new_len (NULL, 1024); - nm_setting_vpn_foreach_data_item (s_vpn, _add_data_item_to_string, auth_dialog_request); - nm_setting_vpn_foreach_secret (s_vpn, _add_secret_to_string, auth_dialog_request); - g_string_append (auth_dialog_request, "DONE\nQUIT\n"); - auth_dialog_request_len = auth_dialog_request->len; - auth_dialog_request_str = g_string_free (auth_dialog_request, FALSE); - - data = g_slice_new (AuthDialogData); - *data = (AuthDialogData) { - .auth_dialog_response = g_string_new_len (NULL, sizeof (data->read_buf)), - .auth_dialog_pid = auth_dialog_pid, - .request = request, - .secrets = g_ptr_array_ref (secrets), - .input_stream = auth_dialog_out, - .output_stream = auth_dialog_in, - }; - - g_output_stream_write_async (auth_dialog_in, - auth_dialog_request_str, - auth_dialog_request_len, - G_PRIORITY_DEFAULT, - request->cancellable, - _auth_dialog_write_done, - auth_dialog_request_str); - - g_input_stream_read_async (auth_dialog_out, - data->read_buf, - sizeof (data->read_buf), - G_PRIORITY_DEFAULT, - request->cancellable, - _auth_dialog_read_done, - data); - - return TRUE; + NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + gs_unref_ptrarray GPtrArray *auth_dialog_argv = NULL; + NMVpnPluginInfo * plugin_info; + const char * s; + GPid auth_dialog_pid; + int auth_dialog_in_fd; + int auth_dialog_out_fd; + GOutputStream * auth_dialog_in; + GInputStream * auth_dialog_out; + GError * error = NULL; + GString * auth_dialog_request; + char * auth_dialog_request_str; + gsize auth_dialog_request_len; + AuthDialogData * data; + int i; + + plugin_info = nm_vpn_plugin_info_list_find_by_service(nm_vpn_get_plugin_infos(), + nm_setting_vpn_get_service_type(s_vpn)); + if (!plugin_info) + return FALSE; + + s = nm_vpn_plugin_info_lookup_property(plugin_info, "GNOME", "supports-external-ui-mode"); + if (!_nm_utils_ascii_str_to_bool(s, FALSE)) + return FALSE; + + auth_dialog_argv = g_ptr_array_new(); + + s = nm_vpn_plugin_info_lookup_property(plugin_info, "GNOME", "auth-dialog"); + g_return_val_if_fail(s, FALSE); + g_ptr_array_add(auth_dialog_argv, (gpointer) s); + + g_ptr_array_add(auth_dialog_argv, "-u"); + g_ptr_array_add(auth_dialog_argv, (gpointer) nm_connection_get_uuid(request->connection)); + g_ptr_array_add(auth_dialog_argv, "-n"); + g_ptr_array_add(auth_dialog_argv, (gpointer) nm_connection_get_id(request->connection)); + g_ptr_array_add(auth_dialog_argv, "-s"); + g_ptr_array_add(auth_dialog_argv, (gpointer) nm_setting_vpn_get_service_type(s_vpn)); + g_ptr_array_add(auth_dialog_argv, "--external-ui-mode"); + g_ptr_array_add(auth_dialog_argv, "-i"); + + if (request->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) + g_ptr_array_add(auth_dialog_argv, "-r"); + + s = nm_vpn_plugin_info_lookup_property(plugin_info, "GNOME", "supports-hints"); + if (_nm_utils_ascii_str_to_bool(s, FALSE)) { + for (i = 0; request->hints[i]; i++) { + g_ptr_array_add(auth_dialog_argv, "-t"); + g_ptr_array_add(auth_dialog_argv, request->hints[i]); + } + } + + g_ptr_array_add(auth_dialog_argv, NULL); + if (!g_spawn_async_with_pipes(NULL, + (char **) auth_dialog_argv->pdata, + NULL, + G_SPAWN_DO_NOT_REAP_CHILD, + NULL, + NULL, + &auth_dialog_pid, + &auth_dialog_in_fd, + &auth_dialog_out_fd, + NULL, + &error)) { + g_warning("Failed to spawn the auth dialog%s\n", error->message); + return FALSE; + } + + auth_dialog_in = g_unix_output_stream_new(auth_dialog_in_fd, TRUE); + auth_dialog_out = g_unix_input_stream_new(auth_dialog_out_fd, TRUE); + + auth_dialog_request = g_string_new_len(NULL, 1024); + nm_setting_vpn_foreach_data_item(s_vpn, _add_data_item_to_string, auth_dialog_request); + nm_setting_vpn_foreach_secret(s_vpn, _add_secret_to_string, auth_dialog_request); + g_string_append(auth_dialog_request, "DONE\nQUIT\n"); + auth_dialog_request_len = auth_dialog_request->len; + auth_dialog_request_str = g_string_free(auth_dialog_request, FALSE); + + data = g_slice_new(AuthDialogData); + *data = (AuthDialogData){ + .auth_dialog_response = g_string_new_len(NULL, sizeof(data->read_buf)), + .auth_dialog_pid = auth_dialog_pid, + .request = request, + .secrets = g_ptr_array_ref(secrets), + .input_stream = auth_dialog_out, + .output_stream = auth_dialog_in, + }; + + g_output_stream_write_async(auth_dialog_in, + auth_dialog_request_str, + auth_dialog_request_len, + G_PRIORITY_DEFAULT, + request->cancellable, + _auth_dialog_write_done, + auth_dialog_request_str); + + g_input_stream_read_async(auth_dialog_out, + data->read_buf, + sizeof(data->read_buf), + G_PRIORITY_DEFAULT, + request->cancellable, + _auth_dialog_read_done, + data); + + return TRUE; } static void -request_secrets_from_ui (RequestData *request) +request_secrets_from_ui(RequestData *request) { - gs_unref_ptrarray GPtrArray *secrets = NULL; - gs_free_error GError *error = NULL; - NMSecretAgentSimplePrivate *priv; - NMSecretAgentSimpleSecret *secret; - const char *title; - gs_free char *msg = NULL; - - priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (request->self); - g_return_if_fail (priv->enabled); - - /* We only handle requests for connection with @path if set. */ - if (priv->path && !g_str_has_prefix (request->request_id, priv->path)) { - g_set_error (&error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Request for %s secrets doesn't match path %s", - request->request_id, priv->path); - goto out_fail_error; - } - - secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) _secret_real_free); - - if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) { - NMSettingWireless *s_wireless; - GBytes *ssid; - char *ssid_utf8; - - s_wireless = nm_connection_get_setting_wireless (request->connection); - ssid = nm_setting_wireless_get_ssid (s_wireless); - ssid_utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - - title = _("Authentication required by wireless network"); - msg = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."), ssid_utf8); - - if (!add_wireless_secrets (request, secrets)) - goto out_fail; - } else if (nm_connection_is_type (request->connection, NM_SETTING_WIRED_SETTING_NAME)) { - title = _("Wired 802.1X authentication"); - msg = g_strdup_printf (_("Secrets are required to access the wired network '%s'"), - nm_connection_get_id (request->connection)); - - if (!add_8021x_secrets (request, secrets)) - goto out_fail; - } else if (nm_connection_is_type (request->connection, NM_SETTING_PPPOE_SETTING_NAME)) { - title = _("DSL authentication"); - msg = g_strdup_printf (_("Secrets are required for the DSL connection '%s'"), - nm_connection_get_id (request->connection)); - - if (!add_pppoe_secrets (request, secrets)) - goto out_fail; - } else if (nm_connection_is_type (request->connection, NM_SETTING_GSM_SETTING_NAME)) { - NMSettingGsm *s_gsm = nm_connection_get_setting_gsm (request->connection); - - if (g_strv_contains (NM_CAST_STRV_CC (request->hints), NM_SETTING_GSM_PIN)) { - title = _("PIN code required"); - msg = g_strdup (_("PIN code is needed for the mobile broadband device")); - - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("PIN"), - NM_SETTING (s_gsm), - NM_SETTING_GSM_PIN); - g_ptr_array_add (secrets, secret); - } else { - title = _("Mobile broadband network password"); - msg = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); - - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_gsm), - NM_SETTING_GSM_PASSWORD); - g_ptr_array_add (secrets, secret); - } - } else if (nm_connection_is_type (request->connection, NM_SETTING_MACSEC_SETTING_NAME)) { - NMSettingMacsec *s_macsec = nm_connection_get_setting_macsec (request->connection); - - msg = g_strdup_printf (_("Secrets are required to access the MACsec network '%s'"), - nm_connection_get_id (request->connection)); - - if (nm_setting_macsec_get_mode (s_macsec) == NM_SETTING_MACSEC_MODE_PSK) { - title = _("MACsec PSK authentication"); - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("MKA CAK"), - NM_SETTING (s_macsec), - NM_SETTING_MACSEC_MKA_CAK); - g_ptr_array_add (secrets, secret); - } else { - title = _("MACsec EAP authentication"); - if (!add_8021x_secrets (request, secrets)) - goto out_fail; - } - } else if (nm_connection_is_type (request->connection, NM_SETTING_WIREGUARD_SETTING_NAME)) { - title = _("WireGuard VPN secret"); - if (!add_wireguard_secrets (request, secrets, &msg, &error)) - goto out_fail_error; - } else if (nm_connection_is_type (request->connection, NM_SETTING_CDMA_SETTING_NAME)) { - NMSettingCdma *s_cdma = nm_connection_get_setting_cdma (request->connection); - - title = _("Mobile broadband network password"); - msg = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); - - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - NM_SETTING (s_cdma), - NM_SETTING_CDMA_PASSWORD); - g_ptr_array_add (secrets, secret); - } else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { - NMSetting *setting = NULL; - - setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME); - if ( setting - && !nm_streq0 (nm_setting_bluetooth_get_connection_type (NM_SETTING_BLUETOOTH (setting)), NM_SETTING_BLUETOOTH_TYPE_NAP)) { - setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_GSM_SETTING_NAME); - if (!setting) - setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_CDMA_SETTING_NAME); - } - - if (!setting) - goto out_fail; - - title = _("Mobile broadband network password"); - msg = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); - - secret = _secret_real_new_plain (NM_SECRET_AGENT_SECRET_TYPE_SECRET, - _("Password"), - setting, - "password"); - g_ptr_array_add (secrets, secret); - } else if (nm_connection_is_type (request->connection, NM_SETTING_VPN_SETTING_NAME)) { - title = _("VPN password required"); - - if (try_spawn_vpn_auth_helper (request, secrets)) { - /* This will emit REQUEST_SECRETS when ready */ - return; - } - - if (!add_vpn_secrets (request, secrets, &msg)) - goto out_fail; - if (!msg) { - msg = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); - } - } else - goto out_fail; - - if (secrets->len == 0) - goto out_fail; - - g_signal_emit (request->self, signals[REQUEST_SECRETS], 0, - request->request_id, title, msg, secrets); - return; + gs_unref_ptrarray GPtrArray *secrets = NULL; + gs_free_error GError * error = NULL; + NMSecretAgentSimplePrivate *priv; + NMSecretAgentSimpleSecret * secret; + const char * title; + gs_free char * msg = NULL; + + priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(request->self); + g_return_if_fail(priv->enabled); + + /* We only handle requests for connection with @path if set. */ + if (priv->path && !g_str_has_prefix(request->request_id, priv->path)) { + g_set_error(&error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Request for %s secrets doesn't match path %s", + request->request_id, + priv->path); + goto out_fail_error; + } + + secrets = g_ptr_array_new_with_free_func((GDestroyNotify) _secret_real_free); + + if (nm_connection_is_type(request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) { + NMSettingWireless *s_wireless; + GBytes * ssid; + char * ssid_utf8; + + s_wireless = nm_connection_get_setting_wireless(request->connection); + ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid_utf8 = nm_utils_ssid_to_utf8(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid)); + + title = _("Authentication required by wireless network"); + msg = g_strdup_printf( + _("Passwords or encryption keys are required to access the wireless network '%s'."), + ssid_utf8); + + if (!add_wireless_secrets(request, secrets)) + goto out_fail; + } else if (nm_connection_is_type(request->connection, NM_SETTING_WIRED_SETTING_NAME)) { + title = _("Wired 802.1X authentication"); + msg = g_strdup_printf(_("Secrets are required to access the wired network '%s'"), + nm_connection_get_id(request->connection)); + + if (!add_8021x_secrets(request, secrets)) + goto out_fail; + } else if (nm_connection_is_type(request->connection, NM_SETTING_PPPOE_SETTING_NAME)) { + title = _("DSL authentication"); + msg = g_strdup_printf(_("Secrets are required for the DSL connection '%s'"), + nm_connection_get_id(request->connection)); + + if (!add_pppoe_secrets(request, secrets)) + goto out_fail; + } else if (nm_connection_is_type(request->connection, NM_SETTING_GSM_SETTING_NAME)) { + NMSettingGsm *s_gsm = nm_connection_get_setting_gsm(request->connection); + + if (g_strv_contains(NM_CAST_STRV_CC(request->hints), NM_SETTING_GSM_PIN)) { + title = _("PIN code required"); + msg = g_strdup(_("PIN code is needed for the mobile broadband device")); + + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("PIN"), + NM_SETTING(s_gsm), + NM_SETTING_GSM_PIN); + g_ptr_array_add(secrets, secret); + } else { + title = _("Mobile broadband network password"); + msg = g_strdup_printf(_("A password is required to connect to '%s'."), + nm_connection_get_id(request->connection)); + + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_gsm), + NM_SETTING_GSM_PASSWORD); + g_ptr_array_add(secrets, secret); + } + } else if (nm_connection_is_type(request->connection, NM_SETTING_MACSEC_SETTING_NAME)) { + NMSettingMacsec *s_macsec = nm_connection_get_setting_macsec(request->connection); + + msg = g_strdup_printf(_("Secrets are required to access the MACsec network '%s'"), + nm_connection_get_id(request->connection)); + + if (nm_setting_macsec_get_mode(s_macsec) == NM_SETTING_MACSEC_MODE_PSK) { + title = _("MACsec PSK authentication"); + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("MKA CAK"), + NM_SETTING(s_macsec), + NM_SETTING_MACSEC_MKA_CAK); + g_ptr_array_add(secrets, secret); + } else { + title = _("MACsec EAP authentication"); + if (!add_8021x_secrets(request, secrets)) + goto out_fail; + } + } else if (nm_connection_is_type(request->connection, NM_SETTING_WIREGUARD_SETTING_NAME)) { + title = _("WireGuard VPN secret"); + if (!add_wireguard_secrets(request, secrets, &msg, &error)) + goto out_fail_error; + } else if (nm_connection_is_type(request->connection, NM_SETTING_CDMA_SETTING_NAME)) { + NMSettingCdma *s_cdma = nm_connection_get_setting_cdma(request->connection); + + title = _("Mobile broadband network password"); + msg = g_strdup_printf(_("A password is required to connect to '%s'."), + nm_connection_get_id(request->connection)); + + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + NM_SETTING(s_cdma), + NM_SETTING_CDMA_PASSWORD); + g_ptr_array_add(secrets, secret); + } else if (nm_connection_is_type(request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { + NMSetting *setting = NULL; + + setting = nm_connection_get_setting_by_name(request->connection, + NM_SETTING_BLUETOOTH_SETTING_NAME); + if (setting + && !nm_streq0(nm_setting_bluetooth_get_connection_type(NM_SETTING_BLUETOOTH(setting)), + NM_SETTING_BLUETOOTH_TYPE_NAP)) { + setting = + nm_connection_get_setting_by_name(request->connection, NM_SETTING_GSM_SETTING_NAME); + if (!setting) + setting = nm_connection_get_setting_by_name(request->connection, + NM_SETTING_CDMA_SETTING_NAME); + } + + if (!setting) + goto out_fail; + + title = _("Mobile broadband network password"); + msg = g_strdup_printf(_("A password is required to connect to '%s'."), + nm_connection_get_id(request->connection)); + + secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), + setting, + "password"); + g_ptr_array_add(secrets, secret); + } else if (nm_connection_is_type(request->connection, NM_SETTING_VPN_SETTING_NAME)) { + title = _("VPN password required"); + + if (try_spawn_vpn_auth_helper(request, secrets)) { + /* This will emit REQUEST_SECRETS when ready */ + return; + } + + if (!add_vpn_secrets(request, secrets, &msg)) + goto out_fail; + if (!msg) { + msg = g_strdup_printf(_("A password is required to connect to '%s'."), + nm_connection_get_id(request->connection)); + } + } else + goto out_fail; + + if (secrets->len == 0) + goto out_fail; + + g_signal_emit(request->self, + signals[REQUEST_SECRETS], + 0, + request->request_id, + title, + msg, + secrets); + return; out_fail: - g_set_error (&error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Cannot service a secrets request %s for a %s connection", - request->request_id, - nm_connection_get_connection_type (request->connection)); + g_set_error(&error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Cannot service a secrets request %s for a %s connection", + request->request_id, + nm_connection_get_connection_type(request->connection)); out_fail_error: - _request_data_complete (request, NULL, error, NULL); - + _request_data_complete(request, NULL, error, NULL); } static void -get_secrets (NMSecretAgentOld *agent, - NMConnection *connection, - const char *connection_path, - const char *setting_name, - const char **hints, - NMSecretAgentGetSecretsFlags flags, - NMSecretAgentOldGetSecretsFunc callback, - gpointer callback_data) +get_secrets(NMSecretAgentOld * agent, + NMConnection * connection, + const char * connection_path, + const char * setting_name, + const char ** hints, + NMSecretAgentGetSecretsFlags flags, + NMSecretAgentOldGetSecretsFunc callback, + gpointer callback_data) { - NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent); - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); - RequestData *request; - gs_free_error GError *error = NULL; - gs_free char *request_id = NULL; - const char *request_id_setting_name; - - request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); - - if (g_hash_table_contains (priv->requests, &request_id)) { - /* We already have a request pending for this (connection, setting) */ - error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, - "Request for %s secrets already pending", request_id); - callback (agent, connection, NULL, error, callback_data); - return; - } - - if (!(flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)) { - /* We don't do stored passwords */ - error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NO_SECRETS, - "Stored passwords not supported"); - callback (agent, connection, NULL, error, callback_data); - return; - } - - nm_assert (g_str_has_suffix (request_id, setting_name)); - request_id_setting_name = &request_id[strlen (request_id) - strlen (setting_name)]; - nm_assert (nm_streq (request_id_setting_name, setting_name)); - - request = g_slice_new (RequestData); - *request = (RequestData) { - .self = self, - .connection = g_object_ref (connection), - .setting_name = request_id_setting_name, - .hints = g_strdupv ((char **) hints), - .callback = callback, - .callback_data = callback_data, - .request_id = g_steal_pointer (&request_id), - .flags = flags, - .cancellable = g_cancellable_new (), - }; - g_hash_table_add (priv->requests, request); - - if (priv->enabled) - request_secrets_from_ui (request); + NMSecretAgentSimple * self = NM_SECRET_AGENT_SIMPLE(agent); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + RequestData * request; + gs_free_error GError *error = NULL; + gs_free char * request_id = NULL; + const char * request_id_setting_name; + + request_id = g_strdup_printf("%s/%s", connection_path, setting_name); + + if (g_hash_table_contains(priv->requests, &request_id)) { + /* We already have a request pending for this (connection, setting) */ + error = g_error_new(NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, + "Request for %s secrets already pending", + request_id); + callback(agent, connection, NULL, error, callback_data); + return; + } + + if (!(flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)) { + /* We don't do stored passwords */ + error = g_error_new(NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_NO_SECRETS, + "Stored passwords not supported"); + callback(agent, connection, NULL, error, callback_data); + return; + } + + nm_assert(g_str_has_suffix(request_id, setting_name)); + request_id_setting_name = &request_id[strlen(request_id) - strlen(setting_name)]; + nm_assert(nm_streq(request_id_setting_name, setting_name)); + + request = g_slice_new(RequestData); + *request = (RequestData){ + .self = self, + .connection = g_object_ref(connection), + .setting_name = request_id_setting_name, + .hints = g_strdupv((char **) hints), + .callback = callback, + .callback_data = callback_data, + .request_id = g_steal_pointer(&request_id), + .flags = flags, + .cancellable = g_cancellable_new(), + }; + g_hash_table_add(priv->requests, request); + + if (priv->enabled) + request_secrets_from_ui(request); } /** @@ -1068,150 +1093,158 @@ get_secrets (NMSecretAgentOld *agent, * cancelled the request, @secrets should be NULL. */ void -nm_secret_agent_simple_response (NMSecretAgentSimple *self, - const char *request_id, - GPtrArray *secrets) +nm_secret_agent_simple_response(NMSecretAgentSimple *self, + const char * request_id, + GPtrArray * secrets) { - NMSecretAgentSimplePrivate *priv; - RequestData *request; - gs_unref_variant GVariant *secrets_dict = NULL; - gs_free_error GError *error = NULL; - int i; - - g_return_if_fail (NM_IS_SECRET_AGENT_SIMPLE (self)); - - priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); - request = g_hash_table_lookup (priv->requests, &request_id); - g_return_if_fail (request != NULL); - - if (secrets) { - GVariantBuilder conn_builder, *setting_builder; - GVariantBuilder vpn_secrets_builder; - GVariantBuilder wg_secrets_builder; - GVariantBuilder wg_peer_builder; - GHashTable *settings; - GHashTableIter iter; - const char *name; - gboolean has_vpn = FALSE; - gboolean has_wg = FALSE; - - settings = g_hash_table_new_full (nm_str_hash, - g_str_equal, - NULL, - (GDestroyNotify) g_variant_builder_unref); - for (i = 0; i < secrets->len; i++) { - SecretReal *secret = secrets->pdata[i]; - - setting_builder = g_hash_table_lookup (settings, nm_setting_get_name (secret->setting)); - if (!setting_builder) { - setting_builder = g_variant_builder_new (NM_VARIANT_TYPE_SETTING); - g_hash_table_insert (settings, (char *) nm_setting_get_name (secret->setting), - setting_builder); - } - - switch (secret->base.secret_type) { - case NM_SECRET_AGENT_SECRET_TYPE_PROPERTY: - case NM_SECRET_AGENT_SECRET_TYPE_SECRET: - g_variant_builder_add (setting_builder, "{sv}", - secret->property, - g_variant_new_string (secret->base.value)); - break; - case NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET: - if (!has_vpn) { - g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}")); - has_vpn = TRUE; - } - g_variant_builder_add (&vpn_secrets_builder, "{ss}", - secret->property, secret->base.value); - break; - case NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK: - if (!has_wg) { - g_variant_builder_init (&wg_secrets_builder, G_VARIANT_TYPE ("aa{sv}")); - has_wg = TRUE; - } - g_variant_builder_init (&wg_peer_builder, G_VARIANT_TYPE ("a{sv}")); - g_variant_builder_add (&wg_peer_builder, "{sv}", - NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY, g_variant_new_string (secret->property)); - g_variant_builder_add (&wg_peer_builder, "{sv}", - NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY, g_variant_new_string (secret->base.value)); - g_variant_builder_add (&wg_secrets_builder, "a{sv}", - &wg_peer_builder); - break; - } - } - - if (has_vpn) { - g_variant_builder_add (setting_builder, "{sv}", - "secrets", - g_variant_builder_end (&vpn_secrets_builder)); - } - - if (has_wg) { - g_variant_builder_add (setting_builder, "{sv}", - NM_SETTING_WIREGUARD_PEERS, - g_variant_builder_end (&wg_secrets_builder)); - } - - g_variant_builder_init (&conn_builder, NM_VARIANT_TYPE_CONNECTION); - g_hash_table_iter_init (&iter, settings); - while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &setting_builder)) - g_variant_builder_add (&conn_builder, "{sa{sv}}", name, setting_builder); - secrets_dict = g_variant_ref_sink (g_variant_builder_end (&conn_builder)); - g_hash_table_destroy (settings); - } else { - error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_USER_CANCELED, - "User cancelled"); - } - - _request_data_complete (request, secrets_dict, error, NULL); + NMSecretAgentSimplePrivate *priv; + RequestData * request; + gs_unref_variant GVariant *secrets_dict = NULL; + gs_free_error GError *error = NULL; + int i; + + g_return_if_fail(NM_IS_SECRET_AGENT_SIMPLE(self)); + + priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + request = g_hash_table_lookup(priv->requests, &request_id); + g_return_if_fail(request != NULL); + + if (secrets) { + GVariantBuilder conn_builder, *setting_builder; + GVariantBuilder vpn_secrets_builder; + GVariantBuilder wg_secrets_builder; + GVariantBuilder wg_peer_builder; + GHashTable * settings; + GHashTableIter iter; + const char * name; + gboolean has_vpn = FALSE; + gboolean has_wg = FALSE; + + settings = g_hash_table_new_full(nm_str_hash, + g_str_equal, + NULL, + (GDestroyNotify) g_variant_builder_unref); + for (i = 0; i < secrets->len; i++) { + SecretReal *secret = secrets->pdata[i]; + + setting_builder = g_hash_table_lookup(settings, nm_setting_get_name(secret->setting)); + if (!setting_builder) { + setting_builder = g_variant_builder_new(NM_VARIANT_TYPE_SETTING); + g_hash_table_insert(settings, + (char *) nm_setting_get_name(secret->setting), + setting_builder); + } + + switch (secret->base.secret_type) { + case NM_SECRET_AGENT_SECRET_TYPE_PROPERTY: + case NM_SECRET_AGENT_SECRET_TYPE_SECRET: + g_variant_builder_add(setting_builder, + "{sv}", + secret->property, + g_variant_new_string(secret->base.value)); + break; + case NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET: + if (!has_vpn) { + g_variant_builder_init(&vpn_secrets_builder, G_VARIANT_TYPE("a{ss}")); + has_vpn = TRUE; + } + g_variant_builder_add(&vpn_secrets_builder, + "{ss}", + secret->property, + secret->base.value); + break; + case NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK: + if (!has_wg) { + g_variant_builder_init(&wg_secrets_builder, G_VARIANT_TYPE("aa{sv}")); + has_wg = TRUE; + } + g_variant_builder_init(&wg_peer_builder, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(&wg_peer_builder, + "{sv}", + NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY, + g_variant_new_string(secret->property)); + g_variant_builder_add(&wg_peer_builder, + "{sv}", + NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY, + g_variant_new_string(secret->base.value)); + g_variant_builder_add(&wg_secrets_builder, "a{sv}", &wg_peer_builder); + break; + } + } + + if (has_vpn) { + g_variant_builder_add(setting_builder, + "{sv}", + "secrets", + g_variant_builder_end(&vpn_secrets_builder)); + } + + if (has_wg) { + g_variant_builder_add(setting_builder, + "{sv}", + NM_SETTING_WIREGUARD_PEERS, + g_variant_builder_end(&wg_secrets_builder)); + } + + g_variant_builder_init(&conn_builder, NM_VARIANT_TYPE_CONNECTION); + g_hash_table_iter_init(&iter, settings); + while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &setting_builder)) + g_variant_builder_add(&conn_builder, "{sa{sv}}", name, setting_builder); + secrets_dict = g_variant_ref_sink(g_variant_builder_end(&conn_builder)); + g_hash_table_destroy(settings); + } else { + error = g_error_new(NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_USER_CANCELED, + "User cancelled"); + } + + _request_data_complete(request, secrets_dict, error, NULL); } static void -cancel_get_secrets (NMSecretAgentOld *agent, - const char *connection_path, - const char *setting_name) +cancel_get_secrets(NMSecretAgentOld *agent, const char *connection_path, const char *setting_name) { - NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent); - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); - gs_free_error GError *error = NULL; - gs_free char *request_id = NULL; - RequestData *request; - - request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); - request = g_hash_table_lookup (priv->requests, &request_id); - if (!request) { - /* this is really a bug of the caller (or us?). We cannot invoke a callback, - * hence the caller cannot cleanup the request. */ - g_return_if_reached (); - } - - g_set_error (&error, - NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_AGENT_CANCELED, - "The secret agent is going away"); - _request_data_complete (request, NULL, error, NULL); + NMSecretAgentSimple * self = NM_SECRET_AGENT_SIMPLE(agent); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + gs_free_error GError *error = NULL; + gs_free char * request_id = NULL; + RequestData * request; + + request_id = g_strdup_printf("%s/%s", connection_path, setting_name); + request = g_hash_table_lookup(priv->requests, &request_id); + if (!request) { + /* this is really a bug of the caller (or us?). We cannot invoke a callback, + * hence the caller cannot cleanup the request. */ + g_return_if_reached(); + } + + g_set_error(&error, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_AGENT_CANCELED, + "The secret agent is going away"); + _request_data_complete(request, NULL, error, NULL); } static void -save_secrets (NMSecretAgentOld *agent, - NMConnection *connection, - const char *connection_path, - NMSecretAgentOldSaveSecretsFunc callback, - gpointer callback_data) +save_secrets(NMSecretAgentOld * agent, + NMConnection * connection, + const char * connection_path, + NMSecretAgentOldSaveSecretsFunc callback, + gpointer callback_data) { - /* We don't support secret storage */ - callback (agent, connection, NULL, callback_data); + /* We don't support secret storage */ + callback(agent, connection, NULL, callback_data); } static void -delete_secrets (NMSecretAgentOld *agent, - NMConnection *connection, - const char *connection_path, - NMSecretAgentOldDeleteSecretsFunc callback, - gpointer callback_data) +delete_secrets(NMSecretAgentOld * agent, + NMConnection * connection, + const char * connection_path, + NMSecretAgentOldDeleteSecretsFunc callback, + gpointer callback_data) { - /* We don't support secret storage, so there's nothing to delete. */ - callback (agent, connection, NULL, callback_data); + /* We don't support secret storage, so there's nothing to delete. */ + callback(agent, connection, NULL, callback_data); } /** @@ -1225,44 +1258,43 @@ delete_secrets (NMSecretAgentOld *agent, * @path. */ void -nm_secret_agent_simple_enable (NMSecretAgentSimple *self, const char *path) +nm_secret_agent_simple_enable(NMSecretAgentSimple *self, const char *path) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); - gs_free RequestData **requests = NULL; - gsize i; - gs_free char *path_full = NULL; - - /* The path is only used to match a request_id with the current - * connection. Since the request_id is "${CONNECTION_PATH}/${SETTING}", - * add a trailing '/' to the path to match the full connection path. - */ - path_full = path ? g_strdup_printf ("%s/", path) : NULL; - - if (!nm_streq0 (path_full, priv->path)) { - g_free (priv->path); - priv->path = g_steal_pointer (&path_full); - } - - if (priv->enabled) - return; - priv->enabled = TRUE; - - /* Service pending secret requests. */ - requests = (RequestData **) g_hash_table_get_keys_as_array (priv->requests, NULL); - for (i = 0; requests[i]; i++) - request_secrets_from_ui (requests[i]); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + gs_free RequestData **requests = NULL; + gsize i; + gs_free char * path_full = NULL; + + /* The path is only used to match a request_id with the current + * connection. Since the request_id is "${CONNECTION_PATH}/${SETTING}", + * add a trailing '/' to the path to match the full connection path. + */ + path_full = path ? g_strdup_printf("%s/", path) : NULL; + + if (!nm_streq0(path_full, priv->path)) { + g_free(priv->path); + priv->path = g_steal_pointer(&path_full); + } + + if (priv->enabled) + return; + priv->enabled = TRUE; + + /* Service pending secret requests. */ + requests = (RequestData **) g_hash_table_get_keys_as_array(priv->requests, NULL); + for (i = 0; requests[i]; i++) + request_secrets_from_ui(requests[i]); } /*****************************************************************************/ static void -nm_secret_agent_simple_init (NMSecretAgentSimple *agent) +nm_secret_agent_simple_init(NMSecretAgentSimple *agent) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(agent); - G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (RequestData, request_id) == 0); - priv->requests = g_hash_table_new_full (nm_pstr_hash, nm_pstr_equal, - NULL, _request_data_free); + G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(RequestData, request_id) == 0); + priv->requests = g_hash_table_new_full(nm_pstr_hash, nm_pstr_equal, NULL, _request_data_free); } /** @@ -1276,87 +1308,95 @@ nm_secret_agent_simple_init (NMSecretAgentSimple *agent) * or %NULL in case of a failure. */ NMSecretAgentSimple * -nm_secret_agent_simple_new (const char *name) +nm_secret_agent_simple_new(const char *name) { - return g_initable_new (NM_TYPE_SECRET_AGENT_SIMPLE, NULL, NULL, - NM_SECRET_AGENT_OLD_IDENTIFIER, name, - NM_SECRET_AGENT_OLD_CAPABILITIES, NM_SECRET_AGENT_CAPABILITY_VPN_HINTS, - NULL); + return g_initable_new(NM_TYPE_SECRET_AGENT_SIMPLE, + NULL, + NULL, + NM_SECRET_AGENT_OLD_IDENTIFIER, + name, + NM_SECRET_AGENT_OLD_CAPABILITIES, + NM_SECRET_AGENT_CAPABILITY_VPN_HINTS, + NULL); } static void -dispose (GObject *object) +dispose(GObject *object) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (object); - gs_free_error GError *error = NULL; - GHashTableIter iter; - RequestData *request; - - g_hash_table_iter_init (&iter, priv->requests); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &request)) { - if (!error) - nm_utils_error_set_cancelled (&error, TRUE, "NMSecretAgentSimple"); - _request_data_complete (request, NULL, error, &iter); - } - - G_OBJECT_CLASS (nm_secret_agent_simple_parent_class)->dispose (object); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(object); + gs_free_error GError *error = NULL; + GHashTableIter iter; + RequestData * request; + + g_hash_table_iter_init(&iter, priv->requests); + while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &request)) { + if (!error) + nm_utils_error_set_cancelled(&error, TRUE, "NMSecretAgentSimple"); + _request_data_complete(request, NULL, error, &iter); + } + + G_OBJECT_CLASS(nm_secret_agent_simple_parent_class)->dispose(object); } static void -finalize (GObject *object) +finalize(GObject *object) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (object); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(object); - g_hash_table_destroy (priv->requests); + g_hash_table_destroy(priv->requests); - g_free (priv->path); + g_free(priv->path); - G_OBJECT_CLASS (nm_secret_agent_simple_parent_class)->finalize (object); + G_OBJECT_CLASS(nm_secret_agent_simple_parent_class)->finalize(object); } void -nm_secret_agent_simple_class_init (NMSecretAgentSimpleClass *klass) +nm_secret_agent_simple_class_init(NMSecretAgentSimpleClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMSecretAgentOldClass *agent_class = NM_SECRET_AGENT_OLD_CLASS (klass); - - object_class->dispose = dispose; - object_class->finalize = finalize; - - agent_class->get_secrets = get_secrets; - agent_class->cancel_get_secrets = cancel_get_secrets; - agent_class->save_secrets = save_secrets; - agent_class->delete_secrets = delete_secrets; - - /** - * NMSecretAgentSimple::request-secrets: - * @agent: the #NMSecretAgentSimple - * @request_id: request ID, to eventually pass to - * nm_secret_agent_simple_response(). - * @title: a title for the password dialog - * @prompt: a prompt message for the password dialog - * @secrets: (element-type #NMSecretAgentSimpleSecret): array of secrets - * being requested. - * - * Emitted when the agent requires secrets from the user. - * - * The application should ask user for the secrets. For example, - * nmtui should create a password dialog (#NmtPasswordDialog) - * with the given title and prompt, and an entry for each - * element of @secrets. If any of the secrets already have a - * <literal>value</literal> filled in, the corresponding entry - * should be initialized to that value. - * - * When the dialog is complete, the app must call - * nm_secret_agent_simple_response() with the results. - */ - signals[REQUEST_SECRETS] = g_signal_new (NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, - G_TYPE_FROM_CLASS (klass), - 0, 0, NULL, NULL, NULL, - G_TYPE_NONE, - 4, - G_TYPE_STRING, /* request_id */ - G_TYPE_STRING, /* title */ - G_TYPE_STRING, /* prompt */ - G_TYPE_PTR_ARRAY); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSecretAgentOldClass *agent_class = NM_SECRET_AGENT_OLD_CLASS(klass); + + object_class->dispose = dispose; + object_class->finalize = finalize; + + agent_class->get_secrets = get_secrets; + agent_class->cancel_get_secrets = cancel_get_secrets; + agent_class->save_secrets = save_secrets; + agent_class->delete_secrets = delete_secrets; + + /** + * NMSecretAgentSimple::request-secrets: + * @agent: the #NMSecretAgentSimple + * @request_id: request ID, to eventually pass to + * nm_secret_agent_simple_response(). + * @title: a title for the password dialog + * @prompt: a prompt message for the password dialog + * @secrets: (element-type #NMSecretAgentSimpleSecret): array of secrets + * being requested. + * + * Emitted when the agent requires secrets from the user. + * + * The application should ask user for the secrets. For example, + * nmtui should create a password dialog (#NmtPasswordDialog) + * with the given title and prompt, and an entry for each + * element of @secrets. If any of the secrets already have a + * <literal>value</literal> filled in, the corresponding entry + * should be initialized to that value. + * + * When the dialog is complete, the app must call + * nm_secret_agent_simple_response() with the results. + */ + signals[REQUEST_SECRETS] = g_signal_new(NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, + G_TYPE_FROM_CLASS(klass), + 0, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 4, + G_TYPE_STRING, /* request_id */ + G_TYPE_STRING, /* title */ + G_TYPE_STRING, /* prompt */ + G_TYPE_PTR_ARRAY); } diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h index 7214203d..bd12d3f8 100644 --- a/clients/common/nm-secret-agent-simple.h +++ b/clients/common/nm-secret-agent-simple.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2013 - 2015 Red Hat, Inc. */ @@ -9,49 +9,53 @@ #include "nm-secret-agent-old.h" typedef enum { - NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, - NM_SECRET_AGENT_SECRET_TYPE_SECRET, - NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, - NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK, + NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + NM_SECRET_AGENT_SECRET_TYPE_SECRET, + NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, + NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK, } NMSecretAgentSecretType; typedef struct { - NMSecretAgentSecretType secret_type; - const char *pretty_name; - const char *entry_id; - char *value; - const char *vpn_type; - bool is_secret:1; - bool no_prompt_entry_id:1; + NMSecretAgentSecretType secret_type; + const char * pretty_name; + const char * entry_id; + char * value; + const char * vpn_type; + bool is_secret : 1; + bool no_prompt_entry_id : 1; } NMSecretAgentSimpleSecret; #define NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "vpn.secrets." -#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE".openconnect" +#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE ".openconnect" /*****************************************************************************/ -#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ()) -#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple)) -#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass)) -#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT_SIMPLE)) -#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE)) -#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass)) +#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type()) +#define NM_SECRET_AGENT_SIMPLE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple)) +#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass)) +#define NM_IS_SECRET_AGENT_SIMPLE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_SECRET_AGENT_SIMPLE)) +#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_SECRET_AGENT_SIMPLE)) +#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass)) -#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets" +#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets" typedef struct _NMSecretAgentSimple NMSecretAgentSimple; typedef struct _NMSecretAgentSimpleClass NMSecretAgentSimpleClass; -GType nm_secret_agent_simple_get_type (void); +GType nm_secret_agent_simple_get_type(void); -NMSecretAgentSimple *nm_secret_agent_simple_new (const char *name); +NMSecretAgentSimple *nm_secret_agent_simple_new(const char *name); -void nm_secret_agent_simple_response (NMSecretAgentSimple *self, - const char *request_id, - GPtrArray *secrets); +void nm_secret_agent_simple_response(NMSecretAgentSimple *self, + const char * request_id, + GPtrArray * secrets); -void nm_secret_agent_simple_enable (NMSecretAgentSimple *self, - const char *path); +void nm_secret_agent_simple_enable(NMSecretAgentSimple *self, const char *path); #endif /* __NM_SECRET_AGENT_SIMPLE_H__ */ diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c index 74ff52bb..8312043f 100644 --- a/clients/common/nm-vpn-helpers.c +++ b/clients/common/nm-vpn-helpers.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2013 - 2015 Red Hat, Inc. */ @@ -23,807 +23,799 @@ /*****************************************************************************/ NMVpnEditorPlugin * -nm_vpn_get_editor_plugin (const char *service_type, GError **error) +nm_vpn_get_editor_plugin(const char *service_type, GError **error) { - NMVpnEditorPlugin *plugin = NULL; - NMVpnPluginInfo *plugin_info; - gs_free_error GError *local = NULL; - - g_return_val_if_fail (service_type, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - plugin_info = nm_vpn_plugin_info_list_find_by_service (nm_vpn_get_plugin_infos (), service_type); - - if (!plugin_info) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, - _("unknown VPN plugin \"%s\""), service_type); - return NULL; - } - plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info); - if (!plugin) - plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info, &local); - - if (!plugin) { - if ( !nm_vpn_plugin_info_get_plugin (plugin_info) - && nm_vpn_plugin_info_lookup_property (plugin_info, NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME, "properties")) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, - _("cannot load legacy-only VPN plugin \"%s\" for \"%s\""), - nm_vpn_plugin_info_get_name (plugin_info), - nm_vpn_plugin_info_get_filename (plugin_info)); - } else if (g_error_matches (local, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, - _("cannot load VPN plugin \"%s\" due to missing \"%s\". Missing client plugin?"), - nm_vpn_plugin_info_get_name (plugin_info), - nm_vpn_plugin_info_get_plugin (plugin_info)); - } else { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, - _("failed to load VPN plugin \"%s\": %s"), - nm_vpn_plugin_info_get_name (plugin_info), - local->message); - } - return NULL; - } - - return plugin; + NMVpnEditorPlugin *plugin = NULL; + NMVpnPluginInfo * plugin_info; + gs_free_error GError *local = NULL; + + g_return_val_if_fail(service_type, NULL); + g_return_val_if_fail(error == NULL || *error == NULL, NULL); + + plugin_info = nm_vpn_plugin_info_list_find_by_service(nm_vpn_get_plugin_infos(), service_type); + + if (!plugin_info) { + g_set_error(error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("unknown VPN plugin \"%s\""), + service_type); + return NULL; + } + plugin = nm_vpn_plugin_info_get_editor_plugin(plugin_info); + if (!plugin) + plugin = nm_vpn_plugin_info_load_editor_plugin(plugin_info, &local); + + if (!plugin) { + if (!nm_vpn_plugin_info_get_plugin(plugin_info) + && nm_vpn_plugin_info_lookup_property(plugin_info, + NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME, + "properties")) { + g_set_error(error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("cannot load legacy-only VPN plugin \"%s\" for \"%s\""), + nm_vpn_plugin_info_get_name(plugin_info), + nm_vpn_plugin_info_get_filename(plugin_info)); + } else if (g_error_matches(local, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + g_set_error( + error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("cannot load VPN plugin \"%s\" due to missing \"%s\". Missing client plugin?"), + nm_vpn_plugin_info_get_name(plugin_info), + nm_vpn_plugin_info_get_plugin(plugin_info)); + } else { + g_set_error(error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("failed to load VPN plugin \"%s\": %s"), + nm_vpn_plugin_info_get_name(plugin_info), + local->message); + } + return NULL; + } + + return plugin; } GSList * -nm_vpn_get_plugin_infos (void) +nm_vpn_get_plugin_infos(void) { - static bool plugins_loaded; - static GSList *plugins = NULL; - - if (G_LIKELY (plugins_loaded)) - return plugins; - plugins_loaded = TRUE; - plugins = nm_vpn_plugin_info_list_load (); - return plugins; + static bool plugins_loaded; + static GSList *plugins = NULL; + + if (G_LIKELY(plugins_loaded)) + return plugins; + plugins_loaded = TRUE; + plugins = nm_vpn_plugin_info_list_load(); + return plugins; } gboolean -nm_vpn_supports_ipv6 (NMConnection *connection) +nm_vpn_supports_ipv6(NMConnection *connection) { - NMSettingVpn *s_vpn; - const char *service_type; - NMVpnEditorPlugin *plugin; - guint32 capabilities; + NMSettingVpn * s_vpn; + const char * service_type; + NMVpnEditorPlugin *plugin; + guint32 capabilities; - s_vpn = nm_connection_get_setting_vpn (connection); - g_return_val_if_fail (s_vpn != NULL, FALSE); + s_vpn = nm_connection_get_setting_vpn(connection); + g_return_val_if_fail(s_vpn != NULL, FALSE); - service_type = nm_setting_vpn_get_service_type (s_vpn); - if (!service_type) - return FALSE; + service_type = nm_setting_vpn_get_service_type(s_vpn); + if (!service_type) + return FALSE; - plugin = nm_vpn_get_editor_plugin (service_type, NULL); - if (!plugin) - return FALSE; + plugin = nm_vpn_get_editor_plugin(service_type, NULL); + if (!plugin) + return FALSE; - capabilities = nm_vpn_editor_plugin_get_capabilities (plugin); - return NM_FLAGS_HAS (capabilities, NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6); + capabilities = nm_vpn_editor_plugin_get_capabilities(plugin); + return NM_FLAGS_HAS(capabilities, NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6); } const NmcVpnPasswordName * -nm_vpn_get_secret_names (const char *service_type) +nm_vpn_get_secret_names(const char *service_type) { - const char *type; - - if (!service_type) - return NULL; - - if ( !NM_STR_HAS_PREFIX (service_type, NM_DBUS_INTERFACE) - || service_type[NM_STRLEN (NM_DBUS_INTERFACE)] != '.') { - /* all our well-known, hard-coded vpn-types start with NM_DBUS_INTERFACE. */ - return NULL; - } - - type = service_type + (NM_STRLEN (NM_DBUS_INTERFACE) + 1); - -#define _VPN_PASSWORD_LIST(...) \ - ({ \ - static const NmcVpnPasswordName _arr[] = { \ - __VA_ARGS__ \ - { 0 }, \ - }; \ - _arr; \ - }) - - if (NM_IN_STRSET (type, "pptp", - "iodine", - "ssh", - "l2tp", - "fortisslvpn")) { - return _VPN_PASSWORD_LIST ( - { "password", N_("Password") }, - ); - } - - if (NM_IN_STRSET (type, "openvpn")) { - return _VPN_PASSWORD_LIST ( - { "password", N_("Password") }, - { "cert-pass", N_("Certificate password") }, - { "http-proxy-password", N_("HTTP proxy password") }, - ); - } - - if (NM_IN_STRSET (type, "vpnc")) { - return _VPN_PASSWORD_LIST ( - { "Xauth password", N_("Password") }, - { "IPSec secret", N_("Group password") }, - ); - }; - - if (NM_IN_STRSET (type, "openswan", - "libreswan", - "strongswan")) { - return _VPN_PASSWORD_LIST ( - { "xauthpassword", N_("Password") }, - { "pskvalue", N_("Group password") }, - ); - }; - - if (NM_IN_STRSET (type, "openconnect")) { - return _VPN_PASSWORD_LIST ( - { "gateway", N_("Gateway") }, - { "cookie", N_("Cookie") }, - { "gwcert", N_("Gateway certificate hash") }, - ); - }; - - return NULL; + const char *type; + + if (!service_type) + return NULL; + + if (!NM_STR_HAS_PREFIX(service_type, NM_DBUS_INTERFACE) + || service_type[NM_STRLEN(NM_DBUS_INTERFACE)] != '.') { + /* all our well-known, hard-coded vpn-types start with NM_DBUS_INTERFACE. */ + return NULL; + } + + type = service_type + (NM_STRLEN(NM_DBUS_INTERFACE) + 1); + +#define _VPN_PASSWORD_LIST(...) \ + ({ \ + static const NmcVpnPasswordName _arr[] = { \ + __VA_ARGS__{0}, \ + }; \ + _arr; \ + }) + + if (NM_IN_STRSET(type, "pptp", "iodine", "ssh", "l2tp", "fortisslvpn")) { + return _VPN_PASSWORD_LIST({"password", N_("Password")}, ); + } + + if (NM_IN_STRSET(type, "openvpn")) { + return _VPN_PASSWORD_LIST({"password", N_("Password")}, + {"cert-pass", N_("Certificate password")}, + {"http-proxy-password", N_("HTTP proxy password")}, ); + } + + if (NM_IN_STRSET(type, "vpnc")) { + return _VPN_PASSWORD_LIST({"Xauth password", N_("Password")}, + {"IPSec secret", N_("Group password")}, ); + }; + + if (NM_IN_STRSET(type, "openswan", "libreswan", "strongswan")) { + return _VPN_PASSWORD_LIST({"xauthpassword", N_("Password")}, + {"pskvalue", N_("Group password")}, ); + }; + + if (NM_IN_STRSET(type, "openconnect")) { + return _VPN_PASSWORD_LIST({"gateway", N_("Gateway")}, + {"cookie", N_("Cookie")}, + {"gwcert", N_("Gateway certificate hash")}, ); + }; + + return NULL; } static gboolean -_extract_variable_value (char *line, const char *tag, char **value) +_extract_variable_value(char *line, const char *tag, char **value) { - char *p1, *p2; - - if (!g_str_has_prefix (line, tag)) - return FALSE; - - p1 = line + strlen (tag); - p2 = line + strlen (line) - 1; - if ((*p1 == '\'' || *p1 == '"') && (*p1 == *p2)) { - p1++; - *p2 = '\0'; - } - NM_SET_OUT (value, g_strdup (p1)); - return TRUE; + char *p1, *p2; + + if (!g_str_has_prefix(line, tag)) + return FALSE; + + p1 = line + strlen(tag); + p2 = line + strlen(line) - 1; + if ((*p1 == '\'' || *p1 == '"') && (*p1 == *p2)) { + p1++; + *p2 = '\0'; + } + NM_SET_OUT(value, g_strdup(p1)); + return TRUE; } gboolean -nm_vpn_openconnect_authenticate_helper (const char *host, - char **cookie, - char **gateway, - char **gwcert, - int *status, - GError **error) +nm_vpn_openconnect_authenticate_helper(const char *host, + char ** cookie, + char ** gateway, + char ** gwcert, + int * status, + GError ** error) { - gs_free char *output = NULL; - gs_free const char **output_v = NULL; - const char *const*iter; - const char *path; - const char *const DEFAULT_PATHS[] = { - "/sbin/", - "/usr/sbin/", - "/usr/local/sbin/", - "/bin/", - "/usr/bin/", - "/usr/local/bin/", - NULL, - }; - - path = nm_utils_file_search_in_paths ("openconnect", "/usr/sbin/openconnect", DEFAULT_PATHS, - G_FILE_TEST_IS_EXECUTABLE, NULL, NULL, error); - if (!path) - return FALSE; - - if (!g_spawn_sync (NULL, - (char **) NM_MAKE_STRV (path, "--authenticate", host), - NULL, - G_SPAWN_SEARCH_PATH - | G_SPAWN_CHILD_INHERITS_STDIN, - NULL, - NULL, - &output, - NULL, - status, - error)) - return FALSE; - - /* Parse output and set cookie, gateway and gwcert - * output example: - * COOKIE='loremipsum' - * HOST='1.2.3.4' - * FINGERPRINT='sha1:32bac90cf09a722e10ecc1942c67fe2ac8c21e2e' - */ - output_v = nm_utils_strsplit_set_with_empty (output, "\r\n"); - for (iter = output_v; iter && *iter; iter++) { - char *s_mutable = (char *) *iter; - - _extract_variable_value (s_mutable, "COOKIE=", cookie); - _extract_variable_value (s_mutable, "HOST=", gateway); - _extract_variable_value (s_mutable, "FINGERPRINT=", gwcert); - } - - return TRUE; + gs_free char * output = NULL; + gs_free const char **output_v = NULL; + const char *const * iter; + const char * path; + const char *const DEFAULT_PATHS[] = { + "/sbin/", + "/usr/sbin/", + "/usr/local/sbin/", + "/bin/", + "/usr/bin/", + "/usr/local/bin/", + NULL, + }; + + path = nm_utils_file_search_in_paths("openconnect", + "/usr/sbin/openconnect", + DEFAULT_PATHS, + G_FILE_TEST_IS_EXECUTABLE, + NULL, + NULL, + error); + if (!path) + return FALSE; + + if (!g_spawn_sync(NULL, + (char **) NM_MAKE_STRV(path, "--authenticate", host), + NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN, + NULL, + NULL, + &output, + NULL, + status, + error)) + return FALSE; + + /* Parse output and set cookie, gateway and gwcert + * output example: + * COOKIE='loremipsum' + * HOST='1.2.3.4' + * FINGERPRINT='sha1:32bac90cf09a722e10ecc1942c67fe2ac8c21e2e' + */ + output_v = nm_utils_strsplit_set_with_empty(output, "\r\n"); + for (iter = output_v; iter && *iter; iter++) { + char *s_mutable = (char *) *iter; + + _extract_variable_value(s_mutable, "COOKIE=", cookie); + _extract_variable_value(s_mutable, "HOST=", gateway); + _extract_variable_value(s_mutable, "FINGERPRINT=", gwcert); + } + + return TRUE; } static gboolean -_wg_complete_peer (GPtrArray **p_peers, - NMWireGuardPeer *peer_take, - gsize peer_start_line_nr, - const char *filename, - GError **error) +_wg_complete_peer(GPtrArray ** p_peers, + NMWireGuardPeer *peer_take, + gsize peer_start_line_nr, + const char * filename, + GError ** error) { - nm_auto_unref_wgpeer NMWireGuardPeer *peer = peer_take; - gs_free_error GError *local = NULL; - - if (!peer) - return TRUE; - - if (!nm_wireguard_peer_is_valid (peer, TRUE, TRUE, &local)) { - nm_utils_error_set (error, NM_UTILS_ERROR_UNKNOWN, - _("Invalid peer starting at %s:%zu: %s"), - filename, - peer_start_line_nr, - local->message); - return FALSE; - } - - if (!*p_peers) - *p_peers = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_wireguard_peer_unref); - g_ptr_array_add (*p_peers, g_steal_pointer (&peer)); - return TRUE; + nm_auto_unref_wgpeer NMWireGuardPeer *peer = peer_take; + gs_free_error GError *local = NULL; + + if (!peer) + return TRUE; + + if (!nm_wireguard_peer_is_valid(peer, TRUE, TRUE, &local)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + _("Invalid peer starting at %s:%zu: %s"), + filename, + peer_start_line_nr, + local->message); + return FALSE; + } + + if (!*p_peers) + *p_peers = g_ptr_array_new_with_free_func((GDestroyNotify) nm_wireguard_peer_unref); + g_ptr_array_add(*p_peers, g_steal_pointer(&peer)); + return TRUE; } static gboolean -_line_match (char *line, const char *key, gsize key_len, const char **out_key, char **out_value) +_line_match(char *line, const char *key, gsize key_len, const char **out_key, char **out_value) { - nm_assert (line); - nm_assert (key); - nm_assert (strlen (key) == key_len); - nm_assert (!strchr (key, '=')); - nm_assert (out_key && !*out_key); - nm_assert (out_value && !*out_value); - - /* Note that `wg-quick` (linux.bash) does case-insensitive comparison (shopt -s nocasematch). - * `wg setconf` does case-insensitive comparison too (with strncasecmp, which is locale dependent). - * - * We do a case-insensitive comparison of the key, however in a locale-independent manner. */ - - if (g_ascii_strncasecmp (line, key, key_len) != 0) - return FALSE; - - if (line[key_len] != '=') - return FALSE; - - *out_key = key; - *out_value = &line[key_len + 1]; - return TRUE; + nm_assert(line); + nm_assert(key); + nm_assert(strlen(key) == key_len); + nm_assert(!strchr(key, '=')); + nm_assert(out_key && !*out_key); + nm_assert(out_value && !*out_value); + + /* Note that `wg-quick` (linux.bash) does case-insensitive comparison (shopt -s nocasematch). + * `wg setconf` does case-insensitive comparison too (with strncasecmp, which is locale dependent). + * + * We do a case-insensitive comparison of the key, however in a locale-independent manner. */ + + if (g_ascii_strncasecmp(line, key, key_len) != 0) + return FALSE; + + if (line[key_len] != '=') + return FALSE; + + *out_key = key; + *out_value = &line[key_len + 1]; + return TRUE; } #define line_match(line, key, out_key, out_value) \ - _line_match ((line), ""key"", NM_STRLEN (key), (out_key), (out_value)) + _line_match((line), "" key "", NM_STRLEN(key), (out_key), (out_value)) static gboolean -value_split_word (char **line_remainder, char **out_word) +value_split_word(char **line_remainder, char **out_word) { - char *str; + char *str; - if ((*line_remainder)[0] == '\0') - return FALSE; + if ((*line_remainder)[0] == '\0') + return FALSE; - *out_word = *line_remainder; + *out_word = *line_remainder; - str = strchrnul (*line_remainder, ','); - if (str[0] == ',') { - str[0] = '\0'; - *line_remainder = &str[1]; - } else - *line_remainder = str; - return TRUE; + str = strchrnul(*line_remainder, ','); + if (str[0] == ',') { + str[0] = '\0'; + *line_remainder = &str[1]; + } else + *line_remainder = str; + return TRUE; } NMConnection * -nm_vpn_wireguard_import (const char *filename, - GError **error) +nm_vpn_wireguard_import(const char *filename, GError **error) { - nm_auto_clear_secret_ptr NMSecretPtr file_content = NM_SECRET_PTR_INIT (); - char ifname[IFNAMSIZ]; - gs_free char *uuid = NULL; - gboolean ifname_valid = FALSE; - const char *cstr; - char *line_remainder; - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection *s_con; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; - NMSettingWireGuard *s_wg; - gs_free_error GError *local = NULL; - enum { - LINE_CONTEXT_INIT, - LINE_CONTEXT_INTERFACE, - LINE_CONTEXT_PEER, - } line_context; - gsize line_nr; - gsize current_peer_start_line_nr = 0; - nm_auto_unref_wgpeer NMWireGuardPeer *current_peer = NULL; - gs_unref_ptrarray GPtrArray *data_dns_search = NULL; - gs_unref_ptrarray GPtrArray *data_dns_v4 = NULL; - gs_unref_ptrarray GPtrArray *data_dns_v6 = NULL; - gs_unref_ptrarray GPtrArray *data_addr_v4 = NULL; - gs_unref_ptrarray GPtrArray *data_addr_v6 = NULL; - gs_unref_ptrarray GPtrArray *data_peers = NULL; - const char *data_private_key = NULL; - gint64 data_table; - guint data_listen_port = 0; - guint data_fwmark = 0; - guint data_mtu = 0; - int is_v4; - guint i; - - g_return_val_if_fail (filename, NULL); - g_return_val_if_fail (!error || !*error, NULL); - - /* contrary to "wg-quick", we never interpret the filename as "/etc/wireguard/$INTERFACE.conf". - * If the filename has no '/', it is interpreted as relative to the current working directory. - * However, we do require a suitable filename suffix and that the name corresponds to the interface - * name. */ - cstr = strrchr (filename, '/'); - cstr = cstr ? &cstr[1] : filename; - if (NM_STR_HAS_SUFFIX (cstr, ".conf")) { - gsize len = strlen (cstr) - NM_STRLEN (".conf"); - - if (len > 0 && len < sizeof (ifname)) { - memcpy (ifname, cstr, len); - ifname[len] = '\0'; - - if (nm_utils_ifname_valid (ifname, NMU_IFACE_KERNEL, NULL)) - ifname_valid = TRUE; - } - } - if (!ifname_valid) { - nm_utils_error_set_literal (error, NM_UTILS_ERROR_UNKNOWN, - _("The name of the WireGuard config must be a valid interface name followed by \".conf\"")); - return FALSE; - } - - if (!nm_utils_file_get_contents (-1, - filename, - 10*1024*1024, - NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET, - &file_content.str, - &file_content.len, - NULL, - error)) - return NULL; - - /* We interpret the file like `wg-quick up` and `wg setconf` do. - * - * Of course the WireGuard scripts do something fundamentlly different. They - * perform actions to configure the WireGuard link in kernel, add routes and - * addresses, and call resolvconf. It all happens at the time when the script - * run. - * - * This code here instead generates a NetworkManager connection profile so that - * NetworkManager will apply a similar configuration when later activating the profile. */ - -#define _TABLE_AUTO ((gint64) -1) -#define _TABLE_OFF ((gint64) -2) - - data_table = _TABLE_AUTO; - - line_remainder = file_content.str; - line_context = LINE_CONTEXT_INIT; - line_nr = 0; - while (line_remainder[0] != '\0') { - const char *matched_key = NULL; - char *value = NULL; - char *line; - char ch; - gint64 i64; - - line_nr++; - - line = line_remainder; - line_remainder = strchrnul (line, '\n'); - if (line_remainder[0] != '\0') - (line_remainder++)[0] = '\0'; - - /* Drop all spaces and truncate at first '#'. - * See wg's config_read_line(). - * - * Note that wg-quick doesn't do that. - * - * Neither `wg setconf` nor `wg-quick` does a strict parsing. - * We don't either. Just try to interpret the file (mostly) the same as - * they would. - */ - { - gsize l, n; - - n = 0; - for (l = 0; (ch = line[l]); l++) { - if (g_ascii_isspace (ch)) { - /* wg-setconf strips all whitespace before parsing the content. That means, - * *[I nterface]" will be accepted. We do that too. */ - continue; - } - if (ch == '#') - break; - line[n++] = line[l]; - } - if (n == 0) - continue; - line[n] = '\0'; - } - - if (g_ascii_strcasecmp (line, "[Interface]") == 0) { - if (!_wg_complete_peer (&data_peers, - g_steal_pointer (¤t_peer), - current_peer_start_line_nr, - filename, - error)) - return FALSE; - line_context = LINE_CONTEXT_INTERFACE; - continue; - } - - if (g_ascii_strcasecmp (line, "[Peer]") == 0) { - if (!_wg_complete_peer (&data_peers, - g_steal_pointer (¤t_peer), - current_peer_start_line_nr, - filename, - error)) - return FALSE; - current_peer_start_line_nr = line_nr; - current_peer = nm_wireguard_peer_new (); - line_context = LINE_CONTEXT_PEER; - continue; - } - - if (line_context == LINE_CONTEXT_INTERFACE) { - - if (line_match (line, "Address", &matched_key, &value)) { - char *value_word; - - while (value_split_word (&value, &value_word)) { - GPtrArray **p_data_addr; - NMIPAddr addr_bin; - int addr_family; - int prefix_len; - - if (!nm_utils_parse_inaddr_prefix_bin (AF_UNSPEC, - value_word, - &addr_family, - &addr_bin, - &prefix_len)) - goto fail_invalid_value; - - p_data_addr = (addr_family == AF_INET) - ? &data_addr_v4 - : &data_addr_v6; - - if (!*p_data_addr) - *p_data_addr = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); - - g_ptr_array_add (*p_data_addr, - nm_ip_address_new_binary (addr_family, - &addr_bin, - prefix_len == -1 - ? ((addr_family == AF_INET) ? 32 : 128) - : prefix_len, - NULL)); - } - continue; - } - - if (line_match (line, "MTU", &matched_key, &value)) { - i64 = _nm_utils_ascii_str_to_int64 (value, 0, 0, G_MAXUINT32, -1); - if (i64 == -1) - goto fail_invalid_value; - - /* wg-quick accepts the "MTU" value, but it also fetches routes to - * autodetect it. NetworkManager won't do that, we can only configure - * an explicit MTU or no autodetection will be performed. */ - data_mtu = i64; - continue; - } - - if (line_match (line, "DNS", &matched_key, &value)) { - char *value_word; - - while (value_split_word (&value, &value_word)) { - GPtrArray **p_data_dns; - NMIPAddr addr_bin; - int addr_family; - - if (nm_utils_parse_inaddr_bin (AF_UNSPEC, - value_word, - &addr_family, - &addr_bin)) { - p_data_dns = (addr_family == AF_INET) - ? &data_dns_v4 - : &data_dns_v6; - if (!*p_data_dns) - *p_data_dns = g_ptr_array_new_with_free_func (g_free); - - g_ptr_array_add (*p_data_dns, - nm_utils_inet_ntop_dup (addr_family, &addr_bin)); - continue; - } - - if (!data_dns_search) - data_dns_search = g_ptr_array_new_with_free_func (g_free); - g_ptr_array_add (data_dns_search, g_strdup (value_word)); - } - continue; - } - - if (line_match (line, "Table", &matched_key, &value)) { - - if (nm_streq (value, "auto")) - data_table = _TABLE_AUTO; - else if (nm_streq (value, "off")) - data_table = _TABLE_OFF; - else { - /* we don't support table names from /etc/iproute2/rt_tables - * But we accept hex like `ip route add` would. */ - i64 = _nm_utils_ascii_str_to_int64 (value, 0, 0, G_MAXINT32, -1); - if (i64 == -1) - goto fail_invalid_value; - data_table = i64; - } - continue; - } - - if ( line_match (line, "PreUp", &matched_key, &value) - || line_match (line, "PreDown", &matched_key, &value) - || line_match (line, "PostUp", &matched_key, &value) - || line_match (line, "PostDown", &matched_key, &value)) { - /* we don't run any scripts. Silently ignore these parameters. */ - continue; - } - - if (line_match (line, "SaveConfig", &matched_key, &value)) { - /* we ignore the setting, but enforce that it's either true or false (like - * wg-quick. */ - if (!NM_IN_STRSET (value, "true", "false")) - goto fail_invalid_value; - continue; - } - - if (line_match (line, "ListenPort", &matched_key, &value)) { - /* we don't use getaddrinfo(), unlike `wg setconf`. Just interpret - * the port as plain decimal number. */ - i64 = _nm_utils_ascii_str_to_int64 (value, 10, 0, 0xFFFF, -1); - if (i64 == -1) - goto fail_invalid_value; - data_listen_port = i64; - continue; - } - - if (line_match (line, "FwMark", &matched_key, &value)) { - if (nm_streq (value, "off")) - data_fwmark = 0; - else { - i64 = _nm_utils_ascii_str_to_int64 (value, 0, 0, G_MAXINT32, -1); - if (i64 == -1) - goto fail_invalid_value; - data_fwmark = i64; - } - continue; - } - - if (line_match (line, "PrivateKey", &matched_key, &value)) { - if (!nm_utils_base64secret_decode (value, NM_WIREGUARD_PUBLIC_KEY_LEN, NULL)) - goto fail_invalid_secret; - data_private_key = value; - continue; - } - - goto fail_invalid_line; - } - - - if (line_context == LINE_CONTEXT_PEER) { - - if (line_match (line, "Endpoint", &matched_key, &value)) { - if (!nm_wireguard_peer_set_endpoint (current_peer, value, FALSE)) - goto fail_invalid_value; - continue; - } - - if (line_match (line, "PublicKey", &matched_key, &value)) { - if (!nm_wireguard_peer_set_public_key (current_peer, value, FALSE)) - goto fail_invalid_value; - continue; - } - - if (line_match (line, "AllowedIPs", &matched_key, &value)) { - char *value_word; - - while (value_split_word (&value, &value_word)) { - if (!nm_wireguard_peer_append_allowed_ip (current_peer, - value_word, - FALSE)) - goto fail_invalid_value; - } - continue; - } - - if (line_match (line, "PersistentKeepalive", &matched_key, &value)) { - if (nm_streq (value, "off")) - i64 = 0; - else { - i64 = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT16, -1); - if (i64 == -1) - goto fail_invalid_value; - } - nm_wireguard_peer_set_persistent_keepalive (current_peer, i64); - continue; - } - - if (line_match (line, "PresharedKey", &matched_key, &value)) { - if (!nm_wireguard_peer_set_preshared_key (current_peer, value, FALSE)) - goto fail_invalid_secret; - nm_wireguard_peer_set_preshared_key_flags (current_peer, NM_SETTING_SECRET_FLAG_NONE); - continue; - } - - goto fail_invalid_line; - } + nm_auto_clear_secret_ptr NMSecretPtr file_content = NM_SECRET_PTR_INIT(); + char ifname[IFNAMSIZ]; + gs_free char * uuid = NULL; + gboolean ifname_valid = FALSE; + const char * cstr; + char * line_remainder; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSettingWireGuard * s_wg; + gs_free_error GError *local = NULL; + enum { + LINE_CONTEXT_INIT, + LINE_CONTEXT_INTERFACE, + LINE_CONTEXT_PEER, + } line_context; + gsize line_nr; + gsize current_peer_start_line_nr = 0; + nm_auto_unref_wgpeer NMWireGuardPeer *current_peer = NULL; + gs_unref_ptrarray GPtrArray *data_dns_search = NULL; + gs_unref_ptrarray GPtrArray *data_dns_v4 = NULL; + gs_unref_ptrarray GPtrArray *data_dns_v6 = NULL; + gs_unref_ptrarray GPtrArray *data_addr_v4 = NULL; + gs_unref_ptrarray GPtrArray *data_addr_v6 = NULL; + gs_unref_ptrarray GPtrArray *data_peers = NULL; + const char * data_private_key = NULL; + gint64 data_table; + guint data_listen_port = 0; + guint data_fwmark = 0; + guint data_mtu = 0; + int is_v4; + guint i; + + g_return_val_if_fail(filename, NULL); + g_return_val_if_fail(!error || !*error, NULL); + + /* contrary to "wg-quick", we never interpret the filename as "/etc/wireguard/$INTERFACE.conf". + * If the filename has no '/', it is interpreted as relative to the current working directory. + * However, we do require a suitable filename suffix and that the name corresponds to the interface + * name. */ + cstr = strrchr(filename, '/'); + cstr = cstr ? &cstr[1] : filename; + if (NM_STR_HAS_SUFFIX(cstr, ".conf")) { + gsize len = strlen(cstr) - NM_STRLEN(".conf"); + + if (len > 0 && len < sizeof(ifname)) { + memcpy(ifname, cstr, len); + ifname[len] = '\0'; + + if (nm_utils_ifname_valid(ifname, NMU_IFACE_KERNEL, NULL)) + ifname_valid = TRUE; + } + } + if (!ifname_valid) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_UNKNOWN, + _("The name of the WireGuard config must be a valid interface " + "name followed by \".conf\"")); + return FALSE; + } + + if (!nm_utils_file_get_contents(-1, + filename, + 10 * 1024 * 1024, + NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET, + &file_content.str, + &file_content.len, + NULL, + error)) + return NULL; + + /* We interpret the file like `wg-quick up` and `wg setconf` do. + * + * Of course the WireGuard scripts do something fundamentlly different. They + * perform actions to configure the WireGuard link in kernel, add routes and + * addresses, and call resolvconf. It all happens at the time when the script + * run. + * + * This code here instead generates a NetworkManager connection profile so that + * NetworkManager will apply a similar configuration when later activating the profile. */ + +#define _TABLE_AUTO ((gint64) -1) +#define _TABLE_OFF ((gint64) -2) + + data_table = _TABLE_AUTO; + + line_remainder = file_content.str; + line_context = LINE_CONTEXT_INIT; + line_nr = 0; + while (line_remainder[0] != '\0') { + const char *matched_key = NULL; + char * value = NULL; + char * line; + char ch; + gint64 i64; + + line_nr++; + + line = line_remainder; + line_remainder = strchrnul(line, '\n'); + if (line_remainder[0] != '\0') + (line_remainder++)[0] = '\0'; + + /* Drop all spaces and truncate at first '#'. + * See wg's config_read_line(). + * + * Note that wg-quick doesn't do that. + * + * Neither `wg setconf` nor `wg-quick` does a strict parsing. + * We don't either. Just try to interpret the file (mostly) the same as + * they would. + */ + { + gsize l, n; + + n = 0; + for (l = 0; (ch = line[l]); l++) { + if (g_ascii_isspace(ch)) { + /* wg-setconf strips all whitespace before parsing the content. That means, + * *[I nterface]" will be accepted. We do that too. */ + continue; + } + if (ch == '#') + break; + line[n++] = line[l]; + } + if (n == 0) + continue; + line[n] = '\0'; + } + + if (g_ascii_strcasecmp(line, "[Interface]") == 0) { + if (!_wg_complete_peer(&data_peers, + g_steal_pointer(¤t_peer), + current_peer_start_line_nr, + filename, + error)) + return FALSE; + line_context = LINE_CONTEXT_INTERFACE; + continue; + } + + if (g_ascii_strcasecmp(line, "[Peer]") == 0) { + if (!_wg_complete_peer(&data_peers, + g_steal_pointer(¤t_peer), + current_peer_start_line_nr, + filename, + error)) + return FALSE; + current_peer_start_line_nr = line_nr; + current_peer = nm_wireguard_peer_new(); + line_context = LINE_CONTEXT_PEER; + continue; + } + + if (line_context == LINE_CONTEXT_INTERFACE) { + if (line_match(line, "Address", &matched_key, &value)) { + char *value_word; + + while (value_split_word(&value, &value_word)) { + GPtrArray **p_data_addr; + NMIPAddr addr_bin; + int addr_family; + int prefix_len; + + if (!nm_utils_parse_inaddr_prefix_bin(AF_UNSPEC, + value_word, + &addr_family, + &addr_bin, + &prefix_len)) + goto fail_invalid_value; + + p_data_addr = (addr_family == AF_INET) ? &data_addr_v4 : &data_addr_v6; + + if (!*p_data_addr) + *p_data_addr = + g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); + + g_ptr_array_add( + *p_data_addr, + nm_ip_address_new_binary( + addr_family, + &addr_bin, + prefix_len == -1 ? ((addr_family == AF_INET) ? 32 : 128) : prefix_len, + NULL)); + } + continue; + } + + if (line_match(line, "MTU", &matched_key, &value)) { + i64 = _nm_utils_ascii_str_to_int64(value, 0, 0, G_MAXUINT32, -1); + if (i64 == -1) + goto fail_invalid_value; + + /* wg-quick accepts the "MTU" value, but it also fetches routes to + * autodetect it. NetworkManager won't do that, we can only configure + * an explicit MTU or no autodetection will be performed. */ + data_mtu = i64; + continue; + } + + if (line_match(line, "DNS", &matched_key, &value)) { + char *value_word; + + while (value_split_word(&value, &value_word)) { + GPtrArray **p_data_dns; + NMIPAddr addr_bin; + int addr_family; + + if (nm_utils_parse_inaddr_bin(AF_UNSPEC, value_word, &addr_family, &addr_bin)) { + p_data_dns = (addr_family == AF_INET) ? &data_dns_v4 : &data_dns_v6; + if (!*p_data_dns) + *p_data_dns = g_ptr_array_new_with_free_func(g_free); + + g_ptr_array_add(*p_data_dns, + nm_utils_inet_ntop_dup(addr_family, &addr_bin)); + continue; + } + + if (!data_dns_search) + data_dns_search = g_ptr_array_new_with_free_func(g_free); + g_ptr_array_add(data_dns_search, g_strdup(value_word)); + } + continue; + } + + if (line_match(line, "Table", &matched_key, &value)) { + if (nm_streq(value, "auto")) + data_table = _TABLE_AUTO; + else if (nm_streq(value, "off")) + data_table = _TABLE_OFF; + else { + /* we don't support table names from /etc/iproute2/rt_tables + * But we accept hex like `ip route add` would. */ + i64 = _nm_utils_ascii_str_to_int64(value, 0, 0, G_MAXINT32, -1); + if (i64 == -1) + goto fail_invalid_value; + data_table = i64; + } + continue; + } + + if (line_match(line, "PreUp", &matched_key, &value) + || line_match(line, "PreDown", &matched_key, &value) + || line_match(line, "PostUp", &matched_key, &value) + || line_match(line, "PostDown", &matched_key, &value)) { + /* we don't run any scripts. Silently ignore these parameters. */ + continue; + } + + if (line_match(line, "SaveConfig", &matched_key, &value)) { + /* we ignore the setting, but enforce that it's either true or false (like + * wg-quick. */ + if (!NM_IN_STRSET(value, "true", "false")) + goto fail_invalid_value; + continue; + } + + if (line_match(line, "ListenPort", &matched_key, &value)) { + /* we don't use getaddrinfo(), unlike `wg setconf`. Just interpret + * the port as plain decimal number. */ + i64 = _nm_utils_ascii_str_to_int64(value, 10, 0, 0xFFFF, -1); + if (i64 == -1) + goto fail_invalid_value; + data_listen_port = i64; + continue; + } + + if (line_match(line, "FwMark", &matched_key, &value)) { + if (nm_streq(value, "off")) + data_fwmark = 0; + else { + i64 = _nm_utils_ascii_str_to_int64(value, 0, 0, G_MAXINT32, -1); + if (i64 == -1) + goto fail_invalid_value; + data_fwmark = i64; + } + continue; + } + + if (line_match(line, "PrivateKey", &matched_key, &value)) { + if (!nm_utils_base64secret_decode(value, NM_WIREGUARD_PUBLIC_KEY_LEN, NULL)) + goto fail_invalid_secret; + data_private_key = value; + continue; + } + + goto fail_invalid_line; + } + + if (line_context == LINE_CONTEXT_PEER) { + if (line_match(line, "Endpoint", &matched_key, &value)) { + if (!nm_wireguard_peer_set_endpoint(current_peer, value, FALSE)) + goto fail_invalid_value; + continue; + } + + if (line_match(line, "PublicKey", &matched_key, &value)) { + if (!nm_wireguard_peer_set_public_key(current_peer, value, FALSE)) + goto fail_invalid_value; + continue; + } + + if (line_match(line, "AllowedIPs", &matched_key, &value)) { + char *value_word; + + while (value_split_word(&value, &value_word)) { + if (!nm_wireguard_peer_append_allowed_ip(current_peer, value_word, FALSE)) + goto fail_invalid_value; + } + continue; + } + + if (line_match(line, "PersistentKeepalive", &matched_key, &value)) { + if (nm_streq(value, "off")) + i64 = 0; + else { + i64 = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT16, -1); + if (i64 == -1) + goto fail_invalid_value; + } + nm_wireguard_peer_set_persistent_keepalive(current_peer, i64); + continue; + } + + if (line_match(line, "PresharedKey", &matched_key, &value)) { + if (!nm_wireguard_peer_set_preshared_key(current_peer, value, FALSE)) + goto fail_invalid_secret; + nm_wireguard_peer_set_preshared_key_flags(current_peer, + NM_SETTING_SECRET_FLAG_NONE); + continue; + } + + goto fail_invalid_line; + } fail_invalid_line: - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("unrecognized line at %s:%zu"), - filename, line_nr); - return FALSE; + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("unrecognized line at %s:%zu"), + filename, + line_nr); + return FALSE; fail_invalid_value: - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid value for '%s' at %s:%zu"), - matched_key, filename, line_nr); - return FALSE; + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid value for '%s' at %s:%zu"), + matched_key, + filename, + line_nr); + return FALSE; fail_invalid_secret: - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("invalid secret '%s' at %s:%zu"), - matched_key, filename, line_nr); - return FALSE; - } - - if (!_wg_complete_peer (&data_peers, - g_steal_pointer (¤t_peer), - current_peer_start_line_nr, - filename, - error)) - return FALSE; - - connection = nm_simple_connection_new (); - s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); - nm_connection_add_setting (connection, NM_SETTING (s_con)); - s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); - nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); - nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - s_wg = NM_SETTING_WIREGUARD (nm_setting_wireguard_new ()); - nm_connection_add_setting (connection, NM_SETTING (s_wg)); - - uuid = nm_utils_uuid_generate (); - - g_object_set (s_con, - NM_SETTING_CONNECTION_ID, - ifname, - NM_SETTING_CONNECTION_UUID, - uuid, - NM_SETTING_CONNECTION_TYPE, - NM_SETTING_WIREGUARD_SETTING_NAME, - NM_SETTING_CONNECTION_INTERFACE_NAME, - ifname, - NULL); - - g_object_set (s_wg, - NM_SETTING_WIREGUARD_PRIVATE_KEY, - data_private_key, - NM_SETTING_WIREGUARD_LISTEN_PORT, - data_listen_port, - NM_SETTING_WIREGUARD_FWMARK, - data_fwmark, - NM_SETTING_WIREGUARD_MTU, - data_mtu, - NULL); - - if (data_peers) { - for (i = 0; i < data_peers->len; i++) - nm_setting_wireguard_append_peer (s_wg, data_peers->pdata[i]); - } - - for (is_v4 = 0; is_v4 < 2; is_v4++) { - const char *method_disabled = is_v4 ? NM_SETTING_IP4_CONFIG_METHOD_DISABLED : NM_SETTING_IP6_CONFIG_METHOD_DISABLED; - const char *method_manual = is_v4 ? NM_SETTING_IP4_CONFIG_METHOD_MANUAL : NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - NMSettingIPConfig *s_ip = is_v4 ? s_ip4 : s_ip6; - GPtrArray *data_dns = is_v4 ? data_dns_v4 : data_dns_v6; - GPtrArray *data_addr = is_v4 ? data_addr_v4 : data_addr_v6; - GPtrArray *data_dns_search2 = data_dns_search; - - if (data_dns && !data_addr) { - /* When specifying "DNS", we also require an "Address" for the same address - * family. That is because a NMSettingIPConfig cannot have @method_disabled - * and DNS settings at the same time. - * - * We don't have addresses. Silently ignore the DNS setting. */ - data_dns = NULL; - data_dns_search2 = NULL; - } - - g_object_set (s_ip, - NM_SETTING_IP_CONFIG_METHOD, - data_addr ? method_manual : method_disabled, - NULL); - - /* For WireGuard profiles, always set dns-priority to a negative value, - * so that DNS servers on other profiles get ignored. This is also what - * wg-quick does, by calling `resolvconf -x`. */ - g_object_set (s_ip, - NM_SETTING_IP_CONFIG_DNS_PRIORITY, - (int) -10, - NULL); - - if (data_addr) { - for (i = 0; i < data_addr->len; i++) - nm_setting_ip_config_add_address (s_ip, data_addr->pdata[i]); - } - if (data_dns) { - for (i = 0; i < data_dns->len; i++) - nm_setting_ip_config_add_dns (s_ip, data_dns->pdata[i]); - - /* Of the wg-quick doesn't specify a search domain, assume the user - * wants to use the domain server for all searches. */ - if (!data_dns_search2) - nm_setting_ip_config_add_dns_search (s_ip, "~"); - } - if (data_dns_search2) { - for (i = 0; i < data_dns_search2->len; i++) - nm_setting_ip_config_add_dns_search (s_ip, data_dns_search2->pdata[i]); - } - - if (data_table == _TABLE_AUTO) { - /* in the "auto" setting, wg-quick adds peer-routes automatically to the main - * table. NetworkManager will do that too, but there are differences: - * - * - NetworkManager (contrary to wg-quick) does not check whether the peer-route is necessary. - * It will always add a route for each allowed-ips range, even if there is already another - * route that would ensure packets to the endpoint are routed via the WireGuard interface. - * If you don't want that, disable "wireguard.peer-routes", and add the necessary routes - * yourself to "ipv4.routes" and "ipv6.routes". - * - * - With "auto", wg-quick also configures policy routing to handle default-routes (/0) to - * avoid routing loops. - * The imported connection profile will have wireguard.ip4-auto-default-route and - * wireguard.ip6-auto-default-route set to "default". It will thus configure wg-quick's - * policy routing if the profile has any AllowedIPs ranges with /0. - */ - } else if (data_table == _TABLE_OFF) { - if (is_v4) { - g_object_set (s_wg, - NM_SETTING_WIREGUARD_PEER_ROUTES, - FALSE, - NULL); - } - } else { - g_object_set (s_ip, - NM_SETTING_IP_CONFIG_ROUTE_TABLE, - (guint) data_table, - NULL); - } - } - - if (!nm_connection_normalize (connection, NULL, NULL, &local)) { - nm_utils_error_set (error, NM_UTILS_ERROR_INVALID_ARGUMENT, - _("Failed to create WireGuard connection: %s"), - local->message); - return FALSE; - } - - return g_steal_pointer (&connection); + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid secret '%s' at %s:%zu"), + matched_key, + filename, + line_nr); + return FALSE; + } + + if (!_wg_complete_peer(&data_peers, + g_steal_pointer(¤t_peer), + current_peer_start_line_nr, + filename, + error)) + return FALSE; + + connection = nm_simple_connection_new(); + s_con = NM_SETTING_CONNECTION(nm_setting_connection_new()); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_ip4 = NM_SETTING_IP_CONFIG(nm_setting_ip4_config_new()); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip6 = NM_SETTING_IP_CONFIG(nm_setting_ip6_config_new()); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_wg = NM_SETTING_WIREGUARD(nm_setting_wireguard_new()); + nm_connection_add_setting(connection, NM_SETTING(s_wg)); + + uuid = nm_utils_uuid_generate(); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + ifname, + NM_SETTING_CONNECTION_UUID, + uuid, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIREGUARD_SETTING_NAME, + NM_SETTING_CONNECTION_INTERFACE_NAME, + ifname, + NULL); + + g_object_set(s_wg, + NM_SETTING_WIREGUARD_PRIVATE_KEY, + data_private_key, + NM_SETTING_WIREGUARD_LISTEN_PORT, + data_listen_port, + NM_SETTING_WIREGUARD_FWMARK, + data_fwmark, + NM_SETTING_WIREGUARD_MTU, + data_mtu, + NULL); + + if (data_peers) { + for (i = 0; i < data_peers->len; i++) + nm_setting_wireguard_append_peer(s_wg, data_peers->pdata[i]); + } + + for (is_v4 = 0; is_v4 < 2; is_v4++) { + const char *method_disabled = + is_v4 ? NM_SETTING_IP4_CONFIG_METHOD_DISABLED : NM_SETTING_IP6_CONFIG_METHOD_DISABLED; + const char *method_manual = + is_v4 ? NM_SETTING_IP4_CONFIG_METHOD_MANUAL : NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + NMSettingIPConfig *s_ip = is_v4 ? s_ip4 : s_ip6; + GPtrArray * data_dns = is_v4 ? data_dns_v4 : data_dns_v6; + GPtrArray * data_addr = is_v4 ? data_addr_v4 : data_addr_v6; + GPtrArray * data_dns_search2 = data_dns_search; + + if (data_dns && !data_addr) { + /* When specifying "DNS", we also require an "Address" for the same address + * family. That is because a NMSettingIPConfig cannot have @method_disabled + * and DNS settings at the same time. + * + * We don't have addresses. Silently ignore the DNS setting. */ + data_dns = NULL; + data_dns_search2 = NULL; + } + + g_object_set(s_ip, + NM_SETTING_IP_CONFIG_METHOD, + data_addr ? method_manual : method_disabled, + NULL); + + /* For WireGuard profiles, always set dns-priority to a negative value, + * so that DNS servers on other profiles get ignored. This is also what + * wg-quick does, by calling `resolvconf -x`. */ + g_object_set(s_ip, NM_SETTING_IP_CONFIG_DNS_PRIORITY, (int) -50, NULL); + + if (data_addr) { + for (i = 0; i < data_addr->len; i++) + nm_setting_ip_config_add_address(s_ip, data_addr->pdata[i]); + } + if (data_dns) { + for (i = 0; i < data_dns->len; i++) + nm_setting_ip_config_add_dns(s_ip, data_dns->pdata[i]); + + /* Of the wg-quick doesn't specify a search domain, assume the user + * wants to use the domain server for all searches. */ + if (!data_dns_search2) + nm_setting_ip_config_add_dns_search(s_ip, "~"); + } + if (data_dns_search2) { + for (i = 0; i < data_dns_search2->len; i++) + nm_setting_ip_config_add_dns_search(s_ip, data_dns_search2->pdata[i]); + } + + if (data_table == _TABLE_AUTO) { + /* in the "auto" setting, wg-quick adds peer-routes automatically to the main + * table. NetworkManager will do that too, but there are differences: + * + * - NetworkManager (contrary to wg-quick) does not check whether the peer-route is necessary. + * It will always add a route for each allowed-ips range, even if there is already another + * route that would ensure packets to the endpoint are routed via the WireGuard interface. + * If you don't want that, disable "wireguard.peer-routes", and add the necessary routes + * yourself to "ipv4.routes" and "ipv6.routes". + * + * - With "auto", wg-quick also configures policy routing to handle default-routes (/0) to + * avoid routing loops. + * The imported connection profile will have wireguard.ip4-auto-default-route and + * wireguard.ip6-auto-default-route set to "default". It will thus configure wg-quick's + * policy routing if the profile has any AllowedIPs ranges with /0. + */ + } else if (data_table == _TABLE_OFF) { + if (is_v4) { + g_object_set(s_wg, NM_SETTING_WIREGUARD_PEER_ROUTES, FALSE, NULL); + } + } else { + g_object_set(s_ip, NM_SETTING_IP_CONFIG_ROUTE_TABLE, (guint) data_table, NULL); + } + } + + if (!nm_connection_normalize(connection, NULL, NULL, &local)) { + nm_utils_error_set(error, + NM_UTILS_ERROR_INVALID_ARGUMENT, + _("Failed to create WireGuard connection: %s"), + local->message); + return FALSE; + } + + return g_steal_pointer(&connection); } diff --git a/clients/common/nm-vpn-helpers.h b/clients/common/nm-vpn-helpers.h index f401c634..eedafecf 100644 --- a/clients/common/nm-vpn-helpers.h +++ b/clients/common/nm-vpn-helpers.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2013 - 2015 Red Hat, Inc. */ @@ -7,26 +7,25 @@ #define __NM_VPN_HELPERS_H__ typedef struct { - const char *name; - const char *ui_name; + const char *name; + const char *ui_name; } NmcVpnPasswordName; -GSList *nm_vpn_get_plugin_infos (void); +GSList *nm_vpn_get_plugin_infos(void); -NMVpnEditorPlugin *nm_vpn_get_editor_plugin (const char *service_type, GError **error); +NMVpnEditorPlugin *nm_vpn_get_editor_plugin(const char *service_type, GError **error); -gboolean nm_vpn_supports_ipv6 (NMConnection *connection); +gboolean nm_vpn_supports_ipv6(NMConnection *connection); -const NmcVpnPasswordName *nm_vpn_get_secret_names (const char *service_type); +const NmcVpnPasswordName *nm_vpn_get_secret_names(const char *service_type); -gboolean nm_vpn_openconnect_authenticate_helper (const char *host, - char **cookie, - char **gateway, - char **gwcert, - int *status, - GError **error); +gboolean nm_vpn_openconnect_authenticate_helper(const char *host, + char ** cookie, + char ** gateway, + char ** gwcert, + int * status, + GError ** error); -NMConnection *nm_vpn_wireguard_import (const char *filename, - GError **error); +NMConnection *nm_vpn_wireguard_import(const char *filename, GError **error); -#endif /* __NM_VPN_HELPERS_H__ */ +#endif /* __NM_VPN_HELPERS_H__ */ diff --git a/clients/common/qrcodegen.c b/clients/common/qrcodegen.c index 7cda9659..2c40fcb9 100644 --- a/clients/common/qrcodegen.c +++ b/clients/common/qrcodegen.c @@ -28,12 +28,11 @@ #include "qrcodegen.h" #ifndef QRCODEGEN_TEST - #define testable static // Keep functions private + #define testable static // Keep functions private #else - #define testable // Expose private functions + #define testable // Expose private functions #endif - /*---- Forward declarations for private functions ----*/ // Regarding all public and private functions defined in this source file: @@ -54,20 +53,24 @@ testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen); -testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); +testable void +addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); testable int getNumRawDataModules(int ver); -testable void calcReedSolomonGenerator(int degree, uint8_t result[]); -testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen, - const uint8_t generator[], int degree, uint8_t result[]); +testable void calcReedSolomonGenerator(int degree, uint8_t result[]); +testable void calcReedSolomonRemainder(const uint8_t data[], + int dataLen, + const uint8_t generator[], + int degree, + uint8_t result[]); testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y); testable void initializeFunctionModules(int version, uint8_t qrcode[]); -static void drawWhiteFunctionModules(uint8_t qrcode[], int version); -static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]); -testable int getAlignmentPatternPositions(int version, uint8_t result[7]); -static void fillRectangle(int left, int top, int width, int height, uint8_t qrcode[]); +static void drawWhiteFunctionModules(uint8_t qrcode[], int version); +static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]); +testable int getAlignmentPatternPositions(int version, uint8_t result[7]); +static void fillRectangle(int left, int top, int width, int height, uint8_t qrcode[]); static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]); static void applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qrcodegen_Mask mask); @@ -78,13 +81,11 @@ static bool hasFinderLikePattern(unsigned char runHistory[7]); testable bool getModule(const uint8_t qrcode[], int x, int y); testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack); testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack); -static bool getBit(int x, int i); +static bool getBit(int x, int i); testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars); testable int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version); -static int numCharCountBits(enum qrcodegen_Mode mode, int version); - - +static int numCharCountBits(enum qrcodegen_Mode mode, int version); /*---- Private tables of constants ----*/ @@ -94,737 +95,841 @@ static const char *ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ // For generating error correction codes. testable const int8_t ECC_CODEWORDS_PER_BLOCK[4][41] = { - // Version: (note that index 0 is for padding, and is set to an illegal value) - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level - {-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Low - {-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28}, // Medium - {-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Quartile - {-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // High + // Version: (note that index 0 is for padding, and is set to an illegal value) + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level + {-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, + 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Low + {-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, + 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28}, // Medium + {-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, + 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Quartile + {-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, + 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // High }; #define qrcodegen_REED_SOLOMON_DEGREE_MAX 30 // Based on the table above // For generating error correction codes. testable const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41] = { - // Version: (note that index 0 is for padding, and is set to an illegal value) - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level - {-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25}, // Low - {-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49}, // Medium - {-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68}, // Quartile - {-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81}, // High + // Version: (note that index 0 is for padding, and is set to an illegal value) + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level + {-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, + 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25}, // Low + {-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, + 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49}, // Medium + {-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, + 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68}, // Quartile + {-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, + 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81}, // High }; // For automatic mask pattern selection. -static const int PENALTY_N1 = 3; -static const int PENALTY_N2 = 3; +static const int PENALTY_N1 = 3; +static const int PENALTY_N2 = 3; static const int PENALTY_N3 = 40; static const int PENALTY_N4 = 10; - - /*---- High-level QR Code encoding functions ----*/ // Public function - see documentation comment in header file. -bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], - enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { - - size_t textLen = strlen(text); - if (textLen == 0) - return qrcodegen_encodeSegmentsAdvanced(NULL, 0, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode); - size_t bufLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); - - struct qrcodegen_Segment seg; - if (qrcodegen_isNumeric(text)) { - if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, textLen) > bufLen) - goto fail; - seg = qrcodegen_makeNumeric(text, tempBuffer); - } else if (qrcodegen_isAlphanumeric(text)) { - if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, textLen) > bufLen) - goto fail; - seg = qrcodegen_makeAlphanumeric(text, tempBuffer); - } else { - if (textLen > bufLen) - goto fail; - for (size_t i = 0; i < textLen; i++) - tempBuffer[i] = (uint8_t)text[i]; - seg.mode = qrcodegen_Mode_BYTE; - seg.bitLength = calcSegmentBitLength(seg.mode, textLen); - if (seg.bitLength == -1) - goto fail; - seg.numChars = (int)textLen; - seg.data = tempBuffer; - } - return qrcodegen_encodeSegmentsAdvanced(&seg, 1, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode); +bool +qrcodegen_encodeText(const char * text, + uint8_t tempBuffer[], + uint8_t qrcode[], + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + enum qrcodegen_Mask mask, + bool boostEcl) +{ + size_t textLen = strlen(text); + if (textLen == 0) + return qrcodegen_encodeSegmentsAdvanced(NULL, + 0, + ecl, + minVersion, + maxVersion, + mask, + boostEcl, + tempBuffer, + qrcode); + size_t bufLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); + + struct qrcodegen_Segment seg; + if (qrcodegen_isNumeric(text)) { + if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, textLen) > bufLen) + goto fail; + seg = qrcodegen_makeNumeric(text, tempBuffer); + } else if (qrcodegen_isAlphanumeric(text)) { + if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, textLen) > bufLen) + goto fail; + seg = qrcodegen_makeAlphanumeric(text, tempBuffer); + } else { + if (textLen > bufLen) + goto fail; + for (size_t i = 0; i < textLen; i++) + tempBuffer[i] = (uint8_t) text[i]; + seg.mode = qrcodegen_Mode_BYTE; + seg.bitLength = calcSegmentBitLength(seg.mode, textLen); + if (seg.bitLength == -1) + goto fail; + seg.numChars = (int) textLen; + seg.data = tempBuffer; + } + return qrcodegen_encodeSegmentsAdvanced(&seg, + 1, + ecl, + minVersion, + maxVersion, + mask, + boostEcl, + tempBuffer, + qrcode); fail: - qrcode[0] = 0; // Set size to invalid value for safety - return false; + qrcode[0] = 0; // Set size to invalid value for safety + return false; } - // Public function - see documentation comment in header file. -bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], - enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { - - struct qrcodegen_Segment seg; - seg.mode = qrcodegen_Mode_BYTE; - seg.bitLength = calcSegmentBitLength(seg.mode, dataLen); - if (seg.bitLength == -1) { - qrcode[0] = 0; // Set size to invalid value for safety - return false; - } - seg.numChars = (int)dataLen; - seg.data = dataAndTemp; - return qrcodegen_encodeSegmentsAdvanced(&seg, 1, ecl, minVersion, maxVersion, mask, boostEcl, dataAndTemp, qrcode); +bool +qrcodegen_encodeBinary(uint8_t dataAndTemp[], + size_t dataLen, + uint8_t qrcode[], + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + enum qrcodegen_Mask mask, + bool boostEcl) +{ + struct qrcodegen_Segment seg; + seg.mode = qrcodegen_Mode_BYTE; + seg.bitLength = calcSegmentBitLength(seg.mode, dataLen); + if (seg.bitLength == -1) { + qrcode[0] = 0; // Set size to invalid value for safety + return false; + } + seg.numChars = (int) dataLen; + seg.data = dataAndTemp; + return qrcodegen_encodeSegmentsAdvanced(&seg, + 1, + ecl, + minVersion, + maxVersion, + mask, + boostEcl, + dataAndTemp, + qrcode); } - // Appends the given number of low-order bits of the given value to the given byte-based // bit buffer, increasing the bit length. Requires 0 <= numBits <= 16 and val < 2^numBits. -testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) { - assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0); - for (int i = numBits - 1; i >= 0; i--, (*bitLen)++) - buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7)); +testable void +appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) +{ + assert(0 <= numBits && numBits <= 16 && (unsigned long) val >> numBits == 0); + for (int i = numBits - 1; i >= 0; i--, (*bitLen)++) + buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7)); } - - /*---- Low-level QR Code encoding functions ----*/ // Public function - see documentation comment in header file. -bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, - enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]) { - return qrcodegen_encodeSegmentsAdvanced(segs, len, ecl, - qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, -1, true, tempBuffer, qrcode); +bool +qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], + size_t len, + enum qrcodegen_Ecc ecl, + uint8_t tempBuffer[], + uint8_t qrcode[]) +{ + return qrcodegen_encodeSegmentsAdvanced(segs, + len, + ecl, + qrcodegen_VERSION_MIN, + qrcodegen_VERSION_MAX, + -1, + true, + tempBuffer, + qrcode); } - // Public function - see documentation comment in header file. -bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl, - int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]) { - assert(segs != NULL || len == 0); - assert(qrcodegen_VERSION_MIN <= minVersion && minVersion <= maxVersion && maxVersion <= qrcodegen_VERSION_MAX); - assert(0 <= (int)ecl && (int)ecl <= 3 && -1 <= (int)mask && (int)mask <= 7); - - // Find the minimal version number to use - int version, dataUsedBits; - for (version = minVersion; ; version++) { - int dataCapacityBits = getNumDataCodewords(version, ecl) * 8; // Number of data bits available - dataUsedBits = getTotalBits(segs, len, version); - if (dataUsedBits != -1 && dataUsedBits <= dataCapacityBits) - break; // This version number is found to be suitable - if (version >= maxVersion) { // All versions in the range could not fit the given data - qrcode[0] = 0; // Set size to invalid value for safety - return false; - } - } - assert(dataUsedBits != -1); - - // Increase the error correction level while the data still fits in the current version number - for (int i = (int)qrcodegen_Ecc_MEDIUM; i <= (int)qrcodegen_Ecc_HIGH; i++) { // From low to high - if (boostEcl && dataUsedBits <= getNumDataCodewords(version, (enum qrcodegen_Ecc)i) * 8) - ecl = (enum qrcodegen_Ecc)i; - } - - // Concatenate all segments to create the data bit string - memset(qrcode, 0, qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0])); - int bitLen = 0; - for (size_t i = 0; i < len; i++) { - const struct qrcodegen_Segment *seg = &segs[i]; - appendBitsToBuffer((int)seg->mode, 4, qrcode, &bitLen); - appendBitsToBuffer(seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen); - for (int j = 0; j < seg->bitLength; j++) - appendBitsToBuffer((seg->data[j >> 3] >> (7 - (j & 7))) & 1, 1, qrcode, &bitLen); - } - assert(bitLen == dataUsedBits); - - // Add terminator and pad up to a byte if applicable - int dataCapacityBits = getNumDataCodewords(version, ecl) * 8; - assert(bitLen <= dataCapacityBits); - int terminatorBits = dataCapacityBits - bitLen; - if (terminatorBits > 4) - terminatorBits = 4; - appendBitsToBuffer(0, terminatorBits, qrcode, &bitLen); - appendBitsToBuffer(0, (8 - bitLen % 8) % 8, qrcode, &bitLen); - assert(bitLen % 8 == 0); - - // Pad with alternating bytes until data capacity is reached - for (uint8_t padByte = 0xEC; bitLen < dataCapacityBits; padByte ^= 0xEC ^ 0x11) - appendBitsToBuffer(padByte, 8, qrcode, &bitLen); - - // Draw function and data codeword modules - addEccAndInterleave(qrcode, version, ecl, tempBuffer); - initializeFunctionModules(version, qrcode); - drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode); - drawWhiteFunctionModules(qrcode, version); - initializeFunctionModules(version, tempBuffer); - - // Handle masking - if (mask == qrcodegen_Mask_AUTO) { // Automatically choose best mask - long minPenalty = LONG_MAX; - for (int i = 0; i < 8; i++) { - enum qrcodegen_Mask msk = (enum qrcodegen_Mask)i; - drawFormatBits(ecl, msk, qrcode); - applyMask(tempBuffer, qrcode, msk); - long penalty = getPenaltyScore(qrcode); - if (penalty < minPenalty) { - mask = msk; - minPenalty = penalty; - } - applyMask(tempBuffer, qrcode, msk); // Undoes the mask due to XOR - } - } - assert(0 <= (int)mask && (int)mask <= 7); - drawFormatBits(ecl, mask, qrcode); - applyMask(tempBuffer, qrcode, mask); - return true; +bool +qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], + size_t len, + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + int mask, + bool boostEcl, + uint8_t tempBuffer[], + uint8_t qrcode[]) +{ + assert(segs != NULL || len == 0); + assert(qrcodegen_VERSION_MIN <= minVersion && minVersion <= maxVersion + && maxVersion <= qrcodegen_VERSION_MAX); + assert(0 <= (int) ecl && (int) ecl <= 3 && -1 <= (int) mask && (int) mask <= 7); + + // Find the minimal version number to use + int version, dataUsedBits; + for (version = minVersion;; version++) { + int dataCapacityBits = + getNumDataCodewords(version, ecl) * 8; // Number of data bits available + dataUsedBits = getTotalBits(segs, len, version); + if (dataUsedBits != -1 && dataUsedBits <= dataCapacityBits) + break; // This version number is found to be suitable + if (version >= maxVersion) { // All versions in the range could not fit the given data + qrcode[0] = 0; // Set size to invalid value for safety + return false; + } + } + assert(dataUsedBits != -1); + + // Increase the error correction level while the data still fits in the current version number + for (int i = (int) qrcodegen_Ecc_MEDIUM; i <= (int) qrcodegen_Ecc_HIGH; + i++) { // From low to high + if (boostEcl && dataUsedBits <= getNumDataCodewords(version, (enum qrcodegen_Ecc) i) * 8) + ecl = (enum qrcodegen_Ecc) i; + } + + // Concatenate all segments to create the data bit string + memset(qrcode, 0, qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0])); + int bitLen = 0; + for (size_t i = 0; i < len; i++) { + const struct qrcodegen_Segment *seg = &segs[i]; + appendBitsToBuffer((int) seg->mode, 4, qrcode, &bitLen); + appendBitsToBuffer(seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen); + for (int j = 0; j < seg->bitLength; j++) + appendBitsToBuffer((seg->data[j >> 3] >> (7 - (j & 7))) & 1, 1, qrcode, &bitLen); + } + assert(bitLen == dataUsedBits); + + // Add terminator and pad up to a byte if applicable + int dataCapacityBits = getNumDataCodewords(version, ecl) * 8; + assert(bitLen <= dataCapacityBits); + int terminatorBits = dataCapacityBits - bitLen; + if (terminatorBits > 4) + terminatorBits = 4; + appendBitsToBuffer(0, terminatorBits, qrcode, &bitLen); + appendBitsToBuffer(0, (8 - bitLen % 8) % 8, qrcode, &bitLen); + assert(bitLen % 8 == 0); + + // Pad with alternating bytes until data capacity is reached + for (uint8_t padByte = 0xEC; bitLen < dataCapacityBits; padByte ^= 0xEC ^ 0x11) + appendBitsToBuffer(padByte, 8, qrcode, &bitLen); + + // Draw function and data codeword modules + addEccAndInterleave(qrcode, version, ecl, tempBuffer); + initializeFunctionModules(version, qrcode); + drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode); + drawWhiteFunctionModules(qrcode, version); + initializeFunctionModules(version, tempBuffer); + + // Handle masking + if (mask == qrcodegen_Mask_AUTO) { // Automatically choose best mask + long minPenalty = LONG_MAX; + for (int i = 0; i < 8; i++) { + enum qrcodegen_Mask msk = (enum qrcodegen_Mask) i; + drawFormatBits(ecl, msk, qrcode); + applyMask(tempBuffer, qrcode, msk); + long penalty = getPenaltyScore(qrcode); + if (penalty < minPenalty) { + mask = msk; + minPenalty = penalty; + } + applyMask(tempBuffer, qrcode, msk); // Undoes the mask due to XOR + } + } + assert(0 <= (int) mask && (int) mask <= 7); + drawFormatBits(ecl, mask, qrcode); + applyMask(tempBuffer, qrcode, mask); + return true; } - - /*---- Error correction code generation functions ----*/ // Appends error correction bytes to each block of the given data array, then interleaves // bytes from the blocks and stores them in the result array. data[0 : dataLen] contains // the input data. data[dataLen : rawCodewords] is used as a temporary work area and will // be clobbered by this function. The final answer is stored in result[0 : rawCodewords]. -testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) { - // Calculate parameter numbers - assert(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); - int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; - int blockEccLen = ECC_CODEWORDS_PER_BLOCK [(int)ecl][version]; - int rawCodewords = getNumRawDataModules(version) / 8; - int dataLen = getNumDataCodewords(version, ecl); - int numShortBlocks = numBlocks - rawCodewords % numBlocks; - int shortBlockDataLen = rawCodewords / numBlocks - blockEccLen; - - // Split data into blocks, calculate ECC, and interleave - // (not concatenate) the bytes into a single sequence - uint8_t generator[qrcodegen_REED_SOLOMON_DEGREE_MAX]; - calcReedSolomonGenerator(blockEccLen, generator); - const uint8_t *dat = data; - for (int i = 0; i < numBlocks; i++) { - int datLen = shortBlockDataLen + (i < numShortBlocks ? 0 : 1); - uint8_t *ecc = &data[dataLen]; // Temporary storage - calcReedSolomonRemainder(dat, datLen, generator, blockEccLen, ecc); - for (int j = 0, k = i; j < datLen; j++, k += numBlocks) { // Copy data - if (j == shortBlockDataLen) - k -= numShortBlocks; - result[k] = dat[j]; - } - for (int j = 0, k = dataLen + i; j < blockEccLen; j++, k += numBlocks) // Copy ECC - result[k] = ecc[j]; - dat += datLen; - } +testable void +addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) +{ + // Calculate parameter numbers + assert(0 <= (int) ecl && (int) ecl < 4 && qrcodegen_VERSION_MIN <= version + && version <= qrcodegen_VERSION_MAX); + int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int) ecl][version]; + int blockEccLen = ECC_CODEWORDS_PER_BLOCK[(int) ecl][version]; + int rawCodewords = getNumRawDataModules(version) / 8; + int dataLen = getNumDataCodewords(version, ecl); + int numShortBlocks = numBlocks - rawCodewords % numBlocks; + int shortBlockDataLen = rawCodewords / numBlocks - blockEccLen; + + // Split data into blocks, calculate ECC, and interleave + // (not concatenate) the bytes into a single sequence + uint8_t generator[qrcodegen_REED_SOLOMON_DEGREE_MAX]; + calcReedSolomonGenerator(blockEccLen, generator); + const uint8_t *dat = data; + for (int i = 0; i < numBlocks; i++) { + int datLen = shortBlockDataLen + (i < numShortBlocks ? 0 : 1); + uint8_t *ecc = &data[dataLen]; // Temporary storage + calcReedSolomonRemainder(dat, datLen, generator, blockEccLen, ecc); + for (int j = 0, k = i; j < datLen; j++, k += numBlocks) { // Copy data + if (j == shortBlockDataLen) + k -= numShortBlocks; + result[k] = dat[j]; + } + for (int j = 0, k = dataLen + i; j < blockEccLen; j++, k += numBlocks) // Copy ECC + result[k] = ecc[j]; + dat += datLen; + } } - // Returns the number of 8-bit codewords that can be used for storing data (not ECC), // for the given version number and error correction level. The result is in the range [9, 2956]. -testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl) { - int v = version, e = (int)ecl; - assert(0 <= e && e < 4); - return getNumRawDataModules(v) / 8 - - ECC_CODEWORDS_PER_BLOCK [e][v] - * NUM_ERROR_CORRECTION_BLOCKS[e][v]; +testable int +getNumDataCodewords(int version, enum qrcodegen_Ecc ecl) +{ + int v = version, e = (int) ecl; + assert(0 <= e && e < 4); + return getNumRawDataModules(v) / 8 + - ECC_CODEWORDS_PER_BLOCK[e][v] * NUM_ERROR_CORRECTION_BLOCKS[e][v]; } - // Returns the number of data bits that can be stored in a QR Code of the given version number, after // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8. // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table. -testable int getNumRawDataModules(int ver) { - assert(qrcodegen_VERSION_MIN <= ver && ver <= qrcodegen_VERSION_MAX); - int result = (16 * ver + 128) * ver + 64; - if (ver >= 2) { - int numAlign = ver / 7 + 2; - result -= (25 * numAlign - 10) * numAlign - 55; - if (ver >= 7) - result -= 36; - } - return result; +testable int +getNumRawDataModules(int ver) +{ + assert(qrcodegen_VERSION_MIN <= ver && ver <= qrcodegen_VERSION_MAX); + int result = (16 * ver + 128) * ver + 64; + if (ver >= 2) { + int numAlign = ver / 7 + 2; + result -= (25 * numAlign - 10) * numAlign - 55; + if (ver >= 7) + result -= 36; + } + return result; } - - /*---- Reed-Solomon ECC generator functions ----*/ // Calculates the Reed-Solomon generator polynomial of the given degree, storing in result[0 : degree]. -testable void calcReedSolomonGenerator(int degree, uint8_t result[]) { - // Start with the monomial x^0 - assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); - memset(result, 0, degree * sizeof(result[0])); - result[degree - 1] = 1; - - // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), - // drop the highest term, and store the rest of the coefficients in order of descending powers. - // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D). - uint8_t root = 1; - for (int i = 0; i < degree; i++) { - // Multiply the current product by (x - r^i) - for (int j = 0; j < degree; j++) { - result[j] = finiteFieldMultiply(result[j], root); - if (j + 1 < degree) - result[j] ^= result[j + 1]; - } - root = finiteFieldMultiply(root, 0x02); - } +testable void +calcReedSolomonGenerator(int degree, uint8_t result[]) +{ + // Start with the monomial x^0 + assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); + memset(result, 0, degree * sizeof(result[0])); + result[degree - 1] = 1; + + // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), + // drop the highest term, and store the rest of the coefficients in order of descending powers. + // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D). + uint8_t root = 1; + for (int i = 0; i < degree; i++) { + // Multiply the current product by (x - r^i) + for (int j = 0; j < degree; j++) { + result[j] = finiteFieldMultiply(result[j], root); + if (j + 1 < degree) + result[j] ^= result[j + 1]; + } + root = finiteFieldMultiply(root, 0x02); + } } - // Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all // polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree]. -testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen, - const uint8_t generator[], int degree, uint8_t result[]) { - - // Perform polynomial division - assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); - memset(result, 0, degree * sizeof(result[0])); - for (int i = 0; i < dataLen; i++) { - uint8_t factor = data[i] ^ result[0]; - memmove(&result[0], &result[1], (degree - 1) * sizeof(result[0])); - result[degree - 1] = 0; - for (int j = 0; j < degree; j++) - result[j] ^= finiteFieldMultiply(generator[j], factor); - } +testable void +calcReedSolomonRemainder(const uint8_t data[], + int dataLen, + const uint8_t generator[], + int degree, + uint8_t result[]) +{ + // Perform polynomial division + assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX); + memset(result, 0, degree * sizeof(result[0])); + for (int i = 0; i < dataLen; i++) { + uint8_t factor = data[i] ^ result[0]; + memmove(&result[0], &result[1], (degree - 1) * sizeof(result[0])); + result[degree - 1] = 0; + for (int j = 0; j < degree; j++) + result[j] ^= finiteFieldMultiply(generator[j], factor); + } } #undef qrcodegen_REED_SOLOMON_DEGREE_MAX - // Returns the product of the two given field elements modulo GF(2^8/0x11D). // All inputs are valid. This could be implemented as a 256*256 lookup table. -testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y) { - // Russian peasant multiplication - uint8_t z = 0; - for (int i = 7; i >= 0; i--) { - z = (z << 1) ^ ((z >> 7) * 0x11D); - z ^= ((y >> i) & 1) * x; - } - return z; +testable uint8_t +finiteFieldMultiply(uint8_t x, uint8_t y) +{ + // Russian peasant multiplication + uint8_t z = 0; + for (int i = 7; i >= 0; i--) { + z = (z << 1) ^ ((z >> 7) * 0x11D); + z ^= ((y >> i) & 1) * x; + } + return z; } - - /*---- Drawing function modules ----*/ // Clears the given QR Code grid with white modules for the given // version's size, then marks every function module as black. -testable void initializeFunctionModules(int version, uint8_t qrcode[]) { - // Initialize QR Code - int qrsize = version * 4 + 17; - memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0])); - qrcode[0] = (uint8_t)qrsize; - - // Fill horizontal and vertical timing patterns - fillRectangle(6, 0, 1, qrsize, qrcode); - fillRectangle(0, 6, qrsize, 1, qrcode); - - // Fill 3 finder patterns (all corners except bottom right) and format bits - fillRectangle(0, 0, 9, 9, qrcode); - fillRectangle(qrsize - 8, 0, 8, 9, qrcode); - fillRectangle(0, qrsize - 8, 9, 8, qrcode); - - // Fill numerous alignment patterns - uint8_t alignPatPos[7]; - int numAlign = getAlignmentPatternPositions(version, alignPatPos); - for (int i = 0; i < numAlign; i++) { - for (int j = 0; j < numAlign; j++) { - // Don't draw on the three finder corners - if (!((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0))) - fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode); - } - } - - // Fill version blocks - if (version >= 7) { - fillRectangle(qrsize - 11, 0, 3, 6, qrcode); - fillRectangle(0, qrsize - 11, 6, 3, qrcode); - } +testable void +initializeFunctionModules(int version, uint8_t qrcode[]) +{ + // Initialize QR Code + int qrsize = version * 4 + 17; + memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0])); + qrcode[0] = (uint8_t) qrsize; + + // Fill horizontal and vertical timing patterns + fillRectangle(6, 0, 1, qrsize, qrcode); + fillRectangle(0, 6, qrsize, 1, qrcode); + + // Fill 3 finder patterns (all corners except bottom right) and format bits + fillRectangle(0, 0, 9, 9, qrcode); + fillRectangle(qrsize - 8, 0, 8, 9, qrcode); + fillRectangle(0, qrsize - 8, 9, 8, qrcode); + + // Fill numerous alignment patterns + uint8_t alignPatPos[7]; + int numAlign = getAlignmentPatternPositions(version, alignPatPos); + for (int i = 0; i < numAlign; i++) { + for (int j = 0; j < numAlign; j++) { + // Don't draw on the three finder corners + if (!((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) + || (i == numAlign - 1 && j == 0))) + fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode); + } + } + + // Fill version blocks + if (version >= 7) { + fillRectangle(qrsize - 11, 0, 3, 6, qrcode); + fillRectangle(0, qrsize - 11, 6, 3, qrcode); + } } - // Draws white function modules and possibly some black modules onto the given QR Code, without changing // non-function modules. This does not draw the format bits. This requires all function modules to be previously // marked black (namely by initializeFunctionModules()), because this may skip redrawing black function modules. -static void drawWhiteFunctionModules(uint8_t qrcode[], int version) { - // Draw horizontal and vertical timing patterns - int qrsize = qrcodegen_getSize(qrcode); - for (int i = 7; i < qrsize - 7; i += 2) { - setModule(qrcode, 6, i, false); - setModule(qrcode, i, 6, false); - } - - // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules) - for (int dy = -4; dy <= 4; dy++) { - for (int dx = -4; dx <= 4; dx++) { - int dist = abs(dx); - if (abs(dy) > dist) - dist = abs(dy); - if (dist == 2 || dist == 4) { - setModuleBounded(qrcode, 3 + dx, 3 + dy, false); - setModuleBounded(qrcode, qrsize - 4 + dx, 3 + dy, false); - setModuleBounded(qrcode, 3 + dx, qrsize - 4 + dy, false); - } - } - } - - // Draw numerous alignment patterns - uint8_t alignPatPos[7]; - int numAlign = getAlignmentPatternPositions(version, alignPatPos); - for (int i = 0; i < numAlign; i++) { - for (int j = 0; j < numAlign; j++) { - if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)) - continue; // Don't draw on the three finder corners - for (int dy = -1; dy <= 1; dy++) { - for (int dx = -1; dx <= 1; dx++) - setModule(qrcode, alignPatPos[i] + dx, alignPatPos[j] + dy, dx == 0 && dy == 0); - } - } - } - - // Draw version blocks - if (version >= 7) { - // Calculate error correction code and pack bits - int rem = version; // version is uint6, in the range [7, 40] - for (int i = 0; i < 12; i++) - rem = (rem << 1) ^ ((rem >> 11) * 0x1F25); - long bits = (long)version << 12 | rem; // uint18 - assert(bits >> 18 == 0); - - // Draw two copies - for (int i = 0; i < 6; i++) { - for (int j = 0; j < 3; j++) { - int k = qrsize - 11 + j; - setModule(qrcode, k, i, (bits & 1) != 0); - setModule(qrcode, i, k, (bits & 1) != 0); - bits >>= 1; - } - } - } +static void +drawWhiteFunctionModules(uint8_t qrcode[], int version) +{ + // Draw horizontal and vertical timing patterns + int qrsize = qrcodegen_getSize(qrcode); + for (int i = 7; i < qrsize - 7; i += 2) { + setModule(qrcode, 6, i, false); + setModule(qrcode, i, 6, false); + } + + // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules) + for (int dy = -4; dy <= 4; dy++) { + for (int dx = -4; dx <= 4; dx++) { + int dist = abs(dx); + if (abs(dy) > dist) + dist = abs(dy); + if (dist == 2 || dist == 4) { + setModuleBounded(qrcode, 3 + dx, 3 + dy, false); + setModuleBounded(qrcode, qrsize - 4 + dx, 3 + dy, false); + setModuleBounded(qrcode, 3 + dx, qrsize - 4 + dy, false); + } + } + } + + // Draw numerous alignment patterns + uint8_t alignPatPos[7]; + int numAlign = getAlignmentPatternPositions(version, alignPatPos); + for (int i = 0; i < numAlign; i++) { + for (int j = 0; j < numAlign; j++) { + if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) + || (i == numAlign - 1 && j == 0)) + continue; // Don't draw on the three finder corners + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) + setModule(qrcode, alignPatPos[i] + dx, alignPatPos[j] + dy, dx == 0 && dy == 0); + } + } + } + + // Draw version blocks + if (version >= 7) { + // Calculate error correction code and pack bits + int rem = version; // version is uint6, in the range [7, 40] + for (int i = 0; i < 12; i++) + rem = (rem << 1) ^ ((rem >> 11) * 0x1F25); + long bits = (long) version << 12 | rem; // uint18 + assert(bits >> 18 == 0); + + // Draw two copies + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 3; j++) { + int k = qrsize - 11 + j; + setModule(qrcode, k, i, (bits & 1) != 0); + setModule(qrcode, i, k, (bits & 1) != 0); + bits >>= 1; + } + } + } } - // Draws two copies of the format bits (with its own error correction code) based // on the given mask and error correction level. This always draws all modules of // the format bits, unlike drawWhiteFunctionModules() which might skip black modules. -static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]) { - // Calculate error correction code and pack bits - assert(0 <= (int)mask && (int)mask <= 7); - static const int table[] = {1, 0, 3, 2}; - int data = table[(int)ecl] << 3 | (int)mask; // errCorrLvl is uint2, mask is uint3 - int rem = data; - for (int i = 0; i < 10; i++) - rem = (rem << 1) ^ ((rem >> 9) * 0x537); - int bits = (data << 10 | rem) ^ 0x5412; // uint15 - assert(bits >> 15 == 0); - - // Draw first copy - for (int i = 0; i <= 5; i++) - setModule(qrcode, 8, i, getBit(bits, i)); - setModule(qrcode, 8, 7, getBit(bits, 6)); - setModule(qrcode, 8, 8, getBit(bits, 7)); - setModule(qrcode, 7, 8, getBit(bits, 8)); - for (int i = 9; i < 15; i++) - setModule(qrcode, 14 - i, 8, getBit(bits, i)); - - // Draw second copy - int qrsize = qrcodegen_getSize(qrcode); - for (int i = 0; i < 8; i++) - setModule(qrcode, qrsize - 1 - i, 8, getBit(bits, i)); - for (int i = 8; i < 15; i++) - setModule(qrcode, 8, qrsize - 15 + i, getBit(bits, i)); - setModule(qrcode, 8, qrsize - 8, true); // Always black +static void +drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]) +{ + // Calculate error correction code and pack bits + assert(0 <= (int) mask && (int) mask <= 7); + static const int table[] = {1, 0, 3, 2}; + int data = table[(int) ecl] << 3 | (int) mask; // errCorrLvl is uint2, mask is uint3 + int rem = data; + for (int i = 0; i < 10; i++) + rem = (rem << 1) ^ ((rem >> 9) * 0x537); + int bits = (data << 10 | rem) ^ 0x5412; // uint15 + assert(bits >> 15 == 0); + + // Draw first copy + for (int i = 0; i <= 5; i++) + setModule(qrcode, 8, i, getBit(bits, i)); + setModule(qrcode, 8, 7, getBit(bits, 6)); + setModule(qrcode, 8, 8, getBit(bits, 7)); + setModule(qrcode, 7, 8, getBit(bits, 8)); + for (int i = 9; i < 15; i++) + setModule(qrcode, 14 - i, 8, getBit(bits, i)); + + // Draw second copy + int qrsize = qrcodegen_getSize(qrcode); + for (int i = 0; i < 8; i++) + setModule(qrcode, qrsize - 1 - i, 8, getBit(bits, i)); + for (int i = 8; i < 15; i++) + setModule(qrcode, 8, qrsize - 15 + i, getBit(bits, i)); + setModule(qrcode, 8, qrsize - 8, true); // Always black } - // Calculates and stores an ascending list of positions of alignment patterns // for this version number, returning the length of the list (in the range [0,7]). // Each position is in the range [0,177), and are used on both the x and y axes. // This could be implemented as lookup table of 40 variable-length lists of unsigned bytes. -testable int getAlignmentPatternPositions(int version, uint8_t result[7]) { - if (version == 1) - return 0; - int numAlign = version / 7 + 2; - int step = (version == 32) ? 26 : - (version*4 + numAlign*2 + 1) / (numAlign*2 - 2) * 2; - for (int i = numAlign - 1, pos = version * 4 + 10; i >= 1; i--, pos -= step) - result[i] = pos; - result[0] = 6; - return numAlign; +testable int +getAlignmentPatternPositions(int version, uint8_t result[7]) +{ + if (version == 1) + return 0; + int numAlign = version / 7 + 2; + int step = (version == 32) ? 26 : (version * 4 + numAlign * 2 + 1) / (numAlign * 2 - 2) * 2; + for (int i = numAlign - 1, pos = version * 4 + 10; i >= 1; i--, pos -= step) + result[i] = pos; + result[0] = 6; + return numAlign; } - // Sets every pixel in the range [left : left + width] * [top : top + height] to black. -static void fillRectangle(int left, int top, int width, int height, uint8_t qrcode[]) { - for (int dy = 0; dy < height; dy++) { - for (int dx = 0; dx < width; dx++) - setModule(qrcode, left + dx, top + dy, true); - } +static void +fillRectangle(int left, int top, int width, int height, uint8_t qrcode[]) +{ + for (int dy = 0; dy < height; dy++) { + for (int dx = 0; dx < width; dx++) + setModule(qrcode, left + dx, top + dy, true); + } } - - /*---- Drawing data modules and masking ----*/ // Draws the raw codewords (including data and ECC) onto the given QR Code. This requires the initial state of // the QR Code to be black at function modules and white at codeword modules (including unused remainder bits). -static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) { - int qrsize = qrcodegen_getSize(qrcode); - int i = 0; // Bit index into the data - // Do the funny zigzag scan - for (int right = qrsize - 1; right >= 1; right -= 2) { // Index of right column in each column pair - if (right == 6) - right = 5; - for (int vert = 0; vert < qrsize; vert++) { // Vertical counter - for (int j = 0; j < 2; j++) { - int x = right - j; // Actual x coordinate - bool upward = ((right + 1) & 2) == 0; - int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate - if (!getModule(qrcode, x, y) && i < dataLen * 8) { - bool black = getBit(data[i >> 3], 7 - (i & 7)); - setModule(qrcode, x, y, black); - i++; - } - // If this QR Code has any remainder bits (0 to 7), they were assigned as - // 0/false/white by the constructor and are left unchanged by this method - } - } - } - assert(i == dataLen * 8); +static void +drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) +{ + int qrsize = qrcodegen_getSize(qrcode); + int i = 0; // Bit index into the data + // Do the funny zigzag scan + for (int right = qrsize - 1; right >= 1; + right -= 2) { // Index of right column in each column pair + if (right == 6) + right = 5; + for (int vert = 0; vert < qrsize; vert++) { // Vertical counter + for (int j = 0; j < 2; j++) { + int x = right - j; // Actual x coordinate + bool upward = ((right + 1) & 2) == 0; + int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate + if (!getModule(qrcode, x, y) && i < dataLen * 8) { + bool black = getBit(data[i >> 3], 7 - (i & 7)); + setModule(qrcode, x, y, black); + i++; + } + // If this QR Code has any remainder bits (0 to 7), they were assigned as + // 0/false/white by the constructor and are left unchanged by this method + } + } + } + assert(i == dataLen * 8); } - // XORs the codeword modules in this QR Code with the given mask pattern. // The function modules must be marked and the codeword bits must be drawn // before masking. Due to the arithmetic of XOR, calling applyMask() with // the same mask value a second time will undo the mask. A final well-formed // QR Code needs exactly one (not zero, two, etc.) mask applied. -static void applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qrcodegen_Mask mask) { - assert(0 <= (int)mask && (int)mask <= 7); // Disallows qrcodegen_Mask_AUTO - int qrsize = qrcodegen_getSize(qrcode); - for (int y = 0; y < qrsize; y++) { - for (int x = 0; x < qrsize; x++) { - if (getModule(functionModules, x, y)) - continue; - bool invert; - switch ((int)mask) { - case 0: invert = (x + y) % 2 == 0; break; - case 1: invert = y % 2 == 0; break; - case 2: invert = x % 3 == 0; break; - case 3: invert = (x + y) % 3 == 0; break; - case 4: invert = (x / 3 + y / 2) % 2 == 0; break; - case 5: invert = x * y % 2 + x * y % 3 == 0; break; - case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break; - case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break; - default: assert(false); return; - } - bool val = getModule(qrcode, x, y); - setModule(qrcode, x, y, val ^ invert); - } - } +static void +applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qrcodegen_Mask mask) +{ + assert(0 <= (int) mask && (int) mask <= 7); // Disallows qrcodegen_Mask_AUTO + int qrsize = qrcodegen_getSize(qrcode); + for (int y = 0; y < qrsize; y++) { + for (int x = 0; x < qrsize; x++) { + if (getModule(functionModules, x, y)) + continue; + bool invert; + switch ((int) mask) { + case 0: + invert = (x + y) % 2 == 0; + break; + case 1: + invert = y % 2 == 0; + break; + case 2: + invert = x % 3 == 0; + break; + case 3: + invert = (x + y) % 3 == 0; + break; + case 4: + invert = (x / 3 + y / 2) % 2 == 0; + break; + case 5: + invert = x * y % 2 + x * y % 3 == 0; + break; + case 6: + invert = (x * y % 2 + x * y % 3) % 2 == 0; + break; + case 7: + invert = ((x + y) % 2 + x * y % 3) % 2 == 0; + break; + default: + assert(false); + return; + } + bool val = getModule(qrcode, x, y); + setModule(qrcode, x, y, val ^ invert); + } + } } - // Calculates and returns the penalty score based on state of the given QR Code's current modules. // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score. -static long getPenaltyScore(const uint8_t qrcode[]) { - int qrsize = qrcodegen_getSize(qrcode); - long result = 0; - - // Adjacent modules in row having same color, and finder-like patterns - for (int y = 0; y < qrsize; y++) { - unsigned char runHistory[7] = {0}; - bool color = false; - unsigned char runX = 0; - for (int x = 0; x < qrsize; x++) { - if (getModule(qrcode, x, y) == color) { - runX++; - if (runX == 5) - result += PENALTY_N1; - else if (runX > 5) - result++; - } else { - addRunToHistory(runX, runHistory); - if (!color && hasFinderLikePattern(runHistory)) - result += PENALTY_N3; - color = getModule(qrcode, x, y); - runX = 1; - } - } - addRunToHistory(runX, runHistory); - if (color) - addRunToHistory(0, runHistory); // Dummy run of white - if (hasFinderLikePattern(runHistory)) - result += PENALTY_N3; - } - // Adjacent modules in column having same color, and finder-like patterns - for (int x = 0; x < qrsize; x++) { - unsigned char runHistory[7] = {0}; - bool color = false; - unsigned char runY = 0; - for (int y = 0; y < qrsize; y++) { - if (getModule(qrcode, x, y) == color) { - runY++; - if (runY == 5) - result += PENALTY_N1; - else if (runY > 5) - result++; - } else { - addRunToHistory(runY, runHistory); - if (!color && hasFinderLikePattern(runHistory)) - result += PENALTY_N3; - color = getModule(qrcode, x, y); - runY = 1; - } - } - addRunToHistory(runY, runHistory); - if (color) - addRunToHistory(0, runHistory); // Dummy run of white - if (hasFinderLikePattern(runHistory)) - result += PENALTY_N3; - } - - // 2*2 blocks of modules having same color - for (int y = 0; y < qrsize - 1; y++) { - for (int x = 0; x < qrsize - 1; x++) { - bool color = getModule(qrcode, x, y); - if ( color == getModule(qrcode, x + 1, y) && - color == getModule(qrcode, x, y + 1) && - color == getModule(qrcode, x + 1, y + 1)) - result += PENALTY_N2; - } - } - - // Balance of black and white modules - int black = 0; - for (int y = 0; y < qrsize; y++) { - for (int x = 0; x < qrsize; x++) { - if (getModule(qrcode, x, y)) - black++; - } - } - int total = qrsize * qrsize; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - int k = (int)((labs(black * 20L - total * 10L) + total - 1) / total) - 1; - result += k * PENALTY_N4; - return result; +static long +getPenaltyScore(const uint8_t qrcode[]) +{ + int qrsize = qrcodegen_getSize(qrcode); + long result = 0; + + // Adjacent modules in row having same color, and finder-like patterns + for (int y = 0; y < qrsize; y++) { + unsigned char runHistory[7] = {0}; + bool color = false; + unsigned char runX = 0; + for (int x = 0; x < qrsize; x++) { + if (getModule(qrcode, x, y) == color) { + runX++; + if (runX == 5) + result += PENALTY_N1; + else if (runX > 5) + result++; + } else { + addRunToHistory(runX, runHistory); + if (!color && hasFinderLikePattern(runHistory)) + result += PENALTY_N3; + color = getModule(qrcode, x, y); + runX = 1; + } + } + addRunToHistory(runX, runHistory); + if (color) + addRunToHistory(0, runHistory); // Dummy run of white + if (hasFinderLikePattern(runHistory)) + result += PENALTY_N3; + } + // Adjacent modules in column having same color, and finder-like patterns + for (int x = 0; x < qrsize; x++) { + unsigned char runHistory[7] = {0}; + bool color = false; + unsigned char runY = 0; + for (int y = 0; y < qrsize; y++) { + if (getModule(qrcode, x, y) == color) { + runY++; + if (runY == 5) + result += PENALTY_N1; + else if (runY > 5) + result++; + } else { + addRunToHistory(runY, runHistory); + if (!color && hasFinderLikePattern(runHistory)) + result += PENALTY_N3; + color = getModule(qrcode, x, y); + runY = 1; + } + } + addRunToHistory(runY, runHistory); + if (color) + addRunToHistory(0, runHistory); // Dummy run of white + if (hasFinderLikePattern(runHistory)) + result += PENALTY_N3; + } + + // 2*2 blocks of modules having same color + for (int y = 0; y < qrsize - 1; y++) { + for (int x = 0; x < qrsize - 1; x++) { + bool color = getModule(qrcode, x, y); + if (color == getModule(qrcode, x + 1, y) && color == getModule(qrcode, x, y + 1) + && color == getModule(qrcode, x + 1, y + 1)) + result += PENALTY_N2; + } + } + + // Balance of black and white modules + int black = 0; + for (int y = 0; y < qrsize; y++) { + for (int x = 0; x < qrsize; x++) { + if (getModule(qrcode, x, y)) + black++; + } + } + int total = qrsize * qrsize; // Note that size is odd, so black/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% + int k = (int) ((labs(black * 20L - total * 10L) + total - 1) / total) - 1; + result += k * PENALTY_N4; + return result; } - // Inserts the given value to the front of the given array, which shifts over the // existing values and deletes the last value. A helper function for getPenaltyScore(). -static void addRunToHistory(unsigned char run, unsigned char history[7]) { - memmove(&history[1], &history[0], 6 * sizeof(history[0])); - history[0] = run; +static void +addRunToHistory(unsigned char run, unsigned char history[7]) +{ + memmove(&history[1], &history[0], 6 * sizeof(history[0])); + history[0] = run; } - // Tests whether the given run history has the pattern of ratio 1:1:3:1:1 in the middle, and // surrounded by at least 4 on either or both ends. A helper function for getPenaltyScore(). // Must only be called immediately after a run of white modules has ended. -static bool hasFinderLikePattern(unsigned char runHistory[7]) { - unsigned char n = runHistory[1]; - // The maximum QR Code size is 177, hence the run length n <= 177. - // Arithmetic is promoted to int, so n*4 will not overflow. - return n > 0 && runHistory[2] == n && runHistory[4] == n && runHistory[5] == n - && runHistory[3] == n * 3 && (runHistory[0] >= n * 4 || runHistory[6] >= n * 4); +static bool +hasFinderLikePattern(unsigned char runHistory[7]) +{ + unsigned char n = runHistory[1]; + // The maximum QR Code size is 177, hence the run length n <= 177. + // Arithmetic is promoted to int, so n*4 will not overflow. + return n > 0 && runHistory[2] == n && runHistory[4] == n && runHistory[5] == n + && runHistory[3] == n * 3 && (runHistory[0] >= n * 4 || runHistory[6] >= n * 4); } - - /*---- Basic QR Code information ----*/ // Public function - see documentation comment in header file. -int qrcodegen_getSize(const uint8_t qrcode[]) { - assert(qrcode != NULL); - int result = qrcode[0]; - assert((qrcodegen_VERSION_MIN * 4 + 17) <= result - && result <= (qrcodegen_VERSION_MAX * 4 + 17)); - return result; +int +qrcodegen_getSize(const uint8_t qrcode[]) +{ + assert(qrcode != NULL); + int result = qrcode[0]; + assert((qrcodegen_VERSION_MIN * 4 + 17) <= result + && result <= (qrcodegen_VERSION_MAX * 4 + 17)); + return result; } - // Public function - see documentation comment in header file. -bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y) { - assert(qrcode != NULL); - int qrsize = qrcode[0]; - return (0 <= x && x < qrsize && 0 <= y && y < qrsize) && getModule(qrcode, x, y); +bool +qrcodegen_getModule(const uint8_t qrcode[], int x, int y) +{ + assert(qrcode != NULL); + int qrsize = qrcode[0]; + return (0 <= x && x < qrsize && 0 <= y && y < qrsize) && getModule(qrcode, x, y); } - // Gets the module at the given coordinates, which must be in bounds. -testable bool getModule(const uint8_t qrcode[], int x, int y) { - int qrsize = qrcode[0]; - assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize); - int index = y * qrsize + x; - return getBit(qrcode[(index >> 3) + 1], index & 7); +testable bool +getModule(const uint8_t qrcode[], int x, int y) +{ + int qrsize = qrcode[0]; + assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize); + int index = y * qrsize + x; + return getBit(qrcode[(index >> 3) + 1], index & 7); } - // Sets the module at the given coordinates, which must be in bounds. -testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack) { - int qrsize = qrcode[0]; - assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize); - int index = y * qrsize + x; - int bitIndex = index & 7; - int byteIndex = (index >> 3) + 1; - if (isBlack) - qrcode[byteIndex] |= 1 << bitIndex; - else - qrcode[byteIndex] &= (1 << bitIndex) ^ 0xFF; +testable void +setModule(uint8_t qrcode[], int x, int y, bool isBlack) +{ + int qrsize = qrcode[0]; + assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize); + int index = y * qrsize + x; + int bitIndex = index & 7; + int byteIndex = (index >> 3) + 1; + if (isBlack) + qrcode[byteIndex] |= 1 << bitIndex; + else + qrcode[byteIndex] &= (1 << bitIndex) ^ 0xFF; } - // Sets the module at the given coordinates, doing nothing if out of bounds. -testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack) { - int qrsize = qrcode[0]; - if (0 <= x && x < qrsize && 0 <= y && y < qrsize) - setModule(qrcode, x, y, isBlack); +testable void +setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack) +{ + int qrsize = qrcode[0]; + if (0 <= x && x < qrsize && 0 <= y && y < qrsize) + setModule(qrcode, x, y, isBlack); } - // Returns true iff the i'th bit of x is set to 1. Requires x >= 0 and 0 <= i <= 14. -static bool getBit(int x, int i) { - return ((x >> i) & 1) != 0; +static bool +getBit(int x, int i) +{ + return ((x >> i) & 1) != 0; } - - /*---- Segment handling ----*/ // Public function - see documentation comment in header file. -bool qrcodegen_isAlphanumeric(const char *text) { - assert(text != NULL); - for (; *text != '\0'; text++) { - if (strchr(ALPHANUMERIC_CHARSET, *text) == NULL) - return false; - } - return true; +bool +qrcodegen_isAlphanumeric(const char *text) +{ + assert(text != NULL); + for (; *text != '\0'; text++) { + if (strchr(ALPHANUMERIC_CHARSET, *text) == NULL) + return false; + } + return true; } - // Public function - see documentation comment in header file. -bool qrcodegen_isNumeric(const char *text) { - assert(text != NULL); - for (; *text != '\0'; text++) { - if (*text < '0' || *text > '9') - return false; - } - return true; +bool +qrcodegen_isNumeric(const char *text) +{ + assert(text != NULL); + for (; *text != '\0'; text++) { + if (*text < '0' || *text > '9') + return false; + } + return true; } - // Public function - see documentation comment in header file. -size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars) { - int temp = calcSegmentBitLength(mode, numChars); - if (temp == -1) - return SIZE_MAX; - assert(0 <= temp && temp <= INT16_MAX); - return ((size_t)temp + 7) / 8; +size_t +qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars) +{ + int temp = calcSegmentBitLength(mode, numChars); + if (temp == -1) + return SIZE_MAX; + assert(0 <= temp && temp <= INT16_MAX); + return ((size_t) temp + 7) / 8; } - // Returns the number of data bits needed to represent a segment // containing the given number of characters using the given mode. Notes: // - Returns -1 on failure, i.e. numChars > INT16_MAX or @@ -833,177 +938,204 @@ size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars // - For byte mode, numChars measures the number of bytes, not Unicode code points. // - For ECI mode, numChars must be 0, and the worst-case number of bits is returned. // An actual ECI segment can have shorter data. For non-ECI modes, the result is exact. -testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars) { - // All calculations are designed to avoid overflow on all platforms - if (numChars > (unsigned int)INT16_MAX) - return -1; - long result = (long)numChars; - if (mode == qrcodegen_Mode_NUMERIC) - result = (result * 10 + 2) / 3; // ceil(10/3 * n) - else if (mode == qrcodegen_Mode_ALPHANUMERIC) - result = (result * 11 + 1) / 2; // ceil(11/2 * n) - else if (mode == qrcodegen_Mode_BYTE) - result *= 8; - else if (mode == qrcodegen_Mode_KANJI) - result *= 13; - else if (mode == qrcodegen_Mode_ECI && numChars == 0) - result = 3 * 8; - else { // Invalid argument - assert(false); - return -1; - } - assert(result >= 0); - if (result > (unsigned int)INT16_MAX) - return -1; - return (int)result; +testable int +calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars) +{ + // All calculations are designed to avoid overflow on all platforms + if (numChars > (unsigned int) INT16_MAX) + return -1; + long result = (long) numChars; + if (mode == qrcodegen_Mode_NUMERIC) + result = (result * 10 + 2) / 3; // ceil(10/3 * n) + else if (mode == qrcodegen_Mode_ALPHANUMERIC) + result = (result * 11 + 1) / 2; // ceil(11/2 * n) + else if (mode == qrcodegen_Mode_BYTE) + result *= 8; + else if (mode == qrcodegen_Mode_KANJI) + result *= 13; + else if (mode == qrcodegen_Mode_ECI && numChars == 0) + result = 3 * 8; + else { // Invalid argument + assert(false); + return -1; + } + assert(result >= 0); + if (result > (unsigned int) INT16_MAX) + return -1; + return (int) result; } - // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]) { - assert(data != NULL || len == 0); - struct qrcodegen_Segment result; - result.mode = qrcodegen_Mode_BYTE; - result.bitLength = calcSegmentBitLength(result.mode, len); - assert(result.bitLength != -1); - result.numChars = (int)len; - if (len > 0) - memcpy(buf, data, len * sizeof(buf[0])); - result.data = buf; - return result; +struct qrcodegen_Segment +qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]) +{ + assert(data != NULL || len == 0); + struct qrcodegen_Segment result; + result.mode = qrcodegen_Mode_BYTE; + result.bitLength = calcSegmentBitLength(result.mode, len); + assert(result.bitLength != -1); + result.numChars = (int) len; + if (len > 0) + memcpy(buf, data, len * sizeof(buf[0])); + result.data = buf; + return result; } - // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]) { - assert(digits != NULL); - struct qrcodegen_Segment result; - size_t len = strlen(digits); - result.mode = qrcodegen_Mode_NUMERIC; - int bitLen = calcSegmentBitLength(result.mode, len); - assert(bitLen != -1); - result.numChars = (int)len; - if (bitLen > 0) - memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0])); - result.bitLength = 0; - - unsigned int accumData = 0; - int accumCount = 0; - for (; *digits != '\0'; digits++) { - char c = *digits; - assert('0' <= c && c <= '9'); - accumData = accumData * 10 + (unsigned int)(c - '0'); - accumCount++; - if (accumCount == 3) { - appendBitsToBuffer(accumData, 10, buf, &result.bitLength); - accumData = 0; - accumCount = 0; - } - } - if (accumCount > 0) // 1 or 2 digits remaining - appendBitsToBuffer(accumData, accumCount * 3 + 1, buf, &result.bitLength); - assert(result.bitLength == bitLen); - result.data = buf; - return result; +struct qrcodegen_Segment +qrcodegen_makeNumeric(const char *digits, uint8_t buf[]) +{ + assert(digits != NULL); + struct qrcodegen_Segment result; + size_t len = strlen(digits); + result.mode = qrcodegen_Mode_NUMERIC; + int bitLen = calcSegmentBitLength(result.mode, len); + assert(bitLen != -1); + result.numChars = (int) len; + if (bitLen > 0) + memset(buf, 0, ((size_t) bitLen + 7) / 8 * sizeof(buf[0])); + result.bitLength = 0; + + unsigned int accumData = 0; + int accumCount = 0; + for (; *digits != '\0'; digits++) { + char c = *digits; + assert('0' <= c && c <= '9'); + accumData = accumData * 10 + (unsigned int) (c - '0'); + accumCount++; + if (accumCount == 3) { + appendBitsToBuffer(accumData, 10, buf, &result.bitLength); + accumData = 0; + accumCount = 0; + } + } + if (accumCount > 0) // 1 or 2 digits remaining + appendBitsToBuffer(accumData, accumCount * 3 + 1, buf, &result.bitLength); + assert(result.bitLength == bitLen); + result.data = buf; + return result; } - // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]) { - assert(text != NULL); - struct qrcodegen_Segment result; - size_t len = strlen(text); - result.mode = qrcodegen_Mode_ALPHANUMERIC; - int bitLen = calcSegmentBitLength(result.mode, len); - assert(bitLen != -1); - result.numChars = (int)len; - if (bitLen > 0) - memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0])); - result.bitLength = 0; - - unsigned int accumData = 0; - int accumCount = 0; - for (; *text != '\0'; text++) { - const char *temp = strchr(ALPHANUMERIC_CHARSET, *text); - assert(temp != NULL); - accumData = accumData * 45 + (unsigned int)(temp - ALPHANUMERIC_CHARSET); - accumCount++; - if (accumCount == 2) { - appendBitsToBuffer(accumData, 11, buf, &result.bitLength); - accumData = 0; - accumCount = 0; - } - } - if (accumCount > 0) // 1 character remaining - appendBitsToBuffer(accumData, 6, buf, &result.bitLength); - assert(result.bitLength == bitLen); - result.data = buf; - return result; +struct qrcodegen_Segment +qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]) +{ + assert(text != NULL); + struct qrcodegen_Segment result; + size_t len = strlen(text); + result.mode = qrcodegen_Mode_ALPHANUMERIC; + int bitLen = calcSegmentBitLength(result.mode, len); + assert(bitLen != -1); + result.numChars = (int) len; + if (bitLen > 0) + memset(buf, 0, ((size_t) bitLen + 7) / 8 * sizeof(buf[0])); + result.bitLength = 0; + + unsigned int accumData = 0; + int accumCount = 0; + for (; *text != '\0'; text++) { + const char *temp = strchr(ALPHANUMERIC_CHARSET, *text); + assert(temp != NULL); + accumData = accumData * 45 + (unsigned int) (temp - ALPHANUMERIC_CHARSET); + accumCount++; + if (accumCount == 2) { + appendBitsToBuffer(accumData, 11, buf, &result.bitLength); + accumData = 0; + accumCount = 0; + } + } + if (accumCount > 0) // 1 character remaining + appendBitsToBuffer(accumData, 6, buf, &result.bitLength); + assert(result.bitLength == bitLen); + result.data = buf; + return result; } - // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]) { - struct qrcodegen_Segment result; - result.mode = qrcodegen_Mode_ECI; - result.numChars = 0; - result.bitLength = 0; - if (assignVal < 0) - assert(false); - else if (assignVal < (1 << 7)) { - memset(buf, 0, 1 * sizeof(buf[0])); - appendBitsToBuffer(assignVal, 8, buf, &result.bitLength); - } else if (assignVal < (1 << 14)) { - memset(buf, 0, 2 * sizeof(buf[0])); - appendBitsToBuffer(2, 2, buf, &result.bitLength); - appendBitsToBuffer(assignVal, 14, buf, &result.bitLength); - } else if (assignVal < 1000000L) { - memset(buf, 0, 3 * sizeof(buf[0])); - appendBitsToBuffer(6, 3, buf, &result.bitLength); - appendBitsToBuffer(assignVal >> 10, 11, buf, &result.bitLength); - appendBitsToBuffer(assignVal & 0x3FF, 10, buf, &result.bitLength); - } else - assert(false); - result.data = buf; - return result; +struct qrcodegen_Segment +qrcodegen_makeEci(long assignVal, uint8_t buf[]) +{ + struct qrcodegen_Segment result; + result.mode = qrcodegen_Mode_ECI; + result.numChars = 0; + result.bitLength = 0; + if (assignVal < 0) + assert(false); + else if (assignVal < (1 << 7)) { + memset(buf, 0, 1 * sizeof(buf[0])); + appendBitsToBuffer(assignVal, 8, buf, &result.bitLength); + } else if (assignVal < (1 << 14)) { + memset(buf, 0, 2 * sizeof(buf[0])); + appendBitsToBuffer(2, 2, buf, &result.bitLength); + appendBitsToBuffer(assignVal, 14, buf, &result.bitLength); + } else if (assignVal < 1000000L) { + memset(buf, 0, 3 * sizeof(buf[0])); + appendBitsToBuffer(6, 3, buf, &result.bitLength); + appendBitsToBuffer(assignVal >> 10, 11, buf, &result.bitLength); + appendBitsToBuffer(assignVal & 0x3FF, 10, buf, &result.bitLength); + } else + assert(false); + result.data = buf; + return result; } - // Calculates the number of bits needed to encode the given segments at the given version. -// Returns a non-negative number if successful. Otherwise returns -1 if a segment has too +// Returns a non-negative number if successful. Otherwise, returns -1 if a segment has too // many characters to fit its length field, or the total bits exceeds INT16_MAX. -testable int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version) { - assert(segs != NULL || len == 0); - long result = 0; - for (size_t i = 0; i < len; i++) { - int numChars = segs[i].numChars; - int bitLength = segs[i].bitLength; - assert(0 <= numChars && numChars <= INT16_MAX); - assert(0 <= bitLength && bitLength <= INT16_MAX); - int ccbits = numCharCountBits(segs[i].mode, version); - assert(0 <= ccbits && ccbits <= 16); - if (numChars >= (1L << ccbits)) - return -1; // The segment's length doesn't fit the field's bit width - result += 4L + ccbits + bitLength; - if (result > INT16_MAX) - return -1; // The sum might overflow an int type - } - assert(0 <= result && result <= INT16_MAX); - return (int)result; +testable int +getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version) +{ + assert(segs != NULL || len == 0); + long result = 0; + for (size_t i = 0; i < len; i++) { + int numChars = segs[i].numChars; + int bitLength = segs[i].bitLength; + assert(0 <= numChars && numChars <= INT16_MAX); + assert(0 <= bitLength && bitLength <= INT16_MAX); + int ccbits = numCharCountBits(segs[i].mode, version); + assert(0 <= ccbits && ccbits <= 16); + if (numChars >= (1L << ccbits)) + return -1; // The segment's length doesn't fit the field's bit width + result += 4L + ccbits + bitLength; + if (result > INT16_MAX) + return -1; // The sum might overflow an int type + } + assert(0 <= result && result <= INT16_MAX); + return (int) result; } - // Returns the bit width of the character count field for a segment in the given mode // in a QR Code at the given version number. The result is in the range [0, 16]. -static int numCharCountBits(enum qrcodegen_Mode mode, int version) { - assert(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); - int i = (version + 7) / 17; - switch (mode) { - case qrcodegen_Mode_NUMERIC : { static const int temp[] = {10, 12, 14}; return temp[i]; } - case qrcodegen_Mode_ALPHANUMERIC: { static const int temp[] = { 9, 11, 13}; return temp[i]; } - case qrcodegen_Mode_BYTE : { static const int temp[] = { 8, 16, 16}; return temp[i]; } - case qrcodegen_Mode_KANJI : { static const int temp[] = { 8, 10, 12}; return temp[i]; } - case qrcodegen_Mode_ECI : return 0; - default: assert(false); return -1; // Dummy value - } +static int +numCharCountBits(enum qrcodegen_Mode mode, int version) +{ + assert(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); + int i = (version + 7) / 17; + switch (mode) { + case qrcodegen_Mode_NUMERIC: + { + static const int temp[] = {10, 12, 14}; + return temp[i]; + } + case qrcodegen_Mode_ALPHANUMERIC: + { + static const int temp[] = {9, 11, 13}; + return temp[i]; + } + case qrcodegen_Mode_BYTE: + { + static const int temp[] = {8, 16, 16}; + return temp[i]; + } + case qrcodegen_Mode_KANJI: + { + static const int temp[] = {8, 10, 12}; + return temp[i]; + } + case qrcodegen_Mode_ECI: + return 0; + default: + assert(false); + return -1; // Dummy value + } } diff --git a/clients/common/qrcodegen.h b/clients/common/qrcodegen.h index 55e2bfec..b91ae49a 100644 --- a/clients/common/qrcodegen.h +++ b/clients/common/qrcodegen.h @@ -27,12 +27,10 @@ #include <stddef.h> #include <stdint.h> - #ifdef __cplusplus extern "C" { #endif - /* * This library creates QR Code symbols, which is a type of two-dimension barcode. * Invented by Denso Wave and described in the ISO/IEC 18004 standard. @@ -48,53 +46,49 @@ extern "C" { * (Note that all ways require supplying the desired error correction level and various byte buffers.) */ - /*---- Enum and struct types----*/ /* * The error correction level in a QR Code symbol. */ enum qrcodegen_Ecc { - // Must be declared in ascending order of error protection - // so that an internal qrcodegen function works properly - qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords - qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords - qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords - qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords + // Must be declared in ascending order of error protection + // so that an internal qrcodegen function works properly + qrcodegen_Ecc_LOW = 0, // The QR Code can tolerate about 7% erroneous codewords + qrcodegen_Ecc_MEDIUM, // The QR Code can tolerate about 15% erroneous codewords + qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords + qrcodegen_Ecc_HIGH, // The QR Code can tolerate about 30% erroneous codewords }; - /* * The mask pattern used in a QR Code symbol. */ enum qrcodegen_Mask { - // A special value to tell the QR Code encoder to - // automatically select an appropriate mask pattern - qrcodegen_Mask_AUTO = -1, - // The eight actual mask patterns - qrcodegen_Mask_0 = 0, - qrcodegen_Mask_1, - qrcodegen_Mask_2, - qrcodegen_Mask_3, - qrcodegen_Mask_4, - qrcodegen_Mask_5, - qrcodegen_Mask_6, - qrcodegen_Mask_7, + // A special value to tell the QR Code encoder to + // automatically select an appropriate mask pattern + qrcodegen_Mask_AUTO = -1, + // The eight actual mask patterns + qrcodegen_Mask_0 = 0, + qrcodegen_Mask_1, + qrcodegen_Mask_2, + qrcodegen_Mask_3, + qrcodegen_Mask_4, + qrcodegen_Mask_5, + qrcodegen_Mask_6, + qrcodegen_Mask_7, }; - /* * Describes how a segment's data bits are interpreted. */ enum qrcodegen_Mode { - qrcodegen_Mode_NUMERIC = 0x1, - qrcodegen_Mode_ALPHANUMERIC = 0x2, - qrcodegen_Mode_BYTE = 0x4, - qrcodegen_Mode_KANJI = 0x8, - qrcodegen_Mode_ECI = 0x7, + qrcodegen_Mode_NUMERIC = 0x1, + qrcodegen_Mode_ALPHANUMERIC = 0x2, + qrcodegen_Mode_BYTE = 0x4, + qrcodegen_Mode_KANJI = 0x8, + qrcodegen_Mode_ECI = 0x7, }; - /* * A segment of character/binary/control data in a QR Code symbol. * The mid-level way to create a segment is to take the payload data @@ -107,43 +101,41 @@ enum qrcodegen_Mode { * the largest QR Code (version 40) has 31329 modules. */ struct qrcodegen_Segment { - // The mode indicator of this segment. - enum qrcodegen_Mode mode; - - // The length of this segment's unencoded data. Measured in characters for - // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. - // Always zero or positive. Not the same as the data's bit length. - int numChars; - - // The data bits of this segment, packed in bitwise big endian. - // Can be null if the bit length is zero. - uint8_t *data; - - // The number of valid data bits used in the buffer. Requires - // 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. - // The character count (numChars) must agree with the mode and the bit buffer length. - int bitLength; + // The mode indicator of this segment. + enum qrcodegen_Mode mode; + + // The length of this segment's unencoded data. Measured in characters for + // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. + // Always zero or positive. Not the same as the data's bit length. + int numChars; + + // The data bits of this segment, packed in bitwise big endian. + // Can be null if the bit length is zero. + uint8_t *data; + + // The number of valid data bits used in the buffer. Requires + // 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. + // The character count (numChars) must agree with the mode and the bit buffer length. + int bitLength; }; - - /*---- Macro constants and functions ----*/ -#define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard -#define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard +#define qrcodegen_VERSION_MIN \ + 1 // The minimum version number supported in the QR Code Model 2 standard +#define qrcodegen_VERSION_MAX \ + 40 // The maximum version number supported in the QR Code Model 2 standard // Calculates the number of bytes needed to store any QR Code up to and including the given version number, // as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];' // can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16). // Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX. -#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1) +#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) *4 + 17) * ((n) *4 + 17) + 7) / 8 + 1) // The worst-case number of bytes needed to store one QR Code, up to and including // version 40. This value equals 3918, which is just under 4 kilobytes. // Use this more convenient value to avoid calculating tighter memory bounds for buffers. -#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX) - - +#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX) /*---- Functions (high level) to generate QR Codes ----*/ @@ -166,9 +158,14 @@ struct qrcodegen_Segment { * - Please consult the QR Code specification for information on * data capacities per version, ECC level, and text encoding mode. */ -bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], - enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); - +bool qrcodegen_encodeText(const char * text, + uint8_t tempBuffer[], + uint8_t qrcode[], + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + enum qrcodegen_Mask mask, + bool boostEcl); /* * Encodes the given binary data to a QR Code, returning true if encoding succeeded. @@ -188,9 +185,14 @@ bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode * - Please consult the QR Code specification for information on * data capacities per version, ECC level, and text encoding mode. */ -bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], - enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); - +bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], + size_t dataLen, + uint8_t qrcode[], + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + enum qrcodegen_Mask mask, + bool boostEcl); /*---- Functions (low level) to generate QR Codes ----*/ @@ -206,9 +208,11 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod * result in them being clobbered, but the QR Code output will still be correct. * But the qrcode array must not overlap tempBuffer or any segment's data buffer. */ -bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, - enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]); - +bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], + size_t len, + enum qrcodegen_Ecc ecl, + uint8_t tempBuffer[], + uint8_t qrcode[]); /* * Renders a QR Code representing the given segments with the given encoding parameters. @@ -225,9 +229,15 @@ bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, * result in them being clobbered, but the QR Code output will still be correct. * But the qrcode array must not overlap tempBuffer or any segment's data buffer. */ -bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl, - int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]); - +bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], + size_t len, + enum qrcodegen_Ecc ecl, + int minVersion, + int maxVersion, + int mask, + bool boostEcl, + uint8_t tempBuffer[], + uint8_t qrcode[]); /* * Tests whether the given string can be encoded as a segment in alphanumeric mode. @@ -236,14 +246,12 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz */ bool qrcodegen_isAlphanumeric(const char *text); - /* * Tests whether the given string can be encoded as a segment in numeric mode. * A string is encodable iff each character is in the range 0 to 9. */ bool qrcodegen_isNumeric(const char *text); - /* * Returns the number of bytes (uint8_t) needed for the data buffer of a segment * containing the given number of characters using the given mode. Notes: @@ -257,7 +265,6 @@ bool qrcodegen_isNumeric(const char *text); */ size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars); - /* * Returns a segment representing the given binary data encoded in * byte mode. All input byte arrays are acceptable. Any text string @@ -265,13 +272,11 @@ size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars */ struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]); - /* * Returns a segment representing the given string of decimal digits encoded in numeric mode. */ struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]); - /* * Returns a segment representing the given text string encoded in alphanumeric mode. * The characters allowed are: 0 to 9, A to Z (uppercase only), space, @@ -279,14 +284,12 @@ struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[] */ struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]); - /* * Returns a segment representing an Extended Channel Interpretation * (ECI) designator with the given assignment value. */ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]); - /*---- Functions to extract raw data from QR Codes ----*/ /* @@ -297,7 +300,6 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]); */ int qrcodegen_getSize(const uint8_t qrcode[]); - /* * Returns the color of the module (pixel) at the given coordinates, which is false * for white or true for black. The top left corner has the coordinates (x=0, y=0). @@ -305,7 +307,6 @@ int qrcodegen_getSize(const uint8_t qrcode[]); */ bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y); - #ifdef __cplusplus } #endif diff --git a/clients/common/settings-docs.h b/clients/common/settings-docs.h index 606a1b95..58fc92e1 100644 --- a/clients/common/settings-docs.h +++ b/clients/common/settings-docs.h @@ -4,6 +4,7 @@ #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_CHANNEL N_("Channel on which the mesh network to join is located.") #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS N_("Anycast DHCP MAC address used when requesting an IP address via DHCP. The specific anycast address used determines which DHCP server class answers the request.") #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_SSID N_("SSID of the mesh network to join.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_AP_ISOLATION N_("Configures AP isolation, which prevents communication between wireless devices connected to this AP. This property can be set to a value different from NM_TERNARY_DEFAULT (-1) only when the interface is configured in AP mode. If set to NM_TERNARY_TRUE (1), devices are not able to communicate with each other. This increases security because it protects devices against attacks from other clients in the network. At the same time, it prevents devices to access resources on the same wireless networks as file shares, printers, etc. If set to NM_TERNARY_FALSE (0), devices can talk to each other. When set to NM_TERNARY_DEFAULT (-1), the global default is used; in case the global default is unspecified it is assumed to be NM_TERNARY_FALSE (0).") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_BAND N_("802.11 frequency band of the network. One of \"a\" for 5GHz 802.11a or \"bg\" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network to the specific band, i.e. if \"a\" is specified, the device will not associate with the same network in the 2.4GHz band even if the network's settings are compatible. This setting depends on specific driver capability and may not work with all drivers.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_BSSID N_("If specified, directs the device to only associate with the given access point. This capability is highly driver dependent and not supported by all devices. Note: this property does not control the BSSID used when creating an Ad-Hoc network and is unlikely to in the future.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CHANNEL N_("Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel. Because channel numbers overlap between bands, this property also requires the \"band\" property to be set.") @@ -128,7 +129,7 @@ #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_INTERVAL N_("Interval (in deciseconds) between queries sent by the bridge after the end of the startup phase.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL N_("Set the Max Response Time/Max Response Delay (in deciseconds) for IGMP/MLD queries sent by the bridge.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR N_("If enabled the bridge's own IP address is used as the source address for IGMP queries otherwise the default of 0.0.0.0 is used.") -#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_ROUTER N_("Sets bridge's multicast router. Multicast-snooping must be enabled for this option to work. Supported values are: 'auto', 'disabled', 'enabled'. If not specified the default value is 'auto'.") +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_ROUTER N_("Sets bridge's multicast router. Multicast-snooping must be enabled for this option to work. Supported values are: 'auto', 'disabled', 'enabled' to which kernel assigns the numbers 1, 0, and 2, respectively. If not specified the default value is 'auto' (1).") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_SNOOPING N_("Controls whether IGMP snooping is enabled for this bridge. Note that if snooping was automatically disabled due to hash collisions, the system may refuse to enable the feature until the collisions are resolved.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT N_("Set the number of IGMP queries to send during startup phase.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL N_("Sets the time (in deciseconds) between queries sent out at startup to determine membership information.") @@ -148,7 +149,7 @@ #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD N_("The password used to authenticate with the network, if required. Many providers do not require a password, or accept any password. But if a password is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD_FLAGS N_("Flags indicating how to handle the \"password\" property.") #define DESCRIBE_DOC_NM_SETTING_CDMA_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently this only applies to 802-1x authentication.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently, this only applies to 802-1x authentication.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection. Note that autoconnect is not implemented for VPN profiles. See \"secondaries\" as an alternative to automatically connect VPN profiles.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY N_("The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES N_("The number of times a connection should be tried when autoactivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden). Setting this to 1 means to try activation only once before blocking autoconnect. Note that after a timeout, NetworkManager will try to autoconnect again.") @@ -157,17 +158,17 @@ #define DESCRIBE_DOC_NM_SETTING_CONNECTION_ID N_("A human readable unique identifier for the connection, like \"Work Wi-Fi\" or \"T-Mobile 3G\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_INTERFACE_NAME N_("The name of the network interface this connection is bound to. If not set, then the connection can be attached to any interface of the appropriate type (subject to restrictions imposed by other settings). For software devices this specifies the name of the created device. For connection types where interface names cannot easily be made persistent (e.g. mobile broadband or USB Ethernet), this property should not be used. Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLDP N_("Whether LLDP is enabled for the connection.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLMNR N_("Whether Link-Local Multicast Name Resolution (LLMNR) is enabled for the connection. LLMNR is a protocol based on the Domain Name System (DNS) packet format that allows both IPv4 and IPv6 hosts to perform name resolution for hosts on the same local link. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable LLMNR for the interface, \"resolve\" (1) do not register hostname but allow resolving of LLMNR host names If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"yes\"). This feature requires a plugin which supports LLMNR. Otherwise the setting has no effect. One such plugin is dns-systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLMNR N_("Whether Link-Local Multicast Name Resolution (LLMNR) is enabled for the connection. LLMNR is a protocol based on the Domain Name System (DNS) packet format that allows both IPv4 and IPv6 hosts to perform name resolution for hosts on the same local link. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable LLMNR for the interface, \"resolve\" (1) do not register hostname but allow resolving of LLMNR host names If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"yes\"). This feature requires a plugin which supports LLMNR. Otherwise, the setting has no effect. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER N_("Interface name of the master device or UUID of the master connection.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable mDNS for the interface, \"resolve\" (1) do not register hostname but allow resolving of mDNS host names and \"default\" (-1) to allow lookup of a global default in NetworkManager.conf. If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"no\"). This feature requires a plugin which supports mDNS. Otherwise the setting has no effect. One such plugin is dns-systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable mDNS for the interface, \"resolve\" (1) do not register hostname but allow resolving of mDNS host names and \"default\" (-1) to allow lookup of a global default in NetworkManager.conf. If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"no\"). This feature requires a plugin which supports mDNS. Otherwise, the setting has no effect. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED N_("Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MUD_URL N_("If configured, set to a Manufacturer Usage Description (MUD) URL that points to manufacturer-recommended network policies for IoT devices. It is transmitted as a DHCPv4 or DHCPv6 option. The value must be a valid URL starting with \"https://\". The special value \"none\" is allowed to indicate that no MUD URL is used. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the ultimate default is \"none\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MULTI_CONNECT N_("Specifies whether the profile can be active multiple times at a particular moment. The value is of type NMConnectionMultiConnect.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS N_("An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection; otherwise users are allowed if and only if they are in this list. When this is not empty, the connection can be active only when one of the specified users is logged into an active session. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently, only VPN connections are supported.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable and to derive the DHCP DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid]. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds to the interface name of the device and \"${MAC}\" is the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable and to derive the DHCP DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid]. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret-key. The '$' character is treated special to perform dynamic substitutions at runtime. Currently, supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds to the interface name of the device and \"${MAC}\" is the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\").") @@ -204,11 +205,11 @@ #define DESCRIBE_DOC_NM_SETTING_GSM_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MAC_ADDRESS N_("If specified, this connection will only apply to the IPoIB device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames.") -#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key.") +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise, it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT N_("The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\".") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE N_("The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\".") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT N_("How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.") -#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently, the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLOW_LABEL N_("The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_INPUT_KEY N_("The key used for tunnel input packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_LOCAL N_("The local endpoint of the tunnel; the value can be empty, otherwise it must contain an IPv4 or IPv6 address.") @@ -225,16 +226,18 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values \"mac\" and \"perm-mac\" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet (01). Currently, these options only work for ethernet type of links. The special value \"duid\" generates a RFC4361-compliant client identifier based on a hash of the interface name as IAID and /etc/machine-id. The special value \"stable\" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If you set the stable-id, you may want to include the \"${DEVICE}\" or \"${MAC}\" specifier to get a per-device key. If unset, a globally configured default is used. If still unset, the default depends on the DHCP plugin.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently, this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\", \"ifname\" and \"stable\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. The special value \"stable\" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_REJECT_SERVERS N_("Array of servers from which DHCP offers must be rejected. This property is useful to avoid getting a lease from misconfigured or rogue servers. For DHCPv4, each element must be an IPv4 address, optionally followed by a slash and a prefix length (e.g. \"192.168.122.0/24\"). This property is currently not implemented for DHCPv6.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER N_("The Vendor Class Identifier DHCP option (60). Special characters in the data string may be escaped using C-style escapes, nevertheless this property cannot contain nul bytes. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the DHCP option is not sent to the server. Since 1.28") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports Conditional Forwarding as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL N_("If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD N_("IP configuration method. NMSettingIP4Config and NMSettingIP6Config both support \"disabled\", \"auto\", \"manual\", and \"link-local\". See the subclass-specific documentation for other values. In general, for the \"auto\" method, properties such as \"dns\" and \"routes\" specify information that is added on to the information returned from automatic configuration. The \"ignore-auto-routes\" and \"ignore-auto-dns\" properties modify this behavior. For methods that imply no upstream network, such as \"shared\" or \"link-local\", these properties must be empty. For IPv4 method \"shared\", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen. Note that the shared method must be configured on the interface which shares the internet to a subnet, not on the uplink which is shared.") @@ -247,16 +250,17 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID N_("A string containing the DHCPv6 Unique Identifier (DUID) used by the dhcp client to identify itself to DHCPv6 servers (RFC 3315). The DUID is carried in the Client Identifier option. If the property is a hex string ('aa:bb:cc') it is interpreted as a binary DUID and filled as an opaque value in the Client Identifier option. The special value \"lease\" will retrieve the DUID previously used from the lease file belonging to the connection. If no DUID is found and \"dhclient\" is the configured dhcp client, the DUID is searched in the system-wide dhclient lease file. If still no DUID is found, or another dhcp client is used, a global and permanent DUID-UUID (RFC 6355) will be generated based on the machine-id. The special values \"llt\" and \"ll\" will generate a DUID of type LLT or LL (see RFC 3315) based on the current MAC address of the device. In order to try providing a stable DUID-LLT, the time field will contain a constant timestamp that is used globally (for all profiles) and persisted to disk. The special values \"stable-llt\", \"stable-ll\" and \"stable-uuid\" will generate a DUID of the corresponding type, derived from the connection's stable-id and a per-host unique key. You may want to include the \"${DEVICE}\" or \"${MAC}\" specifier in the stable-id, in case this profile gets activated on multiple devices. So, the link-layer address of \"stable-ll\" and \"stable-llt\" will be a generated address derived from the stable id. The DUID-LLT time value in the \"stable-llt\" option will be picked among a static timespan of three years (the upper bound of the interval is the same constant timestamp used in \"llt\"). When the property is unset, the global value provided for \"ipv6.dhcp-duid\" is used. If no global value is provided, the default \"lease\" value is assumed.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently, this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\", \"ifname\" and \"stable\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. The special value \"stable\" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_REJECT_SERVERS N_("Array of servers from which DHCP offers must be rejected. This property is useful to avoid getting a lease from misconfigured or rogue servers. For DHCPv4, each element must be an IPv4 address, optionally followed by a slash and a prefix length (e.g. \"192.168.122.0/24\"). This property is currently not implemented for DHCPv6.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports Conditional Forwarding as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IP6_PRIVACY N_("Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If enabled, it makes the kernel generate a temporary IPv6 address in addition to the public one generated from MAC address via modified EUI-64. This enhances privacy, but could cause problems in some applications, on the other hand. The permitted values are: -1: unknown, 0: disabled, 1: enabled (prefer public address), 2: enabled (prefer temporary addresses). Having a per-connection setting set to \"-1\" (unknown) means fallback to global configuration \"ipv6.ip6-privacy\". If also global configuration is unspecified or set to \"-1\", fallback to read \"/proc/sys/net/ipv6/conf/default/use_tempaddr\". Note that this setting is distinct from the Stable Privacy addresses that can be enabled with the \"addr-gen-mode\" property's \"stable-privacy\" setting as another way of avoiding host tracking with IPv6 addresses.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_MAY_FAIL N_("If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully.") @@ -332,7 +336,7 @@ #define DESCRIBE_DOC_NM_SETTING_SERIAL_STOPBITS N_("Number of stop bits for communication on the serial port. Either 1 or 2. The 1 in \"8n1\" for example.") #define DESCRIBE_DOC_NM_SETTING_SRIOV_AUTOPROBE_DRIVERS N_("Whether to autoprobe virtual functions by a compatible driver. If set to NM_TERNARY_TRUE (1), the kernel will try to bind VFs to a compatible driver and if this succeeds a new network interface will be instantiated for each VF. If set to NM_TERNARY_FALSE (0), VFs will not be claimed and no network interfaces will be created for them. When set to NM_TERNARY_DEFAULT (-1), the global default is used; in case the global default is unspecified it is assumed to be NM_TERNARY_TRUE (1).") #define DESCRIBE_DOC_NM_SETTING_SRIOV_TOTAL_VFS N_("The total number of virtual functions to create. Note that when the sriov setting is present NetworkManager enforces the number of virtual functions on the interface (also when it is zero) during activation and resets it upon deactivation. To prevent any changes to SR-IOV parameters don't add a sriov setting to the connection.") -#define DESCRIBE_DOC_NM_SETTING_SRIOV_VFS N_("Array of virtual function descriptors. Each VF descriptor is a dictionary mapping attribute names to GVariant values. The 'index' entry is mandatory for each VF. When represented as string a VF is in the form: \"INDEX [ATTR=VALUE[ ATTR=VALUE]...]\". for example: \"2 mac=00:11:22:33:44:55 spoof-check=true\". Multiple VFs can be specified using a comma as separator. Currently the following attributes are supported: mac, spoof-check, trust, min-tx-rate, max-tx-rate, vlans. The \"vlans\" attribute is represented as a semicolon-separated list of VLAN descriptors, where each descriptor has the form \"ID[.PRIORITY[.PROTO]]\". PROTO can be either 'q' for 802.1Q (the default) or 'ad' for 802.1ad.") +#define DESCRIBE_DOC_NM_SETTING_SRIOV_VFS N_("Array of virtual function descriptors. Each VF descriptor is a dictionary mapping attribute names to GVariant values. The 'index' entry is mandatory for each VF. When represented as string a VF is in the form: \"INDEX [ATTR=VALUE[ ATTR=VALUE]...]\". for example: \"2 mac=00:11:22:33:44:55 spoof-check=true\". Multiple VFs can be specified using a comma as separator. Currently, the following attributes are supported: mac, spoof-check, trust, min-tx-rate, max-tx-rate, vlans. The \"vlans\" attribute is represented as a semicolon-separated list of VLAN descriptors, where each descriptor has the form \"ID[.PRIORITY[.PROTO]]\". PROTO can be either 'q' for 802.1Q (the default) or 'ad' for 802.1ad.") #define DESCRIBE_DOC_NM_SETTING_TC_CONFIG_QDISCS N_("Array of TC queueing disciplines.") #define DESCRIBE_DOC_NM_SETTING_TC_CONFIG_TFILTERS N_("Array of TC traffic filters.") #define DESCRIBE_DOC_NM_SETTING_TEAM_CONFIG N_("The JSON configuration for the team network interface. The property should contain raw JSON configuration data suitable for teamd, because the value is passed directly to teamd. If not specified, the default configuration is used. See man teamd.conf for the format details.") @@ -393,12 +397,12 @@ #define DESCRIBE_DOC_NM_SETTING_VXLAN_SOURCE_PORT_MIN N_("Specifies the minimum UDP source port to communicate to the remote VXLAN tunnel endpoint.") #define DESCRIBE_DOC_NM_SETTING_VXLAN_TOS N_("Specifies the TOS value to use in outgoing packets.") #define DESCRIBE_DOC_NM_SETTING_VXLAN_TTL N_("Specifies the time-to-live value to use in outgoing packets.") -#define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_PEER N_("The P2P device that should be connected to. Currently this is the only way to create or join a group.") +#define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_PEER N_("The P2P device that should be connected to. Currently, this is the only way to create or join a group.") #define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_WFD_IES N_("The Wi-Fi Display (WFD) Information Elements (IEs) to set. Wi-Fi Display requires a protocol specific information element to be set in certain Wi-Fi frames. These can be specified here for the purpose of establishing a connection. This setting is only useful when implementing a Wi-Fi Display client.") #define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_WPS_METHOD N_("Flags indicating which mode of WPS is to be used. There's little point in changing the default setting as NetworkManager will automatically determine the best method to use.") #define DESCRIBE_DOC_NM_SETTING_WIMAX_MAC_ADDRESS N_("If specified, this connection will only apply to the WiMAX device whose MAC address matches. This property does not change the MAC address of the device (known as MAC spoofing). Deprecated: 1") #define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME N_("Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1") -#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise it is a 32-bit fwmark for outgoing packets. Note that \"ip4-auto-default-route\" or \"ip6-auto-default-route\" enabled, implies to automatically choose a fwmark.") +#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise, it is a 32-bit fwmark for outgoing packets. Note that \"ip4-auto-default-route\" or \"ip6-auto-default-route\" enabled, implies to automatically choose a fwmark.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE N_("Whether to enable special handling of the IPv4 default route. If enabled, the IPv4 default route from wireguard.peer-routes will be placed to a dedicated routing-table and two policy routing rules will be added. The fwmark number is also used as routing-table for the default-route, and if fwmark is zero, an unused fwmark/table is chosen automatically. This corresponds to what wg-quick does with Table=auto and what WireGuard calls \"Improved Rule-based Routing\". Note that for this automatism to work, you usually don't want to set ipv4.gateway, because that will result in a conflicting default route. Leaving this at the default will enable this option automatically if ipv4.never-default is not set and there are any peers that use a default-route as allowed-ips.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE N_("Like ip4-auto-default-route, but for the IPv6 default route.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_LISTEN_PORT N_("The listen-port. If listen-port is not specified, the port will be chosen randomly when the interface comes up.") diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in index 606a1b95..58fc92e1 100644 --- a/clients/common/settings-docs.h.in +++ b/clients/common/settings-docs.h.in @@ -4,6 +4,7 @@ #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_CHANNEL N_("Channel on which the mesh network to join is located.") #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS N_("Anycast DHCP MAC address used when requesting an IP address via DHCP. The specific anycast address used determines which DHCP server class answers the request.") #define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_SSID N_("SSID of the mesh network to join.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_AP_ISOLATION N_("Configures AP isolation, which prevents communication between wireless devices connected to this AP. This property can be set to a value different from NM_TERNARY_DEFAULT (-1) only when the interface is configured in AP mode. If set to NM_TERNARY_TRUE (1), devices are not able to communicate with each other. This increases security because it protects devices against attacks from other clients in the network. At the same time, it prevents devices to access resources on the same wireless networks as file shares, printers, etc. If set to NM_TERNARY_FALSE (0), devices can talk to each other. When set to NM_TERNARY_DEFAULT (-1), the global default is used; in case the global default is unspecified it is assumed to be NM_TERNARY_FALSE (0).") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_BAND N_("802.11 frequency band of the network. One of \"a\" for 5GHz 802.11a or \"bg\" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network to the specific band, i.e. if \"a\" is specified, the device will not associate with the same network in the 2.4GHz band even if the network's settings are compatible. This setting depends on specific driver capability and may not work with all drivers.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_BSSID N_("If specified, directs the device to only associate with the given access point. This capability is highly driver dependent and not supported by all devices. Note: this property does not control the BSSID used when creating an Ad-Hoc network and is unlikely to in the future.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CHANNEL N_("Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel. Because channel numbers overlap between bands, this property also requires the \"band\" property to be set.") @@ -128,7 +129,7 @@ #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_INTERVAL N_("Interval (in deciseconds) between queries sent by the bridge after the end of the startup phase.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL N_("Set the Max Response Time/Max Response Delay (in deciseconds) for IGMP/MLD queries sent by the bridge.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR N_("If enabled the bridge's own IP address is used as the source address for IGMP queries otherwise the default of 0.0.0.0 is used.") -#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_ROUTER N_("Sets bridge's multicast router. Multicast-snooping must be enabled for this option to work. Supported values are: 'auto', 'disabled', 'enabled'. If not specified the default value is 'auto'.") +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_ROUTER N_("Sets bridge's multicast router. Multicast-snooping must be enabled for this option to work. Supported values are: 'auto', 'disabled', 'enabled' to which kernel assigns the numbers 1, 0, and 2, respectively. If not specified the default value is 'auto' (1).") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_SNOOPING N_("Controls whether IGMP snooping is enabled for this bridge. Note that if snooping was automatically disabled due to hash collisions, the system may refuse to enable the feature until the collisions are resolved.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT N_("Set the number of IGMP queries to send during startup phase.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL N_("Sets the time (in deciseconds) between queries sent out at startup to determine membership information.") @@ -148,7 +149,7 @@ #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD N_("The password used to authenticate with the network, if required. Many providers do not require a password, or accept any password. But if a password is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD_FLAGS N_("Flags indicating how to handle the \"password\" property.") #define DESCRIBE_DOC_NM_SETTING_CDMA_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently this only applies to 802-1x authentication.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently, this only applies to 802-1x authentication.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection. Note that autoconnect is not implemented for VPN profiles. See \"secondaries\" as an alternative to automatically connect VPN profiles.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY N_("The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES N_("The number of times a connection should be tried when autoactivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden). Setting this to 1 means to try activation only once before blocking autoconnect. Note that after a timeout, NetworkManager will try to autoconnect again.") @@ -157,17 +158,17 @@ #define DESCRIBE_DOC_NM_SETTING_CONNECTION_ID N_("A human readable unique identifier for the connection, like \"Work Wi-Fi\" or \"T-Mobile 3G\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_INTERFACE_NAME N_("The name of the network interface this connection is bound to. If not set, then the connection can be attached to any interface of the appropriate type (subject to restrictions imposed by other settings). For software devices this specifies the name of the created device. For connection types where interface names cannot easily be made persistent (e.g. mobile broadband or USB Ethernet), this property should not be used. Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLDP N_("Whether LLDP is enabled for the connection.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLMNR N_("Whether Link-Local Multicast Name Resolution (LLMNR) is enabled for the connection. LLMNR is a protocol based on the Domain Name System (DNS) packet format that allows both IPv4 and IPv6 hosts to perform name resolution for hosts on the same local link. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable LLMNR for the interface, \"resolve\" (1) do not register hostname but allow resolving of LLMNR host names If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"yes\"). This feature requires a plugin which supports LLMNR. Otherwise the setting has no effect. One such plugin is dns-systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLMNR N_("Whether Link-Local Multicast Name Resolution (LLMNR) is enabled for the connection. LLMNR is a protocol based on the Domain Name System (DNS) packet format that allows both IPv4 and IPv6 hosts to perform name resolution for hosts on the same local link. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable LLMNR for the interface, \"resolve\" (1) do not register hostname but allow resolving of LLMNR host names If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"yes\"). This feature requires a plugin which supports LLMNR. Otherwise, the setting has no effect. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER N_("Interface name of the master device or UUID of the master connection.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable mDNS for the interface, \"resolve\" (1) do not register hostname but allow resolving of mDNS host names and \"default\" (-1) to allow lookup of a global default in NetworkManager.conf. If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"no\"). This feature requires a plugin which supports mDNS. Otherwise the setting has no effect. One such plugin is dns-systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: \"yes\" (2) register hostname and resolving for the connection, \"no\" (0) disable mDNS for the interface, \"resolve\" (1) do not register hostname but allow resolving of mDNS host names and \"default\" (-1) to allow lookup of a global default in NetworkManager.conf. If unspecified, \"default\" ultimately depends on the DNS plugin (which for systemd-resolved currently means \"no\"). This feature requires a plugin which supports mDNS. Otherwise, the setting has no effect. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED N_("Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MUD_URL N_("If configured, set to a Manufacturer Usage Description (MUD) URL that points to manufacturer-recommended network policies for IoT devices. It is transmitted as a DHCPv4 or DHCPv6 option. The value must be a valid URL starting with \"https://\". The special value \"none\" is allowed to indicate that no MUD URL is used. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the ultimate default is \"none\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MULTI_CONNECT N_("Specifies whether the profile can be active multiple times at a particular moment. The value is of type NMConnectionMultiConnect.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS N_("An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection; otherwise users are allowed if and only if they are in this list. When this is not empty, the connection can be active only when one of the specified users is logged into an active session. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently, only VPN connections are supported.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable and to derive the DHCP DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid]. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds to the interface name of the device and \"${MAC}\" is the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable and to derive the DHCP DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid]. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret-key. The '$' character is treated special to perform dynamic substitutions at runtime. Currently, supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds to the interface name of the device and \"${MAC}\" is the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\").") @@ -204,11 +205,11 @@ #define DESCRIBE_DOC_NM_SETTING_GSM_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MAC_ADDRESS N_("If specified, this connection will only apply to the IPoIB device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames.") -#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key.") +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise, it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key.") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT N_("The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\".") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE N_("The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\".") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT N_("How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.") -#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently, the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLOW_LABEL N_("The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_INPUT_KEY N_("The key used for tunnel input packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_LOCAL N_("The local endpoint of the tunnel; the value can be empty, otherwise it must contain an IPv4 or IPv6 address.") @@ -225,16 +226,18 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values \"mac\" and \"perm-mac\" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet (01). Currently, these options only work for ethernet type of links. The special value \"duid\" generates a RFC4361-compliant client identifier based on a hash of the interface name as IAID and /etc/machine-id. The special value \"stable\" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If you set the stable-id, you may want to include the \"${DEVICE}\" or \"${MAC}\" specifier to get a per-device key. If unset, a globally configured default is used. If still unset, the default depends on the DHCP plugin.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently, this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\", \"ifname\" and \"stable\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. The special value \"stable\" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_REJECT_SERVERS N_("Array of servers from which DHCP offers must be rejected. This property is useful to avoid getting a lease from misconfigured or rogue servers. For DHCPv4, each element must be an IPv4 address, optionally followed by a slash and a prefix length (e.g. \"192.168.122.0/24\"). This property is currently not implemented for DHCPv6.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER N_("The Vendor Class Identifier DHCP option (60). Special characters in the data string may be escaped using C-style escapes, nevertheless this property cannot contain nul bytes. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the DHCP option is not sent to the server. Since 1.28") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports Conditional Forwarding as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL N_("If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD N_("IP configuration method. NMSettingIP4Config and NMSettingIP6Config both support \"disabled\", \"auto\", \"manual\", and \"link-local\". See the subclass-specific documentation for other values. In general, for the \"auto\" method, properties such as \"dns\" and \"routes\" specify information that is added on to the information returned from automatic configuration. The \"ignore-auto-routes\" and \"ignore-auto-dns\" properties modify this behavior. For methods that imply no upstream network, such as \"shared\" or \"link-local\", these properties must be empty. For IPv4 method \"shared\", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen. Note that the shared method must be configured on the interface which shares the internet to a subnet, not on the uplink which is shared.") @@ -247,16 +250,17 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID N_("A string containing the DHCPv6 Unique Identifier (DUID) used by the dhcp client to identify itself to DHCPv6 servers (RFC 3315). The DUID is carried in the Client Identifier option. If the property is a hex string ('aa:bb:cc') it is interpreted as a binary DUID and filled as an opaque value in the Client Identifier option. The special value \"lease\" will retrieve the DUID previously used from the lease file belonging to the connection. If no DUID is found and \"dhclient\" is the configured dhcp client, the DUID is searched in the system-wide dhclient lease file. If still no DUID is found, or another dhcp client is used, a global and permanent DUID-UUID (RFC 6355) will be generated based on the machine-id. The special values \"llt\" and \"ll\" will generate a DUID of type LLT or LL (see RFC 3315) based on the current MAC address of the device. In order to try providing a stable DUID-LLT, the time field will contain a constant timestamp that is used globally (for all profiles) and persisted to disk. The special values \"stable-llt\", \"stable-ll\" and \"stable-uuid\" will generate a DUID of the corresponding type, derived from the connection's stable-id and a per-host unique key. You may want to include the \"${DEVICE}\" or \"${MAC}\" specifier in the stable-id, in case this profile gets activated on multiple devices. So, the link-layer address of \"stable-ll\" and \"stable-llt\" will be a generated address derived from the stable id. The DUID-LLT time value in the \"stable-llt\" option will be picked among a static timespan of three years (the upper bound of the interval is the same constant timestamp used in \"llt\"). When the property is unset, the global value provided for \"ipv6.dhcp-duid\" is used. If no global value is provided, the default \"lease\" value is assumed.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME_FLAGS N_("Flags for the DHCP hostname and FQDN. Currently, this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\", \"ifname\" and \"stable\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. The special value \"stable\" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_REJECT_SERVERS N_("Array of servers from which DHCP offers must be rejected. This property is useful to avoid getting a lease from misconfigured or rogue servers. For DHCPv4, each element must be an IPv4 address, optionally followed by a slash and a prefix length (e.g. \"192.168.122.0/24\"). This property is currently not implemented for DHCPv6.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"ndots\", \"no-check-names\", \"no-ip6-dotint\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports Conditional Forwarding as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IP6_PRIVACY N_("Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If enabled, it makes the kernel generate a temporary IPv6 address in addition to the public one generated from MAC address via modified EUI-64. This enhances privacy, but could cause problems in some applications, on the other hand. The permitted values are: -1: unknown, 0: disabled, 1: enabled (prefer public address), 2: enabled (prefer temporary addresses). Having a per-connection setting set to \"-1\" (unknown) means fallback to global configuration \"ipv6.ip6-privacy\". If also global configuration is unspecified or set to \"-1\", fallback to read \"/proc/sys/net/ipv6/conf/default/use_tempaddr\". Note that this setting is distinct from the Stable Privacy addresses that can be enabled with the \"addr-gen-mode\" property's \"stable-privacy\" setting as another way of avoiding host tracking with IPv6 addresses.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_MAY_FAIL N_("If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully.") @@ -332,7 +336,7 @@ #define DESCRIBE_DOC_NM_SETTING_SERIAL_STOPBITS N_("Number of stop bits for communication on the serial port. Either 1 or 2. The 1 in \"8n1\" for example.") #define DESCRIBE_DOC_NM_SETTING_SRIOV_AUTOPROBE_DRIVERS N_("Whether to autoprobe virtual functions by a compatible driver. If set to NM_TERNARY_TRUE (1), the kernel will try to bind VFs to a compatible driver and if this succeeds a new network interface will be instantiated for each VF. If set to NM_TERNARY_FALSE (0), VFs will not be claimed and no network interfaces will be created for them. When set to NM_TERNARY_DEFAULT (-1), the global default is used; in case the global default is unspecified it is assumed to be NM_TERNARY_TRUE (1).") #define DESCRIBE_DOC_NM_SETTING_SRIOV_TOTAL_VFS N_("The total number of virtual functions to create. Note that when the sriov setting is present NetworkManager enforces the number of virtual functions on the interface (also when it is zero) during activation and resets it upon deactivation. To prevent any changes to SR-IOV parameters don't add a sriov setting to the connection.") -#define DESCRIBE_DOC_NM_SETTING_SRIOV_VFS N_("Array of virtual function descriptors. Each VF descriptor is a dictionary mapping attribute names to GVariant values. The 'index' entry is mandatory for each VF. When represented as string a VF is in the form: \"INDEX [ATTR=VALUE[ ATTR=VALUE]...]\". for example: \"2 mac=00:11:22:33:44:55 spoof-check=true\". Multiple VFs can be specified using a comma as separator. Currently the following attributes are supported: mac, spoof-check, trust, min-tx-rate, max-tx-rate, vlans. The \"vlans\" attribute is represented as a semicolon-separated list of VLAN descriptors, where each descriptor has the form \"ID[.PRIORITY[.PROTO]]\". PROTO can be either 'q' for 802.1Q (the default) or 'ad' for 802.1ad.") +#define DESCRIBE_DOC_NM_SETTING_SRIOV_VFS N_("Array of virtual function descriptors. Each VF descriptor is a dictionary mapping attribute names to GVariant values. The 'index' entry is mandatory for each VF. When represented as string a VF is in the form: \"INDEX [ATTR=VALUE[ ATTR=VALUE]...]\". for example: \"2 mac=00:11:22:33:44:55 spoof-check=true\". Multiple VFs can be specified using a comma as separator. Currently, the following attributes are supported: mac, spoof-check, trust, min-tx-rate, max-tx-rate, vlans. The \"vlans\" attribute is represented as a semicolon-separated list of VLAN descriptors, where each descriptor has the form \"ID[.PRIORITY[.PROTO]]\". PROTO can be either 'q' for 802.1Q (the default) or 'ad' for 802.1ad.") #define DESCRIBE_DOC_NM_SETTING_TC_CONFIG_QDISCS N_("Array of TC queueing disciplines.") #define DESCRIBE_DOC_NM_SETTING_TC_CONFIG_TFILTERS N_("Array of TC traffic filters.") #define DESCRIBE_DOC_NM_SETTING_TEAM_CONFIG N_("The JSON configuration for the team network interface. The property should contain raw JSON configuration data suitable for teamd, because the value is passed directly to teamd. If not specified, the default configuration is used. See man teamd.conf for the format details.") @@ -393,12 +397,12 @@ #define DESCRIBE_DOC_NM_SETTING_VXLAN_SOURCE_PORT_MIN N_("Specifies the minimum UDP source port to communicate to the remote VXLAN tunnel endpoint.") #define DESCRIBE_DOC_NM_SETTING_VXLAN_TOS N_("Specifies the TOS value to use in outgoing packets.") #define DESCRIBE_DOC_NM_SETTING_VXLAN_TTL N_("Specifies the time-to-live value to use in outgoing packets.") -#define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_PEER N_("The P2P device that should be connected to. Currently this is the only way to create or join a group.") +#define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_PEER N_("The P2P device that should be connected to. Currently, this is the only way to create or join a group.") #define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_WFD_IES N_("The Wi-Fi Display (WFD) Information Elements (IEs) to set. Wi-Fi Display requires a protocol specific information element to be set in certain Wi-Fi frames. These can be specified here for the purpose of establishing a connection. This setting is only useful when implementing a Wi-Fi Display client.") #define DESCRIBE_DOC_NM_SETTING_WIFI_P2P_WPS_METHOD N_("Flags indicating which mode of WPS is to be used. There's little point in changing the default setting as NetworkManager will automatically determine the best method to use.") #define DESCRIBE_DOC_NM_SETTING_WIMAX_MAC_ADDRESS N_("If specified, this connection will only apply to the WiMAX device whose MAC address matches. This property does not change the MAC address of the device (known as MAC spoofing). Deprecated: 1") #define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME N_("Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1") -#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise it is a 32-bit fwmark for outgoing packets. Note that \"ip4-auto-default-route\" or \"ip6-auto-default-route\" enabled, implies to automatically choose a fwmark.") +#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise, it is a 32-bit fwmark for outgoing packets. Note that \"ip4-auto-default-route\" or \"ip6-auto-default-route\" enabled, implies to automatically choose a fwmark.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE N_("Whether to enable special handling of the IPv4 default route. If enabled, the IPv4 default route from wireguard.peer-routes will be placed to a dedicated routing-table and two policy routing rules will be added. The fwmark number is also used as routing-table for the default-route, and if fwmark is zero, an unused fwmark/table is chosen automatically. This corresponds to what wg-quick does with Table=auto and what WireGuard calls \"Improved Rule-based Routing\". Note that for this automatism to work, you usually don't want to set ipv4.gateway, because that will result in a conflicting default route. Leaving this at the default will enable this option automatically if ipv4.never-default is not set and there are any peers that use a default-route as allowed-ips.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE N_("Like ip4-auto-default-route, but for the IPv6 default route.") #define DESCRIBE_DOC_NM_SETTING_WIREGUARD_LISTEN_PORT N_("The listen-port. If listen-port is not specified, the port will be chosen randomly when the interface comes up.") diff --git a/clients/common/tests/test-clients-common.c b/clients/common/tests/test-clients-common.c index 0b61e7bb..8a59d4e2 100644 --- a/clients/common/tests/test-clients-common.c +++ b/clients/common/tests/test-clients-common.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2017 Red Hat, Inc. */ @@ -14,313 +14,345 @@ /*****************************************************************************/ static void -test_client_meta_check (void) +test_client_meta_check(void) { - const NMMetaSettingInfoEditor *const*infos_p; - NMMetaSettingType m; - guint p; - - G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaSettingInfoEditor, meta_type)); - G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaPropertyInfo, meta_type)); - - for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { - const NMMetaSettingInfo *info = &nm_meta_setting_infos[m]; - GType gtype; - - g_assert (info); - g_assert (info->meta_type == m); - g_assert (info->setting_name); - g_assert (info->get_setting_gtype); - - gtype = info->get_setting_gtype (); - g_assert (gtype != NM_TYPE_SETTING); - - { - nm_auto_unref_gtypeclass GTypeClass *gclass = g_type_class_ref (gtype); - - g_assert (G_TYPE_CHECK_CLASS_TYPE (gclass, gtype)); - } - { - gs_unref_object NMSetting *setting = g_object_new (gtype, NULL); - - g_assert (NM_IS_SETTING (setting)); - g_assert (G_TYPE_CHECK_INSTANCE_TYPE (setting, gtype)); - g_assert_cmpstr (nm_setting_get_name (setting), ==, info->setting_name); - } - } - - for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { - const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; - - g_assert (info); - g_assert (info->meta_type == &nm_meta_type_setting_info_editor); - g_assert (info->general); - g_assert (info->general == &nm_meta_setting_infos[m]); - - g_assert_cmpstr (info->general->setting_name, ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, FALSE)); - g_assert_cmpstr ("name", ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, TRUE)); - - g_assert (info->properties_num == NM_PTRARRAY_LEN (info->properties)); - - if (info->properties_num) { - gs_unref_hashtable GHashTable *property_names = g_hash_table_new (nm_str_hash, g_str_equal); - - g_assert (info->properties); - for (p = 0; p < info->properties_num; p++) { - const NMMetaPropertyInfo *pi = info->properties[p]; - - g_assert (pi); - g_assert (pi->meta_type == &nm_meta_type_property_info); - g_assert (pi->setting_info == info); - g_assert (pi->property_name); - - g_assert (g_hash_table_add (property_names, (gpointer) pi->property_name)); - - g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, FALSE)); - g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, TRUE)); - - g_assert (pi->property_type); - g_assert (pi->property_type->get_fcn); - } - g_assert (!info->properties[info->properties_num]); - } else - g_assert (!info->properties); - - if (info->valid_parts) { - gsize i, l; - gs_unref_hashtable GHashTable *dup = g_hash_table_new (nm_direct_hash, NULL); - - l = NM_PTRARRAY_LEN (info->valid_parts); - g_assert (l >= 2); - - for (i = 0; info->valid_parts[i]; i++) { - g_assert (info->valid_parts[i]->setting_info); - g_assert (g_hash_table_add (dup, (gpointer) info->valid_parts[i]->setting_info)); - - if (i == 0) { - g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]); - g_assert (info->valid_parts[i]->mandatory); - } - if (i == 1) { - g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[m]); - g_assert (info->valid_parts[i]->mandatory); - } - } - g_assert (i == l); - } - } - - for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { - const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; - - g_assert (nm_meta_setting_info_editor_find_by_name (info->general->setting_name, FALSE) == info); - g_assert (nm_meta_setting_info_editor_find_by_gtype (info->general->get_setting_gtype ()) == info); - - for (p = 0; p < info->properties_num; p++) { - const NMMetaPropertyInfo *pi = info->properties[p]; - - g_assert (nm_meta_setting_info_editor_get_property_info (info, pi->property_name) == pi); - g_assert (nm_meta_property_info_find_by_name (info->general->setting_name, pi->property_name) == pi); - } - } - - infos_p = nm_meta_setting_infos_editor_p (); - g_assert (infos_p); - for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) - g_assert (infos_p[m] == &nm_meta_setting_infos_editor[m]); - g_assert (!infos_p[m]); + const NMMetaSettingInfoEditor *const *infos_p; + NMMetaSettingType m; + guint p; + + G_STATIC_ASSERT(G_STRUCT_OFFSET(NMMetaAbstractInfo, meta_type) + == G_STRUCT_OFFSET(NMMetaSettingInfoEditor, meta_type)); + G_STATIC_ASSERT(G_STRUCT_OFFSET(NMMetaAbstractInfo, meta_type) + == G_STRUCT_OFFSET(NMMetaPropertyInfo, meta_type)); + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaSettingInfo *info = &nm_meta_setting_infos[m]; + GType gtype; + + g_assert(info); + g_assert(info->meta_type == m); + g_assert(info->setting_name); + g_assert(info->get_setting_gtype); + + gtype = info->get_setting_gtype(); + g_assert(gtype != NM_TYPE_SETTING); + + { + nm_auto_unref_gtypeclass GTypeClass *gclass = g_type_class_ref(gtype); + + g_assert(G_TYPE_CHECK_CLASS_TYPE(gclass, gtype)); + } + { + gs_unref_object NMSetting *setting = g_object_new(gtype, NULL); + + g_assert(NM_IS_SETTING(setting)); + g_assert(G_TYPE_CHECK_INSTANCE_TYPE(setting, gtype)); + g_assert_cmpstr(nm_setting_get_name(setting), ==, info->setting_name); + } + } + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; + + g_assert(info); + g_assert(info->meta_type == &nm_meta_type_setting_info_editor); + g_assert(info->general); + g_assert(info->general == &nm_meta_setting_infos[m]); + + g_assert_cmpstr(info->general->setting_name, + ==, + info->meta_type->get_name((const NMMetaAbstractInfo *) info, FALSE)); + g_assert_cmpstr("name", + ==, + info->meta_type->get_name((const NMMetaAbstractInfo *) info, TRUE)); + + g_assert(info->properties_num == NM_PTRARRAY_LEN(info->properties)); + + if (info->properties_num) { + gs_unref_hashtable GHashTable *property_names = + g_hash_table_new(nm_str_hash, g_str_equal); + + g_assert(info->properties); + for (p = 0; p < info->properties_num; p++) { + const NMMetaPropertyInfo *pi = info->properties[p]; + + g_assert(pi); + g_assert(pi->meta_type == &nm_meta_type_property_info); + g_assert(pi->setting_info == info); + g_assert(pi->property_name); + + g_assert(g_hash_table_add(property_names, (gpointer) pi->property_name)); + + g_assert_cmpstr(pi->property_name, + ==, + pi->meta_type->get_name((const NMMetaAbstractInfo *) pi, FALSE)); + g_assert_cmpstr(pi->property_name, + ==, + pi->meta_type->get_name((const NMMetaAbstractInfo *) pi, TRUE)); + + g_assert(pi->property_type); + g_assert(pi->property_type->get_fcn); + } + g_assert(!info->properties[info->properties_num]); + } else + g_assert(!info->properties); + + if (info->valid_parts) { + gsize i, l; + gs_unref_hashtable GHashTable *dup = g_hash_table_new(nm_direct_hash, NULL); + + l = NM_PTRARRAY_LEN(info->valid_parts); + g_assert(l >= 2); + + for (i = 0; info->valid_parts[i]; i++) { + g_assert(info->valid_parts[i]->setting_info); + g_assert(g_hash_table_add(dup, (gpointer) info->valid_parts[i]->setting_info)); + + if (i == 0) { + g_assert(info->valid_parts[i]->setting_info + == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]); + g_assert(info->valid_parts[i]->mandatory); + } + if (i == 1) { + g_assert(info->valid_parts[i]->setting_info + == &nm_meta_setting_infos_editor[m]); + g_assert(info->valid_parts[i]->mandatory); + } + } + g_assert(i == l); + } + } + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; + + g_assert(nm_meta_setting_info_editor_find_by_name(info->general->setting_name, FALSE) + == info); + g_assert(nm_meta_setting_info_editor_find_by_gtype(info->general->get_setting_gtype()) + == info); + + for (p = 0; p < info->properties_num; p++) { + const NMMetaPropertyInfo *pi = info->properties[p]; + + g_assert(nm_meta_setting_info_editor_get_property_info(info, pi->property_name) == pi); + g_assert( + nm_meta_property_info_find_by_name(info->general->setting_name, pi->property_name) + == pi); + } + } + + infos_p = nm_meta_setting_infos_editor_p(); + g_assert(infos_p); + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) + g_assert(infos_p[m] == &nm_meta_setting_infos_editor[m]); + g_assert(!infos_p[m]); } /*****************************************************************************/ static void -test_client_import_wireguard_test0 (void) +test_client_import_wireguard_test0(void) { - gs_unref_object NMConnection *connection; - NMSettingWireGuard *s_wg; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; - NMWireGuardPeer *peer; - gs_free_error GError *error = NULL; - - connection = nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test0.conf", - &error); - - g_assert_no_error (error); - - g_assert_cmpstr (nm_connection_get_id (connection), ==, "wg-test0"); - g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "wg-test0"); - g_assert_cmpstr (nm_connection_get_connection_type (connection), ==, NM_SETTING_WIREGUARD_SETTING_NAME); - - s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD)); - - g_assert_cmpint (nm_setting_wireguard_get_listen_port (s_wg), ==, 51820); - g_assert_cmpstr (nm_setting_wireguard_get_private_key (s_wg), ==, "yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk="); - - g_assert_cmpint (nm_setting_wireguard_get_peers_len (s_wg), ==, 3); - - peer = nm_setting_wireguard_get_peer (s_wg, 0); - g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg="); - g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "192.95.5.67:1234"); - g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 2); - g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.192.122.3/32"); - g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 1, NULL), ==, "10.192.124.1/24"); - - peer = nm_setting_wireguard_get_peer (s_wg, 1); - g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0="); - g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "[2607:5300:60:6b0::c05f:543]:2468"); - g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 2); - g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.192.122.4/32"); - g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 1, NULL), ==, "192.168.0.0/16"); - - peer = nm_setting_wireguard_get_peer (s_wg, 2); - g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "gN65BkIKy1eCE9pP1wdc8ROUtkHLF2PfAqYdyYBz6EA="); - g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "test.wireguard.com:18981"); - g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 1); - g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.10.10.230/32"); - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - s_ip6 = nm_connection_get_setting_ip6_config (connection); - - g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); - g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 0); - - g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip4), ==, 1); - g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip6), ==, 0); - - g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip4, 0), ==, "~"); + gs_unref_object NMConnection *connection; + NMSettingWireGuard * s_wg; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMWireGuardPeer * peer; + gs_free_error GError *error = NULL; + + connection = + nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test0.conf", &error); + + g_assert_no_error(error); + + g_assert_cmpstr(nm_connection_get_id(connection), ==, "wg-test0"); + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "wg-test0"); + g_assert_cmpstr(nm_connection_get_connection_type(connection), + ==, + NM_SETTING_WIREGUARD_SETTING_NAME); + + s_wg = NM_SETTING_WIREGUARD(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIREGUARD)); + + g_assert_cmpint(nm_setting_wireguard_get_listen_port(s_wg), ==, 51820); + g_assert_cmpstr(nm_setting_wireguard_get_private_key(s_wg), + ==, + "yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk="); + + g_assert_cmpint(nm_setting_wireguard_get_peers_len(s_wg), ==, 3); + + peer = nm_setting_wireguard_get_peer(s_wg, 0); + g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer), + ==, + "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg="); + g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "192.95.5.67:1234"); + g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 2); + g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.192.122.3/32"); + g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 1, NULL), ==, "10.192.124.1/24"); + + peer = nm_setting_wireguard_get_peer(s_wg, 1); + g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer), + ==, + "TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0="); + g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "[2607:5300:60:6b0::c05f:543]:2468"); + g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 2); + g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.192.122.4/32"); + g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 1, NULL), ==, "192.168.0.0/16"); + + peer = nm_setting_wireguard_get_peer(s_wg, 2); + g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer), + ==, + "gN65BkIKy1eCE9pP1wdc8ROUtkHLF2PfAqYdyYBz6EA="); + g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "test.wireguard.com:18981"); + g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 1); + g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.10.10.230/32"); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + s_ip6 = nm_connection_get_setting_ip6_config(connection); + + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 0); + + g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip4), ==, 1); + g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 0); + + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 0), ==, "~"); } static void -test_client_import_wireguard_test1 (void) +test_client_import_wireguard_test1(void) { - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; - nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test1.conf", &error); - g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); - g_assert (g_str_has_prefix (error->message, "invalid secret 'PrivateKey'")); - g_assert (g_str_has_suffix (error->message, "wg-test1.conf:2")); + nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test1.conf", &error); + g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); + g_assert(g_str_has_prefix(error->message, "invalid secret 'PrivateKey'")); + g_assert(g_str_has_suffix(error->message, "wg-test1.conf:2")); } static void -test_client_import_wireguard_test2 (void) +test_client_import_wireguard_test2(void) { - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; - nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test2.conf", &error); + nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test2.conf", &error); - g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); - g_assert (g_str_has_prefix (error->message, "unrecognized line at")); - g_assert (g_str_has_suffix (error->message, "wg-test2.conf:5")); + g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); + g_assert(g_str_has_prefix(error->message, "unrecognized line at")); + g_assert(g_str_has_suffix(error->message, "wg-test2.conf:5")); } static void -test_client_import_wireguard_test3 (void) +test_client_import_wireguard_test3(void) { - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; - nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test3.conf", &error); - g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); - g_assert (g_str_has_prefix (error->message, "invalid value for 'ListenPort'")); - g_assert (g_str_has_suffix (error->message, "wg-test3.conf:3")); + nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test3.conf", &error); + g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT); + g_assert(g_str_has_prefix(error->message, "invalid value for 'ListenPort'")); + g_assert(g_str_has_suffix(error->message, "wg-test3.conf:3")); } static void -test_client_import_wireguard_missing (void) +test_client_import_wireguard_missing(void) { - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; - nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-missing.conf", &error); - g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT); + nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-missing.conf", &error); + g_assert_error(error, G_FILE_ERROR, G_FILE_ERROR_NOENT); } /*****************************************************************************/ -#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \ - G_STMT_START { \ - static const NMUtilsNamedValue _values[] = { \ - __VA_ARGS__ \ - }; \ - gs_free char *_contents = g_strndup (contents, NM_STRLEN (contents)); \ - gs_unref_hashtable GHashTable *_secrets = NULL; \ - gs_free_error GError *_local = NULL; \ - gssize _error_line; \ - GError **_p_local = nmtst_get_rand_bool () ? &_local : NULL; \ - gssize *_p_error_line = nmtst_get_rand_bool () ? &_error_line : NULL; \ - gboolean _success = !!(success); \ - gssize _exp_error_line = (exp_error_line); \ - int _i; \ - \ - g_assert (_success || (G_N_ELEMENTS (_values) == 0)); \ - \ - _secrets = nmc_utils_parse_passwd_file (_contents, _p_error_line, _p_local); \ - \ - g_assert (_success == (!!_secrets)); \ - if (!_success) { \ - if (_p_error_line) \ - g_assert_cmpint (_exp_error_line, ==, *_p_error_line); \ - if (_p_local) \ - g_assert (_local); \ - } else { \ - if (_p_error_line) \ - g_assert_cmpint (-1, ==, *_p_error_line); \ - g_assert (!_local); \ - \ - for (_i = 0; _i < G_N_ELEMENTS (_values); _i++) { \ - const NMUtilsNamedValue *_n = &_values[_i]; \ - const char *_v; \ - \ - _v = g_hash_table_lookup (_secrets, _n->name); \ - if (!_v) \ - g_error ("cannot find key \"%s\"", _n->name); \ - g_assert_cmpstr (_v, ==, _n->value_str); \ - } \ - \ - g_assert_cmpint (g_hash_table_size (_secrets), ==, G_N_ELEMENTS (_values)); \ - } \ - } G_STMT_END - -#define _do_test_parse_passwd_file_bad( contents, exp_error_line) _do_test_parse_passwd_file (contents, FALSE, exp_error_line) -#define _do_test_parse_passwd_file_good(contents, ...) _do_test_parse_passwd_file (contents, TRUE, -1, __VA_ARGS__) +#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \ + G_STMT_START \ + { \ + static const NMUtilsNamedValue _values[] = {__VA_ARGS__}; \ + gs_free char * _contents = g_strndup(contents, NM_STRLEN(contents)); \ + gs_unref_hashtable GHashTable *_secrets = NULL; \ + gs_free_error GError *_local = NULL; \ + gssize _error_line; \ + GError ** _p_local = nmtst_get_rand_bool() ? &_local : NULL; \ + gssize * _p_error_line = nmtst_get_rand_bool() ? &_error_line : NULL; \ + gboolean _success = !!(success); \ + gssize _exp_error_line = (exp_error_line); \ + int _i; \ + \ + g_assert(_success || (G_N_ELEMENTS(_values) == 0)); \ + \ + _secrets = nmc_utils_parse_passwd_file(_contents, _p_error_line, _p_local); \ + \ + g_assert(_success == (!!_secrets)); \ + if (!_success) { \ + if (_p_error_line) \ + g_assert_cmpint(_exp_error_line, ==, *_p_error_line); \ + if (_p_local) \ + g_assert(_local); \ + } else { \ + if (_p_error_line) \ + g_assert_cmpint(-1, ==, *_p_error_line); \ + g_assert(!_local); \ + \ + for (_i = 0; _i < G_N_ELEMENTS(_values); _i++) { \ + const NMUtilsNamedValue *_n = &_values[_i]; \ + const char * _v; \ + \ + _v = g_hash_table_lookup(_secrets, _n->name); \ + if (!_v) \ + g_error("cannot find key \"%s\"", _n->name); \ + g_assert_cmpstr(_v, ==, _n->value_str); \ + } \ + \ + g_assert_cmpint(g_hash_table_size(_secrets), ==, G_N_ELEMENTS(_values)); \ + } \ + } \ + G_STMT_END + +#define _do_test_parse_passwd_file_bad(contents, exp_error_line) \ + _do_test_parse_passwd_file(contents, FALSE, exp_error_line) +#define _do_test_parse_passwd_file_good(contents, ...) \ + _do_test_parse_passwd_file(contents, TRUE, -1, __VA_ARGS__) static void -test_nmc_utils_parse_passwd_file (void) +test_nmc_utils_parse_passwd_file(void) { - _do_test_parse_passwd_file_good (""); - _do_test_parse_passwd_file_bad ("x", 1); - _do_test_parse_passwd_file_bad ("\r\rx", 3); - _do_test_parse_passwd_file_good ("wifi.psk=abc", - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc") ); - _do_test_parse_passwd_file_good ("wifi.psk:ABC\r" - "wifi-sec.psk = abc ", - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc") ); - _do_test_parse_passwd_file_good ("wifi.psk: abc\r" - "wifi-sec.psk2 = d\\145f\r\n" - " wifi.psk3 = e\\ \n" - " #wifi-sec.psk2 = \r\n" - " wifi-sec.psk4:", - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc"), - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk2", "def"), - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk3", "e "), - NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk4", "") ); + _do_test_parse_passwd_file_good(""); + _do_test_parse_passwd_file_bad("x", 1); + _do_test_parse_passwd_file_bad("\r\rx", 3); + _do_test_parse_passwd_file_good( + "wifi.psk=abc", + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc")); + _do_test_parse_passwd_file_good( + "wifi.psk:ABC\r" + "wifi-sec.psk = abc ", + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc")); + _do_test_parse_passwd_file_good( + "wifi.psk: abc\r" + "wifi-sec.psk2 = d\\145f\r\n" + " wifi.psk3 = e\\ \n" + " #wifi-sec.psk2 = \r\n" + " wifi-sec.psk4:", + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc"), + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk2", "def"), + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk3", "e "), + NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk4", "")); } /*****************************************************************************/ -NMTST_DEFINE (); +NMTST_DEFINE(); int -main (int argc, char **argv) +main(int argc, char **argv) { - nmtst_init (&argc, &argv, TRUE); + nmtst_init(&argc, &argv, TRUE); - g_test_add_func ("/client/meta/check", test_client_meta_check); - g_test_add_func ("/client/import/wireguard/test0", test_client_import_wireguard_test0); - g_test_add_func ("/client/import/wireguard/test1", test_client_import_wireguard_test1); - g_test_add_func ("/client/import/wireguard/test2", test_client_import_wireguard_test2); - g_test_add_func ("/client/import/wireguard/test3", test_client_import_wireguard_test3); - g_test_add_func ("/client/import/wireguard/missing", test_client_import_wireguard_missing); - g_test_add_func ("/client/test_nmc_utils_parse_passwd_file", test_nmc_utils_parse_passwd_file); + g_test_add_func("/client/meta/check", test_client_meta_check); + g_test_add_func("/client/import/wireguard/test0", test_client_import_wireguard_test0); + g_test_add_func("/client/import/wireguard/test1", test_client_import_wireguard_test1); + g_test_add_func("/client/import/wireguard/test2", test_client_import_wireguard_test2); + g_test_add_func("/client/import/wireguard/test3", test_client_import_wireguard_test3); + g_test_add_func("/client/import/wireguard/missing", test_client_import_wireguard_missing); + g_test_add_func("/client/test_nmc_utils_parse_passwd_file", test_nmc_utils_parse_passwd_file); - return g_test_run (); + return g_test_run(); } diff --git a/clients/common/tests/test-libnm-core-aux.c b/clients/common/tests/test-libnm-core-aux.c index 7acbc6e1..5b2b38fd 100644 --- a/clients/common/tests/test-libnm-core-aux.c +++ b/clients/common/tests/test-libnm-core-aux.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: LGPL-2.1+ +/* SPDX-License-Identifier: LGPL-2.1+ */ /* * Copyright (C) 2019 Red Hat, Inc. */ @@ -13,224 +13,238 @@ /*****************************************************************************/ static NMTeamLinkWatcher * -_team_link_watcher_from_string_impl (const char *str, gsize nextra, const char *const*vextra) +_team_link_watcher_from_string_impl(const char *str, gsize nextra, const char *const *vextra) { - NMTeamLinkWatcher *watcher; - gs_free char *str1_free = NULL; - gs_free_error GError *error = NULL; - gsize i; - - g_assert (str); - - watcher = nm_utils_team_link_watcher_from_string (str, &error); - nmtst_assert_success (watcher, error); - - for (i = 0; i < 1 + nextra; i++) { - nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL; - const char *str1; - - if (i == 0) { - str1_free = nm_utils_team_link_watcher_to_string (watcher); - g_assert (str1_free); - str1 = str1_free; - g_assert_cmpstr (str, ==, str1); - } else - str1 = vextra[i - 1]; - - watcher1 = nm_utils_team_link_watcher_from_string (str1, &error); - nmtst_assert_success (watcher1, error); - if (!nm_team_link_watcher_equal (watcher, watcher1)) { - gs_free char *ss1 = NULL; - gs_free char *ss2 = NULL; - - g_print (">>> watcher differs: \"%s\" vs. \"%s\"", - (ss1 = nm_utils_team_link_watcher_to_string (watcher)), - (ss2 = nm_utils_team_link_watcher_to_string (watcher1))); - g_print (">>> ORIG: \"%s\" vs. \"%s\"", str, str1); - g_assert_not_reached (); - } - g_assert (nm_team_link_watcher_equal (watcher1, watcher)); - } - - return watcher; + NMTeamLinkWatcher *watcher; + gs_free char * str1_free = NULL; + gs_free_error GError *error = NULL; + gsize i; + + g_assert(str); + + watcher = nm_utils_team_link_watcher_from_string(str, &error); + nmtst_assert_success(watcher, error); + + for (i = 0; i < 1 + nextra; i++) { + nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL; + const char * str1; + + if (i == 0) { + str1_free = nm_utils_team_link_watcher_to_string(watcher); + g_assert(str1_free); + str1 = str1_free; + g_assert_cmpstr(str, ==, str1); + } else + str1 = vextra[i - 1]; + + watcher1 = nm_utils_team_link_watcher_from_string(str1, &error); + nmtst_assert_success(watcher1, error); + if (!nm_team_link_watcher_equal(watcher, watcher1)) { + gs_free char *ss1 = NULL; + gs_free char *ss2 = NULL; + + g_print(">>> watcher differs: \"%s\" vs. \"%s\"", + (ss1 = nm_utils_team_link_watcher_to_string(watcher)), + (ss2 = nm_utils_team_link_watcher_to_string(watcher1))); + g_print(">>> ORIG: \"%s\" vs. \"%s\"", str, str1); + g_assert_not_reached(); + } + g_assert(nm_team_link_watcher_equal(watcher1, watcher)); + } + + return watcher; } #define _team_link_watcher_from_string(str, ...) \ - _team_link_watcher_from_string_impl ((str), NM_NARG (__VA_ARGS__), NM_MAKE_STRV (__VA_ARGS__)) + _team_link_watcher_from_string_impl((str), NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__)) /*****************************************************************************/ static void -test_team_link_watcher_tofro_string (void) +test_team_link_watcher_tofro_string(void) { - nm_auto_unref_team_link_watcher NMTeamLinkWatcher *w = NULL; - -#define _team_link_watcher_cmp(watcher, \ - name, \ - delay_down, \ - delay_up, \ - init_wait, \ - interval, \ - missed_max, \ - target_host, \ - source_host, \ - vlanid, \ - arping_flags) \ - G_STMT_START { \ - nm_auto_unref_team_link_watcher NMTeamLinkWatcher *_w = g_steal_pointer (watcher); \ - \ - g_assert_cmpstr ((name), ==, nm_team_link_watcher_get_name (_w)); \ - g_assert_cmpint ((delay_down), ==, nm_team_link_watcher_get_delay_down (_w)); \ - g_assert_cmpint ((delay_up), ==, nm_team_link_watcher_get_delay_up (_w)); \ - g_assert_cmpint ((init_wait), ==, nm_team_link_watcher_get_init_wait (_w)); \ - g_assert_cmpint ((interval), ==, nm_team_link_watcher_get_interval (_w)); \ - g_assert_cmpint ((missed_max), ==, nm_team_link_watcher_get_missed_max (_w)); \ - g_assert_cmpstr ((target_host), ==, nm_team_link_watcher_get_target_host (_w)); \ - g_assert_cmpstr ((source_host), ==, nm_team_link_watcher_get_source_host (_w)); \ - g_assert_cmpint ((vlanid), ==, nm_team_link_watcher_get_vlanid (_w)); \ - g_assert_cmpint ((arping_flags), ==, nm_team_link_watcher_get_flags (_w)); \ - } G_STMT_END - - w = _team_link_watcher_from_string ("name=ethtool", - "delay-up=0 name=ethtool", - " delay-down=0 name=ethtool "); - _team_link_watcher_cmp (&w, - "ethtool", - 0, - 0, - -1, - -1, - -1, - NULL, - NULL, - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=ethtool delay-up=10", - " delay-down=0 delay-up=10 name=ethtool"); - _team_link_watcher_cmp (&w, - "ethtool", - 0, - 10, - -1, - -1, - -1, - NULL, - NULL, - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=ethtool delay-up=10 delay-down=11", - " delay-down=11 delay-up=10 name=ethtool"); - _team_link_watcher_cmp (&w, - "ethtool", - 11, - 10, - -1, - -1, - -1, - NULL, - NULL, - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=nsna_ping target-host=xxx", - "name=nsna_ping target-host=xxx", - " missed-max=3 target-host=xxx name=nsna_ping "); - _team_link_watcher_cmp (&w, - "nsna_ping", - -1, - -1, - 0, - 0, - 3, - "xxx", - NULL, - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd", - " source-host=yzd target-host=xxx name=arp_ping "); - _team_link_watcher_cmp (&w, - "arp_ping", - -1, - -1, - 0, - 0, - 3, - "xxx", - "yzd", - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd"); - _team_link_watcher_cmp (&w, - "arp_ping", - -1, - -1, - 0, - 0, - 0, - "xxx", - "yzd", - 0, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); - - w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd validate-active=true", - "source-host=yzd send-always=false name=arp_ping validate-active=true validate-inactive=false target-host=xxx", - " source-host=yzd target-host=xxx validate-active=true name=arp_ping "); - _team_link_watcher_cmp (&w, - "arp_ping", - -1, - -1, - 0, - 0, - 3, - "xxx", - "yzd", - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE); - - w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd validate-active=true validate-inactive=true send-always=true", - "source-host=yzd send-always=true name=arp_ping validate-active=true validate-inactive=true target-host=xxx", - "source-host=yzd send-always=true name=arp_ping validate-active=1 validate-inactive=yes target-host=xxx", - " source-host=yzd target-host=xxx validate-inactive=true send-always=true validate-active=true name=arp_ping "); - _team_link_watcher_cmp (&w, - "arp_ping", - -1, - -1, - 0, - 0, - 3, - "xxx", - "yzd", - -1, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE - | NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_INACTIVE - | NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_SEND_ALWAYS); - - w = _team_link_watcher_from_string ("name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd"); - _team_link_watcher_cmp (&w, - "arp_ping", - -1, - -1, - 0, - 0, - 0, - "xxx", - "yzd", - 0, - NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + nm_auto_unref_team_link_watcher NMTeamLinkWatcher *w = NULL; + +#define _team_link_watcher_cmp(watcher, \ + name, \ + delay_down, \ + delay_up, \ + init_wait, \ + interval, \ + missed_max, \ + target_host, \ + source_host, \ + vlanid, \ + arping_flags) \ + G_STMT_START \ + { \ + nm_auto_unref_team_link_watcher NMTeamLinkWatcher *_w = g_steal_pointer(watcher); \ + \ + g_assert_cmpstr((name), ==, nm_team_link_watcher_get_name(_w)); \ + g_assert_cmpint((delay_down), ==, nm_team_link_watcher_get_delay_down(_w)); \ + g_assert_cmpint((delay_up), ==, nm_team_link_watcher_get_delay_up(_w)); \ + g_assert_cmpint((init_wait), ==, nm_team_link_watcher_get_init_wait(_w)); \ + g_assert_cmpint((interval), ==, nm_team_link_watcher_get_interval(_w)); \ + g_assert_cmpint((missed_max), ==, nm_team_link_watcher_get_missed_max(_w)); \ + g_assert_cmpstr((target_host), ==, nm_team_link_watcher_get_target_host(_w)); \ + g_assert_cmpstr((source_host), ==, nm_team_link_watcher_get_source_host(_w)); \ + g_assert_cmpint((vlanid), ==, nm_team_link_watcher_get_vlanid(_w)); \ + g_assert_cmpint((arping_flags), ==, nm_team_link_watcher_get_flags(_w)); \ + } \ + G_STMT_END + + w = _team_link_watcher_from_string("name=ethtool", + "delay-up=0 name=ethtool", + " delay-down=0 name=ethtool "); + _team_link_watcher_cmp(&w, + "ethtool", + 0, + 0, + -1, + -1, + -1, + NULL, + NULL, + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string("name=ethtool delay-up=10", + " delay-down=0 delay-up=10 name=ethtool"); + _team_link_watcher_cmp(&w, + "ethtool", + 0, + 10, + -1, + -1, + -1, + NULL, + NULL, + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string("name=ethtool delay-up=10 delay-down=11", + " delay-down=11 delay-up=10 name=ethtool"); + _team_link_watcher_cmp(&w, + "ethtool", + 11, + 10, + -1, + -1, + -1, + NULL, + NULL, + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string( + "name=nsna_ping target-host=xxx", + "name=nsna_ping target-host=xxx", + " missed-max=3 target-host=xxx name=nsna_ping "); + _team_link_watcher_cmp(&w, + "nsna_ping", + -1, + -1, + 0, + 0, + 3, + "xxx", + NULL, + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string("name=arp_ping target-host=xxx source-host=yzd", + " source-host=yzd target-host=xxx name=arp_ping "); + _team_link_watcher_cmp(&w, + "arp_ping", + -1, + -1, + 0, + 0, + 3, + "xxx", + "yzd", + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string( + "name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd"); + _team_link_watcher_cmp(&w, + "arp_ping", + -1, + -1, + 0, + 0, + 0, + "xxx", + "yzd", + 0, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); + + w = _team_link_watcher_from_string( + "name=arp_ping target-host=xxx source-host=yzd validate-active=true", + "source-host=yzd send-always=false name=arp_ping validate-active=true " + "validate-inactive=false target-host=xxx", + " source-host=yzd target-host=xxx validate-active=true name=arp_ping "); + _team_link_watcher_cmp(&w, + "arp_ping", + -1, + -1, + 0, + 0, + 3, + "xxx", + "yzd", + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE); + + w = _team_link_watcher_from_string( + "name=arp_ping target-host=xxx source-host=yzd validate-active=true validate-inactive=true " + "send-always=true", + "source-host=yzd send-always=true name=arp_ping validate-active=true " + "validate-inactive=true target-host=xxx", + "source-host=yzd send-always=true name=arp_ping validate-active=1 validate-inactive=yes " + "target-host=xxx", + " source-host=yzd target-host=xxx validate-inactive=true send-always=true " + "validate-active=true name=arp_ping "); + _team_link_watcher_cmp(&w, + "arp_ping", + -1, + -1, + 0, + 0, + 3, + "xxx", + "yzd", + -1, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE + | NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_INACTIVE + | NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_SEND_ALWAYS); + + w = _team_link_watcher_from_string( + "name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd"); + _team_link_watcher_cmp(&w, + "arp_ping", + -1, + -1, + 0, + 0, + 0, + "xxx", + "yzd", + 0, + NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE); } /*****************************************************************************/ -NMTST_DEFINE (); +NMTST_DEFINE(); -int main (int argc, char **argv) +int +main(int argc, char **argv) { - nmtst_init (&argc, &argv, TRUE); + nmtst_init(&argc, &argv, TRUE); - g_test_add_func ("/libnm-core-aux/test_team_link_watcher_tofro_string", test_team_link_watcher_tofro_string); + g_test_add_func("/libnm-core-aux/test_team_link_watcher_tofro_string", + test_team_link_watcher_tofro_string); - return g_test_run (); + return g_test_run(); } |