libnm-core, all: merge IPv4 and IPv6 address/route types
Merge NMIP4Address and NMIP6Address into NMIPAddress, and NMIP4Route and NMIP6Route into NMIPRoute. The new types represent IP addresses as strings, rather than in binary, and so are address-family agnostic.
This commit is contained in:
@@ -24,6 +24,7 @@ libnm_core_headers = \
|
||||
$(core)/nm-setting-generic.h \
|
||||
$(core)/nm-setting-gsm.h \
|
||||
$(core)/nm-setting-infiniband.h \
|
||||
$(core)/nm-setting-ip-config.h \
|
||||
$(core)/nm-setting-ip4-config.h \
|
||||
$(core)/nm-setting-ip6-config.h \
|
||||
$(core)/nm-setting-olpc-mesh.h \
|
||||
@@ -69,6 +70,7 @@ libnm_core_sources = \
|
||||
$(core)/nm-setting-generic.c \
|
||||
$(core)/nm-setting-gsm.c \
|
||||
$(core)/nm-setting-infiniband.c \
|
||||
$(core)/nm-setting-ip-config.c \
|
||||
$(core)/nm-setting-ip4-config.c \
|
||||
$(core)/nm-setting-ip6-config.c \
|
||||
$(core)/nm-setting-olpc-mesh.c \
|
||||
|
@@ -77,7 +77,7 @@
|
||||
const char *_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting,
|
||||
guint32 i);
|
||||
gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
|
||||
NMIP4Address *address,
|
||||
NMIPAddress *address,
|
||||
const char *label);
|
||||
|
||||
/* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
|
||||
|
874
libnm-core/nm-setting-ip-config.c
Normal file
874
libnm-core/nm-setting-ip-config.c
Normal file
@@ -0,0 +1,874 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Copyright 2007 - 2014 Red Hat, Inc.
|
||||
* Copyright 2007 - 2008 Novell, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "nm-setting-ip-config.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-setting-private.h"
|
||||
#include "nm-utils-private.h"
|
||||
|
||||
static char *
|
||||
canonicalize_ip (int family, const char *ip, gboolean null_any)
|
||||
{
|
||||
guint8 addr_bytes[sizeof (struct in6_addr)];
|
||||
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
||||
int ret;
|
||||
|
||||
if (!ip) {
|
||||
g_return_val_if_fail (null_any == TRUE, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = inet_pton (family, ip, addr_bytes);
|
||||
g_return_val_if_fail (ret == 1, NULL);
|
||||
|
||||
if (null_any) {
|
||||
int addrlen = (family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
|
||||
|
||||
if (!memcmp (addr_bytes, &in6addr_any, addrlen))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_strdup (inet_ntop (family, addr_bytes, addr_str, sizeof (addr_str)));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
valid_ip (int family, const char *ip, GError **error)
|
||||
{
|
||||
if (!nm_utils_ipaddr_valid (family, ip)) {
|
||||
g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
|
||||
family == AF_INET ? _("Invalid IPv4 address '%s'") : _("Invalid IPv6 address '%s"),
|
||||
ip);
|
||||
return FALSE;
|
||||
} else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
valid_prefix (int family, guint prefix, GError **error)
|
||||
{
|
||||
if ( (family == AF_INET && prefix > 32)
|
||||
|| (family == AF_INET6 && prefix > 128)
|
||||
|| prefix == 0) {
|
||||
g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
|
||||
family == AF_INET ? _("Invalid IPv4 address prefix '%u'") : _("Invalid IPv6 address prefix '%u"),
|
||||
prefix);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_BOXED_TYPE (NMIPAddress, nm_ip_address, nm_ip_address_dup, nm_ip_address_unref)
|
||||
|
||||
struct NMIPAddress {
|
||||
guint refcount;
|
||||
|
||||
char *address, *gateway;
|
||||
int prefix, family;
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip_address_new:
|
||||
* @family: the IP address family (%AF_INET or %AF_INET6)
|
||||
* @addr: the IP address
|
||||
* @prefix: the address prefix length
|
||||
* @gateway: (allow-none): the gateway
|
||||
* @error: location to store error, or %NULL
|
||||
*
|
||||
* Creates a new #NMIPAddress object.
|
||||
*
|
||||
* Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
|
||||
**/
|
||||
NMIPAddress *
|
||||
nm_ip_address_new (int family,
|
||||
const char *addr, guint prefix, const char *gateway,
|
||||
GError **error)
|
||||
{
|
||||
NMIPAddress *address;
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||
g_return_val_if_fail (addr != NULL, NULL);
|
||||
|
||||
if (!valid_ip (family, addr, error))
|
||||
return NULL;
|
||||
if (!valid_prefix (family, prefix, error))
|
||||
return NULL;
|
||||
if (gateway && !valid_ip (family, gateway, error))
|
||||
return NULL;
|
||||
|
||||
address = g_slice_new0 (NMIPAddress);
|
||||
address->refcount = 1;
|
||||
|
||||
address->family = family;
|
||||
address->address = canonicalize_ip (family, addr, FALSE);
|
||||
address->prefix = prefix;
|
||||
address->gateway = canonicalize_ip (family, gateway, TRUE);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_new_binary:
|
||||
* @family: the IP address family (%AF_INET or %AF_INET6)
|
||||
* @addr: the IP address
|
||||
* @prefix: the address prefix length
|
||||
* @gateway: (allow-none): the gateway
|
||||
* @error: location to store error, or %NULL
|
||||
*
|
||||
* Creates a new #NMIPAddress object. @addr and @gateway (if non-%NULL) must
|
||||
* point to buffers of the correct size for @family.
|
||||
*
|
||||
* Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
|
||||
**/
|
||||
NMIPAddress *
|
||||
nm_ip_address_new_binary (int family,
|
||||
gconstpointer addr, guint prefix, gconstpointer gateway,
|
||||
GError **error)
|
||||
{
|
||||
NMIPAddress *address;
|
||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||
g_return_val_if_fail (addr != NULL, NULL);
|
||||
|
||||
if (!valid_prefix (family, prefix, error))
|
||||
return NULL;
|
||||
|
||||
address = g_slice_new0 (NMIPAddress);
|
||||
address->refcount = 1;
|
||||
|
||||
address->family = family;
|
||||
address->address = g_strdup (inet_ntop (family, addr, string, sizeof (string)));
|
||||
address->prefix = prefix;
|
||||
if (gateway)
|
||||
address->gateway = g_strdup (inet_ntop (family, gateway, string, sizeof (string)));
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_ref:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_ref (NMIPAddress *address)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
|
||||
address->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_unref:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_unref (NMIPAddress *address)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
|
||||
address->refcount--;
|
||||
if (address->refcount == 0) {
|
||||
g_free (address->address);
|
||||
g_free (address->gateway);
|
||||
g_slice_free (NMIPAddress, address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_equal:
|
||||
* @address: the #NMIPAddress
|
||||
* @other: the #NMIPAddress to compare @address to.
|
||||
*
|
||||
* Determines if two #NMIPAddress objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
gboolean
|
||||
nm_ip_address_equal (NMIPAddress *address, NMIPAddress *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->family != other->family
|
||||
|| address->prefix != other->prefix
|
||||
|| strcmp (address->address, other->address) != 0
|
||||
|| g_strcmp0 (address->gateway, other->gateway) != 0)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_dup:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Creates a copy of @address
|
||||
*
|
||||
* Returns: (transfer full): a copy of @address
|
||||
**/
|
||||
NMIPAddress *
|
||||
nm_ip_address_dup (NMIPAddress *address)
|
||||
{
|
||||
NMIPAddress *copy;
|
||||
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address->refcount > 0, NULL);
|
||||
|
||||
copy = nm_ip_address_new (address->family,
|
||||
address->address, address->prefix, address->gateway,
|
||||
NULL);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_get_family:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Gets the IP address family (eg, AF_INET) property of this address
|
||||
* object.
|
||||
*
|
||||
* Returns: the IP address family
|
||||
**/
|
||||
int
|
||||
nm_ip_address_get_family (NMIPAddress *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, 0);
|
||||
g_return_val_if_fail (address->refcount > 0, 0);
|
||||
|
||||
return address->family;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_get_address:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Gets the IP address property of this address object.
|
||||
*
|
||||
* Returns: the IP address
|
||||
**/
|
||||
const char *
|
||||
nm_ip_address_get_address (NMIPAddress *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address->refcount > 0, NULL);
|
||||
|
||||
return address->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_set_address:
|
||||
* @address: the #NMIPAddress
|
||||
* @addr: the IP address, as a string
|
||||
*
|
||||
* Sets the IP address property of this address object.
|
||||
*
|
||||
* @addr must be a valid address of @address's family. If you aren't sure you
|
||||
* have a valid address, use nm_utils_ipaddr_valid() to check it.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_set_address (NMIPAddress *address,
|
||||
const char *addr)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (addr != NULL);
|
||||
g_return_if_fail (nm_utils_ipaddr_valid (address->family, addr));
|
||||
|
||||
g_free (address->address);
|
||||
address->address = canonicalize_ip (address->family, addr, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_get_address_binary: (skip)
|
||||
* @address: the #NMIPAddress
|
||||
* @addr: a buffer in which to store the address in binary format.
|
||||
*
|
||||
* Gets the IP address property of this address object.
|
||||
*
|
||||
* @addr must point to a buffer that is the correct size for @address's family.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_get_address_binary (NMIPAddress *address,
|
||||
gpointer addr)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (addr != NULL);
|
||||
|
||||
inet_pton (address->family, address->address, addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_set_address_binary: (skip)
|
||||
* @address: the #NMIPAddress
|
||||
* @addr: the address, in binary format
|
||||
*
|
||||
* Sets the IP address property of this address object.
|
||||
*
|
||||
* @addr must point to a buffer that is the correct size for @address's family.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_set_address_binary (NMIPAddress *address,
|
||||
gconstpointer addr)
|
||||
{
|
||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (addr != NULL);
|
||||
|
||||
g_free (address->address);
|
||||
address->address = g_strdup (inet_ntop (address->family, addr, string, sizeof (string)));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_get_prefix:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Gets the IP address prefix (ie "24" or "30" etc) property of this address
|
||||
* object.
|
||||
*
|
||||
* Returns: the IP address prefix
|
||||
**/
|
||||
guint
|
||||
nm_ip_address_get_prefix (NMIPAddress *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, 0);
|
||||
g_return_val_if_fail (address->refcount > 0, 0);
|
||||
|
||||
return address->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_set_prefix:
|
||||
* @address: the #NMIPAddress
|
||||
* @prefix: the IP address prefix
|
||||
*
|
||||
* Sets the IP address prefix property of this address object.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_set_prefix (NMIPAddress *address,
|
||||
guint prefix)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (valid_prefix (address->family, prefix, NULL));
|
||||
|
||||
address->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_get_gateway:
|
||||
* @address: the #NMIPAddress
|
||||
*
|
||||
* Gets the gateway property of this address object; this will be %NULL if the
|
||||
* address has no associated gateway.
|
||||
*
|
||||
* Returns: the gateway
|
||||
**/
|
||||
const char *
|
||||
nm_ip_address_get_gateway (NMIPAddress *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address->refcount > 0, NULL);
|
||||
|
||||
return address->gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_address_set_gateway:
|
||||
* @address: the #NMIPAddress
|
||||
* @gateway: (allow-none): the gateway, as a string
|
||||
*
|
||||
* Sets the gateway property of this address object.
|
||||
*
|
||||
* @gateway (if non-%NULL) must be a valid address of @address's family. If you
|
||||
* aren't sure you have a valid address, use nm_utils_ipaddr_valid() to check
|
||||
* it.
|
||||
**/
|
||||
void
|
||||
nm_ip_address_set_gateway (NMIPAddress *address,
|
||||
const char *gateway)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (!gateway || nm_utils_ipaddr_valid (address->family, gateway));
|
||||
|
||||
g_free (address->gateway);
|
||||
address->gateway = canonicalize_ip (address->family, gateway, TRUE);
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_BOXED_TYPE (NMIPRoute, nm_ip_route, nm_ip_route_dup, nm_ip_route_unref)
|
||||
|
||||
struct NMIPRoute {
|
||||
guint refcount;
|
||||
|
||||
int family;
|
||||
char *dest;
|
||||
guint prefix;
|
||||
char *next_hop;
|
||||
guint32 metric;
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip_route_new:
|
||||
* @family: the IP address family (%AF_INET or %AF_INET6)
|
||||
* @dest: the IP address of the route's destination
|
||||
* @prefix: the address prefix length
|
||||
* @next_hop: (allow-none): the IP address of the next hop (or %NULL)
|
||||
* @metric: the route metric (or 0 for "default")
|
||||
* @error: location to store error, or %NULL
|
||||
*
|
||||
* Creates a new #NMIPRoute object.
|
||||
*
|
||||
* Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
|
||||
**/
|
||||
NMIPRoute *
|
||||
nm_ip_route_new (int family,
|
||||
const char *dest,
|
||||
guint prefix,
|
||||
const char *next_hop,
|
||||
guint metric,
|
||||
GError **error)
|
||||
{
|
||||
NMIPRoute *route;
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||
|
||||
if (!valid_ip (family, dest, error))
|
||||
return NULL;
|
||||
if (!valid_prefix (family, prefix, error))
|
||||
return NULL;
|
||||
if (next_hop && !valid_ip (family, next_hop, error))
|
||||
return NULL;
|
||||
|
||||
route = g_slice_new0 (NMIPRoute);
|
||||
route->refcount = 1;
|
||||
|
||||
route->family = family;
|
||||
route->dest = canonicalize_ip (family, dest, FALSE);
|
||||
route->prefix = prefix;
|
||||
route->next_hop = canonicalize_ip (family, next_hop, TRUE);
|
||||
route->metric = metric;
|
||||
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_new_binary:
|
||||
* @family: the IP address family (%AF_INET or %AF_INET6)
|
||||
* @dest: the IP address of the route's destination
|
||||
* @prefix: the address prefix length
|
||||
* @next_hop: (allow-none): the IP address of the next hop (or %NULL)
|
||||
* @metric: the route metric (or 0 for "default")
|
||||
* @error: location to store error, or %NULL
|
||||
*
|
||||
* Creates a new #NMIPRoute object. @dest and @next_hop (if non-%NULL) must
|
||||
* point to buffers of the correct size for @family.
|
||||
*
|
||||
* Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
|
||||
**/
|
||||
NMIPRoute *
|
||||
nm_ip_route_new_binary (int family,
|
||||
gconstpointer dest,
|
||||
guint prefix,
|
||||
gconstpointer next_hop,
|
||||
guint metric,
|
||||
GError **error)
|
||||
{
|
||||
NMIPRoute *route;
|
||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||
|
||||
if (!valid_prefix (family, prefix, error))
|
||||
return NULL;
|
||||
|
||||
route = g_slice_new0 (NMIPRoute);
|
||||
route->refcount = 1;
|
||||
|
||||
route->family = family;
|
||||
route->dest = g_strdup (inet_ntop (family, dest, string, sizeof (string)));
|
||||
route->prefix = prefix;
|
||||
if (next_hop)
|
||||
route->next_hop = g_strdup (inet_ntop (family, next_hop, string, sizeof (string)));
|
||||
route->metric = metric;
|
||||
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_ref:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_ref (NMIPRoute *route)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_unref:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_unref (NMIPRoute *route)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->refcount--;
|
||||
if (route->refcount == 0) {
|
||||
g_free (route->dest);
|
||||
g_free (route->next_hop);
|
||||
g_slice_free (NMIPRoute, route);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_equal:
|
||||
* @route: the #NMIPRoute
|
||||
* @other: the #NMIPRoute to compare @route to.
|
||||
*
|
||||
* Determines if two #NMIPRoute objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
gboolean
|
||||
nm_ip_route_equal (NMIPRoute *route, NMIPRoute *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->prefix != other->prefix
|
||||
|| route->metric != other->metric
|
||||
|| strcmp (route->dest, other->dest) != 0
|
||||
|| g_strcmp0 (route->next_hop, other->next_hop) != 0)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_dup:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Creates a copy of @route
|
||||
*
|
||||
* Returns: (transfer full): a copy of @route
|
||||
**/
|
||||
NMIPRoute *
|
||||
nm_ip_route_dup (NMIPRoute *route)
|
||||
{
|
||||
NMIPRoute *copy;
|
||||
|
||||
g_return_val_if_fail (route != NULL, NULL);
|
||||
g_return_val_if_fail (route->refcount > 0, NULL);
|
||||
|
||||
copy = nm_ip_route_new (route->family,
|
||||
route->dest, route->prefix,
|
||||
route->next_hop, route->metric,
|
||||
NULL);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_family:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Gets the IP address family (eg, AF_INET) property of this route
|
||||
* object.
|
||||
*
|
||||
* Returns: the IP address family
|
||||
**/
|
||||
int
|
||||
nm_ip_route_get_family (NMIPRoute *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, 0);
|
||||
g_return_val_if_fail (route->refcount > 0, 0);
|
||||
|
||||
return route->family;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_dest:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Gets the IP destination address property of this route object.
|
||||
*
|
||||
* Returns: the IP address of the route's destination
|
||||
**/
|
||||
const char *
|
||||
nm_ip_route_get_dest (NMIPRoute *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, NULL);
|
||||
g_return_val_if_fail (route->refcount > 0, NULL);
|
||||
|
||||
return route->dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_dest:
|
||||
* @route: the #NMIPRoute
|
||||
* @dest: the route's destination, as a string
|
||||
*
|
||||
* Sets the destination property of this route object.
|
||||
*
|
||||
* @dest must be a valid address of @route's family. If you aren't sure you
|
||||
* have a valid address, use nm_utils_ipaddr_valid() to check it.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_dest (NMIPRoute *route,
|
||||
const char *dest)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (dest != NULL);
|
||||
g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest));
|
||||
|
||||
g_free (route->dest);
|
||||
route->dest = canonicalize_ip (route->family, dest, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_dest_binary: (skip)
|
||||
* @route: the #NMIPRoute
|
||||
* @dest: a buffer in which to store the destination in binary format.
|
||||
*
|
||||
* Gets the destination property of this route object.
|
||||
*
|
||||
* @dest must point to a buffer that is the correct size for @route's family.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_get_dest_binary (NMIPRoute *route,
|
||||
gpointer dest)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (dest != NULL);
|
||||
|
||||
inet_pton (route->family, route->dest, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_dest_binary: (skip)
|
||||
* @route: the #NMIPRoute
|
||||
* @dest: the route's destination, in binary format
|
||||
*
|
||||
* Sets the destination property of this route object.
|
||||
*
|
||||
* @dest must point to a buffer that is the correct size for @route's family.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_dest_binary (NMIPRoute *route,
|
||||
gconstpointer dest)
|
||||
{
|
||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (dest != NULL);
|
||||
|
||||
g_free (route->dest);
|
||||
route->dest = g_strdup (inet_ntop (route->family, dest, string, sizeof (string)));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_prefix:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Gets the IP prefix (ie "24" or "30" etc) of this route.
|
||||
*
|
||||
* Returns: the IP prefix
|
||||
**/
|
||||
guint
|
||||
nm_ip_route_get_prefix (NMIPRoute *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, 0);
|
||||
g_return_val_if_fail (route->refcount > 0, 0);
|
||||
|
||||
return route->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_prefix:
|
||||
* @route: the #NMIPRoute
|
||||
* @prefix: the route prefix
|
||||
*
|
||||
* Sets the prefix property of this route object.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_prefix (NMIPRoute *route,
|
||||
guint prefix)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (valid_prefix (route->family, prefix, NULL));
|
||||
|
||||
route->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_next_hop:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Gets the IP address of the next hop of this route; this will be %NULL if the
|
||||
* route has no next hop.
|
||||
*
|
||||
* Returns: the IP address of the next hop, or %NULL if this is a device route.
|
||||
**/
|
||||
const char *
|
||||
nm_ip_route_get_next_hop (NMIPRoute *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, NULL);
|
||||
g_return_val_if_fail (route->refcount > 0, NULL);
|
||||
|
||||
return route->next_hop;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_next_hop:
|
||||
* @route: the #NMIPRoute
|
||||
* @next_hop: (allow-none): the route's next hop, as a string
|
||||
*
|
||||
* Sets the next-hop property of this route object.
|
||||
*
|
||||
* @next_hop (if non-%NULL) must be a valid address of @route's family. If you
|
||||
* aren't sure you have a valid address, use nm_utils_ipaddr_valid() to check
|
||||
* it.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_next_hop (NMIPRoute *route,
|
||||
const char *next_hop)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (!next_hop || nm_utils_ipaddr_valid (route->family, next_hop));
|
||||
|
||||
g_free (route->next_hop);
|
||||
route->next_hop = canonicalize_ip (route->family, next_hop, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_next_hop_binary: (skip)
|
||||
* @route: the #NMIPRoute
|
||||
* @next_hop: a buffer in which to store the next hop in binary format.
|
||||
*
|
||||
* Gets the next hop property of this route object.
|
||||
*
|
||||
* @next_hop must point to a buffer that is the correct size for @route's family.
|
||||
*
|
||||
* Returns: %TRUE if @route has a next hop, %FALSE if not (in which case
|
||||
* @next_hop will be zeroed out)
|
||||
**/
|
||||
gboolean
|
||||
nm_ip_route_get_next_hop_binary (NMIPRoute *route,
|
||||
gpointer next_hop)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, FALSE);
|
||||
g_return_val_if_fail (next_hop != NULL, FALSE);
|
||||
|
||||
if (route->next_hop) {
|
||||
inet_pton (route->family, route->next_hop, next_hop);
|
||||
return TRUE;
|
||||
} else {
|
||||
memset (next_hop, 0,
|
||||
route->family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_next_hop_binary: (skip)
|
||||
* @route: the #NMIPRoute
|
||||
* @next_hop: the route's next hop, in binary format
|
||||
*
|
||||
* Sets the destination property of this route object.
|
||||
*
|
||||
* @next_hop (if non-%NULL) must point to a buffer that is the correct size for
|
||||
* @route's family.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_next_hop_binary (NMIPRoute *route,
|
||||
gconstpointer next_hop)
|
||||
{
|
||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (route != NULL);
|
||||
|
||||
g_free (route->next_hop);
|
||||
if (next_hop)
|
||||
route->next_hop = g_strdup (inet_ntop (route->family, next_hop, string, sizeof (string)));
|
||||
else
|
||||
route->next_hop = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_get_metric:
|
||||
* @route: the #NMIPRoute
|
||||
*
|
||||
* Gets the route metric property of this route object; lower values
|
||||
* indicate "better" or more preferred routes; 0 indicates "default"
|
||||
* (meaning NetworkManager will set it appropriately).
|
||||
*
|
||||
* Returns: the route metric
|
||||
**/
|
||||
guint32
|
||||
nm_ip_route_get_metric (NMIPRoute *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, 0);
|
||||
g_return_val_if_fail (route->refcount > 0, 0);
|
||||
|
||||
return route->metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip_route_set_metric:
|
||||
* @route: the #NMIPRoute
|
||||
* @metric: the route metric
|
||||
*
|
||||
* Sets the metric property of this route object.
|
||||
**/
|
||||
void
|
||||
nm_ip_route_set_metric (NMIPRoute *route,
|
||||
guint32 metric)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
|
||||
route->metric = metric;
|
||||
}
|
117
libnm-core/nm-setting-ip-config.h
Normal file
117
libnm-core/nm-setting-ip-config.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Copyright 2007 - 2014 Red Hat, Inc.
|
||||
* Copyright 2007 - 2008 Novell, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_SETTING_IP_CONFIG_H
|
||||
#define NM_SETTING_IP_CONFIG_H
|
||||
|
||||
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
|
||||
#error "Only <NetworkManager.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include "nm-setting.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct NMIPAddress NMIPAddress;
|
||||
|
||||
GType nm_ip_address_get_type (void);
|
||||
|
||||
NMIPAddress *nm_ip_address_new (int family,
|
||||
const char *addr,
|
||||
guint prefix,
|
||||
const char *gateway,
|
||||
GError **error);
|
||||
NMIPAddress *nm_ip_address_new_binary (int family,
|
||||
gconstpointer addr,
|
||||
guint prefix,
|
||||
gconstpointer gateway,
|
||||
GError **error);
|
||||
|
||||
void nm_ip_address_ref (NMIPAddress *address);
|
||||
void nm_ip_address_unref (NMIPAddress *address);
|
||||
gboolean nm_ip_address_equal (NMIPAddress *address,
|
||||
NMIPAddress *other);
|
||||
NMIPAddress *nm_ip_address_dup (NMIPAddress *address);
|
||||
|
||||
int nm_ip_address_get_family (NMIPAddress *address);
|
||||
const char *nm_ip_address_get_address (NMIPAddress *address);
|
||||
void nm_ip_address_set_address (NMIPAddress *address,
|
||||
const char *addr);
|
||||
void nm_ip_address_get_address_binary (NMIPAddress *address,
|
||||
gpointer addr);
|
||||
void nm_ip_address_set_address_binary (NMIPAddress *address,
|
||||
gconstpointer addr);
|
||||
guint nm_ip_address_get_prefix (NMIPAddress *address);
|
||||
void nm_ip_address_set_prefix (NMIPAddress *address,
|
||||
guint prefix);
|
||||
const char *nm_ip_address_get_gateway (NMIPAddress *address);
|
||||
void nm_ip_address_set_gateway (NMIPAddress *address,
|
||||
const char *gateway);
|
||||
|
||||
typedef struct NMIPRoute NMIPRoute;
|
||||
|
||||
GType nm_ip_route_get_type (void);
|
||||
|
||||
NMIPRoute *nm_ip_route_new (int family,
|
||||
const char *dest,
|
||||
guint prefix,
|
||||
const char *next_hop,
|
||||
guint metric,
|
||||
GError **error);
|
||||
NMIPRoute *nm_ip_route_new_binary (int family,
|
||||
gconstpointer dest,
|
||||
guint prefix,
|
||||
gconstpointer next_hop,
|
||||
guint metric,
|
||||
GError **error);
|
||||
|
||||
void nm_ip_route_ref (NMIPRoute *route);
|
||||
void nm_ip_route_unref (NMIPRoute *route);
|
||||
gboolean nm_ip_route_equal (NMIPRoute *route,
|
||||
NMIPRoute *other);
|
||||
NMIPRoute *nm_ip_route_dup (NMIPRoute *route);
|
||||
|
||||
int nm_ip_route_get_family (NMIPRoute *route);
|
||||
const char *nm_ip_route_get_dest (NMIPRoute *route);
|
||||
void nm_ip_route_set_dest (NMIPRoute *route,
|
||||
const char *dest);
|
||||
void nm_ip_route_get_dest_binary (NMIPRoute *route,
|
||||
gpointer dest);
|
||||
void nm_ip_route_set_dest_binary (NMIPRoute *route,
|
||||
gconstpointer dest);
|
||||
guint nm_ip_route_get_prefix (NMIPRoute *route);
|
||||
void nm_ip_route_set_prefix (NMIPRoute *route,
|
||||
guint prefix);
|
||||
const char *nm_ip_route_get_next_hop (NMIPRoute *route);
|
||||
void nm_ip_route_set_next_hop (NMIPRoute *route,
|
||||
const char *next_hop);
|
||||
gboolean nm_ip_route_get_next_hop_binary (NMIPRoute *route,
|
||||
gpointer next_hop);
|
||||
void nm_ip_route_set_next_hop_binary (NMIPRoute *route,
|
||||
gconstpointer next_hop);
|
||||
guint32 nm_ip_route_get_metric (NMIPRoute *route);
|
||||
void nm_ip_route_set_metric (NMIPRoute *route,
|
||||
guint32 metric);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_SETTING_IP_CONFIG_H */
|
@@ -39,9 +39,6 @@
|
||||
* properties related to IPv4 addressing, routing, and Domain Name Service
|
||||
**/
|
||||
|
||||
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)
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING,
|
||||
_nm_register_setting (IP4_CONFIG, 4))
|
||||
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
|
||||
@@ -52,9 +49,9 @@ typedef struct {
|
||||
char *method;
|
||||
GSList *dns; /* list of IP address strings */
|
||||
GSList *dns_search; /* list of strings */
|
||||
GSList *addresses; /* array of NMIP4Address */
|
||||
GSList *addresses; /* array of NMIPAddress */
|
||||
GSList *address_labels; /* list of strings */
|
||||
GSList *routes; /* array of NMIP4Route */
|
||||
GSList *routes; /* array of NMIPRoute */
|
||||
gboolean ignore_auto_routes;
|
||||
gboolean ignore_auto_dns;
|
||||
char *dhcp_client_id;
|
||||
@@ -424,7 +421,7 @@ nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting)
|
||||
*
|
||||
* Returns: the address at index @i
|
||||
**/
|
||||
NMIP4Address *
|
||||
NMIPAddress *
|
||||
nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
@@ -434,7 +431,7 @@ nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
|
||||
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);
|
||||
return (NMIPAddress *) g_slist_nth_data (priv->addresses, i);
|
||||
}
|
||||
|
||||
const char *
|
||||
@@ -463,18 +460,18 @@ _nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
|
||||
NMIP4Address *address)
|
||||
NMIPAddress *address)
|
||||
{
|
||||
return _nm_setting_ip4_config_add_address_with_label (setting, address, "");
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
|
||||
NMIP4Address *address,
|
||||
NMIPAddress *address,
|
||||
const char *label)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
NMIP4Address *copy;
|
||||
NMIPAddress *copy;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
|
||||
@@ -483,11 +480,11 @@ _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
|
||||
|
||||
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))
|
||||
if (nm_ip_address_equal ((NMIPAddress *) iter->data, address))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
copy = nm_ip4_address_dup (address);
|
||||
copy = nm_ip_address_dup (address);
|
||||
priv->addresses = g_slist_append (priv->addresses, copy);
|
||||
priv->address_labels = g_slist_append (priv->address_labels, g_strdup (label));
|
||||
|
||||
@@ -515,7 +512,7 @@ nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i)
|
||||
label = g_slist_nth (priv->address_labels, i);
|
||||
g_return_if_fail (addr != NULL && label != NULL);
|
||||
|
||||
nm_ip4_address_unref ((NMIP4Address *) addr->data);
|
||||
nm_ip_address_unref ((NMIPAddress *) addr->data);
|
||||
priv->addresses = g_slist_delete_link (priv->addresses, addr);
|
||||
g_free (label->data);
|
||||
priv->address_labels = g_slist_delete_link (priv->address_labels, label);
|
||||
@@ -534,7 +531,7 @@ nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting,
|
||||
NMIP4Address *address)
|
||||
NMIPAddress *address)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
GSList *iter;
|
||||
@@ -544,8 +541,8 @@ nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting,
|
||||
|
||||
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);
|
||||
if (nm_ip_address_equal ((NMIPAddress *) iter->data, address)) {
|
||||
nm_ip_address_unref ((NMIPAddress *) iter->data);
|
||||
priv->addresses = g_slist_delete_link (priv->addresses, iter);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
return TRUE;
|
||||
@@ -567,7 +564,7 @@ nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting)
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip_address_unref);
|
||||
priv->addresses = NULL;
|
||||
g_slist_free_full (priv->address_labels, g_free);
|
||||
priv->address_labels = NULL;
|
||||
@@ -595,7 +592,7 @@ nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting)
|
||||
*
|
||||
* Returns: the route at index @i
|
||||
**/
|
||||
NMIP4Route *
|
||||
NMIPRoute *
|
||||
nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
@@ -605,7 +602,7 @@ nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
|
||||
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);
|
||||
return (NMIPRoute *) g_slist_nth_data (priv->routes, i);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -620,10 +617,10 @@ nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
|
||||
NMIP4Route *route)
|
||||
NMIPRoute *route)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
NMIP4Route *copy;
|
||||
NMIPRoute *copy;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
|
||||
@@ -631,11 +628,11 @@ nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
|
||||
|
||||
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))
|
||||
if (nm_ip_route_equal (iter->data, route))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
copy = nm_ip4_route_dup (route);
|
||||
copy = nm_ip_route_dup (route);
|
||||
priv->routes = g_slist_append (priv->routes, copy);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
return TRUE;
|
||||
@@ -660,7 +657,7 @@ nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i)
|
||||
elt = g_slist_nth (priv->routes, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
nm_ip4_route_unref ((NMIP4Route *) elt->data);
|
||||
nm_ip_route_unref ((NMIPRoute *) elt->data);
|
||||
priv->routes = g_slist_delete_link (priv->routes, elt);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
}
|
||||
@@ -676,7 +673,7 @@ nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting,
|
||||
NMIP4Route *route)
|
||||
NMIPRoute *route)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv;
|
||||
GSList *iter;
|
||||
@@ -686,8 +683,8 @@ nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting,
|
||||
|
||||
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);
|
||||
if (nm_ip_route_equal ((NMIPRoute *) iter->data, route)) {
|
||||
nm_ip_route_unref ((NMIPRoute *) iter->data);
|
||||
priv->routes = g_slist_delete_link (priv->routes, iter);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
return TRUE;
|
||||
@@ -709,7 +706,7 @@ nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
|
||||
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
priv->routes = NULL;
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
}
|
||||
@@ -871,7 +868,7 @@ static gboolean
|
||||
verify (NMSetting *setting, NMConnection *connection, GError **error)
|
||||
{
|
||||
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
|
||||
GSList *iter, *l_iter;
|
||||
GSList *iter;
|
||||
int i;
|
||||
|
||||
if (!priv->method) {
|
||||
@@ -957,33 +954,9 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Validate addresses */
|
||||
for (iter = priv->addresses, l_iter = priv->address_labels, i = 0;
|
||||
iter && l_iter;
|
||||
iter = g_slist_next (iter), l_iter = g_slist_next (l_iter), i++) {
|
||||
NMIP4Address *addr = (NMIP4Address *) iter->data;
|
||||
const char *label = (const char *) l_iter->data;
|
||||
guint32 prefix = nm_ip4_address_get_prefix (addr);
|
||||
|
||||
if (!nm_ip4_address_get_address (addr)) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("%d. IPv4 address is invalid"),
|
||||
i+1);
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!prefix || prefix > 32) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("%d. IPv4 address has invalid prefix"),
|
||||
i+1);
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
return FALSE;
|
||||
}
|
||||
/* Validate address labels */
|
||||
for (iter = priv->address_labels, i = 0; iter; iter = g_slist_next (iter), i++) {
|
||||
const char *label = (const char *) iter->data;
|
||||
|
||||
if (!verify_label (label)) {
|
||||
g_set_error (error,
|
||||
@@ -996,7 +969,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
||||
}
|
||||
}
|
||||
|
||||
if (iter || l_iter) {
|
||||
if (g_slist_length (priv->addresses) != g_slist_length (priv->address_labels)) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
@@ -1007,32 +980,6 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Validate routes */
|
||||
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);
|
||||
|
||||
if (!nm_ip4_route_get_dest (route)) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("%d. route is invalid"),
|
||||
i+1);
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!prefix || prefix > 32) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("%d. route has invalid prefix"),
|
||||
i+1);
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate DNS */
|
||||
for (iter = priv->dns, i = 0; iter; iter = g_slist_next (iter), i++) {
|
||||
const char *dns = (const char *) iter->data;
|
||||
@@ -1070,9 +1017,9 @@ finalize (GObject *object)
|
||||
|
||||
g_slist_free_full (priv->dns, g_free);
|
||||
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->addresses, (GDestroyNotify) nm_ip_address_unref);
|
||||
g_slist_free_full (priv->address_labels, g_free);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
|
||||
G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -1138,9 +1085,9 @@ set_property (GObject *object, guint prop_id,
|
||||
priv->dns_search = _nm_utils_strv_to_slist (g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip_address_unref);
|
||||
priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
|
||||
(NMUtilsCopyFunc) nm_ip4_address_dup);
|
||||
(NMUtilsCopyFunc) nm_ip_address_dup);
|
||||
|
||||
if (g_slist_length (priv->addresses) != g_slist_length (priv->address_labels)) {
|
||||
g_slist_free_full (priv->address_labels, g_free);
|
||||
@@ -1154,9 +1101,9 @@ set_property (GObject *object, guint prop_id,
|
||||
priv->address_labels = _nm_utils_strv_to_slist (g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
|
||||
(NMUtilsCopyFunc) nm_ip4_route_dup);
|
||||
(NMUtilsCopyFunc) nm_ip_route_dup);
|
||||
break;
|
||||
case PROP_IGNORE_AUTO_ROUTES:
|
||||
priv->ignore_auto_routes = g_value_get_boolean (value);
|
||||
@@ -1205,13 +1152,13 @@ get_property (GObject *object, guint prop_id,
|
||||
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip4_address_dup, (GDestroyNotify) nm_ip4_address_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip_address_dup, (GDestroyNotify) nm_ip_address_unref));
|
||||
break;
|
||||
case PROP_ADDRESS_LABELS:
|
||||
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->address_labels));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip4_route_dup, (GDestroyNotify) nm_ip4_route_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip_route_dup, (GDestroyNotify) nm_ip_route_unref));
|
||||
break;
|
||||
case PROP_IGNORE_AUTO_ROUTES:
|
||||
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
|
||||
@@ -1325,7 +1272,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
|
||||
* with the "shared", "link-local", or "disabled" methods as addressing is
|
||||
* either automatic or disabled with these methods.
|
||||
*
|
||||
* Element-Type: NMIP4Address
|
||||
* Element-Type: NMIPAddress
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ADDRESSES,
|
||||
@@ -1360,7 +1307,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
|
||||
* the 'shared', 'link-local', or 'disabled' methods because there is no
|
||||
* upstream network.
|
||||
*
|
||||
* Element-Type: NMIP4Route
|
||||
* Element-Type: NMIPRoute
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ROUTES,
|
||||
@@ -1482,463 +1429,3 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
|
||||
struct NMIP4Address {
|
||||
guint32 refcount;
|
||||
guint32 address; /* network byte order */
|
||||
guint32 prefix;
|
||||
guint32 gateway; /* network byte order */
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip4_address_new:
|
||||
*
|
||||
* Creates and returns a new #NMIP4Address object.
|
||||
*
|
||||
* Returns: (transfer full): the new empty #NMIP4Address object
|
||||
**/
|
||||
NMIP4Address *
|
||||
nm_ip4_address_new (void)
|
||||
{
|
||||
NMIP4Address *address;
|
||||
|
||||
address = g_malloc0 (sizeof (NMIP4Address));
|
||||
address->refcount = 1;
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_dup:
|
||||
* @source: the #NMIP4Address object to copy
|
||||
*
|
||||
* Copies a given #NMIP4Address object and returns the copy.
|
||||
*
|
||||
* Returns: (transfer full): the copy of the given #NMIP4Address copy
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_ref:
|
||||
* @address: the #NMIP4Address
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip4_address_ref (NMIP4Address *address)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
|
||||
address->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_unref:
|
||||
* @address: the #NMIP4Address
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_compare:
|
||||
* @address: the #NMIP4Address
|
||||
* @other: the #NMIP4Address to compare @address to.
|
||||
*
|
||||
* Determines if two #NMIP4Address objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_get_address:
|
||||
* @address: the #NMIP4Address
|
||||
*
|
||||
* Gets the IPv4 address property of this address object.
|
||||
*
|
||||
* Returns: the IPv4 address in network byte order
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_set_address:
|
||||
* @address: the #NMIP4Address
|
||||
* @addr: the IPv4 address in network byte order
|
||||
*
|
||||
* Sets the IPv4 address property of this object.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_get_prefix:
|
||||
* @address: the #NMIP4Address
|
||||
*
|
||||
* Gets the IPv4 address prefix (ie "24" or "30" etc) property of this address
|
||||
* object.
|
||||
*
|
||||
* Returns: the IPv4 address prefix
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_set_prefix:
|
||||
* @address: the #NMIP4Address
|
||||
* @prefix: the address prefix, a number between 1 and 32 inclusive
|
||||
*
|
||||
* Sets the IPv4 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);
|
||||
g_return_if_fail (prefix <= 32);
|
||||
g_return_if_fail (prefix > 0);
|
||||
|
||||
address->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_get_gateway:
|
||||
* @address: the #NMIP4Address
|
||||
*
|
||||
* Gets the IPv4 default gateway property of this address object.
|
||||
*
|
||||
* Returns: the IPv4 gateway address in network byte order
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_address_set_gateway:
|
||||
* @address: the #NMIP4Address
|
||||
* @gateway: the IPv4 default gateway in network byte order
|
||||
*
|
||||
* Sets the IPv4 default gateway property of this address object.
|
||||
**/
|
||||
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 */
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip4_route_new:
|
||||
*
|
||||
* Creates and returns a new #NMIP4Route object.
|
||||
*
|
||||
* Returns: (transfer full): the new empty #NMIP4Route object
|
||||
**/
|
||||
NMIP4Route *
|
||||
nm_ip4_route_new (void)
|
||||
{
|
||||
NMIP4Route *route;
|
||||
|
||||
route = g_malloc0 (sizeof (NMIP4Route));
|
||||
route->refcount = 1;
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_dup:
|
||||
* @source: the #NMIP4Route object to copy
|
||||
*
|
||||
* Copies a given #NMIP4Route object and returns the copy.
|
||||
*
|
||||
* Returns: (transfer full): the copy of the given #NMIP4Route copy
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_ref:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip4_route_ref (NMIP4Route *route)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_unref:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_compare:
|
||||
* @route: the #NMIP4Route
|
||||
* @other: the #NMIP4Route to compare @route to.
|
||||
*
|
||||
* Determines if two #NMIP4Route objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_get_dest:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Gets the IPv4 destination address property of this route object.
|
||||
*
|
||||
* Returns: the IPv4 address in network byte order
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_set_dest:
|
||||
* @route: the #NMIP4Route
|
||||
* @dest: the destination address in network byte order
|
||||
*
|
||||
* Sets the IPv4 destination address property of this route object.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_get_prefix:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Gets the IPv4 prefix (ie "24" or "30" etc) of this route.
|
||||
*
|
||||
* Returns: the IPv4 prefix
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_set_prefix:
|
||||
* @route: the #NMIP4Route
|
||||
* @prefix: the prefix, a number between 1 and 32 inclusive
|
||||
*
|
||||
* Sets the IPv4 prefix of this route.
|
||||
**/
|
||||
void
|
||||
nm_ip4_route_set_prefix (NMIP4Route *route, guint32 prefix)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
g_return_if_fail (prefix <= 32);
|
||||
g_return_if_fail (prefix > 0);
|
||||
|
||||
route->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_get_next_hop:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Gets the IPv4 address of the next hop of this route.
|
||||
*
|
||||
* Returns: the IPv4 address in network byte order
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_set_next_hop:
|
||||
* @route: the #NMIP4Route
|
||||
* @next_hop: the IPv4 address of the next hop in network byte order
|
||||
*
|
||||
* Sets the IPv4 address of the next hop of this route.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_get_metric:
|
||||
* @route: the #NMIP4Route
|
||||
*
|
||||
* Gets the route metric property of this route object; lower values indicate
|
||||
* "better" or more preferred routes.
|
||||
*
|
||||
* Returns: the route metric
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip4_route_set_metric:
|
||||
* @route: the #NMIP4Route
|
||||
* @metric: the route metric
|
||||
*
|
||||
* Sets the route metric property of this route object; lower values indicate
|
||||
* "better" or more preferred routes.
|
||||
**/
|
||||
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;
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#endif
|
||||
|
||||
#include "nm-setting.h"
|
||||
#include "nm-setting-ip-config.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -97,57 +98,6 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
#define NM_SETTING_IP4_CONFIG_METHOD_DISABLED "disabled"
|
||||
|
||||
typedef struct NMIP4Address NMIP4Address;
|
||||
|
||||
GType nm_ip4_address_get_type (void);
|
||||
|
||||
NMIP4Address * nm_ip4_address_new (void);
|
||||
NMIP4Address * nm_ip4_address_dup (NMIP4Address *source);
|
||||
void nm_ip4_address_ref (NMIP4Address *address);
|
||||
void nm_ip4_address_unref (NMIP4Address *address);
|
||||
/* Return TRUE if addresses are identical */
|
||||
gboolean nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other);
|
||||
|
||||
guint32 nm_ip4_address_get_address (NMIP4Address *address);
|
||||
void nm_ip4_address_set_address (NMIP4Address *address,
|
||||
guint32 addr); /* network byte order */
|
||||
|
||||
guint32 nm_ip4_address_get_prefix (NMIP4Address *address);
|
||||
void nm_ip4_address_set_prefix (NMIP4Address *address,
|
||||
guint32 prefix);
|
||||
|
||||
guint32 nm_ip4_address_get_gateway (NMIP4Address *address);
|
||||
void nm_ip4_address_set_gateway (NMIP4Address *address,
|
||||
guint32 gateway); /* network byte order */
|
||||
|
||||
typedef struct NMIP4Route NMIP4Route;
|
||||
|
||||
GType nm_ip4_route_get_type (void);
|
||||
|
||||
NMIP4Route * nm_ip4_route_new (void);
|
||||
NMIP4Route * nm_ip4_route_dup (NMIP4Route *source);
|
||||
void nm_ip4_route_ref (NMIP4Route *route);
|
||||
void nm_ip4_route_unref (NMIP4Route *route);
|
||||
/* Return TRUE if routes are identical */
|
||||
gboolean nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other);
|
||||
|
||||
guint32 nm_ip4_route_get_dest (NMIP4Route *route);
|
||||
void nm_ip4_route_set_dest (NMIP4Route *route,
|
||||
guint32 dest); /* network byte order */
|
||||
|
||||
guint32 nm_ip4_route_get_prefix (NMIP4Route *route);
|
||||
void nm_ip4_route_set_prefix (NMIP4Route *route,
|
||||
guint32 prefix);
|
||||
|
||||
guint32 nm_ip4_route_get_next_hop (NMIP4Route *route);
|
||||
void nm_ip4_route_set_next_hop (NMIP4Route *route,
|
||||
guint32 next_hop); /* network byte order */
|
||||
|
||||
guint32 nm_ip4_route_get_metric (NMIP4Route *route);
|
||||
void nm_ip4_route_set_metric (NMIP4Route *route,
|
||||
guint32 metric);
|
||||
|
||||
|
||||
struct _NMSettingIP4Config {
|
||||
NMSetting parent;
|
||||
};
|
||||
@@ -179,17 +129,17 @@ gboolean nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Conf
|
||||
void nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting);
|
||||
|
||||
guint32 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting);
|
||||
NMIP4Address *nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address);
|
||||
NMIPAddress * nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIPAddress *address);
|
||||
void nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, NMIP4Address *address);
|
||||
gboolean nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, NMIPAddress *address);
|
||||
void nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting);
|
||||
|
||||
guint32 nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting);
|
||||
NMIP4Route * nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_add_route (NMSettingIP4Config *setting, NMIP4Route *route);
|
||||
NMIPRoute * nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_add_route (NMSettingIP4Config *setting, NMIPRoute *route);
|
||||
void nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route);
|
||||
gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIPRoute *route);
|
||||
void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting);
|
||||
|
||||
gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
|
||||
|
@@ -37,9 +37,6 @@
|
||||
* properties related to IPv6 addressing, routing, and Domain Name Service
|
||||
**/
|
||||
|
||||
G_DEFINE_BOXED_TYPE (NMIP6Address, nm_ip6_address, nm_ip6_address_dup, nm_ip6_address_unref)
|
||||
G_DEFINE_BOXED_TYPE (NMIP6Route, nm_ip6_route, nm_ip6_route_dup, nm_ip6_route_unref)
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING,
|
||||
_nm_register_setting (IP6_CONFIG, 4))
|
||||
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP6_CONFIG)
|
||||
@@ -51,8 +48,8 @@ typedef struct {
|
||||
char *dhcp_hostname;
|
||||
GSList *dns; /* array of struct in6_addr */
|
||||
GSList *dns_search; /* list of strings */
|
||||
GSList *addresses; /* array of NMIP6Address */
|
||||
GSList *routes; /* array of NMIP6Route */
|
||||
GSList *addresses; /* array of NMIPAddress */
|
||||
GSList *routes; /* array of NMIPRoute */
|
||||
gboolean ignore_auto_routes;
|
||||
gboolean ignore_auto_dns;
|
||||
gboolean never_default;
|
||||
@@ -437,7 +434,7 @@ nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting)
|
||||
*
|
||||
* Returns: the address at index @i
|
||||
**/
|
||||
NMIP6Address *
|
||||
NMIPAddress *
|
||||
nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
@@ -447,7 +444,7 @@ nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (i < g_slist_length (priv->addresses), NULL);
|
||||
|
||||
return (NMIP6Address *) g_slist_nth_data (priv->addresses, i);
|
||||
return (NMIPAddress *) g_slist_nth_data (priv->addresses, i);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,10 +460,10 @@ nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip6_config_add_address (NMSettingIP6Config *setting,
|
||||
NMIP6Address *address)
|
||||
NMIPAddress *address)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
NMIP6Address *copy;
|
||||
NMIPAddress *copy;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
|
||||
@@ -474,11 +471,11 @@ nm_setting_ip6_config_add_address (NMSettingIP6Config *setting,
|
||||
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address))
|
||||
if (nm_ip_address_equal ((NMIPAddress *) iter->data, address))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
copy = nm_ip6_address_dup (address);
|
||||
copy = nm_ip_address_dup (address);
|
||||
priv->addresses = g_slist_append (priv->addresses, copy);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
|
||||
return TRUE;
|
||||
@@ -503,7 +500,7 @@ nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i)
|
||||
elt = g_slist_nth (priv->addresses, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
nm_ip6_address_unref ((NMIP6Address *) elt->data);
|
||||
nm_ip_address_unref ((NMIPAddress *) elt->data);
|
||||
priv->addresses = g_slist_delete_link (priv->addresses, elt);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
|
||||
}
|
||||
@@ -519,7 +516,7 @@ nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting,
|
||||
NMIP6Address *address)
|
||||
NMIPAddress *address)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
GSList *iter;
|
||||
@@ -529,7 +526,7 @@ nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting,
|
||||
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address)) {
|
||||
if (nm_ip_address_equal ((NMIPAddress *) iter->data, address)) {
|
||||
priv->addresses = g_slist_delete_link (priv->addresses, iter);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
|
||||
return TRUE;
|
||||
@@ -551,7 +548,7 @@ nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting)
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip_address_unref);
|
||||
priv->addresses = NULL;
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
|
||||
}
|
||||
@@ -577,7 +574,7 @@ nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting)
|
||||
*
|
||||
* Returns: the route at index @i
|
||||
**/
|
||||
NMIP6Route *
|
||||
NMIPRoute *
|
||||
nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
@@ -587,7 +584,7 @@ nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (i < g_slist_length (priv->routes), NULL);
|
||||
|
||||
return (NMIP6Route *) g_slist_nth_data (priv->routes, i);
|
||||
return (NMIPRoute *) g_slist_nth_data (priv->routes, i);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,10 +599,10 @@ nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip6_config_add_route (NMSettingIP6Config *setting,
|
||||
NMIP6Route *route)
|
||||
NMIPRoute *route)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
NMIP6Route *copy;
|
||||
NMIPRoute *copy;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
|
||||
@@ -613,11 +610,11 @@ nm_setting_ip6_config_add_route (NMSettingIP6Config *setting,
|
||||
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route))
|
||||
if (nm_ip_route_equal ((NMIPRoute *) iter->data, route))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
copy = nm_ip6_route_dup (route);
|
||||
copy = nm_ip_route_dup (route);
|
||||
priv->routes = g_slist_append (priv->routes, copy);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
|
||||
return TRUE;
|
||||
@@ -642,7 +639,7 @@ nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i)
|
||||
elt = g_slist_nth (priv->routes, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
nm_ip6_route_unref ((NMIP6Route *) elt->data);
|
||||
nm_ip_route_unref ((NMIPRoute *) elt->data);
|
||||
priv->routes = g_slist_delete_link (priv->routes, elt);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
|
||||
}
|
||||
@@ -658,7 +655,7 @@ nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i)
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting,
|
||||
NMIP6Route *route)
|
||||
NMIPRoute *route)
|
||||
{
|
||||
NMSettingIP6ConfigPrivate *priv;
|
||||
GSList *iter;
|
||||
@@ -668,8 +665,8 @@ nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting,
|
||||
|
||||
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
|
||||
for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route)) {
|
||||
nm_ip6_route_unref ((NMIP6Route *) iter->data);
|
||||
if (nm_ip_route_equal ((NMIPRoute *) iter->data, route)) {
|
||||
nm_ip_route_unref ((NMIPRoute *) iter->data);
|
||||
priv->routes = g_slist_delete_link (priv->routes, iter);
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
|
||||
return TRUE;
|
||||
@@ -691,7 +688,7 @@ nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting)
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
|
||||
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
priv->routes = NULL;
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
|
||||
}
|
||||
@@ -899,8 +896,8 @@ finalize (GObject *object)
|
||||
|
||||
g_slist_free_full (priv->dns, g_free);
|
||||
g_slist_free_full (priv->dns_search, g_free);
|
||||
g_slist_free_full (priv->addresses, g_free);
|
||||
g_slist_free_full (priv->routes, g_free);
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip_address_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
|
||||
G_OBJECT_CLASS (nm_setting_ip6_config_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -964,14 +961,14 @@ set_property (GObject *object, guint prop_id,
|
||||
priv->dns_search = _nm_utils_strv_to_slist (g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_address_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_address_unref);
|
||||
priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
|
||||
(NMUtilsCopyFunc) nm_ip6_address_dup);
|
||||
(NMUtilsCopyFunc) nm_ip_address_dup);
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip_route_unref);
|
||||
priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
|
||||
(NMUtilsCopyFunc) nm_ip6_route_dup);
|
||||
(NMUtilsCopyFunc) nm_ip_route_dup);
|
||||
break;
|
||||
case PROP_IGNORE_AUTO_ROUTES:
|
||||
priv->ignore_auto_routes = g_value_get_boolean (value);
|
||||
@@ -1015,10 +1012,10 @@ get_property (GObject *object, guint prop_id,
|
||||
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip6_address_dup, (GDestroyNotify) nm_ip6_address_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip_address_dup, (GDestroyNotify) nm_ip_address_unref));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip6_route_dup, (GDestroyNotify) nm_ip6_route_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip_route_dup, (GDestroyNotify) nm_ip_route_unref));
|
||||
break;
|
||||
case PROP_IGNORE_AUTO_ROUTES:
|
||||
g_value_set_boolean (value, priv->ignore_auto_routes);
|
||||
@@ -1139,7 +1136,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
|
||||
* be used with the 'shared' or 'link-local' methods as the interface is
|
||||
* automatically assigned an address with these methods.
|
||||
*
|
||||
* Element-Type: NMIP6Address
|
||||
* Element-Type: NMIPAddress
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ADDRESSES,
|
||||
@@ -1160,7 +1157,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
|
||||
* to those returned by automatic configuration. Routes cannot be used with
|
||||
* the 'shared' or 'link-local' methods because there is no upstream network.
|
||||
*
|
||||
* Element-Type: NMIP6Route
|
||||
* Element-Type: NMIPRoute
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ROUTES,
|
||||
@@ -1259,472 +1256,3 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
struct NMIP6Address {
|
||||
guint32 refcount;
|
||||
struct in6_addr address;
|
||||
guint32 prefix;
|
||||
struct in6_addr gateway;
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip6_address_new:
|
||||
*
|
||||
* Creates and returns a new #NMIP6Address object.
|
||||
*
|
||||
* Returns: (transfer full): the new empty #NMIP6Address object
|
||||
**/
|
||||
NMIP6Address *
|
||||
nm_ip6_address_new (void)
|
||||
{
|
||||
NMIP6Address *address;
|
||||
|
||||
address = g_malloc0 (sizeof (NMIP6Address));
|
||||
address->refcount = 1;
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_dup:
|
||||
* @source: the #NMIP6Address object to copy
|
||||
*
|
||||
* Copies a given #NMIP6Address object and returns the copy.
|
||||
*
|
||||
* Returns: (transfer full): the copy of the given #NMIP6Address copy
|
||||
**/
|
||||
NMIP6Address *
|
||||
nm_ip6_address_dup (NMIP6Address *source)
|
||||
{
|
||||
NMIP6Address *address;
|
||||
|
||||
g_return_val_if_fail (source != NULL, NULL);
|
||||
g_return_val_if_fail (source->refcount > 0, NULL);
|
||||
|
||||
address = nm_ip6_address_new ();
|
||||
address->prefix = source->prefix;
|
||||
memcpy (&address->address, &source->address, sizeof (struct in6_addr));
|
||||
memcpy (&address->gateway, &source->gateway, sizeof (struct in6_addr));
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_ref:
|
||||
* @address: the #NMIP6Address
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip6_address_ref (NMIP6Address *address)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
|
||||
address->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_unref:
|
||||
* @address: the #NMIP6Address
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
void
|
||||
nm_ip6_address_unref (NMIP6Address *address)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
|
||||
address->refcount--;
|
||||
if (address->refcount == 0) {
|
||||
memset (address, 0, sizeof (NMIP6Address));
|
||||
g_free (address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_compare:
|
||||
* @address: the #NMIP6Address
|
||||
* @other: the #NMIP6Address to compare @address to.
|
||||
*
|
||||
* Determines if two #NMIP6Address objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
gboolean
|
||||
nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *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 ( memcmp (&address->address, &other->address, sizeof (struct in6_addr))
|
||||
|| address->prefix != other->prefix
|
||||
|| memcmp (&address->gateway, &other->gateway, sizeof (struct in6_addr)))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_get_address:
|
||||
* @address: the #NMIP6Address
|
||||
*
|
||||
* Gets the IPv6 address property of this address object.
|
||||
*
|
||||
* Returns: (array fixed-size=16) (element-type guint8) (transfer none):
|
||||
* the IPv6 address
|
||||
**/
|
||||
const struct in6_addr *
|
||||
nm_ip6_address_get_address (NMIP6Address *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address->refcount > 0, NULL);
|
||||
|
||||
return &address->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_set_address:
|
||||
* @address: the #NMIP6Address
|
||||
* @addr: the IPv6 address
|
||||
*
|
||||
* Sets the IPv6 address property of this object.
|
||||
**/
|
||||
void
|
||||
nm_ip6_address_set_address (NMIP6Address *address, const struct in6_addr *addr)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
g_return_if_fail (addr != NULL);
|
||||
|
||||
memcpy (&address->address, addr, sizeof (struct in6_addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_get_prefix:
|
||||
* @address: the #NMIP6Address
|
||||
*
|
||||
* Gets the IPv6 address prefix property of this address object.
|
||||
*
|
||||
* Returns: the IPv6 address prefix
|
||||
**/
|
||||
guint32
|
||||
nm_ip6_address_get_prefix (NMIP6Address *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, 0);
|
||||
g_return_val_if_fail (address->refcount > 0, 0);
|
||||
|
||||
return address->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_set_prefix:
|
||||
* @address: the #NMIP6Address
|
||||
* @prefix: the address prefix, a number between 0 and 128 inclusive
|
||||
*
|
||||
* Sets the IPv6 address prefix.
|
||||
**/
|
||||
void
|
||||
nm_ip6_address_set_prefix (NMIP6Address *address, guint32 prefix)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
g_return_if_fail (prefix <= 128);
|
||||
g_return_if_fail (prefix > 0);
|
||||
|
||||
address->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_get_gateway:
|
||||
* @address: the #NMIP6Address
|
||||
*
|
||||
* Gets the IPv6 default gateway property of this address object.
|
||||
*
|
||||
* Returns: (array fixed-size=16) (element-type guint8) (transfer none):
|
||||
* the IPv6 gateway address
|
||||
**/
|
||||
const struct in6_addr *
|
||||
nm_ip6_address_get_gateway (NMIP6Address *address)
|
||||
{
|
||||
g_return_val_if_fail (address != NULL, NULL);
|
||||
g_return_val_if_fail (address->refcount > 0, NULL);
|
||||
|
||||
return &address->gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_address_set_gateway:
|
||||
* @address: the #NMIP6Address
|
||||
* @gateway: the IPv6 default gateway
|
||||
*
|
||||
* Sets the IPv6 default gateway property of this address object.
|
||||
**/
|
||||
void
|
||||
nm_ip6_address_set_gateway (NMIP6Address *address, const struct in6_addr *gateway)
|
||||
{
|
||||
g_return_if_fail (address != NULL);
|
||||
g_return_if_fail (address->refcount > 0);
|
||||
g_return_if_fail (gateway != NULL);
|
||||
|
||||
memcpy (&address->gateway, gateway, sizeof (struct in6_addr));
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
struct NMIP6Route {
|
||||
guint32 refcount;
|
||||
|
||||
struct in6_addr dest;
|
||||
guint32 prefix;
|
||||
struct in6_addr next_hop;
|
||||
guint32 metric; /* lower metric == more preferred */
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip6_route_new:
|
||||
*
|
||||
* Creates and returns a new #NMIP6Route object.
|
||||
*
|
||||
* Returns: (transfer full): the new empty #NMIP6Route object
|
||||
**/
|
||||
NMIP6Route *
|
||||
nm_ip6_route_new (void)
|
||||
{
|
||||
NMIP6Route *route;
|
||||
|
||||
route = g_malloc0 (sizeof (NMIP6Route));
|
||||
route->refcount = 1;
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_dup:
|
||||
* @source: the #NMIP6Route object to copy
|
||||
*
|
||||
* Copies a given #NMIP6Route object and returns the copy.
|
||||
*
|
||||
* Returns: (transfer full): the copy of the given #NMIP6Route copy
|
||||
**/
|
||||
NMIP6Route *
|
||||
nm_ip6_route_dup (NMIP6Route *source)
|
||||
{
|
||||
NMIP6Route *route;
|
||||
|
||||
g_return_val_if_fail (source != NULL, NULL);
|
||||
g_return_val_if_fail (source->refcount > 0, NULL);
|
||||
|
||||
route = nm_ip6_route_new ();
|
||||
route->prefix = source->prefix;
|
||||
route->metric = source->metric;
|
||||
memcpy (&route->dest, &source->dest, sizeof (struct in6_addr));
|
||||
memcpy (&route->next_hop, &source->next_hop, sizeof (struct in6_addr));
|
||||
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_ref:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_ref (NMIP6Route *route)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->refcount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_unref:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero, the object will be destroyed.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_unref (NMIP6Route *route)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->refcount--;
|
||||
if (route->refcount == 0) {
|
||||
memset (route, 0, sizeof (NMIP6Route));
|
||||
g_free (route);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_compare:
|
||||
* @route: the #NMIP6Route
|
||||
* @other: the #NMIP6Route to compare @route to.
|
||||
*
|
||||
* Determines if two #NMIP6Route objects contain the same values.
|
||||
*
|
||||
* Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
|
||||
**/
|
||||
gboolean
|
||||
nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *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 ( memcmp (&route->dest, &other->dest, sizeof (struct in6_addr))
|
||||
|| route->prefix != other->prefix
|
||||
|| memcmp (&route->next_hop, &other->next_hop, sizeof (struct in6_addr))
|
||||
|| route->metric != other->metric)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_get_dest:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Gets the IPv6 destination address property of this route object.
|
||||
*
|
||||
* Returns: (array fixed-size=16) (element-type guint8) (transfer none):
|
||||
* the IPv6 address of destination
|
||||
**/
|
||||
const struct in6_addr *
|
||||
nm_ip6_route_get_dest (NMIP6Route *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, NULL);
|
||||
g_return_val_if_fail (route->refcount > 0, NULL);
|
||||
|
||||
return &route->dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_set_dest:
|
||||
* @route: the #NMIP6Route
|
||||
* @dest: the destination address
|
||||
*
|
||||
* Sets the IPv6 destination address property of this route object.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_set_dest (NMIP6Route *route, const struct in6_addr *dest)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
g_return_if_fail (dest != NULL);
|
||||
|
||||
memcpy (&route->dest, dest, sizeof (struct in6_addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_get_prefix:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Gets the IPv6 prefix (ie "32" or "64" etc) of this route.
|
||||
*
|
||||
* Returns: the IPv6 prefix
|
||||
**/
|
||||
guint32
|
||||
nm_ip6_route_get_prefix (NMIP6Route *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, 0);
|
||||
g_return_val_if_fail (route->refcount > 0, 0);
|
||||
|
||||
return route->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_set_prefix:
|
||||
* @route: the #NMIP6Route
|
||||
* @prefix: the prefix, a number between 1 and 128 inclusive
|
||||
*
|
||||
* Sets the IPv6 prefix of this route.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_set_prefix (NMIP6Route *route, guint32 prefix)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
g_return_if_fail (prefix <= 128);
|
||||
g_return_if_fail (prefix > 0);
|
||||
|
||||
route->prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_get_next_hop:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Gets the IPv6 address of the next hop of this route.
|
||||
*
|
||||
* Returns: (array fixed-size=16) (element-type guint8) (transfer none):
|
||||
* the IPv6 address of next hop
|
||||
**/
|
||||
const struct in6_addr *
|
||||
nm_ip6_route_get_next_hop (NMIP6Route *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, NULL);
|
||||
g_return_val_if_fail (route->refcount > 0, NULL);
|
||||
|
||||
return &route->next_hop;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_set_next_hop:
|
||||
* @route: the #NMIP6Route
|
||||
* @next_hop: the IPv6 address of the next hop
|
||||
*
|
||||
* Sets the IPv6 address of the next hop of this route.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_set_next_hop (NMIP6Route *route, const struct in6_addr *next_hop)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
g_return_if_fail (next_hop != NULL);
|
||||
|
||||
memcpy (&route->next_hop, next_hop, sizeof (struct in6_addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_get_metric:
|
||||
* @route: the #NMIP6Route
|
||||
*
|
||||
* Gets the route metric property of this route object; lower values indicate
|
||||
* "better" or more preferred routes.
|
||||
*
|
||||
* Returns: the route metric
|
||||
**/
|
||||
guint32
|
||||
nm_ip6_route_get_metric (NMIP6Route *route)
|
||||
{
|
||||
g_return_val_if_fail (route != NULL, 0);
|
||||
g_return_val_if_fail (route->refcount > 0, 0);
|
||||
|
||||
return route->metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_route_set_metric:
|
||||
* @route: the #NMIP6Route
|
||||
* @metric: the route metric
|
||||
*
|
||||
* Sets the route metric property of this route object; lower values indicate
|
||||
* "better" or more preferred routes.
|
||||
**/
|
||||
void
|
||||
nm_ip6_route_set_metric (NMIP6Route *route, guint32 metric)
|
||||
{
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (route->refcount > 0);
|
||||
|
||||
route->metric = metric;
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "nm-setting.h"
|
||||
#include "nm-setting-ip-config.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -127,57 +128,6 @@ typedef enum {
|
||||
NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR = 2
|
||||
} NMSettingIP6ConfigPrivacy;
|
||||
|
||||
|
||||
typedef struct NMIP6Address NMIP6Address;
|
||||
|
||||
GType nm_ip6_address_get_type (void);
|
||||
|
||||
NMIP6Address * nm_ip6_address_new (void);
|
||||
NMIP6Address * nm_ip6_address_dup (NMIP6Address *source);
|
||||
void nm_ip6_address_ref (NMIP6Address *address);
|
||||
void nm_ip6_address_unref (NMIP6Address *address);
|
||||
/* Return TRUE if addresses are identical */
|
||||
gboolean nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other);
|
||||
|
||||
const struct in6_addr *nm_ip6_address_get_address (NMIP6Address *address);
|
||||
void nm_ip6_address_set_address (NMIP6Address *address,
|
||||
const struct in6_addr *addr);
|
||||
|
||||
guint32 nm_ip6_address_get_prefix (NMIP6Address *address);
|
||||
void nm_ip6_address_set_prefix (NMIP6Address *address,
|
||||
guint32 prefix);
|
||||
|
||||
const struct in6_addr *nm_ip6_address_get_gateway (NMIP6Address *address);
|
||||
void nm_ip6_address_set_gateway (NMIP6Address *address,
|
||||
const struct in6_addr *gateway);
|
||||
|
||||
typedef struct NMIP6Route NMIP6Route;
|
||||
|
||||
GType nm_ip6_route_get_type (void);
|
||||
|
||||
NMIP6Route * nm_ip6_route_new (void);
|
||||
NMIP6Route * nm_ip6_route_dup (NMIP6Route *source);
|
||||
void nm_ip6_route_ref (NMIP6Route *route);
|
||||
void nm_ip6_route_unref (NMIP6Route *route);
|
||||
/* Return TRUE if routes are identical */
|
||||
gboolean nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other);
|
||||
|
||||
const struct in6_addr *nm_ip6_route_get_dest (NMIP6Route *route);
|
||||
void nm_ip6_route_set_dest (NMIP6Route *route,
|
||||
const struct in6_addr *dest);
|
||||
|
||||
guint32 nm_ip6_route_get_prefix (NMIP6Route *route);
|
||||
void nm_ip6_route_set_prefix (NMIP6Route *route,
|
||||
guint32 prefix);
|
||||
|
||||
const struct in6_addr *nm_ip6_route_get_next_hop (NMIP6Route *route);
|
||||
void nm_ip6_route_set_next_hop (NMIP6Route *route,
|
||||
const struct in6_addr *next_hop);
|
||||
|
||||
guint32 nm_ip6_route_get_metric (NMIP6Route *route);
|
||||
void nm_ip6_route_set_metric (NMIP6Route *route,
|
||||
guint32 metric);
|
||||
|
||||
struct _NMSettingIP6Config {
|
||||
NMSetting parent;
|
||||
};
|
||||
@@ -209,17 +159,17 @@ gboolean nm_setting_ip6_config_remove_dns_search_by_value (NMSetti
|
||||
void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting);
|
||||
|
||||
guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting);
|
||||
NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address);
|
||||
NMIPAddress * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIPAddress *address);
|
||||
void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, NMIP6Address *address);
|
||||
gboolean nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, NMIPAddress *address);
|
||||
void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting);
|
||||
|
||||
guint32 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting);
|
||||
NMIP6Route * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIP6Route *route);
|
||||
NMIPRoute * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIPRoute *route);
|
||||
void nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i);
|
||||
gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, NMIP6Route *route);
|
||||
gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, NMIPRoute *route);
|
||||
void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting);
|
||||
gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting);
|
||||
|
||||
|
@@ -40,29 +40,12 @@ GVariant * _nm_utils_bytes_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_bytes_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
|
||||
GVariant * _nm_utils_ip4_dns_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip4_dns_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
GVariant * _nm_utils_ip4_addresses_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip4_addresses_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
GVariant * _nm_utils_ip4_routes_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip4_routes_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
|
||||
GVariant * _nm_utils_ip6_dns_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip6_dns_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
GVariant * _nm_utils_ip6_addresses_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip6_addresses_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
GVariant * _nm_utils_ip6_routes_to_dbus (const GValue *prop_value);
|
||||
void _nm_utils_ip6_routes_from_dbus (GVariant *dbus_value,
|
||||
GValue *prop_value);
|
||||
|
||||
GSList * _nm_utils_strv_to_slist (char **strv);
|
||||
char ** _nm_utils_slist_to_strv (GSList *slist);
|
||||
|
||||
GPtrArray * _nm_utils_strv_to_ptrarray (char **strv);
|
||||
char ** _nm_utils_ptrarray_to_strv (GPtrArray *ptrarray);
|
||||
|
||||
char ** _nm_utils_strsplit_set (const char *str,
|
||||
const char *delimiters,
|
||||
int max_tokens);
|
||||
|
@@ -662,7 +662,7 @@ _nm_utils_slist_to_strv (GSList *slist)
|
||||
{
|
||||
GSList *iter;
|
||||
char **strv;
|
||||
int len, i = 0;
|
||||
int len, i;
|
||||
|
||||
len = g_slist_length (slist);
|
||||
strv = g_new (char *, len + 1);
|
||||
@@ -674,6 +674,40 @@ _nm_utils_slist_to_strv (GSList *slist)
|
||||
return strv;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
_nm_utils_strv_to_ptrarray (char **strv)
|
||||
{
|
||||
GPtrArray *ptrarray;
|
||||
int i;
|
||||
|
||||
ptrarray = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
if (strv) {
|
||||
for (i = 0; strv[i]; i++)
|
||||
g_ptr_array_add (ptrarray, g_strdup (strv[i]));
|
||||
}
|
||||
|
||||
return ptrarray;
|
||||
}
|
||||
|
||||
char **
|
||||
_nm_utils_ptrarray_to_strv (GPtrArray *ptrarray)
|
||||
{
|
||||
char **strv;
|
||||
int i;
|
||||
|
||||
if (!ptrarray)
|
||||
return g_new0 (char *, 1);
|
||||
|
||||
strv = g_new (char *, ptrarray->len + 1);
|
||||
|
||||
for (i = 0; i < ptrarray->len; i++)
|
||||
strv[i] = g_strdup (ptrarray->pdata[i]);
|
||||
strv[i] = NULL;
|
||||
|
||||
return strv;
|
||||
}
|
||||
|
||||
/**
|
||||
* _nm_utils_strsplit_set:
|
||||
* @str: string to split
|
||||
@@ -1100,11 +1134,12 @@ nm_utils_ip4_dns_from_variant (GVariant *value)
|
||||
|
||||
/**
|
||||
* nm_utils_ip4_addresses_to_variant:
|
||||
* @addresses: (element-type NMIP4Address): an array of #NMIP4Address objects
|
||||
* @addresses: (element-type NMIPAddress): an array of #NMIPAddress objects
|
||||
*
|
||||
* Utility function to convert a #GPtrArray of #NMIP4Address objects into a
|
||||
* #GVariant of type 'aau' representing an array of NetworkManager IPv4
|
||||
* addresses (which are tuples of address, prefix, and gateway).
|
||||
* Utility function to convert a #GPtrArray of #NMIPAddress objects representing
|
||||
* IPv4 addresses into a #GVariant of type 'aau' representing an array of
|
||||
* NetworkManager IPv4 addresses (which are tuples of address, prefix, and
|
||||
* gateway).
|
||||
*
|
||||
* Returns: (transfer none): a new floating #GVariant representing @addresses.
|
||||
**/
|
||||
@@ -1118,12 +1153,18 @@ nm_utils_ip4_addresses_to_variant (GPtrArray *addresses)
|
||||
|
||||
if (addresses) {
|
||||
for (i = 0; i < addresses->len; i++) {
|
||||
NMIP4Address *addr = addresses->pdata[i];
|
||||
NMIPAddress *addr = addresses->pdata[i];
|
||||
guint32 array[3];
|
||||
|
||||
array[0] = nm_ip4_address_get_address (addr);
|
||||
array[1] = nm_ip4_address_get_prefix (addr);
|
||||
array[2] = nm_ip4_address_get_gateway (addr);
|
||||
if (nm_ip_address_get_family (addr) != AF_INET)
|
||||
continue;
|
||||
|
||||
nm_ip_address_get_address_binary (addr, &array[0]);
|
||||
array[1] = nm_ip_address_get_prefix (addr);
|
||||
if (nm_ip_address_get_gateway (addr))
|
||||
inet_pton (AF_INET, nm_ip_address_get_gateway (addr), &array[2]);
|
||||
else
|
||||
array[2] = 0;
|
||||
|
||||
g_variant_builder_add (&builder, "@au",
|
||||
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
|
||||
@@ -1140,10 +1181,10 @@ nm_utils_ip4_addresses_to_variant (GPtrArray *addresses)
|
||||
*
|
||||
* Utility function to convert a #GVariant of type 'aau' representing a list of
|
||||
* NetworkManager IPv4 addresses (which are tuples of address, prefix, and
|
||||
* gateway) into a #GPtrArray of #NMIP4Address objects.
|
||||
* gateway) into a #GPtrArray of #NMIPAddress objects.
|
||||
*
|
||||
* Returns: (transfer full) (element-type NMIP4Address): a newly allocated
|
||||
* #GPtrArray of #NMIP4Address objects
|
||||
* Returns: (transfer full) (element-type NMIPAddress): a newly allocated
|
||||
* #GPtrArray of #NMIPAddress objects
|
||||
**/
|
||||
GPtrArray *
|
||||
nm_utils_ip4_addresses_from_variant (GVariant *value)
|
||||
@@ -1155,12 +1196,13 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
|
||||
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aau")), NULL);
|
||||
|
||||
g_variant_iter_init (&iter, value);
|
||||
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref);
|
||||
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
||||
|
||||
while (g_variant_iter_next (&iter, "@au", &addr_var)) {
|
||||
const guint32 *addr_array;
|
||||
gsize length;
|
||||
NMIP4Address *addr;
|
||||
NMIPAddress *addr;
|
||||
GError *error = NULL;
|
||||
|
||||
addr_array = g_variant_get_fixed_array (addr_var, &length, sizeof (guint32));
|
||||
if (length < 3) {
|
||||
@@ -1169,12 +1211,15 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
|
||||
continue;
|
||||
}
|
||||
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, addr_array[0]);
|
||||
nm_ip4_address_set_prefix (addr, addr_array[1]);
|
||||
nm_ip4_address_set_gateway (addr, addr_array[2]);
|
||||
|
||||
g_ptr_array_add (addresses, addr);
|
||||
addr = nm_ip_address_new_binary (AF_INET,
|
||||
&addr_array[0], addr_array[1], &addr_array[2],
|
||||
&error);
|
||||
if (addr)
|
||||
g_ptr_array_add (addresses, addr);
|
||||
else {
|
||||
g_warning ("Ignoring invalid IP4 address: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_variant_unref (addr_var);
|
||||
}
|
||||
|
||||
@@ -1183,11 +1228,12 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
|
||||
|
||||
/**
|
||||
* nm_utils_ip4_routes_to_variant:
|
||||
* @routes: (element-type NMIP4Route): an array of #NMIP4Route objects
|
||||
* @routes: (element-type NMIPRoute): an array of #NMIP4Route objects
|
||||
*
|
||||
* Utility function to convert a #GPtrArray of #NMIP4Route objects into a
|
||||
* #GVariant of type 'aau' representing an array of NetworkManager IPv4 routes
|
||||
* (which are tuples of route, prefix, next hop, and metric).
|
||||
* Utility function to convert a #GPtrArray of #NMIPRoute objects representing
|
||||
* IPv4 routes into a #GVariant of type 'aau' representing an array of
|
||||
* NetworkManager IPv4 routes (which are tuples of route, prefix, next hop, and
|
||||
* metric).
|
||||
*
|
||||
* Returns: (transfer none): a new floating #GVariant representing @routes.
|
||||
**/
|
||||
@@ -1201,13 +1247,16 @@ nm_utils_ip4_routes_to_variant (GPtrArray *routes)
|
||||
|
||||
if (routes) {
|
||||
for (i = 0; i < routes->len; i++) {
|
||||
NMIP4Route *route = routes->pdata[i];
|
||||
NMIPRoute *route = routes->pdata[i];
|
||||
guint32 array[4];
|
||||
|
||||
array[0] = nm_ip4_route_get_dest (route);
|
||||
array[1] = nm_ip4_route_get_prefix (route);
|
||||
array[2] = nm_ip4_route_get_next_hop (route);
|
||||
array[3] = nm_ip4_route_get_metric (route);
|
||||
if (nm_ip_route_get_family (route) != AF_INET)
|
||||
continue;
|
||||
|
||||
nm_ip_route_get_dest_binary (route, &array[0]);
|
||||
array[1] = nm_ip_route_get_prefix (route);
|
||||
nm_ip_route_get_next_hop_binary (route, &array[2]);
|
||||
array[3] = nm_ip_route_get_metric (route);
|
||||
|
||||
g_variant_builder_add (&builder, "@au",
|
||||
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
|
||||
@@ -1224,10 +1273,10 @@ nm_utils_ip4_routes_to_variant (GPtrArray *routes)
|
||||
*
|
||||
* Utility function to convert a #GVariant of type 'aau' representing an array
|
||||
* of NetworkManager IPv4 routes (which are tuples of route, prefix, next hop,
|
||||
* and metric) into a #GPtrArray of #NMIP4Route objects.
|
||||
* and metric) into a #GPtrArray of #NMIPRoute objects.
|
||||
*
|
||||
* Returns: (transfer full) (element-type NMIP4Route): a newly allocated
|
||||
* #GPtrArray of #NMIP4Route objects
|
||||
* Returns: (transfer full) (element-type NMIPRoute): a newly allocated
|
||||
* #GPtrArray of #NMIPRoute objects
|
||||
**/
|
||||
GPtrArray *
|
||||
nm_utils_ip4_routes_from_variant (GVariant *value)
|
||||
@@ -1239,12 +1288,13 @@ nm_utils_ip4_routes_from_variant (GVariant *value)
|
||||
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aau")), NULL);
|
||||
|
||||
g_variant_iter_init (&iter, value);
|
||||
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
|
||||
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
||||
|
||||
while (g_variant_iter_next (&iter, "@au", &route_var)) {
|
||||
const guint32 *route_array;
|
||||
gsize length;
|
||||
NMIP4Route *route;
|
||||
NMIPRoute *route;
|
||||
GError *error = NULL;
|
||||
|
||||
route_array = g_variant_get_fixed_array (route_var, &length, sizeof (guint32));
|
||||
if (length < 4) {
|
||||
@@ -1253,13 +1303,16 @@ nm_utils_ip4_routes_from_variant (GVariant *value)
|
||||
continue;
|
||||
}
|
||||
|
||||
route = nm_ip4_route_new ();
|
||||
nm_ip4_route_set_dest (route, route_array[0]);
|
||||
nm_ip4_route_set_prefix (route, route_array[1]);
|
||||
nm_ip4_route_set_next_hop (route, route_array[2]);
|
||||
nm_ip4_route_set_metric (route, route_array[3]);
|
||||
|
||||
g_ptr_array_add (routes, route);
|
||||
route = nm_ip_route_new_binary (AF_INET,
|
||||
&route_array[0], route_array[1],
|
||||
&route_array[2], route_array[3],
|
||||
&error);
|
||||
if (route)
|
||||
g_ptr_array_add (routes, route);
|
||||
else {
|
||||
g_warning ("Ignoring invalid IP4 route: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_variant_unref (route_var);
|
||||
}
|
||||
|
||||
@@ -1412,11 +1465,12 @@ nm_utils_ip6_dns_from_variant (GVariant *value)
|
||||
|
||||
/**
|
||||
* nm_utils_ip6_addresses_to_variant:
|
||||
* @addresses: (element-type NMIP6Address): an array of #NMIP6Address objects
|
||||
* @addresses: (element-type NMIPAddress): an array of #NMIPAddress objects
|
||||
*
|
||||
* Utility function to convert a #GPtrArray of #NMIP6Address objects into a
|
||||
* #GVariant of type 'a(ayuay)' representing an array of NetworkManager IPv6
|
||||
* addresses (which are tuples of address, prefix, and gateway).
|
||||
* Utility function to convert a #GPtrArray of #NMIPAddress objects representing
|
||||
* IPv6 addresses into a #GVariant of type 'a(ayuay)' representing an array of
|
||||
* NetworkManager IPv6 addresses (which are tuples of address, prefix, and
|
||||
* gateway).
|
||||
*
|
||||
* Returns: (transfer none): a new floating #GVariant representing @addresses.
|
||||
**/
|
||||
@@ -1430,17 +1484,24 @@ nm_utils_ip6_addresses_to_variant (GPtrArray *addresses)
|
||||
|
||||
if (addresses) {
|
||||
for (i = 0; i < addresses->len; i++) {
|
||||
NMIP6Address *addr = addresses->pdata[i];
|
||||
NMIPAddress *addr = addresses->pdata[i];
|
||||
struct in6_addr ip_bytes, gateway_bytes;
|
||||
GVariant *ip, *gateway;
|
||||
guint32 prefix;
|
||||
|
||||
ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
nm_ip6_address_get_address (addr),
|
||||
16, 1);
|
||||
prefix = nm_ip6_address_get_prefix (addr);
|
||||
gateway = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
nm_ip6_address_get_gateway (addr),
|
||||
16, 1);
|
||||
if (nm_ip_address_get_family (addr) != AF_INET6)
|
||||
continue;
|
||||
|
||||
nm_ip_address_get_address_binary (addr, &ip_bytes);
|
||||
ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &ip_bytes, 16, 1);
|
||||
|
||||
prefix = nm_ip_address_get_prefix (addr);
|
||||
|
||||
if (nm_ip_address_get_gateway (addr))
|
||||
inet_pton (AF_INET6, nm_ip_address_get_gateway (addr), &gateway_bytes);
|
||||
else
|
||||
memset (&gateway_bytes, 0, sizeof (gateway_bytes));
|
||||
gateway = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &gateway_bytes, 16, 1);
|
||||
|
||||
g_variant_builder_add (&builder, "(@ayu@ay)", ip, prefix, gateway);
|
||||
}
|
||||
@@ -1455,10 +1516,10 @@ nm_utils_ip6_addresses_to_variant (GPtrArray *addresses)
|
||||
*
|
||||
* Utility function to convert a #GVariant of type 'a(ayuay)' representing a
|
||||
* list of NetworkManager IPv6 addresses (which are tuples of address, prefix,
|
||||
* and gateway) into a #GPtrArray of #NMIP6Address objects.
|
||||
* and gateway) into a #GPtrArray of #NMIPAddress objects.
|
||||
*
|
||||
* Returns: (transfer full) (element-type NMIP6Address): a newly allocated
|
||||
* #GPtrArray of #NMIP6Address objects
|
||||
* Returns: (transfer full) (element-type NMIPAddress): a newly allocated
|
||||
* #GPtrArray of #NMIPAddress objects
|
||||
**/
|
||||
GPtrArray *
|
||||
nm_utils_ip6_addresses_from_variant (GVariant *value)
|
||||
@@ -1471,12 +1532,13 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
|
||||
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("a(ayuay)")), NULL);
|
||||
|
||||
g_variant_iter_init (&iter, value);
|
||||
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_address_unref);
|
||||
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
||||
|
||||
while (g_variant_iter_next (&iter, "(@ayu@ay)", &addr_var, &prefix, &gateway_var)) {
|
||||
NMIP6Address *addr;
|
||||
NMIPAddress *addr;
|
||||
const struct in6_addr *addr_bytes, *gateway_bytes;
|
||||
gsize addr_len, gateway_len;
|
||||
GError *error = NULL;
|
||||
|
||||
if ( !g_variant_is_of_type (addr_var, G_VARIANT_TYPE_BYTESTRING)
|
||||
|| !g_variant_is_of_type (gateway_var, G_VARIANT_TYPE_BYTESTRING)) {
|
||||
@@ -1490,11 +1552,6 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
|
||||
__func__, (int) addr_len);
|
||||
goto next;
|
||||
}
|
||||
if (prefix > 128) {
|
||||
g_warning ("%s: ignoring invalid IP6 prefix %d",
|
||||
__func__, prefix);
|
||||
goto next;
|
||||
}
|
||||
gateway_bytes = g_variant_get_fixed_array (gateway_var, &gateway_len, 1);
|
||||
if (gateway_len != 16) {
|
||||
g_warning ("%s: ignoring invalid IP6 address of length %d",
|
||||
@@ -1502,11 +1559,13 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
|
||||
goto next;
|
||||
}
|
||||
|
||||
addr = nm_ip6_address_new ();
|
||||
nm_ip6_address_set_address (addr, addr_bytes);
|
||||
nm_ip6_address_set_prefix (addr, prefix);
|
||||
nm_ip6_address_set_gateway (addr, gateway_bytes);
|
||||
g_ptr_array_add (addresses, addr);
|
||||
addr = nm_ip_address_new_binary (AF_INET6, addr_bytes, prefix, gateway_bytes, &error);
|
||||
if (addr)
|
||||
g_ptr_array_add (addresses, addr);
|
||||
else {
|
||||
g_warning ("Ignoring invalid IP4 address: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
next:
|
||||
g_variant_unref (addr_var);
|
||||
@@ -1518,11 +1577,12 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
|
||||
|
||||
/**
|
||||
* nm_utils_ip6_routes_to_variant:
|
||||
* @routes: (element-type NMIP6Route): an array of #NMIP6Route objects
|
||||
* @routes: (element-type NMIPRoute): an array of #NMIPRoute objects
|
||||
*
|
||||
* Utility function to convert a #GPtrArray of #NMIP6Route objects into a
|
||||
* #GVariant of type 'a(ayuayu)' representing an array of NetworkManager IPv6
|
||||
* routes (which are tuples of route, prefix, next hop, and metric).
|
||||
* Utility function to convert a #GPtrArray of #NMIPRoute objects representing
|
||||
* IPv6 routes into a #GVariant of type 'a(ayuayu)' representing an array of
|
||||
* NetworkManager IPv6 routes (which are tuples of route, prefix, next hop, and
|
||||
* metric).
|
||||
*
|
||||
* Returns: (transfer none): a new floating #GVariant representing @routes.
|
||||
**/
|
||||
@@ -1536,18 +1596,20 @@ nm_utils_ip6_routes_to_variant (GPtrArray *routes)
|
||||
|
||||
if (routes) {
|
||||
for (i = 0; i < routes->len; i++) {
|
||||
NMIP6Route *route = routes->pdata[i];
|
||||
NMIPRoute *route = routes->pdata[i];
|
||||
struct in6_addr dest_bytes, next_hop_bytes;
|
||||
GVariant *dest, *next_hop;
|
||||
guint32 prefix, metric;
|
||||
|
||||
dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
nm_ip6_route_get_dest (route),
|
||||
16, 1);
|
||||
prefix = nm_ip6_route_get_prefix (route);
|
||||
next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
nm_ip6_route_get_next_hop (route),
|
||||
16, 1);
|
||||
metric = nm_ip6_route_get_metric (route);
|
||||
if (nm_ip_route_get_family (route) != AF_INET6)
|
||||
continue;
|
||||
|
||||
nm_ip_route_get_dest_binary (route, &dest_bytes);
|
||||
dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &dest_bytes, 16, 1);
|
||||
prefix = nm_ip_route_get_prefix (route);
|
||||
nm_ip_route_get_next_hop_binary (route, &next_hop_bytes);
|
||||
next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &next_hop_bytes, 16, 1);
|
||||
metric = nm_ip_route_get_metric (route);
|
||||
|
||||
g_variant_builder_add (&builder, "(@ayu@ayu)", dest, prefix, next_hop, metric);
|
||||
}
|
||||
@@ -1562,10 +1624,10 @@ nm_utils_ip6_routes_to_variant (GPtrArray *routes)
|
||||
*
|
||||
* Utility function to convert a #GVariant of type 'a(ayuayu)' representing an
|
||||
* array of NetworkManager IPv6 routes (which are tuples of route, prefix, next
|
||||
* hop, and metric) into a #GPtrArray of #NMIP6Route objects.
|
||||
* hop, and metric) into a #GPtrArray of #NMIPRoute objects.
|
||||
*
|
||||
* Returns: (transfer full) (element-type NMIP6Route): a newly allocated
|
||||
* #GPtrArray of #NMIP6Route objects
|
||||
* Returns: (transfer full) (element-type NMIPRoute): a newly allocated
|
||||
* #GPtrArray of #NMIPRoute objects
|
||||
**/
|
||||
GPtrArray *
|
||||
nm_utils_ip6_routes_from_variant (GVariant *value)
|
||||
@@ -1579,11 +1641,12 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
|
||||
|
||||
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("a(ayuayu)")), NULL);
|
||||
|
||||
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
|
||||
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
||||
|
||||
g_variant_iter_init (&iter, value);
|
||||
while (g_variant_iter_next (&iter, "(@ayu@ayu)", &dest_var, &prefix, &next_hop_var, &metric)) {
|
||||
NMIP6Route *route;
|
||||
NMIPRoute *route;
|
||||
GError *error = NULL;
|
||||
|
||||
if ( !g_variant_is_of_type (dest_var, G_VARIANT_TYPE_BYTESTRING)
|
||||
|| !g_variant_is_of_type (next_hop_var, G_VARIANT_TYPE_BYTESTRING)) {
|
||||
@@ -1597,6 +1660,7 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
|
||||
__func__, (int) dest_len);
|
||||
goto next;
|
||||
}
|
||||
|
||||
next_hop = g_variant_get_fixed_array (next_hop_var, &next_hop_len, 1);
|
||||
if (next_hop_len != 16) {
|
||||
g_warning ("%s: ignoring invalid IP6 address of length %d",
|
||||
@@ -1604,12 +1668,13 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
|
||||
goto next;
|
||||
}
|
||||
|
||||
route = nm_ip6_route_new ();
|
||||
nm_ip6_route_set_dest (route, dest);
|
||||
nm_ip6_route_set_prefix (route, prefix);
|
||||
nm_ip6_route_set_next_hop (route, next_hop);
|
||||
nm_ip6_route_set_metric (route, metric);
|
||||
g_ptr_array_add (routes, route);
|
||||
route = nm_ip_route_new_binary (AF_INET6, dest, prefix, next_hop, metric, &error);
|
||||
if (route)
|
||||
g_ptr_array_add (routes, route);
|
||||
else {
|
||||
g_warning ("Ignoring invalid IP6 route: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
next:
|
||||
g_variant_unref (dest_var);
|
||||
@@ -2750,6 +2815,28 @@ nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
|
||||
INET6_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_ipaddr_valid:
|
||||
* @family: %AF_INET or %AF_INET6, or %AF_UNSPEC to accept either
|
||||
* @ip: an IP address
|
||||
*
|
||||
* Checks if @ip contains a valid IP address of the given family.
|
||||
*
|
||||
* Return value: %TRUE or %FALSE
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_ipaddr_valid (int family, const char *ip)
|
||||
{
|
||||
guint8 buf[sizeof (struct in6_addr)];
|
||||
|
||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC, FALSE);
|
||||
|
||||
if (family == AF_UNSPEC)
|
||||
family = strchr (ip, ':') ? AF_INET6 : AF_INET;
|
||||
|
||||
return inet_pton (family, ip, buf) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_check_virtual_device_compatibility:
|
||||
* @virtual_type: a virtual connection type
|
||||
@@ -2809,5 +2896,3 @@ nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_typ
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -174,6 +174,8 @@ gboolean nm_utils_is_uuid (const char *str);
|
||||
const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst);
|
||||
const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst);
|
||||
|
||||
gboolean nm_utils_ipaddr_valid (int family, const char *ip);
|
||||
|
||||
gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type);
|
||||
|
||||
G_END_DECLS
|
||||
|
@@ -324,7 +324,7 @@ static void
|
||||
test_setting_ip4_config_labels (void)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMIP4Address *addr;
|
||||
NMIPAddress *addr;
|
||||
const char *label;
|
||||
GPtrArray *addrs;
|
||||
char **labels;
|
||||
@@ -336,12 +336,11 @@ test_setting_ip4_config_labels (void)
|
||||
NULL);
|
||||
|
||||
/* addr 1 */
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, 0x01010101);
|
||||
nm_ip4_address_set_prefix (addr, 24);
|
||||
addr = nm_ip_address_new (AF_INET, "1.1.1.1", 24, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
nm_setting_ip4_config_add_address (s_ip4, addr);
|
||||
nm_ip4_address_unref (addr);
|
||||
nm_ip_address_unref (addr);
|
||||
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
@@ -349,12 +348,11 @@ test_setting_ip4_config_labels (void)
|
||||
g_assert_cmpstr (label, ==, "");
|
||||
|
||||
/* addr 2 */
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, 0x02020202);
|
||||
nm_ip4_address_set_prefix (addr, 24);
|
||||
addr = nm_ip_address_new (AF_INET, "2.2.2.2", 24, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
_nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1");
|
||||
nm_ip4_address_unref (addr);
|
||||
nm_ip_address_unref (addr);
|
||||
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
@@ -362,12 +360,11 @@ test_setting_ip4_config_labels (void)
|
||||
g_assert_cmpstr (label, ==, "eth0:1");
|
||||
|
||||
/* addr 3 */
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, 0x03030303);
|
||||
nm_ip4_address_set_prefix (addr, 24);
|
||||
addr = nm_ip_address_new (AF_INET, "3.3.3.3", 24, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
_nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "");
|
||||
nm_ip4_address_unref (addr);
|
||||
nm_ip_address_unref (addr);
|
||||
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
@@ -380,12 +377,12 @@ test_setting_ip4_config_labels (void)
|
||||
g_assert_no_error (error);
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 0);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
|
||||
g_assert_cmpstr (label, ==, "eth0:1");
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 1);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
|
||||
g_assert_cmpstr (label, ==, "");
|
||||
|
||||
@@ -409,12 +406,12 @@ test_setting_ip4_config_labels (void)
|
||||
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 0);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
|
||||
g_assert_cmpstr (label, ==, "");
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 1);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
|
||||
g_assert_cmpstr (label, ==, "");
|
||||
|
||||
@@ -428,12 +425,12 @@ test_setting_ip4_config_labels (void)
|
||||
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 0);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
|
||||
g_assert_cmpstr (label, ==, "eth0:1");
|
||||
|
||||
addr = nm_setting_ip4_config_get_address (s_ip4, 1);
|
||||
g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
|
||||
g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
|
||||
label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
|
||||
g_assert_cmpstr (label, ==, "");
|
||||
|
||||
@@ -2457,8 +2454,9 @@ test_setting_ip4_changed_signal (void)
|
||||
NMConnection *connection;
|
||||
gboolean changed = FALSE;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMIP4Address *addr;
|
||||
NMIP4Route *route;
|
||||
NMIPAddress *addr;
|
||||
NMIPRoute *route;
|
||||
GError *error = NULL;
|
||||
|
||||
connection = nm_simple_connection_new ();
|
||||
g_signal_connect (connection,
|
||||
@@ -2489,22 +2487,20 @@ test_setting_ip4_changed_signal (void)
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_clear_dns_searches (s_ip4));
|
||||
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, 0x2233);
|
||||
nm_ip4_address_set_prefix (addr, 24);
|
||||
addr = nm_ip_address_new (AF_INET, "22.33.0.0", 24, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_add_address (s_ip4, addr));
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_remove_address (s_ip4, 0));
|
||||
|
||||
g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*addr != NULL && label != NULL*");
|
||||
g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*addr != NULL*");
|
||||
ASSERT_UNCHANGED (nm_setting_ip4_config_remove_address (s_ip4, 1));
|
||||
g_test_assert_expected_messages ();
|
||||
|
||||
nm_setting_ip4_config_add_address (s_ip4, addr);
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_clear_addresses (s_ip4));
|
||||
|
||||
route = nm_ip4_route_new ();
|
||||
nm_ip4_route_set_dest (route, 0x2233);
|
||||
nm_ip4_route_set_prefix (route, 24);
|
||||
route = nm_ip_route_new (AF_INET, "22.33.0.0", 24, NULL, 0, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_add_route (s_ip4, route));
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_remove_route (s_ip4, 0));
|
||||
@@ -2516,8 +2512,8 @@ test_setting_ip4_changed_signal (void)
|
||||
nm_setting_ip4_config_add_route (s_ip4, route);
|
||||
ASSERT_CHANGED (nm_setting_ip4_config_clear_routes (s_ip4));
|
||||
|
||||
nm_ip4_address_unref (addr);
|
||||
nm_ip4_route_unref (route);
|
||||
nm_ip_address_unref (addr);
|
||||
nm_ip_route_unref (route);
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
@@ -2527,9 +2523,9 @@ test_setting_ip6_changed_signal (void)
|
||||
NMConnection *connection;
|
||||
gboolean changed = FALSE;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
NMIP6Address *addr;
|
||||
NMIP6Route *route;
|
||||
const struct in6_addr t = { { { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 } } };
|
||||
NMIPAddress *addr;
|
||||
NMIPRoute *route;
|
||||
GError *error = NULL;
|
||||
|
||||
connection = nm_simple_connection_new ();
|
||||
g_signal_connect (connection,
|
||||
@@ -2560,9 +2556,8 @@ test_setting_ip6_changed_signal (void)
|
||||
nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com");
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_clear_dns_searches (s_ip6));
|
||||
|
||||
addr = nm_ip6_address_new ();
|
||||
nm_ip6_address_set_address (addr, &t);
|
||||
nm_ip6_address_set_prefix (addr, 64);
|
||||
addr = nm_ip_address_new (AF_INET6, "1:2:3::4:5:6", 64, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_add_address (s_ip6, addr));
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_remove_address (s_ip6, 0));
|
||||
@@ -2574,9 +2569,8 @@ test_setting_ip6_changed_signal (void)
|
||||
nm_setting_ip6_config_add_address (s_ip6, addr);
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_clear_addresses (s_ip6));
|
||||
|
||||
route = nm_ip6_route_new ();
|
||||
nm_ip6_route_set_dest (route, &t);
|
||||
nm_ip6_route_set_prefix (route, 128);
|
||||
route = nm_ip_route_new (AF_INET6, "1:2:3::4:5:6", 128, NULL, 0, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_add_route (s_ip6, route));
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_remove_route (s_ip6, 0));
|
||||
@@ -2588,8 +2582,8 @@ test_setting_ip6_changed_signal (void)
|
||||
nm_setting_ip6_config_add_route (s_ip6, route);
|
||||
ASSERT_CHANGED (nm_setting_ip6_config_clear_routes (s_ip6));
|
||||
|
||||
nm_ip6_address_unref (addr);
|
||||
nm_ip6_route_unref (route);
|
||||
nm_ip_address_unref (addr);
|
||||
nm_ip_route_unref (route);
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user