nm-config.h 11.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright (C) 2011 Red Hat, Inc.
19
 * Copyright (C) 2013 Thomas Bechtold <thomasbechtold@jpberlin.de>
20 21
 */

22 23
#ifndef __NETWORKMANAGER_CONFIG_H__
#define __NETWORKMANAGER_CONFIG_H__
24

25
#include "nm-config-data.h"
26

27 28 29 30 31 32 33
#define NM_TYPE_CONFIG            (nm_config_get_type ())
#define NM_CONFIG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONFIG, NMConfig))
#define NM_CONFIG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  NM_TYPE_CONFIG, NMConfigClass))
#define NM_IS_CONFIG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONFIG))
#define NM_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  NM_TYPE_CONFIG))
#define NM_CONFIG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  NM_TYPE_CONFIG, NMConfigClass))

34 35
/* Properties */
#define NM_CONFIG_CMD_LINE_OPTIONS                  "cmd-line-options"
36
#define NM_CONFIG_ATOMIC_SECTION_PREFIXES           "atomic-section-prefixes"
37

38 39 40
/* Signals */
#define NM_CONFIG_SIGNAL_CONFIG_CHANGED             "config-changed"

41
#define NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL 300
42
#define NM_CONFIG_DEFAULT_CONNECTIVITY_RESPONSE "NetworkManager is online" /* NOT LOCALIZED */
43

44 45
#define NM_CONFIG_KEYFILE_LIST_SEPARATOR ','

46
#define NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN                ".intern."
47
#define NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION            "connection"
48
#define NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE                "device"
49
#define NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN     "global-dns-domain-"
50
#define NM_CONFIG_KEYFILE_GROUPPREFIX_TEST_APPEND_STRINGLIST ".test-append-stringlist"
51 52 53 54

#define NM_CONFIG_KEYFILE_GROUP_MAIN                        "main"
#define NM_CONFIG_KEYFILE_GROUP_LOGGING                     "logging"
#define NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY                "connectivity"
55
#define NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS                  "global-dns"
56
#define NM_CONFIG_KEYFILE_GROUP_CONFIG                      ".config"
57 58 59 60

#define NM_CONFIG_KEYFILE_GROUP_KEYFILE                     "keyfile"
#define NM_CONFIG_KEYFILE_GROUP_IFUPDOWN                    "ifupdown"

61
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT              "auth-polkit"
62
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTOCONNECT_RETRIES_DEFAULT "autoconnect-retries-default"
63
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP                     "dhcp"
64
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG                    "debug"
65
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE            "hostname-mode"
66
#define NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER             "slaves-order"
67
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND               "backend"
68
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE                 "enable"
69
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS            ".was"
70
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH                  "path"
71 72
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES     "unmanaged-devices"
#define NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME              "hostname"
73 74 75
#define NM_CONFIG_KEYFILE_KEY_IFNET_AUTO_REFRESH            "auto_refresh"
#define NM_CONFIG_KEYFILE_KEY_IFNET_MANAGED                 "managed"
#define NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED              "managed"
Beniamino Galvani's avatar
Beniamino Galvani committed
76
#define NM_CONFIG_KEYFILE_KEY_AUDIT                         "audit"
77

78
#define NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED                "managed"
79
#define NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER         "ignore-carrier"
80
#define NM_CONFIG_KEYFILE_KEY_DEVICE_SRIOV_NUM_VFS          "sriov-num-vfs"
81
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND           "wifi.backend"
82
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_RAND_MAC_ADDRESS "wifi.scan-rand-mac-address"
83
#define NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT   "carrier-wait-timeout"
84

85 86 87
#define NM_CONFIG_KEYFILE_KEYPREFIX_WAS                     ".was."
#define NM_CONFIG_KEYFILE_KEYPREFIX_SET                     ".set."

88 89 90 91 92
#define NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS \
	NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS
#define NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_GLOBAL_DNS_DOMAIN \
	NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN

93 94
typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions;

95
typedef enum {
96
	NM_CONFIG_STATE_PROPERTY_NONE,
97 98

	/* 1 set-argument: (gboolean enabled) */
99 100 101
	NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED,
	NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED,
	NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED,
102 103 104 105 106 107 108 109 110
} NMConfigRunStatePropertyType;

typedef struct {
	bool net_enabled;
	bool wifi_enabled;
	bool wwan_enabled;

	/* Whether the runstate is modified and not saved to disk. */
	bool dirty;
111
} NMConfigState;
112

113
typedef struct _NMConfigClass NMConfigClass;
114 115

GType nm_config_get_type (void);
116

117
NMConfig *nm_config_get (void);
118

119
const char *nm_config_change_flags_to_string (NMConfigChangeFlags flags, char *buf, gsize len);
120

121 122
NMConfigData *nm_config_get_data (NMConfig *config);
NMConfigData *nm_config_get_data_orig (NMConfig *config);
123 124 125 126

#define NM_CONFIG_GET_DATA      (nm_config_get_data (nm_config_get ()))
#define NM_CONFIG_GET_DATA_ORIG (nm_config_get_data_orig (nm_config_get ()))

127
gboolean nm_config_get_monitor_connection_files (NMConfig *config);
128 129
const char *nm_config_get_log_level (NMConfig *config);
const char *nm_config_get_log_domains (NMConfig *config);
130
gboolean nm_config_get_configure_and_quit (NMConfig *config);
131
gboolean nm_config_get_is_debug (NMConfig *config);
132

133 134
gboolean nm_config_get_first_start (NMConfig *config);

135 136 137 138 139
void nm_config_set_values (NMConfig *self,
                           GKeyFile *keyfile_intern_new,
                           gboolean allow_write,
                           gboolean force_rewrite);

140
/* for main.c only */
141
NMConfigCmdLineOptions *nm_config_cmd_line_options_new (gboolean first_start);
142 143 144 145
void                    nm_config_cmd_line_options_free (NMConfigCmdLineOptions *cli);
void                    nm_config_cmd_line_options_add_to_entries (NMConfigCmdLineOptions *cli,
                                                                   GOptionContext *opt_ctx);

146 147 148
gboolean nm_config_get_no_auto_default_for_device (NMConfig *config, NMDevice *device);
void nm_config_set_no_auto_default_for_device  (NMConfig *config, NMDevice *device);

149 150
NMConfig *nm_config_new (const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error);
NMConfig *nm_config_setup (const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error);
151
void nm_config_reload (NMConfig *config, NMConfigChangeFlags reload_flags);
152

153
const NMConfigState *nm_config_state_get (NMConfig *config);
154

155 156 157 158 159 160
void _nm_config_state_set (NMConfig *config,
                           gboolean allow_persist,
                           gboolean force_persist,
                           ...);
#define nm_config_state_set(config, allow_persist, force_persist, ...) \
    _nm_config_state_set (config, allow_persist, force_persist, ##__VA_ARGS__, 0)
161

162
int nm_config_parse_boolean (const char *str, int default_value);
163

164
GKeyFile *nm_config_create_keyfile (void);
165
int nm_config_keyfile_get_boolean (const GKeyFile *keyfile,
166 167
                                    const char *section,
                                    const char *key,
168
                                    int default_value);
169 170 171 172 173 174 175
gint64 nm_config_keyfile_get_int64 (const GKeyFile *keyfile,
                                    const char *section,
                                    const char *key,
                                    guint base,
                                    gint64 min,
                                    gint64 max,
                                    gint64 fallback);
176
char *nm_config_keyfile_get_value (const GKeyFile *keyfile,
177 178 179
                                   const char *section,
                                   const char *key,
                                   NMConfigGetValueFlags flags);
180 181
void nm_config_keyfile_set_string_list (GKeyFile *keyfile,
                                        const char *group,
182
                                        const char *key,
183 184
                                        const char *const* strv,
                                        gssize len);
185 186
gboolean nm_config_keyfile_has_global_dns_config (GKeyFile *keyfile, gboolean internal);

187
GSList *nm_config_get_match_spec (const GKeyFile *keyfile, const char *group, const char *key, gboolean *out_has_key);
188

189 190
void _nm_config_sort_groups (char **groups, gsize ngroups);

191 192
gboolean nm_config_set_global_dns (NMConfig *self, NMGlobalDnsConfig *global_dns, GError **error);

193 194
void nm_config_set_connectivity_check_enabled (NMConfig *self, gboolean enabled);

195 196 197 198
/* internal defines ... */
extern guint _nm_config_match_nm_version;
extern char *_nm_config_match_env;

199 200 201
/*****************************************************************************/

#define NM_CONFIG_DEVICE_STATE_DIR ""NMRUNDIR"/devices"
202

203
#define NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT_BOOL     (nm_streq (""NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT, "true"))
204
#define NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL        (nm_streq (""NM_CONFIG_DEFAULT_LOGGING_AUDIT, "true"))
205

206 207 208 209 210 211
typedef enum {
	NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN   = -1,
	NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED = 0,
	NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED   = 1,
} NMConfigDeviceStateManagedType;

212
struct _NMConfigDeviceStateData {
213 214 215
	int ifindex;
	NMConfigDeviceStateManagedType managed;

216
	/* a value of zero means that no metric is set. */
217 218
	guint32 route_metric_default_aspired;
	guint32 route_metric_default_effective;
219

220 221 222
	/* the UUID of the last settings-connection active
	 * on the device. */
	const char *connection_uuid;
223 224

	const char *perm_hw_addr_fake;
225 226 227

	/* whether the device was nm-owned (0/1) or -1 for
	 * non-software devices. */
228
	int nm_owned:3;
229
};
230

231
NMConfigDeviceStateData *nm_config_device_state_load (int ifindex);
232
GHashTable *nm_config_device_state_load_all (void);
233
gboolean nm_config_device_state_write (int ifindex,
234
                                       NMConfigDeviceStateManagedType managed,
235
                                       const char *perm_hw_addr_fake,
236
                                       const char *connection_uuid,
237
                                       int nm_owned,
238 239
                                       guint32 route_metric_default_aspired,
                                       guint32 route_metric_default_effective);
240

241
void nm_config_device_state_prune_unseen (GHashTable *seen_ifindexes);
242

243 244 245 246
const GHashTable *nm_config_device_state_get_all (NMConfig *self);
const NMConfigDeviceStateData *nm_config_device_state_get (NMConfig *self,
                                                           int ifindex);

247 248
/*****************************************************************************/

249
#endif /* __NETWORKMANAGER_CONFIG_H__ */