nm-core-internal.h 33.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
Lubomir Rintel's avatar
Lubomir Rintel committed
18
 * (C) Copyright 2014 - 2018 Red Hat, Inc.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 */

#ifndef NM_CORE_NM_INTERNAL_H
#define NM_CORE_NM_INTERNAL_H

/* This header file contain functions that are provided as private API
 * by libnm-core. It will contain functions to give privileged access to
 * libnm-core. This can be useful for NetworkManager and libnm.so
 * which both are special users of libnm-core.
 * It also exposes some utility functions for reuse.
 *
 * These functions are not exported and are only available to components that link
 * statically against libnm-core. This basically means libnm-core, libnm, NetworkManager
 * and some test programs.
 **/
34 35 36
#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL)
#error Cannot use this header.
#endif
37

38 39
#include "nm-connection.h"
#include "nm-core-enum-types.h"
40 41
#include "nm-core-types-internal.h"
#include "nm-meta-setting.h"
Lubomir Rintel's avatar
Lubomir Rintel committed
42
#include "nm-setting-6lowpan.h"
43 44 45 46 47 48 49 50 51
#include "nm-setting-8021x.h"
#include "nm-setting-adsl.h"
#include "nm-setting-bluetooth.h"
#include "nm-setting-bond.h"
#include "nm-setting-bridge-port.h"
#include "nm-setting-bridge.h"
#include "nm-setting-cdma.h"
#include "nm-setting-connection.h"
#include "nm-setting-dcb.h"
52
#include "nm-setting-dummy.h"
53 54 55
#include "nm-setting-generic.h"
#include "nm-setting-gsm.h"
#include "nm-setting-infiniband.h"
56
#include "nm-setting-ip-tunnel.h"
57
#include "nm-setting-ip4-config.h"
58
#include "nm-setting-ip6-config.h"
59
#include "nm-setting-macsec.h"
60
#include "nm-setting-macvlan.h"
Beniamino Galvani's avatar
Beniamino Galvani committed
61
#include "nm-setting-match.h"
62
#include "nm-setting-olpc-mesh.h"
63
#include "nm-setting-ovs-bridge.h"
64
#include "nm-setting-ovs-interface.h"
65
#include "nm-setting-ovs-patch.h"
66
#include "nm-setting-ovs-port.h"
67 68
#include "nm-setting-ppp.h"
#include "nm-setting-pppoe.h"
69
#include "nm-setting-proxy.h"
70
#include "nm-setting-serial.h"
71
#include "nm-setting-sriov.h"
72
#include "nm-setting-tc-config.h"
73 74
#include "nm-setting-team-port.h"
#include "nm-setting-team.h"
75
#include "nm-setting-tun.h"
76 77
#include "nm-setting-vlan.h"
#include "nm-setting-vpn.h"
78
#include "nm-setting-vxlan.h"
79
#include "nm-setting-wifi-p2p.h"
80 81
#include "nm-setting-wimax.h"
#include "nm-setting-wired.h"
82
#include "nm-setting-wireguard.h"
83 84
#include "nm-setting-wireless-security.h"
#include "nm-setting-wireless.h"
Lubomir Rintel's avatar
Lubomir Rintel committed
85
#include "nm-setting-wpan.h"
86 87 88 89
#include "nm-setting.h"
#include "nm-simple-connection.h"
#include "nm-utils.h"
#include "nm-vpn-dbus-interface.h"
90
#include "nm-vpn-editor-plugin.h"
91
#include "nm-libnm-core-intern/nm-libnm-core-utils.h"
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106
/* IEEE 802.1D-1998 timer values */
#define NM_BR_MIN_HELLO_TIME    1
#define NM_BR_MAX_HELLO_TIME    10

#define NM_BR_MIN_FORWARD_DELAY 2
#define NM_BR_MAX_FORWARD_DELAY 30

#define NM_BR_MIN_MAX_AGE       6
#define NM_BR_MAX_MAX_AGE       40

/* IEEE 802.1D-1998 Table 7.4 */
#define NM_BR_MIN_AGEING_TIME   0
#define NM_BR_MAX_AGEING_TIME   1000000

107 108 109 110 111
#define NM_BR_PORT_MAX_PRIORITY 63
#define NM_BR_PORT_DEF_PRIORITY 32

#define NM_BR_PORT_MAX_PATH_COST 65535

