2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2013-07-12 11:33:52 +02:00
|
|
|
/* NetworkManager
|
2005-04-15 15:43:42 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
2008-06-26 18:31:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-04-15 15:43:42 +00:00
|
|
|
*
|
2014-04-17 11:15:36 +02:00
|
|
|
* Copyright (C) 2005 - 2014 Red Hat, Inc.
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2006 - 2008 Novell, Inc.
|
2005-04-15 15:43:42 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-11-13 10:07:02 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2005-04-15 15:43:42 +00:00
|
|
|
#include <string.h>
|
2014-10-19 17:30:10 -04:00
|
|
|
#include <arpa/inet.h>
|
2013-07-12 11:33:52 +02:00
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
#include "nm-ip4-config.h"
|
2013-07-12 11:33:52 +02:00
|
|
|
|
2008-06-02 08:44:48 +00:00
|
|
|
#include "nm-utils.h"
|
2014-08-28 19:17:07 +02:00
|
|
|
#include "nm-platform.h"
|
2013-07-12 11:33:52 +02:00
|
|
|
#include "nm-dbus-manager.h"
|
2008-03-29 21:35:41 +00:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2013-07-12 11:33:52 +02:00
|
|
|
#include "nm-ip4-config-glue.h"
|
2013-11-19 22:28:36 -06:00
|
|
|
#include "NetworkManagerUtils.h"
|
2014-07-27 20:35:17 +02:00
|
|
|
#include "nm-core-internal.h"
|
2015-01-02 15:42:11 +01:00
|
|
|
#include "nm-route-manager.h"
|
2015-05-20 12:21:11 +02:00
|
|
|
#include "nm-core-internal.h"
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
#include "gsystem-local-alloc.h"
|
2006-01-16 22:58:13 +00:00
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2008-09-05 02:55:40 +00:00
|
|
|
char *path;
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
gboolean never_default;
|
|
|
|
|
guint32 gateway;
|
2013-06-29 13:33:36 +02:00
|
|
|
GArray *addresses;
|
2013-07-31 23:07:32 +02:00
|
|
|
GArray *routes;
|
2007-02-16 11:23:49 +00:00
|
|
|
GArray *nameservers;
|
|
|
|
|
GPtrArray *domains;
|
2008-03-09 05:11:22 +00:00
|
|
|
GPtrArray *searches;
|
2015-03-26 09:23:12 +01:00
|
|
|
GPtrArray *dns_options;
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32 mss;
|
2010-07-16 11:28:39 -07:00
|
|
|
GArray *nis;
|
2013-07-12 11:33:52 +02:00
|
|
|
char *nis_domain;
|
|
|
|
|
GArray *wins;
|
|
|
|
|
guint32 mtu;
|
2014-10-09 18:51:11 +02:00
|
|
|
NMIPConfigSource mtu_source;
|
2015-01-19 18:33:10 +01:00
|
|
|
int ifindex;
|
2015-06-04 15:57:42 +02:00
|
|
|
gint64 route_metric;
|
2015-04-30 18:11:16 +02:00
|
|
|
gboolean metered;
|
2007-02-16 11:23:49 +00:00
|
|
|
} NMIP4ConfigPrivate;
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */
|
|
|
|
|
G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32));
|
|
|
|
|
G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF);
|
2007-02-16 11:23:49 +00:00
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2015-02-20 16:31:10 -06:00
|
|
|
PROP_IFINDEX,
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
PROP_ADDRESS_DATA,
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
PROP_ADDRESSES,
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
PROP_ROUTE_DATA,
|
2013-09-06 11:56:41 +02:00
|
|
|
PROP_ROUTES,
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
PROP_GATEWAY,
|
2007-02-16 11:23:49 +00:00
|
|
|
PROP_NAMESERVERS,
|
|
|
|
|
PROP_DOMAINS,
|
2013-09-06 11:56:41 +02:00
|
|
|
PROP_SEARCHES,
|
2015-03-26 09:23:12 +01:00
|
|
|
PROP_DNS_OPTIONS,
|
2008-12-19 17:01:06 -05:00
|
|
|
PROP_WINS_SERVERS,
|
2007-02-16 11:23:49 +00:00
|
|
|
|
|
|
|
|
LAST_PROP
|
2005-04-15 15:43:42 +00:00
|
|
|
};
|
2013-09-06 11:56:41 +02:00
|
|
|
static GParamSpec *obj_properties[LAST_PROP] = { NULL, };
|
|
|
|
|
#define _NOTIFY(config, prop) G_STMT_START { g_object_notify_by_pspec (G_OBJECT (config), obj_properties[prop]); } G_STMT_END
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
NMIP4Config *
|
2015-02-20 16:31:10 -06:00
|
|
|
nm_ip4_config_new (int ifindex)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2015-02-27 16:49:42 +01:00
|
|
|
g_return_val_if_fail (ifindex >= -1, NULL);
|
2015-02-20 16:31:10 -06:00
|
|
|
return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG,
|
|
|
|
|
NM_IP4_CONFIG_IFINDEX, ifindex,
|
|
|
|
|
NULL);
|
2015-01-19 18:33:10 +01:00
|
|
|
}
|
2013-07-12 11:33:52 +02:00
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_export (NMIP4Config *config)
|
|
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2013-07-03 10:26:19 +02:00
|
|
|
static guint32 counter = 0;
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
if (!priv->path) {
|
|
|
|
|
priv->path = g_strdup_printf (NM_DBUS_PATH "/IP4Config/%d", counter++);
|
|
|
|
|
nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, config);
|
|
|
|
|
}
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_dbus_path (const NMIP4Config *config)
|
2013-07-03 10:26:19 +02:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 16:49:42 +01:00
|
|
|
int
|
|
|
|
|
nm_ip4_config_get_ifindex (const NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
return NM_IP4_CONFIG_GET_PRIVATE (config)->ifindex;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
static gboolean
|
|
|
|
|
same_prefix (guint32 address1, guint32 address2, int plen)
|
|
|
|
|
{
|
|
|
|
|
guint32 masked1 = ntohl (address1) >> (32 - plen);
|
|
|
|
|
guint32 masked2 = ntohl (address2) >> (32 - plen);
|
2013-07-03 10:26:19 +02:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return masked1 == masked2;
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-11-19 22:28:36 -06:00
|
|
|
/**
|
|
|
|
|
* nm_ip4_config_capture_resolv_conf():
|
|
|
|
|
* @nameservers: array of guint32
|
|
|
|
|
* @rc_contents: the contents of a resolv.conf or %NULL to read /etc/resolv.conf
|
|
|
|
|
*
|
2013-12-17 16:41:33 -05:00
|
|
|
* Reads all resolv.conf IPv4 nameservers and adds them to @nameservers.
|
2013-11-19 22:28:36 -06:00
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if nameservers were added, %FALSE if @nameservers is unchanged
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_ip4_config_capture_resolv_conf (GArray *nameservers,
|
2015-05-03 22:54:55 +02:00
|
|
|
GPtrArray *dns_options,
|
2013-11-19 22:28:36 -06:00
|
|
|
const char *rc_contents)
|
|
|
|
|
{
|
2015-05-03 22:54:55 +02:00
|
|
|
GPtrArray *read_ns, *read_options;
|
2013-11-19 22:28:36 -06:00
|
|
|
guint i, j;
|
|
|
|
|
gboolean changed = FALSE;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nameservers != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
read_ns = nm_utils_read_resolv_conf_nameservers (rc_contents);
|
|
|
|
|
if (!read_ns)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < read_ns->len; i++) {
|
|
|
|
|
const char *s = g_ptr_array_index (read_ns, i);
|
|
|
|
|
guint32 ns = 0;
|
|
|
|
|
|
|
|
|
|
if (!inet_pton (AF_INET, s, (void *) &ns) || !ns)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Ignore duplicates */
|
|
|
|
|
for (j = 0; j < nameservers->len; j++) {
|
|
|
|
|
if (g_array_index (nameservers, guint32, j) == ns)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (j == nameservers->len) {
|
|
|
|
|
g_array_append_val (nameservers, ns);
|
|
|
|
|
changed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_ptr_array_unref (read_ns);
|
2015-05-03 22:54:55 +02:00
|
|
|
|
|
|
|
|
if (dns_options) {
|
|
|
|
|
read_options = nm_utils_read_resolv_conf_dns_options (rc_contents);
|
|
|
|
|
if (!read_options)
|
|
|
|
|
return changed;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < read_options->len; i++) {
|
|
|
|
|
const char *s = g_ptr_array_index (read_options, i);
|
|
|
|
|
|
2015-05-20 12:31:10 +02:00
|
|
|
if (_nm_utils_dns_option_validate (s, NULL, NULL, FALSE, _nm_utils_dns_option_descs) &&
|
2015-05-03 22:54:55 +02:00
|
|
|
_nm_utils_dns_option_find_idx (dns_options, s) < 0) {
|
|
|
|
|
g_ptr_array_add (dns_options, g_strdup (s));
|
|
|
|
|
changed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_ptr_array_unref (read_options);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 22:28:36 -06:00
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
static gboolean
|
|
|
|
|
addresses_are_duplicate (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b, gboolean consider_plen)
|
|
|
|
|
{
|
|
|
|
|
return a->address == b->address && (!consider_plen || a->plen == b->plen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
routes_are_duplicate (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gboolean consider_gateway_and_metric)
|
|
|
|
|
{
|
|
|
|
|
return a->network == b->network && a->plen == b->plen &&
|
|
|
|
|
(!consider_gateway_and_metric || (a->gateway == b->gateway && a->metric == b->metric));
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 10:20:24 -04:00
|
|
|
NMIP4Config *
|
2013-11-19 22:28:36 -06:00
|
|
|
nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
|
2013-04-04 10:20:24 -04:00
|
|
|
{
|
2013-11-06 14:13:59 -06:00
|
|
|
NMIP4Config *config;
|
|
|
|
|
NMIP4ConfigPrivate *priv;
|
2013-11-02 09:44:47 -05:00
|
|
|
guint i;
|
2014-11-04 15:48:48 -05:00
|
|
|
guint32 lowest_metric = G_MAXUINT32;
|
2013-11-19 22:51:29 -06:00
|
|
|
guint32 old_gateway = 0;
|
2013-11-19 22:28:36 -06:00
|
|
|
gboolean has_gateway = FALSE;
|
2013-11-06 14:13:59 -06:00
|
|
|
|
|
|
|
|
/* Slaves have no IP configuration */
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
if (nm_platform_link_get_master (NM_PLATFORM_GET, ifindex) > 0)
|
2013-11-06 14:13:59 -06:00
|
|
|
return NULL;
|
|
|
|
|
|
2015-02-20 16:31:10 -06:00
|
|
|
config = nm_ip4_config_new (ifindex);
|
2013-11-06 14:13:59 -06:00
|
|
|
priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2013-04-04 10:20:24 -04:00
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
g_array_unref (priv->addresses);
|
2013-07-31 23:07:32 +02:00
|
|
|
g_array_unref (priv->routes);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
priv->addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
|
2015-06-22 17:28:37 +02:00
|
|
|
priv->routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT);
|
2013-11-02 09:44:47 -05:00
|
|
|
|
|
|
|
|
/* Extract gateway from default route */
|
2013-11-19 22:51:29 -06:00
|
|
|
old_gateway = priv->gateway;
|
2015-06-22 18:11:24 +02:00
|
|
|
for (i = 0; i < priv->routes->len; ) {
|
2013-11-02 09:44:47 -05:00
|
|
|
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
|
|
|
|
|
2014-07-29 19:10:08 +02:00
|
|
|
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
|
2013-11-19 22:51:29 -06:00
|
|
|
if (route->metric < lowest_metric) {
|
2013-11-02 09:44:47 -05:00
|
|
|
priv->gateway = route->gateway;
|
2013-11-19 22:51:29 -06:00
|
|
|
lowest_metric = route->metric;
|
2013-11-02 09:44:47 -05:00
|
|
|
}
|
2013-11-19 22:28:36 -06:00
|
|
|
has_gateway = TRUE;
|
2013-11-02 09:44:47 -05:00
|
|
|
/* Remove the default route from the list */
|
2015-06-22 18:11:24 +02:00
|
|
|
g_array_remove_index_fast (priv->routes, i);
|
|
|
|
|
continue;
|
2013-11-02 09:44:47 -05:00
|
|
|
}
|
2015-06-22 18:11:24 +02:00
|
|
|
i++;
|
2013-11-02 09:44:47 -05:00
|
|
|
}
|
2013-04-04 10:20:24 -04:00
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
/* we detect the route metric based on the default route. All non-default
|
|
|
|
|
* routes have their route metrics explicitly set. */
|
|
|
|
|
priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1;
|
|
|
|
|
|
2013-12-02 16:24:06 -06:00
|
|
|
/* If there is a host route to the gateway, ignore that route. It is
|
|
|
|
|
* automatically added by NetworkManager when needed.
|
|
|
|
|
*/
|
|
|
|
|
if (has_gateway) {
|
|
|
|
|
for (i = 0; i < priv->routes->len; i++) {
|
|
|
|
|
const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
|
|
|
|
|
|
|
|
|
if ( (route->plen == 32)
|
|
|
|
|
&& (route->network == priv->gateway)
|
|
|
|
|
&& (route->gateway == 0)) {
|
|
|
|
|
g_array_remove_index (priv->routes, i);
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 22:28:36 -06:00
|
|
|
/* If the interface has the default route, and has IPv4 addresses, capture
|
|
|
|
|
* nameservers from /etc/resolv.conf.
|
|
|
|
|
*/
|
|
|
|
|
if (priv->addresses->len && has_gateway && capture_resolv_conf) {
|
2015-05-03 22:54:55 +02:00
|
|
|
if (nm_ip4_config_capture_resolv_conf (priv->nameservers, priv->dns_options, NULL))
|
2013-11-19 22:28:36 -06:00
|
|
|
_NOTIFY (config, PROP_NAMESERVERS);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
/* actually, nobody should be connected to the signal, just to be sure, notify */
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ADDRESS_DATA);
|
|
|
|
|
_NOTIFY (config, PROP_ROUTE_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ADDRESSES);
|
|
|
|
|
_NOTIFY (config, PROP_ROUTES);
|
2013-11-19 22:51:29 -06:00
|
|
|
if (priv->gateway != old_gateway)
|
2013-11-02 09:44:47 -05:00
|
|
|
_NOTIFY (config, PROP_GATEWAY);
|
2013-09-06 11:56:41 +02:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return config;
|
2013-04-04 10:20:24 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
gboolean
|
2015-07-13 19:20:08 +02:00
|
|
|
nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_full_sync, gint64 default_route_metric)
|
2013-07-03 10:26:19 +02:00
|
|
|
{
|
2013-06-29 13:33:36 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2013-07-03 10:26:19 +02:00
|
|
|
int i;
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
gs_unref_ptrarray GPtrArray *added_addresses = NULL;
|
2013-07-03 10:26:19 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (config != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
/* Addresses */
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
nm_platform_ip4_address_sync (NM_PLATFORM_GET, ifindex, priv->addresses,
|
|
|
|
|
default_route_metric >= 0 ? &added_addresses : NULL);
|
2013-07-03 10:26:19 +02:00
|
|
|
|
|
|
|
|
/* Routes */
|
|
|
|
|
{
|
|
|
|
|
int count = nm_ip4_config_get_num_routes (config);
|
|
|
|
|
GArray *routes = g_array_sized_new (FALSE, FALSE, sizeof (NMPlatformIP4Route), count);
|
2013-08-26 23:06:03 +02:00
|
|
|
gboolean success;
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
gs_unref_array GArray *device_route_purge_list = NULL;
|
|
|
|
|
|
|
|
|
|
if ( default_route_metric >= 0
|
|
|
|
|
&& added_addresses) {
|
|
|
|
|
/* For IPv6, we explicitly add the device-routes (onlink) to NMIP6Config.
|
|
|
|
|
* As we don't do that for IPv4, add it here shortly before syncing
|
|
|
|
|
* the routes. For NMRouteManager these routes are very much important. */
|
|
|
|
|
for (i = 0; i < added_addresses->len; i++) {
|
|
|
|
|
const NMPlatformIP4Address *addr = added_addresses->pdata[i];
|
|
|
|
|
NMPlatformIP4Route route = { 0 };
|
|
|
|
|
|
|
|
|
|
if (addr->plen == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
route.ifindex = ifindex;
|
|
|
|
|
route.source = NM_IP_CONFIG_SOURCE_KERNEL;
|
|
|
|
|
route.network = nm_utils_ip4_address_clear_host_address (addr->address, addr->plen);
|
|
|
|
|
route.plen = addr->plen;
|
|
|
|
|
route.pref_src = addr->address;
|
|
|
|
|
route.metric = default_route_metric;
|
|
|
|
|
|
|
|
|
|
g_array_append_val (routes, route);
|
|
|
|
|
|
|
|
|
|
if (default_route_metric != NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE) {
|
|
|
|
|
if (!device_route_purge_list)
|
|
|
|
|
device_route_purge_list = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route));
|
|
|
|
|
route.metric = NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE;
|
|
|
|
|
g_array_append_val (device_route_purge_list, route);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-03 10:26:19 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
const NMPlatformIP4Route *route;
|
|
|
|
|
|
2014-07-29 19:39:06 +02:00
|
|
|
route = nm_ip4_config_get_route (config, i);
|
2013-07-03 10:26:19 +02:00
|
|
|
|
|
|
|
|
/* Don't add the route if it's more specific than one of the subnets
|
|
|
|
|
* the device already has an IP address on.
|
|
|
|
|
*/
|
2014-07-29 19:39:06 +02:00
|
|
|
if ( route->gateway == 0
|
|
|
|
|
&& nm_ip4_config_destination_is_direct (config, route->network, route->plen))
|
2013-07-03 10:26:19 +02:00
|
|
|
continue;
|
|
|
|
|
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
/* duplicates in @routes are no problem as route-manager handles them
|
|
|
|
|
* gracefully (by ignoring them). */
|
2014-07-29 19:39:06 +02:00
|
|
|
g_array_append_vals (routes, route, 1);
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
nm_route_manager_ip4_route_register_device_route_purge_list (nm_route_manager_get (), device_route_purge_list);
|
|
|
|
|
|
2015-07-13 19:20:08 +02:00
|
|
|
success = nm_route_manager_ip4_route_sync (nm_route_manager_get (), ifindex, routes, default_route_metric < 0, routes_full_sync);
|
2013-07-03 10:26:19 +02:00
|
|
|
g_array_unref (routes);
|
2013-08-26 23:06:03 +02:00
|
|
|
if (!success)
|
|
|
|
|
return FALSE;
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-05 02:55:40 +00:00
|
|
|
void
|
2014-08-28 17:25:36 +02:00
|
|
|
nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
|
2008-09-05 02:55:40 +00:00
|
|
|
{
|
2015-06-04 15:57:42 +02:00
|
|
|
NMIP4ConfigPrivate *priv;
|
2013-07-12 11:33:52 +02:00
|
|
|
guint naddresses, nroutes, nnameservers, nsearches;
|
|
|
|
|
int i;
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
if (!setting)
|
2013-07-12 11:33:52 +02:00
|
|
|
return;
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_freeze_notify (G_OBJECT (config));
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
naddresses = nm_setting_ip_config_get_num_addresses (setting);
|
|
|
|
|
nroutes = nm_setting_ip_config_get_num_routes (setting);
|
|
|
|
|
nnameservers = nm_setting_ip_config_get_num_dns (setting);
|
|
|
|
|
nsearches = nm_setting_ip_config_get_num_dns_searches (setting);
|
2013-07-12 11:33:52 +02:00
|
|
|
|
|
|
|
|
/* Gateway */
|
2014-10-19 17:30:10 -04:00
|
|
|
if (nm_setting_ip_config_get_never_default (setting))
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_set_never_default (config, TRUE);
|
2014-10-19 17:30:10 -04:00
|
|
|
else if (nm_setting_ip_config_get_ignore_auto_routes (setting))
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_set_never_default (config, FALSE);
|
2014-10-20 21:30:56 -04:00
|
|
|
if (nm_setting_ip_config_get_gateway (setting)) {
|
2014-09-16 16:42:46 -04:00
|
|
|
guint32 gateway;
|
2013-07-12 11:33:52 +02:00
|
|
|
|
2014-10-20 21:30:56 -04:00
|
|
|
inet_pton (AF_INET, nm_setting_ip_config_get_gateway (setting), &gateway);
|
|
|
|
|
nm_ip4_config_set_gateway (config, gateway);
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
if (priv->route_metric == -1)
|
|
|
|
|
priv->route_metric = nm_setting_ip_config_get_route_metric (setting);
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/* Addresses */
|
2013-06-29 13:33:36 +02:00
|
|
|
for (i = 0; i < naddresses; i++) {
|
2014-10-19 17:30:10 -04:00
|
|
|
NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i);
|
2014-09-16 16:38:04 -04:00
|
|
|
GVariant *label;
|
2013-06-29 13:33:36 +02:00
|
|
|
NMPlatformIP4Address address;
|
|
|
|
|
|
|
|
|
|
memset (&address, 0, sizeof (address));
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_address_get_address_binary (s_addr, &address.address);
|
|
|
|
|
address.plen = nm_ip_address_get_prefix (s_addr);
|
2013-07-04 20:40:18 +02:00
|
|
|
address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT;
|
|
|
|
|
address.preferred = NM_PLATFORM_LIFETIME_PERMANENT;
|
2014-10-13 11:52:29 +02:00
|
|
|
address.source = NM_IP_CONFIG_SOURCE_USER;
|
2014-09-16 16:38:04 -04:00
|
|
|
|
|
|
|
|
label = nm_ip_address_get_attribute (s_addr, "label");
|
|
|
|
|
if (label)
|
|
|
|
|
g_strlcpy (address.label, g_variant_get_string (label, NULL), sizeof (address.label));
|
2013-06-29 13:33:36 +02:00
|
|
|
|
|
|
|
|
nm_ip4_config_add_address (config, &address);
|
|
|
|
|
}
|
2013-07-03 10:26:19 +02:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/* Routes */
|
2014-10-19 17:30:10 -04:00
|
|
|
if (nm_setting_ip_config_get_ignore_auto_routes (setting))
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_reset_routes (config);
|
2013-07-31 23:07:32 +02:00
|
|
|
for (i = 0; i < nroutes; i++) {
|
2014-10-19 17:30:10 -04:00
|
|
|
NMIPRoute *s_route = nm_setting_ip_config_get_route (setting, i);
|
2013-07-31 23:07:32 +02:00
|
|
|
NMPlatformIP4Route route;
|
|
|
|
|
|
|
|
|
|
memset (&route, 0, sizeof (route));
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_route_get_dest_binary (s_route, &route.network);
|
|
|
|
|
route.plen = nm_ip_route_get_prefix (s_route);
|
|
|
|
|
nm_ip_route_get_next_hop_binary (s_route, &route.gateway);
|
2014-11-04 15:48:48 -05:00
|
|
|
if (nm_ip_route_get_metric (s_route) == -1)
|
2014-06-09 09:36:01 -04:00
|
|
|
route.metric = default_route_metric;
|
2014-11-04 15:48:48 -05:00
|
|
|
else
|
|
|
|
|
route.metric = nm_ip_route_get_metric (s_route);
|
2014-10-13 11:52:29 +02:00
|
|
|
route.source = NM_IP_CONFIG_SOURCE_USER;
|
2013-07-31 23:07:32 +02:00
|
|
|
|
2014-11-11 15:58:58 +01:00
|
|
|
g_assert (route.plen > 0);
|
|
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
nm_ip4_config_add_route (config, &route);
|
|
|
|
|
}
|
2013-07-12 11:33:52 +02:00
|
|
|
|
|
|
|
|
/* DNS */
|
2014-10-19 17:30:10 -04:00
|
|
|
if (nm_setting_ip_config_get_ignore_auto_dns (setting)) {
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_reset_nameservers (config);
|
|
|
|
|
nm_ip4_config_reset_domains (config);
|
|
|
|
|
nm_ip4_config_reset_searches (config);
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
2014-06-24 12:46:03 -04:00
|
|
|
for (i = 0; i < nnameservers; i++) {
|
|
|
|
|
guint32 ip;
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
if (inet_pton (AF_INET, nm_setting_ip_config_get_dns (setting, i), &ip) == 1)
|
2014-06-24 12:46:03 -04:00
|
|
|
nm_ip4_config_add_nameserver (config, ip);
|
|
|
|
|
}
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < nsearches; i++)
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_ip4_config_add_search (config, nm_setting_ip_config_get_dns_search (setting, i));
|
2013-09-06 11:56:41 +02:00
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
i = 0;
|
|
|
|
|
while ((i = nm_setting_ip_config_next_valid_dns_option (setting, i)) >= 0) {
|
|
|
|
|
nm_ip4_config_add_dns_option (config, nm_setting_ip_config_get_dns_option (setting, i));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_thaw_notify (G_OBJECT (config));
|
2008-09-05 02:55:40 +00:00
|
|
|
}
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2014-05-19 10:24:15 -04:00
|
|
|
NMSetting *
|
|
|
|
|
nm_ip4_config_create_setting (const NMIP4Config *config)
|
2013-07-25 23:36:36 +02:00
|
|
|
{
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip4;
|
2013-07-25 23:36:36 +02:00
|
|
|
guint32 gateway;
|
2015-03-26 09:23:12 +01:00
|
|
|
guint naddresses, nroutes, nnameservers, nsearches, noptions;
|
2013-07-25 23:36:36 +02:00
|
|
|
const char *method = NULL;
|
|
|
|
|
int i;
|
2015-06-04 15:57:42 +02:00
|
|
|
gint64 route_metric;
|
2013-07-25 23:36:36 +02:00
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
|
2014-05-19 10:24:15 -04:00
|
|
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
g_object_set (s_ip4,
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
2014-05-19 10:24:15 -04:00
|
|
|
NULL);
|
|
|
|
|
return NM_SETTING (s_ip4);
|
|
|
|
|
}
|
2013-07-25 23:36:36 +02:00
|
|
|
|
|
|
|
|
gateway = nm_ip4_config_get_gateway (config);
|
|
|
|
|
naddresses = nm_ip4_config_get_num_addresses (config);
|
|
|
|
|
nroutes = nm_ip4_config_get_num_routes (config);
|
|
|
|
|
nnameservers = nm_ip4_config_get_num_nameservers (config);
|
|
|
|
|
nsearches = nm_ip4_config_get_num_searches (config);
|
2015-03-26 09:23:12 +01:00
|
|
|
noptions = nm_ip4_config_get_num_dns_options (config);
|
2015-06-04 15:57:42 +02:00
|
|
|
route_metric = nm_ip4_config_get_route_metric (config);
|
2013-07-25 23:36:36 +02:00
|
|
|
|
|
|
|
|
/* Addresses */
|
|
|
|
|
for (i = 0; i < naddresses; i++) {
|
|
|
|
|
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
|
2014-09-16 16:42:46 -04:00
|
|
|
NMIPAddress *s_addr;
|
2013-07-25 23:36:36 +02:00
|
|
|
|
2013-07-04 20:40:18 +02:00
|
|
|
/* Detect dynamic address */
|
|
|
|
|
if (address->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
|
|
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-25 23:36:36 +02:00
|
|
|
/* Static address found. */
|
|
|
|
|
if (!method)
|
|
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
|
|
|
|
|
|
2014-10-20 21:30:56 -04:00
|
|
|
s_addr = nm_ip_address_new_binary (AF_INET, &address->address, address->plen, NULL);
|
2014-09-16 16:38:04 -04:00
|
|
|
if (*address->label)
|
|
|
|
|
nm_ip_address_set_attribute (s_addr, "label", g_variant_new_string (address->label));
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_address (s_ip4, s_addr);
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_address_unref (s_addr);
|
2013-07-25 23:36:36 +02:00
|
|
|
}
|
2013-11-08 00:29:38 -06:00
|
|
|
|
2014-10-20 21:30:56 -04:00
|
|
|
/* Gateway */
|
2014-11-07 16:34:13 +01:00
|
|
|
if ( gateway
|
|
|
|
|
&& nm_setting_ip_config_get_num_addresses (s_ip4) > 0) {
|
2014-10-20 21:30:56 -04:00
|
|
|
g_object_set (s_ip4,
|
|
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, nm_utils_inet4_ntop (gateway, NULL),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 10:24:15 -04:00
|
|
|
/* Use 'disabled' if the method wasn't previously set */
|
|
|
|
|
if (!method)
|
2013-07-25 23:36:36 +02:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
2015-06-04 15:57:42 +02:00
|
|
|
|
|
|
|
|
g_object_set (s_ip4,
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, method,
|
|
|
|
|
NM_SETTING_IP_CONFIG_ROUTE_METRIC, (gint64) route_metric,
|
|
|
|
|
NULL);
|
2013-07-25 23:36:36 +02:00
|
|
|
|
|
|
|
|
/* Routes */
|
|
|
|
|
for (i = 0; i < nroutes; i++) {
|
2013-09-24 18:19:18 +02:00
|
|
|
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
|
2014-09-16 16:42:46 -04:00
|
|
|
NMIPRoute *s_route;
|
2013-07-25 23:36:36 +02:00
|
|
|
|
|
|
|
|
/* Ignore default route. */
|
2013-07-31 23:07:32 +02:00
|
|
|
if (!route->plen)
|
2013-07-25 23:36:36 +02:00
|
|
|
continue;
|
|
|
|
|
|
2014-05-08 14:56:59 -04:00
|
|
|
/* Ignore routes provided by external sources */
|
2014-10-13 11:52:29 +02:00
|
|
|
if (route->source != NM_IP_CONFIG_SOURCE_USER)
|
2014-05-08 14:56:59 -04:00
|
|
|
continue;
|
|
|
|
|
|
2014-09-16 16:42:46 -04:00
|
|
|
s_route = nm_ip_route_new_binary (AF_INET,
|
|
|
|
|
&route->network, route->plen,
|
|
|
|
|
&route->gateway, route->metric,
|
|
|
|
|
NULL);
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_route (s_ip4, s_route);
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_route_unref (s_route);
|
2013-07-25 23:36:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* DNS */
|
|
|
|
|
for (i = 0; i < nnameservers; i++) {
|
|
|
|
|
guint32 nameserver = nm_ip4_config_get_nameserver (config, i);
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, NULL));
|
2013-07-25 23:36:36 +02:00
|
|
|
}
|
|
|
|
|
for (i = 0; i < nsearches; i++) {
|
|
|
|
|
const char *search = nm_ip4_config_get_search (config, i);
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_dns_search (s_ip4, search);
|
2013-07-25 23:36:36 +02:00
|
|
|
}
|
2014-05-19 10:24:15 -04:00
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
for (i = 0; i < noptions; i++) {
|
|
|
|
|
const char *option = nm_ip4_config_get_dns_option (config, i);
|
|
|
|
|
|
|
|
|
|
nm_setting_ip_config_add_dns_option (s_ip4, option);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 10:24:15 -04:00
|
|
|
return NM_SETTING (s_ip4);
|
2013-07-25 23:36:36 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-08-01 10:34:46 -05:00
|
|
|
void
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
|
2013-08-01 10:34:46 -05:00
|
|
|
{
|
2015-06-04 15:57:42 +02:00
|
|
|
NMIP4ConfigPrivate *dst_priv, *src_priv;
|
2013-08-01 10:34:46 -05:00
|
|
|
guint32 i;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (src != NULL);
|
|
|
|
|
g_return_if_fail (dst != NULL);
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
dst_priv = NM_IP4_CONFIG_GET_PRIVATE (dst);
|
|
|
|
|
src_priv = NM_IP4_CONFIG_GET_PRIVATE (src);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_freeze_notify (G_OBJECT (dst));
|
|
|
|
|
|
2013-08-01 10:34:46 -05:00
|
|
|
/* addresses */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_addresses (src); i++)
|
|
|
|
|
nm_ip4_config_add_address (dst, nm_ip4_config_get_address (src, i));
|
|
|
|
|
|
|
|
|
|
/* nameservers */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nameservers (src); i++)
|
|
|
|
|
nm_ip4_config_add_nameserver (dst, nm_ip4_config_get_nameserver (src, i));
|
|
|
|
|
|
|
|
|
|
/* default gateway */
|
2015-06-28 21:15:12 +02:00
|
|
|
if (nm_ip4_config_get_gateway (src))
|
2013-08-01 10:34:46 -05:00
|
|
|
nm_ip4_config_set_gateway (dst, nm_ip4_config_get_gateway (src));
|
|
|
|
|
|
|
|
|
|
/* routes */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++)
|
|
|
|
|
nm_ip4_config_add_route (dst, nm_ip4_config_get_route (src, i));
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
if (dst_priv->route_metric == -1)
|
|
|
|
|
dst_priv->route_metric = src_priv->route_metric;
|
|
|
|
|
else
|
|
|
|
|
dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric);
|
|
|
|
|
|
2013-08-01 10:34:46 -05:00
|
|
|
/* domains */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_domains (src); i++)
|
|
|
|
|
nm_ip4_config_add_domain (dst, nm_ip4_config_get_domain (src, i));
|
|
|
|
|
|
|
|
|
|
/* dns searches */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_searches (src); i++)
|
|
|
|
|
nm_ip4_config_add_search (dst, nm_ip4_config_get_search (src, i));
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
/* dns options */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_dns_options (src); i++)
|
|
|
|
|
nm_ip4_config_add_dns_option (dst, nm_ip4_config_get_dns_option (src, i));
|
|
|
|
|
|
2014-04-17 11:15:36 +02:00
|
|
|
/* MSS */
|
2015-06-28 21:15:12 +02:00
|
|
|
if (nm_ip4_config_get_mss (src))
|
2013-08-01 10:34:46 -05:00
|
|
|
nm_ip4_config_set_mss (dst, nm_ip4_config_get_mss (src));
|
|
|
|
|
|
2014-04-17 11:15:36 +02:00
|
|
|
/* MTU */
|
2015-06-28 21:15:12 +02:00
|
|
|
if (nm_ip4_config_get_mtu (src))
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (dst, nm_ip4_config_get_mtu (src),
|
|
|
|
|
nm_ip4_config_get_mtu_source (src));
|
2014-04-17 11:15:36 +02:00
|
|
|
|
2013-08-01 10:34:46 -05:00
|
|
|
/* NIS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++)
|
|
|
|
|
nm_ip4_config_add_nis_server (dst, nm_ip4_config_get_nis_server (src, i));
|
|
|
|
|
|
|
|
|
|
if (nm_ip4_config_get_nis_domain (src))
|
|
|
|
|
nm_ip4_config_set_nis_domain (dst, nm_ip4_config_get_nis_domain (src));
|
|
|
|
|
|
|
|
|
|
/* WINS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_wins (src); i++)
|
|
|
|
|
nm_ip4_config_add_wins (dst, nm_ip4_config_get_wins (src, i));
|
2013-09-06 11:56:41 +02:00
|
|
|
|
2015-04-30 18:11:16 +02:00
|
|
|
/* metered flag */
|
|
|
|
|
nm_ip4_config_set_metered (dst, nm_ip4_config_get_metered (dst) ||
|
|
|
|
|
nm_ip4_config_get_metered (src));
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_thaw_notify (G_OBJECT (dst));
|
2013-08-01 10:34:46 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-20 23:36:50 +01:00
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_addresses_get_index (const NMIP4Config *self, const NMPlatformIP4Address *addr)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->addresses->len; i++) {
|
|
|
|
|
const NMPlatformIP4Address *a = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
|
|
|
|
|
|
|
|
|
if (addr->address == a->address &&
|
|
|
|
|
addr->plen == a->plen)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_nameservers_get_index (const NMIP4Config *self, guint32 ns)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->nameservers->len; i++) {
|
|
|
|
|
guint32 n = g_array_index (priv->nameservers, guint32, i);
|
|
|
|
|
|
|
|
|
|
if (ns == n)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_routes_get_index (const NMIP4Config *self, const NMPlatformIP4Route *route)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->routes->len; i++) {
|
|
|
|
|
const NMPlatformIP4Route *r = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
|
|
|
|
|
|
|
|
|
if ( route->network == r->network
|
|
|
|
|
&& route->plen == r->plen)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_domains_get_index (const NMIP4Config *self, const char *domain)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->domains->len; i++) {
|
|
|
|
|
const char *d = g_ptr_array_index (priv->domains, i);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (domain, d) == 0)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_searches_get_index (const NMIP4Config *self, const char *search)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->searches->len; i++) {
|
|
|
|
|
const char *s = g_ptr_array_index (priv->searches, i);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (search, s) == 0)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
static int
|
|
|
|
|
_dns_options_get_index (const NMIP4Config *self, const char *option)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->dns_options->len; i++) {
|
|
|
|
|
const char *s = g_ptr_array_index (priv->dns_options, i);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (option, s) == 0)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 23:36:50 +01:00
|
|
|
static int
|
|
|
|
|
_nis_servers_get_index (const NMIP4Config *self, guint32 nis_server)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->nis->len; i++) {
|
|
|
|
|
guint32 n = g_array_index (priv->nis, guint32, i);
|
|
|
|
|
|
|
|
|
|
if (n == nis_server)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
_wins_get_index (const NMIP4Config *self, guint32 wins_server)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->wins->len; i++) {
|
|
|
|
|
guint32 n = g_array_index (priv->wins, guint32, i);
|
|
|
|
|
|
|
|
|
|
if (n == wins_server)
|
|
|
|
|
return (int) i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
/**
|
2013-09-06 11:02:03 +02:00
|
|
|
* nm_ip4_config_subtract:
|
2013-08-01 14:04:35 -05:00
|
|
|
* @dst: config from which to remove everything in @src
|
|
|
|
|
* @src: config to remove from @dst
|
|
|
|
|
*
|
|
|
|
|
* Removes everything in @src from @dst.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
|
2013-08-01 14:04:35 -05:00
|
|
|
{
|
2014-11-20 23:36:50 +01:00
|
|
|
guint32 i;
|
|
|
|
|
gint idx;
|
2013-08-01 14:04:35 -05:00
|
|
|
|
|
|
|
|
g_return_if_fail (src != NULL);
|
|
|
|
|
g_return_if_fail (dst != NULL);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_freeze_notify (G_OBJECT (dst));
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
/* addresses */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_addresses (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _addresses_get_index (dst, nm_ip4_config_get_address (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_address (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* nameservers */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nameservers (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _nameservers_get_index (dst, nm_ip4_config_get_nameserver (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_nameserver (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* default gateway */
|
|
|
|
|
if (nm_ip4_config_get_gateway (src) == nm_ip4_config_get_gateway (dst))
|
|
|
|
|
nm_ip4_config_set_gateway (dst, 0);
|
|
|
|
|
|
2014-11-07 16:34:13 +01:00
|
|
|
if (!nm_ip4_config_get_num_addresses (dst))
|
|
|
|
|
nm_ip4_config_set_gateway (dst, 0);
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
/* ignore route_metric */
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
/* routes */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _routes_get_index (dst, nm_ip4_config_get_route (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_route (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* domains */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_domains (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _domains_get_index (dst, nm_ip4_config_get_domain (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_domain (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* dns searches */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_searches (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _searches_get_index (dst, nm_ip4_config_get_search (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_search (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
/* dns options */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_dns_options (src); i++) {
|
|
|
|
|
idx = _dns_options_get_index (dst, nm_ip4_config_get_dns_option (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_dns_option (dst, idx);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 11:15:36 +02:00
|
|
|
/* MSS */
|
2013-08-01 14:04:35 -05:00
|
|
|
if (nm_ip4_config_get_mss (src) == nm_ip4_config_get_mss (dst))
|
|
|
|
|
nm_ip4_config_set_mss (dst, 0);
|
|
|
|
|
|
2014-04-17 11:15:36 +02:00
|
|
|
/* MTU */
|
|
|
|
|
if (nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst))
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (dst, 0, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
2014-04-17 11:15:36 +02:00
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
/* NIS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _nis_servers_get_index (dst, nm_ip4_config_get_nis_server (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_nis_server (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (nm_ip4_config_get_nis_domain (src), nm_ip4_config_get_nis_domain (dst)) == 0)
|
|
|
|
|
nm_ip4_config_set_nis_domain (dst, NULL);
|
|
|
|
|
|
|
|
|
|
/* WINS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_wins (src); i++) {
|
2014-11-20 23:36:50 +01:00
|
|
|
idx = _wins_get_index (dst, nm_ip4_config_get_wins (src, i));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
nm_ip4_config_del_wins (dst, idx);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
2013-09-06 11:56:41 +02:00
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (dst));
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-20 23:39:21 +01:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src)
|
|
|
|
|
{
|
|
|
|
|
guint32 i;
|
|
|
|
|
gint idx;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (src != NULL);
|
|
|
|
|
g_return_if_fail (dst != NULL);
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (dst));
|
|
|
|
|
|
|
|
|
|
/* addresses */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_addresses (dst); ) {
|
|
|
|
|
idx = _addresses_get_index (src, nm_ip4_config_get_address (dst, i));
|
|
|
|
|
if (idx < 0)
|
|
|
|
|
nm_ip4_config_del_address (dst, i);
|
|
|
|
|
else
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
/* ignore route_metric */
|
2015-01-26 17:29:25 +01:00
|
|
|
/* ignore nameservers */
|
2014-11-20 23:39:21 +01:00
|
|
|
|
|
|
|
|
/* default gateway */
|
|
|
|
|
if ( !nm_ip4_config_get_num_addresses (dst)
|
|
|
|
|
|| (nm_ip4_config_get_gateway (src) != nm_ip4_config_get_gateway (dst)))
|
|
|
|
|
nm_ip4_config_set_gateway (dst, 0);
|
|
|
|
|
|
|
|
|
|
/* routes */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_routes (dst); ) {
|
|
|
|
|
idx = _routes_get_index (src, nm_ip4_config_get_route (dst, i));
|
|
|
|
|
if (idx < 0)
|
|
|
|
|
nm_ip4_config_del_route (dst, i);
|
|
|
|
|
else
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 17:29:25 +01:00
|
|
|
/* ignore domains */
|
|
|
|
|
/* ignore dns searches */
|
2015-03-26 09:23:12 +01:00
|
|
|
/* ignore dns options */
|
2015-01-26 17:29:25 +01:00
|
|
|
/* ignore NIS */
|
|
|
|
|
/* ignore WINS */
|
2014-11-20 23:39:21 +01:00
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (dst));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_ip4_config_replace:
|
|
|
|
|
* @dst: config from which to remove everything in @src
|
|
|
|
|
* @src: config to remove from @dst
|
|
|
|
|
* @relevant_changes: return whether there are changes to the
|
|
|
|
|
* destination object that are relevant. This is equal to
|
|
|
|
|
* nm_ip4_config_equal() showing any difference.
|
|
|
|
|
*
|
|
|
|
|
* Replaces everything in @dst with @src so that the two configurations
|
|
|
|
|
* contain the same content -- with the exception of the dbus path.
|
|
|
|
|
*
|
|
|
|
|
* Returns: whether the @dst instance changed in any way (including minor changes,
|
|
|
|
|
* that are not signaled by the output parameter @relevant_changes).
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes)
|
2013-09-06 11:02:03 +02:00
|
|
|
{
|
|
|
|
|
#ifndef G_DISABLE_ASSERT
|
|
|
|
|
gboolean config_equal;
|
|
|
|
|
#endif
|
|
|
|
|
gboolean has_minor_changes = FALSE, has_relevant_changes = FALSE, are_equal;
|
|
|
|
|
guint i, num;
|
|
|
|
|
NMIP4ConfigPrivate *dst_priv, *src_priv;
|
|
|
|
|
const NMPlatformIP4Address *dst_addr, *src_addr;
|
|
|
|
|
const NMPlatformIP4Route *dst_route, *src_route;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (src != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (dst != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (src != dst, FALSE);
|
|
|
|
|
|
|
|
|
|
#ifndef G_DISABLE_ASSERT
|
|
|
|
|
config_equal = nm_ip4_config_equal (dst, src);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
dst_priv = NM_IP4_CONFIG_GET_PRIVATE (dst);
|
|
|
|
|
src_priv = NM_IP4_CONFIG_GET_PRIVATE (src);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_freeze_notify (G_OBJECT (dst));
|
|
|
|
|
|
2015-01-19 18:33:10 +01:00
|
|
|
/* ifindex */
|
|
|
|
|
if (src_priv->ifindex != dst_priv->ifindex) {
|
2015-02-20 16:31:10 -06:00
|
|
|
dst_priv->ifindex = src_priv->ifindex;
|
2015-01-19 18:33:10 +01:00
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
/* never_default */
|
|
|
|
|
if (src_priv->never_default != dst_priv->never_default) {
|
|
|
|
|
dst_priv->never_default = src_priv->never_default;
|
2013-10-24 15:15:02 -04:00
|
|
|
has_minor_changes = TRUE;
|
2013-09-06 11:02:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* default gateway */
|
|
|
|
|
if (src_priv->gateway != dst_priv->gateway) {
|
|
|
|
|
nm_ip4_config_set_gateway (dst, src_priv->gateway);
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
if (src_priv->route_metric != dst_priv->route_metric) {
|
|
|
|
|
dst_priv->route_metric = src_priv->route_metric;
|
|
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
/* addresses */
|
|
|
|
|
num = nm_ip4_config_get_num_addresses (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_addresses (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (nm_platform_ip4_address_cmp (src_addr = nm_ip4_config_get_address (src, i),
|
|
|
|
|
dst_addr = nm_ip4_config_get_address (dst, i))) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
if (!addresses_are_duplicate (src_addr, dst_addr, TRUE)) {
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_addresses (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_address (dst, nm_ip4_config_get_address (src, i));
|
|
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* routes */
|
|
|
|
|
num = nm_ip4_config_get_num_routes (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_routes (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (nm_platform_ip4_route_cmp (src_route = nm_ip4_config_get_route (src, i),
|
|
|
|
|
dst_route = nm_ip4_config_get_route (dst, i))) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
if (!routes_are_duplicate (src_route, dst_route, TRUE)) {
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_routes (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_route (dst, nm_ip4_config_get_route (src, i));
|
|
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* nameservers */
|
|
|
|
|
num = nm_ip4_config_get_num_nameservers (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_nameservers (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (nm_ip4_config_get_nameserver (src, i) != nm_ip4_config_get_nameserver (dst, i)) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_nameservers (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_nameserver (dst, nm_ip4_config_get_nameserver (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* domains */
|
|
|
|
|
num = nm_ip4_config_get_num_domains (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_domains (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (g_strcmp0 (nm_ip4_config_get_domain (src, i),
|
|
|
|
|
nm_ip4_config_get_domain (dst, i))) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_domains (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_domain (dst, nm_ip4_config_get_domain (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* dns searches */
|
|
|
|
|
num = nm_ip4_config_get_num_searches (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_searches (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (g_strcmp0 (nm_ip4_config_get_search (src, i),
|
|
|
|
|
nm_ip4_config_get_search (dst, i))) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_searches (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_search (dst, nm_ip4_config_get_search (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
/* dns options */
|
|
|
|
|
num = nm_ip4_config_get_num_dns_options (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_dns_options (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (g_strcmp0 (nm_ip4_config_get_dns_option (src, i),
|
|
|
|
|
nm_ip4_config_get_dns_option (dst, i))) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_dns_options (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_dns_option (dst, nm_ip4_config_get_dns_option (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
/* mss */
|
|
|
|
|
if (src_priv->mss != dst_priv->mss) {
|
|
|
|
|
nm_ip4_config_set_mss (dst, src_priv->mss);
|
|
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* nis */
|
|
|
|
|
num = nm_ip4_config_get_num_nis_servers (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_nis_servers (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (nm_ip4_config_get_nis_server (src, i) != nm_ip4_config_get_nis_server (dst, i)) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_nis_servers (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_nis_server (dst, nm_ip4_config_get_nis_server (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* nis_domain */
|
|
|
|
|
if (g_strcmp0 (src_priv->nis_domain, dst_priv->nis_domain)) {
|
|
|
|
|
nm_ip4_config_set_nis_domain (dst, src_priv->nis_domain);
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wins */
|
|
|
|
|
num = nm_ip4_config_get_num_wins (src);
|
|
|
|
|
are_equal = num == nm_ip4_config_get_num_wins (dst);
|
|
|
|
|
if (are_equal) {
|
|
|
|
|
for (i = 0; i < num; i++ ) {
|
|
|
|
|
if (nm_ip4_config_get_wins (src, i) != nm_ip4_config_get_wins (dst, i)) {
|
|
|
|
|
are_equal = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!are_equal) {
|
|
|
|
|
nm_ip4_config_reset_wins (dst);
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
nm_ip4_config_add_wins (dst, nm_ip4_config_get_wins (src, i));
|
|
|
|
|
has_relevant_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* mtu */
|
|
|
|
|
if (src_priv->mtu != dst_priv->mtu) {
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source);
|
2013-09-06 11:02:03 +02:00
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-30 18:11:16 +02:00
|
|
|
/* metered */
|
|
|
|
|
if (src_priv->metered != dst_priv->metered) {
|
|
|
|
|
dst_priv->metered = src_priv->metered;
|
|
|
|
|
has_minor_changes = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
/* config_equal does not compare *all* the fields, therefore, we might have has_minor_changes
|
|
|
|
|
* regardless of config_equal. But config_equal must correspond to has_relevant_changes. */
|
|
|
|
|
g_assert (config_equal == !has_relevant_changes);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
g_object_thaw_notify (G_OBJECT (dst));
|
|
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
if (relevant_changes)
|
|
|
|
|
*relevant_changes = has_relevant_changes;
|
|
|
|
|
|
|
|
|
|
return has_relevant_changes || has_minor_changes;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:10:15 -05:00
|
|
|
void
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
|
2013-08-01 16:10:15 -05:00
|
|
|
{
|
|
|
|
|
guint32 i, tmp;
|
2013-11-07 18:07:21 +01:00
|
|
|
const char *str;
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
g_return_if_fail (config != NULL);
|
|
|
|
|
|
|
|
|
|
g_message ("--------- NMIP4Config %p (%s)", config, detail);
|
|
|
|
|
|
2013-11-07 18:07:21 +01:00
|
|
|
str = nm_ip4_config_get_dbus_path (config);
|
|
|
|
|
if (str)
|
|
|
|
|
g_message (" path: %s", str);
|
2013-08-01 16:10:15 -05:00
|
|
|
|
2013-11-07 18:07:21 +01:00
|
|
|
/* addresses */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++)
|
|
|
|
|
g_message (" a: %s", nm_platform_ip4_address_to_string (nm_ip4_config_get_address (config, i)));
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
/* default gateway */
|
|
|
|
|
tmp = nm_ip4_config_get_gateway (config);
|
2013-10-30 22:11:21 +01:00
|
|
|
g_message (" gw: %s", nm_utils_inet4_ntop (tmp, NULL));
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
/* nameservers */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++) {
|
|
|
|
|
tmp = nm_ip4_config_get_nameserver (config, i);
|
2013-10-30 22:11:21 +01:00
|
|
|
g_message (" ns: %s", nm_utils_inet4_ntop (tmp, NULL));
|
2013-08-01 16:10:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* routes */
|
2013-11-07 18:07:21 +01:00
|
|
|
for (i = 0; i < nm_ip4_config_get_num_routes (config); i++)
|
|
|
|
|
g_message (" rt: %s", nm_platform_ip4_route_to_string (nm_ip4_config_get_route (config, i)));
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
/* domains */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_domains (config); i++)
|
|
|
|
|
g_message (" domain: %s", nm_ip4_config_get_domain (config, i));
|
|
|
|
|
|
|
|
|
|
/* dns searches */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_searches (config); i++)
|
|
|
|
|
g_message (" search: %s", nm_ip4_config_get_search (config, i));
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
/* dns options */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_dns_options (config); i++)
|
|
|
|
|
g_message (" dnsopt: %s", nm_ip4_config_get_dns_option (config, i));
|
|
|
|
|
|
|
|
|
|
|
2014-11-11 13:26:11 +01:00
|
|
|
g_message (" mss: %"G_GUINT32_FORMAT, nm_ip4_config_get_mss (config));
|
|
|
|
|
g_message (" mtu: %"G_GUINT32_FORMAT, nm_ip4_config_get_mtu (config));
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
/* NIS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++) {
|
2013-10-30 22:11:21 +01:00
|
|
|
tmp = nm_ip4_config_get_nis_server (config, i);
|
|
|
|
|
g_message (" nis: %s", nm_utils_inet4_ntop (tmp, NULL));
|
2013-08-01 16:10:15 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 19:48:48 +02:00
|
|
|
g_message (" nisdmn: %s", str_if_set (nm_ip4_config_get_nis_domain (config), "(none)"));
|
2013-08-01 16:10:15 -05:00
|
|
|
|
|
|
|
|
/* WINS */
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++) {
|
2013-10-30 22:11:21 +01:00
|
|
|
tmp = nm_ip4_config_get_wins (config, i);
|
|
|
|
|
g_message (" wins: %s", nm_utils_inet4_ntop (tmp, NULL));
|
2013-08-01 16:10:15 -05:00
|
|
|
}
|
2013-11-07 18:07:21 +01:00
|
|
|
|
|
|
|
|
g_message (" n-dflt: %d", nm_ip4_config_get_never_default (config));
|
2015-04-30 18:11:16 +02:00
|
|
|
g_message (" mtrd: %d", (int) nm_ip4_config_get_metered (config));
|
2013-08-01 16:10:15 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
gboolean
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_destination_is_direct (const NMIP4Config *config, guint32 network, int plen)
|
2008-09-05 02:55:40 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
guint naddresses = nm_ip4_config_get_num_addresses (config);
|
2013-07-03 10:26:19 +02:00
|
|
|
int i;
|
2008-09-05 02:55:40 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < naddresses; i++) {
|
2013-06-29 13:33:36 +02:00
|
|
|
const NMPlatformIP4Address *item = nm_ip4_config_get_address (config, i);
|
2013-07-03 10:26:19 +02:00
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
if (item->plen <= plen && same_prefix (item->address, network, item->plen))
|
2013-07-12 11:33:52 +02:00
|
|
|
return TRUE;
|
2013-07-03 10:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 10:26:19 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
void
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-11-07 18:07:21 +01:00
|
|
|
priv->never_default = !!never_default;
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
gboolean
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_never_default (const NMIP4Config *config)
|
2006-01-16 22:58:13 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2012-05-14 10:35:39 -04:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->never_default;
|
2006-01-16 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
void
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->gateway != gateway) {
|
|
|
|
|
priv->gateway = gateway;
|
|
|
|
|
_NOTIFY (config, PROP_GATEWAY);
|
|
|
|
|
}
|
2013-07-12 11:33:52 +02:00
|
|
|
}
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_gateway (const NMIP4Config *config)
|
2013-07-12 11:33:52 +02:00
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-08-10 22:37:21 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->gateway;
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-04 15:57:42 +02:00
|
|
|
gint64
|
|
|
|
|
nm_ip4_config_get_route_metric (const NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->route_metric;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_addresses (NMIP4Config *config)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->addresses->len != 0) {
|
|
|
|
|
g_array_set_size (priv->addresses, 0);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ADDRESS_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ADDRESSES);
|
|
|
|
|
}
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-06 14:14:14 -06:00
|
|
|
/**
|
|
|
|
|
* nm_ip4_config_add_address:
|
|
|
|
|
* @config: the #NMIP4Config
|
|
|
|
|
* @new: the new address to add to @config
|
|
|
|
|
*
|
|
|
|
|
* Adds the new address to @config. If an address with the same basic properties
|
|
|
|
|
* (address, prefix) already exists in @config, it is overwritten with the
|
|
|
|
|
* lifetime and preferred of @new. The source is also overwritten by the source
|
|
|
|
|
* from @new if that source is higher priority.
|
|
|
|
|
*/
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
2013-06-29 13:33:36 +02:00
|
|
|
nm_ip4_config_add_address (NMIP4Config *config, const NMPlatformIP4Address *new)
|
2013-06-11 17:05:49 -05:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2014-04-03 12:24:32 +02:00
|
|
|
NMPlatformIP4Address item_old;
|
2013-06-29 13:33:36 +02:00
|
|
|
int i;
|
2013-06-11 17:05:49 -05:00
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (new != NULL);
|
|
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
for (i = 0; i < priv->addresses->len; i++ ) {
|
|
|
|
|
NMPlatformIP4Address *item = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
2013-06-11 17:05:49 -05:00
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
if (addresses_are_duplicate (item, new, FALSE)) {
|
2013-09-06 11:56:41 +02:00
|
|
|
if (nm_platform_ip4_address_cmp (item, new) == 0)
|
|
|
|
|
return;
|
2014-04-03 12:24:32 +02:00
|
|
|
|
|
|
|
|
/* remember the old values. */
|
|
|
|
|
item_old = *item;
|
|
|
|
|
/* Copy over old item to get new lifetime, timestamp, preferred */
|
|
|
|
|
*item = *new;
|
|
|
|
|
|
|
|
|
|
/* But restore highest priority source */
|
|
|
|
|
item->source = MAX (item_old.source, new->source);
|
|
|
|
|
|
|
|
|
|
/* for addresses that we read from the kernel, we keep the timestamps as defined
|
|
|
|
|
* by the previous source (item_old). The reason is, that the other source configured the lifetimes
|
|
|
|
|
* with "what should be" and the kernel values are "what turned out after configuring it".
|
|
|
|
|
*
|
|
|
|
|
* For other sources, the longer lifetime wins. */
|
2014-10-13 11:52:29 +02:00
|
|
|
if ( (new->source == NM_IP_CONFIG_SOURCE_KERNEL && new->source != item_old.source)
|
2014-04-03 12:24:32 +02:00
|
|
|
|| nm_platform_ip_address_cmp_expiry ((const NMPlatformIPAddress *) &item_old, (const NMPlatformIPAddress *) new) > 0) {
|
|
|
|
|
item->timestamp = item_old.timestamp;
|
|
|
|
|
item->lifetime = item_old.lifetime;
|
|
|
|
|
item->preferred = item_old.preferred;
|
|
|
|
|
}
|
|
|
|
|
if (nm_platform_ip4_address_cmp (&item_old, item) == 0)
|
|
|
|
|
return;
|
2013-09-06 11:56:41 +02:00
|
|
|
goto NOTIFY;
|
2013-07-12 11:33:52 +02:00
|
|
|
}
|
2013-06-11 17:05:49 -05:00
|
|
|
}
|
|
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
g_array_append_val (priv->addresses, *new);
|
2013-09-06 11:56:41 +02:00
|
|
|
NOTIFY:
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ADDRESS_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ADDRESSES);
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_address (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->addresses->len);
|
|
|
|
|
|
|
|
|
|
g_array_remove_index (priv->addresses, i);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ADDRESS_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ADDRESSES);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_addresses (const NMIP4Config *config)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
return priv->addresses->len;
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
const NMPlatformIP4Address *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_address (const NMIP4Config *config, guint i)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-12-19 17:01:06 -05:00
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
return &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-02 10:20:03 -05:00
|
|
|
gboolean
|
|
|
|
|
nm_ip4_config_address_exists (const NMIP4Config *config,
|
|
|
|
|
const NMPlatformIP4Address *needle)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->addresses->len; i++) {
|
|
|
|
|
const NMPlatformIP4Address *haystack = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
|
|
|
|
|
|
|
|
|
if (needle->address == haystack->address && needle->plen == haystack->plen)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_routes (NMIP4Config *config)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->routes->len != 0) {
|
|
|
|
|
g_array_set_size (priv->routes, 0);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ROUTE_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ROUTES);
|
|
|
|
|
}
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-06 14:14:14 -06:00
|
|
|
/**
|
|
|
|
|
* nm_ip4_config_add_route:
|
|
|
|
|
* @config: the #NMIP4Config
|
|
|
|
|
* @new: the new route to add to @config
|
|
|
|
|
*
|
|
|
|
|
* Adds the new route to @config. If a route with the same basic properties
|
|
|
|
|
* (network, prefix) already exists in @config, it is overwritten including the
|
|
|
|
|
* gateway and metric of @new. The source is also overwritten by the source
|
|
|
|
|
* from @new if that source is higher priority.
|
|
|
|
|
*/
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
2013-09-24 18:19:18 +02:00
|
|
|
nm_ip4_config_add_route (NMIP4Config *config, const NMPlatformIP4Route *new)
|
2008-12-19 17:01:06 -05:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2014-10-13 11:52:29 +02:00
|
|
|
NMIPConfigSource old_source;
|
2013-07-31 23:07:32 +02:00
|
|
|
int i;
|
2008-12-19 17:01:06 -05:00
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (new != NULL);
|
2014-11-11 15:58:58 +01:00
|
|
|
g_return_if_fail (new->plen > 0);
|
2015-01-19 18:33:10 +01:00
|
|
|
g_assert (priv->ifindex);
|
2013-07-15 17:56:46 -05:00
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
for (i = 0; i < priv->routes->len; i++ ) {
|
|
|
|
|
NMPlatformIP4Route *item = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
2008-12-19 17:01:06 -05:00
|
|
|
|
2013-09-06 11:02:03 +02:00
|
|
|
if (routes_are_duplicate (item, new, FALSE)) {
|
2013-09-06 11:56:41 +02:00
|
|
|
if (nm_platform_ip4_route_cmp (item, new) == 0)
|
|
|
|
|
return;
|
2014-01-06 14:14:14 -06:00
|
|
|
old_source = item->source;
|
2013-07-31 23:07:32 +02:00
|
|
|
memcpy (item, new, sizeof (*item));
|
2014-01-06 14:14:14 -06:00
|
|
|
/* Restore highest priority source */
|
|
|
|
|
item->source = MAX (old_source, new->source);
|
2015-04-20 18:01:58 +02:00
|
|
|
item->ifindex = priv->ifindex;
|
2013-09-06 11:56:41 +02:00
|
|
|
goto NOTIFY;
|
2013-07-12 11:33:52 +02:00
|
|
|
}
|
2008-12-19 17:01:06 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
g_array_append_val (priv->routes, *new);
|
2015-01-19 18:33:10 +01:00
|
|
|
g_array_index (priv->routes, NMPlatformIP4Route, priv->routes->len - 1).ifindex = priv->ifindex;
|
2013-09-06 11:56:41 +02:00
|
|
|
NOTIFY:
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ROUTE_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ROUTES);
|
2008-12-19 17:01:06 -05:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_route (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2013-07-31 23:07:32 +02:00
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->routes->len);
|
|
|
|
|
|
|
|
|
|
g_array_remove_index (priv->routes, i);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
_NOTIFY (config, PROP_ROUTE_DATA);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_ROUTES);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_routes (const NMIP4Config *config)
|
2008-12-19 17:01:06 -05:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-12-19 17:01:06 -05:00
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
return priv->routes->len;
|
2008-12-19 17:01:06 -05:00
|
|
|
}
|
|
|
|
|
|
2013-09-24 18:19:18 +02:00
|
|
|
const NMPlatformIP4Route *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_route (const NMIP4Config *config, guint i)
|
2008-12-19 17:01:06 -05:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-12-19 17:01:06 -05:00
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
return &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
2008-12-19 17:01:06 -05:00
|
|
|
}
|
|
|
|
|
|
2014-08-28 23:36:45 +02:00
|
|
|
const NMPlatformIP4Route *
|
|
|
|
|
nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2014-11-06 21:01:22 +01:00
|
|
|
guint i;
|
2014-08-28 23:36:45 +02:00
|
|
|
NMPlatformIP4Route *best_route = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (host, NULL);
|
|
|
|
|
|
2014-11-06 21:01:22 +01:00
|
|
|
for (i = 0; i < priv->routes->len; i++) {
|
2014-08-28 23:36:45 +02:00
|
|
|
NMPlatformIP4Route *item = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
|
|
|
|
|
|
|
|
|
if (item->gateway != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (best_route && best_route->plen > item->plen)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (nm_utils_ip4_address_clear_host_address (host, item->plen) != nm_utils_ip4_address_clear_host_address (item->network, item->plen))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (best_route && best_route->metric <= item->metric)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
best_route = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return best_route;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 21:01:22 +01:00
|
|
|
const NMPlatformIP4Address *
|
|
|
|
|
nm_ip4_config_get_subnet_for_host (const NMIP4Config *config, guint32 host)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
guint i;
|
|
|
|
|
NMPlatformIP4Address *subnet = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (host, NULL);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->addresses->len; i++) {
|
|
|
|
|
NMPlatformIP4Address *item = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
|
|
|
|
|
|
|
|
|
if (subnet && subnet->plen >= item->plen)
|
|
|
|
|
continue;
|
|
|
|
|
if (nm_utils_ip4_address_clear_host_address (host, item->plen) != nm_utils_ip4_address_clear_host_address (item->address, item->plen))
|
|
|
|
|
continue;
|
|
|
|
|
subnet = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return subnet;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2008-06-02 08:44:48 +00:00
|
|
|
void
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_reset_nameservers (NMIP4Config *config)
|
2007-11-28 22:38:33 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2007-11-28 22:38:33 +00:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->nameservers->len != 0) {
|
|
|
|
|
g_array_set_size (priv->nameservers, 0);
|
|
|
|
|
_NOTIFY (config, PROP_NAMESERVERS);
|
|
|
|
|
}
|
2007-11-28 22:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-02 08:44:48 +00:00
|
|
|
void
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_add_nameserver (NMIP4Config *config, guint32 new)
|
2007-11-28 22:38:33 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
int i;
|
2007-11-28 22:38:33 +00:00
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (new != 0);
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < priv->nameservers->len; i++)
|
|
|
|
|
if (new == g_array_index (priv->nameservers, guint32, i))
|
2012-05-14 10:35:39 -04:00
|
|
|
return;
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_append_val (priv->nameservers, new);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_NAMESERVERS);
|
2008-06-02 08:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_nameserver (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->nameservers->len);
|
|
|
|
|
|
|
|
|
|
g_array_remove_index (priv->nameservers, i);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_NAMESERVERS);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_nameservers (const NMIP4Config *config)
|
2008-06-02 08:44:48 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-08-10 22:37:21 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->nameservers->len;
|
2008-06-02 08:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_nameserver (const NMIP4Config *config, guint i)
|
2008-06-02 08:44:48 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-06-02 08:44:48 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return g_array_index (priv->nameservers, guint32, i);
|
2007-11-28 22:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
2007-11-28 22:38:33 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_domains (NMIP4Config *config)
|
2008-08-06 22:23:48 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->domains->len != 0) {
|
|
|
|
|
g_ptr_array_set_size (priv->domains, 0);
|
|
|
|
|
_NOTIFY (config, PROP_DOMAINS);
|
|
|
|
|
}
|
2008-08-06 22:23:48 +00:00
|
|
|
}
|
2008-03-09 05:11:22 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_add_domain (NMIP4Config *config, const char *domain)
|
2008-03-09 05:11:22 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2009-05-11 20:02:07 -04:00
|
|
|
int i;
|
|
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (domain != NULL);
|
|
|
|
|
g_return_if_fail (domain[0] != '\0');
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < priv->domains->len; i++)
|
|
|
|
|
if (!g_strcmp0 (g_ptr_array_index (priv->domains, i), domain))
|
2009-05-11 20:02:07 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->domains, g_strdup (domain));
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_DOMAINS);
|
2008-03-09 05:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_domain (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->domains->len);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_remove_index (priv->domains, i);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_DOMAINS);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_domains (const NMIP4Config *config)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->domains->len;
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
const char *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_domain (const NMIP4Config *config, guint i)
|
2005-04-15 15:43:42 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2005-04-15 15:43:42 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return g_ptr_array_index (priv->domains, i);
|
2005-04-15 15:43:42 +00:00
|
|
|
}
|
2005-10-28 03:16:02 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
2009-05-11 20:02:07 -04:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_searches (NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2009-05-11 20:02:07 -04:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->searches->len != 0) {
|
|
|
|
|
g_ptr_array_set_size (priv->searches, 0);
|
|
|
|
|
_NOTIFY (config, PROP_SEARCHES);
|
|
|
|
|
}
|
2009-05-11 20:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_add_search (NMIP4Config *config, const char *new)
|
2008-03-09 05:11:22 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2009-05-11 20:02:07 -04:00
|
|
|
int i;
|
|
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (new != NULL);
|
|
|
|
|
g_return_if_fail (new[0] != '\0');
|
2009-05-11 20:02:07 -04:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < priv->searches->len; i++)
|
|
|
|
|
if (!g_strcmp0 (g_ptr_array_index (priv->searches, i), new))
|
2009-05-11 20:02:07 -04:00
|
|
|
return;
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_ptr_array_add (priv->searches, g_strdup (new));
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_SEARCHES);
|
2008-03-09 05:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_search (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->searches->len);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_remove_index (priv->searches, i);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_SEARCHES);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_searches (const NMIP4Config *config)
|
2008-03-09 05:11:22 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-03-09 05:11:22 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->searches->len;
|
2008-03-09 05:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
const char *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_search (const NMIP4Config *config, guint i)
|
2008-03-09 05:11:22 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-03-09 05:11:22 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return g_ptr_array_index (priv->searches, i);
|
2008-03-09 05:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-03-26 09:23:12 +01:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_dns_options (NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
if (priv->dns_options->len != 0) {
|
|
|
|
|
g_ptr_array_set_size (priv->dns_options, 0);
|
|
|
|
|
_NOTIFY (config, PROP_DNS_OPTIONS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_ip4_config_add_dns_option (NMIP4Config *config, const char *new)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (new != NULL);
|
|
|
|
|
g_return_if_fail (new[0] != '\0');
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->dns_options->len; i++)
|
|
|
|
|
if (!g_strcmp0 (g_ptr_array_index (priv->dns_options, i), new))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->dns_options, g_strdup (new));
|
|
|
|
|
_NOTIFY (config, PROP_DNS_OPTIONS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_dns_option(NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->dns_options->len);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_remove_index (priv->dns_options, i);
|
|
|
|
|
_NOTIFY (config, PROP_DNS_OPTIONS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint32
|
|
|
|
|
nm_ip4_config_get_num_dns_options (const NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->dns_options->len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
nm_ip4_config_get_dns_option (const NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return g_ptr_array_index (priv->dns_options, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_set_mss (NMIP4Config *config, guint32 mss)
|
2008-05-23 07:35:43 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-05-23 07:35:43 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
priv->mss = mss;
|
|
|
|
|
}
|
2008-05-23 07:35:43 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_mss (const NMIP4Config *config)
|
2013-07-12 11:33:52 +02:00
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->mss;
|
2008-05-23 07:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_nis_servers (NMIP4Config *config)
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_set_size (priv->nis, 0);
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_add_nis_server (NMIP4Config *config, guint32 nis)
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->nis->len; i++)
|
|
|
|
|
if (nis == g_array_index (priv->nis, guint32, i))
|
|
|
|
|
return;
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_append_val (priv->nis, nis);
|
2006-03-29 Robert Love <rml@novell.com>
Patch by Vinay R <rvinay@novell.com> and Robert Love <rml@novell.com>,
to add support for per-route MSS and improve support for per-interface
MTU:
* src/NetworkManagerSystem.c: Modify nm_system_device_set_ip4_route to
optionally take an MSS parameter and set it for the given route.
Remove nm_system_device_set_ip4_route_with_iface. Pass in the
NMIP4Config's stored MSS, if any.
* src/nm-ip4-config.c: Add 'mtu' and 'mss' to NMIP4Config, representing
the interface's MTU and the route's MSS, respectively. Add functions
nm_ip4_config_get_mtu, nm_ip4_config_set_mtu, nm_ip4_config_get_mss,
and nm_ip4_config_set_mss for retrieving and setting the MTU and the
MSS.
* src/nm-ip4-config.h: Add prototypes for nm_ip4_config_get_mtu,
nm_ip4_config_set_mtu, nm_ip4_config_get_mss, and
nm_ip4_config_set_mss.
* src/vpn-manager/nm-vpn-service.c: Modify to receive the MSS from the
VPN daemon.
* src/backends/NetworkManager{Arch,Debian,Gentoo,RedHat,Slackware,SUSE}.c:
Change the retval of nm_system_get_mtu to guint32.
* src/dhcp-manager/nm-dhcp-manager.c: Set the MTU on the new DHCP-given
NMIP4Config to the MTU provided by the system, if any. TODO: If DHCP
servers can specify MTU's, we should set it here if the MTU was not
provided.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1660 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2006-03-29 19:26:53 +00:00
|
|
|
}
|
2005-10-28 03:16:02 +00:00
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_nis_server (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->nis->len);
|
|
|
|
|
|
|
|
|
|
g_array_remove_index (priv->nis, i);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_nis_servers (const NMIP4Config *config)
|
2008-12-09 20:01:49 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-12-09 20:01:49 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->nis->len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_nis_server (const NMIP4Config *config, guint i)
|
2013-07-12 11:33:52 +02:00
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return g_array_index (priv->nis, guint32, i);
|
2008-12-09 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-07-12 11:33:52 +02:00
|
|
|
nm_ip4_config_set_nis_domain (NMIP4Config *config, const char *domain)
|
2008-12-09 20:01:49 +00:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2008-12-09 20:01:49 +00:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_free (priv->nis_domain);
|
|
|
|
|
priv->nis_domain = g_strdup (domain);
|
2008-12-09 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
const char *
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_nis_domain (const NMIP4Config *config)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->nis_domain;
|
|
|
|
|
}
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_reset_wins (NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
if (priv->wins->len != 0) {
|
|
|
|
|
g_array_set_size (priv->wins, 0);
|
|
|
|
|
_NOTIFY (config, PROP_WINS_SERVERS);
|
|
|
|
|
}
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_add_wins (NMIP4Config *config, guint32 wins)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-07-15 17:56:46 -05:00
|
|
|
g_return_if_fail (wins != 0);
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
for (i = 0; i < priv->wins->len; i++)
|
|
|
|
|
if (wins == g_array_index (priv->wins, guint32, i))
|
|
|
|
|
return;
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_append_val (priv->wins, wins);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_WINS_SERVERS);
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 14:04:35 -05:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_del_wins (NMIP4Config *config, guint i)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (i < priv->wins->len);
|
|
|
|
|
|
|
|
|
|
g_array_remove_index (priv->wins, i);
|
2013-09-06 11:56:41 +02:00
|
|
|
_NOTIFY (config, PROP_WINS_SERVERS);
|
2013-08-01 14:04:35 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_num_wins (const NMIP4Config *config)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->wins->len;
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_wins (const NMIP4Config *config, guint i)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return g_array_index (priv->wins, guint32, i);
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2010-07-16 11:28:39 -07:00
|
|
|
void
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2014-10-09 18:51:11 +02:00
|
|
|
if (source > priv->mtu_source) {
|
|
|
|
|
priv->mtu = mtu;
|
|
|
|
|
priv->mtu_source = source;
|
|
|
|
|
} else if (source == priv->mtu_source && (!priv->mtu || priv->mtu > mtu))
|
|
|
|
|
priv->mtu = mtu;
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
guint32
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_get_mtu (const NMIP4Config *config)
|
2010-07-16 11:28:39 -07:00
|
|
|
{
|
2013-07-12 11:33:52 +02:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
2010-07-16 11:28:39 -07:00
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
return priv->mtu;
|
2010-07-16 11:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-09 18:51:11 +02:00
|
|
|
NMIPConfigSource
|
|
|
|
|
nm_ip4_config_get_mtu_source (const NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->mtu_source;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-04-30 18:11:16 +02:00
|
|
|
void
|
|
|
|
|
nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
priv->metered = !!metered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
nm_ip4_config_get_metered (const NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
|
|
|
|
return priv->metered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2012-05-29 22:24:51 -05:00
|
|
|
static inline void
|
|
|
|
|
hash_u32 (GChecksum *sum, guint32 n)
|
|
|
|
|
{
|
|
|
|
|
g_checksum_update (sum, (const guint8 *) &n, sizeof (n));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_hash (const NMIP4Config *config, GChecksum *sum, gboolean dns_only)
|
2012-05-29 22:24:51 -05:00
|
|
|
{
|
2013-12-02 10:20:26 -05:00
|
|
|
guint32 i;
|
2012-05-29 22:24:51 -05:00
|
|
|
const char *s;
|
|
|
|
|
|
2013-07-04 15:40:01 +02:00
|
|
|
g_return_if_fail (config);
|
|
|
|
|
g_return_if_fail (sum);
|
2012-05-29 22:24:51 -05:00
|
|
|
|
2013-07-04 15:40:01 +02:00
|
|
|
if (!dns_only) {
|
2013-07-12 11:33:52 +02:00
|
|
|
hash_u32 (sum, nm_ip4_config_get_gateway (config));
|
|
|
|
|
|
2012-05-29 22:24:51 -05:00
|
|
|
for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
|
2013-06-29 13:33:36 +02:00
|
|
|
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
|
|
|
|
|
hash_u32 (sum, address->address);
|
|
|
|
|
hash_u32 (sum, address->plen);
|
2012-05-29 22:24:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_routes (config); i++) {
|
2013-07-31 23:07:32 +02:00
|
|
|
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
|
2012-05-29 22:24:51 -05:00
|
|
|
|
2013-07-31 23:07:32 +02:00
|
|
|
hash_u32 (sum, route->network);
|
|
|
|
|
hash_u32 (sum, route->plen);
|
|
|
|
|
hash_u32 (sum, route->gateway);
|
|
|
|
|
hash_u32 (sum, route->metric);
|
2012-05-29 22:24:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++)
|
|
|
|
|
hash_u32 (sum, nm_ip4_config_get_nis_server (config, i));
|
|
|
|
|
|
|
|
|
|
s = nm_ip4_config_get_nis_domain (config);
|
|
|
|
|
if (s)
|
|
|
|
|
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++)
|
|
|
|
|
hash_u32 (sum, nm_ip4_config_get_nameserver (config, i));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++)
|
|
|
|
|
hash_u32 (sum, nm_ip4_config_get_wins (config, i));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_domains (config); i++) {
|
|
|
|
|
s = nm_ip4_config_get_domain (config, i);
|
|
|
|
|
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_searches (config); i++) {
|
|
|
|
|
s = nm_ip4_config_get_search (config, i);
|
|
|
|
|
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
|
|
|
|
}
|
2015-03-26 09:23:12 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < nm_ip4_config_get_num_dns_options (config); i++) {
|
|
|
|
|
s = nm_ip4_config_get_dns_option (config, i);
|
|
|
|
|
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 22:24:51 -05:00
|
|
|
}
|
|
|
|
|
|
2014-01-06 14:14:14 -06:00
|
|
|
/**
|
|
|
|
|
* nm_ip4_config_equal:
|
|
|
|
|
* @a: first config to compare
|
|
|
|
|
* @b: second config to compare
|
|
|
|
|
*
|
|
|
|
|
* Compares two #NMIP4Configs for basic equality. This means that all
|
|
|
|
|
* attributes must exist in the same order in both configs (addresses, routes,
|
|
|
|
|
* domains, DNS servers, etc) but some attributes (address lifetimes, and address
|
|
|
|
|
* and route sources) are ignored.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the configurations are basically equal to each other,
|
|
|
|
|
* %FALSE if not
|
|
|
|
|
*/
|
2013-07-04 15:40:01 +02:00
|
|
|
gboolean
|
2013-09-25 13:08:53 +02:00
|
|
|
nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b)
|
2013-07-04 15:40:01 +02:00
|
|
|
{
|
|
|
|
|
GChecksum *a_checksum = g_checksum_new (G_CHECKSUM_SHA1);
|
|
|
|
|
GChecksum *b_checksum = g_checksum_new (G_CHECKSUM_SHA1);
|
|
|
|
|
gsize a_len = g_checksum_type_get_length (G_CHECKSUM_SHA1);
|
|
|
|
|
gsize b_len = g_checksum_type_get_length (G_CHECKSUM_SHA1);
|
|
|
|
|
guchar a_data[a_len], b_data[b_len];
|
|
|
|
|
gboolean equal;
|
|
|
|
|
|
|
|
|
|
if (a)
|
|
|
|
|
nm_ip4_config_hash (a, a_checksum, FALSE);
|
|
|
|
|
if (b)
|
|
|
|
|
nm_ip4_config_hash (b, b_checksum, FALSE);
|
|
|
|
|
|
|
|
|
|
g_checksum_get_digest (a_checksum, a_data, &a_len);
|
|
|
|
|
g_checksum_get_digest (b_checksum, b_data, &b_len);
|
|
|
|
|
|
|
|
|
|
g_assert (a_len == b_len);
|
|
|
|
|
equal = !memcmp (a_data, b_data, a_len);
|
|
|
|
|
|
|
|
|
|
g_checksum_free (a_checksum);
|
|
|
|
|
g_checksum_free (b_checksum);
|
|
|
|
|
|
|
|
|
|
return equal;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 11:33:52 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
static void
|
|
|
|
|
nm_ip4_config_init (NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
|
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address));
|
2013-07-31 23:07:32 +02:00
|
|
|
priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route));
|
2013-07-12 11:33:52 +02:00
|
|
|
priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32));
|
|
|
|
|
priv->domains = g_ptr_array_new_with_free_func (g_free);
|
|
|
|
|
priv->searches = g_ptr_array_new_with_free_func (g_free);
|
2015-03-26 09:23:12 +01:00
|
|
|
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
2010-07-16 11:28:39 -07:00
|
|
|
priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32));
|
2013-07-12 11:33:52 +02:00
|
|
|
priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32));
|
2015-06-04 15:57:42 +02:00
|
|
|
priv->route_metric = -1;
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
|
|
|
|
|
|
2015-01-28 22:48:53 +01:00
|
|
|
g_free (priv->path);
|
|
|
|
|
|
2013-06-29 13:33:36 +02:00
|
|
|
g_array_unref (priv->addresses);
|
2013-08-08 10:14:38 -05:00
|
|
|
g_array_unref (priv->routes);
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_unref (priv->nameservers);
|
|
|
|
|
g_ptr_array_unref (priv->domains);
|
|
|
|
|
g_ptr_array_unref (priv->searches);
|
2015-03-26 09:23:12 +01:00
|
|
|
g_ptr_array_unref (priv->dns_options);
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_unref (priv->nis);
|
2010-07-16 11:28:39 -07:00
|
|
|
g_free (priv->nis_domain);
|
2013-07-12 11:33:52 +02:00
|
|
|
g_array_unref (priv->wins);
|
2009-02-25 13:50:34 -05:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object);
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-07 10:55:58 -05:00
|
|
|
static void
|
|
|
|
|
gvalue_destroy (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GValue *value = (GValue *) data;
|
|
|
|
|
|
|
|
|
|
g_value_unset (value);
|
|
|
|
|
g_slice_free (GValue, value);
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2013-06-29 13:33:36 +02:00
|
|
|
NMIP4Config *config = NM_IP4_CONFIG (object);
|
2007-02-16 11:23:49 +00:00
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-02-20 16:31:10 -06:00
|
|
|
case PROP_IFINDEX:
|
|
|
|
|
g_value_set_int (value, priv->ifindex);
|
|
|
|
|
break;
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
case PROP_ADDRESS_DATA:
|
|
|
|
|
{
|
|
|
|
|
GPtrArray *addresses = g_ptr_array_new ();
|
|
|
|
|
int naddr = nm_ip4_config_get_num_addresses (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < naddr; i++) {
|
|
|
|
|
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
|
2014-11-07 10:55:58 -05:00
|
|
|
GHashTable *addr_hash;
|
|
|
|
|
GValue *val;
|
|
|
|
|
|
|
|
|
|
addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
|
|
|
|
|
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_STRING);
|
|
|
|
|
g_value_set_string (val, nm_utils_inet4_ntop (address->address, NULL));
|
|
|
|
|
g_hash_table_insert (addr_hash, "address", val);
|
|
|
|
|
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_UINT);
|
|
|
|
|
g_value_set_uint (val, address->plen);
|
|
|
|
|
g_hash_table_insert (addr_hash, "prefix", val);
|
|
|
|
|
|
|
|
|
|
if (*address->label) {
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_STRING);
|
|
|
|
|
g_value_set_string (val, address->label);
|
|
|
|
|
g_hash_table_insert (addr_hash, "label", val);
|
|
|
|
|
}
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
|
2014-11-07 10:55:58 -05:00
|
|
|
g_ptr_array_add (addresses, addr_hash);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_take_boxed (value, addresses);
|
|
|
|
|
}
|
2013-09-06 11:56:41 +02:00
|
|
|
break;
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
case PROP_ADDRESSES:
|
2013-06-29 13:33:36 +02:00
|
|
|
{
|
|
|
|
|
GPtrArray *addresses = g_ptr_array_new ();
|
|
|
|
|
int naddr = nm_ip4_config_get_num_addresses (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < naddr; i++) {
|
|
|
|
|
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
|
|
|
|
|
GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
|
2014-10-20 20:36:57 -04:00
|
|
|
guint32 gateway = i == 0 ? priv->gateway : 0;
|
2013-06-29 13:33:36 +02:00
|
|
|
|
|
|
|
|
g_array_append_val (array, address->address);
|
|
|
|
|
g_array_append_val (array, address->plen);
|
2014-10-20 20:36:57 -04:00
|
|
|
g_array_append_val (array, gateway);
|
2013-06-29 13:33:36 +02:00
|
|
|
|
|
|
|
|
g_ptr_array_add (addresses, array);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_take_boxed (value, addresses);
|
|
|
|
|
}
|
2007-02-16 11:23:49 +00:00
|
|
|
break;
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
case PROP_ROUTE_DATA:
|
|
|
|
|
{
|
|
|
|
|
GPtrArray *routes = g_ptr_array_new ();
|
|
|
|
|
guint nroutes = nm_ip4_config_get_num_routes (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nroutes; i++) {
|
|
|
|
|
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
|
2014-11-07 10:55:58 -05:00
|
|
|
GHashTable *route_hash;
|
|
|
|
|
GValue *val;
|
|
|
|
|
|
|
|
|
|
route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
|
|
|
|
|
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_STRING);
|
|
|
|
|
g_value_set_string (val, nm_utils_inet4_ntop (route->network, NULL));
|
|
|
|
|
g_hash_table_insert (route_hash, "dest", val);
|
|
|
|
|
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_UINT);
|
|
|
|
|
g_value_set_uint (val, route->plen);
|
|
|
|
|
g_hash_table_insert (route_hash, "prefix", val);
|
|
|
|
|
|
|
|
|
|
if (route->gateway) {
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_STRING);
|
|
|
|
|
g_value_set_string (val, nm_utils_inet4_ntop (route->gateway, NULL));
|
2014-11-18 08:30:16 -05:00
|
|
|
g_hash_table_insert (route_hash, "next-hop", val);
|
2014-11-07 10:55:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (val, G_TYPE_UINT);
|
|
|
|
|
g_value_set_uint (val, route->metric);
|
|
|
|
|
g_hash_table_insert (route_hash, "metric", val);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (routes, route_hash);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_take_boxed (value, routes);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-07-12 11:33:52 +02:00
|
|
|
case PROP_ROUTES:
|
2013-07-31 23:07:32 +02:00
|
|
|
{
|
|
|
|
|
GPtrArray *routes = g_ptr_array_new ();
|
|
|
|
|
guint nroutes = nm_ip4_config_get_num_routes (config);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nroutes; i++) {
|
|
|
|
|
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
|
2014-08-29 00:03:47 +02:00
|
|
|
GArray *array;
|
2013-07-31 23:07:32 +02:00
|
|
|
|
2014-08-29 00:03:47 +02:00
|
|
|
/* legacy versions of nm_ip4_route_set_prefix() in libnm-util assert that the
|
|
|
|
|
* plen is positive. Skip the default routes not to break older clients. */
|
|
|
|
|
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
|
2013-07-31 23:07:32 +02:00
|
|
|
g_array_append_val (array, route->network);
|
|
|
|
|
g_array_append_val (array, route->plen);
|
|
|
|
|
g_array_append_val (array, route->gateway);
|
|
|
|
|
g_array_append_val (array, route->metric);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (routes, array);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_take_boxed (value, routes);
|
|
|
|
|
}
|
2013-07-12 11:33:52 +02:00
|
|
|
break;
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
case PROP_GATEWAY:
|
|
|
|
|
if (priv->gateway)
|
|
|
|
|
g_value_set_string (value, nm_utils_inet4_ntop (priv->gateway, NULL));
|
|
|
|
|
else
|
|
|
|
|
g_value_set_string (value, NULL);
|
|
|
|
|
break;
|
2007-02-16 11:23:49 +00:00
|
|
|
case PROP_NAMESERVERS:
|
|
|
|
|
g_value_set_boxed (value, priv->nameservers);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_DOMAINS:
|
|
|
|
|
g_value_set_boxed (value, priv->domains);
|
|
|
|
|
break;
|
2013-09-06 11:56:41 +02:00
|
|
|
case PROP_SEARCHES:
|
|
|
|
|
g_value_set_boxed (value, priv->searches);
|
|
|
|
|
break;
|
2015-03-26 09:23:12 +01:00
|
|
|
case PROP_DNS_OPTIONS:
|
|
|
|
|
g_value_set_boxed (value, priv->dns_options);
|
|
|
|
|
break;
|
2008-12-19 17:01:06 -05:00
|
|
|
case PROP_WINS_SERVERS:
|
|
|
|
|
g_value_set_boxed (value, priv->wins);
|
|
|
|
|
break;
|
2007-02-16 11:23:49 +00:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 16:31:10 -06:00
|
|
|
static void
|
|
|
|
|
set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_IFINDEX:
|
|
|
|
|
priv->ifindex = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
static void
|
|
|
|
|
nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (config_class, sizeof (NMIP4ConfigPrivate));
|
|
|
|
|
|
|
|
|
|
object_class->get_property = get_property;
|
2015-02-20 16:31:10 -06:00
|
|
|
object_class->set_property = set_property;
|
2007-02-16 11:23:49 +00:00
|
|
|
object_class->finalize = finalize;
|
|
|
|
|
|
2015-02-20 16:31:10 -06:00
|
|
|
obj_properties[PROP_IFINDEX] =
|
|
|
|
|
g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "",
|
|
|
|
|
-1, G_MAXINT, -1,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
obj_properties[PROP_ADDRESS_DATA] =
|
|
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_ADDRESS_DATA, "", "",
|
|
|
|
|
DBUS_TYPE_NM_IP_ADDRESSES,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_ADDRESSES] =
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "",
|
|
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_ROUTE_DATA] =
|
|
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_ROUTE_DATA, "", "",
|
|
|
|
|
DBUS_TYPE_NM_IP_ROUTES,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_ROUTES] =
|
libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.
This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.
NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.
The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-10-21 08:33:18 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "",
|
|
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_GATEWAY] =
|
|
|
|
|
g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
|
|
|
|
|
NULL,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_NAMESERVERS] =
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "",
|
2013-07-12 11:33:52 +02:00
|
|
|
DBUS_TYPE_G_UINT_ARRAY,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_DOMAINS] =
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "",
|
2013-07-12 11:33:52 +02:00
|
|
|
DBUS_TYPE_G_ARRAY_OF_STRING,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_SEARCHES] =
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "",
|
2013-09-06 11:56:41 +02:00
|
|
|
DBUS_TYPE_G_ARRAY_OF_STRING,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2015-03-26 09:23:12 +01:00
|
|
|
obj_properties[PROP_DNS_OPTIONS] =
|
|
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_DNS_OPTIONS, "", "",
|
|
|
|
|
DBUS_TYPE_G_ARRAY_OF_STRING,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
2013-09-06 11:56:41 +02:00
|
|
|
obj_properties[PROP_WINS_SERVERS] =
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "",
|
2013-07-12 11:33:52 +02:00
|
|
|
DBUS_TYPE_G_UINT_ARRAY,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2013-09-06 11:56:41 +02:00
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
|
2007-11-28 22:38:33 +00:00
|
|
|
|
2014-01-08 17:53:04 -06:00
|
|
|
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
|
|
|
|
|
G_TYPE_FROM_CLASS (config_class),
|
|
|
|
|
&dbus_glib_nm_ip4_config_object_info);
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|