nm-setting-ip4-config.c 53.3 KB
Newer Older
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
19 20
 * Copyright 2007 - 2014 Red Hat, Inc.
 * Copyright 2007 - 2008 Novell, Inc.
21 22
 */

23 24
#include "config.h"

25
#include <string.h>
26
#include <dbus/dbus-glib.h>
27
#include <glib/gi18n-lib.h>
28

29 30 31
#include "nm-setting-ip4-config.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
32
#include "nm-dbus-glib-types.h"
33
#include "nm-glib-compat.h"
34
#include "nm-setting-private.h"
35

36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/**
 * SECTION:nm-setting-ip4-config
 * @short_description: Describes IPv4 addressing, routing, and name service properties
 * @include: nm-setting-ip4-config.h
 *
 * The #NMSettingIP4Config object is a #NMSetting subclass that describes
 * properties related to IPv4 addressing, routing, and Domain Name Service
 **/

/**
 * nm_setting_ip4_config_error_quark:
 *
 * Registers an error quark for #NMSettingIP4Config if necessary.
 *
 * Returns: the error quark used for #NMSettingIP4Config errors.
 **/
53 54 55 56 57 58 59 60 61 62
GQuark
nm_setting_ip4_config_error_quark (void)
{
	static GQuark quark;

	if (G_UNLIKELY (!quark))
		quark = g_quark_from_static_string ("nm-setting-ip4-config-error-quark");
	return quark;
}

63 64
G_DEFINE_BOXED_TYPE (NMIP4Address, nm_ip4_address, nm_ip4_address_dup, nm_ip4_address_unref)
G_DEFINE_BOXED_TYPE (NMIP4Route, nm_ip4_route, nm_ip4_route_dup, nm_ip4_route_unref)
65

66 67 68 69 70 71
G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING,
                         _nm_register_setting (NM_SETTING_IP4_CONFIG_SETTING_NAME,
                                               g_define_type_id,
                                               4,
                                               NM_SETTING_IP4_CONFIG_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
72

73 74 75 76 77 78 79 80
#define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))

typedef struct {
	char *method;
	GArray *dns;        /* array of guint32; elements in network byte order */
	GSList *dns_search; /* list of strings */
	GSList *addresses;  /* array of NMIP4Address */
	GSList *routes;     /* array of NMIP4Route */
81
	gint64  route_metric;
82 83 84
	gboolean ignore_auto_routes;
	gboolean ignore_auto_dns;
	char *dhcp_client_id;
85
	gboolean dhcp_send_hostname;
86
	char *dhcp_hostname;
87
	gboolean never_default;
88
	gboolean may_fail;
89 90
} NMSettingIP4ConfigPrivate;

91 92
enum {
	PROP_0,
93
	PROP_METHOD,
94 95 96
	PROP_DNS,
	PROP_DNS_SEARCH,
	PROP_ADDRESSES,
97
	PROP_ROUTES,
98
	PROP_ROUTE_METRIC,
99 100
	PROP_IGNORE_AUTO_ROUTES,
	PROP_IGNORE_AUTO_DNS,
101
	PROP_DHCP_CLIENT_ID,
102
	PROP_DHCP_SEND_HOSTNAME,
103
	PROP_DHCP_HOSTNAME,
104
	PROP_NEVER_DEFAULT,
105
	PROP_MAY_FAIL,
106 107 108 109

	LAST_PROP
};

110 111 112 113 114
/**
 * nm_setting_ip4_config_new:
 *
 * Creates a new #NMSettingIP4Config object with default values.
 *
115
 * Returns: (transfer full): the new empty #NMSettingIP4Config object
116
 **/
117 118 119 120 121 122
NMSetting *
nm_setting_ip4_config_new (void)
{
	return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
}

123 124 125 126 127 128
/**
 * nm_setting_ip4_config_get_method:
 * @setting: the #NMSettingIP4Config
 *
 * Returns: the #NMSettingIP4Config:method property of the setting
 **/
129 130 131 132 133 134 135 136
const char *
nm_setting_ip4_config_get_method (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->method;
}

137 138 139 140 141 142
/**
 * nm_setting_ip4_config_get_num_dns:
 * @setting: the #NMSettingIP4Config
 *
 * Returns: the number of configured DNS servers
 **/
143 144 145 146 147 148 149 150
guint32
nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns->len;
}

151 152 153 154 155 156 157 158
/**
 * nm_setting_ip4_config_get_dns:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the DNS server to return
 *
 * Returns: the IPv4 address (network byte order) of the DNS server at index
 * @i
 **/
159 160 161 162 163 164 165 166 167 168 169 170 171
guint32
nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= priv->dns->len, 0);

	return g_array_index (priv->dns, guint32, i);
}