112 113 114 115 116
/* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
 * connection can be replaced by a already-defined connection. This flag only
 * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
 * flag.
 */
117
#define NM_SETTING_COMPARE_FLAG_INFERRABLE ((NMSettingCompareFlags) 0x80000000)
118

119 120 121 122 123 124 125 126 127 128 129 130
/* NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY: this flag is used for properties
 * that automatically get re-applied on an active connection when the settings
 * connection is modified. For most properties, the applied-connection is distinct
 * from the setting-connection and changes don't propagate. Exceptions are the
 * firewall-zone and the metered property.
 */
#define NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY ((NMSettingCompareFlags) 0x40000000)

/* NM_SETTING_COMPARE_FLAG_NONE: for convenience, define a special flag NONE -- which
 * equals to numeric zero (NM_SETTING_COMPARE_FLAG_EXACT).
 */
#define NM_SETTING_COMPARE_FLAG_NONE ((NMSettingCompareFlags) 0)
131

132 133
/*****************************************************************************/

134
#define NM_SETTING_SECRET_FLAG_ALL \
135 136 137 138 139 140 141 142
	((NMSettingSecretFlags) (  NM_SETTING_SECRET_FLAG_NONE \
	                         | NM_SETTING_SECRET_FLAG_AGENT_OWNED \
	                         | NM_SETTING_SECRET_FLAG_NOT_SAVED \
	                         | NM_SETTING_SECRET_FLAG_NOT_REQUIRED))

static inline gboolean
_nm_setting_secret_flags_valid (NMSettingSecretFlags flags)
{
143
	return !NM_FLAGS_ANY (flags, ~NM_SETTING_SECRET_FLAG_ALL);
144 145 146
}

/*****************************************************************************/
147

148 149 150 151
typedef enum { /*< skip >*/
	NM_SETTING_PARSE_FLAGS_NONE                     = 0,
	NM_SETTING_PARSE_FLAGS_STRICT                   = 1LL << 0,
	NM_SETTING_PARSE_FLAGS_BEST_EFFORT              = 1LL << 1,
152
	NM_SETTING_PARSE_FLAGS_NORMALIZE                = 1LL << 2,
153 154 155 156 157 158 159 160 161 162

	_NM_SETTING_PARSE_FLAGS_LAST,
	NM_SETTING_PARSE_FLAGS_ALL                      = ((_NM_SETTING_PARSE_FLAGS_LAST - 1) << 1) - 1,
} NMSettingParseFlags;

gboolean _nm_connection_replace_settings (NMConnection *connection,
                                          GVariant *new_settings,
                                          NMSettingParseFlags parse_flags,
                                          GError **error);

163 164 165 166
gpointer _nm_connection_check_main_setting (NMConnection *connection,
                                            const char *setting_name,
                                            GError **error);

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
typedef enum {
	/* whether the connection has any secrets.
	 *
	 * @arg may be %NULL or a pointer to a gboolean for the result. The return
	 *   value of _nm_connection_aggregate() is likewise the boolean result. */
	NM_CONNECTION_AGGREGATE_ANY_SECRETS,

	/* whether the connection has any secret with flags NM_SETTING_SECRET_FLAG_NONE.
	 * Note that this only cares about the flags, not whether the secret is actually
	 * present.
	 *
	 * @arg may be %NULL or a pointer to a gboolean for the result. The return
	 *   value of _nm_connection_aggregate() is likewise the boolean result. */
	NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS,
} NMConnectionAggregateType;

gboolean _nm_connection_aggregate (NMConnection *connection,
                                   NMConnectionAggregateType type,
                                   gpointer arg);

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
/**
 * NMSettingVerifyResult:
 * @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully
 * @NM_SETTING_VERIFY_ERROR: the setting has a serious misconfiguration
 * @NM_SETTING_VERIFY_NORMALIZABLE: the setting is valid but has properties
 * that should be normalized
 * @NM_SETTING_VERIFY_NORMALIZABLE_ERROR: the setting is invalid but the
 * errors can be fixed by nm_connection_normalize().
 */
typedef enum {
	NM_SETTING_VERIFY_SUCCESS       = TRUE,
	NM_SETTING_VERIFY_ERROR         = FALSE,
	NM_SETTING_VERIFY_NORMALIZABLE  = 2,
	NM_SETTING_VERIFY_NORMALIZABLE_ERROR = 3,
} NMSettingVerifyResult;

