static gboolean
check_connection_mac_address (NMConnection *orig,
                              NMConnection *candidate,
                              GHashTable *settings)
{
	GHashTable *props;
	const char *orig_mac = NULL, *cand_mac = NULL;
	NMSettingWired *s_wired_orig, *s_wired_cand;

	props = check_property_in_hash (settings,
	                                NM_SETTING_WIRED_SETTING_NAME,
	                                NM_SETTING_WIRED_MAC_ADDRESS);
	if (!props)
		return TRUE;

	/* If one of the MAC addresses is NULL, we accept that connection */
	s_wired_orig = nm_connection_get_setting_wired (orig);
	if (s_wired_orig)
		orig_mac = nm_setting_wired_get_mac_address (s_wired_orig);

	s_wired_cand = nm_connection_get_setting_wired (candidate);
	if (s_wired_cand)
		cand_mac = nm_setting_wired_get_mac_address (s_wired_cand);

	if (!orig_mac || !cand_mac) {
		remove_from_hash (settings, props,
		                  NM_SETTING_WIRED_SETTING_NAME,
		                  NM_SETTING_WIRED_MAC_ADDRESS);
		return TRUE;
	}
	return FALSE;
}
Exemplo n.º 2
0
/* return value must be freed by caller with g_free() */
static gchar *
get_mac_address_of_connection (NMConnection *connection)
{
  const GByteArray *mac = NULL;

  if (!connection)
    return NULL;

  /* check the connection type */
  if (nm_connection_is_type (connection,
                             NM_SETTING_WIRELESS_SETTING_NAME))
    {
      /* check wireless settings */
      NMSettingWireless *s_wireless = nm_connection_get_setting_wireless (connection);
      if (!s_wireless)
        return NULL;
      mac = nm_setting_wireless_get_mac_address (s_wireless);
      if (mac)
        return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER);
    }
  else if (nm_connection_is_type (connection,
                                  NM_SETTING_WIRED_SETTING_NAME))
    {
      /* check wired settings */
      NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
      if (!s_wired)
        return NULL;
      mac = nm_setting_wired_get_mac_address (s_wired);
      if (mac)
        return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER);
    }
  else if (nm_connection_is_type (connection,
                                  NM_SETTING_WIMAX_SETTING_NAME))
    {
      /* check wimax settings */
      NMSettingWimax *s_wimax = nm_connection_get_setting_wimax (connection);
      if (!s_wimax)
        return NULL;
      mac = nm_setting_wimax_get_mac_address (s_wimax);
      if (mac)
        return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER);
    }
  else if (nm_connection_is_type (connection,
                                  NM_SETTING_INFINIBAND_SETTING_NAME))
    {
      /* check infiniband settings */
      NMSettingInfiniband *s_infiniband = \
        nm_connection_get_setting_infiniband (connection);
      if (!s_infiniband)
        return NULL;
      mac = nm_setting_infiniband_get_mac_address (s_infiniband);
      if (mac)
        return nm_utils_hwaddr_ntoa (mac->data,
                                     ARPHRD_INFINIBAND);
    }
  /* no MAC address found */
  return NULL;
}
Exemplo n.º 3
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingConnection *s_con;
	NMSettingVlan *s_vlan;
	NMSettingWired *s_wired;
	const char *ctype, *dev_iface_name, *vlan_iface_name;
	const GByteArray *mac_address;
	char *mac_address_str;

	s_con = nm_connection_get_setting_connection (connection);
	g_assert (s_con);

	ctype = nm_setting_connection_get_connection_type (s_con);
	if (strcmp (ctype, NM_SETTING_VLAN_SETTING_NAME) != 0) {
		g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_NOT_VLAN_CONNECTION,
		             "The connection was not a VLAN connection.");
		return FALSE;
	}

	s_vlan = nm_connection_get_setting_vlan (connection);
	if (!s_vlan) {
		g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INVALID_VLAN_CONNECTION,
		             "The connection was not a valid VLAN connection.");
		return FALSE;
	}

	if (nm_setting_vlan_get_id (s_vlan) != nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))) {
		g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_ID_MISMATCH,
		             "The VLAN identifiers of the device and the connection didn't match.");
		return FALSE;
	}

	dev_iface_name = nm_device_get_iface (device);
	vlan_iface_name = nm_setting_vlan_get_interface_name (s_vlan);
	if (vlan_iface_name && g_strcmp0 (dev_iface_name, vlan_iface_name) != 0) {
		g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INTERFACE_MISMATCH,
		             "The interfaces of the device and the connection didn't match.");
		return FALSE;
	}

	s_wired = nm_connection_get_setting_wired (connection);
	if (s_wired)
		mac_address = nm_setting_wired_get_mac_address (s_wired);
	else
		mac_address = NULL;
	if (mac_address) {
		mac_address_str = nm_utils_hwaddr_ntoa_len (mac_address->data, mac_address->len);
		if (!g_strcmp0 (mac_address_str, NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address)) {
			g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_MAC_MISMATCH,
			             "The hardware address of the device and the connection didn't match.");
		}
		g_free (mac_address_str);
	}

	return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error);
}
Exemplo n.º 4
0
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
    NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE (setting);
    NMSettingConnection *s_con;
    NMSettingWired *s_wired;

    if (connection) {
        s_con = nm_connection_get_setting_connection (connection);
        s_wired = nm_connection_get_setting_wired (connection);
    } else {
        s_con = NULL;
        s_wired = NULL;
    }

    if (priv->parent) {
        if (   !nm_utils_is_uuid (priv->parent)
                && !nm_utils_iface_valid_name (priv->parent)) {
            g_set_error (error,
                         NM_CONNECTION_ERROR,
                         NM_CONNECTION_ERROR_INVALID_PROPERTY,
                         _("'%s' is neither an UUID nor an interface name"),
                         priv->parent);
            g_prefix_error (error, "%s.%s: ", NM_SETTING_MACVLAN_SETTING_NAME, NM_SETTING_MACVLAN_PARENT);
            return FALSE;
        }
    } else {
        /* If parent is NULL, the parent must be specified via
         * NMSettingWired:mac-address.
         */
        if (   connection
                && (!s_wired || !nm_setting_wired_get_mac_address (s_wired))) {
            g_set_error (error,
                         NM_CONNECTION_ERROR,
                         NM_CONNECTION_ERROR_MISSING_PROPERTY,
                         _("property is not specified and neither is '%s:%s'"),
                         NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
            g_prefix_error (error, "%s.%s: ", NM_SETTING_MACVLAN_SETTING_NAME, NM_SETTING_MACVLAN_PARENT);
            return FALSE;
        }
    }

    if (!priv->promiscuous && priv->mode != NM_SETTING_MACVLAN_MODE_PASSTHRU) {
        g_set_error_literal (error,
                             NM_CONNECTION_ERROR,
                             NM_CONNECTION_ERROR_INVALID_PROPERTY,
                             _("non promiscuous operation is allowed only in passthru mode'"));
        g_prefix_error (error, "%s.%s: ",
                        NM_SETTING_MACVLAN_SETTING_NAME,
                        NM_SETTING_MACVLAN_PROMISCUOUS);
        return FALSE;

    }

    return TRUE;
}
static gboolean
check_ethernet_compatible (NMDeviceEthernet *device, NMConnection *connection, GError **error)
{
        NMSettingConnection *s_con;
        NMSettingWired *s_wired;
        const char *connection_type;
        gboolean is_pppoe = FALSE;

        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
        g_assert (s_con);

        connection_type = nm_setting_connection_get_connection_type (s_con);
        if (   strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)
            && strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) {
                g_set_error (error, 0, 0,
                             "The connection was not a wired or PPPoE connection.");
                return FALSE;
        }

        if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
                is_pppoe = TRUE;

        s_wired = (NMSettingWired *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED);
        /* Wired setting is optional for PPPoE */
        if (!is_pppoe && !s_wired) {
                g_set_error (error, 0, 0,
                             "The connection was not a valid wired connection.");
                return FALSE;
        }

        if (s_wired) {
                const GByteArray *mac;
                const char *device_mac_str;
                struct ether_addr *device_mac;

                device_mac_str = nm_device_ethernet_get_hw_address (device);
                device_mac = ether_aton (device_mac_str);
                if (!device_mac) {
                        g_set_error (error, 0, 0, "Invalid device MAC address.");
                        return FALSE;
                }

                mac = nm_setting_wired_get_mac_address (s_wired);
                if (mac && memcmp (mac->data, device_mac->ether_addr_octet, ETH_ALEN)) {
                        g_set_error (error, 0, 0,
                                     "The connection's MAC address did not match this device.");
                        return FALSE;
                }
        }

        // FIXME: check bitrate against device capabilities

        return TRUE;
}
Exemplo n.º 6
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingConnection *s_con;
	NMSettingWired *s_wired;
	const char *ctype;
	gboolean is_pppoe = FALSE;

	s_con = nm_connection_get_setting_connection (connection);
	g_assert (s_con);

	ctype = nm_setting_connection_get_connection_type (s_con);
	if (!strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
		is_pppoe = TRUE;
	else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0) {
		g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION,
		             "The connection was not a wired or PPPoE connection.");
		return FALSE;
	}

	s_wired = nm_connection_get_setting_wired (connection);
	/* Wired setting optional for PPPoE */
	if (!is_pppoe && !s_wired) {
		g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION,
		             "The connection was not a valid ethernet connection.");
		return FALSE;
	}

	if (s_wired) {
		const GByteArray *mac;
		const char *perm_str;
		struct ether_addr *perm_mac;

		/* FIXME: filter using s390 subchannels when they are exported over the bus */

		/* Check MAC address */
		perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
		if (perm_str) {
			perm_mac = ether_aton (perm_str);
			if (!perm_mac) {
				g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC,
				             "Invalid device MAC address.");
				return FALSE;
			}
			mac = nm_setting_wired_get_mac_address (s_wired);
			if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) {
				g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH,
				             "The MACs of the device and the connection didn't match.");
				return FALSE;
			}
		}
	}

	return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error);
}
Exemplo n.º 7
0
static void
get_property (GObject *object, guint prop_id,
              GValue *value, GParamSpec *pspec)
{
	NMSettingWired *setting = NM_SETTING_WIRED (object);
	NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);

	switch (prop_id) {
	case PROP_PORT:
		g_value_set_string (value, nm_setting_wired_get_port (setting));
		break;
	case PROP_SPEED:
		g_value_set_uint (value, nm_setting_wired_get_speed (setting));
		break;
	case PROP_DUPLEX:
		g_value_set_string (value, nm_setting_wired_get_duplex (setting));
		break;
	case PROP_AUTO_NEGOTIATE:
		g_value_set_boolean (value, nm_setting_wired_get_auto_negotiate (setting));
		break;
	case PROP_MAC_ADDRESS:
		g_value_set_boxed (value, nm_setting_wired_get_mac_address (setting));
		break;
	case PROP_CLONED_MAC_ADDRESS:
		g_value_set_boxed (value, nm_setting_wired_get_cloned_mac_address (setting));
		break;
	case PROP_MAC_ADDRESS_BLACKLIST:
		g_value_set_boxed (value, nm_setting_wired_get_mac_address_blacklist (setting));
		break;
	case PROP_MTU:
		g_value_set_uint (value, nm_setting_wired_get_mtu (setting));
		break;
	case PROP_S390_SUBCHANNELS:
		g_value_set_boxed (value, nm_setting_wired_get_s390_subchannels (setting));
		break;
	case PROP_S390_NETTYPE:
		g_value_set_string (value, nm_setting_wired_get_s390_nettype (setting));
		break;
	case PROP_S390_OPTIONS:
		g_value_set_boxed (value, priv->s390_options);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Exemplo n.º 8
0
static gboolean
match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
	  NMSettingWired *s_wired;
	  const char *setting_mac;
	  const char *device_mac;

	  s_wired = nm_connection_get_setting_wired (connection);
	  if (!s_wired)
		  return !fail_if_no_hwaddr;

	  setting_mac = nm_setting_wired_get_mac_address (s_wired);
	  if (!setting_mac)
		  return !fail_if_no_hwaddr;

	  device_mac = nm_device_get_hw_address (device);

	  return nm_utils_hwaddr_matches (setting_mac, -1, device_mac, -1);
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingWired *s_wired;
	gboolean is_pppoe = FALSE;

	if (!NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error))
		return FALSE;

	if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME))
		is_pppoe = TRUE;
	else if (!nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		                     _("The connection was not an Ethernet or PPPoE connection."));
		return FALSE;
	}

	s_wired = nm_connection_get_setting_wired (connection);
	/* Wired setting optional for PPPoE */
	if (s_wired) {
		const char *perm_addr, *setting_addr;

		/* FIXME: filter using s390 subchannels when they are exported over the bus */

		/* Check MAC address */
		perm_addr = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
		if (perm_addr) {
			if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) {
				g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
				                     _("Invalid device MAC address."));
				return FALSE;
			}
			setting_addr = nm_setting_wired_get_mac_address (s_wired);
			if (setting_addr && !nm_utils_hwaddr_matches (setting_addr, -1, perm_addr, -1)) {
				g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
				                     _("The MACs of the device and the connection didn't match."));
				return FALSE;
			}
		}
	}

	return TRUE;
}
Exemplo n.º 10
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMDeviceVlanPrivate *priv;
	NMSettingVlan *s_vlan;
	NMSettingWired *s_wired;
	const char *setting_hwaddr;

	if (!NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error))
		return FALSE;

	if (!nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		                     _("The connection was not a VLAN connection."));
		return FALSE;
	}

	s_vlan = nm_connection_get_setting_vlan (connection);
	if (nm_setting_vlan_get_id (s_vlan) != nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		                     _("The VLAN identifiers of the device and the connection didn't match."));
		return FALSE;
	}

	s_wired = nm_connection_get_setting_wired (connection);
	if (s_wired)
		setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
	else
		setting_hwaddr = NULL;
	if (setting_hwaddr) {
		priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
		if (   !priv->hw_address
		    || !nm_utils_hwaddr_matches (setting_hwaddr, -1,
		                                 priv->hw_address, -1)) {
			g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
			                     _("The hardware address of the device and the connection didn't match."));
		}
	}

	return TRUE;
}
Exemplo n.º 11
0
static gboolean
match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
	NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device);
	NMSettingWired *s_wired;
	const char *setting_mac;
	const char *parent_mac;

	s_wired = nm_connection_get_setting_wired (connection);
	if (!s_wired)
		return !fail_if_no_hwaddr;

	setting_mac = nm_setting_wired_get_mac_address (s_wired);
	if (!setting_mac)
		return !fail_if_no_hwaddr;

	if (!priv->parent)
		return !fail_if_no_hwaddr;

	parent_mac = nm_device_get_permanent_hw_address (priv->parent, FALSE);
	return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
}
Exemplo n.º 12
0
static const char *
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
{
	NMSettingVlan *s_vlan;
	NMSettingWired *s_wired;
	const char *parent = NULL;

	g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME), NULL);

	s_vlan = nm_connection_get_setting_vlan (connection);
	g_assert (s_vlan);

	parent = nm_setting_vlan_get_parent (s_vlan);
	if (parent)
		return parent;

	/* Try the hardware address from the VLAN connection's hardware setting */
	s_wired = nm_connection_get_setting_wired (connection);
	if (s_wired)
		return nm_setting_wired_get_mac_address (s_wired);

	return NULL;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
	NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
	NMSettingConnection *s_con = NULL;
	NMSettingWired *s_wired = NULL;
	GSList *iter;

	for (iter = all_settings; iter; iter = iter->next) {
		if (NM_IS_SETTING_CONNECTION (iter->data))
			s_con = iter->data;
		else if (NM_IS_SETTING_WIRED (iter->data))
			s_wired = iter->data;
	}

	/* If iface_name is specified, it must be a valid interface name. We
	 * don't check that it matches parent and/or id, because we allowing
	 * renaming vlans to arbitrary names.
	 */
	if (priv->iface_name && !nm_utils_iface_valid_name (priv->iface_name)) {
		g_set_error (error,
		             NM_SETTING_VLAN_ERROR,
		             NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
		             NM_SETTING_VLAN_INTERFACE_NAME);
		return FALSE;
	}

	if (priv->parent) {
		if (nm_utils_is_uuid (priv->parent)) {
			/* If we have an NMSettingConnection:master with slave-type="vlan",
			 * then it must be the same UUID.
			 */
			if (s_con) {
				const char *master = NULL, *slave_type = NULL;

				slave_type = nm_setting_connection_get_slave_type (s_con);
				if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME))
					master = nm_setting_connection_get_master (s_con);

				if (master && g_strcmp0 (priv->parent, master) != 0) {
					g_set_error (error,
					             NM_SETTING_VLAN_ERROR,
					             NM_SETTING_VLAN_ERROR_INVALID_PARENT,
					             NM_SETTING_CONNECTION_MASTER);
					return FALSE;
				}
			}
		} else if (!nm_utils_iface_valid_name (priv->parent)) {
			/* parent must be either a UUID or an interface name */
			g_set_error (error,
			             NM_SETTING_VLAN_ERROR,
			             NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
			             NM_SETTING_VLAN_PARENT);
			return FALSE;
		} 
	} else {
		/* If parent is NULL, the parent must be specified via
		 * NMSettingWired:mac-address.
		 */
		if (!s_wired || !nm_setting_wired_get_mac_address (s_wired)) {
			g_set_error (error,
			             NM_SETTING_VLAN_ERROR,
			             NM_SETTING_VLAN_ERROR_MISSING_PROPERTY,
			             NM_SETTING_VLAN_PARENT);
			return FALSE;
		}
	}

	if (priv->flags & ~(NM_VLAN_FLAG_REORDER_HEADERS |
	                    NM_VLAN_FLAG_GVRP |
	                    NM_VLAN_FLAG_LOOSE_BINDING)) {
		g_set_error (error,
		             NM_SETTING_VLAN_ERROR,
		             NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
		             NM_SETTING_VLAN_FLAGS);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 14
0
static void
populate_ui (CEPageWired *self)
{
	CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self);
	NMSettingWired *setting = priv->setting;
	const char *port;
	const char *duplex;
	int port_idx = PORT_DEFAULT;
	int speed_idx;
	int mtu_def;
	char **mac_list, **iter;
	const GByteArray *s_mac;
	char *s_mac_str;
	char *active_mac = NULL;
	GtkWidget *entry;

	/* Port */
	port = nm_setting_wired_get_port (setting);
	if (port) {
		if (!strcmp (port, "tp"))
			port_idx = PORT_TP;
		else if (!strcmp (port, "aui"))
			port_idx = PORT_AUI;
		else if (!strcmp (port, "bnc"))
			port_idx = PORT_BNC;
		else if (!strcmp (port, "mii"))
			port_idx = PORT_MII;
	}
	gtk_combo_box_set_active (priv->port, port_idx);

	/* Speed */
	switch (nm_setting_wired_get_speed (setting)) {
	case 10:
		speed_idx = SPEED_10;
		break;
	case 100:
		speed_idx = SPEED_100;
		break;
	case 1000:
		speed_idx = SPEED_1000;
		break;
	case 10000:
		speed_idx = SPEED_10000;
		break;
	default:
		speed_idx = SPEED_DEFAULT;
		break;
	}
	gtk_combo_box_set_active (priv->speed, speed_idx);

	/* Duplex */
	duplex = nm_setting_wired_get_duplex (setting);
	if (duplex && !strcmp (duplex, "half"))
		gtk_toggle_button_set_active (priv->duplex, FALSE);
	else
		gtk_toggle_button_set_active (priv->duplex, TRUE);

	/* Autonegotiate */
	gtk_toggle_button_set_active (priv->autonegotiate, 
	                              nm_setting_wired_get_auto_negotiate (setting));

	/* Device MAC address */
	mac_list = ce_page_get_mac_list (CE_PAGE (self));
	s_mac = nm_setting_wired_get_mac_address (setting);
	s_mac_str = s_mac ? g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
	                                     s_mac->data[0], s_mac->data[1], s_mac->data[2],
	                                     s_mac->data[3], s_mac->data[4], s_mac->data[5]):
	                    NULL;

	for (iter = mac_list; iter && *iter; iter++) {
#if GTK_CHECK_VERSION (2,24,0)
		gtk_combo_box_text_append_text (priv->device_mac, *iter);
#else
		gtk_combo_box_append_text (GTK_COMBO_BOX (priv->device_mac), *iter);
#endif
		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
			active_mac = *iter;
	}

	if (s_mac_str) {
		if (!active_mac) {
#if GTK_CHECK_VERSION (2,24,0)
			gtk_combo_box_text_prepend_text (priv->device_mac, s_mac_str);
#else
			gtk_combo_box_prepend_text (GTK_COMBO_BOX (priv->device_mac), s_mac_str);
#endif
		}

		entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
		if (entry)
			gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : s_mac_str);
	}
	g_strfreev (mac_list);
	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);

	/* Cloned MAC address */
	ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting), priv->cloned_mac);
	g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);

	/* MTU */
	mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
	g_signal_connect (priv->mtu, "output",
	                  G_CALLBACK (ce_spin_output_with_default),
	                  GINT_TO_POINTER (mtu_def));

	gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
}
static void
populate_ui (CEPageEthernet *self)
{
	CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self);
	NMSettingWired *setting = priv->setting;
	const char *port;
	const char *duplex;
	int port_idx = PORT_DEFAULT;
	int speed_idx;
	int mtu_def;
	char **mac_list;
	const GByteArray *s_mac;
	char *s_mac_str;

	/* Port */
	port = nm_setting_wired_get_port (setting);
	if (port) {
		if (!strcmp (port, "tp"))
			port_idx = PORT_TP;
		else if (!strcmp (port, "aui"))
			port_idx = PORT_AUI;
		else if (!strcmp (port, "bnc"))
			port_idx = PORT_BNC;
		else if (!strcmp (port, "mii"))
			port_idx = PORT_MII;
	}
	gtk_combo_box_set_active (priv->port, port_idx);

	/* Speed */
	switch (nm_setting_wired_get_speed (setting)) {
	case 10:
		speed_idx = SPEED_10;
		break;
	case 100:
		speed_idx = SPEED_100;
		break;
	case 1000:
		speed_idx = SPEED_1000;
		break;
	case 10000:
		speed_idx = SPEED_10000;
		break;
	default:
		speed_idx = SPEED_DEFAULT;
		break;
	}
	gtk_combo_box_set_active (priv->speed, speed_idx);

	/* Duplex */
	duplex = nm_setting_wired_get_duplex (setting);
	if (duplex && !strcmp (duplex, "half"))
		gtk_toggle_button_set_active (priv->duplex, FALSE);
	else
		gtk_toggle_button_set_active (priv->duplex, TRUE);

	/* Autonegotiate */
	gtk_toggle_button_set_active (priv->autonegotiate, 
	                              nm_setting_wired_get_auto_negotiate (setting));

	/* Device MAC address */
	mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_ETHERNET,
	                                 NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
	s_mac = nm_setting_wired_get_mac_address (setting);
	s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
	ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
	                         s_mac_str, mac_list);
	g_free (s_mac_str);
	g_strfreev (mac_list);
	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);

	/* Cloned MAC address */
	ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting),
	                      ARPHRD_ETHER, priv->cloned_mac);
	g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);

	/* MTU */
	mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
	g_signal_connect (priv->mtu, "output",
	                  G_CALLBACK (ce_spin_output_with_default),
	                  GINT_TO_POINTER (mtu_def));

	gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
}
static void
connect_ethernet_page (CEPageEthernet *page)
{
        NMSettingWired *setting = page->setting_wired;
        NMSettingConnection *sc;
        int mtu_def;
        char **mac_list;
        const GByteArray *s_mac;
        char *s_mac_str;
        GtkWidget *widget;
        const gchar *name;

        name = nm_setting_connection_get_id (page->setting_connection);
        gtk_entry_set_text (page->name, name);

        /* Device MAC address */
        mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_ETHERNET,
                                         NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
        s_mac = nm_setting_wired_get_mac_address (setting);
        s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
        ce_page_setup_mac_combo (page->device_mac, s_mac_str, mac_list);
        g_free (s_mac_str);
        g_strfreev (mac_list);
        g_signal_connect_swapped (page->device_mac, "changed", G_CALLBACK (ce_page_changed), page);

        /* Cloned MAC address */
        ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting),
                              ARPHRD_ETHER, page->cloned_mac);
        g_signal_connect_swapped (page->cloned_mac, "changed", G_CALLBACK (ce_page_changed), page);

        /* MTU */
        mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
        g_signal_connect (page->mtu, "output",
                          G_CALLBACK (ce_spin_output_with_default),
                          GINT_TO_POINTER (mtu_def));
        gtk_spin_button_set_value (page->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
        g_signal_connect (page->mtu, "value-changed",
                          G_CALLBACK (mtu_changed), page);
        mtu_changed (page->mtu, page);

        g_signal_connect_swapped (page->name, "changed", G_CALLBACK (ce_page_changed), page);
        g_signal_connect_swapped (page->mtu, "value-changed", G_CALLBACK (ce_page_changed), page);

        widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder,
                                                     "auto_connect_check"));
        sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection);
        g_object_bind_property (sc, "autoconnect",
                                widget, "active",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
        g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page);

        widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder,
                                                     "all_user_check"));
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
                                      nm_setting_connection_get_num_permissions (sc) == 0);
        g_signal_connect (widget, "toggled",
                          G_CALLBACK (all_user_changed), page);
        g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page);

        widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone"));
        firewall_ui_setup (sc, widget, CE_PAGE (page)->cancellable);
        g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);

}
Exemplo n.º 17
0
static void
populate_ui (CEPageWired *self)
{
	CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self);
	NMSettingWired *setting = priv->setting;
	const char *port;
	const char *duplex;
	int port_idx = PORT_DEFAULT;
	int speed_idx;
	int mtu_def;

	/* Port */
	port = nm_setting_wired_get_port (setting);
	if (port) {
		if (!strcmp (port, "tp"))
			port_idx = PORT_TP;
		else if (!strcmp (port, "aui"))
			port_idx = PORT_AUI;
		else if (!strcmp (port, "bnc"))
			port_idx = PORT_BNC;
		else if (!strcmp (port, "mii"))
			port_idx = PORT_MII;
	}
	gtk_combo_box_set_active (priv->port, port_idx);

	/* Speed */
	switch (nm_setting_wired_get_speed (setting)) {
	case 10:
		speed_idx = SPEED_10;
		break;
	case 100:
		speed_idx = SPEED_100;
		break;
	case 1000:
		speed_idx = SPEED_1000;
		break;
	case 10000:
		speed_idx = SPEED_10000;
		break;
	default:
		speed_idx = SPEED_DEFAULT;
		break;
	}
	gtk_combo_box_set_active (priv->speed, speed_idx);

	/* Duplex */
	duplex = nm_setting_wired_get_duplex (setting);
	if (duplex && !strcmp (duplex, "half"))
		gtk_toggle_button_set_active (priv->duplex, FALSE);
	else
		gtk_toggle_button_set_active (priv->duplex, TRUE);

	/* Autonegotiate */
	gtk_toggle_button_set_active (priv->autonegotiate, 
	                              nm_setting_wired_get_auto_negotiate (setting));

	/* MAC address */
	ce_page_mac_to_entry (nm_setting_wired_get_mac_address (setting), priv->mac);
	g_signal_connect (priv->mac, "changed", G_CALLBACK (stuff_changed), self);

	/* MTU */
	mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
	g_signal_connect (priv->mtu, "output",
	                  G_CALLBACK (ce_spin_output_with_default),
	                  GINT_TO_POINTER (mtu_def));

	gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
}
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
	NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
	NMSettingConnection *s_con;
	NMSettingWired *s_wired;

	if (connection) {
		s_con = nm_connection_get_setting_connection (connection);
		s_wired = nm_connection_get_setting_wired (connection);
	} else {
		s_con = NULL;
		s_wired = NULL;
	}

	if (priv->parent) {
		if (nm_utils_is_uuid (priv->parent)) {
			/* If we have an NMSettingConnection:master with slave-type="vlan",
			 * then it must be the same UUID.
			 */
			if (s_con) {
				const char *master = NULL, *slave_type = NULL;

				slave_type = nm_setting_connection_get_slave_type (s_con);
				if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME))
					master = nm_setting_connection_get_master (s_con);

				if (master && g_strcmp0 (priv->parent, master) != 0) {
					g_set_error (error,
					             NM_CONNECTION_ERROR,
					             NM_CONNECTION_ERROR_INVALID_PROPERTY,
					             _("'%s' value doesn't match '%s=%s'"),
					             priv->parent, NM_SETTING_CONNECTION_MASTER, master);
					g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
					return FALSE;
				}
			}
		} else if (!nm_utils_iface_valid_name (priv->parent)) {
			/* parent must be either a UUID or an interface name */
			g_set_error (error,
			             NM_CONNECTION_ERROR,
			             NM_CONNECTION_ERROR_INVALID_PROPERTY,
			             _("'%s' is neither an UUID nor an interface name"),
			             priv->parent);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
			return FALSE;
		}
	} else {
		/* If parent is NULL, the parent must be specified via
		 * NMSettingWired:mac-address.
		 */
		if (   connection
		    && (!s_wired || !nm_setting_wired_get_mac_address (s_wired))) {
			g_set_error (error,
			             NM_CONNECTION_ERROR,
			             NM_CONNECTION_ERROR_MISSING_PROPERTY,
			             _("property is not specified and neither is '%s:%s'"),
			             NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
			g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
			return FALSE;
		}
	}

	if (priv->id >= 4095) {
		g_set_error (error,
		             NM_CONNECTION_ERROR,
		             NM_CONNECTION_ERROR_INVALID_PROPERTY,
		             _("the vlan id must be in range 0-4094 but is %u"),
		             priv->id);
		g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_ID);
	}

	if (priv->flags & ~NM_VLAN_FLAGS_ALL) {
		g_set_error_literal (error,
		                     NM_CONNECTION_ERROR,
		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
		                     _("flags are invalid"));
		g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_FLAGS);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 19
0
static void
populate_ui (CEPageVlan *self)
{
    CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self);
    GSList *devices, *d_iter;
    NMConnection *parent_connection = NULL;
    NMDevice *device, *parent_device = NULL;
    const char *parent, *iface, *current_parent;
    int i, mtu_def, mtu_val;

    devices = get_vlan_devices (self);

    /* Parent */
    build_vlan_parent_list (self, devices);

    parent = nm_setting_vlan_get_parent (priv->setting);
    if (parent) {
        /* UUID? */
        parent_connection = (NMConnection *)nm_remote_settings_get_connection_by_uuid (CE_PAGE (self)->settings, parent);
        if (!parent_connection) {
            /* Interface name? */
            for (d_iter = devices; d_iter; d_iter = d_iter->next) {
                device = d_iter->data;

                if (!g_strcmp0 (parent, nm_device_get_iface (device))) {
                    parent_device = device;
                    break;
                }
            }
        }
    }

    /* If NMSettingVlan:parent didn't indicate a device, but we have a
     * wired setting, figure out the device from that.
     */
    if (priv->s_hw && !parent_device) {
        const GByteArray *mac;
        const char *device_mac_str;
        char *mac_str;

        if (NM_IS_SETTING_WIRED (priv->s_hw))
            mac = nm_setting_wired_get_mac_address (NM_SETTING_WIRED (priv->s_hw));
        else
            mac = NULL;

        if (mac) {
            mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER);

            for (d_iter = devices; d_iter; d_iter = d_iter->next) {
                device = d_iter->data;

                if (NM_IS_DEVICE_ETHERNET (device))
                    device_mac_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
                else
                    device_mac_str = NULL;

                if (!g_strcmp0 (mac_str, device_mac_str)) {
                    parent_device = device;
                    break;
                }
            }
        }
    }

    current_parent = parent;
    if (parent_device || parent_connection) {
        for (i = 0; priv->parents[i]; i++) {
            if (parent_device && parent_device != priv->parents[i]->device)
                continue;
            if (parent_connection != priv->parents[i]->connection)
                continue;

            current_parent = priv->parents[i]->label;
            break;
        }
    }
    ce_page_setup_mac_combo (CE_PAGE (self), priv->parent, current_parent, priv->parent_labels);
    g_signal_connect (priv->parent, "changed", G_CALLBACK (parent_changed), self);

    if (current_parent)
        priv->last_parent = g_strndup (current_parent, strcspn (current_parent, " "));

    /* Name */
    iface = nm_setting_vlan_get_interface_name (priv->setting);
    if (iface)
        gtk_entry_set_text (priv->name_entry, iface);
    g_signal_connect (priv->name_entry, "changed", G_CALLBACK (name_changed), self);

    /* ID */
    priv->last_id = nm_setting_vlan_get_id (priv->setting);
    gtk_spin_button_set_value (priv->id_entry, priv->last_id);
    g_signal_connect (priv->id_entry, "value-changed", G_CALLBACK (id_changed), self);

    /* Cloned MAC address */
    if (NM_IS_SETTING_WIRED (priv->s_hw)) {
        ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (NM_SETTING_WIRED (priv->s_hw)),
                              ARPHRD_ETHER, priv->cloned_mac);
    }
    g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);

    /* MTU */
    if (NM_IS_SETTING_WIRED (priv->s_hw)) {
        mtu_def = ce_get_property_default (priv->s_hw, NM_SETTING_WIRED_MTU);
        mtu_val = nm_setting_wired_get_mtu (NM_SETTING_WIRED (priv->s_hw));
    } else {
        mtu_def = mtu_val = 1500;
    }
    g_signal_connect (priv->mtu, "output",
                      G_CALLBACK (ce_spin_output_with_default),
                      GINT_TO_POINTER (mtu_def));

    gtk_spin_button_set_value (priv->mtu, (gdouble) mtu_val);
    g_signal_connect (priv->mtu, "value-changed", G_CALLBACK (stuff_changed), self);

    g_slist_free (devices);
}
Exemplo n.º 20
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingWired *s_wired;

	if (!NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error))
		return FALSE;

	if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) {
		/* NOP */
	} else if (!nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		                     _("The connection was not an Ethernet or PPPoE connection."));
		return FALSE;
	}

	s_wired = nm_connection_get_setting_wired (connection);
	/* Wired setting optional for PPPoE */
	if (s_wired) {
		const char *perm_addr, *s_mac;
		gboolean try_mac = TRUE;
		const char * const *mac_blacklist;
		int i;

		/* Check s390 subchannels */
		if (!match_subchans (NM_DEVICE_ETHERNET (device), s_wired, &try_mac)) {
			g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
			                     _("The connection and device differ in S390 subchannels."));
			return FALSE;
		}

		/* Check MAC address */
		perm_addr = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
		s_mac = nm_setting_wired_get_mac_address (s_wired);
		if (perm_addr) {
			if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) {
				g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
				                     _("Invalid device MAC address."));
				return FALSE;
			}
			if (try_mac && s_mac && !nm_utils_hwaddr_matches (s_mac, -1, perm_addr, -1)) {
				g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
				                     _("The MACs of the device and the connection do not match."));
				return FALSE;
			}

			/* Check for MAC address blacklist */
			mac_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired);
			for (i = 0; mac_blacklist[i]; i++) {
				if (!nm_utils_hwaddr_valid (mac_blacklist[i], ETH_ALEN)) {
					g_warn_if_reached ();
					g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
				                     _("Invalid MAC in the blacklist: %s."), mac_blacklist[i]);
					return FALSE;
				}

				if (nm_utils_hwaddr_matches (mac_blacklist[i], -1, perm_addr, -1)) {
					g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
				                     _("Device MAC (%s) is blacklisted by the connection."), perm_addr);
					return FALSE;
				}
			}
		}
	}

	return TRUE;
}