Blame src/nm-config.h

Packit Service a1bd4f
/* SPDX-License-Identifier: GPL-2.0+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2011 Red Hat, Inc.
Packit 5756e2
 * Copyright (C) 2013 Thomas Bechtold <thomasbechtold@jpberlin.de>
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#ifndef __NETWORKMANAGER_CONFIG_H__
Packit 5756e2
#define __NETWORKMANAGER_CONFIG_H__
Packit 5756e2
Packit 5756e2
#include "nm-config-data.h"
Packit 5756e2
Packit Service a1bd4f
#define NM_TYPE_CONFIG            (nm_config_get_type())
Packit Service a1bd4f
#define NM_CONFIG(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_CONFIG, NMConfig))
Packit Service a1bd4f
#define NM_CONFIG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_CONFIG, NMConfigClass))
Packit Service a1bd4f
#define NM_IS_CONFIG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_CONFIG))
Packit Service a1bd4f
#define NM_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_CONFIG))
Packit Service a1bd4f
#define NM_CONFIG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_CONFIG, NMConfigClass))
Packit 5756e2
Packit 5756e2
/* Properties */
Packit Service a1bd4f
#define NM_CONFIG_CMD_LINE_OPTIONS        "cmd-line-options"
Packit Service a1bd4f
#define NM_CONFIG_ATOMIC_SECTION_PREFIXES "atomic-section-prefixes"
Packit 5756e2
Packit 5756e2
/* Signals */
Packit Service a1bd4f
#define NM_CONFIG_SIGNAL_CONFIG_CHANGED "config-changed"
Packit 5756e2
Packit 5756e2
#define NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL 300
Packit 5756e2
#define NM_CONFIG_DEFAULT_CONNECTIVITY_RESPONSE "NetworkManager is online" /* NOT LOCALIZED */
Packit 5756e2
Packit 5756e2
#define NM_CONFIG_KEYFILE_LIST_SEPARATOR ','
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN                 ".intern."
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION             "connection"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE                 "device"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN      "global-dns-domain-"
Packit 5756e2
#define NM_CONFIG_KEYFILE_GROUPPREFIX_TEST_APPEND_STRINGLIST ".test-append-stringlist"
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_MAIN         "main"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_LOGGING      "logging"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY "connectivity"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_KEYFILE      "keyfile"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_IFUPDOWN     "ifupdown"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS   "global-dns"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_GROUP_CONFIG       ".config"
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_ASSUME_IPV6LL_ONLY          "assume-ipv6ll-only"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT                 "auth-polkit"
Packit 5756e2
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTOCONNECT_RETRIES_DEFAULT "autoconnect-retries-default"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_CONFIGURE_AND_QUIT          "configure-and-quit"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG                       "debug"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP                        "dhcp"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_DNS                         "dns"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE               "hostname-mode"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_IGNORE_CARRIER              "ignore-carrier"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_MONITOR_CONNECTION_FILES    "monitor-connection-files"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_NO_AUTO_DEFAULT             "no-auto-default"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_PLUGINS                     "plugins"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_RC_MANAGER                  "rc-manager"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER                "slaves-order"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MAIN_SYSTEMD_RESOLVED            "systemd-resolved"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_LOGGING_AUDIT   "audit"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_LOGGING_DOMAINS "domains"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_LOGGING_LEVEL   "level"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_ENABLED  "enabled"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_INTERVAL "interval"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_RESPONSE "response"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_URI      "uri"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH              "path"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES "unmanaged-devices"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME          "hostname"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED "managed"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_SEARCHES "searches"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_OPTIONS  "options"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_DOMAIN_SERVERS "servers"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_DOMAIN_OPTIONS "options"
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED                    "managed"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER             "ignore-carrier"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_SRIOV_NUM_VFS              "sriov-num-vfs"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND               "wifi.backend"
Packit 5756e2
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_RAND_MAC_ADDRESS "wifi.scan-rand-mac-address"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_GENERATE_MAC_ADDRESS_MASK \
Packit Service a1bd4f
    "wifi.scan-generate-mac-address-mask"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT "carrier-wait-timeout"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_IWD_AUTOCONNECT "wifi.iwd.autoconnect"
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE "match-device"
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_STOP_MATCH   "stop-match"
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"   /* check-config-options skip */
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE      "enable" /* check-config-options skip */
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEYPREFIX_WAS ".was."
Packit Service a1bd4f
#define NM_CONFIG_KEYFILE_KEYPREFIX_SET ".set."
Packit 5756e2
Packit 5756e2
#define NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS \
Packit Service a1bd4f
    NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS
Packit 5756e2
#define NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_GLOBAL_DNS_DOMAIN \
Packit Service a1bd4f
    NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN
Packit 5756e2
Packit 5756e2
typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions;
Packit 5756e2
Packit 5756e2
typedef enum {
Packit Service a1bd4f
    NM_CONFIG_STATE_PROPERTY_NONE,
Packit 5756e2
Packit Service a1bd4f
    /* 1 set-argument: (gboolean enabled) */
Packit Service a1bd4f
    NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED,
Packit Service a1bd4f
    NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED,
Packit Service a1bd4f
    NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED,
Packit 5756e2
} NMConfigRunStatePropertyType;
Packit 5756e2
Packit 5756e2
typedef enum {
Packit Service a1bd4f
    NM_CONFIG_CONFIGURE_AND_QUIT_INVALID  = -1,
Packit Service a1bd4f
    NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED = FALSE,
Packit Service a1bd4f
    NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED  = TRUE,
Packit Service a1bd4f
    NM_CONFIG_CONFIGURE_AND_QUIT_INITRD,
Packit 5756e2
} NMConfigConfigureAndQuitType;
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    bool net_enabled;
Packit Service a1bd4f
    bool wifi_enabled;
Packit Service a1bd4f
    bool wwan_enabled;
Packit 5756e2
Packit Service a1bd4f
    /* Whether the runstate is modified and not saved to disk. */
Packit Service a1bd4f
    bool dirty;
Packit 5756e2
} NMConfigState;
Packit 5756e2
Packit 5756e2
typedef struct _NMConfigClass NMConfigClass;
Packit 5756e2
Packit Service a1bd4f
GType nm_config_get_type(void);
Packit 5756e2
Packit Service a1bd4f
NMConfig *nm_config_get(void);
Packit 5756e2
Packit Service a1bd4f
const char *nm_config_change_flags_to_string(NMConfigChangeFlags flags, char *buf, gsize len);
Packit 5756e2
Packit Service a1bd4f
NMConfigData *nm_config_get_data(NMConfig *config);
Packit Service a1bd4f
NMConfigData *nm_config_get_data_orig(NMConfig *config);
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_GET_DATA      (nm_config_get_data(nm_config_get()))
Packit Service a1bd4f
#define NM_CONFIG_GET_DATA_ORIG (nm_config_get_data_orig(nm_config_get()))
Packit 5756e2
Packit Service a1bd4f
const char *                 nm_config_get_log_level(NMConfig *config);
Packit Service a1bd4f
const char *                 nm_config_get_log_domains(NMConfig *config);
Packit Service a1bd4f
NMConfigConfigureAndQuitType nm_config_get_configure_and_quit(NMConfig *config);
Packit Service a1bd4f
gboolean                     nm_config_get_is_debug(NMConfig *config);
Packit 5756e2
Packit Service a1bd4f
gboolean nm_config_get_first_start(NMConfig *config);
Packit 5756e2
Packit Service a1bd4f
const char *nm_config_get_no_auto_default_file(NMConfig *config);
Packit 5756e2
Packit Service a1bd4f
void nm_config_set_values(NMConfig *self,
Packit Service a1bd4f
                          GKeyFile *keyfile_intern_new,
Packit Service a1bd4f
                          gboolean  allow_write,
Packit Service a1bd4f
                          gboolean  force_rewrite);
