1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2007 - 2008 Novell, Inc.
4 * Copyright (C) 2007 - 2014 Red Hat, Inc.
5 */
6
7#ifndef __NM_CLIENT_H__
8#define __NM_CLIENT_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-types.h"
15
16G_BEGIN_DECLS
17
18/**
19 * NMClientInstanceFlags:
20 * @NM_CLIENT_INSTANCE_FLAGS_NONE: special value to indicate no flags.
21 * @NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS: by default, NMClient
22 * will fetch the permissions via "GetPermissions" and refetch them when
23 * "CheckPermissions" signal gets received. By setting this flag, this behavior
24 * can be disabled. You can toggle this flag to enable and disable automatic
25 * fetching of the permissions. Watch also nm_client_get_permissions_state()
26 * to know whether the permissions are up to date.
27 *
28 * Since: 1.24
29 */
30typedef enum { /*< flags >*/
31 NM_CLIENT_INSTANCE_FLAGS_NONE = 0,
32 NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS = 1,
33} NMClientInstanceFlags;
34
35#define NM_TYPE_CLIENT (nm_client_get_type())
36#define NM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_CLIENT, NMClient))
37#define NM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_CLIENT, NMClientClass))
38#define NM_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_CLIENT))
39#define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_CLIENT))
40#define NM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_CLIENT, NMClientClass))
41
42#define NM_CLIENT_VERSION "version"
43#define NM_CLIENT_STATE "state"
44#define NM_CLIENT_STARTUP "startup"
45#define NM_CLIENT_NM_RUNNING "nm-running"
46#define NM_CLIENT_DBUS_CONNECTION "dbus-connection"
47#define NM_CLIENT_DBUS_NAME_OWNER "dbus-name-owner"
48#define NM_CLIENT_INSTANCE_FLAGS "instance-flags"
49
50_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
51#define NM_CLIENT_NETWORKING_ENABLED "networking-enabled"
52
53_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
54#define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled"
55_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
56#define NM_CLIENT_WWAN_ENABLED "wwan-enabled"
57_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
58#define NM_CLIENT_WIMAX_ENABLED "wimax-enabled"
59
60#define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
61#define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
62#define NM_CLIENT_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
63
64#define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections"
65#define NM_CLIENT_CONNECTIVITY "connectivity"
66#define NM_CLIENT_CONNECTIVITY_CHECK_URI "connectivity-check-uri"
67#define NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE "connectivity-check-available"
68
69_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
70#define NM_CLIENT_CONNECTIVITY_CHECK_ENABLED "connectivity-check-enabled"
71
72#define NM_CLIENT_PRIMARY_CONNECTION "primary-connection"
73#define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection"
74#define NM_CLIENT_DEVICES "devices"
75#define NM_CLIENT_ALL_DEVICES "all-devices"
76#define NM_CLIENT_CONNECTIONS "connections"
77#define NM_CLIENT_HOSTNAME "hostname"
78#define NM_CLIENT_CAN_MODIFY "can-modify"
79#define NM_CLIENT_METERED "metered"
80#define NM_CLIENT_DNS_MODE "dns-mode"
81#define NM_CLIENT_DNS_RC_MANAGER "dns-rc-manager"
82#define NM_CLIENT_DNS_CONFIGURATION "dns-configuration"
83#define NM_CLIENT_CHECKPOINTS "checkpoints"
84#define NM_CLIENT_CAPABILITIES "capabilities"
85#define NM_CLIENT_PERMISSIONS_STATE "permissions-state"
86
87#define NM_CLIENT_DEVICE_ADDED "device-added"
88#define NM_CLIENT_DEVICE_REMOVED "device-removed"
89#define NM_CLIENT_ANY_DEVICE_ADDED "any-device-added"
90#define NM_CLIENT_ANY_DEVICE_REMOVED "any-device-removed"
91#define NM_CLIENT_PERMISSION_CHANGED "permission-changed"
92#define NM_CLIENT_CONNECTION_ADDED "connection-added"
93#define NM_CLIENT_CONNECTION_REMOVED "connection-removed"
94#define NM_CLIENT_ACTIVE_CONNECTION_ADDED "active-connection-added"
95#define NM_CLIENT_ACTIVE_CONNECTION_REMOVED "active-connection-removed"
96
97/**
98 * NMClientError:
99 * @NM_CLIENT_ERROR_FAILED: unknown or unclassified error
100 * @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
101 * failed because NetworkManager is not running
102 * @NM_CLIENT_ERROR_OBJECT_CREATION_FAILED: NetworkManager claimed that an
103 * operation succeeded, but the object that was allegedly created (eg,
104 * #NMRemoteConnection, #NMActiveConnection) was apparently destroyed before
105 * #NMClient could create a representation of it.
106 *
107 * Describes errors that may result from operations involving a #NMClient.
108 *
109 * D-Bus operations may also return errors from other domains, including
110 * #NMManagerError, #NMSettingsError, #NMAgentManagerError, and #NMConnectionError.
111 **/
112typedef enum {
113 NM_CLIENT_ERROR_FAILED = 0,
114 NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
115 NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
116} NMClientError;
117
118#define NM_CLIENT_ERROR nm_client_error_quark()
119GQuark nm_client_error_quark(void);
120
121/* DNS stuff */
122
123typedef struct NMDnsEntry NMDnsEntry;
124
125NM_AVAILABLE_IN_1_6
126GType nm_dns_entry_get_type(void);
127NM_AVAILABLE_IN_1_6
128void nm_dns_entry_unref(NMDnsEntry *entry);
129NM_AVAILABLE_IN_1_6
130const char *nm_dns_entry_get_interface(NMDnsEntry *entry);
131NM_AVAILABLE_IN_1_6
132const char *const *nm_dns_entry_get_nameservers(NMDnsEntry *entry);
133NM_AVAILABLE_IN_1_6
134const char *const *nm_dns_entry_get_domains(NMDnsEntry *entry);
135NM_AVAILABLE_IN_1_6
136int nm_dns_entry_get_priority(NMDnsEntry *entry);
137NM_AVAILABLE_IN_1_6
138gboolean nm_dns_entry_get_vpn(NMDnsEntry *entry);
139
140/**
141 * NMClient:
142 *
143 * NMClient contains a cache of the objects of NetworkManager's D-Bus API.
144 * It uses #GMainContext and #GDBusConnection for that and registers to
145 * D-Bus signals. That means, when iterating the associated #GMainContext,
146 * D-Bus signals gets processed and the #NMClient instance updates and
147 * emits #GObject signals.
148 */
149typedef struct _NMClientClass NMClientClass;
150
151GType nm_client_get_type(void);
152
153NMClient *nm_client_new(GCancellable *cancellable, GError **error);
154
155void
156nm_client_new_async(GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
157NMClient *nm_client_new_finish(GAsyncResult *result, GError **error);
158
159NM_AVAILABLE_IN_1_24
160NMClientInstanceFlags nm_client_get_instance_flags(NMClient *self);
161
162NM_AVAILABLE_IN_1_22
163GDBusConnection *nm_client_get_dbus_connection(NMClient *client);
164
165NM_AVAILABLE_IN_1_22
166GMainContext *nm_client_get_main_context(NMClient *self);
167
168NM_AVAILABLE_IN_1_22
169GObject *nm_client_get_context_busy_watcher(NMClient *self);
170
171NM_AVAILABLE_IN_1_22
172const char *nm_client_get_dbus_name_owner(NMClient *client);
173
174const char *nm_client_get_version(NMClient *client);
175NMState nm_client_get_state(NMClient *client);
176gboolean nm_client_get_startup(NMClient *client);
177gboolean nm_client_get_nm_running(NMClient *client);
178
179NMObject *nm_client_get_object_by_path(NMClient *client, const char *dbus_path);
180
181NM_AVAILABLE_IN_1_22
182NMMetered nm_client_get_metered(NMClient *client);
183
184gboolean nm_client_networking_get_enabled(NMClient *client);
185
186NM_AVAILABLE_IN_1_24
187const guint32 *nm_client_get_capabilities(NMClient *client, gsize *length);
188
189_NM_DEPRECATED_SYNC_METHOD
190gboolean nm_client_networking_set_enabled(NMClient *client, gboolean enabled, GError **error);
191
192gboolean nm_client_wireless_get_enabled(NMClient *client);
193
194_NM_DEPRECATED_SYNC_METHOD
195void nm_client_wireless_set_enabled(NMClient *client, gboolean enabled);
196
197gboolean nm_client_wireless_hardware_get_enabled(NMClient *client);
198
199gboolean nm_client_wwan_get_enabled(NMClient *client);
200
201_NM_DEPRECATED_SYNC_METHOD
202void nm_client_wwan_set_enabled(NMClient *client, gboolean enabled);
203
204gboolean nm_client_wwan_hardware_get_enabled(NMClient *client);
205
206NM_DEPRECATED_IN_1_22
207gboolean nm_client_wimax_get_enabled(NMClient *client);
208
209NM_DEPRECATED_IN_1_22
210_NM_DEPRECATED_SYNC_METHOD
211void nm_client_wimax_set_enabled(NMClient *client, gboolean enabled);
212
213NM_DEPRECATED_IN_1_22
214gboolean nm_client_wimax_hardware_get_enabled(NMClient *client);
215
216NM_AVAILABLE_IN_1_10
217gboolean nm_client_connectivity_check_get_available(NMClient *client);
218
219NM_AVAILABLE_IN_1_10
220gboolean nm_client_connectivity_check_get_enabled(NMClient *client);
221
222NM_AVAILABLE_IN_1_10
223_NM_DEPRECATED_SYNC_METHOD
224void nm_client_connectivity_check_set_enabled(NMClient *client, gboolean enabled);
225
226NM_AVAILABLE_IN_1_20
227const char *nm_client_connectivity_check_get_uri(NMClient *client);
228
229_NM_DEPRECATED_SYNC_METHOD
230gboolean nm_client_get_logging(NMClient *client, char **level, char **domains, GError **error);
231
232_NM_DEPRECATED_SYNC_METHOD
233gboolean
234nm_client_set_logging(NMClient *client, const char *level, const char *domains, GError **error);
235
236NMClientPermissionResult nm_client_get_permission_result(NMClient *client,
237 NMClientPermission permission);
238
239NM_AVAILABLE_IN_1_24
240NMTernary nm_client_get_permissions_state(NMClient *self);
241
242NMConnectivityState nm_client_get_connectivity(NMClient *client);
243
244_NM_DEPRECATED_SYNC_METHOD
245NM_DEPRECATED_IN_1_22
246NMConnectivityState
247nm_client_check_connectivity(NMClient *client, GCancellable *cancellable, GError **error);
248
249void nm_client_check_connectivity_async(NMClient *client,
250 GCancellable *cancellable,
251 GAsyncReadyCallback callback,
252 gpointer user_data);
253NMConnectivityState
254nm_client_check_connectivity_finish(NMClient *client, GAsyncResult *result, GError **error);
255
256_NM_DEPRECATED_SYNC_METHOD
257gboolean nm_client_save_hostname(NMClient *client,
258 const char *hostname,
259 GCancellable *cancellable,
260 GError **error);
261
262void nm_client_save_hostname_async(NMClient *client,
263 const char *hostname,
264 GCancellable *cancellable,
265 GAsyncReadyCallback callback,
266 gpointer user_data);
267gboolean nm_client_save_hostname_finish(NMClient *client, GAsyncResult *result, GError **error);
268
269/* Devices */
270
271const GPtrArray *nm_client_get_devices(NMClient *client);
272NM_AVAILABLE_IN_1_2
273const GPtrArray *nm_client_get_all_devices(NMClient *client);
274NMDevice *nm_client_get_device_by_path(NMClient *client, const char *object_path);
275NMDevice *nm_client_get_device_by_iface(NMClient *client, const char *iface);
276
277/* Active Connections */
278
279const GPtrArray *nm_client_get_active_connections(NMClient *client);
280
281NMActiveConnection *nm_client_get_primary_connection(NMClient *client);
282NMActiveConnection *nm_client_get_activating_connection(NMClient *client);
283
284void nm_client_activate_connection_async(NMClient *client,
285 NMConnection *connection,
286 NMDevice *device,
287 const char *specific_object,
288 GCancellable *cancellable,
289 GAsyncReadyCallback callback,
290 gpointer user_data);
291NMActiveConnection *
292nm_client_activate_connection_finish(NMClient *client, GAsyncResult *result, GError **error);
293
294void nm_client_add_and_activate_connection_async(NMClient *client,
295 NMConnection *partial,
296 NMDevice *device,
297 const char *specific_object,
298 GCancellable *cancellable,
299 GAsyncReadyCallback callback,
300 gpointer user_data);
301NMActiveConnection *nm_client_add_and_activate_connection_finish(NMClient *client,
302 GAsyncResult *result,
303 GError **error);
304
305NM_AVAILABLE_IN_1_16
306void nm_client_add_and_activate_connection2(NMClient *client,
307 NMConnection *partial,
308 NMDevice *device,
309 const char *specific_object,
310 GVariant *options,
311 GCancellable *cancellable,
312 GAsyncReadyCallback callback,
313 gpointer user_data);
314NM_AVAILABLE_IN_1_16
315NMActiveConnection *nm_client_add_and_activate_connection2_finish(NMClient *client,
316 GAsyncResult *result,
317 GVariant **out_result,
318 GError **error);
319
320_NM_DEPRECATED_SYNC_METHOD
321gboolean nm_client_deactivate_connection(NMClient *client,
322 NMActiveConnection *active,
323 GCancellable *cancellable,
324 GError **error);
325
326void nm_client_deactivate_connection_async(NMClient *client,
327 NMActiveConnection *active,
328 GCancellable *cancellable,
329 GAsyncReadyCallback callback,
330 gpointer user_data);
331gboolean
332nm_client_deactivate_connection_finish(NMClient *client, GAsyncResult *result, GError **error);
333
334/* Connections */
335
336const GPtrArray *nm_client_get_connections(NMClient *client);
337
338NMRemoteConnection *nm_client_get_connection_by_id(NMClient *client, const char *id);
339NMRemoteConnection *nm_client_get_connection_by_path(NMClient *client, const char *path);
340NMRemoteConnection *nm_client_get_connection_by_uuid(NMClient *client, const char *uuid);
341
342void nm_client_add_connection_async(NMClient *client,
343 NMConnection *connection,
344 gboolean save_to_disk,
345 GCancellable *cancellable,
346 GAsyncReadyCallback callback,
347 gpointer user_data);
348NMRemoteConnection *
349nm_client_add_connection_finish(NMClient *client, GAsyncResult *result, GError **error);
350
351NM_AVAILABLE_IN_1_20
352void nm_client_add_connection2(NMClient *client,
353 GVariant *settings,
354 NMSettingsAddConnection2Flags flags,
355 GVariant *args,
356 gboolean ignore_out_result,
357 GCancellable *cancellable,
358 GAsyncReadyCallback callback,
359 gpointer user_data);
360
361NM_AVAILABLE_IN_1_20
362NMRemoteConnection *nm_client_add_connection2_finish(NMClient *client,
363 GAsyncResult *result,
364 GVariant **out_result,
365 GError **error);
366
367_NM_DEPRECATED_SYNC_METHOD
368gboolean nm_client_load_connections(NMClient *client,
369 char **filenames,
370 char ***failures,
371 GCancellable *cancellable,
372 GError **error);
373
374void nm_client_load_connections_async(NMClient *client,
375 char **filenames,
376 GCancellable *cancellable,
377 GAsyncReadyCallback callback,
378 gpointer user_data);
379gboolean nm_client_load_connections_finish(NMClient *client,
380 char ***failures,
381 GAsyncResult *result,
382 GError **error);
383
384_NM_DEPRECATED_SYNC_METHOD
385gboolean nm_client_reload_connections(NMClient *client, GCancellable *cancellable, GError **error);
386
387void nm_client_reload_connections_async(NMClient *client,
388 GCancellable *cancellable,
389 GAsyncReadyCallback callback,
390 gpointer user_data);
391gboolean
392nm_client_reload_connections_finish(NMClient *client, GAsyncResult *result, GError **error);
393
394NM_AVAILABLE_IN_1_6
395const char *nm_client_get_dns_mode(NMClient *client);
396NM_AVAILABLE_IN_1_6
397const char *nm_client_get_dns_rc_manager(NMClient *client);
398NM_AVAILABLE_IN_1_6
399const GPtrArray *nm_client_get_dns_configuration(NMClient *client);
400
401NM_AVAILABLE_IN_1_12
402const GPtrArray *nm_client_get_checkpoints(NMClient *client);
403
404NM_AVAILABLE_IN_1_12
405void nm_client_checkpoint_create(NMClient *client,
406 const GPtrArray *devices,
407 guint32 rollback_timeout,
408 NMCheckpointCreateFlags flags,
409 GCancellable *cancellable,
410 GAsyncReadyCallback callback,
411 gpointer user_data);
412NM_AVAILABLE_IN_1_12
413NMCheckpoint *
414nm_client_checkpoint_create_finish(NMClient *client, GAsyncResult *result, GError **error);
415
416NM_AVAILABLE_IN_1_12
417void nm_client_checkpoint_destroy(NMClient *client,
418 const char *checkpoint_path,
419 GCancellable *cancellable,
420 GAsyncReadyCallback callback,
421 gpointer user_data);
422NM_AVAILABLE_IN_1_12
423gboolean
424nm_client_checkpoint_destroy_finish(NMClient *client, GAsyncResult *result, GError **error);
425
426NM_AVAILABLE_IN_1_12
427void nm_client_checkpoint_rollback(NMClient *client,
428 const char *checkpoint_path,
429 GCancellable *cancellable,
430 GAsyncReadyCallback callback,
431 gpointer user_data);
432NM_AVAILABLE_IN_1_12
433GHashTable *
434nm_client_checkpoint_rollback_finish(NMClient *client, GAsyncResult *result, GError **error);
435
436NM_AVAILABLE_IN_1_12
437void nm_client_checkpoint_adjust_rollback_timeout(NMClient *client,
438 const char *checkpoint_path,
439 guint32 add_timeout,
440 GCancellable *cancellable,
441 GAsyncReadyCallback callback,
442 gpointer user_data);
443
444NM_AVAILABLE_IN_1_12
445gboolean nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient *client,
446 GAsyncResult *result,
447 GError **error);
448
449NM_AVAILABLE_IN_1_22
450void nm_client_reload(NMClient *client,
451 NMManagerReloadFlags flags,
452 GCancellable *cancellable,
453 GAsyncReadyCallback callback,
454 gpointer user_data);
455NM_AVAILABLE_IN_1_22
456gboolean nm_client_reload_finish(NMClient *client, GAsyncResult *result, GError **error);
457
458/*****************************************************************************/
459
460NM_AVAILABLE_IN_1_24
461void nm_client_dbus_call(NMClient *client,
462 const char *object_path,
463 const char *interface_name,
464 const char *method_name,
465 GVariant *parameters,
466 const GVariantType *reply_type,
467 int timeout_msec,
468 GCancellable *cancellable,
469 GAsyncReadyCallback callback,
470 gpointer user_data);
471
472NM_AVAILABLE_IN_1_24
473GVariant *nm_client_dbus_call_finish(NMClient *client, GAsyncResult *result, GError **error);
474
475NM_AVAILABLE_IN_1_24
476void nm_client_dbus_set_property(NMClient *client,
477 const char *object_path,
478 const char *interface_name,
479 const char *property_name,
480 GVariant *value,
481 int timeout_msec,
482 GCancellable *cancellable,
483 GAsyncReadyCallback callback,
484 gpointer user_data);
485
486NM_AVAILABLE_IN_1_24
487gboolean nm_client_dbus_set_property_finish(NMClient *client, GAsyncResult *result, GError **error);
488
489/*****************************************************************************/
490
491NM_AVAILABLE_IN_1_30
492void nm_utils_print(int output_mode, const char *msg);
493
494G_END_DECLS
495
496#endif /* __NM_CLIENT_H__ */
497

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