summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2015-03-18 11:52:10 +0100
committerJiří Klimeš <jklimes@redhat.com>2015-03-18 17:28:52 +0100
commit9d30807fe26282f682732f930900361aedcaf59e (patch)
treec14607447e9f3c7e0106d65aace180443236a6e2
parentb988a2e1c65c05e4b4ce9ae8b71a78609f7f06b5 (diff)
downloadnetwork-manager-applet-9d30807fe26282f682732f930900361aedcaf59e.tar.gz
editor: fix on-the-fly color validation for 0.0.0.0/:: (rh #1201416)
https://bugzilla.redhat.com/show_bug.cgi?id=1201416
-rw-r--r--src/connection-editor/ip4-routes-dialog.c5
-rw-r--r--src/connection-editor/ip6-routes-dialog.c3
-rw-r--r--src/connection-editor/page-ip4.c30
-rw-r--r--src/connection-editor/page-ip6.c40
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 42e3a6a9..c7ff6cc7 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 3cfdb747..b7e48f2c 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 f2cbb02d..f4c24bb5 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 cfa09ffd..0d79589b 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));