device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-util / nm-setting-connection.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /*
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301 USA.
18  *
19  * Copyright 2007 - 2013 Red Hat, Inc.
20  * Copyright 2007 - 2008 Novell, Inc.
21  */
22
23 #include "nm-default.h"
24
25 #include <string.h>
26
27 #include "nm-utils.h"
28 #include "nm-dbus-glib-types.h"
29 #include "nm-param-spec-specialized.h"
30 #include "nm-setting-connection.h"
31 #include "nm-setting-private.h"
32
33 /**
34  * SECTION:nm-setting-connection
35  * @short_description: Describes general connection properties
36  * @include: nm-setting-connection.h
37  *
38  * The #NMSettingConnection object is a #NMSetting subclass that describes
39  * properties that apply to all #NMConnection objects, regardless of what type
40  * of network connection they describe.  Each #NMConnection object must contain
41  * a #NMSettingConnection setting.
42  **/
43
44 /**
45  * nm_setting_connection_error_quark:
46  *
47  * Registers an error quark for #NMSettingConnection if necessary.
48  *
49  * Returns: the error quark used for #NMSettingConnection errors.
50  **/
51 GQuark
52 nm_setting_connection_error_quark (void)
53 {
54         static GQuark quark;
55
56         if (G_UNLIKELY (!quark))
57                 quark = g_quark_from_static_string ("nm-setting-connection-error-quark");
58         return quark;
59 }
60
61
62 G_DEFINE_TYPE_WITH_CODE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING,
63                          _nm_register_setting (NM_SETTING_CONNECTION_SETTING_NAME,
64                                                g_define_type_id,
65                                                0,
66                                                NM_SETTING_CONNECTION_ERROR))
67 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CONNECTION)
68
69 #define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate))
70
71 typedef enum {
72         PERM_TYPE_USER = 0,
73 } PermType;
74
75 typedef struct {
76         guint8 ptype;
77         char *item;
78 } Permission;
79
80 typedef struct {
81         char *id;
82         char *uuid;
83         char *interface_name;
84         char *type;
85         char *master;
86         char *slave_type;
87         GSList *permissions; /* list of Permission structs */
88         gboolean autoconnect;
89         guint64 timestamp;
90         gboolean read_only;
91         char *zone;
92         GSList *secondaries; /* secondary connections to activate with the base connection */
93         guint gateway_ping_timeout;
94 } NMSettingConnectionPrivate;
95
96 enum {
97         PROP_0,
98         PROP_ID,
99         PROP_UUID,
100         PROP_INTERFACE_NAME,
101         PROP_TYPE,
102         PROP_PERMISSIONS,
103         PROP_AUTOCONNECT,
104         PROP_TIMESTAMP,
105         PROP_READ_ONLY,
106         PROP_ZONE,
107         PROP_MASTER,
108         PROP_SLAVE_TYPE,
109         PROP_SECONDARIES,
110         PROP_GATEWAY_PING_TIMEOUT,
111
112         LAST_PROP
113 };
114
115 /***********************************************************************/
116
117 #define PERM_USER_PREFIX  "user:"
118
119 static Permission *
120 permission_new_from_str (const char *str)
121 {
122         Permission *p;
123         const char *last_colon;
124         size_t ulen = 0, i;
125
126         g_return_val_if_fail (strncmp (str, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0, NULL);
127         str += strlen (PERM_USER_PREFIX);
128
129         last_colon = strrchr (str, ':');
130         if (last_colon) {
131                 /* Ensure that somebody didn't pass "user::" */
132                 g_return_val_if_fail (last_colon > str, NULL);
133
134                 /* Reject :[detail] for now */
135                 g_return_val_if_fail (*(last_colon + 1) == '\0', NULL);
136
137                 /* Make sure we don't include detail in the username */
138                 ulen = last_colon - str;
139         } else
140                 ulen = strlen (str);
141
142         /* Sanity check the length of the username */
143         g_return_val_if_fail (ulen < 100, NULL);
144
145         /* Make sure there's no ':' in the username */
146         for (i = 0; i < ulen; i++)
147                 g_return_val_if_fail (str[i] != ':', NULL);
148
149         /* And the username must be valid UTF-8 */
150         g_return_val_if_fail (g_utf8_validate (str, -1, NULL) == TRUE, NULL);
151
152         /* Yay, valid... create the new permission */
153         p = g_slice_new0 (Permission);
154         p->ptype = PERM_TYPE_USER;
155         if (last_colon) {
156                 p->item = g_malloc (ulen + 1);
157                 memcpy (p->item, str, ulen);
158                 p->item[ulen] = '\0';
159         } else
160                 p->item = g_strdup (str);
161
162         return p;
163 }
164
165 static Permission *
166 permission_new (const char *uname)
167 {
168         Permission *p;
169
170         g_return_val_if_fail (uname, NULL);
171         g_return_val_if_fail (uname[0] != '\0', NULL);
172         g_return_val_if_fail (strchr (uname, ':') == NULL, NULL);
173         g_return_val_if_fail (g_utf8_validate (uname, -1, NULL) == TRUE, NULL);
174
175         /* Yay, valid... create the new permission */
176         p = g_slice_new0 (Permission);
177         p->ptype = PERM_TYPE_USER;
178         p->item = g_strdup (uname);
179         return p;
180 }
181
182 static char *
183 permission_to_string (Permission *p)
184 {
185         return g_strdup_printf (PERM_USER_PREFIX "%s:", p->item);
186 }
187
188 static void
189 permission_free (Permission *p)
190 {
191         g_free (p->item);
192         memset (p, 0, sizeof (*p));
193         g_slice_free (Permission, p);
194 }
195
196 /***********************************************************************/
197
198 /**
199  * nm_setting_connection_new:
200  *
201  * Creates a new #NMSettingConnection object with default values.
202  *
203  * Returns: the new empty #NMSettingConnection object
204  **/
205 NMSetting *nm_setting_connection_new (void)
206 {
207         return (NMSetting *) g_object_new (NM_TYPE_SETTING_CONNECTION, NULL);
208 }
209
210 /**
211  * nm_setting_connection_get_id:
212  * @setting: the #NMSettingConnection
213  *
214  * Returns the #NMSettingConnection:id property of the connection.
215  *
216  * Returns: the connection ID
217  **/
218 const char *
219 nm_setting_connection_get_id (NMSettingConnection *setting)
220 {
221         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
222
223         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->id;
224 }
225
226 /**
227  * nm_setting_connection_get_uuid:
228  * @setting: the #NMSettingConnection
229  *
230  * Returns the #NMSettingConnection:uuid property of the connection.
231  *
232  * Returns: the connection UUID
233  **/
234 const char *
235 nm_setting_connection_get_uuid (NMSettingConnection *setting)
236 {
237         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
238
239         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->uuid;
240 }
241
242 /**
243  * nm_setting_connection_get_interface_name:
244  * @setting: the #NMSettingConnection
245  *
246  * Returns the #NMSettingConnection:interface-name property of the connection.
247  *
248  * Returns: the connection's interface name
249  *
250  * Since: 0.9.10
251  **/
252 const char *
253 nm_setting_connection_get_interface_name (NMSettingConnection *setting)
254 {
255         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
256
257         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->interface_name;
258 }
259
260 /**
261  * nm_setting_connection_get_connection_type:
262  * @setting: the #NMSettingConnection
263  *
264  * Returns the #NMSettingConnection:type property of the connection.
265  *
266  * Returns: the connection type
267  **/
268 const char *
269 nm_setting_connection_get_connection_type (NMSettingConnection *setting)
270 {
271         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
272
273         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->type;
274 }
275
276
277 /**
278  * nm_setting_connection_get_num_permissions:
279  * @setting: the #NMSettingConnection
280  *
281  * Returns the number of entires in the #NMSettingConnection:permissions
282  * property of this setting.
283  *
284  * Returns: the number of permissions entires
285  */
286 guint32
287 nm_setting_connection_get_num_permissions (NMSettingConnection *setting)
288 {
289         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
290
291         return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->permissions);
292 }
293
294 /**
295  * nm_setting_connection_get_permission:
296  * @setting: the #NMSettingConnection
297  * @idx: the zero-based index of the permissions entry
298  * @out_ptype: on return, the permission type (at this time, always "user")
299  * @out_pitem: on return, the permission item (formatted accoring to @ptype, see
300  * #NMSettingConnection:permissions for more detail
301  * @out_detail: on return, the permission detail (at this time, always %NULL)
302  *
303  * Retrieve one of the entries of the #NMSettingConnection:permissions property
304  * of this setting.
305  *
306  * Returns: %TRUE if a permission was returned, %FALSE if @idx was invalid
307  */
308 gboolean
309 nm_setting_connection_get_permission (NMSettingConnection *setting,
310                                       guint32 idx,
311                                       const char **out_ptype,
312                                       const char **out_pitem,
313                                       const char **out_detail)
314 {
315         NMSettingConnectionPrivate *priv;
316         Permission *p;
317
318         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
319
320         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
321
322         g_return_val_if_fail (idx < g_slist_length (priv->permissions), FALSE);
323
324         p = g_slist_nth_data (priv->permissions, idx);
325         if (out_ptype)
326                 *out_ptype = "user";
327         if (out_pitem)
328                 *out_pitem = p->item;
329         if (out_detail)
330                 *out_detail = NULL;
331
332         return TRUE;
333 }
334
335 /**
336  * nm_setting_connection_permissions_user_allowed:
337  * @setting: the #NMSettingConnection
338  * @uname: the user name to check permissions for
339  *
340  * Checks whether the given username is allowed to view/access this connection.
341  *
342  * Returns: %TRUE if the requested user is allowed to view this connection,
343  * %FALSE if the given user is not allowed to view this connection
344  */
345 gboolean
346 nm_setting_connection_permissions_user_allowed (NMSettingConnection *setting,
347                                                 const char *uname)
348 {
349         NMSettingConnectionPrivate *priv;
350         GSList *iter;
351
352         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
353         g_return_val_if_fail (uname != NULL, FALSE);
354         g_return_val_if_fail (*uname != '\0', FALSE);
355
356         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
357
358         /* If no permissions, visible to all */
359         if (priv->permissions == NULL)
360                 return TRUE;
361
362         /* Find the username in the permissions list */
363         for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
364                 Permission *p = iter->data;
365
366                 if (strcmp (uname, p->item) == 0)
367                         return TRUE;
368         }
369
370         return FALSE;
371 }
372
373 /**
374  * nm_setting_connection_add_permission:
375  * @setting: the #NMSettingConnection
376  * @ptype: the permission type; at this time only "user" is supported
377  * @pitem: the permission item formatted as required for @ptype
378  * @detail: (allow-none): unused at this time; must be %NULL
379  *
380  * Adds a permission to the connection's permission list.  At this time, only
381  * the "user" permission type is supported, and @pitem must be a username. See
382  * #NMSettingConnection:permissions: for more details.
383  *
384  * Returns: %TRUE if the permission was unique and was successfully added to the
385  * list, %FALSE if @ptype or @pitem was invalid or it the permission was already
386  * present in the list
387  */
388 gboolean
389 nm_setting_connection_add_permission (NMSettingConnection *setting,
390                                       const char *ptype,
391                                       const char *pitem,
392                                       const char *detail)
393 {
394         NMSettingConnectionPrivate *priv;
395         Permission *p;
396         GSList *iter;
397
398         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
399         g_return_val_if_fail (ptype, FALSE);
400         g_return_val_if_fail (strlen (ptype) > 0, FALSE);
401         g_return_val_if_fail (detail == NULL, FALSE);
402
403         /* Only "user" for now... */
404         g_return_val_if_fail (strcmp (ptype, "user") == 0, FALSE);
405
406         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
407
408         /* No dupes */
409         for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
410                 p = iter->data;
411                 if (strcmp (pitem, p->item) == 0)
412                         return FALSE;
413         }
414
415         p = permission_new (pitem);
416         g_return_val_if_fail (p != NULL, FALSE);
417         priv->permissions = g_slist_append (priv->permissions, p);
418         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
419
420         return TRUE;
421 }
422
423 /**
424  * nm_setting_connection_remove_permission:
425  * @setting: the #NMSettingConnection
426  * @idx: the zero-based index of the permission to remove
427  *
428  * Removes the permission at index @idx from the connection.
429  */
430 void
431 nm_setting_connection_remove_permission (NMSettingConnection *setting,
432                                          guint32 idx)
433 {
434         NMSettingConnectionPrivate *priv;
435         GSList *iter;
436
437         g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
438
439         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
440         iter = g_slist_nth (priv->permissions, idx);
441         g_return_if_fail (iter != NULL);
442
443         permission_free ((Permission *) iter->data);
444         priv->permissions = g_slist_delete_link (priv->permissions, iter);
445         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
446 }
447
448 /**
449  * nm_setting_connection_remove_permission_by_value:
450  * @setting: the #NMSettingConnection
451  * @ptype: the permission type; at this time only "user" is supported
452  * @pitem: the permission item formatted as required for @ptype
453  * @detail: (allow-none): unused at this time; must be %NULL
454  *
455  * Removes the permission from the connection.
456  * At this time, only the "user" permission type is supported, and @pitem must
457  * be a username. See #NMSettingConnection:permissions: for more details.
458  *
459  * Returns: %TRUE if the permission was found and removed; %FALSE if it was not.
460  *
461  * Since: 0.9.10
462  */
463 gboolean
464 nm_setting_connection_remove_permission_by_value (NMSettingConnection *setting,
465                                                   const char *ptype,
466                                                   const char *pitem,
467                                                   const char *detail)
468 {
469         NMSettingConnectionPrivate *priv;
470         Permission *p;
471         GSList *iter;
472
473         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
474         g_return_val_if_fail (ptype, FALSE);
475         g_return_val_if_fail (strlen (ptype) > 0, FALSE);
476         g_return_val_if_fail (detail == NULL, FALSE);
477
478         /* Only "user" for now... */
479         g_return_val_if_fail (strcmp (ptype, "user") == 0, FALSE);
480
481         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
482         for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
483                 p = iter->data;
484                 if (strcmp (pitem, p->item) == 0) {
485                         permission_free ((Permission *) iter->data);
486                         priv->permissions = g_slist_delete_link (priv->permissions, iter);
487                         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
488                         return TRUE;
489                 }
490         }
491         return FALSE;
492 }
493
494 /**
495  * nm_setting_connection_get_autoconnect:
496  * @setting: the #NMSettingConnection
497  *
498  * Returns the #NMSettingConnection:autoconnect property of the connection.
499  *
500  * Returns: the connection's autoconnect behavior
501  **/
502 gboolean
503 nm_setting_connection_get_autoconnect (NMSettingConnection *setting)
504 {
505         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
506
507         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->autoconnect;
508 }
509
510 /**
511  * nm_setting_connection_get_timestamp:
512  * @setting: the #NMSettingConnection
513  *
514  * Returns the #NMSettingConnection:timestamp property of the connection.
515  *
516  * Returns: the connection's timestamp
517  **/
518 guint64
519 nm_setting_connection_get_timestamp (NMSettingConnection *setting)
520 {
521         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
522
523         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->timestamp;
524 }
525
526 /**
527  * nm_setting_connection_get_read_only:
528  * @setting: the #NMSettingConnection
529  *
530  * Returns the #NMSettingConnection:read-only property of the connection.
531  *
532  * Returns: %TRUE if the connection is read-only, %FALSE if it is not
533  **/
534 gboolean
535 nm_setting_connection_get_read_only (NMSettingConnection *setting)
536 {
537         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), TRUE);
538
539         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->read_only;
540 }
541
542 /**
543  * nm_setting_connection_get_zone:
544  * @setting: the #NMSettingConnection
545  *
546  * Returns the #NMSettingConnection:zone property of the connection.
547  *
548  * Returns: the trust level of a connection
549  **/
550 const char *
551 nm_setting_connection_get_zone (NMSettingConnection *setting)
552 {
553         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
554
555         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->zone;
556 }
557
558 /**
559  * nm_setting_connection_get_master:
560  * @setting: the #NMSettingConnection
561  *
562  * Returns the #NMSettingConnection:master property of the connection.
563  *
564  * Returns: interface name of the master device or UUID of the master
565  * connection.
566  */
567 const char *
568 nm_setting_connection_get_master (NMSettingConnection *setting)
569 {
570         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
571
572         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->master;
573 }
574
575 /**
576  * nm_setting_connection_get_slave_type:
577  * @setting: the #NMSettingConnection
578  *
579  * Returns the #NMSettingConnection:slave-type property of the connection.
580  *
581  * Returns: the type of slave this connection is, if any
582  */
583 const char *
584 nm_setting_connection_get_slave_type (NMSettingConnection *setting)
585 {
586         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
587
588         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type;
589 }
590
591 /**
592  * nm_setting_connection_is_slave_type:
593  * @setting: the #NMSettingConnection
594  * @type: the setting name (ie #NM_SETTING_BOND_SETTING_NAME) to be matched
595  * against @setting's slave type
596  *
597  * Returns: %TRUE if connection is of the given slave @type
598  */
599 gboolean
600 nm_setting_connection_is_slave_type (NMSettingConnection *setting,
601                                      const char *type)
602 {
603         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
604
605         return !g_strcmp0 (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type, type);
606 }
607
608 /**
609  * nm_setting_connection_get_num_secondaries:
610  * @setting: the #NMSettingConnection
611  *
612  * Returns: the number of configured secondary connection UUIDs
613  *
614  * Since: 0.9.8
615  **/
616 guint32
617 nm_setting_connection_get_num_secondaries (NMSettingConnection *setting)
618 {
619         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
620
621         return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->secondaries);
622 }
623
624 /**
625  * nm_setting_connection_get_secondary:
626  * @setting: the #NMSettingConnection
627  * @idx: the zero-based index of the secondary connection UUID entry
628  *
629  * Returns: the secondary connection UUID at index @idx
630  *
631  * Since: 0.9.8
632  **/
633 const char *
634 nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx)
635 {
636         NMSettingConnectionPrivate *priv;
637
638         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
639
640         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
641         g_return_val_if_fail (idx <= g_slist_length (priv->secondaries), NULL);
642
643         return (const char *) g_slist_nth_data (priv->secondaries, idx);
644 }
645
646 /**
647  * nm_setting_connection_add_secondary:
648  * @setting: the #NMSettingConnection
649  * @sec_uuid: the secondary connection UUID to add
650  *
651  * Adds a new secondary connetion UUID to the setting.
652  *
653  * Returns: %TRUE if the secondary connection UUID was added; %FALSE if the UUID
654  * was already present
655  *
656  * Since: 0.9.8
657  **/
658 gboolean
659 nm_setting_connection_add_secondary (NMSettingConnection *setting,
660                                      const char *sec_uuid)
661 {
662         NMSettingConnectionPrivate *priv;
663         GSList *iter;
664
665         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
666         g_return_val_if_fail (sec_uuid != NULL, FALSE);
667         g_return_val_if_fail (sec_uuid[0] != '\0', FALSE);
668
669         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
670         for (iter = priv->secondaries; iter; iter = g_slist_next (iter)) {
671                 if (!strcmp (sec_uuid, (char *) iter->data))
672                         return FALSE;
673         }
674
675         priv->secondaries = g_slist_append (priv->secondaries, g_strdup (sec_uuid));
676         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
677         return TRUE;
678 }
679
680 /**
681  * nm_setting_connection_remove_secondary:
682  * @setting: the #NMSettingConnection
683  * @idx: index number of the secondary connection UUID
684  *
685  * Removes the secondary coonnection UUID at index @idx.
686  *
687  * Since: 0.9.8
688  **/
689 void
690 nm_setting_connection_remove_secondary (NMSettingConnection *setting, guint32 idx)
691 {
692         NMSettingConnectionPrivate *priv;
693         GSList *elt;
694
695         g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
696
697         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
698         elt = g_slist_nth (priv->secondaries, idx);
699         g_return_if_fail (elt != NULL);
700
701         g_free (elt->data);
702         priv->secondaries = g_slist_delete_link (priv->secondaries, elt);
703         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
704 }
705
706 /**
707  * nm_setting_connection_remove_secondary_by_value:
708  * @setting: the #NMSettingConnection
709  * @sec_uuid: the secondary connection UUID to remove
710  *
711  * Removes the secondary coonnection UUID @sec_uuid.
712  *
713  * Returns: %TRUE if the secondary connection UUID was found and removed; %FALSE if it was not.
714  *
715  * Since: 0.9.10
716  **/
717 gboolean
718 nm_setting_connection_remove_secondary_by_value (NMSettingConnection *setting,
719                                                  const char *sec_uuid)
720 {
721         NMSettingConnectionPrivate *priv;
722         GSList *iter;
723
724         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
725         g_return_val_if_fail (sec_uuid != NULL, FALSE);
726         g_return_val_if_fail (sec_uuid[0] != '\0', FALSE);
727
728         priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
729         for (iter = priv->secondaries; iter; iter = g_slist_next (iter)) {
730                 if (!strcmp (sec_uuid, (char *) iter->data)) {
731                         priv->secondaries = g_slist_delete_link (priv->secondaries, iter);
732                         g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
733                         return TRUE;
734                 }
735         }
736         return FALSE;
737 }
738
739 /**
740  * nm_setting_connection_get_gateway_ping_timeout:
741  * @setting: the #NMSettingConnection
742  *
743  * Returns: the value contained in the #NMSettingConnection:gateway-ping-timeout
744  * property.
745  *
746  * Since: 0.9.10
747  **/
748 guint32
749 nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting)
750 {
751         g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
752
753         return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->gateway_ping_timeout;
754 }
755
756
757 static gboolean
758 verify (NMSetting *setting, GSList *all_settings, GError **error)
759 {
760         NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
761         gboolean is_slave;
762         GSList *iter;
763
764         if (!priv->id) {
765                 g_set_error_literal (error,
766                                      NM_SETTING_CONNECTION_ERROR,
767                                      NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
768                                      _("property is missing"));
769                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_ID);
770                 return FALSE;
771         } else if (!strlen (priv->id)) {
772                 g_set_error_literal (error,
773                                      NM_SETTING_CONNECTION_ERROR,
774                                      NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
775                                      _("property is empty"));
776                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_ID);
777                 return FALSE;
778         }
779
780         if (!priv->uuid) {
781                 g_set_error_literal (error,
782                                      NM_SETTING_CONNECTION_ERROR,
783                                      NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
784                                      _("property is missing"));
785                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
786                 return FALSE;
787         } else if (!nm_utils_is_uuid (priv->uuid)) {
788                 g_set_error (error,
789                              NM_SETTING_CONNECTION_ERROR,
790                              NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
791                              _("'%s' is not a valid UUID"),
792                              priv->uuid);
793                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
794                 return FALSE;
795         }
796
797         /* FIXME: previously, verify() set the NMSettingConnection:interface_name property,
798          * thus modifying the setting. verify() should not do this, but keep this not to change
799          * behaviour.
800          */
801         if (!priv->interface_name) {
802                 for (iter = all_settings; iter; iter = iter->next) {
803                         NMSetting *s_current = iter->data;
804                         char *virtual_iface_name = NULL;
805
806                         if (NM_IS_SETTING_BOND (s_current))
807                                 g_object_get (s_current, NM_SETTING_BOND_INTERFACE_NAME, &virtual_iface_name, NULL);
808                         else if (NM_IS_SETTING_BRIDGE (s_current))
809                                 g_object_get (s_current, NM_SETTING_BRIDGE_INTERFACE_NAME, &virtual_iface_name, NULL);
810                         else if (NM_IS_SETTING_TEAM (s_current))
811                                 g_object_get (s_current, NM_SETTING_TEAM_INTERFACE_NAME, &virtual_iface_name, NULL);
812                         else if (NM_IS_SETTING_VLAN (s_current))
813                                 g_object_get (s_current, NM_SETTING_VLAN_INTERFACE_NAME, &virtual_iface_name, NULL);
814                         /* For NMSettingInfiniband, virtual_iface_name has no backing field.
815                          * No need to set the (unset) interface_name to the default value.
816                          **/
817
818                         if (virtual_iface_name) {
819                                 if (nm_utils_iface_valid_name (virtual_iface_name)) {
820                                         /* found a new interface name. */
821                                         priv->interface_name = virtual_iface_name;
822                                         break;
823                                 }
824                                 g_free (virtual_iface_name);
825                         }
826                 }
827         }
828
829         if (priv->interface_name) {
830                 if (!nm_utils_iface_valid_name (priv->interface_name)) {
831                         g_set_error (error,
832                                      NM_SETTING_CONNECTION_ERROR,
833                                      NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
834                                      _("'%s' is not a valid interface name"),
835                                      priv->interface_name);
836                         g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
837                         return FALSE;
838                 }
839         }
840
841         if (!priv->type) {
842                 g_set_error_literal (error,
843                                      NM_SETTING_CONNECTION_ERROR,
844                                      NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
845                                      _("property is missing"));
846                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
847                 return FALSE;
848         } else if (!strlen (priv->type)) {
849                 g_set_error_literal (error,
850                                      NM_SETTING_CONNECTION_ERROR,
851                                      NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
852                                      _("property is empty"));
853                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
854                 return FALSE;
855         }
856
857         /* Make sure the corresponding 'type' item is present */
858         if (all_settings && !nm_setting_find_in_list (all_settings, priv->type)) {
859                 g_set_error (error,
860                              NM_SETTING_CONNECTION_ERROR,
861                              NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND,
862                              _("requires presence of '%s' setting in the connection"),
863                              priv->type);
864                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
865                 return FALSE;
866         }
867
868         is_slave = (   priv->slave_type
869                     && (   !strcmp (priv->slave_type, NM_SETTING_BOND_SETTING_NAME)
870                         || !strcmp (priv->slave_type, NM_SETTING_BRIDGE_SETTING_NAME)
871                         || !strcmp (priv->slave_type, NM_SETTING_TEAM_SETTING_NAME)));
872
873         if (priv->slave_type && !is_slave) {
874                 g_set_error (error,
875                              NM_SETTING_CONNECTION_ERROR,
876                              NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
877                              _("Unknown slave type '%s'"), priv->slave_type);
878                 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
879                 return NM_SETTING_VERIFY_ERROR;
880         }
881
882         if (is_slave) {
883                 if (!priv->master) {
884                         g_set_error (error,
885                                      NM_SETTING_CONNECTION_ERROR,
886                                      NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
887                                      _("Slave connections need a valid '%s' property"),
888                                      NM_SETTING_CONNECTION_MASTER);
889                         g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER);
890                         return NM_SETTING_VERIFY_ERROR;
891                 }
892         } else {
893                 if (priv->master) {
894                         g_set_error (error,
895                                      NM_SETTING_CONNECTION_ERROR,
896                                      NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
897                                      _("Cannot set '%s' without '%s'"),
898                                      NM_SETTING_CONNECTION_MASTER, NM_SETTING_CONNECTION_SLAVE_TYPE);
899                         g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
900                         return NM_SETTING_VERIFY_ERROR;
901                 }
902         }
903
904         return TRUE;
905 }
906
907 static gboolean
908 compare_property (NMSetting *setting,
909                   NMSetting *other,
910                   const GParamSpec *prop_spec,
911                   NMSettingCompareFlags flags)
912 {
913         /* Handle ignore ID */
914         if (   (flags & NM_SETTING_COMPARE_FLAG_IGNORE_ID)
915             && g_strcmp0 (prop_spec->name, NM_SETTING_CONNECTION_ID) == 0)
916                 return TRUE;
917
918         /* Otherwise chain up to parent to handle generic compare */
919         return NM_SETTING_CLASS (nm_setting_connection_parent_class)->compare_property (setting, other, prop_spec, flags);
920 }
921
922 static void
923 nm_setting_connection_init (NMSettingConnection *setting)
924 {
925 }
926
927 static void
928 finalize (GObject *object)
929 {
930         NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (object);
931
932         g_free (priv->id);
933         g_free (priv->uuid);
934         g_free (priv->interface_name);
935         g_free (priv->type);
936         g_free (priv->zone);
937         g_free (priv->master);
938         g_free (priv->slave_type);
939         g_slist_free_full (priv->permissions, (GDestroyNotify) permission_free);
940         g_slist_free_full (priv->secondaries, g_free);
941
942         G_OBJECT_CLASS (nm_setting_connection_parent_class)->finalize (object);
943 }
944
945 static GSList *
946 perm_stringlist_to_permlist (GSList *strlist)
947 {
948         GSList *list = NULL, *iter;
949
950         for (iter = strlist; iter; iter = g_slist_next (iter)) {
951                 Permission *p;
952
953                 p = permission_new_from_str ((const char *) iter->data);
954                 if (p)
955                         list = g_slist_append (list, p);
956         }
957
958         return list;
959 }
960
961 static void
962 set_property (GObject *object, guint prop_id,
963               const GValue *value, GParamSpec *pspec)
964 {
965         NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (object);
966
967         switch (prop_id) {
968         case PROP_ID:
969                 g_free (priv->id);
970                 priv->id = g_value_dup_string (value);
971                 break;
972         case PROP_UUID:
973                 g_free (priv->uuid);
974                 priv->uuid = g_value_dup_string (value);
975                 break;
976         case PROP_INTERFACE_NAME:
977                 g_free (priv->interface_name);
978                 priv->interface_name = g_value_dup_string (value);
979                 break;
980         case PROP_TYPE:
981                 g_free (priv->type);
982                 priv->type = g_value_dup_string (value);
983                 break;
984         case PROP_PERMISSIONS:
985                 g_slist_free_full (priv->permissions, (GDestroyNotify) permission_free);
986                 priv->permissions = perm_stringlist_to_permlist (g_value_get_boxed (value));
987                 break;
988         case PROP_AUTOCONNECT:
989                 priv->autoconnect = g_value_get_boolean (value);
990                 break;
991         case PROP_TIMESTAMP:
992                 priv->timestamp = g_value_get_uint64 (value);
993                 break;
994         case PROP_READ_ONLY:
995                 priv->read_only = g_value_get_boolean (value);
996                 break;
997         case PROP_ZONE:
998                 g_free (priv->zone);
999                 priv->zone = g_value_dup_string (value);
1000                 break;
1001         case PROP_MASTER:
1002                 g_free (priv->master);
1003                 priv->master = g_value_dup_string (value);
1004                 break;
1005         case PROP_SLAVE_TYPE:
1006                 g_free (priv->slave_type);
1007                 priv->slave_type = g_value_dup_string (value);
1008                 break;
1009         case PROP_SECONDARIES:
1010                 g_slist_free_full (priv->secondaries, g_free);
1011                 priv->secondaries = g_value_dup_boxed (value);
1012                 break;
1013         case PROP_GATEWAY_PING_TIMEOUT:
1014                 priv->gateway_ping_timeout = g_value_get_uint (value);
1015                 break;
1016         default:
1017                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1018                 break;
1019         }
1020 }
1021
1022 static GSList *
1023 perm_permlist_to_stringlist (GSList *permlist)
1024 {
1025         GSList *list = NULL, *iter;
1026
1027         for (iter = permlist; iter; iter = g_slist_next (iter))
1028                 list = g_slist_append (list, permission_to_string ((Permission *) iter->data));
1029         return list;
1030 }
1031
1032 static void
1033 get_property (GObject *object, guint prop_id,
1034               GValue *value, GParamSpec *pspec)
1035 {
1036         NMSettingConnection *setting = NM_SETTING_CONNECTION (object);
1037         NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
1038
1039         switch (prop_id) {
1040         case PROP_ID:
1041                 g_value_set_string (value, nm_setting_connection_get_id (setting));
1042                 break;
1043         case PROP_UUID:
1044                 g_value_set_string (value, nm_setting_connection_get_uuid (setting));
1045                 break;
1046         case PROP_INTERFACE_NAME:
1047                 g_value_set_string (value, nm_setting_connection_get_interface_name (setting));
1048                 break;
1049         case PROP_TYPE:
1050                 g_value_set_string (value, nm_setting_connection_get_connection_type (setting));
1051                 break;
1052         case PROP_PERMISSIONS:
1053                 g_value_take_boxed (value, perm_permlist_to_stringlist (priv->permissions));
1054                 break;
1055         case PROP_AUTOCONNECT:
1056                 g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting));
1057                 break;
1058         case PROP_TIMESTAMP:
1059                 g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting));
1060                 break;
1061         case PROP_READ_ONLY:
1062                 g_value_set_boolean (value, nm_setting_connection_get_read_only (setting));
1063                 break;
1064         case PROP_ZONE:
1065                 g_value_set_string (value, nm_setting_connection_get_zone (setting));
1066                 break;
1067         case PROP_MASTER:
1068                 g_value_set_string (value, nm_setting_connection_get_master (setting));
1069                 break;
1070         case PROP_SLAVE_TYPE:
1071                 g_value_set_string (value, nm_setting_connection_get_slave_type (setting));
1072                 break;
1073         case PROP_SECONDARIES:
1074                 g_value_set_boxed (value, priv->secondaries);
1075                 break;
1076         case PROP_GATEWAY_PING_TIMEOUT:
1077                 g_value_set_uint (value, priv->gateway_ping_timeout);
1078                 break;
1079         default:
1080                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1081                 break;
1082         }
1083 }
1084
1085 static void
1086 nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
1087 {
1088         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1089         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1090
1091         g_type_class_add_private (setting_class, sizeof (NMSettingConnectionPrivate));
1092
1093         /* virtual methods */
1094         object_class->set_property = set_property;
1095         object_class->get_property = get_property;
1096         object_class->finalize     = finalize;
1097         parent_class->verify       = verify;
1098         parent_class->compare_property = compare_property;
1099
1100         /* Properties */
1101
1102         /**
1103          * NMSettingConnection:id:
1104          *
1105          * A human readable unique identifier for the connection, like "Work Wi-Fi"
1106          * or "T-Mobile 3G".
1107          **/
1108         g_object_class_install_property
1109                 (object_class, PROP_ID,
1110                  g_param_spec_string (NM_SETTING_CONNECTION_ID, "", "",
1111                                       NULL,
1112                                       G_PARAM_READWRITE |
1113                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1114                                       G_PARAM_STATIC_STRINGS));
1115
1116         /**
1117          * NMSettingConnection:uuid:
1118          *
1119          * A universally unique identifier for the connection, for example generated
1120          * with libuuid.  It should be assigned when the connection is created, and
1121          * never changed as long as the connection still applies to the same
1122          * network.  For example, it should not be changed when the
1123          * #NMSettingConnection:id property or #NMSettingIP4Config changes, but
1124          * might need to be re-created when the Wi-Fi SSID, mobile broadband network
1125          * provider, or #NMSettingConnection:type property changes.
1126          *
1127          * The UUID must be in the format "2815492f-7e56-435e-b2e9-246bd7cdc664"
1128          * (ie, contains only hexadecimal characters and "-").  A suitable UUID may
1129          * be generated by nm_utils_uuid_generate() or
1130          * nm_utils_uuid_generate_from_string().
1131          **/
1132         g_object_class_install_property
1133                 (object_class, PROP_UUID,
1134                  g_param_spec_string (NM_SETTING_CONNECTION_UUID, "", "",
1135                                       NULL,
1136                                       G_PARAM_READWRITE |
1137                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1138                                       G_PARAM_STATIC_STRINGS));
1139
1140         /**
1141          * NMSettingConnection:interface-name:
1142          *
1143          * The name of the network interface this connection is bound to. If not
1144          * set, then the connection can be attached to any interface of the
1145          * appropriate type (subject to restrictions imposed by other settings).
1146          *
1147          * For software devices this specifies the name of the created device.
1148          *
1149          * For connection types where interface names cannot easily be made
1150          * persistent (e.g. mobile broadband or USB Ethernet), this property should
1151          * not be used. Setting this property restricts the interfaces a connection
1152          * can be used with, and if interface names change or are reordered the
1153          * connection may be applied to the wrong interface.
1154          *
1155          * Since: 0.9.10
1156          **/
1157         g_object_class_install_property
1158                 (object_class, PROP_INTERFACE_NAME,
1159                  g_param_spec_string (NM_SETTING_CONNECTION_INTERFACE_NAME, "", "",
1160                                       NULL,
1161                                       G_PARAM_READWRITE |
1162                                       NM_SETTING_PARAM_INFERRABLE |
1163                                       G_PARAM_STATIC_STRINGS));
1164
1165         /**
1166          * NMSettingConnection:type:
1167          *
1168          * Base type of the connection. For hardware-dependent connections, should
1169          * contain the setting name of the hardware-type specific setting (ie,
1170          * "802-3-ethernet" or "802-11-wireless" or "bluetooth", etc), and for
1171          * non-hardware dependent connections like VPN or otherwise, should contain
1172          * the setting name of that setting type (ie, "vpn" or "bridge", etc).
1173          **/
1174         g_object_class_install_property
1175                 (object_class, PROP_TYPE,
1176                  g_param_spec_string (NM_SETTING_CONNECTION_TYPE, "", "",
1177                                       NULL,
1178                                       G_PARAM_READWRITE |
1179                                       NM_SETTING_PARAM_INFERRABLE |
1180                                       G_PARAM_STATIC_STRINGS));
1181
1182         /**
1183          * NMSettingConnection:permissions:
1184          *
1185          * An array of strings defining what access a given user has to this
1186          * connection.  If this is %NULL or empty, all users are allowed to access
1187          * this connection.  Otherwise a user is allowed to access this connection
1188          * if and only if they are in this list. Each entry is of the form
1189          * "[type]:[id]:[reserved]"; for example, "user:dcbw:blah".
1190          *
1191          * At this time only the "user" [type] is allowed.  Any other values are
1192          * ignored and reserved for future use.  [id] is the username that this
1193          * permission refers to, which may not contain the ":" character. Any
1194          * [reserved] information present must be ignored and is reserved for future
1195          * use.  All of [type], [id], and [reserved] must be valid UTF-8.
1196          */
1197         g_object_class_install_property
1198                 (object_class, PROP_PERMISSIONS,
1199                  _nm_param_spec_specialized (NM_SETTING_CONNECTION_PERMISSIONS, "", "",
1200                                              DBUS_TYPE_G_LIST_OF_STRING,
1201                                              G_PARAM_READWRITE |
1202                                              G_PARAM_STATIC_STRINGS));
1203
1204         /**
1205          * NMSettingConnection:autoconnect:
1206          *
1207          * Whether or not the connection should be automatically connected by
1208          * NetworkManager when the resources for the connection are available.
1209          * %TRUE to automatically activate the connection, %FALSE to require manual
1210          * intervention to activate the connection.
1211          **/
1212         g_object_class_install_property
1213                 (object_class, PROP_AUTOCONNECT,
1214                  g_param_spec_boolean (NM_SETTING_CONNECTION_AUTOCONNECT, "", "",
1215                                        TRUE,
1216                                        G_PARAM_READWRITE |
1217                                        G_PARAM_CONSTRUCT |
1218                                        NM_SETTING_PARAM_FUZZY_IGNORE |
1219                                        G_PARAM_STATIC_STRINGS));
1220
1221         /**
1222          * NMSettingConnection:timestamp:
1223          *
1224          * The time, in seconds since the Unix Epoch, that the connection was last
1225          * _successfully_ fully activated.
1226          *
1227          * NetworkManager updates the connection timestamp periodically when the
1228          * connection is active to ensure that an active connection has the latest
1229          * timestamp. The property is only meant for reading (changes to this
1230          * property will not be preserved).
1231          **/
1232         g_object_class_install_property
1233                 (object_class, PROP_TIMESTAMP,
1234                  g_param_spec_uint64 (NM_SETTING_CONNECTION_TIMESTAMP, "", "",
1235                                       0, G_MAXUINT64, 0,
1236                                       G_PARAM_READWRITE |
1237                                       G_PARAM_CONSTRUCT |
1238                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1239                                       G_PARAM_STATIC_STRINGS));
1240
1241         /**
1242          * NMSettingConnection:read-only:
1243          *
1244          * %FALSE if the connection can be modified using the provided settings
1245          * service's D-Bus interface with the right privileges, or %TRUE if the
1246          * connection is read-only and cannot be modified.
1247          **/
1248         g_object_class_install_property
1249                 (object_class, PROP_READ_ONLY,
1250                  g_param_spec_boolean (NM_SETTING_CONNECTION_READ_ONLY, "", "",
1251                                        FALSE,
1252                                        G_PARAM_READWRITE |
1253                                        G_PARAM_CONSTRUCT |
1254                                        NM_SETTING_PARAM_FUZZY_IGNORE |
1255                                        G_PARAM_STATIC_STRINGS));
1256
1257         /**
1258          * NMSettingConnection:zone:
1259          *
1260          * The trust level of a the connection.  Free form case-insensitive string
1261          * (for example "Home", "Work", "Public").  %NULL or unspecified zone means
1262          * the connection will be placed in the default zone as defined by the
1263          * firewall.
1264          **/
1265         g_object_class_install_property
1266                 (object_class, PROP_ZONE,
1267                  g_param_spec_string (NM_SETTING_CONNECTION_ZONE, "", "",
1268                                       NULL,
1269                                       G_PARAM_READWRITE |
1270                                       G_PARAM_CONSTRUCT |
1271                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1272                                       G_PARAM_STATIC_STRINGS));
1273
1274         /**
1275          * NMSettingConnection:master:
1276          *
1277          * Interface name of the master device or UUID of the master connection.
1278          **/
1279         g_object_class_install_property
1280                 (object_class, PROP_MASTER,
1281                  g_param_spec_string (NM_SETTING_CONNECTION_MASTER, "", "",
1282                                       NULL,
1283                                       G_PARAM_READWRITE |
1284                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1285                                       NM_SETTING_PARAM_INFERRABLE |
1286                                       G_PARAM_STATIC_STRINGS));
1287
1288         /**
1289          * NMSettingConnection:slave-type:
1290          *
1291          * Setting name of the device type of this slave's master connection (eg,
1292          * %NM_SETTING_BOND_SETTING_NAME), or %NULL if this connection is not a
1293          * slave.
1294          **/
1295         g_object_class_install_property
1296                 (object_class, PROP_SLAVE_TYPE,
1297                  g_param_spec_string (NM_SETTING_CONNECTION_SLAVE_TYPE, "", "",
1298                                       NULL,
1299                                       G_PARAM_READWRITE |
1300                                       NM_SETTING_PARAM_FUZZY_IGNORE |
1301                                       NM_SETTING_PARAM_INFERRABLE |
1302                                       G_PARAM_STATIC_STRINGS));
1303
1304         /**
1305          * NMSettingConnection:secondaries:
1306          *
1307          * List of connection UUIDs that should be activated when the base
1308          * connection itself is activated. Currently only VPN connections are
1309          * supported.
1310          *
1311          * Since: 0.9.8
1312          **/
1313         g_object_class_install_property
1314                 (object_class, PROP_SECONDARIES,
1315                  _nm_param_spec_specialized (NM_SETTING_CONNECTION_SECONDARIES, "", "",
1316                                              DBUS_TYPE_G_LIST_OF_STRING,
1317                                              G_PARAM_READWRITE |
1318                                              NM_SETTING_PARAM_FUZZY_IGNORE |
1319                                              G_PARAM_STATIC_STRINGS));
1320
1321         /**
1322          * NMSettingConnection:gateway-ping-timeout:
1323          *
1324          * If greater than zero, delay success of IP addressing until either the
1325          * timeout is reached, or an IP gateway replies to a ping.
1326          *
1327          * Since: 0.9.10
1328          **/
1329         g_object_class_install_property
1330                 (object_class, PROP_GATEWAY_PING_TIMEOUT,
1331                  g_param_spec_uint (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, "", "",
1332                                     0, 30, 0,
1333                                     G_PARAM_READWRITE |
1334                                     G_PARAM_CONSTRUCT |
1335                                     G_PARAM_STATIC_STRINGS));
1336 }