NMSettingVerifyResult _nm_connection_verify (NMConnection *connection, GError **error);

205 206
gboolean _nm_connection_remove_setting (NMConnection *connection, GType setting_type);

207 208 209 210
NMConnection *_nm_simple_connection_new_from_dbus (GVariant      *dict,
                                                   NMSettingParseFlags parse_flags,
                                                   GError       **error);

211
NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting);
212

213 214
gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
/*****************************************************************************/

GHashTable *_nm_setting_gendata_hash (NMSetting *setting,
                                      gboolean create_if_necessary);

void _nm_setting_gendata_notify (NMSetting *setting,
                                 gboolean keys_changed);

guint _nm_setting_gendata_get_all (NMSetting *setting,
                                   const char *const**out_names,
                                   GVariant *const**out_values);

gboolean _nm_setting_gendata_reset_from_hash (NMSetting *setting,
                                              GHashTable *new);

void _nm_setting_gendata_to_gvalue (NMSetting *setting,
                                    GValue *value);

GVariant *nm_setting_gendata_get (NMSetting *setting,
                                  const char *name);

const char *const*nm_setting_gendata_get_all_names (NMSetting *setting,
                                                    guint *out_len);

GVariant *const*nm_setting_gendata_get_all_values (NMSetting *setting);

/*****************************************************************************/

243 244 245 246 247
guint nm_setting_ethtool_init_features (NMSettingEthtool *setting,
                                        NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */);

/*****************************************************************************/

248 249 250 251
#define NM_UTILS_HWADDR_LEN_MAX_STR (NM_UTILS_HWADDR_LEN_MAX * 3)

guint8 *_nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize buffer_length, gsize *out_length);
const char *nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_case, char *buf, gsize buf_len);
252

253 254
gboolean nm_utils_is_valid_iface_name_utf8safe (const char *utf8safe_name);

255 256
GSList *    _nm_utils_hash_values_to_slist (GHashTable *hash);

257 258
GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);

259 260
typedef gpointer (*NMUtilsCopyFunc) (gpointer);

261 262
const char **_nm_ip_address_get_attribute_names (const NMIPAddress *addr, gboolean sorted, guint *out_length);

263
gboolean _nm_ip_route_attribute_validate_all (const NMIPRoute *route);
264 265
const char **_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length);
GHashTable *_nm_ip_route_get_attributes_direct (NMIPRoute *route);
266

267
NMSriovVF *_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, gboolean ignore_unknown, GError **error);
268 269
gboolean _nm_sriov_vf_attribute_validate_all (const NMSriovVF *vf, GError **error);

270 271 272 273 274
GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
                                 NMUtilsCopyFunc copy_func,
                                 GDestroyNotify free_func);
GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);

275
gssize _nm_utils_ptrarray_find_first (gconstpointer *list, gssize len, gconstpointer needle);
276

277 278
GSList *    _nm_utils_strv_to_slist (char **strv, gboolean deep_copy);
char **     _nm_utils_slist_to_strv (GSList *slist, gboolean deep_copy);
279 280 281 282

GPtrArray * _nm_utils_strv_to_ptrarray (char **strv);
char **     _nm_utils_ptrarray_to_strv (GPtrArray *ptrarray);

283 284 285 286 287 288 289
gboolean _nm_utils_check_file (const char *filename,
                               gint64 check_owner,
                               NMUtilsCheckFilePredicate check_file,
                               gpointer user_data,
                               struct stat *out_st,
                               GError **error);

290 291 292 293 294
gboolean _nm_utils_check_module_file (const char *name,
                                      int check_owner,
                                      NMUtilsCheckFilePredicate check_file,
                                      gpointer user_data,
                                      GError **error);
295

296 297 298 299 300 301 302 303 304 305 306 307
/*****************************************************************************/

typedef struct _NMUuid {
	guchar uuid[16];
} NMUuid;

NMUuid *_nm_utils_uuid_parse (const char *str,
                              NMUuid *uuid);
char *_nm_utils_uuid_unparse (const NMUuid *uuid,
                              char *out_str /*[37]*/);
NMUuid *_nm_utils_uuid_generate_random (NMUuid *out_uuid);

308 309
gboolean nm_utils_uuid_is_null (const NMUuid *uuid);

310
#define NM_UTILS_UUID_TYPE_LEGACY            0
311 312
#define NM_UTILS_UUID_TYPE_VERSION3          3
#define NM_UTILS_UUID_TYPE_VERSION5          5
313

