1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2007 - 2018 Red Hat, Inc.
4 * Copyright (C) 2007 - 2008 Novell, Inc.
5 */
6
7#ifndef __NM_CONNECTION_H__
8#define __NM_CONNECTION_H__
9
10#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION)
11#error "Only <NetworkManager.h> can be included directly."
12#endif
13
14#include "nm-core-types.h"
15#include "nm-setting.h"
16
17G_BEGIN_DECLS
18
19#define NM_TYPE_CONNECTION (nm_connection_get_type())
20#define NM_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_CONNECTION, NMConnection))
21#define NM_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_CONNECTION))
22#define NM_CONNECTION_GET_INTERFACE(obj) \
23 (G_TYPE_INSTANCE_GET_INTERFACE((obj), NM_TYPE_CONNECTION, NMConnectionClass))
24
25/* Signals */
26#define NM_CONNECTION_SECRETS_UPDATED "secrets-updated"
27#define NM_CONNECTION_SECRETS_CLEARED "secrets-cleared"
28#define NM_CONNECTION_CHANGED "changed"
29
30/*
31 * NM_CONNECTION_NORMALIZE_PARAM_IP4_CONFIG_METHOD: overwrite the ip4 method
32 * when normalizing ip4 configuration. This only takes effect, if the profile
33 * has no IPv4 settings and new settings are to be added. If omitted, this
34 * defaults depends on the profile type but usually it is "auto".
35 *
36 * Since: 1.34
37 */
38#define NM_CONNECTION_NORMALIZE_PARAM_IP4_CONFIG_METHOD "ip4-config-method"
39
40/*
41 * NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD: overwrite the ip6 method
42 * when normalizing ip6 configuration. This only takes effect, if the profile
43 * has no IPv6 settings and new settings are to be added. If omitted, this
44 * defaults depends on the profile type but usually it is "auto".
45 */
46#define NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD "ip6-config-method"
47
48/**
49 * NMConnection:
50 *
51 * NMConnection is the interface implemented by #NMRemoteConnection on the
52 * client side, and #NMSettingsConnection on the daemon side.
53 */
54
55/**
56 * NMConnectionInterface:
57 * @parent: the parent interface struct
58 * @secrets_updated: emitted when the connection's secrets are updated
59 * @secrets_cleared: emitted when the connection's secrets are cleared
60 * @changed: emitted when any change to the connection's settings occurs
61 */
62typedef struct {
63 GTypeInterface parent;
64
65 /* Signals */
66 void (*secrets_updated)(NMConnection *connection, const char *setting);
67 void (*secrets_cleared)(NMConnection *connection);
68 void (*changed)(NMConnection *connection);
69
70} NMConnectionInterface;
71
72GType nm_connection_get_type(void);
73
74void nm_connection_add_setting(NMConnection *connection, NMSetting *setting);
75
76void nm_connection_remove_setting(NMConnection *connection, GType setting_type);
77
78NMSetting *nm_connection_get_setting(NMConnection *connection, GType setting_type);
79
80NMSetting *nm_connection_get_setting_by_name(NMConnection *connection, const char *name);
81
82/**
83 * NM_VARIANT_TYPE_CONNECTION:
84 *
85 * #GVariantType for a dictionary mapping from setting names to
86 * %NM_VARIANT_TYPE_SETTING variants. This is used to represent an
87 * #NMConnection, and is the type taken by nm_simple_connection_new_from_dbus()
88 * and returned from nm_connection_to_dbus().
89 */
90#define NM_VARIANT_TYPE_CONNECTION (G_VARIANT_TYPE("a{sa{sv}}"))
91
92/**
93 * NM_VARIANT_TYPE_SETTING:
94 *
95 * #GVariantType for a dictionary mapping from property names to values. This is
96 * an alias for %G_VARIANT_TYPE_VARDICT, and is the type of each element of
97 * an %NM_VARIANT_TYPE_CONNECTION dictionary.
98 */
99#define NM_VARIANT_TYPE_SETTING G_VARIANT_TYPE_VARDICT
100
101/**
102 * NMConnectionSerializationFlags:
103 * @NM_CONNECTION_SERIALIZE_ALL: serialize all properties (including secrets)
104 * @NM_CONNECTION_SERIALIZE_WITH_NON_SECRET: serialize properties that are
105 * not secrets. Since 1.32.
106 * @NM_CONNECTION_SERIALIZE_NO_SECRETS: this is a deprecated alias for
107 * @NM_CONNECTION_SERIALIZE_WITH_NON_SECRET.
108 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS: serialize all secrets. This flag is
109 * ignored if any of @NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED,
110 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED or
111 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED is set. Since 1.32.
112 * @NM_CONNECTION_SERIALIZE_ONLY_SECRETS: a deprecated alias for
113 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS.
114 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED: serialize agent-owned
115 * secrets. Since: 1.20.
116 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED: serialize system-owned
117 * secrets. Since: 1.32.
118 * @NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED: serialize secrets that
119 * are marked as never saved. Since: 1.32.
120 *
121 * These flags determine which properties are serialized when calling
122 * nm_connection_to_dbus().
123 **/
124typedef enum /*< flags >*/ {
125 NM_CONNECTION_SERIALIZE_ALL = 0x00000000,
126 NM_CONNECTION_SERIALIZE_WITH_NON_SECRET = 0x00000001,
127 NM_CONNECTION_SERIALIZE_NO_SECRETS = 0x00000001,
128 NM_CONNECTION_SERIALIZE_WITH_SECRETS = 0x00000002,
129 NM_CONNECTION_SERIALIZE_ONLY_SECRETS = 0x00000002,
130 NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED = 0x00000004,
131 NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED = 0x00000008,
132 NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED = 0x00000010,
133} NMConnectionSerializationFlags;
134
135GVariant *nm_connection_to_dbus(NMConnection *connection, NMConnectionSerializationFlags flags);
136
137gboolean
138nm_connection_replace_settings(NMConnection *connection, GVariant *new_settings, GError **error);
139
140void nm_connection_replace_settings_from_connection(NMConnection *connection,
141 NMConnection *new_connection);
142
143void nm_connection_clear_settings(NMConnection *connection);
144
145gboolean nm_connection_compare(NMConnection *a, NMConnection *b, NMSettingCompareFlags flags);
146
147gboolean nm_connection_diff(NMConnection *a,
148 NMConnection *b,
149 NMSettingCompareFlags flags,
150 GHashTable **out_settings);
151
152gboolean nm_connection_verify(NMConnection *connection, GError **error);
153NM_AVAILABLE_IN_1_2
154gboolean nm_connection_verify_secrets(NMConnection *connection, GError **error);
155gboolean nm_connection_normalize(NMConnection *connection,
156 GHashTable *parameters,
157 gboolean *modified,
158 GError **error);
159
160const char *nm_connection_need_secrets(NMConnection *connection, GPtrArray **hints);
161
162void nm_connection_clear_secrets(NMConnection *connection);
163
164void nm_connection_clear_secrets_with_flags(NMConnection *connection,
165 NMSettingClearSecretsWithFlagsFn func,
166 gpointer user_data);
167
168gboolean nm_connection_update_secrets(NMConnection *connection,
169 const char *setting_name,
170 GVariant *secrets,
171 GError **error);
172
173void nm_connection_set_path(NMConnection *connection, const char *path);
174
175const char *nm_connection_get_path(NMConnection *connection);
176
177const char *nm_connection_get_interface_name(NMConnection *connection);
178
179gboolean nm_connection_is_type(NMConnection *connection, const char *type);
180
181void nm_connection_for_each_setting_value(NMConnection *connection,
182 NMSettingValueIterFn func,
183 gpointer user_data);
184
185NM_AVAILABLE_IN_1_10
186NMSetting **nm_connection_get_settings(NMConnection *connection, guint *out_length);
187
188void nm_connection_dump(NMConnection *connection);
189
190/* Helpers */
191const char *nm_connection_get_uuid(NMConnection *connection);
192const char *nm_connection_get_id(NMConnection *connection);
193const char *nm_connection_get_connection_type(NMConnection *connection);
194
195gboolean nm_connection_is_virtual(NMConnection *connection);
196char *nm_connection_get_virtual_device_description(NMConnection *connection);
197
198NMSetting8021x *nm_connection_get_setting_802_1x(NMConnection *connection);
199NMSettingBluetooth *nm_connection_get_setting_bluetooth(NMConnection *connection);
200NMSettingBond *nm_connection_get_setting_bond(NMConnection *connection);
201NMSettingTeam *nm_connection_get_setting_team(NMConnection *connection);
202NMSettingTeamPort *nm_connection_get_setting_team_port(NMConnection *connection);
203NMSettingBridge *nm_connection_get_setting_bridge(NMConnection *connection);
204NMSettingBridgePort *nm_connection_get_setting_bridge_port(NMConnection *connection);
205NMSettingCdma *nm_connection_get_setting_cdma(NMConnection *connection);
206NMSettingConnection *nm_connection_get_setting_connection(NMConnection *connection);
207NMSettingDcb *nm_connection_get_setting_dcb(NMConnection *connection);
208NM_AVAILABLE_IN_1_8
209NMSettingDummy *nm_connection_get_setting_dummy(NMConnection *connection);
210NMSettingGeneric *nm_connection_get_setting_generic(NMConnection *connection);
211NMSettingGsm *nm_connection_get_setting_gsm(NMConnection *connection);
212NMSettingInfiniband *nm_connection_get_setting_infiniband(NMConnection *connection);
213NM_AVAILABLE_IN_1_2
214NMSettingIPTunnel *nm_connection_get_setting_ip_tunnel(NMConnection *connection);
215NMSettingIPConfig *nm_connection_get_setting_ip4_config(NMConnection *connection);
216NMSettingIPConfig *nm_connection_get_setting_ip6_config(NMConnection *connection);
217NM_AVAILABLE_IN_1_6
218NMSettingMacsec *nm_connection_get_setting_macsec(NMConnection *connection);
219NM_AVAILABLE_IN_1_2
220NMSettingMacvlan *nm_connection_get_setting_macvlan(NMConnection *connection);
221NMSettingOlpcMesh *nm_connection_get_setting_olpc_mesh(NMConnection *connection);
222NM_AVAILABLE_IN_1_14
223NMSettingOvsBridge *nm_connection_get_setting_ovs_bridge(NMConnection *connection);
224NM_AVAILABLE_IN_1_14
225NMSettingOvsInterface *nm_connection_get_setting_ovs_interface(NMConnection *connection);
226NM_AVAILABLE_IN_1_14
227NMSettingOvsPatch *nm_connection_get_setting_ovs_patch(NMConnection *connection);
228NM_AVAILABLE_IN_1_14
229NMSettingOvsPort *nm_connection_get_setting_ovs_port(NMConnection *connection);
230NMSettingPpp *nm_connection_get_setting_ppp(NMConnection *connection);
231NMSettingPppoe *nm_connection_get_setting_pppoe(NMConnection *connection);
232NM_AVAILABLE_IN_1_6
233NMSettingProxy *nm_connection_get_setting_proxy(NMConnection *connection);
234NMSettingSerial *nm_connection_get_setting_serial(NMConnection *connection);
235NM_AVAILABLE_IN_1_12
236NMSettingTCConfig *nm_connection_get_setting_tc_config(NMConnection *connection);
237NM_AVAILABLE_IN_1_14
238NMSettingTun *nm_connection_get_setting_tun(NMConnection *connection);
239NMSettingVpn *nm_connection_get_setting_vpn(NMConnection *connection);
240NMSettingWimax *nm_connection_get_setting_wimax(NMConnection *connection);
241NMSettingAdsl *nm_connection_get_setting_adsl(NMConnection *connection);
242NMSettingWired *nm_connection_get_setting_wired(NMConnection *connection);
243NMSettingWireless *nm_connection_get_setting_wireless(NMConnection *connection);
244NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security(NMConnection *connection);
245NMSettingVlan *nm_connection_get_setting_vlan(NMConnection *connection);
246NM_AVAILABLE_IN_1_2
247NMSettingVxlan *nm_connection_get_setting_vxlan(NMConnection *connection);
248
249G_END_DECLS
250
251#endif /* __NM_CONNECTION_H__ */
252

source code of include/libnm/nm-connection.h