2008-11-03 16:05:11 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager system settings service - keyfile plugin
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2010-01-08 11:23:39 -08:00
|
|
|
* Copyright (C) 2008 - 2009 Novell, Inc.
|
2011-07-07 15:25:11 +02:00
|
|
|
* Copyright (C) 2008 - 2011 Red Hat, Inc.
|
2008-11-03 16:05:11 +00:00
|
|
|
*/
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-07-07 18:57:37 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdlib.h>
|
2008-04-22 14:48:02 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <nm-setting.h>
|
2008-05-08 01:02:42 +00:00
|
|
|
#include <nm-setting-ip4-config.h>
|
2010-01-08 11:23:39 -08:00
|
|
|
#include <nm-setting-ip6-config.h>
|
2008-08-11 17:13:22 +00:00
|
|
|
#include <nm-setting-vpn.h>
|
2008-10-27 17:07:42 +00:00
|
|
|
#include <nm-setting-connection.h>
|
2009-01-12 14:21:44 -05:00
|
|
|
#include <nm-setting-wired.h>
|
|
|
|
|
#include <nm-setting-wireless.h>
|
2010-05-25 23:34:09 -07:00
|
|
|
#include <nm-setting-bluetooth.h>
|
2011-03-02 18:17:57 -06:00
|
|
|
#include <nm-setting-8021x.h>
|
2011-10-10 16:00:28 -04:00
|
|
|
#include <nm-utils.h>
|
2008-05-08 01:02:42 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <string.h>
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-05-08 01:02:42 +00:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2013-02-24 13:01:08 +01:00
|
|
|
#include "nm-glib-compat.h"
|
2011-06-01 16:44:02 -05:00
|
|
|
#include "nm-system-config-interface.h"
|
2014-04-05 09:37:04 -04:00
|
|
|
#include "nm-logging.h"
|
2008-04-22 14:48:02 +00:00
|
|
|
#include "reader.h"
|
2010-09-16 17:39:06 -05:00
|
|
|
#include "common.h"
|
2013-04-03 11:48:04 -05:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
|
/* Some setting properties also contain setting names, such as
|
|
|
|
|
* NMSettingConnection's 'type' property (which specifies the base type of the
|
2013-11-29 08:40:30 +01:00
|
|
|
* connection, e.g. ethernet or wifi) or 'slave-type' (specifies type of slave
|
|
|
|
|
* connection, e.g. bond or bridge). This function handles translating those
|
|
|
|
|
* properties' values to the real setting name if they are an alias.
|
2013-04-03 11:48:04 -05:00
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
setting_alias_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
|
|
|
|
char *s;
|
|
|
|
|
const char *key_setting_name;
|
|
|
|
|
|
|
|
|
|
s = nm_keyfile_plugin_kf_get_string (keyfile, setting_name, key, NULL);
|
|
|
|
|
if (s) {
|
|
|
|
|
key_setting_name = nm_keyfile_plugin_get_setting_name_for_alias (s);
|
|
|
|
|
g_object_set (G_OBJECT (setting),
|
|
|
|
|
key, key_setting_name ? key_setting_name : s,
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-05-08 01:02:42 +00:00
|
|
|
static gboolean
|
|
|
|
|
read_array_of_uint (GKeyFile *file,
|
|
|
|
|
NMSetting *setting,
|
|
|
|
|
const char *key)
|
|
|
|
|
{
|
|
|
|
|
GArray *array = NULL;
|
|
|
|
|
gsize length;
|
|
|
|
|
int i;
|
2009-01-12 14:21:44 -05:00
|
|
|
gint *tmp;
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp = nm_keyfile_plugin_kf_get_integer_list (file, nm_setting_get_name (setting), key, &length, NULL);
|
2009-01-12 14:21:44 -05:00
|
|
|
array = g_array_sized_new (FALSE, FALSE, sizeof (guint32), length);
|
2012-10-02 17:59:47 +02:00
|
|
|
g_return_val_if_fail (array != NULL, FALSE);
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
|
g_array_append_val (array, tmp[i]);
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2012-10-02 17:59:47 +02:00
|
|
|
g_object_set (setting, key, array, NULL);
|
|
|
|
|
g_array_unref (array);
|
2008-05-08 01:02:42 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
static gboolean
|
|
|
|
|
get_one_int (const char *str, guint32 max_val, const char *key_name, guint32 *out)
|
|
|
|
|
{
|
|
|
|
|
long tmp;
|
2013-12-04 14:18:31 +01:00
|
|
|
char *endptr;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
if (!str || !str[0]) {
|
|
|
|
|
if (key_name)
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring missing number %s", __func__, key_name);
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
errno = 0;
|
2013-12-04 14:18:31 +01:00
|
|
|
tmp = strtol (str, &endptr, 10);
|
|
|
|
|
if (errno || (tmp < 0) || (tmp > max_val) || *endptr != 0) {
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
if (key_name)
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid number %s '%s'", __func__, key_name, str);
|
2008-08-06 22:23:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*out = (guint32) tmp;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
static gpointer
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
build_ip4_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
|
2008-05-08 01:02:42 +00:00
|
|
|
{
|
2014-06-24 12:46:03 -04:00
|
|
|
gpointer result;
|
2013-07-31 23:59:50 +02:00
|
|
|
guint32 addr;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
guint32 address = 0;
|
|
|
|
|
guint32 gateway = 0;
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
guint32 metric = 0;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (address_str, NULL);
|
|
|
|
|
|
|
|
|
|
/* Address */
|
|
|
|
|
err = inet_pton (AF_INET, address_str, &addr);
|
|
|
|
|
if (err <= 0) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 address '%s'", __func__, address_str);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-07-31 23:59:50 +02:00
|
|
|
address = addr;
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* Gateway */
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
if (gateway_str && gateway_str[0]) {
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
err = inet_pton (AF_INET, gateway_str, &addr);
|
|
|
|
|
if (err <= 0) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 gateway '%s'", __func__, gateway_str);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
return NULL;
|
2008-05-08 01:02:42 +00:00
|
|
|
}
|
2013-07-31 23:59:50 +02:00
|
|
|
gateway = addr;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gateway = 0;
|
2008-05-08 01:02:42 +00:00
|
|
|
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
/* parse metric, default to 0 */
|
|
|
|
|
if (metric_str) {
|
|
|
|
|
if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
if (route) {
|
|
|
|
|
result = nm_ip4_route_new ();
|
|
|
|
|
nm_ip4_route_set_dest (result, address);
|
|
|
|
|
nm_ip4_route_set_prefix (result, plen);
|
|
|
|
|
nm_ip4_route_set_next_hop (result, gateway);
|
|
|
|
|
nm_ip4_route_set_metric (result, metric);
|
|
|
|
|
} else {
|
|
|
|
|
result = nm_ip4_address_new ();
|
|
|
|
|
nm_ip4_address_set_address (result, address);
|
|
|
|
|
nm_ip4_address_set_prefix (result, plen);
|
|
|
|
|
nm_ip4_address_set_gateway (result, gateway);
|
|
|
|
|
}
|
2008-07-07 18:57:37 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
static gpointer
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
{
|
2014-06-24 12:46:03 -04:00
|
|
|
gpointer result;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
struct in6_addr addr;
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
guint32 metric = 0;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
int err;
|
2008-05-08 01:02:42 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
g_return_val_if_fail (address_str, NULL);
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
if (route)
|
|
|
|
|
result = nm_ip6_route_new ();
|
|
|
|
|
else
|
|
|
|
|
result = nm_ip6_address_new ();
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
/* add address and prefix length */
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
err = inet_pton (AF_INET6, address_str, &addr);
|
|
|
|
|
if (err <= 0) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
goto error_out;
|
2008-05-08 01:02:42 +00:00
|
|
|
}
|
2014-06-24 12:46:03 -04:00
|
|
|
if (route) {
|
|
|
|
|
nm_ip6_route_set_dest (result, &addr);
|
|
|
|
|
nm_ip6_route_set_prefix (result, plen);
|
|
|
|
|
} else {
|
|
|
|
|
nm_ip6_address_set_address (result, &addr);
|
|
|
|
|
nm_ip6_address_set_prefix (result, plen);
|
|
|
|
|
}
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
|
|
|
|
/* add gateway */
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
if (gateway_str && gateway_str[0]) {
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
err = inet_pton (AF_INET6, gateway_str, &addr);
|
|
|
|
|
if (err <= 0) {
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
/* Try workaround for routes written by broken keyfile writer.
|
|
|
|
|
* Due to bug bgo#719851, an older version of writer would have
|
|
|
|
|
* written "a:b:c:d::/plen,metric" if the gateway was ::, instead
|
|
|
|
|
* of "a:b:c:d::/plen,,metric" or "a:b:c:d::/plen,::,metric"
|
|
|
|
|
* Try workaround by interepeting gateway_str as metric to accept such
|
|
|
|
|
* invalid routes. This broken syntax should not be not officially
|
|
|
|
|
* supported.
|
|
|
|
|
**/
|
|
|
|
|
if (route && !metric_str && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric))
|
|
|
|
|
addr = in6addr_any;
|
|
|
|
|
else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
goto error_out;
|
|
|
|
|
}
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
}
|
|
|
|
|
} else
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
addr = in6addr_any;
|
|
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
if (route) {
|
2014-06-24 12:46:03 -04:00
|
|
|
nm_ip6_route_set_next_hop (result, &addr);
|
|
|
|
|
|
|
|
|
|
/* parse metric, default to 0 */
|
|
|
|
|
if (metric_str) {
|
|
|
|
|
if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
nm_ip6_route_set_metric (result, metric);
|
|
|
|
|
} else
|
|
|
|
|
nm_ip6_address_set_gateway (result, &addr);
|
2008-07-16 07:37:10 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
return result;
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
|
|
|
|
|
error_out:
|
2014-06-24 12:46:03 -04:00
|
|
|
if (route)
|
|
|
|
|
nm_ip6_route_unref (result);
|
|
|
|
|
else
|
|
|
|
|
nm_ip4_route_unref (result);
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
return NULL;
|
2008-07-16 07:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* On success, returns pointer to the zero-terminated field (original @current).
|
|
|
|
|
* The @current * pointer target is set to point to the rest of the input
|
2013-04-19 15:48:01 +02:00
|
|
|
* or %NULL if there is no more input. Sets error to %NULL for convenience.
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*
|
2013-04-19 15:48:01 +02:00
|
|
|
* On failure, returns %NULL (unspecified). The @current pointer target is
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
* resets to its original value to allow skipping fields. The @error target
|
2013-04-19 15:48:01 +02:00
|
|
|
* is set to the character that breaks the parsing or %NULL if @current was %NULL.
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*
|
2013-04-19 15:48:01 +02:00
|
|
|
* When @current target is %NULL, gracefully fail returning %NULL while
|
|
|
|
|
* leaving the @current target %NULL end setting @error to %NULL;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*/
|
|
|
|
|
static char *
|
|
|
|
|
read_field (char **current, char **error, const char *characters, const char *delimiters)
|
2009-01-12 14:21:44 -05:00
|
|
|
{
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
char *start;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (current, NULL);
|
|
|
|
|
g_return_val_if_fail (error, NULL);
|
|
|
|
|
g_return_val_if_fail (characters, NULL);
|
|
|
|
|
g_return_val_if_fail (delimiters, NULL);
|
2009-01-12 14:21:44 -05:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
if (!*current) {
|
|
|
|
|
/* graceful failure, leave '*current' NULL */
|
|
|
|
|
*error = NULL;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2009-01-12 14:21:44 -05:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* fail on empty input */
|
2014-04-05 09:42:00 -04:00
|
|
|
if (!**current)
|
|
|
|
|
return NULL;
|
2009-01-12 14:21:44 -05:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* remember beginning of input */
|
|
|
|
|
start = *current;
|
|
|
|
|
|
|
|
|
|
while (**current && strchr (characters, **current))
|
|
|
|
|
(*current)++;
|
|
|
|
|
if (**current)
|
|
|
|
|
if (strchr (delimiters, **current)) {
|
|
|
|
|
/* success, more data available */
|
|
|
|
|
*error = NULL;
|
|
|
|
|
*(*current)++ = '\0';
|
|
|
|
|
return start;
|
|
|
|
|
} else {
|
|
|
|
|
/* error, bad character */
|
|
|
|
|
*error = *current;
|
|
|
|
|
*current = start;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* success, end of input */
|
|
|
|
|
*error = NULL;
|
|
|
|
|
*current = NULL;
|
|
|
|
|
return start;
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
#define IP_ADDRESS_CHARS "0123456789abcdefABCDEF:.%"
|
|
|
|
|
#define DIGITS "0123456789"
|
|
|
|
|
#define DELIMITERS "/;,"
|
2008-08-06 22:23:48 +00:00
|
|
|
|
|
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* The following IPv4 and IPv6 address formats are supported:
|
|
|
|
|
*
|
|
|
|
|
* address (DEPRECATED)
|
|
|
|
|
* address/plen
|
|
|
|
|
* address/gateway (DEPRECATED)
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
* address/plen,gateway
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*
|
|
|
|
|
* The following IPv4 and IPv6 route formats are supported:
|
|
|
|
|
*
|
|
|
|
|
* address/plen (NETWORK dev DEVICE)
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
* address/plen,gateway (NETWORK via GATEWAY dev DEVICE)
|
|
|
|
|
* address/plen,,metric (NETWORK dev DEVICE metric METRIC)
|
|
|
|
|
* address/plen,gateway,metric (NETWORK via GATEWAY dev DEVICE metric METRIC)
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*
|
|
|
|
|
* For backward, forward and sideward compatibility, slash (/),
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
* semicolon (;) and comma (,) are interchangable. The choice of
|
|
|
|
|
* separator in the above examples is therefore not significant.
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
*
|
|
|
|
|
* Leaving out the prefix length is discouraged and DEPRECATED. The
|
|
|
|
|
* default value of IPv6 prefix length was 64 and has not been
|
|
|
|
|
* changed. The default for IPv4 is now 24, which is the closest
|
|
|
|
|
* IPv4 equivalent. These defaults may just as well be changed to
|
|
|
|
|
* match the iproute2 defaults (32 for IPv4 and 128 for IPv6).
|
|
|
|
|
*/
|
|
|
|
|
static gpointer
|
|
|
|
|
read_one_ip_address_or_route (GKeyFile *file,
|
2014-06-24 12:46:03 -04:00
|
|
|
const char *setting_name,
|
|
|
|
|
const char *key_name,
|
|
|
|
|
gboolean ipv6,
|
|
|
|
|
gboolean route)
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
{
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
guint32 plen;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
gpointer result;
|
|
|
|
|
char *address_str, *plen_str, *gateway_str, *metric_str, *value, *current, *error;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
current = value = nm_keyfile_plugin_kf_get_string (file, setting_name, key_name, NULL);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
if (!value)
|
|
|
|
|
return NULL;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* get address field */
|
|
|
|
|
address_str = read_field (¤t, &error, IP_ADDRESS_CHARS, DELIMITERS);
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "keyfile: Unexpected character '%c' in '%s.%s' address (position %td of '%s').",
|
|
|
|
|
*error, setting_name, key_name, error - current, current);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
/* get prefix length field (skippable) */
|
|
|
|
|
plen_str = read_field (¤t, &error, DIGITS, DELIMITERS);
|
|
|
|
|
/* get gateway field */
|
|
|
|
|
gateway_str = read_field (¤t, &error, IP_ADDRESS_CHARS, DELIMITERS);
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "keyfile: Unexpected character '%c' in '%s.%s' %s (position %td of '%s').",
|
|
|
|
|
*error, setting_name, key_name,
|
|
|
|
|
plen_str ? "gateway" : "gateway or prefix length",
|
|
|
|
|
error - current, current);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
/* for routes, get metric */
|
|
|
|
|
if (route) {
|
|
|
|
|
metric_str = read_field (¤t, &error, DIGITS, DELIMITERS);
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "keyfile: Unexpected character '%c' in '%s.%s' prefix length (position %td of '%s').",
|
|
|
|
|
*error, setting_name, key_name, error - current, current);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
metric_str = NULL;
|
|
|
|
|
if (current) {
|
|
|
|
|
/* there is still some data */
|
|
|
|
|
if (*current) {
|
|
|
|
|
/* another field follows */
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "keyfile: %s.%s: Garbage at the and of the line: %s",
|
|
|
|
|
setting_name, key_name, current);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
goto error;
|
|
|
|
|
} else {
|
|
|
|
|
/* semicolon at the end of input */
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_info (LOGD_SETTINGS, "keyfile: %s.%s: Deprecated semicolon at the end of value.",
|
|
|
|
|
setting_name, key_name);
|
2008-08-06 22:23:48 +00:00
|
|
|
}
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
}
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* parse plen, fallback to defaults */
|
|
|
|
|
if (plen_str)
|
|
|
|
|
g_return_val_if_fail (get_one_int (plen_str, ipv6 ? 128 : 32,
|
|
|
|
|
key_name, &plen), NULL);
|
|
|
|
|
else {
|
|
|
|
|
if (route)
|
|
|
|
|
plen = ipv6 ? 128 : 24;
|
|
|
|
|
else
|
|
|
|
|
plen = ipv6 ? 64 : 24;
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "keyfile: Missing prefix length in '%s.%s', defaulting to %d",
|
|
|
|
|
setting_name, key_name, plen);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
}
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
/* build the appropriate data structure for NetworkManager settings */
|
|
|
|
|
result = (ipv6 ? build_ip6_address_or_route : build_ip4_address_or_route) (
|
keyfile: fix reader and writer for writing routes
Keyfile plugin writer had a bug, when writing IP6 routes with gateway
"::". Instead of writing "net/plen,,metric" it wrote "net/plen,metric".
- fix this bug and add test cases. Also, add a workaround to reader, to
accept such wrongly written IP6 routes as valid.
- change the writer for IP4 addresses, IP4 routes and IP6 routes to
omit the gateway and the metric, if it is 0.0.0.0/::/0, respectively.
Also change the reader, to accept such empty gateway as valid.
It only omits the gateway, if the metric is not 0, this means it would
write:
route1=1.2.3.4/24,0.0.0.0,1
instead of
route1=1.2.3.4/24,,1
Both representations are now supported by the reader, but older plugin
versions could only read the former (thus, we keep writing that
version).
With a metric of zero, it would instead write:
route1=1.2.3.4/24
- some refactoring and code cleanup. Fix a memory leak.
https://bugzilla.gnome.org/show_bug.cgi?id=719851
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-04 14:32:13 +01:00
|
|
|
key_name, address_str, plen, gateway_str, metric_str, route);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
return result;
|
|
|
|
|
error:
|
|
|
|
|
g_free (value);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-08-06 22:23:48 +00:00
|
|
|
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
static void
|
2012-10-03 14:50:59 +02:00
|
|
|
ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
|
|
|
|
gboolean ipv6 = !strcmp (setting_name, "ipv6");
|
2012-10-03 14:50:59 +02:00
|
|
|
gboolean routes = !strcmp (key, "routes");
|
|
|
|
|
static const char *key_names_routes[] = { "route", "routes", NULL };
|
|
|
|
|
static const char *key_names_addresses[] = { "address", "addresses", NULL };
|
|
|
|
|
const char **key_names = routes ? key_names_routes : key_names_addresses;
|
|
|
|
|
GPtrArray *list;
|
2014-06-24 12:46:03 -04:00
|
|
|
GDestroyNotify free_func;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
int i;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
if (ipv6) {
|
|
|
|
|
if (routes)
|
|
|
|
|
free_func = (GDestroyNotify) nm_ip6_route_unref;
|
|
|
|
|
else
|
|
|
|
|
free_func = (GDestroyNotify) nm_ip6_address_unref;
|
|
|
|
|
} else {
|
|
|
|
|
if (routes)
|
|
|
|
|
free_func = (GDestroyNotify) nm_ip4_route_unref;
|
|
|
|
|
else
|
|
|
|
|
free_func = (GDestroyNotify) nm_ip4_address_unref;
|
|
|
|
|
}
|
|
|
|
|
list = g_ptr_array_new_with_free_func (free_func);
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
for (i = -1; i < 1000; i++) {
|
|
|
|
|
const char **key_basename;
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
for (key_basename = key_names; *key_basename; key_basename++) {
|
|
|
|
|
char *key_name;
|
|
|
|
|
gpointer item;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
/* -1 means no suffix */
|
|
|
|
|
if (i >= 0)
|
|
|
|
|
key_name = g_strdup_printf ("%s%d", *key_basename, i);
|
|
|
|
|
else
|
|
|
|
|
key_name = g_strdup (*key_basename);
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
item = read_one_ip_address_or_route (keyfile, setting_name, key_name, ipv6, routes);
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
if (item)
|
|
|
|
|
g_ptr_array_add (list, item);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
g_free (key_name);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
}
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
if (list->len >= 1)
|
|
|
|
|
g_object_set (setting, key, list, NULL);
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
|
2012-10-03 14:50:59 +02:00
|
|
|
g_ptr_array_unref (list);
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
2008-07-16 07:37:10 +00:00
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
static void
|
2011-03-02 18:17:57 -06:00
|
|
|
ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
2009-01-12 14:21:44 -05:00
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2014-06-24 12:46:03 -04:00
|
|
|
GPtrArray *array;
|
2009-01-12 14:21:44 -05:00
|
|
|
gsize length;
|
|
|
|
|
char **list, **iter;
|
|
|
|
|
int ret;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
list = nm_keyfile_plugin_kf_get_string_list (keyfile, setting_name, key, &length, NULL);
|
2009-01-12 14:21:44 -05:00
|
|
|
if (!list || !g_strv_length (list))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
array = g_ptr_array_sized_new (length + 1);
|
2009-01-12 14:21:44 -05:00
|
|
|
for (iter = list; *iter; iter++) {
|
2013-07-31 23:59:50 +02:00
|
|
|
guint32 addr;
|
2009-01-12 14:21:44 -05:00
|
|
|
|
|
|
|
|
ret = inet_pton (AF_INET, *iter, &addr);
|
|
|
|
|
if (ret <= 0) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid DNS server address '%s'", __func__, *iter);
|
2009-01-12 14:21:44 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
g_ptr_array_add (array, *iter);
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
2014-06-24 12:46:03 -04:00
|
|
|
g_ptr_array_add (array, NULL);
|
2008-10-27 17:36:18 +00:00
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
g_object_set (setting, key, array->pdata, NULL);
|
|
|
|
|
g_ptr_array_unref (array);
|
|
|
|
|
g_strfreev (list);
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
2008-07-16 07:37:10 +00:00
|
|
|
|
2010-01-08 11:23:39 -08:00
|
|
|
static void
|
2011-03-02 18:17:57 -06:00
|
|
|
ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
2010-01-08 11:23:39 -08:00
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
|
|
|
|
GPtrArray *array = NULL;
|
|
|
|
|
gsize length;
|
|
|
|
|
char **list, **iter;
|
|
|
|
|
int ret;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
list = nm_keyfile_plugin_kf_get_string_list (keyfile, setting_name, key, &length, NULL);
|
2010-01-08 11:23:39 -08:00
|
|
|
if (!list || !g_strv_length (list))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
array = g_ptr_array_sized_new (length + 1);
|
2012-10-02 17:59:47 +02:00
|
|
|
|
2010-01-08 11:23:39 -08:00
|
|
|
for (iter = list; *iter; iter++) {
|
|
|
|
|
struct in6_addr addr;
|
|
|
|
|
|
|
|
|
|
ret = inet_pton (AF_INET6, *iter, &addr);
|
|
|
|
|
if (ret <= 0) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid DNS server IPv6 address '%s'", __func__, *iter);
|
2010-01-08 11:23:39 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
g_ptr_array_add (array, *iter);
|
2010-01-08 11:23:39 -08:00
|
|
|
}
|
2014-06-24 12:46:03 -04:00
|
|
|
g_ptr_array_add (array, NULL);
|
2010-01-08 11:23:39 -08:00
|
|
|
|
2014-06-24 12:46:03 -04:00
|
|
|
g_object_set (setting, key, array->pdata, NULL);
|
|
|
|
|
g_ptr_array_unref (array);
|
|
|
|
|
g_strfreev (list);
|
2010-01-08 11:23:39 -08:00
|
|
|
}
|
2008-07-16 07:37:10 +00:00
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
static void
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path, gsize enforce_length)
|
2009-01-12 14:21:44 -05:00
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2014-07-30 10:57:45 -04:00
|
|
|
char *tmp_string = NULL, *p, *mac_str;
|
2009-01-12 14:21:44 -05:00
|
|
|
gint *tmp_list;
|
|
|
|
|
GByteArray *array = NULL;
|
|
|
|
|
gsize length;
|
2008-08-06 22:23:48 +00:00
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
p = tmp_string = nm_keyfile_plugin_kf_get_string (keyfile, setting_name, key, NULL);
|
2014-05-27 16:04:56 +02:00
|
|
|
if (tmp_string && tmp_string[0]) {
|
2009-01-12 14:21:44 -05:00
|
|
|
/* Look for enough ':' characters to signify a MAC address */
|
2014-05-27 16:04:56 +02:00
|
|
|
guint i = 0;
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
while (*p) {
|
|
|
|
|
if (*p == ':')
|
|
|
|
|
i++;
|
|
|
|
|
p++;
|
2008-08-06 22:23:48 +00:00
|
|
|
}
|
2011-11-18 11:13:30 -06:00
|
|
|
|
2014-05-27 16:04:56 +02:00
|
|
|
if (enforce_length == 0 || enforce_length == i+1) {
|
|
|
|
|
/* If we found enough it's probably a string-format MAC address */
|
|
|
|
|
array = g_byte_array_sized_new (i+1);
|
|
|
|
|
g_byte_array_set_size (array, i+1);
|
2014-07-04 15:59:19 -04:00
|
|
|
if (!nm_utils_hwaddr_aton (tmp_string, array->data, array->len)) {
|
2014-05-27 16:04:56 +02:00
|
|
|
g_byte_array_unref (array);
|
|
|
|
|
array = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-16 07:37:10 +00:00
|
|
|
}
|
2009-01-12 14:21:44 -05:00
|
|
|
g_free (tmp_string);
|
|
|
|
|
|
2011-11-18 11:13:30 -06:00
|
|
|
if (array == NULL) {
|
|
|
|
|
/* Old format; list of ints */
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp_list = nm_keyfile_plugin_kf_get_integer_list (keyfile, setting_name, key, &length, NULL);
|
2014-05-27 16:04:56 +02:00
|
|
|
if (length > 0 && (enforce_length == 0 || enforce_length == length)) {
|
|
|
|
|
gsize i;
|
|
|
|
|
|
2011-11-18 11:13:30 -06:00
|
|
|
array = g_byte_array_sized_new (length);
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
int val = tmp_list[i];
|
|
|
|
|
const guint8 v = (guint8) (val & 0xFF);
|
|
|
|
|
|
|
|
|
|
if (val < 0 || val > 255) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: %s / %s ignoring invalid byte element '%d' (not "
|
|
|
|
|
" between 0 and 255 inclusive)", __func__, setting_name,
|
|
|
|
|
key, val);
|
2011-11-18 11:13:30 -06:00
|
|
|
g_byte_array_free (array, TRUE);
|
|
|
|
|
array = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_byte_array_append (array, &v, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_free (tmp_list);
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2014-07-30 10:57:45 -04:00
|
|
|
if (!array) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid MAC address for %s / %s",
|
|
|
|
|
__func__, setting_name, key);
|
2014-07-30 10:57:45 -04:00
|
|
|
return;
|
2009-01-12 14:21:44 -05:00
|
|
|
}
|
2014-07-30 10:57:45 -04:00
|
|
|
|
|
|
|
|
mac_str = nm_utils_hwaddr_ntoa (array->data, array->len);
|
|
|
|
|
g_object_set (setting, key, mac_str, NULL);
|
|
|
|
|
g_free (mac_str);
|
|
|
|
|
g_byte_array_free (array, TRUE);
|
2008-05-08 01:02:42 +00:00
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2014-05-27 16:04:56 +02:00
|
|
|
static void
|
|
|
|
|
mac_address_parser_ETHER (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
mac_address_parser (setting, key, keyfile, keyfile_path, ETH_ALEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mac_address_parser_INFINIBAND (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
mac_address_parser (setting, key, keyfile, keyfile_path, INFINIBAND_ALEN);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 17:13:22 +00:00
|
|
|
static void
|
|
|
|
|
read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key)
|
|
|
|
|
{
|
|
|
|
|
char **keys, **iter;
|
|
|
|
|
char *value;
|
2008-10-27 17:36:18 +00:00
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2008-08-11 17:13:22 +00:00
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
keys = nm_keyfile_plugin_kf_get_keys (file, setting_name, NULL, NULL);
|
2008-08-11 17:13:22 +00:00
|
|
|
if (!keys || !*keys)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (iter = keys; *iter; iter++) {
|
2013-04-03 11:48:04 -05:00
|
|
|
value = nm_keyfile_plugin_kf_get_string (file, setting_name, *iter, NULL);
|
2008-08-11 17:13:22 +00:00
|
|
|
if (!value)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (NM_IS_SETTING_VPN (setting)) {
|
2014-04-24 17:22:16 +02:00
|
|
|
if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE) && strcmp (*iter, NM_SETTING_VPN_USER_NAME))
|
2008-10-29 09:13:40 +00:00
|
|
|
nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), *iter, value);
|
2008-08-11 17:13:22 +00:00
|
|
|
}
|
2013-06-18 10:59:17 +02:00
|
|
|
if (NM_IS_SETTING_BOND (setting)) {
|
2014-08-05 14:13:42 -04:00
|
|
|
if (strcmp (*iter, "interface-name"))
|
2013-06-18 10:59:17 +02:00
|
|
|
nm_setting_bond_add_option (NM_SETTING_BOND (setting), *iter, value);
|
|
|
|
|
}
|
2008-08-11 17:13:22 +00:00
|
|
|
g_free (value);
|
|
|
|
|
}
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-18 16:13:39 +02:00
|
|
|
static void
|
|
|
|
|
unescape_semicolons (char *str)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
gsize len = strlen (str);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
if (str[i] == '\\' && str[i+1] == ';') {
|
|
|
|
|
memmove(str + i, str + i + 1, len - (i + 1));
|
|
|
|
|
len--;
|
|
|
|
|
}
|
|
|
|
|
str[len] = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
static GBytes *
|
|
|
|
|
get_bytes (GKeyFile *keyfile,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
const char *key,
|
|
|
|
|
gboolean zero_terminate,
|
|
|
|
|
gboolean unescape_semicolon)
|
2010-09-16 18:27:19 -05:00
|
|
|
{
|
|
|
|
|
GByteArray *array = NULL;
|
2011-07-07 15:25:11 +02:00
|
|
|
char *tmp_string;
|
2010-09-16 18:27:19 -05:00
|
|
|
gint *tmp_list;
|
|
|
|
|
gsize length;
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-07-07 15:25:11 +02:00
|
|
|
/* New format: just a string
|
2011-10-14 11:20:22 -05:00
|
|
|
* Old format: integer list; e.g. 11;25;38;
|
2010-09-16 18:27:19 -05:00
|
|
|
*/
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp_string = nm_keyfile_plugin_kf_get_string (keyfile, setting_name, key, NULL);
|
2010-09-16 18:27:19 -05:00
|
|
|
if (tmp_string) {
|
2011-07-07 15:25:11 +02:00
|
|
|
GRegex *regex;
|
|
|
|
|
GMatchInfo *match_info;
|
2011-10-18 16:13:39 +02:00
|
|
|
const char *pattern = "^[[:space:]]*[[:digit:]]{1,3}[[:space:]]*;([[:space:]]*[[:digit:]]{1,3}[[:space:]]*;)*([[:space:]]*)?$";
|
2010-09-16 18:27:19 -05:00
|
|
|
|
2011-07-07 15:25:11 +02:00
|
|
|
regex = g_regex_new (pattern, 0, 0, NULL);
|
|
|
|
|
g_regex_match (regex, tmp_string, 0, &match_info);
|
2011-09-29 23:52:17 -05:00
|
|
|
if (!g_match_info_matches (match_info)) {
|
|
|
|
|
/* Handle as a simple string (ie, new format) */
|
2011-10-18 16:13:39 +02:00
|
|
|
if (unescape_semicolon)
|
|
|
|
|
unescape_semicolons (tmp_string);
|
2011-09-29 23:52:17 -05:00
|
|
|
length = strlen (tmp_string);
|
|
|
|
|
if (zero_terminate)
|
|
|
|
|
length++;
|
|
|
|
|
array = g_byte_array_sized_new (length);
|
|
|
|
|
g_byte_array_append (array, (guint8 *) tmp_string, length);
|
|
|
|
|
}
|
2011-07-07 15:25:11 +02:00
|
|
|
g_match_info_free (match_info);
|
|
|
|
|
g_regex_unref (regex);
|
2011-03-02 18:17:57 -06:00
|
|
|
g_free (tmp_string);
|
2010-09-16 18:27:19 -05:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
if (!array) {
|
|
|
|
|
/* Old format; list of ints */
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp_list = nm_keyfile_plugin_kf_get_integer_list (keyfile, setting_name, key, &length, NULL);
|
2011-03-02 18:17:57 -06:00
|
|
|
array = g_byte_array_sized_new (length);
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
int val = tmp_list[i];
|
|
|
|
|
unsigned char v = (unsigned char) (val & 0xFF);
|
2010-09-16 18:27:19 -05:00
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
if (val < 0 || val > 255) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: %s / %s ignoring invalid byte element '%d' (not "
|
|
|
|
|
" between 0 and 255 inclusive)", __func__, setting_name,
|
|
|
|
|
key, val);
|
2011-03-02 18:17:57 -06:00
|
|
|
} else
|
|
|
|
|
g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
|
|
|
|
|
}
|
|
|
|
|
g_free (tmp_list);
|
2010-09-16 18:27:19 -05:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
if (array->len == 0) {
|
|
|
|
|
g_byte_array_free (array, TRUE);
|
2014-06-26 10:42:11 -04:00
|
|
|
return NULL;
|
|
|
|
|
} else
|
|
|
|
|
return g_byte_array_free_to_bytes (array);
|
2011-03-02 18:17:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ssid_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2014-06-26 10:42:11 -04:00
|
|
|
GBytes *bytes;
|
2011-03-02 18:17:57 -06:00
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
bytes = get_bytes (keyfile, setting_name, key, FALSE, TRUE);
|
|
|
|
|
if (bytes) {
|
|
|
|
|
g_object_set (setting, key, bytes, NULL);
|
|
|
|
|
g_bytes_unref (bytes);
|
2011-03-02 18:17:57 -06:00
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid SSID for %s / %s",
|
|
|
|
|
__func__, setting_name, key);
|
2011-03-02 18:17:57 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-17 16:36:18 -08:00
|
|
|
static void
|
|
|
|
|
password_raw_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2014-06-26 10:42:11 -04:00
|
|
|
GBytes *bytes;
|
2011-11-17 16:36:18 -08:00
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
bytes = get_bytes (keyfile, setting_name, key, FALSE, TRUE);
|
|
|
|
|
if (bytes) {
|
|
|
|
|
g_object_set (setting, key, bytes, NULL);
|
|
|
|
|
g_bytes_unref (bytes);
|
2011-11-17 16:36:18 -08:00
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid raw password for %s / %s",
|
|
|
|
|
__func__, setting_name, key);
|
2011-11-17 16:36:18 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
static char *
|
2014-06-26 10:42:11 -04:00
|
|
|
get_cert_path (const char *keyfile_path, const guint8 *cert_path, gsize cert_path_len)
|
2011-03-02 18:17:57 -06:00
|
|
|
{
|
|
|
|
|
const char *base;
|
|
|
|
|
char *p = NULL, *path, *dirname, *tmp;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (keyfile_path != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (cert_path != NULL, NULL);
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
base = path = g_malloc0 (cert_path_len + 1);
|
|
|
|
|
memcpy (path, cert_path, cert_path_len);
|
2011-03-02 18:17:57 -06:00
|
|
|
|
|
|
|
|
if (path[0] == '/')
|
|
|
|
|
return path;
|
|
|
|
|
|
|
|
|
|
p = strrchr (path, '/');
|
|
|
|
|
if (p)
|
|
|
|
|
base = p + 1;
|
|
|
|
|
|
|
|
|
|
dirname = g_path_get_dirname (keyfile_path);
|
|
|
|
|
tmp = g_build_path ("/", dirname, base, NULL);
|
|
|
|
|
g_free (dirname);
|
|
|
|
|
g_free (path);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SCHEME_PATH "file://"
|
|
|
|
|
|
2011-06-01 16:44:02 -05:00
|
|
|
static const char *certext[] = { ".pem", ".cert", ".crt", ".cer", ".p12", ".der", ".key" };
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-29 23:52:17 -05:00
|
|
|
has_cert_ext (const char *path)
|
2011-06-01 16:44:02 -05:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (certext); i++) {
|
2011-09-29 23:52:17 -05:00
|
|
|
if (g_str_has_suffix (path, certext[i]))
|
2011-06-01 16:44:02 -05:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 23:52:17 -05:00
|
|
|
static gboolean
|
2014-06-26 10:42:11 -04:00
|
|
|
handle_as_scheme (GBytes *bytes, NMSetting *setting, const char *key)
|
2011-09-29 23:52:17 -05:00
|
|
|
{
|
2014-06-26 10:42:11 -04:00
|
|
|
const guint8 *data;
|
|
|
|
|
gsize data_len;
|
|
|
|
|
|
|
|
|
|
data = g_bytes_get_data (bytes, &data_len);
|
|
|
|
|
|
2011-09-29 23:52:17 -05:00
|
|
|
/* It's the PATH scheme, can just set plain data */
|
2014-06-26 10:42:11 -04:00
|
|
|
if ( (data_len > strlen (SCHEME_PATH))
|
|
|
|
|
&& g_str_has_prefix ((const char *) data, SCHEME_PATH)
|
|
|
|
|
&& (data[data_len - 1] == '\0')) {
|
|
|
|
|
g_object_set (setting, key, bytes, NULL);
|
2011-09-29 23:52:17 -05:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2014-06-26 10:42:11 -04:00
|
|
|
handle_as_path (GBytes *bytes,
|
2011-09-29 23:52:17 -05:00
|
|
|
NMSetting *setting,
|
|
|
|
|
const char *key,
|
|
|
|
|
const char *keyfile_path)
|
|
|
|
|
{
|
2014-06-26 10:42:11 -04:00
|
|
|
const guint8 *data;
|
|
|
|
|
gsize data_len;
|
|
|
|
|
gsize validate_len;
|
2011-09-29 23:52:17 -05:00
|
|
|
char *path;
|
|
|
|
|
gboolean exists, success = FALSE;
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
data = g_bytes_get_data (bytes, &data_len);
|
|
|
|
|
if (data_len > 500 || data_len < 1)
|
2011-09-29 23:52:17 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* If there's a trailing NULL tell g_utf8_validate() to to until the NULL */
|
2014-06-26 10:42:11 -04:00
|
|
|
if (data[data_len - 1] == '\0')
|
2011-09-29 23:52:17 -05:00
|
|
|
validate_len = -1;
|
2014-06-26 10:42:11 -04:00
|
|
|
else
|
|
|
|
|
validate_len = data_len;
|
2011-09-29 23:52:17 -05:00
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
if (g_utf8_validate ((const char *) data, validate_len, NULL) == FALSE)
|
2011-09-29 23:52:17 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Might be a bare path without the file:// prefix; in that case
|
|
|
|
|
* if it's an absolute path, use that, otherwise treat it as a
|
|
|
|
|
* relative path to the current directory.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
path = get_cert_path (keyfile_path, data, data_len);
|
2011-09-29 23:52:17 -05:00
|
|
|
exists = g_file_test (path, G_FILE_TEST_EXISTS);
|
|
|
|
|
if ( exists
|
2014-06-26 10:42:11 -04:00
|
|
|
|| memchr (data, '/', data_len)
|
2011-09-29 23:52:17 -05:00
|
|
|
|| has_cert_ext (path)) {
|
2014-06-26 10:42:11 -04:00
|
|
|
GByteArray *tmp;
|
|
|
|
|
GBytes *val;
|
|
|
|
|
|
2011-09-29 23:52:17 -05:00
|
|
|
/* Construct the proper value as required for the PATH scheme */
|
2014-06-26 10:42:11 -04:00
|
|
|
tmp = g_byte_array_sized_new (strlen (SCHEME_PATH) + strlen (path) + 1);
|
|
|
|
|
g_byte_array_append (tmp, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH));
|
|
|
|
|
g_byte_array_append (tmp, (const guint8 *) path, strlen (path));
|
|
|
|
|
g_byte_array_append (tmp, (const guint8 *) "\0", 1);
|
|
|
|
|
val = g_byte_array_free_to_bytes (tmp);
|
2011-09-29 23:52:17 -05:00
|
|
|
g_object_set (setting, key, val, NULL);
|
2014-06-26 10:42:11 -04:00
|
|
|
g_bytes_unref (val);
|
2011-09-29 23:52:17 -05:00
|
|
|
success = TRUE;
|
|
|
|
|
|
|
|
|
|
/* Warn if the certificate didn't exist */
|
|
|
|
|
if (exists == FALSE)
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "certificate or key %s does not exist", path);
|
2011-09-29 23:52:17 -05:00
|
|
|
}
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
static void
|
|
|
|
|
cert_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
2014-06-26 10:42:11 -04:00
|
|
|
GBytes *bytes;
|
2011-03-02 18:17:57 -06:00
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
bytes = get_bytes (keyfile, setting_name, key, TRUE, FALSE);
|
|
|
|
|
if (bytes) {
|
2011-09-29 23:52:17 -05:00
|
|
|
/* Try as a path + scheme (ie, starts with "file://") */
|
2014-06-26 10:42:11 -04:00
|
|
|
success = handle_as_scheme (bytes, setting, key);
|
2011-03-02 18:17:57 -06:00
|
|
|
|
2011-09-29 23:52:17 -05:00
|
|
|
/* If not, it might be a plain path */
|
|
|
|
|
if (success == FALSE)
|
2014-06-26 10:42:11 -04:00
|
|
|
success = handle_as_path (bytes, setting, key, keyfile_path);
|
2011-03-02 18:17:57 -06:00
|
|
|
|
2011-09-29 23:52:17 -05:00
|
|
|
/* If neither of those two, assume blob with certificate data */
|
|
|
|
|
if (success == FALSE)
|
2014-06-26 10:42:11 -04:00
|
|
|
g_object_set (setting, key, bytes, NULL);
|
2011-03-02 18:17:57 -06:00
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid key/cert value for %s / %s",
|
|
|
|
|
__func__, setting_name, key);
|
2010-09-16 18:27:19 -05:00
|
|
|
}
|
2011-09-29 23:52:17 -05:00
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
if (bytes)
|
|
|
|
|
g_bytes_unref (bytes);
|
2010-09-16 18:27:19 -05:00
|
|
|
}
|
2009-01-12 14:21:44 -05:00
|
|
|
|
2014-09-24 09:12:46 -04:00
|
|
|
static void
|
|
|
|
|
parity_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name = nm_setting_get_name (setting);
|
|
|
|
|
NMSettingSerialParity parity;
|
|
|
|
|
int int_val;
|
|
|
|
|
char *str_val;
|
|
|
|
|
|
|
|
|
|
/* Keyfile traditionally stored this as the ASCII value for 'E', 'o', or 'n'.
|
|
|
|
|
* We now accept either that or the (case-insensitive) character itself (but
|
|
|
|
|
* still always write it the old way, for backward compatibility).
|
|
|
|
|
*/
|
|
|
|
|
int_val = nm_keyfile_plugin_kf_get_integer (keyfile, setting_name, key, NULL);
|
|
|
|
|
if (!int_val) {
|
|
|
|
|
str_val = nm_keyfile_plugin_kf_get_string (keyfile, setting_name, key, NULL);
|
|
|
|
|
if (str_val) {
|
|
|
|
|
if (str_val[0] && !str_val[1])
|
|
|
|
|
int_val = str_val[0];
|
|
|
|
|
else {
|
|
|
|
|
/* This will hit the warning below */
|
|
|
|
|
int_val = 'X';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!int_val)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (int_val) {
|
|
|
|
|
case 'E':
|
|
|
|
|
case 'e':
|
|
|
|
|
parity = NM_SETTING_SERIAL_PARITY_EVEN;
|
|
|
|
|
break;
|
|
|
|
|
case 'O':
|
|
|
|
|
case 'o':
|
|
|
|
|
parity = NM_SETTING_SERIAL_PARITY_ODD;
|
|
|
|
|
break;
|
|
|
|
|
case 'N':
|
|
|
|
|
case 'n':
|
|
|
|
|
parity = NM_SETTING_SERIAL_PARITY_NONE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid value for %s / %s",
|
|
|
|
|
__func__, setting_name, key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_set (setting, key, parity, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
typedef struct {
|
|
|
|
|
const char *setting_name;
|
|
|
|
|
const char *key;
|
|
|
|
|
gboolean check_for_key;
|
2011-03-02 18:17:57 -06:00
|
|
|
void (*parser) (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path);
|
2009-01-12 14:21:44 -05:00
|
|
|
} KeyParser;
|
|
|
|
|
|
2010-09-25 00:34:10 -05:00
|
|
|
/* A table of keys that require further parsing/conversion because they are
|
2009-01-12 14:21:44 -05:00
|
|
|
* stored in a format that can't be automatically read using the key's type.
|
2010-01-08 11:23:39 -08:00
|
|
|
* i.e. IPv4 addresses, which are stored in NetworkManager as guint32, but are
|
keyfile: unify IPv4/IPv6 address and routing configuration (bgo #682943)
IPv4 and IPv6 address configuration is now handled together and supports
the following syntax (slashes can be replaced with semicolons):
address/plen
address/plen,gateway
IPv4 and IPv6 route configuration is also handled uniformly and supports
the following syntax:
address/plen (for device routes)
address/plen,gateway (for gateway routes)
address/plen,gateway,metric (for gateway routes with metric)
For compatibility reasons, slash (/), comma (,) and semicolon (;) are
considered equal by the parser. The /plen part is optional for both
addresses and routes for compatibility reasons.
Leaving out the prefix length is not considered a good idea. IPv6
addresses default to 64 and IPv4 now defaults to 24 which is the closest
possible IPv4 counterpart. Routes default to single addresses.
Example 1:
[ipv4]
method=manual
addresses1=192.168.56.5/24,192.168.56.1
addresses2=192.168.57.5/24
routes1=4.5.6.0/24
routes2=1.2.3.0/24,4.5.6.7
routes3=7.8.9.0/24,4.5.6.7,99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3/64,2001:db8:a:b::1
addresses2=2001:db8:c:d::3/64
routes1=2001:db8:e:f::/64,2001:db8:a:b::4
Example 2 (equivalent):
[ipv4]
method=manual
addresses1=192.168.56.5;24;192.168.56.1
addresses2=192.168.57.5;24
routes1=4.5.6.0;24
routes2=1.2.3.0;24;4.5.6.7
routes3=7.8.9.0;24;4.5.6.7;99
[ipv6]
method=manual
addresses1=2001:db8:a:b::3;64;2001:db8:a:b::1
addresses2=2001:db8:c:d::3;64
routes1=2001:db8:e:f::;64;2001:db8:a:b::4
For writing, I have arbitrarily chosen one of the formats 'reader'
can parse. Address and prefix length are separated by slash (/),
everything else is separated by comma (,).
addresses1=address/plen,gateway
routes1=address/plen,gateway,metric
Note: The modified 'reader' exposes a bug in the 'writer' and ignores
out badly-formatted routes. This problem is also fixed by this
commit. Keyfile tests now pass.
2012-09-21 16:59:07 +02:00
|
|
|
* stored in keyfiles as strings, eg "10.1.1.2" or IPv6 addresses stored
|
2010-01-08 11:23:39 -08:00
|
|
|
* in struct in6_addr internally, but as string in keyfiles.
|
2009-01-12 14:21:44 -05:00
|
|
|
*/
|
|
|
|
|
static KeyParser key_parsers[] = {
|
2013-04-03 11:48:04 -05:00
|
|
|
{ NM_SETTING_CONNECTION_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_TYPE,
|
|
|
|
|
TRUE,
|
|
|
|
|
setting_alias_parser },
|
2014-05-29 19:17:00 +02:00
|
|
|
{ NM_SETTING_BRIDGE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_BRIDGE_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
|
|
|
|
mac_address_parser_ETHER },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_ADDRESSES,
|
|
|
|
|
FALSE,
|
2012-10-03 14:50:59 +02:00
|
|
|
ip_address_or_route_parser },
|
2010-01-08 11:23:39 -08:00
|
|
|
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_ADDRESSES,
|
|
|
|
|
FALSE,
|
2012-10-03 14:50:59 +02:00
|
|
|
ip_address_or_route_parser },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_ROUTES,
|
|
|
|
|
FALSE,
|
2012-10-03 14:50:59 +02:00
|
|
|
ip_address_or_route_parser },
|
2010-01-08 11:23:39 -08:00
|
|
|
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_ROUTES,
|
|
|
|
|
FALSE,
|
2012-10-03 14:50:59 +02:00
|
|
|
ip_address_or_route_parser },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP4_CONFIG_DNS,
|
|
|
|
|
FALSE,
|
|
|
|
|
ip4_dns_parser },
|
2010-01-08 11:23:39 -08:00
|
|
|
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_DNS,
|
|
|
|
|
FALSE,
|
|
|
|
|
ip6_dns_parser },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRED_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2010-06-22 14:21:25 +02:00
|
|
|
{ NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRELESS_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2010-06-22 14:21:25 +02:00
|
|
|
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2009-01-12 19:05:24 -05:00
|
|
|
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRELESS_BSSID,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2010-05-25 23:34:09 -07:00
|
|
|
{ NM_SETTING_BLUETOOTH_SETTING_NAME,
|
|
|
|
|
NM_SETTING_BLUETOOTH_BDADDR,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2011-11-18 11:13:30 -06:00
|
|
|
{ NM_SETTING_INFINIBAND_SETTING_NAME,
|
|
|
|
|
NM_SETTING_INFINIBAND_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_INFINIBAND },
|
2012-08-15 16:20:57 -05:00
|
|
|
{ NM_SETTING_WIMAX_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIMAX_MAC_ADDRESS,
|
|
|
|
|
TRUE,
|
2014-05-27 16:04:56 +02:00
|
|
|
mac_address_parser_ETHER },
|
2010-09-16 18:27:19 -05:00
|
|
|
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRELESS_SSID,
|
|
|
|
|
TRUE,
|
|
|
|
|
ssid_parser },
|
2011-11-17 16:36:18 -08:00
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_PASSWORD_RAW,
|
|
|
|
|
TRUE,
|
|
|
|
|
password_raw_parser },
|
2011-03-02 18:17:57 -06:00
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_CA_CERT,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
|
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_CLIENT_CERT,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
|
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_PRIVATE_KEY,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
|
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_PHASE2_CA_CERT,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
|
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_PHASE2_CLIENT_CERT,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
|
|
|
|
{ NM_SETTING_802_1X_SETTING_NAME,
|
|
|
|
|
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY,
|
|
|
|
|
TRUE,
|
|
|
|
|
cert_parser },
|
2014-09-24 09:12:46 -04:00
|
|
|
{ NM_SETTING_SERIAL_SETTING_NAME,
|
|
|
|
|
NM_SETTING_SERIAL_PARITY,
|
|
|
|
|
TRUE,
|
|
|
|
|
parity_parser },
|
2009-01-12 14:21:44 -05:00
|
|
|
{ NULL, NULL, FALSE }
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
typedef struct {
|
|
|
|
|
GKeyFile *keyfile;
|
|
|
|
|
const char *keyfile_path;
|
|
|
|
|
} ReadInfo;
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
static void
|
|
|
|
|
read_one_setting_value (NMSetting *setting,
|
2008-11-20 21:23:55 +00:00
|
|
|
const char *key,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamFlags flags,
|
|
|
|
|
gpointer user_data)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
2011-03-02 18:17:57 -06:00
|
|
|
ReadInfo *info = user_data;
|
2008-10-27 17:36:18 +00:00
|
|
|
const char *setting_name;
|
2008-04-22 14:48:02 +00:00
|
|
|
GType type;
|
|
|
|
|
GError *err = NULL;
|
2008-05-08 01:02:42 +00:00
|
|
|
gboolean check_for_key = TRUE;
|
2009-01-12 14:21:44 -05:00
|
|
|
KeyParser *parser = &key_parsers[0];
|
2008-05-08 01:02:42 +00:00
|
|
|
|
2008-11-20 21:23:55 +00:00
|
|
|
/* Property is not writable */
|
|
|
|
|
if (!(flags & G_PARAM_WRITABLE))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-05-08 01:02:42 +00:00
|
|
|
/* Setting name gets picked up from the keyfile's section name instead */
|
|
|
|
|
if (!strcmp (key, NM_SETTING_NAME))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-10-27 17:07:42 +00:00
|
|
|
/* Don't read the NMSettingConnection object's 'read-only' property */
|
|
|
|
|
if ( NM_IS_SETTING_CONNECTION (setting)
|
|
|
|
|
&& !strcmp (key, NM_SETTING_CONNECTION_READ_ONLY))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-10-27 17:36:18 +00:00
|
|
|
setting_name = nm_setting_get_name (setting);
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
/* Look through the list of handlers for non-standard format key values */
|
|
|
|
|
while (parser->setting_name) {
|
|
|
|
|
if (!strcmp (parser->setting_name, setting_name) && !strcmp (parser->key, key)) {
|
|
|
|
|
check_for_key = parser->check_for_key;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
parser++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* VPN properties don't have the exact key name */
|
|
|
|
|
if (NM_IS_SETTING_VPN (setting))
|
2008-09-04 14:32:14 +00:00
|
|
|
check_for_key = FALSE;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-06-18 10:59:17 +02:00
|
|
|
/* Bonding 'options' don't have the exact key name. The options are right under [bond] group. */
|
|
|
|
|
if (NM_IS_SETTING_BOND (setting))
|
|
|
|
|
check_for_key = FALSE;
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
/* Check for the exact key in the GKeyFile if required. Most setting
|
|
|
|
|
* properties map 1:1 to a key in the GKeyFile, but for those properties
|
|
|
|
|
* like IP addresses and routes where more than one value is actually
|
|
|
|
|
* encoded by the setting property, this won't be true.
|
|
|
|
|
*/
|
2013-04-03 11:48:04 -05:00
|
|
|
if (check_for_key && !nm_keyfile_plugin_kf_has_key (info->keyfile, setting_name, key, &err)) {
|
2009-01-12 14:21:44 -05:00
|
|
|
/* Key doesn't exist or an error ocurred, thus nothing to do. */
|
2008-04-22 14:48:02 +00:00
|
|
|
if (err) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Error loading setting '%s' value: %s", setting_name, err->message);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_error_free (err);
|
|
|
|
|
}
|
2009-01-12 14:21:44 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
/* If there's a custom parser for this key, handle that before the generic
|
|
|
|
|
* parsers below.
|
|
|
|
|
*/
|
2013-10-31 14:13:33 +01:00
|
|
|
if (parser->setting_name) {
|
2011-03-02 18:17:57 -06:00
|
|
|
(*parser->parser) (setting, key, info->keyfile, info->keyfile_path);
|
2008-04-22 14:48:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type = G_VALUE_TYPE (value);
|
|
|
|
|
|
|
|
|
|
if (type == G_TYPE_STRING) {
|
|
|
|
|
char *str_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
str_val = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_set (setting, key, str_val, NULL);
|
|
|
|
|
g_free (str_val);
|
|
|
|
|
} else if (type == G_TYPE_UINT) {
|
|
|
|
|
int int_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
if (int_val < 0)
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Casting negative value (%i) to uint", int_val);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_set (setting, key, int_val, NULL);
|
|
|
|
|
} else if (type == G_TYPE_INT) {
|
|
|
|
|
int int_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_set (setting, key, int_val, NULL);
|
|
|
|
|
} else if (type == G_TYPE_BOOLEAN) {
|
|
|
|
|
gboolean bool_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
bool_val = nm_keyfile_plugin_kf_get_boolean (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_set (setting, key, bool_val, NULL);
|
|
|
|
|
} else if (type == G_TYPE_CHAR) {
|
|
|
|
|
int int_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
if (int_val < G_MININT8 || int_val > G_MAXINT8)
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Casting value (%i) to char", int_val);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
g_object_set (setting, key, int_val, NULL);
|
|
|
|
|
} else if (type == G_TYPE_UINT64) {
|
|
|
|
|
char *tmp_str;
|
|
|
|
|
guint64 uint_val;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp_str = nm_keyfile_plugin_kf_get_value (info->keyfile, setting_name, key, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
uint_val = g_ascii_strtoull (tmp_str, NULL, 10);
|
2008-06-05 13:16:02 +00:00
|
|
|
g_free (tmp_str);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_set (setting, key, uint_val, NULL);
|
2014-06-26 10:42:11 -04:00
|
|
|
} else if (type == G_TYPE_BYTES) {
|
2008-04-22 14:48:02 +00:00
|
|
|
gint *tmp;
|
|
|
|
|
GByteArray *array;
|
2014-06-26 10:42:11 -04:00
|
|
|
GBytes *bytes;
|
2008-04-22 14:48:02 +00:00
|
|
|
gsize length;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
tmp = nm_keyfile_plugin_kf_get_integer_list (info->keyfile, setting_name, key, &length, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
array = g_byte_array_sized_new (length);
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
int val = tmp[i];
|
|
|
|
|
unsigned char v = (unsigned char) (val & 0xFF);
|
|
|
|
|
|
2009-01-12 14:21:44 -05:00
|
|
|
if (val < 0 || val > 255) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s: %s / %s ignoring invalid byte element '%d' (not "
|
|
|
|
|
" between 0 and 255 inclusive)", __func__, setting_name,
|
|
|
|
|
key, val);
|
2009-01-12 14:21:44 -05:00
|
|
|
} else
|
2008-04-22 14:48:02 +00:00
|
|
|
g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 10:42:11 -04:00
|
|
|
bytes = g_byte_array_free_to_bytes (array);
|
|
|
|
|
g_object_set (setting, key, bytes, NULL);
|
|
|
|
|
g_bytes_unref (bytes);
|
2008-06-05 13:16:02 +00:00
|
|
|
g_free (tmp);
|
2014-08-21 13:19:53 -04:00
|
|
|
} else if (type == G_TYPE_STRV) {
|
2008-04-22 14:48:02 +00:00
|
|
|
gchar **sa;
|
|
|
|
|
gsize length;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
sa = nm_keyfile_plugin_kf_get_string_list (info->keyfile, setting_name, key, &length, NULL);
|
2014-08-21 13:19:53 -04:00
|
|
|
g_object_set (setting, key, sa, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
g_strfreev (sa);
|
2014-06-24 17:40:08 -04:00
|
|
|
} else if (type == G_TYPE_HASH_TABLE) {
|
2011-03-02 18:17:57 -06:00
|
|
|
read_hash_of_string (info->keyfile, setting, key);
|
2014-06-26 13:21:06 -04:00
|
|
|
} else if (type == G_TYPE_ARRAY) {
|
2011-03-02 18:17:57 -06:00
|
|
|
if (!read_array_of_uint (info->keyfile, setting, key)) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'",
|
|
|
|
|
setting_name, key, G_VALUE_TYPE_NAME (value));
|
2008-05-08 01:02:42 +00:00
|
|
|
}
|
2014-10-15 10:39:02 -05:00
|
|
|
} else if (G_VALUE_HOLDS_FLAGS (value)) {
|
|
|
|
|
guint64 uint_val;
|
|
|
|
|
|
|
|
|
|
/* Flags are guint but GKeyFile has no uint reader, just uint64 */
|
|
|
|
|
uint_val = nm_keyfile_plugin_kf_get_uint64 (info->keyfile, setting_name, key, &err);
|
|
|
|
|
if (!err) {
|
|
|
|
|
if (uint_val <= G_MAXUINT)
|
|
|
|
|
g_object_set (setting, key, (guint) uint_val, NULL);
|
|
|
|
|
else {
|
|
|
|
|
nm_log_warn (LOGD_SETTINGS, "Too large FLAGS property (read): '%s/%s' : '%s'",
|
|
|
|
|
setting_name, key, G_VALUE_TYPE_NAME (value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_clear_error (&err);
|
|
|
|
|
} else if (G_VALUE_HOLDS_ENUM (value)) {
|
|
|
|
|
gint int_val;
|
|
|
|
|
|
|
|
|
|
int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, &err);
|
|
|
|
|
if (!err)
|
|
|
|
|
g_object_set (setting, key, (gint) int_val, NULL);
|
|
|
|
|
g_clear_error (&err);
|
2008-04-22 14:48:02 +00:00
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'",
|
|
|
|
|
setting_name, key, G_VALUE_TYPE_NAME (value));
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMSetting *
|
2013-04-03 11:48:04 -05:00
|
|
|
read_setting (GKeyFile *file, const char *keyfile_path, const char *group)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
2014-08-17 23:09:55 +02:00
|
|
|
NMSetting *setting = NULL;
|
2011-03-02 18:17:57 -06:00
|
|
|
ReadInfo info = { file, keyfile_path };
|
2013-04-03 11:48:04 -05:00
|
|
|
const char *alias;
|
2014-08-16 10:13:56 -04:00
|
|
|
GType type;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
alias = nm_keyfile_plugin_get_setting_name_for_alias (group);
|
2014-08-16 10:13:56 -04:00
|
|
|
if (alias)
|
|
|
|
|
group = alias;
|
|
|
|
|
|
2014-08-12 17:25:26 -04:00
|
|
|
type = nm_setting_lookup_type (group);
|
2014-08-16 10:13:56 -04:00
|
|
|
if (type) {
|
|
|
|
|
setting = g_object_new (type, NULL);
|
2011-03-02 18:17:57 -06:00
|
|
|
nm_setting_enumerate_values (setting, read_one_setting_value, &info);
|
2014-08-16 10:13:56 -04:00
|
|
|
} else
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Invalid setting name '%s'", group);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
return setting;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-04 14:32:14 +00:00
|
|
|
static void
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
read_vpn_secrets (GKeyFile *file, NMSettingVpn *s_vpn)
|
2008-09-04 14:32:14 +00:00
|
|
|
{
|
|
|
|
|
char **keys, **iter;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
keys = nm_keyfile_plugin_kf_get_keys (file, VPN_SECRETS_GROUP, NULL, NULL);
|
2008-09-04 14:32:14 +00:00
|
|
|
for (iter = keys; *iter; iter++) {
|
|
|
|
|
char *secret;
|
|
|
|
|
|
2013-04-03 11:48:04 -05:00
|
|
|
secret = nm_keyfile_plugin_kf_get_string (file, VPN_SECRETS_GROUP, *iter, NULL);
|
2008-10-29 09:13:40 +00:00
|
|
|
if (secret) {
|
|
|
|
|
nm_setting_vpn_add_secret (s_vpn, *iter, secret);
|
|
|
|
|
g_free (secret);
|
|
|
|
|
}
|
2008-09-04 14:32:14 +00:00
|
|
|
}
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
NMConnection *
|
2011-01-18 13:22:00 -06:00
|
|
|
nm_keyfile_plugin_connection_from_file (const char *filename, GError **error)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
|
|
|
|
GKeyFile *key_file;
|
|
|
|
|
struct stat statbuf;
|
2013-08-13 23:28:54 +02:00
|
|
|
gboolean bad_permissions;
|
2008-04-22 14:48:02 +00:00
|
|
|
NMConnection *connection = NULL;
|
2010-09-16 15:43:22 -05:00
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSetting *setting;
|
|
|
|
|
gchar **groups;
|
|
|
|
|
gsize length;
|
|
|
|
|
int i;
|
|
|
|
|
gboolean vpn_secrets = FALSE;
|
|
|
|
|
GError *verify_error = NULL;
|
|
|
|
|
|
|
|
|
|
if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) {
|
2010-09-16 17:39:06 -05:00
|
|
|
g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0,
|
2010-09-16 15:43:22 -05:00
|
|
|
"File did not exist or was not a regular file");
|
2008-04-22 14:48:02 +00:00
|
|
|
return NULL;
|
2010-09-16 15:43:22 -05:00
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
bad_permissions = statbuf.st_mode & 0077;
|
|
|
|
|
|
2013-08-13 23:28:54 +02:00
|
|
|
if (bad_permissions) {
|
2010-09-16 17:39:06 -05:00
|
|
|
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
2013-08-13 23:28:54 +02:00
|
|
|
"File permissions (%o) were insecure",
|
|
|
|
|
statbuf.st_mode);
|
2009-02-22 17:16:09 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
2010-09-16 15:43:22 -05:00
|
|
|
if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error))
|
|
|
|
|
goto out;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2014-08-13 14:34:29 -04:00
|
|
|
connection = nm_simple_connection_new ();
|
2008-09-04 14:32:14 +00:00
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
groups = g_key_file_get_groups (key_file, &length);
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
/* Only read out secrets when needed */
|
|
|
|
|
if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
|
|
|
|
|
vpn_secrets = TRUE;
|
|
|
|
|
continue;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 18:17:57 -06:00
|
|
|
setting = read_setting (key_file, filename, groups[i]);
|
2010-09-16 15:43:22 -05:00
|
|
|
if (setting)
|
|
|
|
|
nm_connection_add_setting (connection, setting);
|
|
|
|
|
}
|
2010-05-26 00:10:42 -07:00
|
|
|
|
2011-12-05 12:27:47 +01:00
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
2014-07-03 13:18:17 +02:00
|
|
|
if (!s_con) {
|
|
|
|
|
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
|
|
|
|
}
|
2013-11-14 09:49:30 -06:00
|
|
|
|
2014-07-03 13:18:17 +02:00
|
|
|
/* Make sure that we have 'id' even if not explictly specified in the keyfile */
|
|
|
|
|
if (!nm_setting_connection_get_id (s_con)) {
|
|
|
|
|
char *base_name;
|
2012-09-10 14:23:24 +02:00
|
|
|
|
2014-07-03 13:18:17 +02:00
|
|
|
base_name = g_path_get_basename (filename);
|
|
|
|
|
g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
|
|
|
|
|
g_free (base_name);
|
|
|
|
|
}
|
2012-09-10 14:23:24 +02:00
|
|
|
|
2014-07-03 13:18:17 +02:00
|
|
|
/* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
|
|
|
|
|
if (!nm_setting_connection_get_uuid (s_con)) {
|
|
|
|
|
char *hashed_uuid;
|
2012-09-10 14:23:24 +02:00
|
|
|
|
2014-07-03 13:18:17 +02:00
|
|
|
hashed_uuid = nm_utils_uuid_generate_from_string (filename);
|
|
|
|
|
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
|
|
|
|
|
g_free (hashed_uuid);
|
2010-09-16 15:43:22 -05:00
|
|
|
}
|
2008-09-04 14:32:14 +00:00
|
|
|
|
2014-08-05 14:13:42 -04:00
|
|
|
/* Make sure that we have 'interface-name' even if it was specified in the
|
|
|
|
|
* "wrong" (ie, deprecated) group.
|
|
|
|
|
*/
|
|
|
|
|
if ( !nm_setting_connection_get_interface_name (s_con)
|
|
|
|
|
&& nm_setting_connection_get_connection_type (s_con)) {
|
|
|
|
|
char *interface_name;
|
|
|
|
|
|
|
|
|
|
interface_name = g_key_file_get_string (key_file,
|
|
|
|
|
nm_setting_connection_get_connection_type (s_con),
|
|
|
|
|
"interface-name",
|
|
|
|
|
NULL);
|
|
|
|
|
if (interface_name) {
|
|
|
|
|
g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, interface_name, NULL);
|
|
|
|
|
g_free (interface_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
/* Handle vpn secrets after the 'vpn' setting was read */
|
|
|
|
|
if (vpn_secrets) {
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMSettingVpn *s_vpn;
|
2010-09-16 15:43:22 -05:00
|
|
|
|
2011-12-05 12:27:47 +01:00
|
|
|
s_vpn = nm_connection_get_setting_vpn (connection);
|
2010-09-16 15:43:22 -05:00
|
|
|
if (s_vpn)
|
|
|
|
|
read_vpn_secrets (key_file, s_vpn);
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
g_strfreev (groups);
|
|
|
|
|
|
2014-07-03 14:12:58 +02:00
|
|
|
/* Normalize and verify the connection */
|
|
|
|
|
if (!nm_connection_normalize (connection, NULL, NULL, &verify_error)) {
|
2010-09-16 17:39:06 -05:00
|
|
|
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
2014-10-13 11:57:35 -04:00
|
|
|
"invalid connection: %s",
|
|
|
|
|
verify_error->message);
|
2010-09-16 15:43:22 -05:00
|
|
|
g_clear_error (&verify_error);
|
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
connection = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_key_file_free (key_file);
|
2008-04-22 14:48:02 +00:00
|
|
|
return connection;
|
|
|
|
|
}
|