172 173 174 175 176 177 178 179 180 181
/**
 * nm_setting_ip4_config_add_dns:
 * @setting: the #NMSettingIP4Config
 * @dns: the IPv4 address (network byte order) of the DNS server to add
 *
 * Adds a new DNS server to the setting.
 *
 * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
 * known
 **/
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
gboolean
nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns)
{
	NMSettingIP4ConfigPrivate *priv;
	int i;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (i = 0; i < priv->dns->len; i++) {
		if (dns == g_array_index (priv->dns, guint32, i))
			return FALSE;
	}

	g_array_append_val (priv->dns, dns);
197
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
198 199 200
	return TRUE;
}

201 202 203 204 205 206 207
/**
 * nm_setting_ip4_config_remove_dns:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the DNS server to remove
 *
 * Removes the DNS server at index @i.
 **/
208 209 210 211 212 213 214 215 216 217 218
void
nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_return_if_fail (i <= priv->dns->len);

	g_array_remove_index (priv->dns, i);
219
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
220 221
}

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
/**
 * nm_setting_ip4_config_remove_dns_by_value:
 * @setting: the #NMSettingIP4Config
 * @dns: the DNS server to remove
 *
 * Removes the DNS server @dns.
 *
 * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
 * domain was already known
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns)
{
	NMSettingIP4ConfigPrivate *priv;
	int i;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (i = 0; i < priv->dns->len; i++) {
		if (dns == g_array_index (priv->dns, guint32, i)) {
			g_array_remove_index (priv->dns, i);
			g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
			return TRUE;
		}
	}
	return FALSE;
}

253 254 255 256 257 258
/**
 * nm_setting_ip4_config_clear_dns:
 * @setting: the #NMSettingIP4Config
 *
 * Removes all configured DNS servers.
 **/
259 260 261 262 263 264 265 266 267
void
nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_array_remove_range (priv->dns, 0, priv->dns->len);
268
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
269 270
}

271 272 273 274 275 276
/**
 * nm_setting_ip4_config_get_num_dns_searches:
 * @setting: the #NMSettingIP4Config
 *
 * Returns: the number of configured DNS search domains
 **/
277 278 279 280 281 282 283 284
guint32
nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);

	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search);
}

285 286 287 288 289 290 291
/**
 * nm_setting_ip4_config_get_dns_search:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the DNS search domain to return
 *
 * Returns: the DNS search domain at index @i
 **/
292 293 294 295 296 297 298 299 300 301 302 303 304
const char *
nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->dns_search), NULL);

	return (const char *) g_slist_nth_data (priv->dns_search, i);
}

305 306 307 308 309 310 311 312 313 314
/**
 * nm_setting_ip4_config_add_dns_search:
 * @setting: the #NMSettingIP4Config
 * @dns_search: the search domain to add
 *
 * Adds a new DNS search domain to the setting.
 *
 * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
 * domain was already known
 **/
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
gboolean
nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting,
                                      const char *dns_search)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (dns_search != NULL, FALSE);
	g_return_val_if_fail (dns_search[0] != '\0', FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
		if (!strcmp (dns_search, (char *) iter->data))
			return FALSE;
	}

	priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
333
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
334 335 336
	return TRUE;
}

337 338 339 340 341 342 343
/**
 * nm_setting_ip4_config_remove_dns_search:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the DNS search domain
 *
 * Removes the DNS search domain at index @i.
 **/
344 345 346 347 348 349 350 351 352 353 354 355 356 357
void
nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *elt;

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	elt = g_slist_nth (priv->dns_search, i);
	g_return_if_fail (elt != NULL);

	g_free (elt->data);
	priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
358
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
359 360
}

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
/**
 * nm_setting_ip4_config_remove_dns_search_by_value:
 * @setting: the #NMSettingIP4Config
 * @dns_search: the search domain to remove
 *
 * Removes the DNS search domain @dns_search.
 *
 * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
 *
 * Since 0.9.10
 **/
gboolean
nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting,
                                                  const char *dns_search)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (dns_search != NULL, FALSE);
	g_return_val_if_fail (dns_search[0] != '\0', FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
		if (!strcmp (dns_search, (char *) iter->data)) {
			priv->dns_search = g_slist_delete_link (priv->dns_search, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
			return TRUE;
		}
	}
	return FALSE;
}

394 395 396 397 398 399
/**
 * nm_setting_ip4_config_clear_dns_searches:
 * @setting: the #NMSettingIP4Config
 *
 * Removes all configured DNS search domains.
 **/