314 315
NMUuid *nm_utils_uuid_generate_from_string_bin (NMUuid *uuid, const char *s, gssize slen, int uuid_type, gpointer type_args);

316 317
char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_type, gpointer type_args);

318
/* arbitrarily chosen namespace UUID for _nm_utils_uuid_generate_from_strings() */
319 320 321 322
#define NM_UTILS_UUID_NS "b425e9fb-7598-44b4-9e3b-5a2e3aaa4905"

char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED;

323 324 325 326 327 328 329 330
char *nm_utils_uuid_generate_buf_ (char *buf);
#define nm_utils_uuid_generate_buf(buf) \
	({ \
		G_STATIC_ASSERT (sizeof (buf) == G_N_ELEMENTS (buf) && sizeof (buf) >= 37); \
		nm_utils_uuid_generate_buf_ (buf); \
	})
#define nm_utils_uuid_generate_a() (nm_utils_uuid_generate_buf_ (g_alloca (37)))

331 332
void _nm_dbus_errors_init (void);

333 334
extern gboolean _nm_utils_is_manager_process;

335 336 337 338
gboolean _nm_dbus_typecheck_response (GVariant *response,
                                      const GVariantType *reply_type,
                                      GError **error);

339 340 341 342 343 344 345 346 347 348
gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
                                     const char *signal_name,
                                     const GVariantType *signature,
                                     GCallback c_handler,
                                     gpointer data,
                                     GClosureNotify destroy_data,
                                     GConnectFlags connect_flags);
#define _nm_dbus_signal_connect(proxy, name, signature, handler, data) \
	_nm_dbus_signal_connect_data (proxy, name, signature, handler, data, NULL, (GConnectFlags) 0)

349 350 351 352 353 354
GVariant *_nm_dbus_proxy_call_finish (GDBusProxy           *proxy,
                                      GAsyncResult         *res,
                                      const GVariantType   *reply_type,
                                      GError              **error);

GVariant *_nm_dbus_proxy_call_sync   (GDBusProxy           *proxy,
355
                                      const char           *method_name,
356 357 358
                                      GVariant             *parameters,
                                      const GVariantType   *reply_type,
                                      GDBusCallFlags        flags,
359
                                      int                   timeout_msec,
360 361 362
                                      GCancellable         *cancellable,
                                      GError              **error);

363 364 365 366 367
GVariant * _nm_dbus_connection_call_finish (GDBusConnection *dbus_connection,
                                            GAsyncResult *result,
                                            const GVariantType *reply_type,
                                            GError **error);

368 369
gboolean _nm_dbus_error_has_name (GError     *error,
                                  const char *dbus_error_name);
370

371
/*****************************************************************************/
372

373 374 375 376 377 378 379
char *_nm_utils_ssid_to_string_arr (const guint8 *ssid, gsize len);
char *_nm_utils_ssid_to_string (GBytes *ssid);
char *_nm_utils_ssid_to_utf8 (GBytes *ssid);
gboolean _nm_utils_is_empty_ssid (GBytes *ssid);

/*****************************************************************************/

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
gboolean _nm_vpn_plugin_info_check_file (const char *filename,
                                         gboolean check_absolute,
                                         gboolean do_validate_filename,
                                         gint64 check_owner,
                                         NMUtilsCheckFilePredicate check_file,
                                         gpointer user_data,
                                         GError **error);

const char *_nm_vpn_plugin_info_get_default_dir_etc (void);
const char *_nm_vpn_plugin_info_get_default_dir_lib (void);
const char *_nm_vpn_plugin_info_get_default_dir_user (void);

GSList *_nm_vpn_plugin_info_list_load_dir (const char *dirname,
                                           gboolean do_validate_filename,
                                           gint64 check_owner,
                                           NMUtilsCheckFilePredicate check_file,
                                           gpointer user_data);

398
/*****************************************************************************/
399

400 401 402 403
typedef struct {
	const char *name;
	gboolean numeric;
	gboolean ipv6_only;
404
} NMUtilsDNSOptionDesc;
405

406
extern const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[];
407 408 409

gboolean    _nm_utils_dns_option_validate (const char *option, char **out_name,
                                           long *out_value, gboolean ipv6,
410
                                           const NMUtilsDNSOptionDesc *option_descs);
411
gssize      _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option);
412

413
/*****************************************************************************/
414

