mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 19:30:07 +01:00
Previously we would call
nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
which treats the data in response as NUL terminated. That is not
entirely wrong, because the HTTP request's response is guaranteed
to have a NUL termination at the end. However, it doesn't seam to good
either.
For one, we already have the length. Use it. But also, if the response
contains any NUL bytes in the middle, then this would wrongly only
consider the first line. We should not accept "00:11:22:33:44:55\0bogus"
as valid.
While at it, reject NUL characters from nmcs_utils_hwaddr_normalize() --
except one NUL at the end.
132 lines
5.4 KiB
C
132 lines
5.4 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
|
#ifndef __NM_CLOUD_SETUP_UTILS_H__
|
|
#define __NM_CLOUD_SETUP_UTILS_H__
|
|
|
|
#include "nm-glib-aux/nm-logging-fwd.h"
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* mark names for variables that can be used as configuration. Search
|
|
* for NMCS_ENV_VARIABLE() to find all honored environment variables. */
|
|
#define NMCS_ENV_VARIABLE(var) "" var ""
|
|
|
|
/*****************************************************************************/
|
|
|
|
extern volatile NMLogLevel _nm_logging_configured_level;
|
|
|
|
static inline gboolean
|
|
nm_logging_enabled(NMLogLevel level)
|
|
{
|
|
return level >= _nm_logging_configured_level;
|
|
}
|
|
|
|
void _nm_logging_enabled_init(const char *level_str);
|
|
|
|
void _nm_log_impl_cs(NMLogLevel level, const char *fmt, ...) _nm_printf(2, 3);
|
|
|
|
#define _nm_log(level, ...) _nm_log_impl_cs((level), __VA_ARGS__);
|
|
|
|
#define _NMLOG(level, ...) \
|
|
G_STMT_START \
|
|
{ \
|
|
const NMLogLevel _level = (level); \
|
|
\
|
|
if (nm_logging_enabled(_level)) { \
|
|
_nm_log(_level, __VA_ARGS__); \
|
|
} \
|
|
} \
|
|
G_STMT_END
|
|
|
|
/*****************************************************************************/
|
|
|
|
#ifndef NM_DIST_VERSION
|
|
#define NM_DIST_VERSION VERSION
|
|
#endif
|
|
|
|
/*****************************************************************************/
|
|
|
|
gpointer nmcs_wait_for_objects_register(gpointer target);
|
|
|
|
gboolean nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int timeout_msec);
|
|
|
|
/*****************************************************************************/
|
|
|
|
typedef void (*NMCSUtilsPollProbeStartFcn)(GCancellable * cancellable,
|
|
gpointer probe_user_data,
|
|
GAsyncReadyCallback callback,
|
|
gpointer user_data);
|
|
|
|
typedef gboolean (*NMCSUtilsPollProbeFinishFcn)(GObject * source,
|
|
GAsyncResult *result,
|
|
gpointer probe_user_data,
|
|
GError ** error);
|
|
|
|
void nmcs_utils_poll(int poll_timeout_ms,
|
|
int ratelimit_timeout_ms,
|
|
int sleep_timeout_ms,
|
|
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
|
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
|
gpointer probe_user_data,
|
|
GCancellable * cancellable,
|
|
GAsyncReadyCallback callback,
|
|
gpointer user_data);
|
|
|
|
gboolean nmcs_utils_poll_finish(GAsyncResult *result, gpointer *probe_user_data, GError **error);
|
|
|
|
/*****************************************************************************/
|
|
|
|
char *nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len);
|
|
|
|
static inline char *
|
|
nmcs_utils_hwaddr_normalize_gbytes(GBytes *hwaddr)
|
|
{
|
|
const char *str;
|
|
gsize len;
|
|
|
|
str = g_bytes_get_data(hwaddr, &len);
|
|
return nmcs_utils_hwaddr_normalize(str, len);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
const char *nmcs_utils_parse_memmem(GBytes *mem, const char *needle);
|
|
|
|
const char *nmcs_utils_parse_get_full_line(GBytes *mem, const char *needle);
|
|
|
|
/*****************************************************************************/
|
|
|
|
char *nmcs_utils_uri_build_concat_v(const char *base, const char **components, gsize n_components);
|
|
|
|
#define nmcs_utils_uri_build_concat(base, ...) \
|
|
nmcs_utils_uri_build_concat_v(base, ((const char *[]){__VA_ARGS__}), NM_NARG(__VA_ARGS__))
|
|
|
|
/*****************************************************************************/
|
|
|
|
gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip,
|
|
NMIPAddress ** entries_arr,
|
|
guint entries_len);
|
|
|
|
gboolean nmcs_setting_ip_replace_ipv4_routes(NMSettingIPConfig *s_ip,
|
|
NMIPRoute ** entries_arr,
|
|
guint entries_len);
|
|
|
|
gboolean nmcs_setting_ip_replace_ipv4_rules(NMSettingIPConfig *s_ip,
|
|
NMIPRoutingRule ** entries_arr,
|
|
guint entries_len);
|
|
|
|
/*****************************************************************************/
|
|
|
|
NMConnection *nmcs_device_get_applied_connection(NMDevice * device,
|
|
GCancellable *cancellable,
|
|
guint64 * version_id,
|
|
GError ** error);
|
|
|
|
gboolean nmcs_device_reapply(NMDevice * device,
|
|
GCancellable *sigterm_cancellable,
|
|
NMConnection *connection,
|
|
guint64 version_id,
|
|
gboolean * out_version_id_changed,
|
|
GError ** error);
|
|
|
|
#endif /* __NM_CLOUD_SETUP_UTILS_H__ */
|