Commit 5366c3d6 authored by Dan Winship's avatar Dan Winship Committed by Dan Williams

wired: split NMDeviceWired out of NMDeviceEthernet and add NMDeviceInfiniband

parent 730f034a
......@@ -101,20 +101,22 @@ typedef enum {
* @NM_DEVICE_TYPE_WIMAX: an 802.16e Mobile WiMAX broadband device
* @NM_DEVICE_TYPE_MODEM: a modem supporting analog telephone, CDMA/EVDO,
* GSM/UMTS, or LTE network access protocols
* @NM_DEVICE_TYPE_INFINIBAND: an IP-over-Infiniband device
*
* #NMDeviceType values indicate the type of hardware represented by
* an #NMDevice.
**/
typedef enum {
NM_DEVICE_TYPE_UNKNOWN = 0,
NM_DEVICE_TYPE_ETHERNET = 1,
NM_DEVICE_TYPE_WIFI = 2,
NM_DEVICE_TYPE_UNUSED1 = 3,
NM_DEVICE_TYPE_UNUSED2 = 4,
NM_DEVICE_TYPE_BT = 5, /* Bluetooth */
NM_DEVICE_TYPE_OLPC_MESH = 6,
NM_DEVICE_TYPE_WIMAX = 7,
NM_DEVICE_TYPE_MODEM = 8,
NM_DEVICE_TYPE_UNKNOWN = 0,
NM_DEVICE_TYPE_ETHERNET = 1,
NM_DEVICE_TYPE_WIFI = 2,
NM_DEVICE_TYPE_UNUSED1 = 3,
NM_DEVICE_TYPE_UNUSED2 = 4,
NM_DEVICE_TYPE_BT = 5, /* Bluetooth */
NM_DEVICE_TYPE_OLPC_MESH = 6,
NM_DEVICE_TYPE_WIMAX = 7,
NM_DEVICE_TYPE_MODEM = 8,
NM_DEVICE_TYPE_INFINIBAND = 9,
} NMDeviceType;
/**
......
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.Device.Infiniband">
<property name="HwAddress" type="s" access="read">
<tp:docstring>
Hardware address of the device.
</tp:docstring>
</property>
<property name="Carrier" type="b" access="read">
<tp:docstring>
Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
</tp:docstring>
</property>
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
<tp:docstring>
A dictionary mapping property names to variant boxed values
</tp:docstring>
</arg>
</signal>
</interface>
</node>
......@@ -130,12 +130,16 @@ NetworkManager_SOURCES = \
wifi-utils-nl80211.h \
nm-device-wifi.c \
nm-device-wifi.h \
nm-device-wired.c \
nm-device-wired.h \
nm-device-olpc-mesh.c \
nm-device-olpc-mesh.h \
nm-device-bt.c \
nm-device-bt.h \
nm-device-modem.h \
nm-device-modem.c \
nm-device-infiniband.c \
nm-device-infiniband.h \
nm-wifi-ap.c \
nm-wifi-ap.h \
nm-wifi-ap-utils.c \
......@@ -201,6 +205,9 @@ nm-device-interface-glue.h: $(top_srcdir)/introspection/nm-device.xml
nm-device-ethernet-glue.h: $(top_srcdir)/introspection/nm-device-ethernet.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_ethernet --mode=glib-server --output=$@ $<
nm-device-infiniband-glue.h: $(top_srcdir)/introspection/nm-device-infiniband.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_infiniband --mode=glib-server --output=$@ $<
nm-device-wifi-glue.h: $(top_srcdir)/introspection/nm-device-wifi.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_wifi --mode=glib-server --output=$@ $<
......@@ -233,6 +240,7 @@ BUILT_SOURCES = \
nm-manager-glue.h \
nm-device-interface-glue.h \
nm-device-ethernet-glue.h \
nm-device-infiniband-glue.h \
nm-device-wifi-glue.h \
nm-device-olpc-mesh-glue.h \
nm-device-bt-glue.h \
......
......@@ -47,7 +47,7 @@ static guint32 log_domains = \
LOGD_DHCP4 | LOGD_DHCP6 | LOGD_PPP | LOGD_IP4 | LOGD_IP6 | LOGD_AUTOIP4 | \
LOGD_DNS | LOGD_VPN | LOGD_SHARING | LOGD_SUPPLICANT | LOGD_AGENTS | \
LOGD_SETTINGS | LOGD_SUSPEND | LOGD_CORE | LOGD_DEVICE | LOGD_OLPC_MESH | \
LOGD_WIMAX;
LOGD_WIMAX | LOGD_INFINIBAND;
typedef struct {
guint32 num;
......@@ -88,6 +88,7 @@ static const LogDesc domain_descs[] = {
{ LOGD_DEVICE, "DEVICE" },
{ LOGD_OLPC_MESH, "OLPC" },
{ LOGD_WIMAX, "WIMAX" },
{ LOGD_INFINIBAND,"INFINIBAND" },
{ 0, NULL }
};
......
......@@ -52,6 +52,7 @@ enum {
LOGD_DEVICE = 0x00200000, /* Device state and activation */
LOGD_OLPC_MESH = 0x00400000,
LOGD_WIMAX = 0x00800000,
LOGD_INFINIBAND = 0x01000000,
};
#define LOGD_DHCP (LOGD_DHCP4 | LOGD_DHCP6)
......
This diff is collapsed.
......@@ -23,9 +23,8 @@
#define NM_DEVICE_ETHERNET_H
#include <glib-object.h>
#include <net/ethernet.h>
#include "nm-device.h"
#include "nm-device-wired.h"
G_BEGIN_DECLS
......@@ -42,11 +41,11 @@ G_BEGIN_DECLS
#define NM_DEVICE_ETHERNET_CARRIER "carrier"
typedef struct {
NMDevice parent;
NMDeviceWired parent;
} NMDeviceEthernet;
typedef struct {
NMDeviceClass parent;
NMDeviceWiredClass parent;
/* Signals */
void (*properties_changed) (NMDeviceEthernet *device, GHashTable *properties);
......@@ -60,9 +59,6 @@ NMDevice *nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver);
void nm_device_ethernet_get_address (NMDeviceEthernet *dev,
struct ether_addr *addr);
gboolean nm_device_bond_connection_matches (NMDevice *device, NMConnection *connection);
G_END_DECLS
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* 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.
*
* Copyright 2011 Red Hat, Inc.
*/
#ifndef NM_DEVICE_INFINIBAND_H
#define NM_DEVICE_INFINIBAND_H
#include <glib-object.h>
#include "nm-device-wired.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_INFINIBAND (nm_device_infiniband_get_type ())
#define NM_DEVICE_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfiniband))
#define NM_DEVICE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandClass))
#define NM_IS_DEVICE_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_INFINIBAND))
#define NM_IS_DEVICE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_INFINIBAND))
#define NM_DEVICE_INFINIBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandClass))
#define NM_DEVICE_INFINIBAND_HW_ADDRESS "hw-address"
#define NM_DEVICE_INFINIBAND_CARRIER "carrier"
typedef struct {
NMDeviceWired parent;
} NMDeviceInfiniband;
typedef struct {
NMDeviceWiredClass parent;
/* Signals */
void (*properties_changed) (NMDeviceInfiniband *device, GHashTable *properties);
} NMDeviceInfinibandClass;
GType nm_device_infiniband_get_type (void);
NMDevice *nm_device_infiniband_new (const char *udi,
const char *iface,
const char *driver);
G_END_DECLS
#endif /* NM_DEVICE_INFINIBAND_H */
This diff is collapsed.
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* 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.
*
* Copyright (C) 2005 - 2010 Red Hat, Inc.
* Copyright (C) 2006 - 2008 Novell, Inc.
*/
#ifndef NM_DEVICE_WIRED_H
#define NM_DEVICE_WIRED_H
#include <glib-object.h>
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_WIRED (nm_device_wired_get_type ())
#define NM_DEVICE_WIRED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_WIRED, NMDeviceWired))
#define NM_DEVICE_WIRED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_WIRED, NMDeviceWiredClass))
#define NM_IS_DEVICE_WIRED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_WIRED))
#define NM_IS_DEVICE_WIRED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_WIRED))
#define NM_DEVICE_WIRED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_WIRED, NMDeviceWiredClass))
typedef struct {
NMDevice parent;
} NMDeviceWired;
typedef struct {
NMDeviceClass parent;
} NMDeviceWiredClass;
GType nm_device_wired_get_type (void);
guint8 *nm_device_wired_get_hwaddr (NMDeviceWired *dev);
int nm_device_wired_get_hwaddr_type (NMDeviceWired *dev);
gboolean nm_device_wired_get_carrier (NMDeviceWired *dev);
G_END_DECLS
#endif /* NM_DEVICE_WIRED_H */
......@@ -296,15 +296,6 @@ constructor (GType type,
goto error;
}
if (NM_DEVICE_GET_CLASS (dev)->update_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_hw_address (dev);
if (NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address (dev);
if (NM_DEVICE_GET_CLASS (dev)->update_initial_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_initial_hw_address (dev);
priv->dhcp_manager = nm_dhcp_manager_get ();
priv->fw_manager = nm_firewall_manager_get ();
......@@ -319,6 +310,24 @@ error:
return NULL;
}
static void
constructed (GObject *object)
{
NMDevice *dev = NM_DEVICE (object);
if (NM_DEVICE_GET_CLASS (dev)->update_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_hw_address (dev);
if (NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address (dev);
if (NM_DEVICE_GET_CLASS (dev)->update_initial_hw_address)
NM_DEVICE_GET_CLASS (dev)->update_initial_hw_address (dev);
if (G_OBJECT_CLASS (nm_device_parent_class)->constructed)
G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
}
static gboolean
nm_device_hw_is_up (NMDevice *self)
{
......@@ -3598,6 +3607,7 @@ nm_device_class_init (NMDeviceClass *klass)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->constructor = constructor;
object_class->constructed = constructed;
klass->get_type_capabilities = real_get_type_capabilities;
klass->get_generic_capabilities = real_get_generic_capabilities;
......
......@@ -26,6 +26,7 @@
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <net/if_arp.h>
#include <gudev/gudev.h>
......@@ -35,6 +36,7 @@
#include "NetworkManagerUtils.h"
#include "nm-device-wifi.h"
#include "nm-device-olpc-mesh.h"
#include "nm-device-infiniband.h"
#include "nm-device-ethernet.h"
#include "wifi-utils.h"
#if WITH_WIMAX
......@@ -381,6 +383,13 @@ is_wimax (const char *driver)
return g_strcmp0 (driver, "i2400m_usb") == 0;
}
static gboolean
is_infiniband (GUdevDevice *device)
{
gint etype = g_udev_device_get_sysfs_attr_as_int (device, "type");
return etype == ARPHRD_INFINIBAND;
}
static GObject *
device_creator (NMUdevManager *manager,
GUdevDevice *udev_device,
......@@ -454,7 +463,9 @@ device_creator (NMUdevManager *manager,
#if WITH_WIMAX
device = (GObject *) nm_device_wimax_new (path, ifname, driver);
#endif
} else
} else if (is_infiniband (udev_device))
device = (GObject *) nm_device_infiniband_new (path, ifname, driver);
else
device = (GObject *) nm_device_ethernet_new (path, ifname, driver);
out:
......@@ -488,7 +499,7 @@ net_add (NMUdevManager *self, GUdevDevice *device)
* s390 CTC-type devices that report 256 for some reason.
* FIXME: use something other than interface name to detect CTC here.
*/
if ((etype != 1) && (is_ctc == FALSE)) {
if ((etype != ARPHRD_ETHER) && (etype != ARPHRD_INFINIBAND) && (is_ctc == FALSE)) {
nm_log_dbg (LOGD_HW, "(%s): ignoring interface with type %d", iface, etype);
return;
}
......
......@@ -29,8 +29,7 @@
#include <string.h>
#include <ctype.h>
#include <gmodule.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <net/if_arp.h>
#include <pwd.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
......@@ -53,8 +52,10 @@
#include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h>
#include <nm-setting-bond.h>
#include <nm-utils.h>
#include "../nm-device-ethernet.h"
#include "../nm-device-wired.h"
#include "nm-dbus-glib-types.h"
#include "nm-settings.h"
#include "nm-settings-connection.h"
......@@ -1227,6 +1228,7 @@ have_connection_for_device (NMSettings *self, GByteArray *mac, NMDevice *device)
gpointer data;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingInfiniband *s_infiniband;
const GByteArray *setting_mac;
gboolean ret = FALSE;
......@@ -1251,10 +1253,12 @@ have_connection_for_device (NMSettings *self, GByteArray *mac, NMDevice *device)
}
if ( strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME)
&& strcmp (ctype, NM_SETTING_INFINIBAND_SETTING_NAME)
&& strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
continue;
s_wired = nm_connection_get_setting_wired (connection);
s_infiniband = nm_connection_get_setting_infiniband (connection);
/* No wired setting; therefore the PPPoE connection applies to any device */
if (!s_wired && !strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
......@@ -1262,10 +1266,15 @@ have_connection_for_device (NMSettings *self, GByteArray *mac, NMDevice *device)
break;
}
setting_mac = nm_setting_wired_get_mac_address (s_wired);
g_assert (s_wired != NULL || s_infiniband != NULL);
setting_mac = s_wired ?
nm_setting_wired_get_mac_address (s_wired) :
nm_setting_infiniband_get_mac_address (s_infiniband);
if (setting_mac) {
/* A connection mac-locked to this device */
if (!memcmp (setting_mac->data, mac->data, ETH_ALEN)) {
if (mac->len == setting_mac->len &&
!memcmp (setting_mac->data, mac->data, mac->len)) {
ret = TRUE;
break;
}
......@@ -1281,7 +1290,7 @@ have_connection_for_device (NMSettings *self, GByteArray *mac, NMDevice *device)
/* Search through the list of blacklisted MAC addresses in the config file. */
static gboolean
is_mac_auto_wired_blacklisted (NMSettings *self, const GByteArray *mac)
is_mac_auto_wired_blacklisted (NMSettings *self, const GByteArray *mac, int hwaddr_type)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GKeyFile *config;
......@@ -1305,15 +1314,15 @@ is_mac_auto_wired_blacklisted (NMSettings *self, const GByteArray *mac)
list = g_key_file_get_string_list (config, "main", CONFIG_KEY_NO_AUTO_DEFAULT, NULL, NULL);
for (iter = list; iter && *iter; iter++) {
struct ether_addr *candidate;
guint8 *candidate, buffer[NM_UTILS_HWADDR_LEN_MAX];
if (strcmp(g_strstrip(*iter), "*") == 0) {
if (strcmp (g_strstrip (*iter), "*") == 0) {
found = TRUE;
break;
}
candidate = ether_aton (*iter);
if (candidate && !memcmp (mac->data, candidate->ether_addr_octet, ETH_ALEN)) {
candidate = nm_utils_hwaddr_aton (*iter, hwaddr_type, buffer);
if (candidate && !memcmp (mac->data, candidate, mac->len)) {
found = TRUE;
break;
}
......@@ -1336,6 +1345,7 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMSettingConnection *s_con;
int hwaddr_type;
char *tmp;
GKeyFile *config;
char **list, **iter, **updated;
......@@ -1367,20 +1377,27 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
if (!config)
goto cleanup;
if (nm_connection_get_setting_wired (NM_CONNECTION (wired)))
hwaddr_type = ARPHRD_ETHER;
else if (nm_connection_get_setting_infiniband (NM_CONNECTION (wired)))
hwaddr_type = ARPHRD_INFINIBAND;
else
goto cleanup;
g_key_file_set_list_separator (config, ',');
g_key_file_load_from_file (config, priv->config_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
list = g_key_file_get_string_list (config, "main", CONFIG_KEY_NO_AUTO_DEFAULT, &len, NULL);
for (iter = list; iter && *iter; iter++) {
struct ether_addr *candidate;
guint8 *candidate, buffer[NM_UTILS_HWADDR_LEN_MAX];
if (strcmp(g_strstrip(*iter), "*") == 0) {
if (strcmp (g_strstrip (*iter), "*") == 0) {
found = TRUE;
break;
}
candidate = ether_aton (*iter);
if (candidate && !memcmp (mac->data, candidate->ether_addr_octet, ETH_ALEN)) {
candidate = nm_utils_hwaddr_aton (*iter, hwaddr_type, buffer);
if (candidate && !memcmp (mac->data, candidate, mac->len)) {
found = TRUE;
break;
}
......@@ -1388,9 +1405,7 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
/* Add this device's MAC to the list */
if (!found) {
tmp = g_strdup_printf ("%02x:%02x:%02x:%02x:%02x:%02x",
mac->data[0], mac->data[1], mac->data[2],
mac->data[3], mac->data[4], mac->data[5]);
tmp = nm_utils_hwaddr_ntoa (mac->data, hwaddr_type);
/* New list; size + 1 for the new element, + 1 again for ending NULL */
updated = g_malloc0 (sizeof (char*) * (len + 2));
......@@ -1480,13 +1495,14 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GByteArray *mac = NULL;
struct ether_addr tmp;
guint8 *hwaddr;
int hwaddr_type;
NMDefaultWiredConnection *wired;
gboolean read_only = TRUE;
const char *id;
char *defname;
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_ETHERNET)
if (!NM_IS_DEVICE_WIRED (device))
return;
/* If the device isn't managed or it already has a default wired connection,
......@@ -1496,13 +1512,14 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|| g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG))
return;
nm_device_ethernet_get_address (NM_DEVICE_ETHERNET (device), &tmp);
hwaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device));
hwaddr_type = nm_device_wired_get_hwaddr_type (NM_DEVICE_WIRED (device));
mac = g_byte_array_sized_new (ETH_ALEN);
g_byte_array_append (mac, tmp.ether_addr_octet, ETH_ALEN);
mac = g_byte_array_new ();
g_byte_array_append (mac, hwaddr, nm_utils_hwaddr_len (hwaddr_type));
if ( have_connection_for_device (self, mac, device)
|| is_mac_auto_wired_blacklisted (self, mac))
|| is_mac_auto_wired_blacklisted (self, mac, hwaddr_type))
goto ignore;
if (get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS))
......@@ -1536,7 +1553,7 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device)
{
NMDefaultWiredConnection *connection;
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_ETHERNET)
if (!NM_IS_DEVICE_WIRED (device))
return;
connection = (NMDefaultWiredConnection *) g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment