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

« back to all changes in this revision

Viewing changes to src/nm-device-ethernet.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
 
24
24
#include <glib/gi18n.h>
25
25
#include <netinet/in.h>
26
26
#include <string.h>
27
 
#include <net/ethernet.h>
28
27
#include <stdlib.h>
29
 
#include <linux/types.h>
30
28
#include <linux/sockios.h>
31
 
#include <linux/version.h>
32
29
#include <linux/ethtool.h>
33
30
#include <sys/ioctl.h>
34
31
#include <unistd.h>
407
404
                                          NULL);
408
405
}
409
406
 
410
 
/* Returns speed in Mb/s */
411
 
static guint32
412
 
nm_device_ethernet_get_speed (NMDeviceEthernet *self)
413
 
{
414
 
        int fd;
415
 
        struct ifreq ifr;
416
 
        struct ethtool_cmd edata = {
417
 
                .cmd = ETHTOOL_GSET,
418
 
        };
419
 
        guint32 speed = 0;
420
 
 
421
 
        g_return_val_if_fail (self != NULL, 0);
422
 
 
423
 
        fd = socket (PF_INET, SOCK_DGRAM, 0);
424
 
        if (fd < 0) {
425
 
                nm_log_warn (LOGD_HW, "couldn't open control socket.");
426
 
                return 0;
427
 
        }
428
 
 
429
 
        memset (&ifr, 0, sizeof (struct ifreq));
430
 
        strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
431
 
        ifr.ifr_data = (char *) &edata;
432
 
 
433
 
        if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
434
 
                goto out;
435
 
 
436
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
437
 
        speed = edata.speed;
438
 
#else
439
 
        speed = ethtool_cmd_speed (&edata);
440
 
#endif
441
 
 
442
 
        if (speed == G_MAXUINT16 || speed == G_MAXUINT32)
443
 
                speed = 0;
444
 
 
445
 
out:
446
 
        close (fd);
447
 
        return speed;
448
 
}
449
 
 
450
407
static void
451
408
_update_hw_addr (NMDeviceEthernet *self, const guint8 *addr)
452
409
{
901
858
static NMSupplicantConfig *
902
859
build_supplicant_config (NMDeviceEthernet *self)
903
860
{
904
 
        const char *con_path;
 
861
        const char *con_uuid;
905
862
        NMSupplicantConfig *config = NULL;
906
863
        NMSetting8021x *security;
907
864
        NMConnection *connection;
908
865
 
909
866
        connection = nm_device_get_connection (NM_DEVICE (self));
910
867
        g_return_val_if_fail (connection, NULL);
911
 
        con_path = nm_connection_get_path (connection);
 
868
        con_uuid = nm_connection_get_uuid (connection);
912
869
 
913
870
        config = nm_supplicant_config_new ();
914
871
        if (!config)
915
872
                return NULL;
916
873
 
917
874
        security = nm_connection_get_setting_802_1x (connection);
918
 
        if (!nm_supplicant_config_add_setting_8021x (config, security, con_path, TRUE)) {
 
875
        if (!nm_supplicant_config_add_setting_8021x (config, security, con_uuid, TRUE)) {
919
876
                nm_log_warn (LOGD_DEVICE, "Couldn't add 802.1X security setting to supplicant config.");
920
877
                g_object_unref (config);
921
878
                config = NULL;
1541
1498
                g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER));
1542
1499
                break;
1543
1500
        case PROP_SPEED:
1544
 
                g_value_set_uint (value, nm_device_ethernet_get_speed (self));
 
1501
                g_value_set_uint (value, nm_device_wired_get_speed (NM_DEVICE_WIRED (self)));
1545
1502
                break;
1546
1503
        case PROP_CARRIER:
1547
1504
                g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (self)));