1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
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.
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.
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.
19 * Copyright 2007 - 2014 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
26 #include <arpa/inet.h>
28 #include "nm-setting-ip-config.h"
29 #include "nm-setting-ip4-config.h"
30 #include "nm-setting-ip6-config.h"
32 #include "nm-setting-private.h"
33 #include "nm-utils-private.h"
36 * SECTION:nm-setting-ip-config
37 * @short_description: Abstract base class for IPv4 and IPv6
38 * addressing, routing, and name service properties
39 * @include: nm-setting-ip-config.h
40 * @see_also: #NMSettingIP4Config, #NMSettingIP6Config
42 * #NMSettingIPConfig is the abstract base class of
43 * #NMSettingIP4Config and #NMSettingIP6Config, providing properties
44 * related to IP addressing, routing, and Domain Name Service.
47 const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[] = {
48 { NM_SETTING_DNS_OPTION_DEBUG, FALSE, FALSE },
49 { NM_SETTING_DNS_OPTION_NDOTS, TRUE, FALSE },
50 { NM_SETTING_DNS_OPTION_TIMEOUT, TRUE, FALSE },
51 { NM_SETTING_DNS_OPTION_ATTEMPTS, TRUE, FALSE },
52 { NM_SETTING_DNS_OPTION_ROTATE, FALSE, FALSE },
53 { NM_SETTING_DNS_OPTION_NO_CHECK_NAMES, FALSE, FALSE },
54 { NM_SETTING_DNS_OPTION_INET6, FALSE, TRUE },
55 { NM_SETTING_DNS_OPTION_IP6_BYTESTRING, FALSE, TRUE },
56 { NM_SETTING_DNS_OPTION_IP6_DOTINT, FALSE, TRUE },
57 { NM_SETTING_DNS_OPTION_NO_IP6_DOTINT, FALSE, TRUE },
58 { NM_SETTING_DNS_OPTION_EDNS0, FALSE, FALSE },
59 { NM_SETTING_DNS_OPTION_SINGLE_REQUEST, FALSE, FALSE },
60 { NM_SETTING_DNS_OPTION_SINGLE_REQUEST_REOPEN, FALSE, FALSE },
61 { NM_SETTING_DNS_OPTION_NO_TLD_QUERY, FALSE, FALSE },
62 { NULL, FALSE, FALSE }
66 _addr_size (int family)
70 return sizeof (in_addr_t);
72 return sizeof (struct in6_addr);
74 g_return_val_if_reached (0);
79 canonicalize_ip (int family, const char *ip, gboolean null_any)
81 guint8 addr_bytes[sizeof (struct in6_addr)];
82 char addr_str[NM_UTILS_INET_ADDRSTRLEN];
88 if (family == AF_INET)
89 return g_strdup ("0.0.0.0");
90 if (family == AF_INET6)
91 return g_strdup ("::");
92 g_return_val_if_reached (NULL);
95 ret = inet_pton (family, ip, addr_bytes);
96 g_return_val_if_fail (ret == 1, NULL);
99 if (!memcmp (addr_bytes, &in6addr_any, _addr_size (family)))
103 return g_strdup (inet_ntop (family, addr_bytes, addr_str, sizeof (addr_str)));
107 canonicalize_ip_binary (int family, gconstpointer ip, gboolean null_any)
109 char string[NM_UTILS_INET_ADDRSTRLEN];
114 if (family == AF_INET)
115 return g_strdup ("0.0.0.0");
116 if (family == AF_INET6)
117 return g_strdup ("::");
118 g_return_val_if_reached (NULL);
121 if (!memcmp (ip, &in6addr_any, _addr_size (family)))
124 return g_strdup (inet_ntop (family, ip, string, sizeof (string)));
128 valid_ip (int family, const char *ip, GError **error)
131 g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
132 family == AF_INET ? _("Missing IPv4 address") : _("Missing IPv6 address"));
135 if (!nm_utils_ipaddr_valid (family, ip)) {
136 g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
137 family == AF_INET ? _("Invalid IPv4 address '%s'") : _("Invalid IPv6 address '%s'"),
145 valid_prefix (int family, guint prefix, GError **error, gboolean allow_zero_prefix)
147 if ( (family == AF_INET && prefix > 32)
148 || (family == AF_INET6 && prefix > 128)
149 || (!allow_zero_prefix && prefix == 0)) {
150 g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
151 family == AF_INET ? _("Invalid IPv4 address prefix '%u'") : _("Invalid IPv6 address prefix '%u'"),
160 valid_metric (gint64 metric, GError **error)
162 if (metric < -1 || metric > G_MAXUINT32) {
166 /* We can't concatenate G_GINT64_FORMAT into a translatable string */
167 g_snprintf (buf, sizeof (buf), "%" G_GINT64_FORMAT, metric);
168 g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
169 _("Invalid routing metric '%s'"), buf);
178 G_DEFINE_BOXED_TYPE (NMIPAddress, nm_ip_address, nm_ip_address_dup, nm_ip_address_unref)
186 GHashTable *attributes;
191 * @family: the IP address family (<literal>AF_INET</literal> or
192 * <literal>AF_INET6</literal>)
193 * @addr: the IP address
194 * @prefix: the address prefix length
195 * @error: location to store error, or %NULL
197 * Creates a new #NMIPAddress object.
199 * Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
202 nm_ip_address_new (int family,
203 const char *addr, guint prefix,
206 NMIPAddress *address;
208 g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
209 g_return_val_if_fail (addr != NULL, NULL);
211 if (!valid_ip (family, addr, error))
213 if (!valid_prefix (family, prefix, error, FALSE))
216 address = g_slice_new0 (NMIPAddress);
217 address->refcount = 1;
219 address->family = family;
220 address->address = canonicalize_ip (family, addr, FALSE);
221 address->prefix = prefix;
227 * nm_ip_address_new_binary:
228 * @family: the IP address family (<literal>AF_INET</literal> or
229 * <literal>AF_INET6</literal>)
230 * @addr: the IP address
231 * @prefix: the address prefix length
232 * @error: location to store error, or %NULL
234 * Creates a new #NMIPAddress object. @addr must point to a buffer of the
235 * correct size for @family.
237 * Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
240 nm_ip_address_new_binary (int family,
241 gconstpointer addr, guint prefix,
244 NMIPAddress *address;
245 char string[NM_UTILS_INET_ADDRSTRLEN];
247 g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
248 g_return_val_if_fail (addr != NULL, NULL);
250 if (!valid_prefix (family, prefix, error, FALSE))
253 address = g_slice_new0 (NMIPAddress);
254 address->refcount = 1;
256 address->family = family;
257 address->address = g_strdup (inet_ntop (family, addr, string, sizeof (string)));
258 address->prefix = prefix;
265 * @address: the #NMIPAddress
267 * Increases the reference count of the object.
270 nm_ip_address_ref (NMIPAddress *address)
272 g_return_if_fail (address != NULL);
273 g_return_if_fail (address->refcount > 0);
279 * nm_ip_address_unref:
280 * @address: the #NMIPAddress
282 * Decreases the reference count of the object. If the reference count
283 * reaches zero, the object will be destroyed.
286 nm_ip_address_unref (NMIPAddress *address)
288 g_return_if_fail (address != NULL);
289 g_return_if_fail (address->refcount > 0);
292 if (address->refcount == 0) {
293 g_free (address->address);
294 if (address->attributes)
295 g_hash_table_unref (address->attributes);
296 g_slice_free (NMIPAddress, address);
301 * nm_ip_address_equal:
302 * @address: the #NMIPAddress
303 * @other: the #NMIPAddress to compare @address to.
305 * Determines if two #NMIPAddress objects contain the same address and prefix
306 * (attributes are not compared).
308 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
311 nm_ip_address_equal (NMIPAddress *address, NMIPAddress *other)
313 g_return_val_if_fail (address != NULL, FALSE);
314 g_return_val_if_fail (address->refcount > 0, FALSE);
316 g_return_val_if_fail (other != NULL, FALSE);
317 g_return_val_if_fail (other->refcount > 0, FALSE);
319 if ( address->family != other->family
320 || address->prefix != other->prefix
321 || strcmp (address->address, other->address) != 0)
328 * @address: the #NMIPAddress
330 * Creates a copy of @address
332 * Returns: (transfer full): a copy of @address
335 nm_ip_address_dup (NMIPAddress *address)
339 g_return_val_if_fail (address != NULL, NULL);
340 g_return_val_if_fail (address->refcount > 0, NULL);
342 copy = nm_ip_address_new (address->family,
343 address->address, address->prefix,
345 if (address->attributes) {
350 g_hash_table_iter_init (&iter, address->attributes);
351 while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
352 nm_ip_address_set_attribute (copy, key, value);
359 * nm_ip_address_get_family:
360 * @address: the #NMIPAddress
362 * Gets the IP address family (eg, AF_INET) property of this address
365 * Returns: the IP address family
368 nm_ip_address_get_family (NMIPAddress *address)
370 g_return_val_if_fail (address != NULL, 0);
371 g_return_val_if_fail (address->refcount > 0, 0);
373 return address->family;
377 * nm_ip_address_get_address:
378 * @address: the #NMIPAddress
380 * Gets the IP address property of this address object.
382 * Returns: the IP address
385 nm_ip_address_get_address (NMIPAddress *address)
387 g_return_val_if_fail (address != NULL, NULL);
388 g_return_val_if_fail (address->refcount > 0, NULL);
390 return address->address;
394 * nm_ip_address_set_address:
395 * @address: the #NMIPAddress
396 * @addr: the IP address, as a string
398 * Sets the IP address property of this address object.
400 * @addr must be a valid address of @address's family. If you aren't sure you
401 * have a valid address, use nm_utils_ipaddr_valid() to check it.
404 nm_ip_address_set_address (NMIPAddress *address,
407 g_return_if_fail (address != NULL);
408 g_return_if_fail (addr != NULL);
409 g_return_if_fail (nm_utils_ipaddr_valid (address->family, addr));
411 g_free (address->address);
412 address->address = canonicalize_ip (address->family, addr, FALSE);
416 * nm_ip_address_get_address_binary: (skip)
417 * @address: the #NMIPAddress
418 * @addr: a buffer in which to store the address in binary format.
420 * Gets the IP address property of this address object.
422 * @addr must point to a buffer that is the correct size for @address's family.
425 nm_ip_address_get_address_binary (NMIPAddress *address,
428 g_return_if_fail (address != NULL);
429 g_return_if_fail (addr != NULL);
431 inet_pton (address->family, address->address, addr);
435 * nm_ip_address_set_address_binary: (skip)
436 * @address: the #NMIPAddress
437 * @addr: the address, in binary format
439 * Sets the IP address property of this address object.
441 * @addr must point to a buffer that is the correct size for @address's family.
444 nm_ip_address_set_address_binary (NMIPAddress *address,
447 char string[NM_UTILS_INET_ADDRSTRLEN];
449 g_return_if_fail (address != NULL);
450 g_return_if_fail (addr != NULL);
452 g_free (address->address);
453 address->address = g_strdup (inet_ntop (address->family, addr, string, sizeof (string)));
457 * nm_ip_address_get_prefix:
458 * @address: the #NMIPAddress
460 * Gets the IP address prefix (ie "24" or "30" etc) property of this address
463 * Returns: the IP address prefix
466 nm_ip_address_get_prefix (NMIPAddress *address)
468 g_return_val_if_fail (address != NULL, 0);
469 g_return_val_if_fail (address->refcount > 0, 0);
471 return address->prefix;
475 * nm_ip_address_set_prefix:
476 * @address: the #NMIPAddress
477 * @prefix: the IP address prefix
479 * Sets the IP address prefix property of this address object.
482 nm_ip_address_set_prefix (NMIPAddress *address,
485 g_return_if_fail (address != NULL);
486 g_return_if_fail (valid_prefix (address->family, prefix, NULL, FALSE));
488 address->prefix = prefix;
492 * nm_ip_address_get_attribute_names:
493 * @address: the #NMIPAddress
495 * Gets an array of attribute names defined on @address.
497 * Returns: (transfer full): a %NULL-terminated array of attribute names,
500 nm_ip_address_get_attribute_names (NMIPAddress *address)
506 g_return_val_if_fail (address != NULL, NULL);
508 names = g_ptr_array_new ();
510 if (address->attributes) {
511 g_hash_table_iter_init (&iter, address->attributes);
512 while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
513 g_ptr_array_add (names, g_strdup (key));
515 g_ptr_array_add (names, NULL);
517 return (char **) g_ptr_array_free (names, FALSE);
521 * nm_ip_address_get_attribute:
522 * @address: the #NMIPAddress
523 * @name: the name of an address attribute
525 * Gets the value of the attribute with name @name on @address
527 * Returns: (transfer none): the value of the attribute with name @name on
528 * @address, or %NULL if @address has no such attribute.
531 nm_ip_address_get_attribute (NMIPAddress *address, const char *name)
533 g_return_val_if_fail (address != NULL, NULL);
534 g_return_val_if_fail (name != NULL && *name != '\0', NULL);
536 if (address->attributes)
537 return g_hash_table_lookup (address->attributes, name);
543 * nm_ip_address_set_attribute:
544 * @address: the #NMIPAddress
545 * @name: the name of an address attribute
546 * @value: (transfer none) (allow-none): the value
548 * Sets or clears the named attribute on @address to the given value.
551 nm_ip_address_set_attribute (NMIPAddress *address, const char *name, GVariant *value)
553 g_return_if_fail (address != NULL);
554 g_return_if_fail (name != NULL && *name != '\0');
555 g_return_if_fail (strcmp (name, "address") != 0 && strcmp (name, "prefix") != 0);
557 if (!address->attributes) {
558 address->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
559 g_free, (GDestroyNotify) g_variant_unref);
563 g_hash_table_insert (address->attributes, g_strdup (name), g_variant_ref_sink (value));
565 g_hash_table_remove (address->attributes, name);
569 G_DEFINE_BOXED_TYPE (NMIPRoute, nm_ip_route, nm_ip_route_dup, nm_ip_route_unref)
580 GHashTable *attributes;
585 * @family: the IP address family (<literal>AF_INET</literal> or
586 * <literal>AF_INET6</literal>)
587 * @dest: the IP address of the route's destination
588 * @prefix: the address prefix length
589 * @next_hop: (allow-none): the IP address of the next hop (or %NULL)
590 * @metric: the route metric (or -1 for "default")
591 * @error: location to store error, or %NULL
593 * Creates a new #NMIPRoute object.
595 * Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
598 nm_ip_route_new (int family,
601 const char *next_hop,
607 g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
608 g_return_val_if_fail (dest, NULL);
610 if (!valid_ip (family, dest, error))
612 if (!valid_prefix (family, prefix, error, TRUE))
614 if (next_hop && !valid_ip (family, next_hop, error))
616 if (!valid_metric (metric, error))
619 route = g_slice_new0 (NMIPRoute);
622 route->family = family;
623 route->dest = canonicalize_ip (family, dest, FALSE);
624 route->prefix = prefix;
625 route->next_hop = canonicalize_ip (family, next_hop, TRUE);
626 route->metric = metric;
632 * nm_ip_route_new_binary:
633 * @family: the IP address family (<literal>AF_INET</literal> or
634 * <literal>AF_INET6</literal>)
635 * @dest: the IP address of the route's destination
636 * @prefix: the address prefix length
637 * @next_hop: (allow-none): the IP address of the next hop (or %NULL)
638 * @metric: the route metric (or -1 for "default")
639 * @error: location to store error, or %NULL
641 * Creates a new #NMIPRoute object. @dest and @next_hop (if non-%NULL) must
642 * point to buffers of the correct size for @family.
644 * Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
647 nm_ip_route_new_binary (int family,
650 gconstpointer next_hop,
656 g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
657 g_return_val_if_fail (dest, NULL);
659 if (!valid_prefix (family, prefix, error, TRUE))
661 if (!valid_metric (metric, error))
664 route = g_slice_new0 (NMIPRoute);
667 route->family = family;
668 route->dest = canonicalize_ip_binary (family, dest, FALSE);
669 route->prefix = prefix;
670 route->next_hop = canonicalize_ip_binary (family, next_hop, TRUE);
671 route->metric = metric;
678 * @route: the #NMIPRoute
680 * Increases the reference count of the object.
683 nm_ip_route_ref (NMIPRoute *route)
685 g_return_if_fail (route != NULL);
686 g_return_if_fail (route->refcount > 0);
693 * @route: the #NMIPRoute
695 * Decreases the reference count of the object. If the reference count
696 * reaches zero, the object will be destroyed.
699 nm_ip_route_unref (NMIPRoute *route)
701 g_return_if_fail (route != NULL);
702 g_return_if_fail (route->refcount > 0);
705 if (route->refcount == 0) {
706 g_free (route->dest);
707 g_free (route->next_hop);
708 if (route->attributes)
709 g_hash_table_unref (route->attributes);
710 g_slice_free (NMIPRoute, route);
716 * @route: the #NMIPRoute
717 * @other: the #NMIPRoute to compare @route to.
719 * Determines if two #NMIPRoute objects contain the same destination, prefix,
720 * next hop, and metric. (Attributes are not compared.)
722 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
725 nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other)
727 g_return_val_if_fail (route != NULL, FALSE);
728 g_return_val_if_fail (route->refcount > 0, FALSE);
730 g_return_val_if_fail (other != NULL, FALSE);
731 g_return_val_if_fail (other->refcount > 0, FALSE);
733 if ( route->prefix != other->prefix
734 || route->metric != other->metric
735 || strcmp (route->dest, other->dest) != 0
736 || g_strcmp0 (route->next_hop, other->next_hop) != 0)
743 * @route: the #NMIPRoute
745 * Creates a copy of @route
747 * Returns: (transfer full): a copy of @route
750 nm_ip_route_dup (NMIPRoute *route)
754 g_return_val_if_fail (route != NULL, NULL);
755 g_return_val_if_fail (route->refcount > 0, NULL);
757 copy = nm_ip_route_new (route->family,
758 route->dest, route->prefix,
759 route->next_hop, route->metric,
761 if (route->attributes) {
766 g_hash_table_iter_init (&iter, route->attributes);
767 while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
768 nm_ip_route_set_attribute (copy, key, value);
775 * nm_ip_route_get_family:
776 * @route: the #NMIPRoute
778 * Gets the IP address family (eg, AF_INET) property of this route
781 * Returns: the IP address family
784 nm_ip_route_get_family (NMIPRoute *route)
786 g_return_val_if_fail (route != NULL, 0);
787 g_return_val_if_fail (route->refcount > 0, 0);
789 return route->family;
793 * nm_ip_route_get_dest:
794 * @route: the #NMIPRoute
796 * Gets the IP destination address property of this route object.
798 * Returns: the IP address of the route's destination
801 nm_ip_route_get_dest (NMIPRoute *route)
803 g_return_val_if_fail (route != NULL, NULL);
804 g_return_val_if_fail (route->refcount > 0, NULL);
810 * nm_ip_route_set_dest:
811 * @route: the #NMIPRoute
812 * @dest: the route's destination, as a string
814 * Sets the destination property of this route object.
816 * @dest must be a valid address of @route's family. If you aren't sure you
817 * have a valid address, use nm_utils_ipaddr_valid() to check it.
820 nm_ip_route_set_dest (NMIPRoute *route,
823 g_return_if_fail (route != NULL);
824 g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest));
826 g_free (route->dest);
827 route->dest = canonicalize_ip (route->family, dest, FALSE);
831 * nm_ip_route_get_dest_binary: (skip)
832 * @route: the #NMIPRoute
833 * @dest: a buffer in which to store the destination in binary format.
835 * Gets the destination property of this route object.
837 * @dest must point to a buffer that is the correct size for @route's family.
840 nm_ip_route_get_dest_binary (NMIPRoute *route,
843 g_return_if_fail (route != NULL);
844 g_return_if_fail (dest != NULL);
846 inet_pton (route->family, route->dest, dest);
850 * nm_ip_route_set_dest_binary: (skip)
851 * @route: the #NMIPRoute
852 * @dest: the route's destination, in binary format
854 * Sets the destination property of this route object.
856 * @dest must point to a buffer that is the correct size for @route's family.
859 nm_ip_route_set_dest_binary (NMIPRoute *route,
862 char string[NM_UTILS_INET_ADDRSTRLEN];
864 g_return_if_fail (route != NULL);
865 g_return_if_fail (dest != NULL);
867 g_free (route->dest);
868 route->dest = g_strdup (inet_ntop (route->family, dest, string, sizeof (string)));
872 * nm_ip_route_get_prefix:
873 * @route: the #NMIPRoute
875 * Gets the IP prefix (ie "24" or "30" etc) of this route.
877 * Returns: the IP prefix
880 nm_ip_route_get_prefix (NMIPRoute *route)
882 g_return_val_if_fail (route != NULL, 0);
883 g_return_val_if_fail (route->refcount > 0, 0);
885 return route->prefix;
889 * nm_ip_route_set_prefix:
890 * @route: the #NMIPRoute
891 * @prefix: the route prefix
893 * Sets the prefix property of this route object.
896 nm_ip_route_set_prefix (NMIPRoute *route,
899 g_return_if_fail (route != NULL);
900 g_return_if_fail (valid_prefix (route->family, prefix, NULL, TRUE));
902 route->prefix = prefix;
906 * nm_ip_route_get_next_hop:
907 * @route: the #NMIPRoute
909 * Gets the IP address of the next hop of this route; this will be %NULL if the
910 * route has no next hop.
912 * Returns: the IP address of the next hop, or %NULL if this is a device route.
915 nm_ip_route_get_next_hop (NMIPRoute *route)
917 g_return_val_if_fail (route != NULL, NULL);
918 g_return_val_if_fail (route->refcount > 0, NULL);
920 return route->next_hop;
924 * nm_ip_route_set_next_hop:
925 * @route: the #NMIPRoute
926 * @next_hop: (allow-none): the route's next hop, as a string
928 * Sets the next-hop property of this route object.
930 * @next_hop (if non-%NULL) must be a valid address of @route's family. If you
931 * aren't sure you have a valid address, use nm_utils_ipaddr_valid() to check
935 nm_ip_route_set_next_hop (NMIPRoute *route,
936 const char *next_hop)
938 g_return_if_fail (route != NULL);
939 g_return_if_fail (!next_hop || nm_utils_ipaddr_valid (route->family, next_hop));
941 g_free (route->next_hop);
942 route->next_hop = canonicalize_ip (route->family, next_hop, TRUE);
946 * nm_ip_route_get_next_hop_binary: (skip)
947 * @route: the #NMIPRoute
948 * @next_hop: a buffer in which to store the next hop in binary format.
950 * Gets the next hop property of this route object.
952 * @next_hop must point to a buffer that is the correct size for @route's family.
954 * Returns: %TRUE if @route has a next hop, %FALSE if not (in which case
955 * @next_hop will be zeroed out)
958 nm_ip_route_get_next_hop_binary (NMIPRoute *route,
961 g_return_val_if_fail (route != NULL, FALSE);
962 g_return_val_if_fail (next_hop != NULL, FALSE);
964 if (route->next_hop) {
965 inet_pton (route->family, route->next_hop, next_hop);
968 memset (next_hop, 0, _addr_size (route->family));
974 * nm_ip_route_set_next_hop_binary: (skip)
975 * @route: the #NMIPRoute
976 * @next_hop: the route's next hop, in binary format
978 * Sets the destination property of this route object.
980 * @next_hop (if non-%NULL) must point to a buffer that is the correct size for
984 nm_ip_route_set_next_hop_binary (NMIPRoute *route,
985 gconstpointer next_hop)
987 g_return_if_fail (route != NULL);
989 g_free (route->next_hop);
990 route->next_hop = canonicalize_ip_binary (route->family, next_hop, TRUE);
994 * nm_ip_route_get_metric:
995 * @route: the #NMIPRoute
997 * Gets the route metric property of this route object; lower values
998 * indicate "better" or more preferred routes; -1 indicates "default"
999 * (meaning NetworkManager will set it appropriately).
1001 * Returns: the route metric
1004 nm_ip_route_get_metric (NMIPRoute *route)
1006 g_return_val_if_fail (route != NULL, 0);
1007 g_return_val_if_fail (route->refcount > 0, 0);
1009 return route->metric;
1013 * nm_ip_route_set_metric:
1014 * @route: the #NMIPRoute
1015 * @metric: the route metric (or -1 for "default")
1017 * Sets the metric property of this route object.
1020 nm_ip_route_set_metric (NMIPRoute *route,
1023 g_return_if_fail (route != NULL);
1024 g_return_if_fail (valid_metric (metric, NULL));
1026 route->metric = metric;
1030 * nm_ip_route_get_attribute_names:
1031 * @route: the #NMIPRoute
1033 * Gets an array of attribute names defined on @route.
1035 * Returns: (transfer full): a %NULL-terminated array of attribute names
1038 nm_ip_route_get_attribute_names (NMIPRoute *route)
1040 GHashTableIter iter;
1044 g_return_val_if_fail (route != NULL, NULL);
1046 names = g_ptr_array_new ();
1048 if (route->attributes) {
1049 g_hash_table_iter_init (&iter, route->attributes);
1050 while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
1051 g_ptr_array_add (names, g_strdup (key));
1053 g_ptr_array_add (names, NULL);
1055 return (char **) g_ptr_array_free (names, FALSE);
1059 * nm_ip_route_get_attribute:
1060 * @route: the #NMIPRoute
1061 * @name: the name of an route attribute
1063 * Gets the value of the attribute with name @name on @route
1065 * Returns: (transfer none): the value of the attribute with name @name on
1066 * @route, or %NULL if @route has no such attribute.
1069 nm_ip_route_get_attribute (NMIPRoute *route, const char *name)
1071 g_return_val_if_fail (route != NULL, NULL);
1072 g_return_val_if_fail (name != NULL && *name != '\0', NULL);
1074 if (route->attributes)
1075 return g_hash_table_lookup (route->attributes, name);
1081 * nm_ip_route_set_attribute:
1082 * @route: the #NMIPRoute
1083 * @name: the name of a route attribute
1084 * @value: (transfer none) (allow-none): the value
1086 * Sets the named attribute on @route to the given value.
1089 nm_ip_route_set_attribute (NMIPRoute *route, const char *name, GVariant *value)
1091 g_return_if_fail (route != NULL);
1092 g_return_if_fail (name != NULL && *name != '\0');
1093 g_return_if_fail ( strcmp (name, "dest") != 0 && strcmp (name, "prefix") != 0
1094 && strcmp (name, "next-hop") != 0 && strcmp (name, "metric") != 0);
1096 if (!route->attributes) {
1097 route->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
1098 g_free, (GDestroyNotify) g_variant_unref);
1102 g_hash_table_insert (route->attributes, g_strdup (name), g_variant_ref_sink (value));
1104 g_hash_table_remove (route->attributes, name);
1108 G_DEFINE_ABSTRACT_TYPE (NMSettingIPConfig, nm_setting_ip_config, NM_TYPE_SETTING)
1110 #define NM_SETTING_IP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP_CONFIG, NMSettingIPConfigPrivate))
1114 GPtrArray *dns; /* array of IP address strings */
1115 GPtrArray *dns_search; /* array of domain name strings */
1116 GPtrArray *dns_options;/* array of DNS options */
1117 GPtrArray *addresses; /* array of NMIPAddress */
1118 GPtrArray *routes; /* array of NMIPRoute */
1119 gint64 route_metric;
1121 gboolean ignore_auto_routes;
1122 gboolean ignore_auto_dns;
1123 char *dhcp_hostname;
1124 gboolean dhcp_send_hostname;
1125 gboolean never_default;
1129 } NMSettingIPConfigPrivate;
1141 PROP_IGNORE_AUTO_ROUTES,
1142 PROP_IGNORE_AUTO_DNS,
1144 PROP_DHCP_SEND_HOSTNAME,
1153 #define NM_SETTING_IP_CONFIG_GET_FAMILY(setting) (NM_IS_SETTING_IP4_CONFIG (setting) ? AF_INET : AF_INET6)
1156 * nm_setting_ip_config_get_method:
1157 * @setting: the #NMSettingIPConfig
1159 * Returns: the #NMSettingIPConfig:method property of the setting; see
1160 * #NMSettingIP4Config and #NMSettingIP6Config for details of the
1161 * methods available with each type.
1164 nm_setting_ip_config_get_method (NMSettingIPConfig *setting)
1166 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1168 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->method;
1172 * nm_setting_ip_config_get_num_dns:
1173 * @setting: the #NMSettingIPConfig
1175 * Returns: the number of configured DNS servers
1178 nm_setting_ip_config_get_num_dns (NMSettingIPConfig *setting)
1180 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1182 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns->len;
1186 * nm_setting_ip_config_get_dns:
1187 * @setting: the #NMSettingIPConfig
1188 * @idx: index number of the DNS server to return
1190 * Returns: the IP address of the DNS server at index @idx
1193 nm_setting_ip_config_get_dns (NMSettingIPConfig *setting, int idx)
1195 NMSettingIPConfigPrivate *priv;
1197 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1199 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1200 g_return_val_if_fail (idx < priv->dns->len, NULL);
1202 return priv->dns->pdata[idx];
1206 * nm_setting_ip_config_add_dns:
1207 * @setting: the #NMSettingIPConfig
1208 * @dns: the IP address of the DNS server to add
1210 * Adds a new DNS server to the setting.
1212 * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
1216 nm_setting_ip_config_add_dns (NMSettingIPConfig *setting, const char *dns)
1218 NMSettingIPConfigPrivate *priv;
1219 char *dns_canonical;
1222 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1223 g_return_val_if_fail (dns != NULL, FALSE);
1224 g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE);
1226 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1228 dns_canonical = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns, FALSE);
1229 for (i = 0; i < priv->dns->len; i++) {
1230 if (!strcmp (dns_canonical, priv->dns->pdata[i])) {
1231 g_free (dns_canonical);
1236 g_ptr_array_add (priv->dns, dns_canonical);
1237 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
1242 * nm_setting_ip_config_remove_dns:
1243 * @setting: the #NMSettingIPConfig
1244 * @idx: index number of the DNS server to remove
1246 * Removes the DNS server at index @idx.
1249 nm_setting_ip_config_remove_dns (NMSettingIPConfig *setting, int idx)
1251 NMSettingIPConfigPrivate *priv;
1253 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1255 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1256 g_return_if_fail (idx < priv->dns->len);
1258 g_ptr_array_remove_index (priv->dns, idx);
1259 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
1263 * nm_setting_ip_config_remove_dns_by_value:
1264 * @setting: the #NMSettingIPConfig
1265 * @dns: the DNS server to remove
1267 * Removes the DNS server @dns.
1269 * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
1272 nm_setting_ip_config_remove_dns_by_value (NMSettingIPConfig *setting, const char *dns)
1274 NMSettingIPConfigPrivate *priv;
1275 char *dns_canonical;
1278 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1279 g_return_val_if_fail (dns != NULL, FALSE);
1280 g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE);
1282 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1284 dns_canonical = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns, FALSE);
1285 for (i = 0; i < priv->dns->len; i++) {
1286 if (!strcmp (dns_canonical, priv->dns->pdata[i])) {
1287 g_ptr_array_remove_index (priv->dns, i);
1288 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
1289 g_free (dns_canonical);
1293 g_free (dns_canonical);
1298 * nm_setting_ip_config_clear_dns:
1299 * @setting: the #NMSettingIPConfig
1301 * Removes all configured DNS servers.
1304 nm_setting_ip_config_clear_dns (NMSettingIPConfig *setting)
1306 NMSettingIPConfigPrivate *priv;
1308 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1310 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1311 g_ptr_array_set_size (priv->dns, 0);
1312 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
1316 * nm_setting_ip_config_get_num_dns_searches:
1317 * @setting: the #NMSettingIPConfig
1319 * Returns: the number of configured DNS search domains
1322 nm_setting_ip_config_get_num_dns_searches (NMSettingIPConfig *setting)
1324 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1326 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns_search->len;
1330 * nm_setting_ip_config_get_dns_search:
1331 * @setting: the #NMSettingIPConfig
1332 * @idx: index number of the DNS search domain to return
1334 * Returns: the DNS search domain at index @idx
1337 nm_setting_ip_config_get_dns_search (NMSettingIPConfig *setting, int idx)
1339 NMSettingIPConfigPrivate *priv;
1341 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1343 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1344 g_return_val_if_fail (idx < priv->dns_search->len, NULL);
1346 return priv->dns_search->pdata[idx];
1350 * nm_setting_ip_config_add_dns_search:
1351 * @setting: the #NMSettingIPConfig
1352 * @dns_search: the search domain to add
1354 * Adds a new DNS search domain to the setting.
1356 * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
1357 * domain was already known
1360 nm_setting_ip_config_add_dns_search (NMSettingIPConfig *setting,
1361 const char *dns_search)
1363 NMSettingIPConfigPrivate *priv;
1366 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1367 g_return_val_if_fail (dns_search != NULL, FALSE);
1368 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
1370 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1371 for (i = 0; i < priv->dns_search->len; i++) {
1372 if (!strcmp (dns_search, priv->dns_search->pdata[i]))
1376 g_ptr_array_add (priv->dns_search, g_strdup (dns_search));
1377 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
1382 * nm_setting_ip_config_remove_dns_search:
1383 * @setting: the #NMSettingIPConfig
1384 * @idx: index number of the DNS search domain
1386 * Removes the DNS search domain at index @idx.
1389 nm_setting_ip_config_remove_dns_search (NMSettingIPConfig *setting, int idx)
1391 NMSettingIPConfigPrivate *priv;
1393 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1395 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1396 g_return_if_fail (idx < priv->dns_search->len);
1398 g_ptr_array_remove_index (priv->dns_search, idx);
1399 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
1403 * nm_setting_ip_config_remove_dns_search_by_value:
1404 * @setting: the #NMSettingIPConfig
1405 * @dns_search: the search domain to remove
1407 * Removes the DNS search domain @dns_search.
1409 * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
1414 nm_setting_ip_config_remove_dns_search_by_value (NMSettingIPConfig *setting,
1415 const char *dns_search)
1417 NMSettingIPConfigPrivate *priv;
1420 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1421 g_return_val_if_fail (dns_search != NULL, FALSE);
1422 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
1424 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1425 for (i = 0; i < priv->dns_search->len; i++) {
1426 if (!strcmp (dns_search, priv->dns_search->pdata[i])) {
1427 g_ptr_array_remove_index (priv->dns_search, i);
1428 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
1436 * nm_setting_ip_config_clear_dns_searches:
1437 * @setting: the #NMSettingIPConfig
1439 * Removes all configured DNS search domains.
1442 nm_setting_ip_config_clear_dns_searches (NMSettingIPConfig *setting)
1444 NMSettingIPConfigPrivate *priv;
1446 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1448 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1449 g_ptr_array_set_size (priv->dns_search, 0);
1450 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
1454 * nm_setting_ip_config_get_num_dns_options:
1455 * @setting: the #NMSettingIPConfig
1457 * Returns: the number of configured DNS options
1462 nm_setting_ip_config_get_num_dns_options (NMSettingIPConfig *setting)
1464 NMSettingIPConfigPrivate *priv;
1466 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1468 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1470 return priv->dns_options ? priv->dns_options->len : 0;
1474 * nm_setting_ip_config_has_dns_options:
1475 * @setting: the #NMSettingIPConfig
1477 * NMSettingIPConfig can have a list of dns-options. If the list
1478 * is empty, there are two similar (but differentiated) states.
1479 * Either the options are explicitly set to have no values,
1480 * or the options are left undefined. The latter means to use
1481 * a default configuration, while the former explicitly means "no-options".
1483 * Returns: whether DNS options are initalized or left unset (the default).
1486 nm_setting_ip_config_has_dns_options (NMSettingIPConfig *setting)
1488 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1490 return !!NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns_options;
1494 * nm_setting_ip_config_get_dns_option:
1495 * @setting: the #NMSettingIPConfig
1496 * @idx: index number of the DNS option
1498 * Returns: the DNS option at index @idx
1503 nm_setting_ip_config_get_dns_option (NMSettingIPConfig *setting, guint idx)
1505 NMSettingIPConfigPrivate *priv;
1507 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1509 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1510 g_return_val_if_fail (priv->dns_options, NULL);
1511 g_return_val_if_fail (idx < priv->dns_options->len, NULL);
1513 return priv->dns_options->pdata[idx];
1517 * nm_setting_ip_config_next_valid_dns_option:
1518 * @setting: the #NMSettingIPConfig
1519 * @idx: index to start the search from
1521 * Returns: the index, greater or equal than @idx, of the first valid
1522 * DNS option, or -1 if no valid option is found
1527 nm_setting_ip_config_next_valid_dns_option (NMSettingIPConfig *setting, guint idx)
1529 NMSettingIPConfigPrivate *priv;
1531 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), -1);
1533 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1535 if (!priv->dns_options)
1538 for (; idx < priv->dns_options->len; idx++) {
1539 if (_nm_utils_dns_option_validate (priv->dns_options->pdata[idx], NULL, NULL,
1540 NM_IS_SETTING_IP6_CONFIG (setting),
1541 _nm_utils_dns_option_descs))
1549 * nm_setting_ip_config_add_dns_option:
1550 * @setting: the #NMSettingIPConfig
1551 * @dns_option: the DNS option to add
1553 * Adds a new DNS option to the setting.
1555 * Returns: %TRUE if the DNS option was added; %FALSE otherwise
1560 nm_setting_ip_config_add_dns_option (NMSettingIPConfig *setting,
1561 const char *dns_option)
1563 NMSettingIPConfigPrivate *priv;
1565 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1566 g_return_val_if_fail (dns_option != NULL, FALSE);
1567 g_return_val_if_fail (dns_option[0] != '\0', FALSE);
1569 if (!_nm_utils_dns_option_validate (dns_option, NULL, NULL, FALSE, NULL))
1572 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1573 if (!priv->dns_options)
1574 priv->dns_options = g_ptr_array_new_with_free_func (g_free);
1576 if (_nm_utils_dns_option_find_idx (priv->dns_options, dns_option) >= 0)
1580 g_ptr_array_add (priv->dns_options, g_strdup (dns_option));
1581 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
1586 * nm_setting_ip_config_remove_dns_option:
1587 * @setting: the #NMSettingIPConfig
1588 * @idx: index number of the DNS option
1590 * Removes the DNS option at index @idx.
1595 nm_setting_ip_config_remove_dns_option (NMSettingIPConfig *setting, int idx)
1597 NMSettingIPConfigPrivate *priv;
1599 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1601 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1602 g_return_if_fail (priv->dns_options);
1603 g_return_if_fail (idx < priv->dns_options->len);
1605 g_ptr_array_remove_index (priv->dns_options, idx);
1606 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
1610 * nm_setting_ip_config_remove_dns_option_by_value:
1611 * @setting: the #NMSettingIPConfig
1612 * @dns_option: the DNS option to remove
1614 * Removes the DNS option @dns_option.
1616 * Returns: %TRUE if the DNS option was found and removed; %FALSE if it was not.
1621 nm_setting_ip_config_remove_dns_option_by_value (NMSettingIPConfig *setting,
1622 const char *dns_option)
1624 NMSettingIPConfigPrivate *priv;
1627 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1628 g_return_val_if_fail (dns_option != NULL, FALSE);
1629 g_return_val_if_fail (dns_option[0] != '\0', FALSE);
1631 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1632 if (!priv->dns_options)
1635 i = _nm_utils_dns_option_find_idx (priv->dns_options, dns_option);
1637 g_ptr_array_remove_index (priv->dns_options, i);
1638 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
1646 * nm_setting_ip_config_clear_dns_options:
1647 * @setting: the #NMSettingIPConfig
1648 * @is_set: the dns-options can be either empty or unset (default).
1649 * Specify how to clear the options.
1651 * Removes all configured DNS options.
1656 nm_setting_ip_config_clear_dns_options (NMSettingIPConfig *setting, gboolean is_set)
1658 NMSettingIPConfigPrivate *priv;
1660 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1662 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1663 if (!priv->dns_options) {
1666 priv->dns_options = g_ptr_array_new_with_free_func (g_free);
1669 g_ptr_array_unref (priv->dns_options);
1670 priv->dns_options = NULL;
1672 if (priv->dns_options->len == 0)
1674 g_ptr_array_set_size (priv->dns_options, 0);
1677 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
1681 * nm_setting_ip_config_get_num_addresses:
1682 * @setting: the #NMSettingIPConfig
1684 * Returns: the number of configured addresses
1687 nm_setting_ip_config_get_num_addresses (NMSettingIPConfig *setting)
1689 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1691 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->addresses->len;
1695 * nm_setting_ip_config_get_address:
1696 * @setting: the #NMSettingIPConfig
1697 * @idx: index number of the address to return
1699 * Returns: (transfer none): the address at index @idx
1702 nm_setting_ip_config_get_address (NMSettingIPConfig *setting, int idx)
1704 NMSettingIPConfigPrivate *priv;
1706 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1708 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1709 g_return_val_if_fail (idx < priv->addresses->len, NULL);
1711 return priv->addresses->pdata[idx];
1715 * nm_setting_ip_config_add_address:
1716 * @setting: the #NMSettingIPConfig
1717 * @address: the new address to add
1719 * Adds a new IP address and associated information to the setting. The
1720 * given address is duplicated internally and is not changed by this function.
1722 * Returns: %TRUE if the address was added; %FALSE if the address was already
1726 nm_setting_ip_config_add_address (NMSettingIPConfig *setting,
1727 NMIPAddress *address)
1729 NMSettingIPConfigPrivate *priv;
1732 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1733 g_return_val_if_fail (address != NULL, FALSE);
1734 g_return_val_if_fail (address->family == NM_SETTING_IP_CONFIG_GET_FAMILY (setting), FALSE);
1736 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1737 for (i = 0; i < priv->addresses->len; i++) {
1738 if (nm_ip_address_equal (priv->addresses->pdata[i], address))
1742 g_ptr_array_add (priv->addresses, nm_ip_address_dup (address));
1744 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
1749 * nm_setting_ip_config_remove_address:
1750 * @setting: the #NMSettingIPConfig
1751 * @idx: index number of the address to remove
1753 * Removes the address at index @idx.
1756 nm_setting_ip_config_remove_address (NMSettingIPConfig *setting, int idx)
1758 NMSettingIPConfigPrivate *priv;
1760 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1762 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1763 g_return_if_fail (idx < priv->addresses->len);
1765 g_ptr_array_remove_index (priv->addresses, idx);
1767 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
1771 * nm_setting_ip_config_remove_address_by_value:
1772 * @setting: the #NMSettingIPConfig
1773 * @address: the IP address to remove
1775 * Removes the address @address.
1777 * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
1780 nm_setting_ip_config_remove_address_by_value (NMSettingIPConfig *setting,
1781 NMIPAddress *address)
1783 NMSettingIPConfigPrivate *priv;
1786 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1787 g_return_val_if_fail (address != NULL, FALSE);
1789 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1790 for (i = 0; i < priv->addresses->len; i++) {
1791 if (nm_ip_address_equal (priv->addresses->pdata[i], address)) {
1792 g_ptr_array_remove_index (priv->addresses, i);
1793 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
1801 * nm_setting_ip_config_clear_addresses:
1802 * @setting: the #NMSettingIPConfig
1804 * Removes all configured addresses.
1807 nm_setting_ip_config_clear_addresses (NMSettingIPConfig *setting)
1809 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1811 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1813 g_ptr_array_set_size (priv->addresses, 0);
1814 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
1818 * nm_setting_ip_config_get_gateway:
1819 * @setting: the #NMSettingIPConfig
1821 * Returns: the IP address of the gateway associated with this configuration, or
1825 nm_setting_ip_config_get_gateway (NMSettingIPConfig *setting)
1827 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1829 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->gateway;
1833 * nm_setting_ip_config_get_num_routes:
1834 * @setting: the #NMSettingIPConfig
1836 * Returns: the number of configured routes
1839 nm_setting_ip_config_get_num_routes (NMSettingIPConfig *setting)
1841 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
1843 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->routes->len;
1847 * nm_setting_ip_config_get_route:
1848 * @setting: the #NMSettingIPConfig
1849 * @idx: index number of the route to return
1851 * Returns: (transfer none): the route at index @idx
1854 nm_setting_ip_config_get_route (NMSettingIPConfig *setting, int idx)
1856 NMSettingIPConfigPrivate *priv;
1858 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
1860 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1861 g_return_val_if_fail (idx < priv->routes->len, NULL);
1863 return priv->routes->pdata[idx];
1867 * nm_setting_ip_config_add_route:
1868 * @setting: the #NMSettingIPConfig
1869 * @route: the route to add
1871 * Adds a new route and associated information to the setting. The
1872 * given route is duplicated internally and is not changed by this function.
1874 * Returns: %TRUE if the route was added; %FALSE if the route was already known.
1877 nm_setting_ip_config_add_route (NMSettingIPConfig *setting,
1880 NMSettingIPConfigPrivate *priv;
1883 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1884 g_return_val_if_fail (route != NULL, FALSE);
1885 g_return_val_if_fail (route->family == NM_SETTING_IP_CONFIG_GET_FAMILY (setting), FALSE);
1887 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1888 for (i = 0; i < priv->routes->len; i++) {
1889 if (nm_ip_route_equal (priv->routes->pdata[i], route))
1893 g_ptr_array_add (priv->routes, nm_ip_route_dup (route));
1894 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
1899 * nm_setting_ip_config_remove_route:
1900 * @setting: the #NMSettingIPConfig
1901 * @idx: index number of the route
1903 * Removes the route at index @idx.
1906 nm_setting_ip_config_remove_route (NMSettingIPConfig *setting, int idx)
1908 NMSettingIPConfigPrivate *priv;
1910 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1912 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1913 g_return_if_fail (idx < priv->routes->len);
1915 g_ptr_array_remove_index (priv->routes, idx);
1916 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
1920 * nm_setting_ip_config_remove_route_by_value:
1921 * @setting: the #NMSettingIPConfig
1922 * @route: the route to remove
1924 * Removes the route @route.
1926 * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
1929 nm_setting_ip_config_remove_route_by_value (NMSettingIPConfig *setting,
1932 NMSettingIPConfigPrivate *priv;
1935 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
1936 g_return_val_if_fail (route != NULL, FALSE);
1938 priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1939 for (i = 0; i < priv->routes->len; i++) {
1940 if (nm_ip_route_equal (priv->routes->pdata[i], route)) {
1941 g_ptr_array_remove_index (priv->routes, i);
1942 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
1950 * nm_setting_ip_config_clear_routes:
1951 * @setting: the #NMSettingIPConfig
1953 * Removes all configured routes.
1956 nm_setting_ip_config_clear_routes (NMSettingIPConfig *setting)
1958 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
1960 g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
1962 g_ptr_array_set_size (priv->routes, 0);
1963 g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
1967 * nm_setting_ip_config_get_route_metric:
1968 * @setting: the #NMSettingIPConfig
1970 * Returns the value contained in the #NMSettingIPConfig:route-metric
1973 * Returns: the route metric that is used for routes that don't explicitly
1974 * specify a metric. See #NMSettingIPConfig:route-metric for more details.
1977 nm_setting_ip_config_get_route_metric (NMSettingIPConfig *setting)
1979 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), -1);
1981 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->route_metric;
1986 * nm_setting_ip_config_get_ignore_auto_routes:
1987 * @setting: the #NMSettingIPConfig
1989 * Returns the value contained in the #NMSettingIPConfig:ignore-auto-routes
1992 * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
1996 nm_setting_ip_config_get_ignore_auto_routes (NMSettingIPConfig *setting)
1998 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
2000 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
2004 * nm_setting_ip_config_get_ignore_auto_dns:
2005 * @setting: the #NMSettingIPConfig
2007 * Returns the value contained in the #NMSettingIPConfig:ignore-auto-dns
2010 * Returns: %TRUE if automatically configured (ie via DHCP) DNS information
2011 * should be ignored.
2014 nm_setting_ip_config_get_ignore_auto_dns (NMSettingIPConfig *setting)
2016 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
2018 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
2022 * nm_setting_ip_config_get_dhcp_hostname:
2023 * @setting: the #NMSettingIPConfig
2025 * Returns the value contained in the #NMSettingIPConfig:dhcp-hostname
2028 * Returns: the configured hostname to send to the DHCP server
2031 nm_setting_ip_config_get_dhcp_hostname (NMSettingIPConfig *setting)
2033 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
2035 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
2039 * nm_setting_ip_config_get_dhcp_send_hostname:
2040 * @setting: the #NMSettingIPConfig
2042 * Returns the value contained in the #NMSettingIPConfig:dhcp-send-hostname
2045 * Returns: %TRUE if NetworkManager should send the machine hostname to the
2046 * DHCP server when requesting addresses to allow the server to automatically
2047 * update DNS information for this machine.
2050 nm_setting_ip_config_get_dhcp_send_hostname (NMSettingIPConfig *setting)
2052 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
2054 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_send_hostname;
2058 * nm_setting_ip_config_get_never_default:
2059 * @setting: the #NMSettingIPConfig
2061 * Returns the value contained in the #NMSettingIPConfig:never-default
2064 * Returns: %TRUE if this connection should never be the default
2068 nm_setting_ip_config_get_never_default (NMSettingIPConfig *setting)
2070 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
2072 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->never_default;
2076 * nm_setting_ip_config_get_may_fail:
2077 * @setting: the #NMSettingIPConfig
2079 * Returns the value contained in the #NMSettingIPConfig:may-fail
2082 * Returns: %TRUE if this connection doesn't require this type of IP
2083 * addressing to complete for the connection to succeed.
2086 nm_setting_ip_config_get_may_fail (NMSettingIPConfig *setting)
2088 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
2090 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->may_fail;
2094 * nm_setting_ip_config_get_dad_timeout:
2095 * @setting: the #NMSettingIPConfig
2097 * Returns: the #NMSettingIPConfig:dad-timeout property.
2102 nm_setting_ip_config_get_dad_timeout (NMSettingIPConfig *setting)
2104 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
2106 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dad_timeout;
2110 * nm_setting_ip_config_get_dhcp_timeout:
2111 * @setting: the #NMSettingIPConfig
2113 * Returns the value contained in the #NMSettingIPConfig:dhcp-timeout
2116 * Returns: the configured DHCP timeout in seconds. 0 = default for
2117 * the particular kind of device.
2122 nm_setting_ip_config_get_dhcp_timeout (NMSettingIPConfig *setting)
2124 g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
2126 return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_timeout;
2130 verify_label (const char *label)
2135 p = strchr (label, ':');
2138 iface = g_strndup (label, p - label);
2139 if (!nm_utils_iface_valid_name (iface)) {
2145 for (p++; *p; p++) {
2146 if (!g_ascii_isalnum (*p) && *p != '_')
2154 verify (NMSetting *setting, NMConnection *connection, GError **error)
2156 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
2159 if (!priv->method) {
2160 g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY,
2161 _("property is missing"));
2162 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_METHOD);
2166 if (priv->dhcp_hostname && !*priv->dhcp_hostname) {
2167 g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
2168 _("property is empty"));
2169 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME);
2174 for (i = 0; i < priv->dns->len; i++) {
2175 const char *dns = priv->dns->pdata[i];
2177 if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns)) {
2179 NM_CONNECTION_ERROR,
2180 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2181 _("%d. DNS server address is invalid"),
2183 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_DNS);
2188 /* Validate addresses */
2189 for (i = 0; i < priv->addresses->len; i++) {
2190 NMIPAddress *addr = (NMIPAddress *) priv->addresses->pdata[i];
2193 if (nm_ip_address_get_family (addr) != NM_SETTING_IP_CONFIG_GET_FAMILY (setting)) {
2195 NM_CONNECTION_ERROR,
2196 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2197 _("%d. IP address is invalid"),
2199 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
2203 label = nm_ip_address_get_attribute (addr, "label");
2205 if (!g_variant_is_of_type (label, G_VARIANT_TYPE_STRING)) {
2207 NM_CONNECTION_ERROR,
2208 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2209 _("%d. IP address has 'label' property with invalid type"),
2211 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
2214 if (!verify_label (g_variant_get_string (label, NULL))) {
2216 NM_CONNECTION_ERROR,
2217 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2218 _("%d. IP address has invalid label '%s'"),
2219 i+1, g_variant_get_string (label, NULL));
2220 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
2226 /* Validate gateway */
2227 if (priv->gateway) {
2228 if (!priv->addresses->len) {
2229 g_set_error_literal (error,
2230 NM_CONNECTION_ERROR,
2231 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2232 _("gateway cannot be set if there are no addresses configured"));
2233 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_GATEWAY);
2237 if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), priv->gateway)) {
2238 g_set_error_literal (error,
2239 NM_CONNECTION_ERROR,
2240 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2241 _("gateway is invalid"));
2242 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_GATEWAY);
2247 /* Validate routes */
2248 for (i = 0; i < priv->routes->len; i++) {
2249 NMIPRoute *route = (NMIPRoute *) priv->routes->pdata[i];
2251 if (nm_ip_route_get_family (route) != NM_SETTING_IP_CONFIG_GET_FAMILY (setting)) {
2253 NM_CONNECTION_ERROR,
2254 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2255 _("%d. route is invalid"),
2257 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ROUTES);
2260 if (nm_ip_route_get_prefix (route) == 0) {
2262 NM_CONNECTION_ERROR,
2263 NM_CONNECTION_ERROR_INVALID_PROPERTY,
2264 _("%d. route cannot be a default route"),
2266 g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ROUTES);
2276 nm_setting_ip_config_init (NMSettingIPConfig *setting)
2278 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
2280 priv->dns = g_ptr_array_new_with_free_func (g_free);
2281 priv->dns_search = g_ptr_array_new_with_free_func (g_free);
2282 priv->dns_options = NULL;
2283 priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
2284 priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
2288 finalize (GObject *object)
2290 NMSettingIPConfig *self = NM_SETTING_IP_CONFIG (object);
2291 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (self);
2293 g_free (priv->method);
2294 g_free (priv->gateway);
2295 g_free (priv->dhcp_hostname);
2297 g_ptr_array_unref (priv->dns);
2298 g_ptr_array_unref (priv->dns_search);
2299 if (priv->dns_options)
2300 g_ptr_array_unref (priv->dns_options);
2301 g_ptr_array_unref (priv->addresses);
2302 g_ptr_array_unref (priv->routes);
2304 G_OBJECT_CLASS (nm_setting_ip_config_parent_class)->finalize (object);
2308 set_property (GObject *object, guint prop_id,
2309 const GValue *value, GParamSpec *pspec)
2311 NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG (object);
2312 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
2313 const char *gateway;
2319 g_free (priv->method);
2320 priv->method = g_value_dup_string (value);
2323 g_ptr_array_unref (priv->dns);
2324 priv->dns = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
2326 case PROP_DNS_SEARCH:
2327 g_ptr_array_unref (priv->dns_search);
2328 priv->dns_search = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
2330 case PROP_DNS_OPTIONS:
2331 strv = g_value_get_boxed (value);
2333 if (priv->dns_options) {
2334 g_ptr_array_unref (priv->dns_options);
2335 priv->dns_options = NULL;
2338 if (priv->dns_options)
2339 g_ptr_array_set_size (priv->dns_options, 0);
2341 priv->dns_options = g_ptr_array_new_with_free_func (g_free);
2342 for (i = 0; strv[i]; i++) {
2343 if ( _nm_utils_dns_option_validate (strv[i], NULL, NULL, FALSE, NULL)
2344 && _nm_utils_dns_option_find_idx (priv->dns_options, strv[i]) < 0)
2345 g_ptr_array_add (priv->dns_options, g_strdup (strv[i]));
2349 case PROP_ADDRESSES:
2350 g_ptr_array_unref (priv->addresses);
2351 priv->addresses = _nm_utils_copy_array (g_value_get_boxed (value),
2352 (NMUtilsCopyFunc) nm_ip_address_dup,
2353 (GDestroyNotify) nm_ip_address_unref);
2356 gateway = g_value_get_string (value);
2357 g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway));
2358 g_free (priv->gateway);
2359 priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, TRUE);
2362 g_ptr_array_unref (priv->routes);
2363 priv->routes = _nm_utils_copy_array (g_value_get_boxed (value),
2364 (NMUtilsCopyFunc) nm_ip_route_dup,
2365 (GDestroyNotify) nm_ip_route_unref);
2367 case PROP_ROUTE_METRIC:
2368 priv->route_metric = g_value_get_int64 (value);
2370 case PROP_IGNORE_AUTO_ROUTES:
2371 priv->ignore_auto_routes = g_value_get_boolean (value);
2373 case PROP_IGNORE_AUTO_DNS:
2374 priv->ignore_auto_dns = g_value_get_boolean (value);
2376 case PROP_DHCP_HOSTNAME:
2377 g_free (priv->dhcp_hostname);
2378 priv->dhcp_hostname = g_value_dup_string (value);
2380 case PROP_DHCP_SEND_HOSTNAME:
2381 priv->dhcp_send_hostname = g_value_get_boolean (value);
2383 case PROP_NEVER_DEFAULT:
2384 priv->never_default = g_value_get_boolean (value);
2387 priv->may_fail = g_value_get_boolean (value);
2389 case PROP_DAD_TIMEOUT:
2390 priv->dad_timeout = g_value_get_int (value);
2392 case PROP_DHCP_TIMEOUT:
2393 priv->dhcp_timeout = g_value_get_int (value);
2396 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2402 get_property (GObject *object, guint prop_id,
2403 GValue *value, GParamSpec *pspec)
2405 NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG (object);
2406 NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
2410 g_value_set_string (value, nm_setting_ip_config_get_method (setting));
2413 g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns));
2415 case PROP_DNS_SEARCH:
2416 g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns_search));
2418 case PROP_DNS_OPTIONS:
2419 g_value_take_boxed (value, priv->dns_options ? _nm_utils_ptrarray_to_strv (priv->dns_options) : NULL);
2421 case PROP_ADDRESSES:
2422 g_value_take_boxed (value, _nm_utils_copy_array (priv->addresses,
2423 (NMUtilsCopyFunc) nm_ip_address_dup,
2424 (GDestroyNotify) nm_ip_address_unref));
2427 g_value_set_string (value, nm_setting_ip_config_get_gateway (setting));
2430 g_value_take_boxed (value, _nm_utils_copy_array (priv->routes,
2431 (NMUtilsCopyFunc) nm_ip_route_dup,
2432 (GDestroyNotify) nm_ip_route_unref));
2434 case PROP_ROUTE_METRIC:
2435 g_value_set_int64 (value, priv->route_metric);
2437 case PROP_IGNORE_AUTO_ROUTES:
2438 g_value_set_boolean (value, nm_setting_ip_config_get_ignore_auto_routes (setting));
2440 case PROP_IGNORE_AUTO_DNS:
2441 g_value_set_boolean (value, nm_setting_ip_config_get_ignore_auto_dns (setting));
2443 case PROP_DHCP_HOSTNAME:
2444 g_value_set_string (value, nm_setting_ip_config_get_dhcp_hostname (setting));
2446 case PROP_DHCP_SEND_HOSTNAME:
2447 g_value_set_boolean (value, nm_setting_ip_config_get_dhcp_send_hostname (setting));
2449 case PROP_NEVER_DEFAULT:
2450 g_value_set_boolean (value, priv->never_default);
2453 g_value_set_boolean (value, priv->may_fail);
2455 case PROP_DAD_TIMEOUT:
2456 g_value_set_int (value, nm_setting_ip_config_get_dad_timeout (setting));
2458 case PROP_DHCP_TIMEOUT:
2459 g_value_set_int (value, nm_setting_ip_config_get_dhcp_timeout (setting));
2462 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2468 ip_gateway_set (NMSetting *setting,
2469 GVariant *connection_dict,
2470 const char *property,
2473 /* Don't set from 'gateway' if we're going to use the gateway in 'addresses' */
2474 if (_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "gateway"))
2477 g_object_set (setting, property, g_variant_get_string (value, NULL), NULL);
2481 nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
2483 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
2484 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
2486 g_type_class_add_private (setting_class, sizeof (NMSettingIPConfigPrivate));
2488 /* virtual methods */
2489 object_class->set_property = set_property;
2490 object_class->get_property = get_property;
2491 object_class->finalize = finalize;
2492 parent_class->verify = verify;
2497 * NMSettingIPConfig:method:
2499 * IP configuration method.
2501 * #NMSettingIP4Config and #NMSettingIP6Config both support "auto",
2502 * "manual", and "link-local". See the subclass-specific documentation for
2505 * In general, for the "auto" method, properties such as
2506 * #NMSettingIPConfig:dns and #NMSettingIPConfig:routes specify information
2507 * that is added on to the information returned from automatic
2508 * configuration. The #NMSettingIPConfig:ignore-auto-routes and
2509 * #NMSettingIPConfig:ignore-auto-dns properties modify this behavior.
2511 * For methods that imply no upstream network, such as "shared" or
2512 * "link-local", these properties must be empty.
2514 * For IPv4 method "shared", the IP subnet can be configured by adding one
2515 * manual IPv4 address or otherwise 10.42.x.0/24 is chosen.
2517 g_object_class_install_property
2518 (object_class, PROP_METHOD,
2519 g_param_spec_string (NM_SETTING_IP_CONFIG_METHOD, "", "",
2522 NM_SETTING_PARAM_INFERRABLE |
2523 G_PARAM_STATIC_STRINGS));
2526 * NMSettingIPConfig:dns:
2528 * Array of IP addresses of DNS servers.
2530 g_object_class_install_property
2531 (object_class, PROP_DNS,
2532 g_param_spec_boxed (NM_SETTING_IP_CONFIG_DNS, "", "",
2535 G_PARAM_STATIC_STRINGS));
2538 * NMSettingIPConfig:dns-search:
2540 * Array of DNS search domains.
2542 g_object_class_install_property
2543 (object_class, PROP_DNS_SEARCH,
2544 g_param_spec_boxed (NM_SETTING_IP_CONFIG_DNS_SEARCH, "", "",
2547 G_PARAM_STATIC_STRINGS));
2550 * NMSettingIPConfig:dns-options:
2552 * Array of DNS options.
2554 * %NULL means that the options are unset and left at the default.
2555 * In this case NetworkManager will use default options. This is
2556 * distinct from an empty list of properties.
2560 g_object_class_install_property
2561 (object_class, PROP_DNS_OPTIONS,
2562 g_param_spec_boxed (NM_SETTING_IP_CONFIG_DNS_OPTIONS, "", "",
2565 G_PARAM_STATIC_STRINGS));
2568 * NMSettingIPConfig:addresses:
2570 * Array of IP addresses.
2572 * Element-Type: NMIPAddress
2574 g_object_class_install_property
2575 (object_class, PROP_ADDRESSES,
2576 g_param_spec_boxed (NM_SETTING_IP_CONFIG_ADDRESSES, "", "",
2579 NM_SETTING_PARAM_INFERRABLE |
2580 /* "addresses" is a legacy D-Bus property, because the
2581 * "addresses" GObject property normally gets set from
2582 * the "address-data" D-Bus property...
2584 NM_SETTING_PARAM_LEGACY |
2585 G_PARAM_STATIC_STRINGS));
2588 * NMSettingIPConfig:gateway:
2590 * The gateway associated with this configuration. This is only meaningful
2591 * if #NMSettingIPConfig:addresses is also set.
2593 g_object_class_install_property
2594 (object_class, PROP_GATEWAY,
2595 g_param_spec_string (NM_SETTING_IP_CONFIG_GATEWAY, "", "",
2598 NM_SETTING_PARAM_INFERRABLE |
2599 G_PARAM_STATIC_STRINGS));
2601 _nm_setting_class_override_property (parent_class,
2602 NM_SETTING_IP_CONFIG_GATEWAY,
2603 G_VARIANT_TYPE_STRING,
2609 * NMSettingIPConfig:routes:
2611 * Array of IP routes.
2613 * Element-Type: NMIPRoute
2615 g_object_class_install_property
2616 (object_class, PROP_ROUTES,
2617 g_param_spec_boxed (NM_SETTING_IP_CONFIG_ROUTES, "", "",
2620 NM_SETTING_PARAM_INFERRABLE |
2621 /* See :addresses above Re: LEGACY */
2622 NM_SETTING_PARAM_LEGACY |
2623 G_PARAM_STATIC_STRINGS));
2626 * NMSettingIPConfig:route-metric:
2628 * The default metric for routes that don't explicitly specify a metric.
2629 * The default value -1 means that the metric is choosen automatically
2630 * based on the device type.
2631 * The metric applies to dynamic routes, manual (static) routes that
2632 * don't have an explicit metric setting, address prefix routes, and
2633 * the default route.
2634 * Note that for IPv6, the kernel accepts zero (0) but coerces it to
2635 * 1024 (user default). Hence, setting this property to zero effectively
2636 * mean setting it to 1024.
2637 * For IPv4, zero is a regular value for the metric.
2639 g_object_class_install_property
2640 (object_class, PROP_ROUTE_METRIC,
2641 g_param_spec_int64 (NM_SETTING_IP_CONFIG_ROUTE_METRIC, "", "",
2642 -1, G_MAXUINT32, -1,
2645 G_PARAM_STATIC_STRINGS));
2648 * NMSettingIPConfig:ignore-auto-routes:
2650 * When #NMSettingIPConfig:method is set to "auto" and this property to
2651 * %TRUE, automatically configured routes are ignored and only routes
2652 * specified in the #NMSettingIPConfig:routes property, if any, are used.
2654 g_object_class_install_property
2655 (object_class, PROP_IGNORE_AUTO_ROUTES,
2656 g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, "", "",
2660 G_PARAM_STATIC_STRINGS));
2663 * NMSettingIPConfig:ignore-auto-dns:
2665 * When #NMSettingIPConfig:method is set to "auto" and this property to
2666 * %TRUE, automatically configured nameservers and search domains are
2667 * ignored and only nameservers and search domains specified in the
2668 * #NMSettingIPConfig:dns and #NMSettingIPConfig:dns-search properties, if
2671 g_object_class_install_property
2672 (object_class, PROP_IGNORE_AUTO_DNS,
2673 g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, "", "",
2677 G_PARAM_STATIC_STRINGS));
2680 * NMSettingIPConfig:dhcp-hostname:
2682 * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the
2683 * specified name will be sent to the DHCP server when acquiring a lease.
2684 * This property and #NMSettingIP4Config:dhcp-fqdn are mutually exclusive and
2685 * cannot be set at the same time.
2687 g_object_class_install_property
2688 (object_class, PROP_DHCP_HOSTNAME,
2689 g_param_spec_string (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "", "",
2692 NM_SETTING_PARAM_INFERRABLE |
2693 G_PARAM_STATIC_STRINGS));
2696 * NMSettingIPConfig:dhcp-send-hostname:
2698 * If %TRUE, a hostname is sent to the DHCP server when acquiring a lease.
2699 * Some DHCP servers use this hostname to update DNS databases, essentially
2700 * providing a static hostname for the computer. If the
2701 * #NMSettingIPConfig:dhcp-hostname property is %NULL and this property is
2702 * %TRUE, the current persistent hostname of the computer is sent.
2704 g_object_class_install_property
2705 (object_class, PROP_DHCP_SEND_HOSTNAME,
2706 g_param_spec_boolean (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, "", "",
2710 G_PARAM_STATIC_STRINGS));
2713 * NMSettingIPConfig:never-default:
2715 * If %TRUE, this connection will never be the default connection for this
2716 * IP type, meaning it will never be assigned the default route by
2719 g_object_class_install_property
2720 (object_class, PROP_NEVER_DEFAULT,
2721 g_param_spec_boolean (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, "", "",
2725 G_PARAM_STATIC_STRINGS));
2728 * NMSettingIPConfig:may-fail:
2730 * If %TRUE, allow overall network configuration to proceed even if the
2731 * configuration specified by this property times out. Note that at least
2732 * one IP configuration must succeed or overall network configuration will
2733 * still fail. For example, in IPv6-only networks, setting this property to
2734 * %TRUE on the #NMSettingIP4Config allows the overall network configuration
2735 * to succeed if IPv4 configuration fails but IPv6 configuration completes
2738 g_object_class_install_property
2739 (object_class, PROP_MAY_FAIL,
2740 g_param_spec_boolean (NM_SETTING_IP_CONFIG_MAY_FAIL, "", "",
2744 G_PARAM_STATIC_STRINGS));
2747 * NMSettingIPConfig:dad-timeout:
2749 * Timeout in milliseconds used to check for the presence of duplicate IP
2750 * addresses on the network. If an address conflict is detected, the
2751 * activation will fail. A zero value means that no duplicate address
2752 * detection is performed, -1 means the default value (either configuration
2753 * ipvx.dad-timeout override or 3 seconds). A value greater than zero is a
2754 * timeout in milliseconds.
2758 g_object_class_install_property
2759 (object_class, PROP_DAD_TIMEOUT,
2760 g_param_spec_int (NM_SETTING_IP_CONFIG_DAD_TIMEOUT, "", "",
2761 -1, NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX, -1,
2764 NM_SETTING_PARAM_FUZZY_IGNORE |
2765 G_PARAM_STATIC_STRINGS));
2767 * NMSettingIPConfig:dhcp-timeout:
2769 * A timeout for a DHCP transaction in seconds.
2771 g_object_class_install_property
2772 (object_class, PROP_DHCP_TIMEOUT,
2773 g_param_spec_int (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, "", "",
2776 NM_SETTING_PARAM_FUZZY_IGNORE |
2777 G_PARAM_STATIC_STRINGS));