[network-manager-applet] editor: fix on-the-fly color validation for 0.0.0.0/:: (rh #1201416)
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] editor: fix on-the-fly color validation for 0.0.0.0/:: (rh #1201416)
- Date: Wed, 18 Mar 2015 17:21:36 +0000 (UTC)
commit 9d30807fe26282f682732f930900361aedcaf59e
Author: Jiří Klimeš <jklimes redhat com>
Date: Wed Mar 18 11:52:10 2015 +0100
editor: fix on-the-fly color validation for 0.0.0.0/:: (rh #1201416)
https://bugzilla.redhat.com/show_bug.cgi?id=1201416
src/connection-editor/ip4-routes-dialog.c | 5 +++-
src/connection-editor/ip6-routes-dialog.c | 3 ++
src/connection-editor/page-ip4.c | 30 ++++++++++++++++++---
src/connection-editor/page-ip6.c | 40 +++++++++++++++++++++++-----
4 files changed, 66 insertions(+), 12 deletions(-)
---
diff --git a/src/connection-editor/ip4-routes-dialog.c b/src/connection-editor/ip4-routes-dialog.c
index 42e3a6a..c7ff6cc 100644
--- a/src/connection-editor/ip4-routes-dialog.c
+++ b/src/connection-editor/ip4-routes-dialog.c
@@ -475,11 +475,14 @@ cell_changed_cb (GtkEditable *editable,
else
value_valid = TRUE;
} else {
- struct in_addr tmp_addr;
+ struct in_addr tmp_addr = { 0 };
if (inet_pton (AF_INET, cell_text, &tmp_addr) > 0)
value_valid = TRUE;
+ /* 0.0.0.0 is not accepted for address */
+ if (column == COL_ADDRESS && tmp_addr.s_addr == 0)
+ value_valid = FALSE;
/* Consider empty next_hop as valid */
if (!*cell_text && column == COL_NEXT_HOP)
value_valid = TRUE;
diff --git a/src/connection-editor/ip6-routes-dialog.c b/src/connection-editor/ip6-routes-dialog.c
index 3cfdb74..b7e48f2 100644
--- a/src/connection-editor/ip6-routes-dialog.c
+++ b/src/connection-editor/ip6-routes-dialog.c
@@ -425,6 +425,9 @@ cell_changed_cb (GtkEditable *editable,
if (inet_pton (AF_INET6, cell_text, &tmp_addr) > 0)
value_valid = TRUE;
+ /* :: is not accepted for address */
+ if (column == COL_ADDRESS && IN6_IS_ADDR_UNSPECIFIED (&tmp_addr))
+ value_valid = FALSE;
/* Consider empty next_hop as valid */
if (!*cell_text && column == COL_NEXT_HOP)
value_valid = TRUE;
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index f2cbb02..f4c24bb 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -704,6 +704,18 @@ parse_netmask (const char *str, guint32 *prefix)
}
static gboolean
+is_address_unspecified (const char *str)
+{
+ struct in_addr addr;
+
+ if (!str)
+ return FALSE;
+
+ return ( inet_pton (AF_INET, str, &addr) == 1
+ && addr.s_addr == INADDR_ANY);
+}
+
+static gboolean
cell_changed_cb (GtkEditable *editable,
gpointer user_data)
{
@@ -726,6 +738,13 @@ cell_changed_cb (GtkEditable *editable,
if (inet_pton (AF_INET, cell_text, &tmp_addr) > 0)
value_valid = TRUE;
+
+ /* 0.0.0.0 is not accepted for address */
+ if (column == COL_ADDRESS && tmp_addr.s_addr == 0)
+ value_valid = FALSE;
+ /* Consider empty gateway as valid */
+ if (!*cell_text && column == COL_GATEWAY)
+ value_valid = TRUE;
}
/* Change cell's background color while editing */
@@ -921,7 +940,8 @@ cell_error_data_func (GtkTreeViewColumn *tree_column,
gtk_tree_model_get (tree_model, iter, col, &value, -1);
if (col == COL_ADDRESS)
- invalid = !value || !*value || !nm_utils_ipaddr_valid (AF_INET, value);
+ invalid = !value || !*value || !nm_utils_ipaddr_valid (AF_INET, value)
+ || is_address_unspecified (value);
else if (col == COL_PREFIX)
invalid = !parse_netmask (value, &prefix);
else if (col == COL_GATEWAY)
@@ -1143,7 +1163,9 @@ ui_to_setting (CEPageIP4 *self)
COL_GATEWAY, &addr_gw,
-1);
- if (!addr || !nm_utils_ipaddr_valid (AF_INET, addr)) {
+ if ( !addr
+ || !nm_utils_ipaddr_valid (AF_INET, addr)
+ || is_address_unspecified (addr)) {
g_warning ("%s: IPv4 address '%s' missing or invalid!",
__func__, addr ? addr : "<none>");
g_free (addr);
@@ -1162,7 +1184,7 @@ ui_to_setting (CEPageIP4 *self)
}
/* Gateway is optional... */
- if (addr_gw && !nm_utils_ipaddr_valid (AF_INET, addr_gw)) {
+ if (addr_gw && *addr_gw && !nm_utils_ipaddr_valid (AF_INET, addr_gw)) {
g_warning ("%s: IPv4 gateway '%s' invalid!",
__func__, addr_gw);
g_free (addr);
@@ -1174,7 +1196,7 @@ ui_to_setting (CEPageIP4 *self)
nm_addr = nm_ip_address_new (AF_INET, addr, prefix, NULL);
g_ptr_array_add (addresses, nm_addr);
- if (addresses->len == 1 && addr_gw) {
+ if (addresses->len == 1 && addr_gw && *addr_gw) {
gateway = addr_gw;
addr_gw = NULL;
}
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index cfa09ff..0d79589 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -474,6 +474,18 @@ is_prefix_valid (const char *prefix_str, guint32 *out_prefix)
}
}
+static gboolean
+is_address_unspecified (const char *str)
+{
+ struct in6_addr addr;
+
+ if (!str)
+ return FALSE;
+
+ return ( inet_pton (AF_INET6, str, &addr) == 1
+ && IN6_IS_ADDR_UNSPECIFIED (&addr));
+}
+
static void
addr_add_clicked (GtkButton *button, gpointer user_data)
{
@@ -722,6 +734,13 @@ cell_changed_cb (GtkEditable *editable,
if (inet_pton (AF_INET6, cell_text, &tmp_addr))
value_valid = TRUE;
+
+ /* :: is not accepted for address */
+ if (column == COL_ADDRESS && IN6_IS_ADDR_UNSPECIFIED (&tmp_addr))
+ value_valid = FALSE;
+ /* Consider empty gateway as valid */
+ if (!*cell_text && column == COL_GATEWAY)
+ value_valid = TRUE;
}
/* Change cell's background color while editing */
@@ -921,7 +940,8 @@ cell_error_data_func (GtkTreeViewColumn *tree_column,
gtk_tree_model_get (tree_model, iter, col, &value, -1);
if (col == COL_ADDRESS)
- invalid = !value || !*value || !nm_utils_ipaddr_valid (AF_INET6, value);
+ invalid = !value || !*value || !nm_utils_ipaddr_valid (AF_INET6, value)
+ || is_address_unspecified (value);
else if (col == COL_PREFIX)
invalid = !is_prefix_valid (value, NULL);
else if (col == COL_GATEWAY)
@@ -1081,6 +1101,7 @@ ui_to_setting (CEPageIP6 *self)
GtkTreeIter tree_iter;
int int_method = IP6_METHOD_AUTO;
const char *method;
+ char *gateway = NULL;
gboolean valid = FALSE, iter_valid;
const char *text;
gboolean ignore_auto_dns = FALSE;
@@ -1139,7 +1160,9 @@ ui_to_setting (CEPageIP6 *self)
COL_GATEWAY, &addr_gw_str,
-1);
- if (!addr_str || !nm_utils_ipaddr_valid (AF_INET6, addr_str)) {
+ if ( !addr_str
+ || !nm_utils_ipaddr_valid (AF_INET6, addr_str)
+ || is_address_unspecified (addr_str)) {
g_warning ("%s: IPv6 address '%s' missing or invalid!",
__func__, addr_str ? addr_str : "<none>");
g_free (addr_str);
@@ -1160,7 +1183,7 @@ ui_to_setting (CEPageIP6 *self)
}
/* Gateway is optional... */
- if (addr_gw_str && !nm_utils_ipaddr_valid (AF_INET6, addr_gw_str)) {
+ if (addr_gw_str && *addr_gw_str && !nm_utils_ipaddr_valid (AF_INET6, addr_gw_str)) {
g_warning ("%s: IPv6 gateway '%s' invalid!",
__func__, addr_gw_str);
g_free (addr_str);
@@ -1173,10 +1196,9 @@ ui_to_setting (CEPageIP6 *self)
nm_setting_ip_config_add_address (priv->setting, addr);
nm_ip_address_unref (addr);
- if (nm_setting_ip_config_get_num_addresses (priv->setting) == 1 && addr_gw_str) {
- g_object_set (G_OBJECT (priv->setting),
- NM_SETTING_IP_CONFIG_GATEWAY, addr_gw_str,
- NULL);
+ if (nm_setting_ip_config_get_num_addresses (priv->setting) == 1 && addr_gw_str &&
*addr_gw_str) {
+ gateway = addr_gw_str;
+ addr_gw_str = NULL;
}
g_free (addr_str);
@@ -1186,6 +1208,10 @@ ui_to_setting (CEPageIP6 *self)
iter_valid = gtk_tree_model_iter_next (model, &tree_iter);
}
+ g_object_set (G_OBJECT (priv->setting),
+ NM_SETTING_IP_CONFIG_GATEWAY, gateway,
+ NULL);
+
/* DNS servers */
nm_setting_ip_config_clear_dns (priv->setting);
text = gtk_entry_get_text (GTK_ENTRY (priv->dns_servers));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]