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 <dbus/dbus-glib.h>
28 #include "nm-setting-ip4-config.h"
29 #include "nm-param-spec-specialized.h"
31 #include "nm-dbus-glib-types.h"
32 #include "nm-setting-private.h"
35 * SECTION:nm-setting-ip4-config
36 * @short_description: Describes IPv4 addressing, routing, and name service properties
37 * @include: nm-setting-ip4-config.h
39 * The #NMSettingIP4Config object is a #NMSetting subclass that describes
40 * properties related to IPv4 addressing, routing, and Domain Name Service
44 * nm_setting_ip4_config_error_quark:
46 * Registers an error quark for #NMSettingIP4Config if necessary.
48 * Returns: the error quark used for #NMSettingIP4Config errors.
51 nm_setting_ip4_config_error_quark (void)
55 if (G_UNLIKELY (!quark))
56 quark = g_quark_from_static_string ("nm-setting-ip4-config-error-quark");
60 G_DEFINE_BOXED_TYPE (NMIP4Address, nm_ip4_address, nm_ip4_address_dup, nm_ip4_address_unref)
61 G_DEFINE_BOXED_TYPE (NMIP4Route, nm_ip4_route, nm_ip4_route_dup, nm_ip4_route_unref)
63 G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING,
64 _nm_register_setting (NM_SETTING_IP4_CONFIG_SETTING_NAME,
67 NM_SETTING_IP4_CONFIG_ERROR))
68 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
70 #define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))
74 GArray *dns; /* array of guint32; elements in network byte order */
75 GSList *dns_search; /* list of strings */
76 GSList *addresses; /* array of NMIP4Address */
77 GSList *routes; /* array of NMIP4Route */
79 gboolean ignore_auto_routes;
80 gboolean ignore_auto_dns;
82 gboolean dhcp_send_hostname;
85 gboolean never_default;
87 } NMSettingIP4ConfigPrivate;
97 PROP_IGNORE_AUTO_ROUTES,
101 PROP_DHCP_SEND_HOSTNAME,
110 * nm_setting_ip4_config_new:
112 * Creates a new #NMSettingIP4Config object with default values.
114 * Returns: (transfer full): the new empty #NMSettingIP4Config object
117 nm_setting_ip4_config_new (void)
119 return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
123 * nm_setting_ip4_config_get_method:
124 * @setting: the #NMSettingIP4Config
126 * Returns: the #NMSettingIP4Config:method property of the setting
129 nm_setting_ip4_config_get_method (NMSettingIP4Config *setting)
131 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
133 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->method;
137 * nm_setting_ip4_config_get_num_dns:
138 * @setting: the #NMSettingIP4Config
140 * Returns: the number of configured DNS servers
143 nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
145 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
147 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns->len;
151 * nm_setting_ip4_config_get_dns:
152 * @setting: the #NMSettingIP4Config
153 * @i: index number of the DNS server to return
155 * Returns: the IPv4 address (network byte order) of the DNS server at index
159 nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
161 NMSettingIP4ConfigPrivate *priv;
163 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
165 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
166 g_return_val_if_fail (i <= priv->dns->len, 0);
168 return g_array_index (priv->dns, guint32, i);
172 * nm_setting_ip4_config_add_dns:
173 * @setting: the #NMSettingIP4Config
174 * @dns: the IPv4 address (network byte order) of the DNS server to add
176 * Adds a new DNS server to the setting.
178 * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
182 nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns)
184 NMSettingIP4ConfigPrivate *priv;
187 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
189 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
190 for (i = 0; i < priv->dns->len; i++) {
191 if (dns == g_array_index (priv->dns, guint32, i))
195 g_array_append_val (priv->dns, dns);
196 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
201 * nm_setting_ip4_config_remove_dns:
202 * @setting: the #NMSettingIP4Config
203 * @i: index number of the DNS server to remove
205 * Removes the DNS server at index @i.
208 nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
210 NMSettingIP4ConfigPrivate *priv;
212 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
214 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
215 g_return_if_fail (i <= priv->dns->len);
217 g_array_remove_index (priv->dns, i);
218 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
222 * nm_setting_ip4_config_remove_dns_by_value:
223 * @setting: the #NMSettingIP4Config
224 * @dns: the DNS server to remove
226 * Removes the DNS server @dns.
228 * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
229 * domain was already known
234 nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns)
236 NMSettingIP4ConfigPrivate *priv;
239 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
241 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
242 for (i = 0; i < priv->dns->len; i++) {
243 if (dns == g_array_index (priv->dns, guint32, i)) {
244 g_array_remove_index (priv->dns, i);
245 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
253 * nm_setting_ip4_config_clear_dns:
254 * @setting: the #NMSettingIP4Config
256 * Removes all configured DNS servers.
259 nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting)
261 NMSettingIP4ConfigPrivate *priv;
263 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
265 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
266 g_array_remove_range (priv->dns, 0, priv->dns->len);
267 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
271 * nm_setting_ip4_config_get_num_dns_searches:
272 * @setting: the #NMSettingIP4Config
274 * Returns: the number of configured DNS search domains
277 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting)
279 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
281 return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search);
285 * nm_setting_ip4_config_get_dns_search:
286 * @setting: the #NMSettingIP4Config
287 * @i: index number of the DNS search domain to return
289 * Returns: the DNS search domain at index @i
292 nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i)
294 NMSettingIP4ConfigPrivate *priv;
296 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
298 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
299 g_return_val_if_fail (i <= g_slist_length (priv->dns_search), NULL);
301 return (const char *) g_slist_nth_data (priv->dns_search, i);
305 * nm_setting_ip4_config_add_dns_search:
306 * @setting: the #NMSettingIP4Config
307 * @dns_search: the search domain to add
309 * Adds a new DNS search domain to the setting.
311 * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
312 * domain was already known
315 nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting,
316 const char *dns_search)
318 NMSettingIP4ConfigPrivate *priv;
321 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
322 g_return_val_if_fail (dns_search != NULL, FALSE);
323 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
325 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
326 for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
327 if (!strcmp (dns_search, (char *) iter->data))
331 priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
332 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
337 * nm_setting_ip4_config_remove_dns_search:
338 * @setting: the #NMSettingIP4Config
339 * @i: index number of the DNS search domain
341 * Removes the DNS search domain at index @i.
344 nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i)
346 NMSettingIP4ConfigPrivate *priv;
349 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
351 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
352 elt = g_slist_nth (priv->dns_search, i);
353 g_return_if_fail (elt != NULL);
356 priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
357 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
361 * nm_setting_ip4_config_remove_dns_search_by_value:
362 * @setting: the #NMSettingIP4Config
363 * @dns_search: the search domain to remove
365 * Removes the DNS search domain @dns_search.
367 * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
372 nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting,
373 const char *dns_search)
375 NMSettingIP4ConfigPrivate *priv;
378 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
379 g_return_val_if_fail (dns_search != NULL, FALSE);
380 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
382 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
383 for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
384 if (!strcmp (dns_search, (char *) iter->data)) {
385 priv->dns_search = g_slist_delete_link (priv->dns_search, iter);
386 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
394 * nm_setting_ip4_config_clear_dns_searches:
395 * @setting: the #NMSettingIP4Config
397 * Removes all configured DNS search domains.
400 nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting)
402 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
404 g_slist_free_full (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
405 NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
406 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
410 * nm_setting_ip4_config_get_num_addresses:
411 * @setting: the #NMSettingIP4Config
413 * Returns: the number of configured addresses
416 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting)
418 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
420 return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->addresses);
424 * nm_setting_ip4_config_get_address:
425 * @setting: the #NMSettingIP4Config
426 * @i: index number of the address to return
428 * Returns: the address at index @i
431 nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
433 NMSettingIP4ConfigPrivate *priv;
435 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
437 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
438 g_return_val_if_fail (i <= g_slist_length (priv->addresses), NULL);
440 return (NMIP4Address *) g_slist_nth_data (priv->addresses, i);
444 * nm_setting_ip4_config_add_address:
445 * @setting: the #NMSettingIP4Config
446 * @address: the new address to add
448 * Adds a new IPv4 address and associated information to the setting. The
449 * given address is duplicated internally and is not changed by this function.
451 * Returns: %TRUE if the address was added; %FALSE if the address was already
455 nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
456 NMIP4Address *address)
458 NMSettingIP4ConfigPrivate *priv;
462 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
463 g_return_val_if_fail (address != NULL, FALSE);
465 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
466 for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
467 if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address))
471 copy = nm_ip4_address_dup (address);
472 priv->addresses = g_slist_append (priv->addresses, copy);
473 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
478 * nm_setting_ip4_config_remove_address:
479 * @setting: the #NMSettingIP4Config
480 * @i: index number of the address to remove
482 * Removes the address at index @i.
485 nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i)
487 NMSettingIP4ConfigPrivate *priv;
490 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
492 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
493 elt = g_slist_nth (priv->addresses, i);
494 g_return_if_fail (elt != NULL);
496 nm_ip4_address_unref ((NMIP4Address *) elt->data);
497 priv->addresses = g_slist_delete_link (priv->addresses, elt);
498 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
502 * nm_setting_ip4_config_remove_address_by_value:
503 * @setting: the #NMSettingIP4Config
504 * @address: the IP address to remove
506 * Removes the address @address.
508 * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
513 nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting,
514 NMIP4Address *address)
516 NMSettingIP4ConfigPrivate *priv;
519 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
520 g_return_val_if_fail (address != NULL, FALSE);
522 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
523 for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
524 if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) {
525 nm_ip4_address_unref ((NMIP4Address *) iter->data);
526 priv->addresses = g_slist_delete_link (priv->addresses, iter);
527 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
535 * nm_setting_ip4_config_clear_addresses:
536 * @setting: the #NMSettingIP4Config
538 * Removes all configured addresses.
541 nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting)
543 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
545 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
547 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
548 priv->addresses = NULL;
549 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
553 * nm_setting_ip4_config_get_num_routes:
554 * @setting: the #NMSettingIP4Config
556 * Returns: the number of configured routes
559 nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting)
561 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
563 return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->routes);
567 * nm_setting_ip4_config_get_route:
568 * @setting: the #NMSettingIP4Config
569 * @i: index number of the route to return
571 * Returns: the route at index @i
574 nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
576 NMSettingIP4ConfigPrivate *priv;
578 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
580 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
581 g_return_val_if_fail (i <= g_slist_length (priv->routes), NULL);
583 return (NMIP4Route *) g_slist_nth_data (priv->routes, i);
587 * nm_setting_ip4_config_add_route:
588 * @setting: the #NMSettingIP4Config
589 * @route: the route to add
591 * Adds a new IPv4 route and associated information to the setting. The
592 * given route is duplicated internally and is not changed by this function.
594 * Returns: %TRUE if the route was added; %FALSE if the route was already known.
597 nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
600 NMSettingIP4ConfigPrivate *priv;
604 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
605 g_return_val_if_fail (route != NULL, FALSE);
607 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
608 for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
609 if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route))
613 copy = nm_ip4_route_dup (route);
614 priv->routes = g_slist_append (priv->routes, copy);
615 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
620 * nm_setting_ip4_config_remove_route:
621 * @setting: the #NMSettingIP4Config
622 * @i: index number of the route
624 * Removes the route at index @i.
627 nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i)
629 NMSettingIP4ConfigPrivate *priv;
632 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
634 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
635 elt = g_slist_nth (priv->routes, i);
636 g_return_if_fail (elt != NULL);
638 nm_ip4_route_unref ((NMIP4Route *) elt->data);
639 priv->routes = g_slist_delete_link (priv->routes, elt);
640 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
644 * nm_setting_ip4_config_remove_route_by_value:
645 * @setting: the #NMSettingIP4Config
646 * @route: the route to remove
648 * Removes the route @route.
650 * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
655 nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting,
658 NMSettingIP4ConfigPrivate *priv;
661 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
662 g_return_val_if_fail (route != NULL, FALSE);
664 priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
665 for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
666 if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route)) {
667 nm_ip4_route_unref ((NMIP4Route *) iter->data);
668 priv->routes = g_slist_delete_link (priv->routes, iter);
669 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
677 * nm_setting_ip4_config_clear_routes:
678 * @setting: the #NMSettingIP4Config
680 * Removes all configured routes.
683 nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
685 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
687 g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
689 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
691 g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
695 * nm_setting_ip4_config_get_route_metric:
696 * @setting: the #NMSettingIP4Config
698 * Returns the value contained in the #NMSettingIP4Config:route-metric
701 * Returns: the route metric that is used for IPv4 routes that don't explicitly
702 * specify a metric. See #NMSettingIP4Config:route-metric for more details.
707 nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting)
709 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), -1);
711 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->route_metric;
715 * nm_setting_ip4_config_get_ignore_auto_routes:
716 * @setting: the #NMSettingIP4Config
718 * Returns the value contained in the #NMSettingIP4Config:ignore-auto-routes
721 * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
725 nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting)
727 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
729 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
733 * nm_setting_ip4_config_get_ignore_auto_dns:
734 * @setting: the #NMSettingIP4Config
736 * Returns the value contained in the #NMSettingIP4Config:ignore-auto-dns
739 * Returns: %TRUE if automatically configured (ie via DHCP) DNS information
743 nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting)
745 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
747 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
751 * nm_setting_ip4_config_get_dhcp_client_id:
752 * @setting: the #NMSettingIP4Config
754 * Returns the value contained in the #NMSettingIP4Config:dhcp-client-id
757 * Returns: the configured Client ID to send to the DHCP server when requesting
758 * addresses via DHCP.
761 nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
763 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
765 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
769 * nm_setting_ip4_config_get_dhcp_send_hostname:
770 * @setting: the #NMSettingIP4Config
772 * Returns the value contained in the #NMSettingIP4Config:dhcp-send-hostname
775 * Returns: %TRUE if NetworkManager should send the machine hostname to the
776 * DHCP server when requesting addresses to allow the server to automatically
777 * update DNS information for this machine.
780 nm_setting_ip4_config_get_dhcp_send_hostname (NMSettingIP4Config *setting)
782 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
784 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_send_hostname;
788 * nm_setting_ip4_config_get_dhcp_hostname:
789 * @setting: the #NMSettingIP4Config
791 * Returns the value contained in the #NMSettingIP4Config:dhcp-hostname
794 * Returns: the configured hostname to send to the DHCP server
797 nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting)
799 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
801 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
805 * nm_setting_ip4_config_get_dhcp_timeout:
806 * @setting: the #NMSettingIP4Config
808 * Returns the value contained in the #NMSettingIP4Config:dhcp-timeout
811 * Returns: The number of seconds after which unfinished DHCP transaction
812 * fails or zero for "default".
815 nm_setting_ip4_config_get_dhcp_timeout (NMSettingIP4Config *setting)
817 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
819 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_timeout;
823 * nm_setting_ip4_config_get_never_default:
824 * @setting: the #NMSettingIP4Config
826 * Returns the value contained in the #NMSettingIP4Config:never-default
829 * Returns: %TRUE if this connection should never be the default connection
830 * for IPv4 addressing
833 nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting)
835 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
837 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->never_default;
841 * nm_setting_ip4_config_get_may_fail:
842 * @setting: the #NMSettingIP4Config
844 * Returns the value contained in the #NMSettingIP4Config:may-fail
847 * Returns: %TRUE if this connection doesn't require IPv4 addressing to complete
848 * for the connection to succeed.
851 nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting)
853 g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
855 return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->may_fail;
859 verify (NMSetting *setting, GSList *all_settings, GError **error)
861 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
866 g_set_error_literal (error,
867 NM_SETTING_IP4_CONFIG_ERROR,
868 NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
869 _("property is missing"));
870 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
874 if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
875 if (!priv->addresses) {
877 NM_SETTING_IP4_CONFIG_ERROR,
878 NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
879 _("this property cannot be empty for '%s=%s'"),
880 NM_SETTING_IP4_CONFIG_METHOD, priv->method);
881 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
884 } else if ( !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
885 || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
886 || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
887 if (priv->dns && priv->dns->len) {
889 NM_SETTING_IP4_CONFIG_ERROR,
890 NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
891 _("this property is not allowed for '%s=%s'"),
892 NM_SETTING_IP4_CONFIG_METHOD, priv->method);
893 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS);
897 if (g_slist_length (priv->dns_search)) {
899 NM_SETTING_IP4_CONFIG_ERROR,
900 NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
901 _("this property is not allowed for '%s=%s'"),
902 NM_SETTING_IP4_CONFIG_METHOD, priv->method);
903 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS_SEARCH);
907 /* Shared allows IP addresses; link-local and disabled do not */
908 if (strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
909 if (g_slist_length (priv->addresses)) {
911 NM_SETTING_IP4_CONFIG_ERROR,
912 NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
913 _("this property is not allowed for '%s=%s'"),
914 NM_SETTING_IP4_CONFIG_METHOD, priv->method);
915 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
919 } else if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
922 g_set_error_literal (error,
923 NM_SETTING_IP4_CONFIG_ERROR,
924 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
925 _("property is invalid"));
926 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
930 if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
931 g_set_error_literal (error,
932 NM_SETTING_IP4_CONFIG_ERROR,
933 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
934 _("property is empty"));
935 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID);
939 if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
940 g_set_error_literal (error,
941 NM_SETTING_IP4_CONFIG_ERROR,
942 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
943 _("property is empty"));
944 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
948 /* Validate addresses */
949 for (iter = priv->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
950 NMIP4Address *addr = (NMIP4Address *) iter->data;
951 guint32 prefix = nm_ip4_address_get_prefix (addr);
953 if (!nm_ip4_address_get_address (addr)) {
955 NM_SETTING_IP4_CONFIG_ERROR,
956 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
957 _("%d. IPv4 address is invalid"),
959 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
963 if (!prefix || prefix > 32) {
965 NM_SETTING_IP4_CONFIG_ERROR,
966 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
967 _("%d. IPv4 address has invalid prefix"),
969 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
974 /* Validate routes */
975 for (iter = priv->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
976 NMIP4Route *route = (NMIP4Route *) iter->data;
977 guint32 prefix = nm_ip4_route_get_prefix (route);
979 if (!prefix || prefix > 32) {
981 NM_SETTING_IP4_CONFIG_ERROR,
982 NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
983 _("%d. route has invalid prefix"),
985 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
995 nm_setting_ip4_config_init (NMSettingIP4Config *setting)
997 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
1000 priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
1004 finalize (GObject *object)
1006 NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
1007 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (self);
1009 g_free (priv->method);
1010 g_free (priv->dhcp_hostname);
1011 g_free (priv->dhcp_client_id);
1013 g_array_free (priv->dns, TRUE);
1015 g_slist_free_full (priv->dns_search, g_free);
1016 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
1017 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
1019 G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
1023 set_property (GObject *object, guint prop_id,
1024 const GValue *value, GParamSpec *pspec)
1026 NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
1027 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
1031 g_free (priv->method);
1032 priv->method = g_value_dup_string (value);
1035 g_array_free (priv->dns, TRUE);
1036 priv->dns = g_value_dup_boxed (value);
1038 priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
1040 case PROP_DNS_SEARCH:
1041 g_slist_free_full (priv->dns_search, g_free);
1042 priv->dns_search = g_value_dup_boxed (value);
1044 case PROP_ADDRESSES:
1045 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
1046 priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
1049 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
1050 priv->routes = nm_utils_ip4_routes_from_gvalue (value);
1052 case PROP_ROUTE_METRIC:
1053 priv->route_metric = g_value_get_int64 (value);
1055 case PROP_IGNORE_AUTO_ROUTES:
1056 priv->ignore_auto_routes = g_value_get_boolean (value);
1058 case PROP_IGNORE_AUTO_DNS:
1059 priv->ignore_auto_dns = g_value_get_boolean (value);
1061 case PROP_DHCP_CLIENT_ID:
1062 g_free (priv->dhcp_client_id);
1063 priv->dhcp_client_id = g_value_dup_string (value);
1065 case PROP_DHCP_SEND_HOSTNAME:
1066 priv->dhcp_send_hostname = g_value_get_boolean (value);
1068 case PROP_DHCP_HOSTNAME:
1069 g_free (priv->dhcp_hostname);
1070 priv->dhcp_hostname = g_value_dup_string (value);
1072 case PROP_DHCP_TIMEOUT:
1073 priv->dhcp_timeout = g_value_get_uint (value);
1075 case PROP_NEVER_DEFAULT:
1076 priv->never_default = g_value_get_boolean (value);
1079 priv->may_fail = g_value_get_boolean (value);
1082 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1088 get_property (GObject *object, guint prop_id,
1089 GValue *value, GParamSpec *pspec)
1091 NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
1092 NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
1096 g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
1099 g_value_set_boxed (value, priv->dns);
1101 case PROP_DNS_SEARCH:
1102 g_value_set_boxed (value, priv->dns_search);
1104 case PROP_ADDRESSES:
1105 nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
1108 nm_utils_ip4_routes_to_gvalue (priv->routes, value);
1110 case PROP_ROUTE_METRIC:
1111 g_value_set_int64 (value, priv->route_metric);
1113 case PROP_IGNORE_AUTO_ROUTES:
1114 g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
1116 case PROP_IGNORE_AUTO_DNS:
1117 g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
1119 case PROP_DHCP_CLIENT_ID:
1120 g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
1122 case PROP_DHCP_SEND_HOSTNAME:
1123 g_value_set_boolean (value, nm_setting_ip4_config_get_dhcp_send_hostname (setting));
1125 case PROP_DHCP_HOSTNAME:
1126 g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
1128 case PROP_DHCP_TIMEOUT:
1129 g_value_set_uint (value, nm_setting_ip4_config_get_dhcp_timeout (setting));
1131 case PROP_NEVER_DEFAULT:
1132 g_value_set_boolean (value, priv->never_default);
1135 g_value_set_boolean (value, priv->may_fail);
1138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1144 nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
1146 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1147 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1149 g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
1151 /* virtual methods */
1152 object_class->set_property = set_property;
1153 object_class->get_property = get_property;
1154 object_class->finalize = finalize;
1155 parent_class->verify = verify;
1159 * NMSettingIP4Config:method:
1161 * IPv4 configuration method. If "auto" is specified then the appropriate
1162 * automatic method (DHCP, PPP, etc) is used for the interface and most
1163 * other properties can be left unset. If "link-local" is specified, then a
1164 * link-local address in the 169.254/16 range will be assigned to the
1165 * interface. If "manual" is specified, static IP addressing is used and at
1166 * least one IP address must be given in the "addresses" property. If
1167 * "shared" is specified (indicating that this connection will provide
1168 * network access to other computers) then the interface is assigned an
1169 * address in the 10.42.x.1/24 range and a DHCP and forwarding DNS server
1170 * are started, and the interface is NAT-ed to the current default network
1171 * connection. "disabled" means IPv4 will not be used on this connection.
1172 * This property must be set.
1174 g_object_class_install_property
1175 (object_class, PROP_METHOD,
1176 g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD, "", "",
1179 NM_SETTING_PARAM_INFERRABLE |
1180 G_PARAM_STATIC_STRINGS));
1183 * NMSettingIP4Config:dns:
1185 * List of DNS servers (network byte order). For the "auto" method, these
1186 * DNS servers are appended to those (if any) returned by automatic
1187 * configuration. DNS servers cannot be used with the "shared",
1188 * "link-local", or "disabled" methods as there is no upstream network. In
1189 * all other methods, these DNS servers are used as the only DNS servers for
1192 g_object_class_install_property
1193 (object_class, PROP_DNS,
1194 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS, "", "",
1195 DBUS_TYPE_G_UINT_ARRAY,
1197 G_PARAM_STATIC_STRINGS));
1200 * NMSettingIP4Config:dns-search:
1202 * List of DNS search domains. For the "auto" method, these search domains
1203 * are appended to those returned by automatic configuration. Search domains
1204 * cannot be used with the "shared", "link-local", or "disabled" methods as
1205 * there is no upstream network. In all other methods, these search domains
1206 * are used as the only search domains for this connection.
1208 g_object_class_install_property
1209 (object_class, PROP_DNS_SEARCH,
1210 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS_SEARCH, "", "",
1211 DBUS_TYPE_G_LIST_OF_STRING,
1213 G_PARAM_STATIC_STRINGS));
1216 * NMSettingIP4Config:addresses:
1218 * Array of IPv4 address structures. Each IPv4 address structure is
1219 * composed of 3 32-bit values; the first being the IPv4 address (network
1220 * byte order), the second the prefix (1 - 32), and last the IPv4 gateway
1221 * (network byte order). The gateway may be left as 0 if no gateway exists
1222 * for that subnet. For the "auto" method, given IP addresses are appended
1223 * to those returned by automatic configuration. Addresses cannot be used
1224 * with the "shared", "link-local", or "disabled" methods as addressing is
1225 * either automatic or disabled with these methods.
1227 g_object_class_install_property
1228 (object_class, PROP_ADDRESSES,
1229 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ADDRESSES, "", "",
1230 DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
1232 NM_SETTING_PARAM_INFERRABLE |
1233 G_PARAM_STATIC_STRINGS));
1236 * NMSettingIP4Config:routes:
1238 * Array of IPv4 route structures. Each IPv4 route structure is composed of
1239 * 4 32-bit values; the first being the destination IPv4 network or address
1240 * (network byte order), the second the destination network or address
1241 * prefix (1 - 32), the third being the next-hop (network byte order) if
1242 * any, and the fourth being the route metric. For the "auto" method, given
1243 * IP routes are appended to those returned by automatic configuration.
1244 * Routes cannot be used with the "shared", "link-local", or "disabled"
1245 * methods because there is no upstream network.
1247 g_object_class_install_property
1248 (object_class, PROP_ROUTES,
1249 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ROUTES, "", "",
1250 DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
1252 NM_SETTING_PARAM_INFERRABLE |
1253 G_PARAM_STATIC_STRINGS));
1256 * NMSettingIP4Config:route-metric:
1258 * The default metric for routes that don't explicitly specify a metric.
1259 * The default value -1 means that the metric is choosen automatically
1260 * based on the device type.
1261 * The metric applies to dynamic routes, manual (static) routes that
1262 * don't have an explicit metric setting, address prefix routes, and
1263 * the default route.
1264 * As the linux kernel accepts zero (0) as a valid metric, zero is
1269 g_object_class_install_property
1270 (object_class, PROP_ROUTE_METRIC,
1271 g_param_spec_int64 (NM_SETTING_IP4_CONFIG_ROUTE_METRIC, "", "",
1272 -1, G_MAXUINT32, -1,
1275 G_PARAM_STATIC_STRINGS));
1278 * NMSettingIP4Config:ignore-auto-routes:
1280 * When the method is set to "auto" and this property to %TRUE,
1281 * automatically configured routes are ignored and only routes specified in
1282 * the #NMSettingIP4Config:routes property, if any, are used.
1284 g_object_class_install_property
1285 (object_class, PROP_IGNORE_AUTO_ROUTES,
1286 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, "", "",
1290 G_PARAM_STATIC_STRINGS));
1293 * NMSettingIP4Config:ignore-auto-dns:
1295 * When the method is set to "auto" and this property to %TRUE,
1296 * automatically configured nameservers and search domains are ignored and
1297 * only nameservers and search domains specified in the
1298 * #NMSettingIP4Config:dns and #NMSettingIP4Config:dns-search properties, if
1301 g_object_class_install_property
1302 (object_class, PROP_IGNORE_AUTO_DNS,
1303 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, "", "",
1307 G_PARAM_STATIC_STRINGS));
1310 * NMSettingIP4Config:dhcp-client-id:
1312 * A string sent to the DHCP server to identify the local machine which the
1313 * DHCP server may use to customize the DHCP lease and options.
1315 g_object_class_install_property
1316 (object_class, PROP_DHCP_CLIENT_ID,
1317 g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
1320 G_PARAM_STATIC_STRINGS));
1323 * NMSettingIP4Config:dhcp-send-hostname:
1325 * If %TRUE, a hostname is sent to the DHCP server when acquiring a lease.
1326 * Some DHCP servers use this hostname to update DNS databases, essentially
1327 * providing a static hostname for the computer. If the
1328 * #NMSettingIP4Config:dhcp-hostname property is empty and this property is
1329 * %TRUE, the current persistent hostname of the computer is sent.
1331 g_object_class_install_property
1332 (object_class, PROP_DHCP_SEND_HOSTNAME,
1333 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, "", "",
1337 G_PARAM_STATIC_STRINGS));
1340 * NMSettingIP4Config:dhcp-hostname:
1342 * If the #NMSettingIP4Config:dhcp-send-hostname property is %TRUE, then the
1343 * specified name will be sent to the DHCP server when acquiring a lease.
1345 g_object_class_install_property
1346 (object_class, PROP_DHCP_HOSTNAME,
1347 g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "", "",
1350 NM_SETTING_PARAM_INFERRABLE |
1351 G_PARAM_STATIC_STRINGS));
1354 * NMSettingIP4Config:dhcp-timeout:
1356 * Number of seconds after which the unfinished DHCP transaction fails
1357 * or zero for default.
1359 g_object_class_install_property
1360 (object_class, PROP_DHCP_TIMEOUT,
1361 g_param_spec_uint (NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT, "", "",
1364 G_PARAM_STATIC_STRINGS));
1367 * NMSettingIP4Config:never-default:
1369 * If %TRUE, this connection will never be the default IPv4 connection,
1370 * meaning it will never be assigned the default route by NetworkManager.
1372 g_object_class_install_property
1373 (object_class, PROP_NEVER_DEFAULT,
1374 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, "", "",
1378 G_PARAM_STATIC_STRINGS));
1381 * NMSettingIP4Config:may-fail:
1383 * If %TRUE, allow overall network configuration to proceed even if IPv4
1384 * configuration times out. Note that at least one IP configuration must
1385 * succeed or overall network configuration will still fail. For example,
1386 * in IPv6-only networks, setting this property to %TRUE allows the overall
1387 * network configuration to succeed if IPv4 configuration fails but IPv6
1388 * configuration completes successfully.
1390 g_object_class_install_property
1391 (object_class, PROP_MAY_FAIL,
1392 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MAY_FAIL, "", "",
1396 G_PARAM_STATIC_STRINGS));
1400 struct NMIP4Address {
1402 guint32 address; /* network byte order */
1404 guint32 gateway; /* network byte order */
1408 * nm_ip4_address_new:
1410 * Creates and returns a new #NMIP4Address object.
1412 * Returns: (transfer full): the new empty #NMIP4Address object
1415 nm_ip4_address_new (void)
1417 NMIP4Address *address;
1419 address = g_malloc0 (sizeof (NMIP4Address));
1420 address->refcount = 1;
1425 * nm_ip4_address_dup:
1426 * @source: the #NMIP4Address object to copy
1428 * Copies a given #NMIP4Address object and returns the copy.
1430 * Returns: (transfer full): the copy of the given #NMIP4Address copy
1433 nm_ip4_address_dup (NMIP4Address *source)
1435 NMIP4Address *address;
1437 g_return_val_if_fail (source != NULL, NULL);
1438 g_return_val_if_fail (source->refcount > 0, NULL);
1440 address = nm_ip4_address_new ();
1441 address->address = source->address;
1442 address->prefix = source->prefix;
1443 address->gateway = source->gateway;
1449 * nm_ip4_address_ref:
1450 * @address: the #NMIP4Address
1452 * Increases the reference count of the object.
1455 nm_ip4_address_ref (NMIP4Address *address)
1457 g_return_if_fail (address != NULL);
1458 g_return_if_fail (address->refcount > 0);
1460 address->refcount++;
1464 * nm_ip4_address_unref:
1465 * @address: the #NMIP4Address
1467 * Decreases the reference count of the object. If the reference count
1468 * reaches zero, the object will be destroyed.
1471 nm_ip4_address_unref (NMIP4Address *address)
1473 g_return_if_fail (address != NULL);
1474 g_return_if_fail (address->refcount > 0);
1476 address->refcount--;
1477 if (address->refcount == 0) {
1478 memset (address, 0, sizeof (NMIP4Address));
1484 * nm_ip4_address_compare:
1485 * @address: the #NMIP4Address
1486 * @other: the #NMIP4Address to compare @address to.
1488 * Determines if two #NMIP4Address objects contain the same values.
1490 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
1493 nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other)
1495 g_return_val_if_fail (address != NULL, FALSE);
1496 g_return_val_if_fail (address->refcount > 0, FALSE);
1498 g_return_val_if_fail (other != NULL, FALSE);
1499 g_return_val_if_fail (other->refcount > 0, FALSE);
1501 if ( address->address != other->address
1502 || address->prefix != other->prefix
1503 || address->gateway != other->gateway)
1509 * nm_ip4_address_get_address:
1510 * @address: the #NMIP4Address
1512 * Gets the IPv4 address property of this address object.
1514 * Returns: the IPv4 address in network byte order
1517 nm_ip4_address_get_address (NMIP4Address *address)
1519 g_return_val_if_fail (address != NULL, 0);
1520 g_return_val_if_fail (address->refcount > 0, 0);
1522 return address->address;
1526 * nm_ip4_address_set_address:
1527 * @address: the #NMIP4Address
1528 * @addr: the IPv4 address in network byte order
1530 * Sets the IPv4 address property of this object.
1533 nm_ip4_address_set_address (NMIP4Address *address, guint32 addr)
1535 g_return_if_fail (address != NULL);
1536 g_return_if_fail (address->refcount > 0);
1538 address->address = addr;
1542 * nm_ip4_address_get_prefix:
1543 * @address: the #NMIP4Address
1545 * Gets the IPv4 address prefix (ie "24" or "30" etc) property of this address
1548 * Returns: the IPv4 address prefix
1551 nm_ip4_address_get_prefix (NMIP4Address *address)
1553 g_return_val_if_fail (address != NULL, 0);
1554 g_return_val_if_fail (address->refcount > 0, 0);
1556 return address->prefix;
1560 * nm_ip4_address_set_prefix:
1561 * @address: the #NMIP4Address
1562 * @prefix: the address prefix, a number between 1 and 32 inclusive
1564 * Sets the IPv4 address prefix.
1567 nm_ip4_address_set_prefix (NMIP4Address *address, guint32 prefix)
1569 g_return_if_fail (address != NULL);
1570 g_return_if_fail (address->refcount > 0);
1571 g_return_if_fail (prefix <= 32);
1572 g_return_if_fail (prefix > 0);
1574 address->prefix = prefix;
1578 * nm_ip4_address_get_gateway:
1579 * @address: the #NMIP4Address
1581 * Gets the IPv4 default gateway property of this address object.
1583 * Returns: the IPv4 gateway address in network byte order
1586 nm_ip4_address_get_gateway (NMIP4Address *address)
1588 g_return_val_if_fail (address != NULL, 0);
1589 g_return_val_if_fail (address->refcount > 0, 0);
1591 return address->gateway;
1595 * nm_ip4_address_set_gateway:
1596 * @address: the #NMIP4Address
1597 * @gateway: the IPv4 default gateway in network byte order
1599 * Sets the IPv4 default gateway property of this address object.
1602 nm_ip4_address_set_gateway (NMIP4Address *address, guint32 gateway)
1604 g_return_if_fail (address != NULL);
1605 g_return_if_fail (address->refcount > 0);
1607 address->gateway = gateway;
1614 guint32 dest; /* network byte order */
1616 guint32 next_hop; /* network byte order */
1617 guint32 metric; /* lower metric == more preferred */
1623 * Creates and returns a new #NMIP4Route object.
1625 * Returns: (transfer full): the new empty #NMIP4Route object
1628 nm_ip4_route_new (void)
1632 route = g_malloc0 (sizeof (NMIP4Route));
1633 route->refcount = 1;
1639 * @source: the #NMIP4Route object to copy
1641 * Copies a given #NMIP4Route object and returns the copy.
1643 * Returns: (transfer full): the copy of the given #NMIP4Route copy
1646 nm_ip4_route_dup (NMIP4Route *source)
1650 g_return_val_if_fail (source != NULL, NULL);
1651 g_return_val_if_fail (source->refcount > 0, NULL);
1653 route = nm_ip4_route_new ();
1654 route->dest = source->dest;
1655 route->prefix = source->prefix;
1656 route->next_hop = source->next_hop;
1657 route->metric = source->metric;
1664 * @route: the #NMIP4Route
1666 * Increases the reference count of the object.
1669 nm_ip4_route_ref (NMIP4Route *route)
1671 g_return_if_fail (route != NULL);
1672 g_return_if_fail (route->refcount > 0);
1678 * nm_ip4_route_unref:
1679 * @route: the #NMIP4Route
1681 * Decreases the reference count of the object. If the reference count
1682 * reaches zero, the object will be destroyed.
1685 nm_ip4_route_unref (NMIP4Route *route)
1687 g_return_if_fail (route != NULL);
1688 g_return_if_fail (route->refcount > 0);
1691 if (route->refcount == 0) {
1692 memset (route, 0, sizeof (NMIP4Route));
1698 * nm_ip4_route_compare:
1699 * @route: the #NMIP4Route
1700 * @other: the #NMIP4Route to compare @route to.
1702 * Determines if two #NMIP4Route objects contain the same values.
1704 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
1707 nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other)
1709 g_return_val_if_fail (route != NULL, FALSE);
1710 g_return_val_if_fail (route->refcount > 0, FALSE);
1712 g_return_val_if_fail (other != NULL, FALSE);
1713 g_return_val_if_fail (other->refcount > 0, FALSE);
1715 if ( route->dest != other->dest
1716 || route->prefix != other->prefix
1717 || route->next_hop != other->next_hop
1718 || route->metric != other->metric)
1724 * nm_ip4_route_get_dest:
1725 * @route: the #NMIP4Route
1727 * Gets the IPv4 destination address property of this route object.
1729 * Returns: the IPv4 address in network byte order
1732 nm_ip4_route_get_dest (NMIP4Route *route)
1734 g_return_val_if_fail (route != NULL, 0);
1735 g_return_val_if_fail (route->refcount > 0, 0);
1741 * nm_ip4_route_set_dest:
1742 * @route: the #NMIP4Route
1743 * @dest: the destination address in network byte order
1745 * Sets the IPv4 destination address property of this route object.
1748 nm_ip4_route_set_dest (NMIP4Route *route, guint32 dest)
1750 g_return_if_fail (route != NULL);
1751 g_return_if_fail (route->refcount > 0);
1757 * nm_ip4_route_get_prefix:
1758 * @route: the #NMIP4Route
1760 * Gets the IPv4 prefix (ie "24" or "30" etc) of this route.
1762 * Returns: the IPv4 prefix
1765 nm_ip4_route_get_prefix (NMIP4Route *route)
1767 g_return_val_if_fail (route != NULL, 0);
1768 g_return_val_if_fail (route->refcount > 0, 0);
1770 return route->prefix;
1774 * nm_ip4_route_set_prefix:
1775 * @route: the #NMIP4Route
1776 * @prefix: the prefix, a number between 1 and 32 inclusive
1778 * Sets the IPv4 prefix of this route.
1781 nm_ip4_route_set_prefix (NMIP4Route *route, guint32 prefix)
1783 g_return_if_fail (route != NULL);
1784 g_return_if_fail (route->refcount > 0);
1785 g_return_if_fail (prefix <= 32);
1786 g_return_if_fail (prefix > 0);
1788 route->prefix = prefix;
1792 * nm_ip4_route_get_next_hop:
1793 * @route: the #NMIP4Route
1795 * Gets the IPv4 address of the next hop of this route.
1797 * Returns: the IPv4 address in network byte order
1800 nm_ip4_route_get_next_hop (NMIP4Route *route)
1802 g_return_val_if_fail (route != NULL, 0);
1803 g_return_val_if_fail (route->refcount > 0, 0);
1805 return route->next_hop;
1809 * nm_ip4_route_set_next_hop:
1810 * @route: the #NMIP4Route
1811 * @next_hop: the IPv4 address of the next hop in network byte order
1813 * Sets the IPv4 address of the next hop of this route.
1816 nm_ip4_route_set_next_hop (NMIP4Route *route, guint32 next_hop)
1818 g_return_if_fail (route != NULL);
1819 g_return_if_fail (route->refcount > 0);
1821 route->next_hop = next_hop;
1825 * nm_ip4_route_get_metric:
1826 * @route: the #NMIP4Route
1828 * Gets the route metric property of this route object; lower values indicate
1829 * "better" or more preferred routes.
1831 * Returns: the route metric
1834 nm_ip4_route_get_metric (NMIP4Route *route)
1836 g_return_val_if_fail (route != NULL, 0);
1837 g_return_val_if_fail (route->refcount > 0, 0);
1839 return route->metric;
1843 * nm_ip4_route_set_metric:
1844 * @route: the #NMIP4Route
1845 * @metric: the route metric
1847 * Sets the route metric property of this route object; lower values indicate
1848 * "better" or more preferred routes.
1851 nm_ip4_route_set_metric (NMIP4Route *route, guint32 metric)
1853 g_return_if_fail (route != NULL);
1854 g_return_if_fail (route->refcount > 0);
1856 route->metric = metric;