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 | |
18 | G_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 | */ |
63 | typedef 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 | |
73 | GType nm_connection_get_type(void); |
74 | |
75 | void nm_connection_add_setting(NMConnection *connection, NMSetting *setting); |
76 | |
77 | void nm_connection_remove_setting(NMConnection *connection, GType setting_type); |
78 | |
79 | NMSetting *nm_connection_get_setting(NMConnection *connection, GType setting_type); |
80 | |
81 | NMSetting *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 | **/ |
125 | typedef 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 | |
136 | GVariant *nm_connection_to_dbus(NMConnection *connection, NMConnectionSerializationFlags flags); |
137 | |
138 | gboolean |
139 | nm_connection_replace_settings(NMConnection *connection, GVariant *new_settings, GError **error); |
140 | |
141 | void nm_connection_replace_settings_from_connection(NMConnection *connection, |
142 | NMConnection *new_connection); |
143 | |
144 | void nm_connection_clear_settings(NMConnection *connection); |
145 | |
146 | gboolean nm_connection_compare(NMConnection *a, NMConnection *b, NMSettingCompareFlags flags); |
147 | |
148 | gboolean nm_connection_diff(NMConnection *a, |
149 | NMConnection *b, |
150 | NMSettingCompareFlags flags, |
151 | GHashTable **out_settings); |
152 | |
153 | gboolean nm_connection_verify(NMConnection *connection, GError **error); |
154 | NM_AVAILABLE_IN_1_2 |
155 | gboolean nm_connection_verify_secrets(NMConnection *connection, GError **error); |
156 | gboolean nm_connection_normalize(NMConnection *connection, |
157 | GHashTable *parameters, |
158 | gboolean *modified, |
159 | GError **error); |
160 | |
161 | const char *nm_connection_need_secrets(NMConnection *connection, GPtrArray **hints); |
162 | |
163 | void nm_connection_clear_secrets(NMConnection *connection); |
164 | |
165 | void nm_connection_clear_secrets_with_flags(NMConnection *connection, |
166 | NMSettingClearSecretsWithFlagsFn func, |
167 | gpointer user_data); |
168 | |
169 | gboolean nm_connection_update_secrets(NMConnection *connection, |
170 | const char *setting_name, |
171 | GVariant *secrets, |
172 | GError **error); |
173 | |
174 | void nm_connection_set_path(NMConnection *connection, const char *path); |
175 | |
176 | const char *nm_connection_get_path(NMConnection *connection); |
177 | |
178 | const char *nm_connection_get_interface_name(NMConnection *connection); |
179 | |
180 | gboolean nm_connection_is_type(NMConnection *connection, const char *type); |
181 | |
182 | void nm_connection_for_each_setting_value(NMConnection *connection, |
183 | NMSettingValueIterFn func, |
184 | gpointer user_data); |
185 | |
186 | NM_AVAILABLE_IN_1_10 |
187 | NMSetting **nm_connection_get_settings(NMConnection *connection, guint *out_length); |
188 | |
189 | void nm_connection_dump(NMConnection *connection); |
190 | |
191 | /* Helpers */ |
192 | const char *nm_connection_get_uuid(NMConnection *connection); |
193 | const char *nm_connection_get_id(NMConnection *connection); |
194 | const char *nm_connection_get_connection_type(NMConnection *connection); |
195 | |
196 | gboolean nm_connection_is_virtual(NMConnection *connection); |
197 | char *nm_connection_get_virtual_device_description(NMConnection *connection); |
198 | |
199 | NMSetting8021x *nm_connection_get_setting_802_1x(NMConnection *connection); |
200 | NMSettingBluetooth *nm_connection_get_setting_bluetooth(NMConnection *connection); |
201 | NMSettingBond *nm_connection_get_setting_bond(NMConnection *connection); |
202 | NMSettingTeam *nm_connection_get_setting_team(NMConnection *connection); |
203 | NMSettingTeamPort *nm_connection_get_setting_team_port(NMConnection *connection); |
204 | NMSettingBridge *nm_connection_get_setting_bridge(NMConnection *connection); |
205 | NMSettingBridgePort *nm_connection_get_setting_bridge_port(NMConnection *connection); |
206 | NMSettingCdma *nm_connection_get_setting_cdma(NMConnection *connection); |
207 | NMSettingConnection *nm_connection_get_setting_connection(NMConnection *connection); |
208 | NMSettingDcb *nm_connection_get_setting_dcb(NMConnection *connection); |
209 | NM_AVAILABLE_IN_1_8 |
210 | NMSettingDummy *nm_connection_get_setting_dummy(NMConnection *connection); |
211 | NMSettingGeneric *nm_connection_get_setting_generic(NMConnection *connection); |
212 | NMSettingGsm *nm_connection_get_setting_gsm(NMConnection *connection); |
213 | NMSettingInfiniband *nm_connection_get_setting_infiniband(NMConnection *connection); |
214 | NM_AVAILABLE_IN_1_2 |
215 | NMSettingIPTunnel *nm_connection_get_setting_ip_tunnel(NMConnection *connection); |
216 | NMSettingIPConfig *nm_connection_get_setting_ip4_config(NMConnection *connection); |
217 | NMSettingIPConfig *nm_connection_get_setting_ip6_config(NMConnection *connection); |
218 | NM_AVAILABLE_IN_1_6 |
219 | NMSettingMacsec *nm_connection_get_setting_macsec(NMConnection *connection); |
220 | NM_AVAILABLE_IN_1_2 |
221 | NMSettingMacvlan *nm_connection_get_setting_macvlan(NMConnection *connection); |
222 | NMSettingOlpcMesh *nm_connection_get_setting_olpc_mesh(NMConnection *connection); |
223 | NM_AVAILABLE_IN_1_10 |
224 | NMSettingOvsBridge *nm_connection_get_setting_ovs_bridge(NMConnection *connection); |
225 | NM_AVAILABLE_IN_1_10 |
226 | NMSettingOvsInterface *nm_connection_get_setting_ovs_interface(NMConnection *connection); |
227 | NMSettingOvsPatch *nm_connection_get_setting_ovs_patch(NMConnection *connection); |
228 | NM_AVAILABLE_IN_1_10 |
229 | NMSettingOvsPort *nm_connection_get_setting_ovs_port(NMConnection *connection); |
230 | NMSettingPpp *nm_connection_get_setting_ppp(NMConnection *connection); |
231 | NMSettingPppoe *nm_connection_get_setting_pppoe(NMConnection *connection); |
232 | NM_AVAILABLE_IN_1_6 |
233 | NMSettingProxy *nm_connection_get_setting_proxy(NMConnection *connection); |
234 | NMSettingSerial *nm_connection_get_setting_serial(NMConnection *connection); |
235 | NM_AVAILABLE_IN_1_12 |
236 | NMSettingTCConfig *nm_connection_get_setting_tc_config(NMConnection *connection); |
237 | NM_AVAILABLE_IN_1_2 |
238 | NMSettingTun *nm_connection_get_setting_tun(NMConnection *connection); |
239 | NMSettingVpn *nm_connection_get_setting_vpn(NMConnection *connection); |
240 | NMSettingWimax *nm_connection_get_setting_wimax(NMConnection *connection); |
241 | NMSettingAdsl *nm_connection_get_setting_adsl(NMConnection *connection); |
242 | NMSettingWired *nm_connection_get_setting_wired(NMConnection *connection); |
243 | NMSettingWireless *nm_connection_get_setting_wireless(NMConnection *connection); |
244 | NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security(NMConnection *connection); |
245 | NMSettingVlan *nm_connection_get_setting_vlan(NMConnection *connection); |
246 | NM_AVAILABLE_IN_1_2 |
247 | NMSettingVxlan *nm_connection_get_setting_vxlan(NMConnection *connection); |
248 | |
249 | G_END_DECLS |
250 | |
251 | #endif /* __NM_CONNECTION_H__ */ |
252 | |