2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-07-24 08:53:33 -04:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2005 - 2017 Red Hat, Inc.
|
2014-07-24 08:53:33 -04:00
|
|
|
*/
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#ifndef __NM_UTILS_H__
|
|
|
|
|
#define __NM_UTILS_H__
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION)
|
|
|
|
|
#error "Only <NetworkManager.h> can be included directly."
|
2014-07-06 16:53:02 -04:00
|
|
|
#endif
|
|
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
2014-10-21 22:09:52 -04:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
2014-08-02 10:50:25 -04:00
|
|
|
/* For ETH_ALEN and INFINIBAND_ALEN */
|
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
|
#include <linux/if_infiniband.h>
|
|
|
|
|
|
2014-07-04 13:26:57 -04:00
|
|
|
#include "nm-core-enum-types.h"
|
2018-05-25 12:05:24 +02:00
|
|
|
#include "nm-setting-sriov.h"
|
2017-11-18 17:17:24 +01:00
|
|
|
#include "nm-setting-tc-config.h"
|
2018-05-25 12:05:24 +02:00
|
|
|
#include "nm-setting-wireless-security.h"
|
2014-07-24 08:53:33 -04:00
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
2018-12-29 13:01:28 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-03-02 11:08:34 +01:00
|
|
|
typedef struct _NMVariantAttributeSpec NMVariantAttributeSpec;
|
|
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
/* SSID helpers */
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_is_empty_ssid(const guint8 *ssid, gsize len);
|
|
|
|
|
const char *nm_utils_escape_ssid(const guint8 *ssid, gsize len);
|
|
|
|
|
gboolean nm_utils_same_ssid(const guint8 *ssid1,
|
|
|
|
|
gsize len1,
|
|
|
|
|
const guint8 *ssid2,
|
|
|
|
|
gsize len2,
|
|
|
|
|
gboolean ignore_trailing_null);
|
|
|
|
|
char * nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMUtilsSecurityType:
|
|
|
|
|
* @NMU_SEC_INVALID: unknown or invalid security, placeholder and not used
|
|
|
|
|
* @NMU_SEC_NONE: unencrypted and open
|
|
|
|
|
* @NMU_SEC_STATIC_WEP: static WEP keys are used for encryption
|
|
|
|
|
* @NMU_SEC_LEAP: Cisco LEAP is used for authentication and for generating the
|
|
|
|
|
* dynamic WEP keys automatically
|
|
|
|
|
* @NMU_SEC_DYNAMIC_WEP: standard 802.1x is used for authentication and
|
|
|
|
|
* generating the dynamic WEP keys automatically
|
|
|
|
|
* @NMU_SEC_WPA_PSK: WPA1 is used with Pre-Shared Keys (PSK)
|
|
|
|
|
* @NMU_SEC_WPA_ENTERPRISE: WPA1 is used with 802.1x authentication
|
|
|
|
|
* @NMU_SEC_WPA2_PSK: WPA2/RSN is used with Pre-Shared Keys (PSK)
|
|
|
|
|
* @NMU_SEC_WPA2_ENTERPRISE: WPA2 is used with 802.1x authentication
|
2019-10-04 11:37:45 +02:00
|
|
|
* @NMU_SEC_SAE: is used with WPA3 Enterprise
|
2019-11-17 23:57:15 +01:00
|
|
|
* @NMU_SEC_OWE: is used with Enhanced Open
|
2014-07-24 08:53:33 -04:00
|
|
|
*
|
|
|
|
|
* Describes generic security mechanisms that 802.11 access points may offer.
|
|
|
|
|
* Used with nm_utils_security_valid() for checking whether a given access
|
|
|
|
|
* point is compatible with a network device.
|
|
|
|
|
**/
|
|
|
|
|
typedef enum {
|
2020-09-28 16:03:33 +02:00
|
|
|
NMU_SEC_INVALID = 0,
|
|
|
|
|
NMU_SEC_NONE,
|
|
|
|
|
NMU_SEC_STATIC_WEP,
|
|
|
|
|
NMU_SEC_LEAP,
|
|
|
|
|
NMU_SEC_DYNAMIC_WEP,
|
|
|
|
|
NMU_SEC_WPA_PSK,
|
|
|
|
|
NMU_SEC_WPA_ENTERPRISE,
|
|
|
|
|
NMU_SEC_WPA2_PSK,
|
|
|
|
|
NMU_SEC_WPA2_ENTERPRISE,
|
|
|
|
|
NMU_SEC_SAE,
|
|
|
|
|
NMU_SEC_OWE,
|
2014-07-24 08:53:33 -04:00
|
|
|
} NMUtilsSecurityType;
|
|
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_security_valid(NMUtilsSecurityType type,
|
|
|
|
|
NMDeviceWifiCapabilities wifi_caps,
|
|
|
|
|
gboolean have_ap,
|
|
|
|
|
gboolean adhoc,
|
|
|
|
|
NM80211ApFlags ap_flags,
|
|
|
|
|
NM80211ApSecurityFlags ap_wpa,
|
|
|
|
|
NM80211ApSecurityFlags ap_rsn);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_ap_mode_security_valid(NMUtilsSecurityType type,
|
|
|
|
|
NMDeviceWifiCapabilities wifi_caps);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_wep_key_valid(const char *key, NMWepKeyType wep_type);
|
|
|
|
|
gboolean nm_utils_wpa_psk_valid(const char *psk);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2016-09-23 10:30:50 +02:00
|
|
|
NM_AVAILABLE_IN_1_6
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_is_json_object(const char *str, GError **error);
|
2014-11-25 23:01:55 +01:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
GVariant * nm_utils_ip4_dns_to_variant(char **dns);
|
|
|
|
|
char ** nm_utils_ip4_dns_from_variant(GVariant *value);
|
|
|
|
|
GVariant * nm_utils_ip4_addresses_to_variant(GPtrArray *addresses, const char *gateway);
|
|
|
|
|
GPtrArray *nm_utils_ip4_addresses_from_variant(GVariant *value, char **out_gateway);
|
|
|
|
|
GVariant * nm_utils_ip4_routes_to_variant(GPtrArray *routes);
|
|
|
|
|
GPtrArray *nm_utils_ip4_routes_from_variant(GVariant *value);
|
|
|
|
|
|
|
|
|
|
guint32 nm_utils_ip4_netmask_to_prefix(guint32 netmask);
|
|
|
|
|
guint32 nm_utils_ip4_prefix_to_netmask(guint32 prefix);
|
|
|
|
|
guint32 nm_utils_ip4_get_default_prefix(guint32 ip);
|
|
|
|
|
|
|
|
|
|
GVariant * nm_utils_ip6_dns_to_variant(char **dns);
|
|
|
|
|
char ** nm_utils_ip6_dns_from_variant(GVariant *value);
|
|
|
|
|
GVariant * nm_utils_ip6_addresses_to_variant(GPtrArray *addresses, const char *gateway);
|
|
|
|
|
GPtrArray *nm_utils_ip6_addresses_from_variant(GVariant *value, char **out_gateway);
|
|
|
|
|
GVariant * nm_utils_ip6_routes_to_variant(GPtrArray *routes);
|
|
|
|
|
GPtrArray *nm_utils_ip6_routes_from_variant(GVariant *value);
|
|
|
|
|
|
|
|
|
|
GVariant * nm_utils_ip_addresses_to_variant(GPtrArray *addresses);
|
|
|
|
|
GPtrArray *nm_utils_ip_addresses_from_variant(GVariant *value, int family);
|
|
|
|
|
GVariant * nm_utils_ip_routes_to_variant(GPtrArray *routes);
|
|
|
|
|
GPtrArray *nm_utils_ip_routes_from_variant(GVariant *value, int family);
|
2015-05-28 21:52:24 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_uuid_generate(void);
|
2015-05-28 21:52:24 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_file_is_certificate(const char *filename);
|
|
|
|
|
gboolean nm_utils_file_is_private_key(const char *filename, gboolean *out_encrypted);
|
|
|
|
|
gboolean nm_utils_file_is_pkcs12(const char *filename);
|
|
|
|
|
|
|
|
|
|
typedef gboolean (*NMUtilsFileSearchInPathsPredicate)(const char *filename, gpointer user_data);
|
|
|
|
|
|
|
|
|
|
struct stat;
|
2014-11-25 23:01:55 +01:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
typedef gboolean (*NMUtilsCheckFilePredicate)(const char * filename,
|
|
|
|
|
const struct stat *stat,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError ** error);
|
|
|
|
|
|
|
|
|
|
const char *nm_utils_file_search_in_paths(const char * progname,
|
|
|
|
|
const char * try_first,
|
|
|
|
|
const char *const * paths,
|
|
|
|
|
GFileTest file_test_flags,
|
|
|
|
|
NMUtilsFileSearchInPathsPredicate predicate,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError ** error);
|
|
|
|
|
|
|
|
|
|
guint32 nm_utils_wifi_freq_to_channel(guint32 freq);
|
|
|
|
|
guint32 nm_utils_wifi_channel_to_freq(guint32 channel, const char *band);
|
|
|
|
|
guint32 nm_utils_wifi_find_next_channel(guint32 channel, int direction, char *band);
|
|
|
|
|
gboolean nm_utils_wifi_is_channel_valid(guint32 channel, const char *band);
|
2015-08-18 09:37:48 +02:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
const guint *nm_utils_wifi_2ghz_freqs(void);
|
2015-08-18 09:37:48 +02:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
const guint *nm_utils_wifi_5ghz_freqs(void);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
const char *nm_utils_wifi_strength_bars(guint8 strength);
|
2014-09-19 16:51:07 -04:00
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
/**
|
|
|
|
|
* NM_UTILS_HWADDR_LEN_MAX:
|
|
|
|
|
*
|
|
|
|
|
* The maximum length of hardware addresses handled by NetworkManager itself,
|
|
|
|
|
* nm_utils_hwaddr_len(), and nm_utils_hwaddr_aton().
|
|
|
|
|
*/
|
|
|
|
|
#define NM_UTILS_HWADDR_LEN_MAX 20 /* INFINIBAND_ALEN */
|
|
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gsize nm_utils_hwaddr_len(int type) G_GNUC_PURE;
|
2014-10-28 08:32:25 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
char * nm_utils_hwaddr_ntoa(gconstpointer addr, gsize length);
|
|
|
|
|
GByteArray *nm_utils_hwaddr_atoba(const char *asc, gsize length);
|
|
|
|
|
guint8 * nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize length);
|
2014-10-28 08:32:25 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_hwaddr_valid(const char *asc, gssize length);
|
|
|
|
|
char * nm_utils_hwaddr_canonical(const char *asc, gssize length);
|
|
|
|
|
gboolean nm_utils_hwaddr_matches(gconstpointer hwaddr1,
|
|
|
|
|
gssize hwaddr1_len,
|
|
|
|
|
gconstpointer hwaddr2,
|
|
|
|
|
gssize hwaddr2_len);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
char * nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len);
|
|
|
|
|
GBytes *nm_utils_hexstr2bin(const char *hex);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2016-12-23 12:52:51 +01:00
|
|
|
NM_DEPRECATED_IN_1_6_FOR(nm_utils_is_valid_iface_name)
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_iface_valid_name(const char *name);
|
2016-12-23 12:52:41 +01:00
|
|
|
NM_AVAILABLE_IN_1_6
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_is_valid_iface_name(const char *name, GError **error);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_is_uuid(const char *str);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NM_UTILS_INET_ADDRSTRLEN:
|
|
|
|
|
*
|
|
|
|
|
* Defines the minimal length for a char buffer that is suitable as @dst argument
|
|
|
|
|
* for both nm_utils_inet4_ntop() and nm_utils_inet6_ntop().
|
|
|
|
|
**/
|
2020-09-28 16:03:33 +02:00
|
|
|
#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN
|
|
|
|
|
const char *nm_utils_inet4_ntop(in_addr_t inaddr, char *dst);
|
|
|
|
|
const char *nm_utils_inet6_ntop(const struct in6_addr *in6addr, char *dst);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_ipaddr_valid(int family, const char *ip);
|
2014-09-16 16:42:46 -04:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_check_virtual_device_compatibility(GType virtual_type, GType other_type);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2015-01-15 16:42:26 -05:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
int nm_utils_bond_mode_string_to_int(const char *mode);
|
2015-01-15 16:42:26 -05:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
const char *nm_utils_bond_mode_int_to_string(int mode);
|
2014-12-16 18:13:14 +01:00
|
|
|
|
2015-06-04 15:05:33 +02:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_enum_to_str(GType type, int value);
|
2015-06-04 15:05:33 +02:00
|
|
|
|
|
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean nm_utils_enum_from_str(GType type, const char *str, int *out_value, char **err_token);
|
2015-06-04 15:05:33 +02:00
|
|
|
|
2015-09-06 13:11:11 +02:00
|
|
|
NM_AVAILABLE_IN_1_2
|
2020-09-28 16:03:33 +02:00
|
|
|
const char **nm_utils_enum_get_values(GType type, int from, int to);
|
2015-09-06 13:11:11 +02:00
|
|
|
|
2016-12-20 16:36:15 +01:00
|
|
|
NM_AVAILABLE_IN_1_6
|
2020-09-28 16:03:33 +02:00
|
|
|
guint nm_utils_version(void);
|
2016-12-20 16:36:15 +01:00
|
|
|
|
2017-03-02 11:08:34 +01:00
|
|
|
NM_AVAILABLE_IN_1_8
|
2020-09-28 16:03:33 +02:00
|
|
|
GHashTable *nm_utils_parse_variant_attributes(const char *string,
|
|
|
|
|
char attr_separator,
|
|
|
|
|
char key_value_separator,
|
|
|
|
|
gboolean ignore_unknown,
|
|
|
|
|
const NMVariantAttributeSpec *const *spec,
|
|
|
|
|
GError ** error);
|
2017-03-02 11:08:34 +01:00
|
|
|
|
|
|
|
|
NM_AVAILABLE_IN_1_8
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_format_variant_attributes(GHashTable *attributes,
|
|
|
|
|
char attr_separator,
|
|
|
|
|
char key_value_separator);
|
2017-03-02 11:08:34 +01:00
|
|
|
|
2017-11-18 17:17:24 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
NMTCQdisc *nm_utils_tc_qdisc_from_str(const char *str, GError **error);
|
2017-11-18 17:17:24 +01:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_tc_qdisc_to_str(NMTCQdisc *qdisc, GError **error);
|
2017-11-18 17:17:24 +01:00
|
|
|
|
2017-11-28 09:22:49 +01:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
NMTCAction *nm_utils_tc_action_from_str(const char *str, GError **error);
|
2017-11-28 09:22:49 +01:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_tc_action_to_str(NMTCAction *action, GError **error);
|
2017-11-28 09:22:49 +01:00
|
|
|
|
2017-11-28 09:26:14 +01:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
NMTCTfilter *nm_utils_tc_tfilter_from_str(const char *str, GError **error);
|
2017-11-28 09:26:14 +01:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_tc_tfilter_to_str(NMTCTfilter *tfilter, GError **error);
|
2017-11-28 09:26:14 +01:00
|
|
|
|
2018-06-15 14:15:27 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
NM_AVAILABLE_IN_1_14
|
2020-09-28 16:03:33 +02:00
|
|
|
char *nm_utils_sriov_vf_to_str(const NMSriovVF *vf, gboolean omit_index, GError **error);
|
2018-05-25 12:05:24 +02:00
|
|
|
NM_AVAILABLE_IN_1_14
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSriovVF *nm_utils_sriov_vf_from_str(const char *str, GError **error);
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-06-15 14:15:27 +02:00
|
|
|
NM_AVAILABLE_IN_1_12
|
2020-09-28 16:03:33 +02:00
|
|
|
gint64 nm_utils_get_timestamp_msec(void);
|
2018-06-15 14:15:27 +02:00
|
|
|
|
2019-03-02 17:10:25 +01:00
|
|
|
NM_AVAILABLE_IN_1_16
|
2020-09-28 16:03:33 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_utils_base64secret_decode(const char *base64_key, gsize required_key_len, guint8 *out_key);
|
2018-05-25 12:05:24 +02:00
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#endif /* __NM_UTILS_H__ */
|