415 416 417 418 419 420 421 422
typedef struct _NMUtilsStrStrDictKey NMUtilsStrStrDictKey;
guint                 _nm_utils_strstrdictkey_hash   (gconstpointer a);
gboolean              _nm_utils_strstrdictkey_equal  (gconstpointer a, gconstpointer b);
NMUtilsStrStrDictKey *_nm_utils_strstrdictkey_create (const char *v1, const char *v2);

#define _nm_utils_strstrdictkey_static(v1, v2) \
    ( (NMUtilsStrStrDictKey *) ("\03" v1 "\0" v2 "") )

423
/*****************************************************************************/
424

425 426 427 428 429 430 431 432 433
gboolean _nm_setting_vlan_set_priorities (NMSettingVlan *setting,
                                          NMVlanPriorityMap map,
                                          const NMVlanQosMapping *qos_map,
                                          guint n_qos_map);
void     _nm_setting_vlan_get_priorities (NMSettingVlan *setting,
                                          NMVlanPriorityMap map,
                                          NMVlanQosMapping **out_qos_map,
                                          guint *out_n_qos_map);

434
/*****************************************************************************/
435

436 437 438 439 440 441 442 443
struct ether_addr;

gboolean _nm_utils_generate_mac_address_mask_parse (const char *value,
                                                    struct ether_addr *out_mask,
                                                    struct ether_addr **out_ouis,
                                                    gsize *out_ouis_len,
                                                    GError **error);

444
/*****************************************************************************/
445 446 447 448 449

NMSettingIPConfig *nm_connection_get_setting_ip_config (NMConnection *connection,
                                                        int addr_family);

/*****************************************************************************/
450

451 452 453 454 455
typedef enum {
	NM_BOND_OPTION_TYPE_INT,
	NM_BOND_OPTION_TYPE_STRING,
	NM_BOND_OPTION_TYPE_BOTH,
	NM_BOND_OPTION_TYPE_IP,
456
	NM_BOND_OPTION_TYPE_MAC,
457 458 459 460 461 462
	NM_BOND_OPTION_TYPE_IFNAME,
} NMBondOptionType;

NMBondOptionType
_nm_setting_bond_get_option_type (NMSettingBond *setting, const char *name);

463
/*****************************************************************************/
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480

/* nm_connection_get_uuid() asserts against NULL, which is the right thing to
 * do in order to catch bugs. However, sometimes that behavior is inconvenient.
 * Just try or return NULL. */

static inline const char *
_nm_connection_get_id (NMConnection *connection)
{
	return connection ? nm_connection_get_id (connection) : NULL;
}

static inline const char *
_nm_connection_get_uuid (NMConnection *connection)
{
	return connection ? nm_connection_get_uuid (connection) : NULL;
}

481 482
NMConnectionMultiConnect _nm_connection_get_multi_connect (NMConnection *connection);

483
/*****************************************************************************/
484

485 486 487 488 489 490 491 492 493 494 495 496 497 498
typedef enum {
	NM_BOND_MODE_UNKNOWN = 0,
	NM_BOND_MODE_ROUNDROBIN,
	NM_BOND_MODE_ACTIVEBACKUP,
	NM_BOND_MODE_XOR,
	NM_BOND_MODE_BROADCAST,
	NM_BOND_MODE_8023AD,
	NM_BOND_MODE_TLB,
	NM_BOND_MODE_ALB,
} NMBondMode;

NMBondMode _nm_setting_bond_mode_from_string (const char *str);
gboolean _nm_setting_bond_option_supported (const char *option, NMBondMode mode);

499
/*****************************************************************************/
500

501 502 503 504
NMSettingBluetooth *_nm_connection_get_setting_bluetooth_for_nap (NMConnection *connection);

/*****************************************************************************/

505 506
const char *nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst);

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
static inline char *
nm_utils_inet4_ntop_dup (in_addr_t addr)
{
	char buf[NM_UTILS_INET_ADDRSTRLEN];

	return g_strdup (nm_utils_inet4_ntop (addr, buf));
}

static inline char *
nm_utils_inet6_ntop_dup (const struct in6_addr *addr)
{
	char buf[NM_UTILS_INET_ADDRSTRLEN];

	return g_strdup (nm_utils_inet6_ntop (addr, buf));
}