400 401 402 403 404
void
nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting)
{
	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

405
	g_slist_free_full (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
406
	NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
407
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
408 409
}

410 411 412 413 414 415
/**
 * nm_setting_ip4_config_get_num_addresses:
 * @setting: the #NMSettingIP4Config
 *
 * Returns: the number of configured addresses
 **/
416 417 418 419 420 421 422 423
guint32
nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);

	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->addresses);
}

424 425 426 427 428 429 430
/**
 * nm_setting_ip4_config_get_address:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the address to return
 *
 * Returns: the address at index @i
 **/
431 432 433 434 435 436 437 438 439 440 441 442 443
NMIP4Address *
nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->addresses), NULL);

	return (NMIP4Address *) g_slist_nth_data (priv->addresses, i);
}

444 445 446 447 448 449 450 451 452 453 454
/**
 * nm_setting_ip4_config_add_address:
 * @setting: the #NMSettingIP4Config
 * @address: the new address to add
 *
 * Adds a new IPv4 address and associated information to the setting.  The
 * given address is duplicated internally and is not changed by this function.
 *
 * Returns: %TRUE if the address was added; %FALSE if the address was already
 * known.
 **/
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
gboolean
nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
                                   NMIP4Address *address)
{
	NMSettingIP4ConfigPrivate *priv;
	NMIP4Address *copy;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (address != NULL, FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
		if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address))
			return FALSE;
	}

	copy = nm_ip4_address_dup (address);
	priv->addresses = g_slist_append (priv->addresses, copy);
474
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
475 476 477
	return TRUE;
}

478 479 480 481 482 483 484
/**
 * nm_setting_ip4_config_remove_address:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the address to remove
 *
 * Removes the address at index @i.
 **/
485 486 487 488
void
nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;
489
	GSList *elt;
490 491 492 493

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
494 495
	elt = g_slist_nth (priv->addresses, i);
	g_return_if_fail (elt != NULL);
496

497 498
	nm_ip4_address_unref ((NMIP4Address *) elt->data);
	priv->addresses = g_slist_delete_link (priv->addresses, elt);
499
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
500 501
}

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
/**
 * nm_setting_ip4_config_remove_address_by_value:
 * @setting: the #NMSettingIP4Config
 * @address: the IP address to remove
 *
 * Removes the address @address.
 *
 * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting,
                                               NMIP4Address *address)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (address != NULL, FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
		if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) {
			nm_ip4_address_unref ((NMIP4Address *) iter->data);
			priv->addresses = g_slist_delete_link (priv->addresses, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
			return TRUE;
		}
	}
	return FALSE;
}

535 536 537 538 539 540
/**
 * nm_setting_ip4_config_clear_addresses:
 * @setting: the #NMSettingIP4Config
 *
 * Removes all configured addresses.
 **/
541 542 543 544 545 546 547
void
nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting)
{
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

548
	g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
549
	priv->addresses = NULL;
550
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
551 552
}

553 554 555 556 557 558
/**
 * nm_setting_ip4_config_get_num_routes:
 * @setting: the #NMSettingIP4Config
 *
 * Returns: the number of configured routes
 **/
559 560 561 562 563 564 565 566
guint32
nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);

	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->routes);
}

567 568 569 570 571 572 573
/**
 * nm_setting_ip4_config_get_route:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the route to return
 *
 * Returns: the route at index @i
 **/
574 575 576 577 578 579 580 581 582 583 584 585 586
NMIP4Route *
nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->routes), NULL);

	return (NMIP4Route *) g_slist_nth_data (priv->routes, i);
}

587 588 589 590 591 592 593 594 595 596
/**
 * nm_setting_ip4_config_add_route:
 * @setting: the #NMSettingIP4Config
 * @route: the route to add
 *
 * Adds a new IPv4 route and associated information to the setting.  The
 * given route is duplicated internally and is not changed by this function.
 *
 * Returns: %TRUE if the route was added; %FALSE if the route was already known.
 **/
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
gboolean
nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
                                 NMIP4Route *route)
{
	NMSettingIP4ConfigPrivate *priv;
	NMIP4Route *copy;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (route != NULL, FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
		if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route))
			return FALSE;
	}

	copy = nm_ip4_route_dup (route);
	priv->routes = g_slist_append (priv->routes, copy);
616
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
617 618 619
	return TRUE;
}

620 621 622 623 624 625 626
/**
 * nm_setting_ip4_config_remove_route:
 * @setting: the #NMSettingIP4Config
 * @i: index number of the route
 *
 * Removes the route at index @i.
 **/
627 628 629 630 631 632 633 634 635 636 637 638 639 640
void
nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *elt;

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	elt = g_slist_nth (priv->routes, i);
	g_return_if_fail (elt != NULL);

	nm_ip4_route_unref ((NMIP4Route *) elt->data);
	priv->routes = g_slist_delete_link (priv->routes, elt);
641
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
642 643
}

644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
/**
 * nm_setting_ip4_config_remove_route_by_value:
 * @setting: the #NMSettingIP4Config
 * @route: the route to remove
 *
 * Removes the route @route.
 *
 * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting,
                                             NMIP4Route *route)
{
	NMSettingIP4ConfigPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
	g_return_val_if_fail (route != NULL, FALSE);

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
		if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route)) {
			nm_ip4_route_unref ((NMIP4Route *) iter->data);
			priv->routes = g_slist_delete_link (priv->routes, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
			return TRUE;
		}
	}
	return FALSE;
}

677 678 679 680 681 682
/**
 * nm_setting_ip4_config_clear_routes:
 * @setting: the #NMSettingIP4Config
 *
 * Removes all configured routes.
 **/
683 684 685 686 687 688 689
void
nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
{
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

690
	g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
691
	priv->routes = NULL;
692
	g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
693 694
}

695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
/**
 * nm_setting_ip4_config_get_route_metric:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:route-metric
 * property.
 *
 * Returns: the route metric that is used for IPv4 routes that don't explicitly
 * specify a metric. See #NMSettingIP4Config:route-metric for more details.
 *
 * Since: 1.0
 **/
gint64
nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), -1);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->route_metric;
}

715 716 717 718 719 720 721 722 723 724
/**
 * nm_setting_ip4_config_get_ignore_auto_routes:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:ignore-auto-routes
 * property.
 *
 * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
 * ignored.
 **/
725 726 727 728 729 730 731 732
gboolean
nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
}

733 734 735 736 737 738 739 740 741 742
/**
 * nm_setting_ip4_config_get_ignore_auto_dns:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:ignore-auto-dns
 * property.
 *
 * Returns: %TRUE if automatically configured (ie via DHCP) DNS information
 * should be ignored.
 **/
743 744 745 746 747 748 749 750
gboolean
nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
}

751 752 753 754 755 756 757 758 759 760
/**
 * nm_setting_ip4_config_get_dhcp_client_id:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:dhcp-client-id
 * property.
 *
 * Returns: the configured Client ID to send to the DHCP server when requesting
 * addresses via DHCP.
 **/
761 762 763
const char *
nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
{
764
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
765 766 767 768

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
}

769 770 771 772 773 774 775 776 777 778 779
/**
 * nm_setting_ip4_config_get_dhcp_send_hostname:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:dhcp-send-hostname
 * property.
 *
 * Returns: %TRUE if NetworkManager should send the machine hostname to the
 * DHCP server when requesting addresses to allow the server to automatically
 * update DNS information for this machine.
 **/
780 781 782 783 784 785 786 787
gboolean
nm_setting_ip4_config_get_dhcp_send_hostname (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_send_hostname;
}

788 789 790 791 792 793 794 795 796
/**
 * nm_setting_ip4_config_get_dhcp_hostname:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:dhcp-hostname
 * property.
 *
 * Returns: the configured hostname to send to the DHCP server
 **/
797 798 799
const char *
nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting)
{
800
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
801 802 803 804

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
}

805 806 807 808 809 810 811 812 813 814
/**
 * nm_setting_ip4_config_get_never_default:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:never-default
 * property.
 *
 * Returns: %TRUE if this connection should never be the default connection
 * for IPv4 addressing
 **/
815 816 817 818 819 820 821 822
gboolean
nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->never_default;
}

823 824 825 826 827 828 829 830 831 832
/**
 * nm_setting_ip4_config_get_may_fail:
 * @setting: the #NMSettingIP4Config
 *
 * Returns the value contained in the #NMSettingIP4Config:may-fail
 * property.
 *
 * Returns: %TRUE if this connection doesn't require IPv4 addressing to complete
 * for the connection to succeed.
 **/
833 834 835 836 837 838 839 840
gboolean
nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);

	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->may_fail;
}

841
static gboolean
842
verify (NMSetting *setting, GSList *all_settings, GError **error)
843
{
844
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
845
	GSList *iter;
846
	int i;
847

848
	if (!priv->method) {
849 850 851 852
		g_set_error_literal (error,
		                     NM_SETTING_IP4_CONFIG_ERROR,
		                     NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
		                     _("property is missing"));
853
		g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
854
		return FALSE;
855
	}
856

857 858
	if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
		if (!priv->addresses) {
859 860 861 862 863
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
			             _("this property cannot be empty for '%s=%s'"),
			             NM_SETTING_IP4_CONFIG_METHOD, priv->method);
864
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
865 866
			return FALSE;
		}
867
	} else if (   !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
868 869
	           || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
	           || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
870
		if (priv->dns && priv->dns->len) {
871 872 873
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
874 875
			             _("this property is not allowed for '%s=%s'"),
			             NM_SETTING_IP4_CONFIG_METHOD, priv->method);
876
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS);
877 878 879
			return FALSE;
		}

880
		if (g_slist_length (priv->dns_search)) {
881 882 883
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
884 885
			             _("this property is not allowed for '%s=%s'"),
			             NM_SETTING_IP4_CONFIG_METHOD, priv->method);
886
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS_SEARCH);
887 888 889
			return FALSE;
		}

890 891 892 893 894 895 896 897 898 899 900
		/* Shared allows IP addresses; link-local and disabled do not */
		if (strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
			if (g_slist_length (priv->addresses)) {
				g_set_error (error,
				             NM_SETTING_IP4_CONFIG_ERROR,
				             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
				             _("this property is not allowed for '%s=%s'"),
				             NM_SETTING_IP4_CONFIG_METHOD, priv->method);
				g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
				return FALSE;
			}
901
		}
902
	} else if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
903 904
		/* nothing to do */
	} else {
905 906 907 908
		g_set_error_literal (error,
		                     NM_SETTING_IP4_CONFIG_ERROR,
		                     NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
		                     _("property is invalid"));
909
		g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
910
		return FALSE;
911 912
	}

913
	if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
914 915 916 917
		g_set_error_literal (error,
		                     NM_SETTING_IP4_CONFIG_ERROR,
		                     NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
		                     _("property is empty"));
918
		g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID);
919 920 921
		return FALSE;
	}

922
	if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
923 924 925 926
		g_set_error_literal (error,
		                     NM_SETTING_IP4_CONFIG_ERROR,
		                     NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
		                     _("property is empty"));
927
		g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
928 929 930
		return FALSE;
	}

931
	/* Validate addresses */
932
	for (iter = priv->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
933 934
		NMIP4Address *addr = (NMIP4Address *) iter->data;
		guint32 prefix = nm_ip4_address_get_prefix (addr);
935

936
		if (!nm_ip4_address_get_address (addr)) {
937 938 939
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
940 941
			             _("%d. IPv4 address is invalid"),
			             i+1);
942
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
943 944 945
			return FALSE;
		}

946
		if (!prefix || prefix > 32) {
947 948 949
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
950 951
			             _("%d. IPv4 address has invalid prefix"),
			             i+1);
952
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
953 954 955 956 957
			return FALSE;
		}
	}

	/* Validate routes */
958 959 960
	for (iter = priv->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
		NMIP4Route *route = (NMIP4Route *) iter->data;
		guint32 prefix = nm_ip4_route_get_prefix (route);
961

962
		if (!nm_ip4_route_get_dest (route)) {
963 964 965
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
966 967
			             _("%d. route is invalid"),
			             i+1);
968
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
969 970 971
			return FALSE;
		}

972
		if (!prefix || prefix > 32) {
973 974 975
			g_set_error (error,
			             NM_SETTING_IP4_CONFIG_ERROR,
			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
976 977
			             _("%d. route has invalid prefix"),
			             i+1);
978
			g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
979 980 981 982
			return FALSE;
		}
	}

983 984 985 986 987 988 989
	return TRUE;
}


static void
nm_setting_ip4_config_init (NMSettingIP4Config *setting)
{
990 991 992 993
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);


	priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
994 995 996 997 998 999
}

static void
finalize (GObject *object)
{
	NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
1000
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (self);
1001

1002
	g_free (priv->method);
1003 1004
	g_free (priv->dhcp_hostname);
	g_free (priv->dhcp_client_id);
1005

1006
	g_array_free (priv->dns, TRUE);
1007

1008 1009 1010
	g_slist_free_full (priv->dns_search, g_free);
	g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
	g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
1011 1012 1013 1014 1015 1016

	G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
}

static void
set_property (GObject *object, guint prop_id,
1017
              const GValue *value, GParamSpec *pspec)
1018 1019
{
	NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
1020
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
1021 1022

	switch (prop_id) {
1023
	case PROP_METHOD:
1024 1025
		g_free (priv->method);
		priv->method = g_value_dup_string (value);
1026
		break;
1027
	case PROP_DNS:
1028 1029 1030
		g_array_free (priv->dns, TRUE);
		priv->dns = g_value_dup_boxed (value);
		if (!priv->dns)
Thomas Haller's avatar
Thomas Haller committed
1031
			priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
1032 1033
		break;
	case PROP_DNS_SEARCH:
1034
		g_slist_free_full (priv->dns_search, g_free);
1035
		priv->dns_search = g_value_dup_boxed (value);
1036 1037
		break;
	case PROP_ADDRESSES:
1038
		g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
1039
		priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
1040
		break;
1041
	case PROP_ROUTES:
1042
		g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
1043
		priv->routes = nm_utils_ip4_routes_from_gvalue (value);
1044
		break;
1045 1046 1047
	case PROP_ROUTE_METRIC:
		priv->route_metric = g_value_get_int64 (value);
		break;
1048
	case PROP_IGNORE_AUTO_ROUTES:
1049
		priv->ignore_auto_routes = g_value_get_boolean (value);
1050 1051
		break;
	case PROP_IGNORE_AUTO_DNS:
1052
		priv->ignore_auto_dns = g_value_get_boolean (value);
1053
		break;
1054
	case PROP_DHCP_CLIENT_ID:
1055 1056
		g_free (priv->dhcp_client_id);
		priv->dhcp_client_id = g_value_dup_string (value);
1057
		break;
1058 1059 1060
	case PROP_DHCP_SEND_HOSTNAME:
		priv->dhcp_send_hostname = g_value_get_boolean (value);
		break;
1061
	case PROP_DHCP_HOSTNAME:
1062 1063
		g_free (priv->dhcp_hostname);
		priv->dhcp_hostname = g_value_dup_string (value);
1064
		break;
1065 1066 1067
	case PROP_NEVER_DEFAULT:
		priv->never_default = g_value_get_boolean (value);
		break;
1068 1069 1070
	case PROP_MAY_FAIL:
		priv->may_fail = g_value_get_boolean (value);
		break;
1071 1072 1073 1074 1075 1076 1077 1078
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
get_property (GObject *object, guint prop_id,
1079
              GValue *value, GParamSpec *pspec)
1080 1081
{
	NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
1082
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
1083 1084

	switch (prop_id) {
1085
	case PROP_METHOD:
1086
		g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
1087
		break;
1088
	case PROP_DNS:
1089
		g_value_set_boxed (value, priv->dns);
1090 1091
		break;
	case PROP_DNS_SEARCH:
1092
		g_value_set_boxed (value, priv->dns_search);
1093 1094
		break;
	case PROP_ADDRESSES:
1095
		nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
1096
		break;
1097
	case PROP_ROUTES:
1098
		nm_utils_ip4_routes_to_gvalue (priv->routes, value);
1099
		break;
1100 1101 1102
	case PROP_ROUTE_METRIC:
		g_value_set_int64 (value, priv->route_metric);
		break;
1103
	case PROP_IGNORE_AUTO_ROUTES:
1104
		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
1105
		break;
1106
	case PROP_IGNORE_AUTO_DNS:
1107
		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
1108
		break;
1109
	case PROP_DHCP_CLIENT_ID:
1110
		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
1111
		break;
1112 1113 1114
	case PROP_DHCP_SEND_HOSTNAME:
		g_value_set_boolean (value, nm_setting_ip4_config_get_dhcp_send_hostname (setting));
		break;
1115
	case PROP_DHCP_HOSTNAME:
1116
		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
1117
		break;
1118 1119 1120
	case PROP_NEVER_DEFAULT:
		g_value_set_boolean (value, priv->never_default);
		break;
1121 1122 1123
	case PROP_MAY_FAIL:
		g_value_set_boolean (value, priv->may_fail);
		break;
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);

1136 1137
	g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));

1138 1139 1140 1141 1142 1143 1144
	/* virtual methods */
	object_class->set_property = set_property;
	object_class->get_property = get_property;
	object_class->finalize     = finalize;
	parent_class->verify       = verify;

	/* Properties */
1145 1146 1147
	/**
	 * NMSettingIP4Config:method:
	 *
1148
	 * IPv4 configuration method.  If "auto" is specified then the appropriate
1149
	 * automatic method (DHCP, PPP, etc) is used for the interface and most
1150
	 * other properties can be left unset.  If "link-local" is specified, then a
1151
	 * link-local address in the 169.254/16 range will be assigned to the
1152 1153 1154
	 * interface.  If "manual" is specified, static IP addressing is used and at
	 * least one IP address must be given in the "addresses" property.  If
	 * "shared" is specified (indicating that this connection will provide
1155 1156 1157
	 * network access to other computers) then the interface is assigned an
	 * address in the 10.42.x.1/24 range and a DHCP and forwarding DNS server
	 * are started, and the interface is NAT-ed to the current default network
1158
	 * connection.  "disabled" means IPv4 will not be used on this connection.
1159
	 * This property must be set.
1160
	 **/
1161
	g_object_class_install_property
1162
		(object_class, PROP_METHOD,
1163 1164
		 g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD, "", "",
		                      NULL,
1165 1166
		                      G_PARAM_READWRITE |
		                      NM_SETTING_PARAM_INFERRABLE |
1167
		                      G_PARAM_STATIC_STRINGS));
1168

1169 1170 1171
	/**
	 * NMSettingIP4Config:dns:
	 *
1172
	 * List of DNS servers (network byte order).  For the "auto" method, these
1173
	 * DNS servers are appended to those (if any) returned by automatic
1174 1175 1176 1177
	 * configuration.  DNS servers cannot be used with the "shared",
	 * "link-local", or "disabled" methods as there is no upstream network.  In
	 * all other methods, these DNS servers are used as the only DNS servers for
	 * this connection.
1178
	 **/
1179 1180
	g_object_class_install_property
		(object_class, PROP_DNS,
1181 1182 1183 1184
		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS, "", "",
		                             DBUS_TYPE_G_UINT_ARRAY,
		                             G_PARAM_READWRITE |
		                             G_PARAM_STATIC_STRINGS));
1185

1186 1187 1188
	/**
	 * NMSettingIP4Config:dns-search:
	 *
1189
	 * List of DNS search domains.  For the "auto" method, these search domains
1190
	 * are appended to those returned by automatic configuration. Search domains
1191
	 * cannot be used with the "shared", "link-local", or "disabled" methods as
1192 1193
	 * there is no upstream network.  In all other methods, these search domains
	 * are used as the only search domains for this connection.
1194
	 **/
1195 1196
	g_object_class_install_property
		(object_class, PROP_DNS_SEARCH,
1197 1198 1199 1200
		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS_SEARCH, "", "",
		                             DBUS_TYPE_G_LIST_OF_STRING,
		                             G_PARAM_READWRITE |
		                             G_PARAM_STATIC_STRINGS));
1201

1202 1203 1204 1205 1206 1207 1208
	/**
	 * NMSettingIP4Config:addresses:
	 *
	 * Array of IPv4 address structures.  Each IPv4 address structure is
	 * composed of 3 32-bit values; the first being the IPv4 address (network
	 * byte order), the second the prefix (1 - 32), and last the IPv4 gateway
	 * (network byte order). The gateway may be left as 0 if no gateway exists
1209
	 * for that subnet.  For the "auto" method, given IP addresses are appended
1210
	 * to those returned by automatic configuration.  Addresses cannot be used
1211
	 * with the "shared", "link-local", or "disabled" methods as addressing is
1212
	 * either automatic or disabled with these methods.
1213
	 **/
1214 1215
	g_object_class_install_property
		(object_class, PROP_ADDRESSES,
1216 1217
		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ADDRESSES, "", "",
		                             DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
1218 1219
		                             G_PARAM_READWRITE |
		                             NM_SETTING_PARAM_INFERRABLE |
1220
		                             G_PARAM_STATIC_STRINGS));
1221

1222 1223 1224
	/**
	 * NMSettingIP4Config:routes:
	 *
1225 1226 1227 1228 1229 1230 1231 1232
	 * Array of IPv4 route structures.  Each IPv4 route structure is composed of
	 * 4 32-bit values; the first being the destination IPv4 network or address
	 * (network byte order), the second the destination network or address
	 * prefix (1 - 32), the third being the next-hop (network byte order) if
	 * any, and the fourth being the route metric. For the "auto" method, given
	 * IP routes are appended to those returned by automatic configuration.
	 * Routes cannot be used with the "shared", "link-local", or "disabled"
	 * methods because there is no upstream network.
1233
	 **/
1234 1235
	g_object_class_install_property
		(object_class, PROP_ROUTES,
1236 1237
		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ROUTES, "", "",
		                             DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
1238 1239
		                             G_PARAM_READWRITE |
		                             NM_SETTING_PARAM_INFERRABLE |
1240
		                             G_PARAM_STATIC_STRINGS));
1241

1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
	/**
	 * NMSettingIP4Config:route-metric:
	 *
	 * The default metric for routes that don't explicitly specify a metric.
	 * The default value -1 means that the metric is choosen automatically
	 * based on the device type.
	 * The metric applies to dynamic routes, manual (static) routes that
	 * don't have an explicit metric setting, address prefix routes, and
	 * the default route.
	 * As the linux kernel accepts zero (0) as a valid metric, zero is
	 * a valid value.
	 *
	 * Since: 1.0
	 **/
	g_object_class_install_property
	    (object_class, PROP_ROUTE_METRIC,
	     g_param_spec_int64 (NM_SETTING_IP4_CONFIG_ROUTE_METRIC, "", "",
	                         -1, G_MAXUINT32, -1,
	                         G_PARAM_READWRITE |
	                         G_PARAM_CONSTRUCT |
	                         G_PARAM_STATIC_STRINGS));

1264 1265 1266
	/**
	 * NMSettingIP4Config:ignore-auto-routes:
	 *
1267 1268 1269
	 * When the method is set to "auto" and this property to %TRUE,
	 * automatically configured routes are ignored and only routes specified in
	 * the #NMSettingIP4Config:routes property, if any, are used.
1270
	 **/
1271
	g_object_class_install_property
1272
		(object_class, PROP_IGNORE_AUTO_ROUTES,
1273 1274
		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, "", "",
		                       FALSE,
1275 1276
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT |
1277
		                       G_PARAM_STATIC_STRINGS));
1278

1279 1280 1281
	/**
	 * NMSettingIP4Config:ignore-auto-dns:
	 *
1282 1283 1284 1285 1286
	 * When the method is set to "auto" and this property to %TRUE,
	 * automatically configured nameservers and search domains are ignored and
	 * only nameservers and search domains specified in the
	 * #NMSettingIP4Config:dns and #NMSettingIP4Config:dns-search properties, if
	 * any, are used.
1287
	 **/
1288 1289
	g_object_class_install_property
		(object_class, PROP_IGNORE_AUTO_DNS,
1290 1291
		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, "", "",
		                       FALSE,
1292 1293
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT |
1294
		                       G_PARAM_STATIC_STRINGS));
1295

1296 1297 1298 1299
	/**
	 * NMSettingIP4Config:dhcp-client-id:
	 *
	 * A string sent to the DHCP server to identify the local machine which the
1300
	 * DHCP server may use to customize the DHCP lease and options.
1301
	 **/
1302 1303
	g_object_class_install_property
		(object_class, PROP_DHCP_CLIENT_ID,
1304 1305 1306 1307
		 g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS));
1308

1309 1310 1311
	/**
	 * NMSettingIP4Config:dhcp-send-hostname:
	 *
1312
	 * If %TRUE, a hostname is sent to the DHCP server when acquiring a lease.
1313
	 * Some DHCP servers use this hostname to update DNS databases, essentially
1314 1315 1316
	 * providing a static hostname for the computer.  If the
	 * #NMSettingIP4Config:dhcp-hostname property is empty and this property is
	 * %TRUE, the current persistent hostname of the computer is sent.
1317
	 **/
1318 1319
	g_object_class_install_property
		(object_class, PROP_DHCP_SEND_HOSTNAME,
1320 1321
		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, "", "",
		                       TRUE,
1322 1323
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT |
1324
		                       G_PARAM_STATIC_STRINGS));
1325

1326 1327 1328
	/**
	 * NMSettingIP4Config:dhcp-hostname:
	 *
1329
	 * If the #NMSettingIP4Config:dhcp-send-hostname property is %TRUE, then the
1330 1331
	 * specified name will be sent to the DHCP server when acquiring a lease.
	 **/
1332 1333
	g_object_class_install_property
		(object_class, PROP_DHCP_HOSTNAME,
1334 1335
		 g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "", "",
		                      NULL,
1336 1337
		                      G_PARAM_READWRITE |
		                      NM_SETTING_PARAM_INFERRABLE |
1338
		                      G_PARAM_STATIC_STRINGS));
1339

1340 1341 1342
	/**
	 * NMSettingIP4Config:never-default:
	 *
1343
	 * If %TRUE, this connection will never be the default IPv4 connection,
1344 1345
	 * meaning it will never be assigned the default route by NetworkManager.
	 **/
1346 1347
	g_object_class_install_property
		(object_class, PROP_NEVER_DEFAULT,
1348 1349
		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, "", "",
		                       FALSE,
1350 1351
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT |
1352
		                       G_PARAM_STATIC_STRINGS));
1353 1354 1355 1356

	/**
	 * NMSettingIP4Config:may-fail:
	 *
1357
	 * If %TRUE, allow overall network configuration to proceed even if IPv4
1358 1359 1360 1361 1362
	 * configuration times out.  Note that at least one IP configuration must
	 * succeed or overall network configuration will still fail.  For example,
	 * in IPv6-only networks, setting this property to %TRUE allows the overall
	 * network configuration to succeed if IPv4 configuration fails but IPv6
	 * configuration completes successfully.
1363 1364 1365
	 **/
	g_object_class_install_property
		(object_class, PROP_MAY_FAIL,
1366 1367
		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MAY_FAIL, "", "",
		                       TRUE,
1368 1369
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT |
1370
		                       G_PARAM_STATIC_STRINGS));
1371
}
1372

1373