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