Packit 5756e2
Packit 5756e2
/* for main.c only */
Packit Service a1bd4f
NMConfigCmdLineOptions *nm_config_cmd_line_options_new(gboolean first_start);
Packit Service a1bd4f
void                    nm_config_cmd_line_options_free(NMConfigCmdLineOptions *cli);
Packit Service a1bd4f
void                    nm_config_cmd_line_options_add_to_entries(NMConfigCmdLineOptions *cli,
Packit Service a1bd4f
                                                                  GOptionContext *        opt_ctx);
Packit 5756e2
Packit Service a1bd4f
gboolean nm_config_get_no_auto_default_for_device(NMConfig *config, NMDevice *device);
Packit Service a1bd4f
void     nm_config_set_no_auto_default_for_device(NMConfig *config, NMDevice *device);
Packit 5756e2
Packit Service a1bd4f
NMConfig *
Packit Service a1bd4f
nm_config_new(const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error);
Packit Service a1bd4f
NMConfig *
Packit Service a1bd4f
nm_config_setup(const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error);
Packit Service a1bd4f
void nm_config_reload(NMConfig *config, NMConfigChangeFlags reload_flags, gboolean emit_warnings);
Packit 5756e2
Packit Service a1bd4f
const NMConfigState *nm_config_state_get(NMConfig *config);
Packit 5756e2
Packit Service a1bd4f
void _nm_config_state_set(NMConfig *config, gboolean allow_persist, gboolean force_persist, ...);
Packit 5756e2
#define nm_config_state_set(config, allow_persist, force_persist, ...) \
Packit Service a1bd4f
    _nm_config_state_set(config, allow_persist, force_persist, ##__VA_ARGS__, 0)
Packit Service a1bd4f
Packit Service a1bd4f
int nm_config_parse_boolean(const char *str, int default_value);
Packit Service a1bd4f
Packit Service a1bd4f
GKeyFile *nm_config_create_keyfile(void);
Packit Service a1bd4f
int       nm_config_keyfile_get_boolean(const GKeyFile *keyfile,
Packit Service a1bd4f
                                        const char *    section,
Packit Service a1bd4f
                                        const char *    key,
Packit Service a1bd4f
                                        int             default_value);
Packit Service a1bd4f
gint64    nm_config_keyfile_get_int64(const GKeyFile *keyfile,
Packit Service a1bd4f
                                      const char *    section,
Packit Service a1bd4f
                                      const char *    key,
Packit Service a1bd4f
                                      guint           base,
Packit Service a1bd4f
                                      gint64          min,
Packit Service a1bd4f
                                      gint64          max,
Packit Service a1bd4f
                                      gint64          fallback);
Packit Service a1bd4f
char *    nm_config_keyfile_get_value(const GKeyFile *      keyfile,
Packit Service a1bd4f
                                      const char *          section,
Packit Service a1bd4f
                                      const char *          key,
Packit Service a1bd4f
                                      NMConfigGetValueFlags flags);
Packit Service a1bd4f
void      nm_config_keyfile_set_string_list(GKeyFile *         keyfile,
Packit Service a1bd4f
                                            const char *       group,
Packit Service a1bd4f
                                            const char *       key,
Packit Service a1bd4f
                                            const char *const *strv,
Packit Service a1bd4f
                                            gssize             len);
Packit Service a1bd4f
gboolean  nm_config_keyfile_has_global_dns_config(GKeyFile *keyfile, gboolean internal);
Packit Service a1bd4f
Packit Service a1bd4f
GSList *nm_config_get_match_spec(const GKeyFile *keyfile,
Packit Service a1bd4f
                                 const char *    group,
Packit Service a1bd4f
                                 const char *    key,
Packit Service a1bd4f
                                 gboolean *      out_has_key);
Packit Service a1bd4f
Packit Service a1bd4f
void _nm_config_sort_groups(char **groups, gsize ngroups);
Packit Service a1bd4f
Packit Service a1bd4f
gboolean nm_config_set_global_dns(NMConfig *self, NMGlobalDnsConfig *global_dns, GError **error);
Packit Service a1bd4f
Packit Service a1bd4f
void nm_config_set_connectivity_check_enabled(NMConfig *self, gboolean enabled);
Packit 5756e2
Packit 5756e2
/* internal defines ... */
Packit 5756e2
extern guint _nm_config_match_nm_version;
Packit 5756e2
extern char *_nm_config_match_env;
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_DEVICE_STATE_DIR "" NMRUNDIR "/devices"
Packit 5756e2
Packit Service a1bd4f
#define NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL (nm_streq("" NM_CONFIG_DEFAULT_LOGGING_AUDIT, "true"))
Packit 5756e2
Packit 5756e2
typedef enum {
Packit Service a1bd4f
    NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN   = -1,
Packit Service a1bd4f
    NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED = 0,
Packit Service a1bd4f
    NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED   = 1,
Packit 5756e2
} NMConfigDeviceStateManagedType;
Packit 5756e2
Packit 5756e2
struct _NMConfigDeviceStateData {
Packit Service a1bd4f
    int                            ifindex;
Packit Service a1bd4f
    NMConfigDeviceStateManagedType managed;
Packit 5756e2
Packit Service a1bd4f
    /* a value of zero means that no metric is set. */
Packit Service a1bd4f
    guint32 route_metric_default_aspired;
Packit Service a1bd4f
    guint32 route_metric_default_effective;
Packit 5756e2
Packit Service a1bd4f
    /* the UUID of the last settings-connection active
Packit Service a1bd4f
     * on the device. */
Packit Service a1bd4f
    const char *connection_uuid;
Packit 5756e2
Packit Service a1bd4f
    const char *perm_hw_addr_fake;
Packit 5756e2
Packit Service a1bd4f
    /* whether the device was nm-owned (0/1) or -1 for
Packit Service a1bd4f
     * non-software devices. */
Packit Service a1bd4f
    NMTernary nm_owned : 3;
Packit 5756e2
};
Packit 5756e2
Packit Service a1bd4f
NMConfigDeviceStateData *nm_config_device_state_load(int ifindex);
Packit Service a1bd4f
GHashTable *             nm_config_device_state_load_all(void);
Packit Service a1bd4f
gboolean                 nm_config_device_state_write(int                            ifindex,
Packit Service a1bd4f
                                                      NMConfigDeviceStateManagedType managed,
Packit Service a1bd4f
                                                      const char *                   perm_hw_addr_fake,
Packit Service a1bd4f
                                                      const char *                   connection_uuid,
Packit Service a1bd4f
                                                      NMTernary                      nm_owned,
Packit Service a1bd4f
                                                      guint32                        route_metric_default_aspired,
Packit Service a1bd4f
                                                      guint32                        route_metric_default_effective,
Packit Service a1bd4f
                                                      const char *                   next_server,
Packit Service a1bd4f
                                                      const char *                   root_path);
Packit Service a1bd4f
Packit Service a1bd4f
void nm_config_device_state_prune_stale(GHashTable *preserve_ifindexes,
Packit Service a1bd4f
                                        NMPlatform *preserve_in_platform);
Packit Service a1bd4f
Packit Service a1bd4f
const GHashTable *             nm_config_device_state_get_all(NMConfig *self);
Packit Service a1bd4f
const NMConfigDeviceStateData *nm_config_device_state_get(NMConfig *self, int ifindex);
Packit Service a1bd4f
Packit Service a1bd4f
const char *const *nm_config_get_warnings(NMConfig *config);
Packit Service a1bd4f
void               nm_config_clear_warnings(NMConfig *config);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
#endif /* __NETWORKMANAGER_CONFIG_H__ */