~ubuntu-branches/ubuntu/precise/network-manager/precise

« back to all changes in this revision

Viewing changes to src/nm-device-wired.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-02-09 16:45:41 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20120209164541-4h90zknlsfdb7x35
Tags: 0.9.2.0+git201202091925.c721477-0ubuntu1
* upstream snapshot 2012-02-09 19:25:59 (GMT)
  + c721477d11d4fe144111d6d2eec8f93f2e9186c9
* debian/patches/avoid-periodic-disk-wakeups.patch: refreshed.
* debian/patches/nl3-default-ip6-route.patch: refreshed.
* debian/libnm-glib4.symbols: add symbols:
  + nm_active_connection_get_master@Base
  + nm_client_new_async@Base
  + nm_client_new_finish@Base
  + nm_remote_settings_new_async@Base
  + nm_remote_settings_new_finish@Base
  + nm_device_get_state_reason@Base
* debian/libnm-util2.symbols: add symbols:
  + nm_setting_802_1x_get_pac_file@Base
  + nm_setting_infiniband_get_transport_mode@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
16
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
 *
18
 
 * Copyright (C) 2005 - 2011 Red Hat, Inc.
 
18
 * Copyright (C) 2005 - 2012 Red Hat, Inc.
19
19
 * Copyright (C) 2006 - 2008 Novell, Inc.
20
20
 */
21
21
 
25
25
#include <linux/if.h>
26
26
#include <linux/if_infiniband.h>
27
27
#include <netinet/ether.h>
 
28
#include <linux/sockios.h>
 
29
#include <linux/version.h>
 
30
#include <linux/ethtool.h>
 
31
#include <sys/ioctl.h>
 
32
#include <unistd.h>
28
33
 
29
34
#include "nm-device-wired.h"
30
35
#include "nm-device-private.h"
48
53
        guint               hw_addr_type;
49
54
        guint               hw_addr_len;
50
55
        gboolean            carrier;
 
56
        guint32             speed;
51
57
 
52
58
        NMNetlinkMonitor *  monitor;
53
59
        gulong              link_connected_id;
56
62
 
57
63
} NMDeviceWiredPrivate;
58
64
 
 
65
 
 
66
/* Returns speed in Mb/s */
 
67
static guint32
 
68
ethtool_get_speed (NMDeviceWired *self)
 
69
{
 
70
        int fd;
 
71
        struct ifreq ifr;
 
72
        struct ethtool_cmd edata = {
 
73
                .cmd = ETHTOOL_GSET,
 
74
        };
 
75
        guint32 speed = 0;
 
76
 
 
77
        g_return_val_if_fail (self != NULL, 0);
 
78
 
 
79
        fd = socket (PF_INET, SOCK_DGRAM, 0);
 
80
        if (fd < 0) {
 
81
                nm_log_warn (LOGD_HW, "couldn't open control socket.");
 
82
                return 0;
 
83
        }
 
84
 
 
85
        memset (&ifr, 0, sizeof (struct ifreq));
 
86
        strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
 
87
        ifr.ifr_data = (char *) &edata;
 
88
 
 
89
        if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
 
90
                goto out;
 
91
 
 
92
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
 
93
        speed = edata.speed;
 
94
#else
 
95
        speed = ethtool_cmd_speed (&edata);
 
96
#endif
 
97
 
 
98
        if (speed == G_MAXUINT16 || speed == G_MAXUINT32)
 
99
                speed = 0;
 
100
 
 
101
out:
 
102
        close (fd);
 
103
        return speed;
 
104
}
 
105
 
 
106
static void
 
107
set_speed (NMDeviceWired *self, const guint32 speed)
 
108
{
 
109
        NMDeviceWiredPrivate *priv;
 
110
 
 
111
        g_return_if_fail (NM_IS_DEVICE (self));
 
112
 
 
113
        priv = NM_DEVICE_WIRED_GET_PRIVATE (self);
 
114
        if (priv->speed == speed)
 
115
                return;
 
116
 
 
117
        priv->speed = speed;
 
118
        g_object_notify (G_OBJECT (self), "speed");
 
119
 
 
120
        nm_log_dbg (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)),
 
121
                     "(%s): speed is now %d Mb/s",
 
122
                     nm_device_get_iface (NM_DEVICE (self)),
 
123
                     speed);
 
124
}
 
125
 
59
126
static void
60
127
carrier_action_defer_clear (NMDeviceWired *self)
61
128
{
139
206
                        return;
140
207
 
141
208
                set_carrier (self, TRUE, FALSE);
 
209
                set_speed (self, ethtool_get_speed (self));
142
210
        }
143
211
}
144
212
 
537
605
{
538
606
        NMDeviceWiredPrivate *priv;
539
607
 
540
 
        g_return_val_if_fail (dev != NULL, -1);
 
608
        g_return_val_if_fail (dev != NULL, FALSE);
541
609
 
542
610
        priv = NM_DEVICE_WIRED_GET_PRIVATE (dev);
543
611
        return priv->carrier;
544
612
}
 
613
 
 
614
/**
 
615
 * nm_device_wired_get_speed:
 
616
 * @dev: an #NMDeviceWired
 
617
 *
 
618
 * Get @dev's speed
 
619
 *
 
620
 * Return value: @dev's speed in Mb/s
 
621
 */
 
622
guint32
 
623
nm_device_wired_get_speed (NMDeviceWired *dev)
 
624
{
 
625
        NMDeviceWiredPrivate *priv;
 
626
 
 
627
        g_return_val_if_fail (dev != NULL, 0);
 
628
 
 
629
        priv = NM_DEVICE_WIRED_GET_PRIVATE (dev);
 
630
        return priv->speed;
 
631
}