|
Packit Service |
a1bd4f |
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2004 - 2016 Red Hat, Inc.
|
|
Packit |
5756e2 |
* Copyright (C) 2005 - 2008 Novell, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#ifndef __NETWORKMANAGER_UTILS_H__
|
|
Packit |
5756e2 |
#define __NETWORKMANAGER_UTILS_H__
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-core-utils.h"
|
|
Packit |
5756e2 |
#include "nm-glib-aux/nm-dedup-multi.h"
|
|
Packit |
5756e2 |
#include "nm-setting-ip-config.h"
|
|
Packit |
5756e2 |
#include "nm-setting-ip6-config.h"
|
|
Packit |
5756e2 |
#include "platform/nm-platform.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *nm_utils_get_ip_config_method(NMConnection *connection, int addr_family);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
const char *nm_utils_get_shared_wifi_permission(NMConnection *connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_complete_generic(NMPlatform * platform,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
const char * ctype,
|
|
Packit Service |
a1bd4f |
NMConnection *const *existing_connections,
|
|
Packit Service |
a1bd4f |
const char * preferred_id,
|
|
Packit Service |
a1bd4f |
const char * fallback_id_prefix,
|
|
Packit Service |
a1bd4f |
const char * ifname_prefix,
|
|
Packit Service |
a1bd4f |
const char * ifname,
|
|
Packit Service |
a1bd4f |
gboolean default_enable_ipv6);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
typedef gboolean(NMUtilsMatchFilterFunc)(NMConnection *connection, gpointer user_data);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
NMConnection *nm_utils_match_connection(NMConnection *const * connections,
|
|
Packit Service |
a1bd4f |
NMConnection * original,
|
|
Packit Service |
a1bd4f |
gboolean indicated,
|
|
Packit Service |
a1bd4f |
gboolean device_has_carrier,
|
|
Packit Service |
a1bd4f |
gint64 default_v4_metric,
|
|
Packit Service |
a1bd4f |
gint64 default_v6_metric,
|
|
Packit Service |
a1bd4f |
NMUtilsMatchFilterFunc match_filter_func,
|
|
Packit Service |
a1bd4f |
gpointer match_filter_data);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink,
|
|
Packit Service |
a1bd4f |
const char * match_device_type,
|
|
Packit Service |
a1bd4f |
const char * match_dhcp_plugin,
|
|
Packit Service |
a1bd4f |
const GSList * specs,
|
|
Packit Service |
a1bd4f |
int no_match_value);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMPlatformRoutingRule *nm_ip_routing_rule_to_platform(const NMIPRoutingRule *rule,
|
|
Packit Service |
a1bd4f |
NMPlatformRoutingRule *out_pl);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/* during shutdown, there are two relevant timeouts. One is
|
|
Packit |
5756e2 |
* NM_SHUTDOWN_TIMEOUT_MS which is plenty of time, that we give for all
|
|
Packit |
5756e2 |
* actions to complete. Of course, during shutdown components should hurry
|
|
Packit |
5756e2 |
* to cleanup.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* When we initiate shutdown, we should start killing child processes
|
|
Packit |
5756e2 |
* with SIGTERM. If they don't complete within NM_SHUTDOWN_TIMEOUT_MS, we send
|
|
Packit |
5756e2 |
* SIGKILL.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* After NM_SHUTDOWN_TIMEOUT_MS, NetworkManager will however not yet terminate right
|
|
Packit |
5756e2 |
* away. It iterates the mainloop for another NM_SHUTDOWN_TIMEOUT_MS_WATCHDOG. This
|
|
Packit |
5756e2 |
* should give time to reap the child process (after SIGKILL).
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* So, the maximum time we should wait before sending SIGKILL should be at most
|
|
Packit |
5756e2 |
* NM_SHUTDOWN_TIMEOUT_MS.
|
|
Packit |
5756e2 |
*/
|
|
Packit Service |
a1bd4f |
#define NM_SHUTDOWN_TIMEOUT_MS 1500
|
|
Packit Service |
a1bd4f |
#define NM_SHUTDOWN_TIMEOUT_MS_WATCHDOG 500
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef enum {
|
|
Packit Service |
a1bd4f |
/* There is no watched_obj argument, and the shutdown is delayed until the user
|
|
Packit Service |
a1bd4f |
* explicitly calls unregister on the returned handle. */
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_HANDLE,
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* The watched_obj argument is a GObject, and shutdown is delayed until the object
|
|
Packit Service |
a1bd4f |
* gets destroyed (or unregistered). */
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_OBJECT,
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* The watched_obj argument is a GCancellable, and shutdown is delayed until the object
|
|
Packit Service |
a1bd4f |
* gets destroyed (or unregistered). Note that after NM_SHUTDOWN_TIMEOUT_MS, the
|
|
Packit Service |
a1bd4f |
* cancellable will be cancelled to notify listeners about the shutdown. */
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_CANCELLABLE,
|
|
Packit |
5756e2 |
} NMShutdownWaitType;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct _NMShutdownWaitObjHandle NMShutdownWaitObjHandle;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMShutdownWaitObjHandle *nm_shutdown_wait_obj_register_full(gpointer watched_obj,
|
|
Packit Service |
a1bd4f |
NMShutdownWaitType wait_type,
|
|
Packit Service |
a1bd4f |
char * msg_reason,
|
|
Packit Service |
a1bd4f |
gboolean free_msg_reason);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline NMShutdownWaitObjHandle *
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_object_full(gpointer watched_obj,
|
|
Packit Service |
a1bd4f |
char * msg_reason,
|
|
Packit Service |
a1bd4f |
gboolean free_msg_reason)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nm_shutdown_wait_obj_register_full(watched_obj,
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_OBJECT,
|
|
Packit Service |
a1bd4f |
msg_reason,
|
|
Packit Service |
a1bd4f |
free_msg_reason);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nm_shutdown_wait_obj_register_object(watched_obj, msg_reason) \
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_object_full((watched_obj), ("" msg_reason ""), FALSE)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline NMShutdownWaitObjHandle *
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_handle_full(char *msg_reason, gboolean free_msg_reason)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nm_shutdown_wait_obj_register_full(NULL,
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_HANDLE,
|
|
Packit Service |
a1bd4f |
msg_reason,
|
|
Packit Service |
a1bd4f |
free_msg_reason);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nm_shutdown_wait_obj_register_handle(msg_reason) \
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_handle_full(("" msg_reason ""), FALSE)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline NMShutdownWaitObjHandle *
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_cancellable_full(GCancellable *watched_obj,
|
|
Packit Service |
a1bd4f |
char * msg_reason,
|
|
Packit Service |
a1bd4f |
gboolean free_msg_reason)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nm_shutdown_wait_obj_register_full(watched_obj,
|
|
Packit Service |
a1bd4f |
NM_SHUTDOWN_WAIT_TYPE_CANCELLABLE,
|
|
Packit Service |
a1bd4f |
msg_reason,
|
|
Packit Service |
a1bd4f |
free_msg_reason);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nm_shutdown_wait_obj_register_cancellable(watched_obj, msg_reason) \
|
|
Packit Service |
a1bd4f |
nm_shutdown_wait_obj_register_cancellable_full((watched_obj), ("" msg_reason ""), FALSE)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_shutdown_wait_obj_unregister(NMShutdownWaitObjHandle *handle);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *nm_utils_file_is_in_path(const char *abs_filename, const char *abs_path);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
GPtrArray *
|
|
Packit Service |
a1bd4f |
nm_utils_qdiscs_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, int ip_ifindex);
|
|
Packit Service |
a1bd4f |
GPtrArray *
|
|
Packit Service |
a1bd4f |
nm_utils_tfilters_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, int ip_ifindex);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_ip_route_attribute_to_platform(int addr_family,
|
|
Packit Service |
a1bd4f |
NMIPRoute * s_route,
|
|
Packit Service |
a1bd4f |
NMPlatformIPRoute *r,
|
|
Packit Service |
a1bd4f |
guint32 route_table);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_ip_addresses_to_dbus(int addr_family,
|
|
Packit Service |
a1bd4f |
const NMDedupMultiHeadEntry *head_entry,
|
|
Packit Service |
a1bd4f |
const NMPObject * best_default_route,
|
|
Packit Service |
a1bd4f |
NMSettingIP6ConfigPrivacy ipv6_privacy,
|
|
Packit Service |
a1bd4f |
GVariant ** out_address_data,
|
|
Packit Service |
a1bd4f |
GVariant ** out_addresses);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_ip_routes_to_dbus(int addr_family,
|
|
Packit Service |
a1bd4f |
const NMDedupMultiHeadEntry *head_entry,
|
|
Packit Service |
a1bd4f |
GVariant ** out_route_data,
|
|
Packit Service |
a1bd4f |
GVariant ** out_routes);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/* For now, all we track about a DHCP lease is the GHashTable with
|
|
Packit |
5756e2 |
* the options.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* We don't add a separate type for that, but we also don't want to use
|
|
Packit |
5756e2 |
* GHashTable directly (because most importantly leases should be immutable
|
|
Packit |
5756e2 |
* and passing a GHashTable pointer around neither makes it clear that
|
|
Packit |
5756e2 |
* this is a lease nor that it's immutable.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Instead, add a simple opaque pointer and accessors that cast to a GHashTable.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* It has no overhead at run time, but gives some rudimentary type safety. */
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct _NMDhcpLease NMDhcpLease;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline NMDhcpLease *
|
|
Packit Service |
a1bd4f |
nm_dhcp_lease_new_from_options(GHashTable *options_take)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
/* a NMDhcpLease is really just a GHashTable. But it's also supposed to be *immutable*.
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Hence, the API here takes over ownership of the reference to @options_take, that
|
|
Packit Service |
a1bd4f |
* is to emphasize that we acquire ownership of the hash, and it should not be modified
|
|
Packit Service |
a1bd4f |
* anymore. */
|
|
Packit Service |
a1bd4f |
return (NMDhcpLease *) options_take;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline GHashTable *
|
|
Packit Service |
a1bd4f |
nm_dhcp_lease_get_options(NMDhcpLease *lease)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return (GHashTable *) lease;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void
|
|
Packit Service |
a1bd4f |
nm_dhcp_lease_ref(NMDhcpLease *lease)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
if (lease)
|
|
Packit Service |
a1bd4f |
g_hash_table_ref((GHashTable *) lease);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void
|
|
Packit Service |
a1bd4f |
nm_dhcp_lease_unref(NMDhcpLease *lease)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
if (lease)
|
|
Packit Service |
a1bd4f |
g_hash_table_unref((GHashTable *) lease);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline const char *
|
|
Packit Service |
a1bd4f |
nm_dhcp_lease_lookup_option(NMDhcpLease *lease, const char *option)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(option);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return nm_g_hash_table_lookup((GHashTable *) lease, option);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_AUTO_DEFINE_FCN(NMDhcpLease *, _nm_auto_unref_dhcplease, nm_dhcp_lease_unref);
|
|
Packit Service |
a1bd4f |
#define nm_auto_unref_dhcplease nm_auto(_nm_auto_unref_dhcplease)
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/*****************************************************************************/
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
typedef struct _NMUtilsShareRules NMUtilsShareRules;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
NMUtilsShareRules *nm_utils_share_rules_new(void);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_share_rules_free(NMUtilsShareRules *self);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void
|
|
Packit Service |
a1bd4f |
nm_utils_share_rules_add_rule_take(NMUtilsShareRules *self, const char *table, char *rule_take);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
static inline void
|
|
Packit Service |
a1bd4f |
nm_utils_share_rules_add_rule(NMUtilsShareRules *self, const char *table, const char *rule)
|
|
Packit Service |
a1bd4f |
{
|
|
Packit Service |
a1bd4f |
nm_utils_share_rules_add_rule_take(self, table, g_strdup(rule));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nm_utils_share_rules_add_rule_v(self, table, ...) \
|
|
Packit Service |
a1bd4f |
nm_utils_share_rules_add_rule_take((self), (table), g_strdup_printf(__VA_ARGS__))
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_share_rules_add_all_rules(NMUtilsShareRules *self,
|
|
Packit Service |
a1bd4f |
const char * ip_iface,
|
|
Packit Service |
a1bd4f |
in_addr_t addr,
|
|
Packit Service |
a1bd4f |
guint plen);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_utils_share_rules_apply(NMUtilsShareRules *self, gboolean shared);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#endif /* __NETWORKMANAGER_UTILS_H__ */
|