libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()
[NetworkManager.git] / libnm-core / nm-setting-ip4-config.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 2014 Red Hat, Inc.
20  */
21
22 #include "nm-default.h"
23
24 #include <string.h>
25
26 #include "nm-setting-ip4-config.h"
27 #include "nm-setting-private.h"
28
29 /**
30  * SECTION:nm-setting-ip4-config
31  * @short_description: Describes IPv4 addressing, routing, and name service properties
32  *
33  * The #NMSettingIP4Config object is a #NMSetting subclass that describes
34  * properties related to IPv4 addressing, routing, and Domain Name Service.
35  *
36  * #NMSettingIP4Config has few properties or methods of its own; it inherits
37  * almost everything from #NMSettingIPConfig.
38  *
39  * NetworkManager supports 5 values for the #NMSettingIPConfig:method property
40  * for IPv4.  If "auto" is specified then the appropriate automatic method
41  * (DHCP, PPP, etc) is used for the interface and most other properties can be
42  * left unset.  If "link-local" is specified, then a link-local address in the
43  * 169.254/16 range will be assigned to the interface.  If "manual" is
44  * specified, static IP addressing is used and at least one IP address must be
45  * given in the "addresses" property.  If "shared" is specified (indicating that
46  * this connection will provide network access to other computers) then the
47  * interface is assigned an address in the 10.42.x.1/24 range and a DHCP and
48  * forwarding DNS server are started, and the interface is NAT-ed to the current
49  * default network connection.  "disabled" means IPv4 will not be used on this
50  * connection.
51  **/
52
53 G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING_IP_CONFIG,
54                          _nm_register_setting (IP4_CONFIG, 4))
55 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
56
57 #define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))
58
59 typedef struct {
60         char *dhcp_client_id;
61         char *dhcp_fqdn;
62 } NMSettingIP4ConfigPrivate;
63
64 enum {
65         PROP_0,
66         PROP_DHCP_CLIENT_ID,
67         PROP_DHCP_FQDN,
68
69         LAST_PROP
70 };
71
72 /**
73  * nm_setting_ip4_config_new:
74  *
75  * Creates a new #NMSettingIP4Config object with default values.
76  *
77  * Returns: (transfer full): the new empty #NMSettingIP4Config object
78  **/
79 NMSetting *
80 nm_setting_ip4_config_new (void)
81 {
82         return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
83 }
84
85 /**
86  * nm_setting_ip4_config_get_dhcp_client_id:
87  * @setting: the #NMSettingIP4Config
88  *
89  * Returns the value contained in the #NMSettingIP4Config:dhcp-client-id
90  * property.
91  *
92  * Returns: the configured Client ID to send to the DHCP server when requesting
93  * addresses via DHCP.
94  **/
95 const char *
96 nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
97 {
98         g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
99
100         return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
101 }
102
103 /**
104  * nm_setting_ip4_config_get_dhcp_fqdn:
105  * @setting: the #NMSettingIP4Config
106  *
107  * Returns the value contained in the #NMSettingIP4Config:dhcp-fqdn
108  * property.
109  *
110  * Returns: the configured FQDN to send to the DHCP server
111  *
112  * Since: 1.2
113  **/
114 const char *
115 nm_setting_ip4_config_get_dhcp_fqdn (NMSettingIP4Config *setting)
116 {
117         g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
118
119         return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_fqdn;
120 }
121
122 static gboolean
123 verify (NMSetting *setting, NMConnection *connection, GError **error)
124 {
125         NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
126         NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
127         NMSettingVerifyResult ret;
128         const char *method;
129
130         ret = NM_SETTING_CLASS (nm_setting_ip4_config_parent_class)->verify (setting, connection, error);
131         if (ret != NM_SETTING_VERIFY_SUCCESS)
132                 return ret;
133
134         method = nm_setting_ip_config_get_method (s_ip);
135         /* Base class already checked that it exists */
136         g_assert (method);
137
138         if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
139                 if (nm_setting_ip_config_get_num_addresses (s_ip) == 0) {
140                         g_set_error (error,
141                                      NM_CONNECTION_ERROR,
142                                      NM_CONNECTION_ERROR_MISSING_PROPERTY,
143                                      _("this property cannot be empty for '%s=%s'"),
144                                      NM_SETTING_IP_CONFIG_METHOD, method);
145                         g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
146                         return FALSE;
147                 }
148         } else if (   !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
149                    || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
150                    || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
151                 if (nm_setting_ip_config_get_num_dns (s_ip) > 0) {
152                         g_set_error (error,
153                                      NM_CONNECTION_ERROR,
154                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
155                                      _("this property is not allowed for '%s=%s'"),
156                                      NM_SETTING_IP_CONFIG_METHOD, method);
157                         g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS);
158                         return FALSE;
159                 }
160
161                 if (nm_setting_ip_config_get_num_dns_searches (s_ip) > 0) {
162                         g_set_error (error,
163                                      NM_CONNECTION_ERROR,
164                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
165                                      _("this property is not allowed for '%s=%s'"),
166                                      NM_SETTING_IP_CONFIG_METHOD, method);
167                         g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS_SEARCH);
168                         return FALSE;
169                 }
170
171                 /* Shared allows IP addresses; link-local and disabled do not */
172                 if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
173                         if (nm_setting_ip_config_get_num_addresses (s_ip) > 0) {
174                                 g_set_error (error,
175                                              NM_CONNECTION_ERROR,
176                                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
177                                              _("this property is not allowed for '%s=%s'"),
178                                              NM_SETTING_IP_CONFIG_METHOD, method);
179                                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
180                                 return FALSE;
181                         }
182                 }
183         } else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
184                 /* nothing to do */
185         } else {
186                 g_set_error_literal (error,
187                                      NM_CONNECTION_ERROR,
188                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
189                                      _("property is invalid"));
190                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD);
191                 return FALSE;
192         }
193
194         if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
195                 g_set_error_literal (error,
196                                      NM_CONNECTION_ERROR,
197                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
198                                      _("property is empty"));
199                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID);
200                 return FALSE;
201         }
202
203         if (priv->dhcp_fqdn && !*priv->dhcp_fqdn) {
204                 g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
205                                      _("property is empty"));
206                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN);
207                 return FALSE;
208         }
209
210         if (priv->dhcp_fqdn && !strchr (priv->dhcp_fqdn, '.')) {
211                 g_set_error (error,
212                              NM_CONNECTION_ERROR,
213                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
214                              _("'%s' is not a valid FQDN"), priv->dhcp_fqdn);
215                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN);
216                 return FALSE;
217         }
218
219         if (priv->dhcp_fqdn && nm_setting_ip_config_get_dhcp_hostname (s_ip)) {
220                 g_set_error_literal (error,
221                                      NM_CONNECTION_ERROR,
222                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
223                                      _("property cannot be set when dhcp-hostname is also set"));
224                 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN);
225                 return FALSE;
226         }
227
228         return TRUE;
229 }
230
231 static void
232 nm_setting_ip4_config_init (NMSettingIP4Config *setting)
233 {
234 }
235
236 static void
237 finalize (GObject *object)
238 {
239         NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (object);
240
241         g_free (priv->dhcp_client_id);
242         g_free (priv->dhcp_fqdn);
243
244         G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
245 }
246
247 static void
248 set_property (GObject *object, guint prop_id,
249               const GValue *value, GParamSpec *pspec)
250 {
251         NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (object);
252
253         switch (prop_id) {
254         case PROP_DHCP_CLIENT_ID:
255                 g_free (priv->dhcp_client_id);
256                 priv->dhcp_client_id = g_value_dup_string (value);
257                 break;
258         case PROP_DHCP_FQDN:
259                 g_free (priv->dhcp_fqdn);
260                 priv->dhcp_fqdn = g_value_dup_string (value);
261                 break;
262         default:
263                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264                 break;
265         }
266 }
267
268 static void
269 get_property (GObject *object, guint prop_id,
270               GValue *value, GParamSpec *pspec)
271 {
272         NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (object);
273
274         switch (prop_id) {
275         case PROP_DHCP_CLIENT_ID:
276                 g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (s_ip4));
277                 break;
278         case PROP_DHCP_FQDN:
279                 g_value_set_string (value, nm_setting_ip4_config_get_dhcp_fqdn (s_ip4));
280                 break;
281         default:
282                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283                 break;
284         }
285 }
286
287 static GVariant *
288 ip4_dns_to_dbus (const GValue *prop_value)
289 {
290         return nm_utils_ip4_dns_to_variant (g_value_get_boxed (prop_value));
291 }
292
293 static void
294 ip4_dns_from_dbus (GVariant *dbus_value,
295                    GValue *prop_value)
296 {
297         g_value_take_boxed (prop_value, nm_utils_ip4_dns_from_variant (dbus_value));
298 }
299
300 static GVariant *
301 ip4_addresses_get (NMSetting  *setting,
302                    const char *property)
303 {
304         GPtrArray *addrs;
305         const char *gateway;
306         GVariant *ret;
307
308         g_object_get (setting, property, &addrs, NULL);
309         gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
310         ret = nm_utils_ip4_addresses_to_variant (addrs, gateway);
311         g_ptr_array_unref (addrs);
312
313         return ret;
314 }
315
316 static gboolean
317 ip4_addresses_set (NMSetting  *setting,
318                    GVariant   *connection_dict,
319                    const char *property,
320                    GVariant   *value,
321                    NMSettingParseFlags parse_flags,
322                    GError    **error)
323 {
324         GPtrArray *addrs;
325         GVariant *s_ip4;
326         char **labels, *gateway = NULL;
327         int i;
328
329         /* FIXME: properly handle errors */
330
331         if (!_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "address-data"))
332                 return TRUE;
333
334         addrs = nm_utils_ip4_addresses_from_variant (value, &gateway);
335
336         s_ip4 = g_variant_lookup_value (connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
337         if (g_variant_lookup (s_ip4, "address-labels", "^as", &labels)) {
338                 for (i = 0; i < addrs->len && labels[i]; i++)
339                         if (*labels[i])
340                                 nm_ip_address_set_attribute (addrs->pdata[i], "label", g_variant_new_string (labels[i]));
341                 g_strfreev (labels);
342         }
343         g_variant_unref (s_ip4);
344
345         g_object_set (setting,
346                       NM_SETTING_IP_CONFIG_ADDRESSES, addrs,
347                       NM_SETTING_IP_CONFIG_GATEWAY, gateway,
348                       NULL);
349         g_ptr_array_unref (addrs);
350         g_free (gateway);
351         return TRUE;
352 }
353
354 static GVariant *
355 ip4_address_labels_get (NMSetting    *setting,
356                         NMConnection *connection,
357                         const char   *property)
358 {
359         NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
360         gboolean have_labels = FALSE;
361         GPtrArray *labels;
362         GVariant *ret;
363         int num_addrs, i;
364
365         num_addrs = nm_setting_ip_config_get_num_addresses (s_ip);
366         for (i = 0; i < num_addrs; i++) {
367                 NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
368                 GVariant *label = nm_ip_address_get_attribute (addr, "label");
369
370                 if (label) {
371                         have_labels = TRUE;
372                         break;
373                 }
374         }
375         if (!have_labels)
376                 return NULL;
377
378         labels = g_ptr_array_sized_new (num_addrs);
379         for (i = 0; i < num_addrs; i++) {
380                 NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
381                 GVariant *label = nm_ip_address_get_attribute (addr, "label");
382
383                 g_ptr_array_add (labels, (char *) (label ? g_variant_get_string (label, NULL) : ""));
384         }
385
386         ret = g_variant_new_strv ((const char * const *) labels->pdata, labels->len);
387         g_ptr_array_unref (labels);
388
389         return ret;
390 }
391
392 static GVariant *
393 ip4_address_data_get (NMSetting    *setting,
394                       NMConnection *connection,
395                       const char   *property)
396 {
397         GPtrArray *addrs;
398         GVariant *ret;
399
400         g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
401         ret = nm_utils_ip_addresses_to_variant (addrs);
402         g_ptr_array_unref (addrs);
403
404         return ret;
405 }
406
407 static gboolean
408 ip4_address_data_set (NMSetting  *setting,
409                       GVariant   *connection_dict,
410                       const char *property,
411                       GVariant   *value,
412                       NMSettingParseFlags parse_flags,
413                       GError    **error)
414 {
415         GPtrArray *addrs;
416
417         /* FIXME: properly handle errors */
418
419         /* Ignore 'address-data' if we're going to process 'addresses' */
420         if (_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "address-data"))
421                 return TRUE;
422
423         addrs = nm_utils_ip_addresses_from_variant (value, AF_INET);
424         g_object_set (setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
425         g_ptr_array_unref (addrs);
426         return TRUE;
427 }
428
429 static GVariant *
430 ip4_routes_get (NMSetting  *setting,
431                 const char *property)
432 {
433         GPtrArray *routes;
434         GVariant *ret;
435
436         g_object_get (setting, property, &routes, NULL);
437         ret = nm_utils_ip4_routes_to_variant (routes);
438         g_ptr_array_unref (routes);
439
440         return ret;
441 }
442
443 static gboolean
444 ip4_routes_set (NMSetting  *setting,
445                 GVariant   *connection_dict,
446                 const char *property,
447                 GVariant   *value,
448                 NMSettingParseFlags parse_flags,
449                 GError    **error)
450 {
451         GPtrArray *routes;
452
453         /* FIXME: properly handle errors */
454
455         if (!_nm_setting_use_legacy_property (setting, connection_dict, "routes", "route-data"))
456                 return TRUE;
457
458         routes = nm_utils_ip4_routes_from_variant (value);
459         g_object_set (setting, property, routes, NULL);
460         g_ptr_array_unref (routes);
461         return TRUE;
462 }
463
464 static GVariant *
465 ip4_route_data_get (NMSetting    *setting,
466                     NMConnection *connection,
467                     const char   *property)
468 {
469         GPtrArray *routes;
470         GVariant *ret;
471
472         g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
473         ret = nm_utils_ip_routes_to_variant (routes);
474         g_ptr_array_unref (routes);
475
476         return ret;
477 }
478
479 static gboolean
480 ip4_route_data_set (NMSetting  *setting,
481                     GVariant   *connection_dict,
482                     const char *property,
483                     GVariant   *value,
484                     NMSettingParseFlags parse_flags,
485                     GError    **error)
486 {
487         GPtrArray *routes;
488
489         /* FIXME: properly handle errors */
490
491         /* Ignore 'route-data' if we're going to process 'routes' */
492         if (_nm_setting_use_legacy_property (setting, connection_dict, "routes", "route-data"))
493                 return TRUE;
494
495         routes = nm_utils_ip_routes_from_variant (value, AF_INET);
496         g_object_set (setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);
497         g_ptr_array_unref (routes);
498         return TRUE;
499 }
500
501
502 static void
503 nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
504 {
505         NMSettingClass *setting_class = NM_SETTING_CLASS (ip4_class);
506         GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
507
508         g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
509
510         /* virtual methods */
511         object_class->set_property = set_property;
512         object_class->get_property = get_property;
513         object_class->finalize     = finalize;
514         setting_class->verify = verify;
515
516         /* properties */
517
518         /* ---ifcfg-rh---
519          * property: method
520          * variable: BOOTPROTO
521          * format:   string
522          * values:   none, dhcp (bootp), static, ibft, autoip, shared
523          * default:  none
524          * description: Method used for IPv4 protocol configuration.
525          * ---end---
526          */
527
528         /* ---keyfile---
529          * property: dns
530          * format: list of DNS IP addresses
531          * description: List of DNS servers.
532          * example: dns=1.2.3.4;8.8.8.8;8.8.4.4;
533          * ---end---
534          * ---ifcfg-rh---
535          * property: dns
536          * variable: DNS1, DNS2, ...
537          * format:   string
538          * description: List of DNS servers. Even if NetworkManager supports many DNS
539          *   servers, initscripts and resolver only care about the first three, usually.
540          * example: DNS1=1.2.3.4 DNS2=10.0.0.254 DNS3=8.8.8.8
541          * ---end---
542          */
543
544         /* ---ifcfg-rh---
545          * property: dns-search
546          * variable: DOMAIN
547          * format:   string (space-separated domains)
548          * description: List of DNS search domains.
549          * ---end---
550          */
551
552         /* ---keyfile---
553          * property: addresses
554          * variable: address1, address2, ...
555          * format: address/plen
556          * description: List of static IP addresses.
557          * example: address1=192.168.100.100/24 address2=10.1.1.5/24
558          * ---end---
559          * ---ifcfg-rh---
560          * property: addresses
561          * variable: IPADDR, PREFIX, IPADDR1, PREFIX1, ...
562          * description: List of static IP addresses.
563          * example: IPADDR=10.5.5.23 PREFIX=24 IPADDR1=1.1.1.2 PREFIX1=16
564          * ---end---
565          */
566
567         /* ---keyfile---
568          * property: gateway
569          * variable: gateway
570          * format: string
571          * description: Gateway IP addresses as a string.
572          * example: gateway=192.168.100.1
573          * ---end---
574          * ---ifcfg-rh---
575          * property: gateway
576          * variable: GATEWAY
577          * description: Gateway IP address.
578          * example: GATEWAY=10.5.5.1
579          * ---end---
580          */
581
582         /* ---keyfile---
583          * property: routes
584          * variable: route1, route2, ...
585          * format: route/plen[,gateway,metric]
586          * description: List of IP routes.
587          * example: route1=8.8.8.0/24,10.1.1.1,77
588          *   route2=7.7.0.0/16
589          * ---end---
590          * ---ifcfg-rh---
591          * property: routes
592          * variable: ADDRESS1, NETMASK1, GATEWAY1, METRIC1, ...
593          * description: List of static routes. They are not stored in ifcfg-* file,
594          *   but in route-* file instead.
595          * ---end---
596          */
597
598         /* ---ifcfg-rh---
599          * property: ignore-auto-routes
600          * variable: PEERROUTES(+)
601          * default: yes
602          * description: PEERROUTES has the opposite meaning as 'ignore-auto-routes' property.
603          * ---end---
604          */
605
606         /* ---ifcfg-rh---
607          * property: ignore-auto-dns
608          * variable: PEERDNS
609          * default: yes
610          * description: PEERDNS has the opposite meaning as 'ignore-auto-dns' property.
611          * ---end---
612          */
613
614         /* ---ifcfg-rh---
615          * property: dhcp-send-hostname
616          * variable: DHCP_SEND_HOSTNAME(+)
617          * default: yes
618          * description: Whether DHCP_HOSTNAME should be sent to the DHCP server.
619          * ---end---
620          */
621
622         /* ---ifcfg-rh---
623          * property: dhcp-hostname
624          * variable: DHCP_HOSTNAME
625          * description: Hostname to send to the DHCP server. When both DHCP_HOSTNAME and
626          *    DHCP_FQDN are specified only the latter is used.
627          * ---end---
628          */
629
630         /* ---ifcfg-rh---
631          * property: never-default
632          * variable: DEFROUTE (GATEWAYDEV in /etc/sysconfig/network)
633          * default: yes
634          * description: DEFROUTE=no tells NetworkManager that this connection
635          *   should not be assigned the default route. DEFROUTE has the opposite
636          *   meaning as 'never-default' property.
637          * ---end---
638          */
639
640         /* ---ifcfg-rh---
641          * property: may-fail
642          * variable: IPV4_FAILURE_FATAL(+)
643          * default: no
644          * description: IPV4_FAILURE_FATAL has the opposite meaning as 'may-fail' property.
645          * ---end---
646          */
647
648         /* ---ifcfg-rh---
649          * property: route-metric
650          * variable: IPV4_ROUTE_METRIC(+)
651          * default: -1
652          * description: IPV4_ROUTE_METRIC is the default IPv4 metric for routes on this connection.
653          *   If set to -1, a default metric based on the device type is used.
654          * ---end---
655          */
656
657         /**
658          * NMSettingIP4Config:dhcp-client-id:
659          *
660          * A string sent to the DHCP server to identify the local machine which the
661          * DHCP server may use to customize the DHCP lease and options.
662          **/
663         /* ---ifcfg-rh---
664          * property: dhcp-client-id
665          * variable: DHCP_CLIENT_ID(+)
666          * description: A string sent to the DHCP server to identify the local machine.
667          * example: DHCP_CLIENT_ID=ax-srv-1
668          * ---end---
669          */
670         g_object_class_install_property
671                 (object_class, PROP_DHCP_CLIENT_ID,
672                  g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
673                                       NULL,
674                                       G_PARAM_READWRITE |
675                                       G_PARAM_STATIC_STRINGS));
676
677         /* ---ifcfg-rh---
678          * property: dad-timeout
679          * variable: ARPING_WAIT
680          * default: missing variable means global default (config override or 3)
681          * description: Timeout (in seconds) for performing DAD before configuring
682          * IPv4 addresses. 0 turns off the DAD completely, -1 means default value.
683          * example: ARPING_WAIT=2
684          * ---end---
685          */
686
687         /* ---ifcfg-rh---
688          * property: dhcp-timeout
689          * variable: IPV4_DHCP_TIMEOUT(+)
690          * description: A timeout after which the DHCP transaction fails in case of no response.
691          * example: IPV4_DHCP_TIMEOUT=10
692          * ---end---
693          */
694
695         /**
696          * NMSettingIP4Config:dhcp-fqdn:
697          *
698          * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the
699          * specified FQDN will be sent to the DHCP server when acquiring a lease. This
700          * property and #NMSettingIPConfig:dhcp-hostname are mutually exclusive and
701          * cannot be set at the same time.
702          *
703          * Since: 1.2
704          */
705         /* ---ifcfg-rh---
706          * property: dhcp-fqdn
707          * variable: DHCP_FQDN
708          * description: FQDN to send to the DHCP server. When both DHCP_HOSTNAME and
709          *    DHCP_FQDN are specified only the latter is used.
710          * example: DHCP_FQDN=foo.bar.com
711          * ---end---
712          */
713         g_object_class_install_property
714                 (object_class, PROP_DHCP_FQDN,
715                  g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_FQDN, "", "",
716                                       NULL,
717                                       G_PARAM_READWRITE |
718                                       G_PARAM_STATIC_STRINGS));
719
720         /* IP4-specific property overrides */
721
722         /* ---dbus---
723          * property: dns
724          * format: array of uint32
725          * description: Array of IP addresses of DNS servers (as network-byte-order
726          *   integers)
727          * ---end---
728          */
729         _nm_setting_class_transform_property (setting_class,
730                                               NM_SETTING_IP_CONFIG_DNS,
731                                               G_VARIANT_TYPE ("au"),
732                                               ip4_dns_to_dbus,
733                                               ip4_dns_from_dbus);
734
735         /* ---dbus---
736          * property: addresses
737          * format: array of array of uint32
738          * description: Deprecated in favor of the 'address-data' and 'gateway'
739          *   properties, but this can be used for backward-compatibility with older
740          *   daemons. Note that if you send this property the daemon will ignore
741          *   'address-data' and 'gateway'.
742          *
743          *   Array of IPv4 address structures.  Each IPv4 address structure is
744          *   composed of 3 32-bit values; the first being the IPv4 address (network
745          *   byte order), the second the prefix (1 - 32), and last the IPv4 gateway
746          *   (network byte order). The gateway may be left as 0 if no gateway exists
747          *   for that subnet.
748          * ---end---
749          */
750         _nm_setting_class_override_property (setting_class,
751                                              NM_SETTING_IP_CONFIG_ADDRESSES,
752                                              G_VARIANT_TYPE ("aau"),
753                                              ip4_addresses_get,
754                                              ip4_addresses_set,
755                                              NULL);
756
757         _nm_setting_class_add_dbus_only_property (setting_class,
758                                                   "address-labels",
759                                                   G_VARIANT_TYPE_STRING_ARRAY,
760                                                   ip4_address_labels_get,
761                                                   NULL);
762
763         /* ---dbus---
764          * property: address-data
765          * format: array of vardict
766          * description: Array of IPv4 addresses. Each address dictionary contains at
767          *   least 'address' and 'prefix' entries, containing the IP address as a
768          *   string, and the prefix length as a uint32. Additional attributes may
769          *   also exist on some addresses.
770          * ---end---
771          */
772         _nm_setting_class_add_dbus_only_property (setting_class,
773                                                   "address-data",
774                                                   G_VARIANT_TYPE ("aa{sv}"),
775                                                   ip4_address_data_get,
776                                                   ip4_address_data_set);
777
778         /* ---dbus---
779          * property: routes
780          * format: array of array of uint32
781          * description: Deprecated in favor of the 'route-data' property, but this
782          *   can be used for backward-compatibility with older daemons. Note that if
783          *   you send this property the daemon will ignore 'route-data'.
784          *
785          *   Array of IPv4 route structures.  Each IPv4 route structure is composed
786          *   of 4 32-bit values; the first being the destination IPv4 network or
787          *   address (network byte order), the second the destination network or
788          *   address prefix (1 - 32), the third being the next-hop (network byte
789          *   order) if any, and the fourth being the route metric. If the metric is
790          *   0, NM will choose an appropriate default metric for the device. (There
791          *   is no way to explicitly specify an actual metric of 0 with this
792          *   property.)
793          * ---end---
794          */
795         _nm_setting_class_override_property (setting_class,
796                                              NM_SETTING_IP_CONFIG_ROUTES,
797                                              G_VARIANT_TYPE ("aau"),
798                                              ip4_routes_get,
799                                              ip4_routes_set,
800                                              NULL);
801
802         /* ---dbus---
803          * property: route-data
804          * format: array of vardict
805          * description: Array of IPv4 routes. Each route dictionary contains at
806          *   least 'dest' and 'prefix' entries, containing the destination IP
807          *   address as a string, and the prefix length as a uint32. Most routes
808          *   will also have a 'gateway' entry, containing the gateway IP address as
809          *   a string. If the route has a 'metric' entry (containing a uint32), that
810          *   will be used as the metric for the route (otherwise NM will pick a
811          *   default value appropriate to the device). Additional attributes may
812          *   also exist on some routes.
813          * ---end---
814          */
815         _nm_setting_class_add_dbus_only_property (setting_class,
816                                                   "route-data",
817                                                   G_VARIANT_TYPE ("aa{sv}"),
818                                                   ip4_route_data_get,
819                                                   ip4_route_data_set);
820
821 }