static inline char *
524
nm_utils_inet_ntop_dup (int addr_family, gconstpointer addr)
525 526 527 528 529 530
{
	char buf[NM_UTILS_INET_ADDRSTRLEN];

	return g_strdup (nm_utils_inet_ntop (addr_family, addr, buf));
}

531 532
gboolean _nm_utils_inet6_is_token (const struct in6_addr *in6addr);

533
/*****************************************************************************/
534

535 536
gboolean _nm_team_link_watchers_equal (GPtrArray *a, GPtrArray *b, gboolean ignore_order);

537 538 539 540 541 542 543 544 545 546 547 548
gboolean _nm_utils_team_config_equal (const char *conf1, const char *conf2, gboolean port);
GValue *_nm_utils_team_config_get (const char *conf,
                                   const char *key,
                                   const char *key2,
                                   const char *key3,
                                   gboolean port_config);

gboolean _nm_utils_team_config_set (char **conf,
                                    const char *key,
                                    const char *key2,
                                    const char *key3,
                                    const GValue *value);
549

550 551
/*****************************************************************************/

552 553 554 555 556 557 558
guint32 _nm_utils_parse_tc_handle                (const char *str,
                                                  GError **error);
void _nm_utils_string_append_tc_parent           (GString *string,
                                                  const char *prefix,
                                                  guint32 parent);
void _nm_utils_string_append_tc_qdisc_rest       (GString *string,
                                                  NMTCQdisc *qdisc);
559 560 561
gboolean _nm_utils_string_append_tc_tfilter_rest (GString *string,
                                                  NMTCTfilter *tfilter,
                                                  GError **error);
562 563 564

/*****************************************************************************/

565 566 567 568 569 570 571 572 573 574 575 576 577
static inline gboolean
_nm_connection_type_is_master (const char *type)
{
	return (NM_IN_STRSET (type,
	                      NM_SETTING_BOND_SETTING_NAME,
	                      NM_SETTING_BRIDGE_SETTING_NAME,
	                      NM_SETTING_TEAM_SETTING_NAME,
	                      NM_SETTING_OVS_BRIDGE_SETTING_NAME,
	                      NM_SETTING_OVS_PORT_SETTING_NAME));
}

/*****************************************************************************/

578 579 580
gboolean _nm_utils_dhcp_duid_valid (const char *duid, GBytes **out_duid_bin);

/*****************************************************************************/
581 582

gboolean _nm_setting_sriov_sort_vfs (NMSettingSriov *setting);
583
gboolean _nm_setting_bridge_port_sort_vlans (NMSettingBridgePort *setting);
584
gboolean _nm_setting_bridge_sort_vlans (NMSettingBridge *setting);
585

586 587
/*****************************************************************************/

588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
typedef struct _NMSockAddrEndpoint NMSockAddrEndpoint;

NMSockAddrEndpoint *nm_sock_addr_endpoint_new (const char *endpoint);

NMSockAddrEndpoint *nm_sock_addr_endpoint_ref (NMSockAddrEndpoint *self);
void nm_sock_addr_endpoint_unref (NMSockAddrEndpoint *self);

const char *nm_sock_addr_endpoint_get_endpoint (NMSockAddrEndpoint *self);
const char *nm_sock_addr_endpoint_get_host (NMSockAddrEndpoint *self);
gint32 nm_sock_addr_endpoint_get_port (NMSockAddrEndpoint *self);

gboolean nm_sock_addr_endpoint_get_fixed_sockaddr (NMSockAddrEndpoint *self,
                                                   gpointer sockaddr);

#define nm_auto_unref_sockaddrendpoint nm_auto(_nm_auto_unref_sockaddrendpoint)
603
NM_AUTO_DEFINE_FCN0 (NMSockAddrEndpoint *, _nm_auto_unref_sockaddrendpoint, nm_sock_addr_endpoint_unref)
604 605 606

/*****************************************************************************/

607 608 609 610 611 612 613 614 615
NMSockAddrEndpoint *_nm_wireguard_peer_get_endpoint (const NMWireGuardPeer *self);
void _nm_wireguard_peer_set_endpoint (NMWireGuardPeer *self,
                                      NMSockAddrEndpoint *endpoint);

void _nm_wireguard_peer_set_public_key_bin (NMWireGuardPeer *self,
                                            const guint8 public_key[static NM_WIREGUARD_PUBLIC_KEY_LEN]);

/*****************************************************************************/

