mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 18:20:22 +01:00
core: remove NMDeviceWired
With carrier handling moved to NMDevice, the only thing left in NMDeviceWired was speed, which was actually ethernet-specific anyway. So move that to NMDeviceEthernet, and then kill NMDeviceWired.
This commit is contained in:
parent
82222d3898
commit
38459f5a00
13 changed files with 77 additions and 235 deletions
|
|
@ -87,8 +87,6 @@ nm_sources = \
|
|||
devices/nm-device-vlan.h \
|
||||
devices/nm-device-wifi.c \
|
||||
devices/nm-device-wifi.h \
|
||||
devices/nm-device-wired.c \
|
||||
devices/nm-device-wired.h \
|
||||
\
|
||||
dhcp-manager/nm-dhcp-client.c \
|
||||
dhcp-manager/nm-dhcp-client.h \
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
#include "nm-device-bond-glue.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE_WIRED)
|
||||
G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BOND, NMDeviceBondPrivate))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -43,11 +43,11 @@ typedef enum {
|
|||
#define NM_DEVICE_BOND_SLAVES "slaves"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWired parent;
|
||||
NMDevice parent;
|
||||
} NMDeviceBond;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWiredClass parent;
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceBondClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
#include "nm-device-bridge-glue.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE_WIRED)
|
||||
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -43,11 +43,11 @@ typedef enum {
|
|||
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWired parent;
|
||||
NMDevice parent;
|
||||
} NMDeviceBridge;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWiredClass parent;
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceBridgeClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/version.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/if.h>
|
||||
|
|
@ -59,7 +60,7 @@
|
|||
#include "nm-device-ethernet-glue.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE_WIRED)
|
||||
G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetPrivate))
|
||||
|
||||
|
|
@ -84,6 +85,8 @@ typedef struct {
|
|||
guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */
|
||||
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
|
||||
|
||||
guint32 speed;
|
||||
|
||||
Supplicant supplicant;
|
||||
guint supplicant_timeout_id;
|
||||
|
||||
|
|
@ -1316,6 +1319,60 @@ get_connection_hw_address (NMDevice *device,
|
|||
return s_wired ? nm_setting_wired_get_mac_address (s_wired) : NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
get_link_speed (NMDevice *device)
|
||||
{
|
||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
|
||||
struct ifreq ifr;
|
||||
struct ethtool_cmd edata = {
|
||||
.cmd = ETHTOOL_GSET,
|
||||
};
|
||||
guint32 speed;
|
||||
int fd;
|
||||
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_log_warn (LOGD_HW | LOGD_ETHER, "couldn't open ethtool control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
memset (&ifr, 0, sizeof (struct ifreq));
|
||||
strncpy (ifr.ifr_name, nm_device_get_iface (device), IFNAMSIZ);
|
||||
ifr.ifr_data = (char *) &edata;
|
||||
|
||||
if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) {
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
close (fd);
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
|
||||
speed = edata.speed;
|
||||
#else
|
||||
speed = ethtool_cmd_speed (&edata);
|
||||
#endif
|
||||
if (speed == G_MAXUINT16 || speed == G_MAXUINT32)
|
||||
speed = 0;
|
||||
|
||||
if (priv->speed == speed)
|
||||
return;
|
||||
|
||||
priv->speed = speed;
|
||||
g_object_notify (G_OBJECT (device), "speed");
|
||||
|
||||
nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): speed is now %d Mb/s",
|
||||
nm_device_get_iface (device), speed);
|
||||
}
|
||||
|
||||
static void
|
||||
carrier_changed (NMDevice *device, gboolean carrier)
|
||||
{
|
||||
if (carrier)
|
||||
get_link_speed (device);
|
||||
|
||||
NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->carrier_changed (device, carrier);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
|
|
@ -1342,7 +1399,7 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER));
|
||||
break;
|
||||
case PROP_SPEED:
|
||||
g_value_set_uint (value, nm_device_wired_get_speed (NM_DEVICE_WIRED (self)));
|
||||
g_value_set_uint (value, priv->speed);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
|
@ -1392,6 +1449,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
|
|||
parent_class->spec_match_list = spec_match_list;
|
||||
parent_class->match_l2_config = match_l2_config;
|
||||
parent_class->get_connection_hw_address = get_connection_hw_address;
|
||||
parent_class->carrier_changed = carrier_changed;
|
||||
|
||||
parent_class->state_changed = device_state_changed;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -46,11 +46,11 @@ typedef enum
|
|||
#define NM_DEVICE_ETHERNET_SPEED "speed"
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWired parent;
|
||||
NMDevice parent;
|
||||
} NMDeviceEthernet;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWiredClass parent;
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceEthernetClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#include "nm-device-infiniband-glue.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE_WIRED)
|
||||
G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -41,11 +41,11 @@ typedef enum {
|
|||
} NMInfinibandError;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWired parent;
|
||||
NMDevice parent;
|
||||
} NMDeviceInfiniband;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWiredClass parent;
|
||||
NMDeviceClass parent;
|
||||
|
||||
} NMDeviceInfinibandClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -1,161 +0,0 @@
|
|||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2006 - 2008 Novell, Inc.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nm-device-wired.h"
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-dhcp-manager.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-system.h"
|
||||
#include "nm-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceWired, nm_device_wired, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WIRED, NMDeviceWiredPrivate))
|
||||
|
||||
#define NM_DEVICE_WIRED_LOG_LEVEL(dev) ((nm_device_get_device_type (dev) == NM_DEVICE_TYPE_INFINIBAND) ? LOGD_INFINIBAND : LOGD_ETHER)
|
||||
|
||||
typedef struct {
|
||||
guint32 speed;
|
||||
} NMDeviceWiredPrivate;
|
||||
|
||||
|
||||
/* Returns speed in Mb/s */
|
||||
static guint32
|
||||
ethtool_get_speed (NMDeviceWired *self)
|
||||
{
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
struct ethtool_cmd edata = {
|
||||
.cmd = ETHTOOL_GSET,
|
||||
};
|
||||
guint32 speed = 0;
|
||||
|
||||
g_return_val_if_fail (self != NULL, 0);
|
||||
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_log_warn (LOGD_HW, "couldn't open control socket.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset (&ifr, 0, sizeof (struct ifreq));
|
||||
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
||||
ifr.ifr_data = (char *) &edata;
|
||||
|
||||
if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
|
||||
goto out;
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
|
||||
speed = edata.speed;
|
||||
#else
|
||||
speed = ethtool_cmd_speed (&edata);
|
||||
#endif
|
||||
|
||||
if (speed == G_MAXUINT16 || speed == G_MAXUINT32)
|
||||
speed = 0;
|
||||
|
||||
out:
|
||||
close (fd);
|
||||
return speed;
|
||||
}
|
||||
|
||||
static void
|
||||
set_speed (NMDeviceWired *self, const guint32 speed)
|
||||
{
|
||||
NMDeviceWiredPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_DEVICE (self));
|
||||
|
||||
priv = NM_DEVICE_WIRED_GET_PRIVATE (self);
|
||||
if (priv->speed == speed)
|
||||
return;
|
||||
|
||||
priv->speed = speed;
|
||||
g_object_notify (G_OBJECT (self), "speed");
|
||||
|
||||
nm_log_dbg (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)),
|
||||
"(%s): speed is now %d Mb/s",
|
||||
nm_device_get_iface (NM_DEVICE (self)),
|
||||
speed);
|
||||
}
|
||||
|
||||
static void
|
||||
carrier_changed (NMDevice *device, gboolean carrier)
|
||||
{
|
||||
NMDeviceWired *wired_device = NM_DEVICE_WIRED (device);
|
||||
|
||||
if (carrier)
|
||||
set_speed (wired_device, ethtool_get_speed (wired_device));
|
||||
|
||||
G_OBJECT_CLASS (nm_device_wired_parent_class)->carrier_changed (device, carrier);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_wired_init (NMDeviceWired * self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_wired_class_init (NMDeviceWiredClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMDeviceWiredPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
|
||||
parent_class->carrier_changed = carrier_changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_wired_get_speed:
|
||||
* @dev: an #NMDeviceWired
|
||||
*
|
||||
* Get @dev's speed
|
||||
*
|
||||
* Return value: @dev's speed in Mb/s
|
||||
*/
|
||||
guint32
|
||||
nm_device_wired_get_speed (NMDeviceWired *dev)
|
||||
{
|
||||
NMDeviceWiredPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (dev != NULL, 0);
|
||||
|
||||
priv = NM_DEVICE_WIRED_GET_PRIVATE (dev);
|
||||
return priv->speed;
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/* -*- 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 - 2012 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);
|
||||
|
||||
guint32 nm_device_wired_get_speed (NMDeviceWired *dev);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_WIRED_H */
|
||||
|
|
@ -54,7 +54,6 @@
|
|||
#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"
|
||||
|
|
@ -1481,7 +1480,7 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device)
|
|||
{
|
||||
NMDefaultWiredConnection *connection;
|
||||
|
||||
if (!NM_IS_DEVICE_WIRED (device))
|
||||
if (!NM_IS_DEVICE_ETHERNET (device))
|
||||
return;
|
||||
|
||||
connection = (NMDefaultWiredConnection *) g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue