2008-07-03 16:22:17 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2008-07-27 20:03:46 +00:00
|
|
|
/*
|
|
|
|
* Dan Williams <dcbw@redhat.com>
|
|
|
|
* Tambet Ingo <tambet@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2010-04-15 21:51:47 +00:00
|
|
|
* (C) Copyright 2007 - 2010 Red Hat, Inc.
|
2008-07-27 20:03:46 +00:00
|
|
|
* (C) Copyright 2007 - 2008 Novell, Inc.
|
|
|
|
*/
|
|
|
|
|
2008-03-13 03:11:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
#include "nm-setting-ip4-config.h"
|
|
|
|
#include "nm-param-spec-specialized.h"
|
|
|
|
#include "nm-utils.h"
|
2008-03-29 21:35:41 +00:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2008-06-12 23:58:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This should really be standard. */
|
|
|
|
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
|
|
|
|
|
|
|
|
GType
|
|
|
|
nm_setting_ip4_config_error_get_type (void)
|
|
|
|
{
|
|
|
|
static GType etype = 0;
|
|
|
|
|
|
|
|
if (etype == 0) {
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
/* Unknown error. */
|
|
|
|
ENUM_ENTRY (NM_SETTING_IP4_CONFIG_ERROR_UNKNOWN, "UnknownError"),
|
|
|
|
/* The specified property was invalid. */
|
|
|
|
ENUM_ENTRY (NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY, "InvalidProperty"),
|
|
|
|
/* The specified property was missing and is required. */
|
|
|
|
ENUM_ENTRY (NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY, "MissingProperty"),
|
|
|
|
/* The specified property was not allowed in combination with the current 'method' */
|
|
|
|
ENUM_ENTRY (NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD, "NotAllowedForMethod"),
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
etype = g_enum_register_static ("NMSettingIP4ConfigError", values);
|
|
|
|
}
|
|
|
|
return etype;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
#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 */
|
|
|
|
gboolean ignore_auto_routes;
|
|
|
|
gboolean ignore_auto_dns;
|
|
|
|
char *dhcp_client_id;
|
2009-03-16 12:31:28 +00:00
|
|
|
gboolean dhcp_send_hostname;
|
2008-10-29 14:35:25 +00:00
|
|
|
char *dhcp_hostname;
|
2008-12-09 20:01:49 +00:00
|
|
|
gboolean never_default;
|
2010-05-02 23:51:26 +00:00
|
|
|
gboolean may_fail;
|
2008-10-29 14:35:25 +00:00
|
|
|
} NMSettingIP4ConfigPrivate;
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2008-03-13 03:11:02 +00:00
|
|
|
PROP_METHOD,
|
2007-11-07 16:06:43 +00:00
|
|
|
PROP_DNS,
|
|
|
|
PROP_DNS_SEARCH,
|
|
|
|
PROP_ADDRESSES,
|
2008-06-02 08:44:48 +00:00
|
|
|
PROP_ROUTES,
|
2008-08-06 22:23:48 +00:00
|
|
|
PROP_IGNORE_AUTO_ROUTES,
|
|
|
|
PROP_IGNORE_AUTO_DNS,
|
2008-07-03 16:22:17 +00:00
|
|
|
PROP_DHCP_CLIENT_ID,
|
2009-03-16 12:31:28 +00:00
|
|
|
PROP_DHCP_SEND_HOSTNAME,
|
2008-07-03 16:22:17 +00:00
|
|
|
PROP_DHCP_HOSTNAME,
|
2008-12-09 20:01:49 +00:00
|
|
|
PROP_NEVER_DEFAULT,
|
2010-05-02 23:51:26 +00:00
|
|
|
PROP_MAY_FAIL,
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
NMSetting *
|
|
|
|
nm_setting_ip4_config_new (void)
|
|
|
|
{
|
|
|
|
return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting)
|
|
|
|
{
|
|
|
|
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
|
|
|
|
|
|
|
|
nm_utils_slist_free (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
|
|
|
|
NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (copy != NULL, FALSE);
|
|
|
|
|
|
|
|
priv->addresses = g_slist_append (priv->addresses, copy);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_setting_ip4_config_remove_address (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->addresses, i);
|
|
|
|
g_return_if_fail (elt != NULL);
|
|
|
|
|
|
|
|
nm_ip4_address_unref ((NMIP4Address *) elt->data);
|
|
|
|
priv->addresses = g_slist_delete_link (priv->addresses, elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
|
|
|
priv->addresses = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (copy != NULL, FALSE);
|
|
|
|
|
|
|
|
priv->routes = g_slist_append (priv->routes, copy);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
|
|
|
priv->routes = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
|
|
|
|
|
|
|
|
return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
|
|
|
|
}
|
|
|
|
|
2009-03-16 12:31:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
const char *
|
|
|
|
nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
|
|
|
|
|
|
|
|
return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
|
|
|
|
}
|
|
|
|
|
2008-12-09 20:01:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:51:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
static gboolean
|
2008-06-12 23:58:08 +00:00
|
|
|
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
2007-11-07 16:06:43 +00:00
|
|
|
{
|
2008-10-29 14:35:25 +00:00
|
|
|
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
|
2008-07-07 18:57:37 +00:00
|
|
|
GSList *iter;
|
|
|
|
int i;
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!priv->method) {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD);
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
2008-06-12 23:58:08 +00:00
|
|
|
}
|
2008-03-13 03:11:02 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
|
|
|
|
if (!priv->addresses) {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
2007-11-07 16:06:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-29 14:35:25 +00:00
|
|
|
} else if ( !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
|
2010-04-15 21:51:47 +00:00
|
|
|
|| !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
|
|
|
|
|| !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
|
2008-10-29 14:35:25 +00:00
|
|
|
if (priv->dns && priv->dns->len) {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
|
|
|
|
NM_SETTING_IP4_CONFIG_DNS);
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (g_slist_length (priv->dns_search)) {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
|
|
|
|
NM_SETTING_IP4_CONFIG_DNS_SEARCH);
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (g_slist_length (priv->addresses)) {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
|
|
|
|
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-29 14:35:25 +00:00
|
|
|
} else if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
|
2008-03-13 03:11:02 +00:00
|
|
|
/* nothing to do */
|
|
|
|
} else {
|
2008-06-12 23:58:08 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD);
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
2007-11-07 16:06:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID);
|
2008-07-03 16:22:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
|
2008-07-03 16:22:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-07 18:57:37 +00:00
|
|
|
/* Validate addresses */
|
2008-10-29 14:35:25 +00:00
|
|
|
for (iter = priv->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
|
|
|
|
NMIP4Address *addr = (NMIP4Address *) iter->data;
|
|
|
|
guint32 prefix = nm_ip4_address_get_prefix (addr);
|
2008-07-07 18:57:37 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!nm_ip4_address_get_address (addr)) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!prefix || prefix > 32) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate routes */
|
2008-10-29 14:35:25 +00:00
|
|
|
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);
|
2008-07-27 21:24:55 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!nm_ip4_route_get_dest (route)) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_ROUTES);
|
2008-07-07 18:57:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (!prefix || prefix > 32) {
|
2008-07-27 21:24:55 +00:00
|
|
|
g_set_error (error,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR,
|
|
|
|
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
|
|
|
|
NM_SETTING_IP4_CONFIG_ROUTES);
|
2008-07-07 18:57:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
nm_setting_ip4_config_init (NMSettingIP4Config *setting)
|
|
|
|
{
|
2008-10-29 14:35:25 +00:00
|
|
|
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
|
|
|
|
|
2008-10-27 17:36:18 +00:00
|
|
|
g_object_set (setting, NM_SETTING_NAME, NM_SETTING_IP4_CONFIG_SETTING_NAME, NULL);
|
2008-10-29 14:35:25 +00:00
|
|
|
|
|
|
|
priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
|
2007-11-07 16:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
|
2008-10-29 14:35:25 +00:00
|
|
|
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (self);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
g_free (priv->method);
|
2008-03-13 03:11:02 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
g_array_free (priv->dns, TRUE);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_slist_free (priv->dns_search, g_free);
|
|
|
|
nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
|
|
|
nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
|
2008-10-29 14:35:25 +00:00
|
|
|
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2008-03-13 03:11:02 +00:00
|
|
|
case PROP_METHOD:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_free (priv->method);
|
|
|
|
priv->method = g_value_dup_string (value);
|
2008-03-12 12:45:20 +00:00
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
case PROP_DNS:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_array_free (priv->dns, TRUE);
|
|
|
|
priv->dns = g_value_dup_boxed (value);
|
|
|
|
if (!priv->dns)
|
|
|
|
priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
|
|
|
case PROP_DNS_SEARCH:
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_slist_free (priv->dns_search, g_free);
|
|
|
|
priv->dns_search = g_value_dup_boxed (value);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
|
|
|
case PROP_ADDRESSES:
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
|
|
|
priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
|
2008-07-27 21:24:55 +00:00
|
|
|
break;
|
2008-06-02 08:44:48 +00:00
|
|
|
case PROP_ROUTES:
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
|
|
|
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
2008-08-06 22:23:48 +00:00
|
|
|
case PROP_IGNORE_AUTO_ROUTES:
|
2008-10-29 14:35:25 +00:00
|
|
|
priv->ignore_auto_routes = g_value_get_boolean (value);
|
2008-08-06 22:23:48 +00:00
|
|
|
break;
|
|
|
|
case PROP_IGNORE_AUTO_DNS:
|
2008-10-29 14:35:25 +00:00
|
|
|
priv->ignore_auto_dns = g_value_get_boolean (value);
|
2008-05-23 07:35:43 +00:00
|
|
|
break;
|
2008-07-03 16:22:17 +00:00
|
|
|
case PROP_DHCP_CLIENT_ID:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_free (priv->dhcp_client_id);
|
|
|
|
priv->dhcp_client_id = g_value_dup_string (value);
|
2008-07-03 16:22:17 +00:00
|
|
|
break;
|
2009-03-16 12:31:28 +00:00
|
|
|
case PROP_DHCP_SEND_HOSTNAME:
|
|
|
|
priv->dhcp_send_hostname = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-07-03 16:22:17 +00:00
|
|
|
case PROP_DHCP_HOSTNAME:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_free (priv->dhcp_hostname);
|
|
|
|
priv->dhcp_hostname = g_value_dup_string (value);
|
2009-03-16 12:31:28 +00:00
|
|
|
/* FIXME: Is this a good idea? */
|
|
|
|
if (priv->dhcp_hostname)
|
|
|
|
priv->dhcp_send_hostname = TRUE;
|
2008-07-03 16:22:17 +00:00
|
|
|
break;
|
2008-12-09 20:01:49 +00:00
|
|
|
case PROP_NEVER_DEFAULT:
|
|
|
|
priv->never_default = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-05-02 23:51:26 +00:00
|
|
|
case PROP_MAY_FAIL:
|
|
|
|
priv->may_fail = g_value_get_boolean (value);
|
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
|
2008-10-29 14:35:25 +00:00
|
|
|
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2008-03-13 03:11:02 +00:00
|
|
|
case PROP_METHOD:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
|
2008-03-12 12:45:20 +00:00
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
case PROP_DNS:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_boxed (value, priv->dns);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
|
|
|
case PROP_DNS_SEARCH:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_boxed (value, priv->dns_search);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
|
|
|
case PROP_ADDRESSES:
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
2008-06-02 08:44:48 +00:00
|
|
|
case PROP_ROUTES:
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_utils_ip4_routes_to_gvalue (priv->routes, value);
|
2008-08-06 22:23:48 +00:00
|
|
|
break;
|
|
|
|
case PROP_IGNORE_AUTO_ROUTES:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
|
2008-06-02 08:44:48 +00:00
|
|
|
break;
|
2008-08-06 22:23:48 +00:00
|
|
|
case PROP_IGNORE_AUTO_DNS:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
|
2008-05-23 07:35:43 +00:00
|
|
|
break;
|
2008-07-03 16:22:17 +00:00
|
|
|
case PROP_DHCP_CLIENT_ID:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
|
2008-07-03 16:22:17 +00:00
|
|
|
break;
|
2009-03-16 12:31:28 +00:00
|
|
|
case PROP_DHCP_SEND_HOSTNAME:
|
|
|
|
g_value_set_boolean (value, nm_setting_ip4_config_get_dhcp_send_hostname (setting));
|
|
|
|
break;
|
2008-07-03 16:22:17 +00:00
|
|
|
case PROP_DHCP_HOSTNAME:
|
2008-10-29 14:35:25 +00:00
|
|
|
g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
|
2008-07-03 16:22:17 +00:00
|
|
|
break;
|
2008-12-09 20:01:49 +00:00
|
|
|
case PROP_NEVER_DEFAULT:
|
|
|
|
g_value_set_boolean (value, priv->never_default);
|
|
|
|
break;
|
2010-05-02 23:51:26 +00:00
|
|
|
case PROP_MAY_FAIL:
|
|
|
|
g_value_set_boolean (value, priv->may_fail);
|
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
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);
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
/* virtual methods */
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->finalize = finalize;
|
|
|
|
parent_class->verify = verify;
|
|
|
|
|
|
|
|
/* Properties */
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:method:
|
|
|
|
*
|
|
|
|
* IPv4 configuration method. If 'auto' is specified then the appropriate
|
2009-11-16 21:37:35 +00:00
|
|
|
* automatic method (DHCP, PPP, etc) is used for the interface and most
|
|
|
|
* other properties can be left unset. If 'link-local' is specified, then a
|
2009-11-16 20:33:27 +00:00
|
|
|
* link-local address in the 169.254/16 range will be assigned to the
|
|
|
|
* 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
|
|
|
|
* 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
|
2010-04-15 21:51:47 +00:00
|
|
|
* connection. 'disabled' means IPv4 will not be used on this connection.
|
|
|
|
* This property must be set.
|
2009-11-16 20:33:27 +00:00
|
|
|
**/
|
2007-11-07 16:06:43 +00:00
|
|
|
g_object_class_install_property
|
2008-03-13 03:11:02 +00:00
|
|
|
(object_class, PROP_METHOD,
|
|
|
|
g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD,
|
|
|
|
"Method",
|
2009-11-16 20:33:27 +00:00
|
|
|
"IPv4 configuration method. If 'auto' is specified "
|
|
|
|
"then the appropriate automatic method (DHCP, PPP, "
|
2009-11-16 21:37:35 +00:00
|
|
|
"etc) is used for the interface and most other "
|
2009-11-16 20:33:27 +00:00
|
|
|
"properties can be left unset. If 'link-local' "
|
|
|
|
"is specified, then a link-local address in the "
|
|
|
|
"169.254/16 range will be assigned to the "
|
|
|
|
"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 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 "
|
2010-04-15 21:51:47 +00:00
|
|
|
"connection. 'disabled' means IPv4 will not be "
|
|
|
|
"used on this connection. This property must be set.",
|
2008-03-13 03:11:02 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2008-03-12 12:45:20 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:dns:
|
|
|
|
*
|
2009-11-16 21:37:35 +00:00
|
|
|
* List of DNS servers (network byte order). For the 'auto' method, these
|
2009-11-16 20:33:27 +00:00
|
|
|
* DNS servers are appended to those (if any) returned by automatic
|
2010-04-15 21:51:47 +00:00
|
|
|
* configuration. DNS servers cannot be used with the 'shared', 'link-local',
|
|
|
|
* or 'disabled' methods as there is no usptream network. In all other
|
2009-11-16 20:33:27 +00:00
|
|
|
* methods, these DNS servers are used as the only DNS servers for this
|
|
|
|
* connection.
|
|
|
|
**/
|
2007-11-07 16:06:43 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DNS,
|
2008-08-26 09:34:31 +00:00
|
|
|
_nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS,
|
2007-11-07 16:06:43 +00:00
|
|
|
"DNS",
|
2009-11-16 21:37:35 +00:00
|
|
|
"List of DNS servers (network byte order). For "
|
2009-11-16 20:33:27 +00:00
|
|
|
"the 'auto' method, these DNS servers are "
|
|
|
|
"appended to those (if any) returned by automatic "
|
|
|
|
"configuration. DNS servers cannot be used with "
|
2010-04-15 21:51:47 +00:00
|
|
|
"the 'shared', 'link-local', or 'disabled' "
|
|
|
|
"methods as there is no usptream network. In all "
|
|
|
|
"other methods, these DNS servers are used as the "
|
|
|
|
"only DNS servers for this connection.",
|
2007-11-07 16:06:43 +00:00
|
|
|
DBUS_TYPE_G_UINT_ARRAY,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:dns-search:
|
|
|
|
*
|
2009-11-16 21:37:35 +00:00
|
|
|
* List of DNS search domains. For the 'auto' method, these search domains
|
|
|
|
* are appended to those returned by automatic configuration. Search domains
|
2010-04-15 21:51:47 +00:00
|
|
|
* cannot be used with the 'shared', 'link-local', or 'disabled' methods as
|
|
|
|
* there is no upstream network. In all other methods, these search domains
|
|
|
|
* are used as the only search domains for this connection.
|
2009-11-16 20:33:27 +00:00
|
|
|
**/
|
2007-11-07 16:06:43 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DNS_SEARCH,
|
2008-08-26 09:34:31 +00:00
|
|
|
_nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS_SEARCH,
|
2007-11-07 16:06:43 +00:00
|
|
|
"DNS search",
|
2009-11-16 21:37:35 +00:00
|
|
|
"List of DNS search domains. For the 'auto' "
|
|
|
|
"method, these search domains are appended to "
|
|
|
|
"those returned by automatic configuration. "
|
2010-04-15 21:51:47 +00:00
|
|
|
"Search domains cannot be used with the 'shared', "
|
|
|
|
"'link-local', or 'disabled' methods as there is "
|
|
|
|
"no upstream network. In all other methods, these "
|
|
|
|
"search domains are used as the only search domains "
|
|
|
|
"for this connection.",
|
2008-03-29 21:35:41 +00:00
|
|
|
DBUS_TYPE_G_LIST_OF_STRING,
|
2007-11-07 16:06:43 +00:00
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* for that subnet. For the 'auto' method, given IP addresses are appended
|
|
|
|
* to those returned by automatic configuration. Addresses cannot be used
|
2010-04-15 21:51:47 +00:00
|
|
|
* with the 'shared', 'link-local', or 'disabled' methods as addressing is
|
|
|
|
* either automatic or disabled with these methods.
|
2009-11-16 20:33:27 +00:00
|
|
|
**/
|
2007-11-07 16:06:43 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_ADDRESSES,
|
2008-08-26 09:34:31 +00:00
|
|
|
_nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ADDRESSES,
|
2007-11-07 16:06:43 +00:00
|
|
|
"Addresses",
|
2009-11-16 20:33:27 +00:00
|
|
|
"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 "
|
|
|
|
"for that subnet. For the 'auto' method, given "
|
|
|
|
"IP addresses are appended to those returned by "
|
|
|
|
"automatic configuration. Addresses cannot be "
|
2010-04-15 21:51:47 +00:00
|
|
|
"used with the 'shared', 'link-local', or "
|
|
|
|
"'disabled' methods as addressing is either "
|
|
|
|
"automatic or disabled with these methods.",
|
2008-03-29 21:35:41 +00:00
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
2007-11-07 16:06:43 +00:00
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2008-05-23 07:35:43 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:routes:
|
|
|
|
*
|
|
|
|
* 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
|
2010-04-15 21:51:47 +00:00
|
|
|
* configuration. Routes cannot be used with the 'shared', 'link-local',
|
|
|
|
* or 'disabled' methods because there is no upstream network.
|
2009-11-16 20:33:27 +00:00
|
|
|
**/
|
2008-06-02 08:44:48 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_ROUTES,
|
2008-08-26 09:34:31 +00:00
|
|
|
_nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ROUTES,
|
2008-06-02 08:44:48 +00:00
|
|
|
"Routes",
|
2009-11-16 20:33:27 +00:00
|
|
|
"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 "
|
2010-04-15 21:51:47 +00:00
|
|
|
"'shared', 'link-local', or 'disabled', methods "
|
|
|
|
"as there is no upstream network.",
|
2008-06-02 08:44:48 +00:00
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:ignore-auto-routes:
|
|
|
|
*
|
|
|
|
* When the method is set to 'auto' and this property to TRUE, automatically
|
|
|
|
* configured routes are ignored and only routes specified in
|
|
|
|
* #NMSettingIP4Config:routes, if any, are used.
|
|
|
|
**/
|
2008-05-23 07:35:43 +00:00
|
|
|
g_object_class_install_property
|
2008-08-06 22:23:48 +00:00
|
|
|
(object_class, PROP_IGNORE_AUTO_ROUTES,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES,
|
|
|
|
"Ignore automatic routes",
|
2009-11-16 20:33:27 +00:00
|
|
|
"When the method is set to 'auto' and this property "
|
|
|
|
"to TRUE, automatically configured routes are "
|
|
|
|
"ignored and only routes specified in the 'routes' "
|
|
|
|
"property, if any, are used.",
|
2008-08-06 22:23:48 +00:00
|
|
|
FALSE,
|
2009-02-02 01:18:21 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:ignore-auto-dns:
|
|
|
|
*
|
|
|
|
* When the method is set to 'auto' and this property to TRUE, automatically
|
2010-03-29 08:26:57 +00:00
|
|
|
* configured nameservers and search domains are ignored and only nameservers
|
2009-11-16 20:33:27 +00:00
|
|
|
* and search domains specified in #NMSettingIP4Config:dns and
|
|
|
|
* #NMSettingIP4Config:dns-search, if any, are used.
|
|
|
|
**/
|
2008-08-06 22:23:48 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_IGNORE_AUTO_DNS,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS,
|
|
|
|
"Ignore automatic DNS",
|
2009-11-16 20:33:27 +00:00
|
|
|
"When the method is set to 'auto' and this property "
|
|
|
|
"to TRUE, automatically configured nameservers and "
|
2010-03-29 08:26:57 +00:00
|
|
|
"search domains are ignored and only nameservers and "
|
2009-11-16 20:33:27 +00:00
|
|
|
"search domains specified in the 'dns' and 'dns-search' "
|
|
|
|
"properties, if any, are used.",
|
2008-05-23 07:35:43 +00:00
|
|
|
FALSE,
|
2009-02-02 01:18:21 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
|
2008-07-03 16:22:17 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:dhcp-client-id:
|
|
|
|
*
|
|
|
|
* A string sent to the DHCP server to identify the local machine which the
|
|
|
|
* DHCP server may use to cusomize the DHCP lease and options.
|
|
|
|
**/
|
2008-07-03 16:22:17 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DHCP_CLIENT_ID,
|
|
|
|
g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID,
|
|
|
|
"DHCP Client ID",
|
2009-11-16 20:33:27 +00:00
|
|
|
"A string sent to the DHCP server to identify the "
|
|
|
|
"local machine which the DHCP server may use to "
|
|
|
|
"cusomize the DHCP lease and options.",
|
2008-07-03 16:22:17 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2009-03-16 12:31:28 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:dhcp-send-hostname:
|
|
|
|
*
|
|
|
|
* If TRUE, a hostname is sent to the DHCP server when acquiring a lease.
|
|
|
|
* Some DHCP servers use this hostname to update DNS databases, essentially
|
|
|
|
* providing a static hostname for the computer. If
|
|
|
|
* #NMSettingIP4Config:dhcp-hostname is empty and this property is TRUE,
|
|
|
|
* the current persistent hostname of the computer is sent.
|
|
|
|
**/
|
2009-03-16 12:31:28 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DHCP_SEND_HOSTNAME,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME,
|
|
|
|
"Send DHCP hostname",
|
2009-11-16 20:33:27 +00:00
|
|
|
"If TRUE, a hostname is sent to the DHCP server when "
|
|
|
|
"acquiring a lease. Some DHCP servers use this "
|
|
|
|
"hostname to update DNS databases, essentially "
|
|
|
|
"providing a static hostname for the computer. If "
|
|
|
|
"the 'dhcp-hostname' property is empty and this "
|
|
|
|
"property is TRUE, the current persistent hostname "
|
|
|
|
"of the computer is sent.",
|
2009-03-16 12:31:28 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
|
2008-07-03 16:22:17 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:dhcp-hostname:
|
|
|
|
*
|
|
|
|
* If the #NMSettingIP4Config:dhcp-send-hostname property is TRUE, then the
|
|
|
|
* specified name will be sent to the DHCP server when acquiring a lease.
|
|
|
|
**/
|
2008-07-03 16:22:17 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DHCP_HOSTNAME,
|
|
|
|
g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME,
|
|
|
|
"DHCP Hostname",
|
2009-11-16 20:33:27 +00:00
|
|
|
"If the 'dhcp-send-hostname' property is TRUE, then "
|
|
|
|
"the specified name will be sent to the DHCP server "
|
|
|
|
"when acquiring a lease.",
|
2008-07-03 16:22:17 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2008-12-09 20:01:49 +00:00
|
|
|
|
2009-11-16 20:33:27 +00:00
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:never-default:
|
|
|
|
*
|
|
|
|
* If TRUE, this connection will never be the default IPv4 connection,
|
|
|
|
* meaning it will never be assigned the default route by NetworkManager.
|
|
|
|
**/
|
2008-12-09 20:01:49 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_NEVER_DEFAULT,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT,
|
|
|
|
"Never default",
|
2009-11-16 20:33:27 +00:00
|
|
|
"If TRUE, this connection will never be the default "
|
|
|
|
"IPv4 connection, meaning it will never be assigned "
|
|
|
|
"the default route by NetworkManager.",
|
2008-12-09 20:01:49 +00:00
|
|
|
FALSE,
|
2009-02-02 01:18:21 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
|
2010-05-02 23:51:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NMSettingIP4Config:may-fail:
|
|
|
|
*
|
|
|
|
* If TRUE, allow overall network configuration to proceed even if IPv4
|
|
|
|
* configuration fails or 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.
|
|
|
|
**/
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_MAY_FAIL,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MAY_FAIL,
|
|
|
|
"May Fail",
|
|
|
|
"If TRUE, allow overall network configuration to "
|
|
|
|
"proceed even if IPv4 configuration fails or 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.",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
|
2007-11-07 16:06:43 +00:00
|
|
|
}
|
2008-07-03 16:22:17 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
|
|
|
|
struct NMIP4Address {
|
|
|
|
guint32 refcount;
|
|
|
|
guint32 address; /* network byte order */
|
|
|
|
guint32 prefix;
|
|
|
|
guint32 gateway; /* network byte order */
|
|
|
|
};
|
|
|
|
|
|
|
|
NMIP4Address *
|
|
|
|
nm_ip4_address_new (void)
|
|
|
|
{
|
|
|
|
NMIP4Address *address;
|
|
|
|
|
|
|
|
address = g_malloc0 (sizeof (NMIP4Address));
|
|
|
|
address->refcount = 1;
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
NMIP4Address *
|
|
|
|
nm_ip4_address_dup (NMIP4Address *source)
|
|
|
|
{
|
|
|
|
NMIP4Address *address;
|
|
|
|
|
|
|
|
g_return_val_if_fail (source != NULL, NULL);
|
|
|
|
g_return_val_if_fail (source->refcount > 0, NULL);
|
|
|
|
|
|
|
|
address = nm_ip4_address_new ();
|
|
|
|
address->address = source->address;
|
|
|
|
address->prefix = source->prefix;
|
|
|
|
address->gateway = source->gateway;
|
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_address_ref (NMIP4Address *address)
|
|
|
|
{
|
|
|
|
g_return_if_fail (address != NULL);
|
|
|
|
g_return_if_fail (address->refcount > 0);
|
|
|
|
|
|
|
|
address->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_address_unref (NMIP4Address *address)
|
|
|
|
{
|
|
|
|
g_return_if_fail (address != NULL);
|
|
|
|
g_return_if_fail (address->refcount > 0);
|
|
|
|
|
|
|
|
address->refcount--;
|
|
|
|
if (address->refcount == 0) {
|
|
|
|
memset (address, 0, sizeof (NMIP4Address));
|
|
|
|
g_free (address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (address != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (address->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
g_return_val_if_fail (other != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (other->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
if ( address->address != other->address
|
|
|
|
|| address->prefix != other->prefix
|
|
|
|
|| address->gateway != other->gateway)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_address_get_address (NMIP4Address *address)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (address != NULL, 0);
|
|
|
|
g_return_val_if_fail (address->refcount > 0, 0);
|
|
|
|
|
|
|
|
return address->address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_address_set_address (NMIP4Address *address, guint32 addr)
|
|
|
|
{
|
|
|
|
g_return_if_fail (address != NULL);
|
|
|
|
g_return_if_fail (address->refcount > 0);
|
|
|
|
|
|
|
|
address->address = addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_address_get_prefix (NMIP4Address *address)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (address != NULL, 0);
|
|
|
|
g_return_val_if_fail (address->refcount > 0, 0);
|
|
|
|
|
|
|
|
return address->prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_address_set_prefix (NMIP4Address *address, guint32 prefix)
|
|
|
|
{
|
|
|
|
g_return_if_fail (address != NULL);
|
|
|
|
g_return_if_fail (address->refcount > 0);
|
|
|
|
|
|
|
|
address->prefix = prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_address_get_gateway (NMIP4Address *address)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (address != NULL, 0);
|
|
|
|
g_return_val_if_fail (address->refcount > 0, 0);
|
|
|
|
|
|
|
|
return address->gateway;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_address_set_gateway (NMIP4Address *address, guint32 gateway)
|
|
|
|
{
|
|
|
|
g_return_if_fail (address != NULL);
|
|
|
|
g_return_if_fail (address->refcount > 0);
|
|
|
|
|
|
|
|
address->gateway = gateway;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct NMIP4Route {
|
|
|
|
guint32 refcount;
|
|
|
|
|
|
|
|
guint32 dest; /* network byte order */
|
|
|
|
guint32 prefix;
|
|
|
|
guint32 next_hop; /* network byte order */
|
|
|
|
guint32 metric; /* lower metric == more preferred */
|
|
|
|
};
|
|
|
|
|
|
|
|
NMIP4Route *
|
|
|
|
nm_ip4_route_new (void)
|
|
|
|
{
|
|
|
|
NMIP4Route *route;
|
|
|
|
|
|
|
|
route = g_malloc0 (sizeof (NMIP4Route));
|
|
|
|
route->refcount = 1;
|
|
|
|
return route;
|
|
|
|
}
|
|
|
|
|
|
|
|
NMIP4Route *
|
|
|
|
nm_ip4_route_dup (NMIP4Route *source)
|
|
|
|
{
|
|
|
|
NMIP4Route *route;
|
|
|
|
|
|
|
|
g_return_val_if_fail (source != NULL, NULL);
|
|
|
|
g_return_val_if_fail (source->refcount > 0, NULL);
|
|
|
|
|
|
|
|
route = nm_ip4_route_new ();
|
|
|
|
route->dest = source->dest;
|
|
|
|
route->prefix = source->prefix;
|
|
|
|
route->next_hop = source->next_hop;
|
|
|
|
route->metric = source->metric;
|
|
|
|
|
|
|
|
return route;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_ref (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_unref (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->refcount--;
|
|
|
|
if (route->refcount == 0) {
|
|
|
|
memset (route, 0, sizeof (NMIP4Route));
|
|
|
|
g_free (route);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (route != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (route->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
g_return_val_if_fail (other != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (other->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
if ( route->dest != other->dest
|
|
|
|
|| route->prefix != other->prefix
|
|
|
|
|| route->next_hop != other->next_hop
|
|
|
|
|| route->metric != other->metric)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_route_get_dest (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (route != NULL, 0);
|
|
|
|
g_return_val_if_fail (route->refcount > 0, 0);
|
|
|
|
|
|
|
|
return route->dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_set_dest (NMIP4Route *route, guint32 dest)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->dest = dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_route_get_prefix (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (route != NULL, 0);
|
|
|
|
g_return_val_if_fail (route->refcount > 0, 0);
|
|
|
|
|
|
|
|
return route->prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_set_prefix (NMIP4Route *route, guint32 prefix)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->prefix = prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_route_get_next_hop (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (route != NULL, 0);
|
|
|
|
g_return_val_if_fail (route->refcount > 0, 0);
|
|
|
|
|
|
|
|
return route->next_hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_set_next_hop (NMIP4Route *route, guint32 next_hop)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->next_hop = next_hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
nm_ip4_route_get_metric (NMIP4Route *route)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (route != NULL, 0);
|
|
|
|
g_return_val_if_fail (route->refcount > 0, 0);
|
|
|
|
|
|
|
|
return route->metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nm_ip4_route_set_metric (NMIP4Route *route, guint32 metric)
|
|
|
|
{
|
|
|
|
g_return_if_fail (route != NULL);
|
|
|
|
g_return_if_fail (route->refcount > 0);
|
|
|
|
|
|
|
|
route->metric = metric;
|
|
|
|
}
|
|
|
|
|