Thomas Haller's avatar
Thomas Haller committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
const NMIPAddr *nm_ip_routing_rule_get_from_bin (const NMIPRoutingRule *self);
void nm_ip_routing_rule_set_from_bin (NMIPRoutingRule *self,
                                      gconstpointer from,
                                      guint8 len);

const NMIPAddr *nm_ip_routing_rule_get_to_bin (const NMIPRoutingRule *self);
void nm_ip_routing_rule_set_to_bin (NMIPRoutingRule *self,
                                    gconstpointer to,
                                    guint8 len);

gboolean nm_ip_routing_rule_get_xifname_bin (const NMIPRoutingRule *self,
                                             gboolean iif /* or else oif */,
                                             char out_xifname[static 16]);

#define NM_IP_ROUTING_RULE_ATTR_ACTION      "action"
#define NM_IP_ROUTING_RULE_ATTR_DPORT_END   "dport-end"
#define NM_IP_ROUTING_RULE_ATTR_DPORT_START "dport-start"
#define NM_IP_ROUTING_RULE_ATTR_FAMILY      "family"
#define NM_IP_ROUTING_RULE_ATTR_FROM        "from"
#define NM_IP_ROUTING_RULE_ATTR_FROM_LEN    "from-len"
#define NM_IP_ROUTING_RULE_ATTR_FWMARK      "fwmark"
#define NM_IP_ROUTING_RULE_ATTR_FWMASK      "fwmask"
#define NM_IP_ROUTING_RULE_ATTR_IIFNAME     "iifname"
#define NM_IP_ROUTING_RULE_ATTR_INVERT      "invert"
#define NM_IP_ROUTING_RULE_ATTR_IPPROTO     "ipproto"
#define NM_IP_ROUTING_RULE_ATTR_OIFNAME     "oifname"
#define NM_IP_ROUTING_RULE_ATTR_PRIORITY    "priority"
#define NM_IP_ROUTING_RULE_ATTR_SPORT_END   "sport-end"
#define NM_IP_ROUTING_RULE_ATTR_SPORT_START "sport-start"
#define NM_IP_ROUTING_RULE_ATTR_TABLE       "table"
#define NM_IP_ROUTING_RULE_ATTR_TO          "to"
#define NM_IP_ROUTING_RULE_ATTR_TOS         "tos"
#define NM_IP_ROUTING_RULE_ATTR_TO_LEN      "to-len"

NMIPRoutingRule *nm_ip_routing_rule_from_dbus (GVariant *variant,
                                               gboolean strict,
                                               GError **error);
GVariant *nm_ip_routing_rule_to_dbus (const NMIPRoutingRule *self);

/*****************************************************************************/

657 658
typedef struct _NMSettInfoSetting  NMSettInfoSetting;
typedef struct _NMSettInfoProperty NMSettInfoProperty;
659

660 661
typedef GVariant *(*NMSettingPropertyGetFunc)           (NMSetting     *setting,
                                                         const char    *property);
662 663
typedef GVariant *(*NMSettingPropertySynthFunc)         (const NMSettInfoSetting *sett_info,
                                                         guint property_idx,
664
                                                         NMConnection  *connection,
665 666
                                                         NMSetting     *setting,
                                                         NMConnectionSerializationFlags flags);
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
typedef gboolean  (*NMSettingPropertySetFunc)           (NMSetting     *setting,
                                                         GVariant      *connection_dict,
                                                         const char    *property,
                                                         GVariant      *value,
                                                         NMSettingParseFlags parse_flags,
                                                         GError       **error);
typedef gboolean  (*NMSettingPropertyNotSetFunc)        (NMSetting     *setting,
                                                         GVariant      *connection_dict,
                                                         const char    *property,
                                                         NMSettingParseFlags parse_flags,
                                                         GError       **error);
typedef GVariant *(*NMSettingPropertyTransformToFunc)   (const GValue *from);
typedef void      (*NMSettingPropertyTransformFromFunc) (GVariant *from,
                                                          GValue *to);

682
struct _NMSettInfoProperty {
683 684 685 686 687 688 689 690 691 692 693
	const char *name;
	GParamSpec *param_spec;
	const GVariantType *dbus_type;

	NMSettingPropertyGetFunc           get_func;
	NMSettingPropertySynthFunc         synth_func;
	NMSettingPropertySetFunc           set_func;
	NMSettingPropertyNotSetFunc        not_set_func;

	NMSettingPropertyTransformToFunc   to_dbus;
	NMSettingPropertyTransformFromFunc from_dbus;
694
};
695 696

typedef struct {
697 698 699 700
	const GVariantType *(*get_variant_type) (const struct _NMSettInfoSetting *sett_info,
	                                         const char *name,
	                                         GError **error);
} NMSettInfoSettGendata;
701 702

typedef struct {
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
	/* if set, then this setting class has no own fields. Instead, its
	 * data is entirely based on gendata. Meaning: it tracks all data
	 * as native GVariants.
	 * It might have some GObject properties, but these are merely accessors
	 * to the underlying gendata.
	 *
	 * Note, that at the moment there are few hooks, to customize the behavior
	 * of the setting further. They are currently unneeded. This is desired,
	 * but could be added when there is a good reason.
	 *
	 * However, a few hooks there are... see NMSettInfoSettGendata. */
	const NMSettInfoSettGendata *gendata_info;
} NMSettInfoSettDetail;

struct _NMSettInfoSetting {
718
	NMSettingClass *setting_class;
719 720

	/* the properties, sorted by property name. */
721
	const NMSettInfoProperty *property_infos;
722 723 724 725 726 727 728 729 730 731 732 733 734

	/* the @property_infos list is sorted by property name. For some uses we need
	 * a different sort order. If @property_infos_sorted is set, this is the order
	 * instead. It is used for:
	 *
	 *   - nm_setting_enumerate_values()
	 *   - keyfile writer adding keys to the group.
	 *
	 * Note that currently only NMSettingConnection implements here a sort order
	 * that differs from alphabetical sort of the property names.
	 */
	const NMSettInfoProperty *const*property_infos_sorted;

735 736
	guint property_infos_len;
	NMSettInfoSettDetail detail;
737
};
738

739 740 741 742 743 744 745 746 747 748 749 750 751
static inline const NMSettInfoProperty *
_nm_sett_info_property_info_get_sorted (const NMSettInfoSetting *sett_info,
                                        guint idx)
{
	nm_assert (sett_info);
	nm_assert (idx < sett_info->property_infos_len);
	nm_assert (!sett_info->property_infos_sorted || sett_info->property_infos_sorted[idx]);

	return   sett_info->property_infos_sorted
	       ? sett_info->property_infos_sorted[idx]
	       : &sett_info->property_infos[idx];
}

752 753 754
const NMSettInfoProperty *_nm_sett_info_setting_get_property_info (const NMSettInfoSetting *sett_info,
                                                                   const char *property_name);

755
const NMSettInfoSetting *_nm_setting_class_get_sett_info (NMSettingClass *setting_class);
756

757 758 759 760 761 762 763
static inline const NMSettInfoProperty *
_nm_setting_class_get_property_info (NMSettingClass *setting_class,
                                     const char *property_name)
{
	return _nm_sett_info_setting_get_property_info (_nm_setting_class_get_sett_info (setting_class),
	                                                property_name);
}
764 765 766

/*****************************************************************************/

767 768 769 770 771 772 773 774 775
NMSetting8021xCKScheme _nm_setting_802_1x_cert_get_scheme (GBytes *bytes, GError **error);

GBytes *_nm_setting_802_1x_cert_value_to_bytes (NMSetting8021xCKScheme scheme,
                                                const guint8 *val_bin,
                                                gssize val_len,
                                                GError **error);

/*****************************************************************************/

776 777 778
GVariant *_nm_connection_for_each_secret (NMConnection *self,
                                          GVariant *secrets,
                                          gboolean remove_non_secrets,
779
                                          _NMConnectionForEachSecretFunc callback,
780 781 782 783 784 785 786 787 788 789 790 791
                                          gpointer callback_data);

typedef gboolean (*NMConnectionFindSecretFunc) (NMSettingSecretFlags flags,
                                                gpointer user_data);

gboolean _nm_connection_find_secret (NMConnection *self,
                                     GVariant *secrets,
                                     NMConnectionFindSecretFunc callback,
                                     gpointer callback_data);

/*****************************************************************************/

792 793 794
gboolean nm_utils_base64secret_normalize (const char *base64_key,
                                          gsize required_key_len,
                                          char **out_base64_key_norm);
795 796 797

/*****************************************************************************/

798 799 800 801
void _nm_bridge_vlan_str_append_rest (const NMBridgeVlan *vlan,
                                      GString *string,
                                      gboolean leading_space);

802
#endif