b0308e7162b5062a51ec19bfd626e143b4a83ae4
[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 void
317 ip4_addresses_set (NMSetting  *setting,
318                    GVariant   *connection_dict,
319                    const char *property,
320                    GVariant   *value)
321 {
322         GPtrArray *addrs;
323         GVariant *s_ip4;
324         char **labels, *gateway = NULL;
325         int i;
326
327         if (!_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "address-data"))
328                 return;
329
330         addrs = nm_utils_ip4_addresses_from_variant (value, &gateway);
331
332         s_ip4 = g_variant_lookup_value (connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
333         if (g_variant_lookup (s_ip4, "address-labels", "^as", &labels)) {
334                 for (i = 0; i < addrs->len && labels[i]; i++)
335                         if (*labels[i])
336                                 nm_ip_address_set_attribute (addrs->pdata[i], "label", g_variant_new_string (labels[i]));
337                 g_strfreev (labels);
338         }
339         g_variant_unref (s_ip4);
340
341         g_object_set (setting,
342                       NM_SETTING_IP_CONFIG_ADDRESSES, addrs,
343                       NM_SETTING_IP_CONFIG_GATEWAY, gateway,
344                       NULL);
345         g_ptr_array_unref (addrs);
346         g_free (gateway);
347 }
348
349 static GVariant *
350 ip4_address_labels_get (NMSetting    *setting,
351                         NMConnection *connection,
352                         const char   *property)
353 {
354         NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
355         gboolean have_labels = FALSE;
356         GPtrArray *labels;
357         GVariant *ret;
358         int num_addrs, i;
359
360         num_addrs = nm_setting_ip_config_get_num_addresses (s_ip);
361         for (i = 0; i < num_addrs; i++) {
362                 NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
363                 GVariant *label = nm_ip_address_get_attribute (addr, "label");
364
365                 if (label) {
366                         have_labels = TRUE;
367                         break;
368                 }
369         }
370         if (!have_labels)
371                 return NULL;
372
373         labels = g_ptr_array_sized_new (num_addrs);
374         for (i = 0; i < num_addrs; i++) {
375                 NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
376                 GVariant *label = nm_ip_address_get_attribute (addr, "label");
377
378                 g_ptr_array_add (labels, (char *) (label ? g_variant_get_string (label, NULL) : ""));
379         }
380
381         ret = g_variant_new_strv ((const char * const *) labels->pdata, labels->len);
382         g_ptr_array_unref (labels);
383
384         return ret;
385 }
386
387 static GVariant *
388 ip4_address_data_get (NMSetting    *setting,
389                       NMConnection *connection,
390                       const char   *property)
391 {
392         GPtrArray *addrs;
393         GVariant *ret;
394
395         g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
396         ret = nm_utils_ip_addresses_to_variant (addrs);
397         g_ptr_array_unref (addrs);
398
399         return ret;
400 }
401
402 static void
403 ip4_address_data_set (NMSetting  *setting,
404                       GVariant   *connection_dict,
405                       const char *property,
406                       GVariant   *value)
407 {
408         GPtrArray *addrs;
409
410         /* Ignore 'address-data' if we're going to process 'addresses' */
411         if (_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "address-data"))
412                 return;
413
414         addrs = nm_utils_ip_addresses_from_variant (value, AF_INET);
415         g_object_set (setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
416         g_ptr_array_unref (addrs);
417 }
418
419 static GVariant *
420 ip4_routes_get (NMSetting  *setting,
421                 const char *property)
422 {
423         GPtrArray *routes;
424         GVariant *ret;
425
426         g_object_get (setting, property, &routes, NULL);
427         ret = nm_utils_ip4_routes_to_variant (routes);
428         g_ptr_array_unref (routes);
429
430         return ret;
431 }
432
433 static void
434 ip4_routes_set (NMSetting  *setting,
435                 GVariant   *connection_dict,
436                 const char *property,
437                 GVariant   *value)
438 {
439         GPtrArray *routes;
440
441         if (!_nm_setting_use_legacy_property (setting, connection_dict, "routes", "route-data"))
442                 return;
443
444         routes = nm_utils_ip4_routes_from_variant (value);
445         g_object_set (setting, property, routes, NULL);
446         g_ptr_array_unref (routes);
447 }
448
449 static GVariant *
450 ip4_route_data_get (NMSetting    *setting,
451                     NMConnection *connection,
452                     const char   *property)
453 {
454         GPtrArray *routes;
455         GVariant *ret;
456
457         g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
458         ret = nm_utils_ip_routes_to_variant (routes);
459         g_ptr_array_unref (routes);
460
461         return ret;
462 }
463
464 static void
465 ip4_route_data_set (NMSetting  *setting,
466                     GVariant   *connection_dict,
467                     const char *property,
468                     GVariant   *value)
469 {
470         GPtrArray *routes;
471
472         /* Ignore 'route-data' if we're going to process 'routes' */
473         if (_nm_setting_use_legacy_property (setting, connection_dict, "routes", "route-data"))
474                 return;
475
476         routes = nm_utils_ip_routes_from_variant (value, AF_INET);
477         g_object_set (setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);
478         g_ptr_array_unref (routes);
479 }
480
481
482 static void
483 nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
484 {
485         NMSettingClass *setting_class = NM_SETTING_CLASS (ip4_class);
486         GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
487
488         g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
489
490         /* virtual methods */
491         object_class->set_property = set_property;
492         object_class->get_property = get_property;
493         object_class->finalize     = finalize;
494         setting_class->verify = verify;
495
496         /* properties */
497
498         /* ---ifcfg-rh---
499          * property: method
500          * variable: BOOTPROTO
501          * format:   string
502          * values:   none, dhcp (bootp), static, ibft, autoip, shared
503          * default:  none
504          * description: Method used for IPv4 protocol configuration.
505          * ---end---
506          */
507
508         /* ---keyfile---
509          * property: dns
510          * format: list of DNS IP addresses
511          * description: List of DNS servers.
512          * example: dns=1.2.3.4;8.8.8.8;8.8.4.4;
513          * ---end---
514          * ---ifcfg-rh---
515          * property: dns
516          * variable: DNS1, DNS2, ...
517          * format:   string
518          * description: List of DNS servers. Even if NetworkManager supports many DNS
519          *   servers, initscripts and resolver only care about the first three, usually.
520          * example: DNS1=1.2.3.4 DNS2=10.0.0.254 DNS3=8.8.8.8
521          * ---end---
522          */
523
524         /* ---ifcfg-rh---
525          * property: dns-search
526          * variable: DOMAIN
527          * format:   string (space-separated domains)
528          * description: List of DNS search domains.
529          * ---end---
530          */
531
532         /* ---keyfile---
533          * property: addresses
534          * variable: address1, address2, ...
535          * format: address/plen
536          * description: List of static IP addresses.
537          * example: address1=192.168.100.100/24 address2=10.1.1.5/24
538          * ---end---
539          * ---ifcfg-rh---
540          * property: addresses
541          * variable: IPADDR, PREFIX, IPADDR1, PREFIX1, ...
542          * description: List of static IP addresses.
543          * example: IPADDR=10.5.5.23 PREFIX=24 IPADDR1=1.1.1.2 PREFIX1=16
544          * ---end---
545          */
546
547         /* ---keyfile---
548          * property: gateway
549          * variable: gateway
550          * format: string
551          * description: Gateway IP addresses as a string.
552          * example: gateway=192.168.100.1
553          * ---end---
554          * ---ifcfg-rh---
555          * property: gateway
556          * variable: GATEWAY
557          * description: Gateway IP address.
558          * example: GATEWAY=10.5.5.1
559          * ---end---
560          */
561
562         /* ---keyfile---
563          * property: routes
564          * variable: route1, route2, ...
565          * format: route/plen[,gateway,metric]
566          * description: List of IP routes.
567          * example: route1=8.8.8.0/24,10.1.1.1,77
568          *   route2=7.7.0.0/16
569          * ---end---
570          * ---ifcfg-rh---
571          * property: routes
572          * variable: ADDRESS1, NETMASK1, GATEWAY1, METRIC1, ...
573          * description: List of static routes. They are not stored in ifcfg-* file,
574          *   but in route-* file instead.
575          * ---end---
576          */
577
578         /* ---ifcfg-rh---
579          * property: ignore-auto-routes
580          * variable: PEERROUTES(+)
581          * default: yes
582          * description: PEERROUTES has the opposite meaning as 'ignore-auto-routes' property.
583          * ---end---
584          */
585
586         /* ---ifcfg-rh---
587          * property: ignore-auto-dns
588          * variable: PEERDNS
589          * default: yes
590          * description: PEERDNS has the opposite meaning as 'ignore-auto-dns' property.
591          * ---end---
592          */
593
594         /* ---ifcfg-rh---
595          * property: dhcp-send-hostname
596          * variable: DHCP_SEND_HOSTNAME(+)
597          * default: yes
598          * description: Whether DHCP_HOSTNAME should be sent to the DHCP server.
599          * ---end---
600          */
601
602         /* ---ifcfg-rh---
603          * property: dhcp-hostname
604          * variable: DHCP_HOSTNAME
605          * description: Hostname to send to the DHCP server. When both DHCP_HOSTNAME and
606          *    DHCP_FQDN are specified only the latter is used.
607          * ---end---
608          */
609
610         /* ---ifcfg-rh---
611          * property: never-default
612          * variable: DEFROUTE (GATEWAYDEV in /etc/sysconfig/network)
613          * default: yes
614          * description: DEFROUTE=no tells NetworkManager that this connection
615          *   should not be assigned the default route. DEFROUTE has the opposite
616          *   meaning as 'never-default' property.
617          * ---end---
618          */
619
620         /* ---ifcfg-rh---
621          * property: may-fail
622          * variable: IPV4_FAILURE_FATAL(+)
623          * default: no
624          * description: IPV4_FAILURE_FATAL has the opposite meaning as 'may-fail' property.
625          * ---end---
626          */
627
628         /* ---ifcfg-rh---
629          * property: route-metric
630          * variable: IPV4_ROUTE_METRIC(+)
631          * default: -1
632          * description: IPV4_ROUTE_METRIC is the default IPv4 metric for routes on this connection.
633          *   If set to -1, a default metric based on the device type is used.
634          * ---end---
635          */
636
637         /**
638          * NMSettingIP4Config:dhcp-client-id:
639          *
640          * A string sent to the DHCP server to identify the local machine which the
641          * DHCP server may use to customize the DHCP lease and options.
642          **/
643         /* ---ifcfg-rh---
644          * property: dhcp-client-id
645          * variable: DHCP_CLIENT_ID(+)
646          * description: A string sent to the DHCP server to identify the local machine.
647          * example: DHCP_CLIENT_ID=ax-srv-1
648          * ---end---
649          */
650         g_object_class_install_property
651                 (object_class, PROP_DHCP_CLIENT_ID,
652                  g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
653                                       NULL,
654                                       G_PARAM_READWRITE |
655                                       G_PARAM_STATIC_STRINGS));
656
657         /* ---ifcfg-rh---
658          * property: dad-timeout
659          * variable: ARPING_WAIT
660          * default: missing variable means global default (config override or 3)
661          * description: Timeout (in seconds) for performing DAD before configuring
662          * IPv4 addresses. 0 turns off the DAD completely, -1 means default value.
663          * example: ARPING_WAIT=2
664          * ---end---
665          */
666
667         /* ---ifcfg-rh---
668          * property: dhcp-timeout
669          * variable: IPV4_DHCP_TIMEOUT(+)
670          * description: A timeout after which the DHCP transaction fails in case of no response.
671          * example: IPV4_DHCP_TIMEOUT=10
672          * ---end---
673          */
674
675         /**
676          * NMSettingIP4Config:dhcp-fqdn:
677          *
678          * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the
679          * specified FQDN will be sent to the DHCP server when acquiring a lease. This
680          * property and #NMSettingIPConfig:dhcp-hostname are mutually exclusive and
681          * cannot be set at the same time.
682          *
683          * Since: 1.2
684          */
685         /* ---ifcfg-rh---
686          * property: dhcp-fqdn
687          * variable: DHCP_FQDN
688          * description: FQDN to send to the DHCP server. When both DHCP_HOSTNAME and
689          *    DHCP_FQDN are specified only the latter is used.
690          * example: DHCP_FQDN=foo.bar.com
691          * ---end---
692          */
693         g_object_class_install_property
694                 (object_class, PROP_DHCP_FQDN,
695                  g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_FQDN, "", "",
696                                       NULL,
697                                       G_PARAM_READWRITE |
698                                       G_PARAM_STATIC_STRINGS));
699
700         /* IP4-specific property overrides */
701
702         /* ---dbus---
703          * property: dns
704          * format: array of uint32
705          * description: Array of IP addresses of DNS servers (as network-byte-order
706          *   integers)
707          * ---end---
708          */
709         _nm_setting_class_transform_property (setting_class,
710                                               NM_SETTING_IP_CONFIG_DNS,
711                                               G_VARIANT_TYPE ("au"),
712                                               ip4_dns_to_dbus,
713                                               ip4_dns_from_dbus);
714
715         /* ---dbus---
716          * property: addresses
717          * format: array of array of uint32
718          * description: Deprecated in favor of the 'address-data' and 'gateway'
719          *   properties, but this can be used for backward-compatibility with older
720          *   daemons. Note that if you send this property the daemon will ignore
721          *   'address-data' and 'gateway'.
722          *
723          *   Array of IPv4 address structures.  Each IPv4 address structure is
724          *   composed of 3 32-bit values; the first being the IPv4 address (network
725          *   byte order), the second the prefix (1 - 32), and last the IPv4 gateway
726          *   (network byte order). The gateway may be left as 0 if no gateway exists
727          *   for that subnet.
728          * ---end---
729          */
730         _nm_setting_class_override_property (setting_class,
731                                              NM_SETTING_IP_CONFIG_ADDRESSES,
732                                              G_VARIANT_TYPE ("aau"),
733                                              ip4_addresses_get,
734                                              ip4_addresses_set,
735                                              NULL);
736
737         _nm_setting_class_add_dbus_only_property (setting_class,
738                                                   "address-labels",
739                                                   G_VARIANT_TYPE_STRING_ARRAY,
740                                                   ip4_address_labels_get,
741                                                   NULL);
742
743         /* ---dbus---
744          * property: address-data
745          * format: array of vardict
746          * description: Array of IPv4 addresses. Each address dictionary contains at
747          *   least 'address' and 'prefix' entries, containing the IP address as a
748          *   string, and the prefix length as a uint32. Additional attributes may
749          *   also exist on some addresses.
750          * ---end---
751          */
752         _nm_setting_class_add_dbus_only_property (setting_class,
753                                                   "address-data",
754                                                   G_VARIANT_TYPE ("aa{sv}"),
755                                                   ip4_address_data_get,
756                                                   ip4_address_data_set);
757
758         /* ---dbus---
759          * property: routes
760          * format: array of array of uint32
761          * description: Deprecated in favor of the 'route-data' property, but this
762          *   can be used for backward-compatibility with older daemons. Note that if
763          *   you send this property the daemon will ignore 'route-data'.
764          *
765          *   Array of IPv4 route structures.  Each IPv4 route structure is composed
766          *   of 4 32-bit values; the first being the destination IPv4 network or
767          *   address (network byte order), the second the destination network or
768          *   address prefix (1 - 32), the third being the next-hop (network byte
769          *   order) if any, and the fourth being the route metric. If the metric is
770          *   0, NM will choose an appropriate default metric for the device. (There
771          *   is no way to explicitly specify an actual metric of 0 with this
772          *   property.)
773          * ---end---
774          */
775         _nm_setting_class_override_property (setting_class,
776                                              NM_SETTING_IP_CONFIG_ROUTES,
777                                              G_VARIANT_TYPE ("aau"),
778                                              ip4_routes_get,
779                                              ip4_routes_set,
780                                              NULL);
781
782         /* ---dbus---
783          * property: route-data
784          * format: array of vardict
785          * description: Array of IPv4 routes. Each route dictionary contains at
786          *   least 'dest' and 'prefix' entries, containing the destination IP
787          *   address as a string, and the prefix length as a uint32. Most routes
788          *   will also have a 'gateway' entry, containing the gateway IP address as
789          *   a string. If the route has a 'metric' entry (containing a uint32), that
790          *   will be used as the metric for the route (otherwise NM will pick a
791          *   default value appropriate to the device). Additional attributes may
792          *   also exist on some routes.
793          * ---end---
794          */
795         _nm_setting_class_add_dbus_only_property (setting_class,
796                                                   "route-data",
797                                                   G_VARIANT_TYPE ("aa{sv}"),
798                                                   ip4_route_data_get,
799                                                   ip4_route_data_set);
800
801 }