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

« back to all changes in this revision

Viewing changes to .pc/avoid-periodic-disk-wakeups.patch/src/nm-manager.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:
16
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
 *
18
18
 * Copyright (C) 2007 - 2009 Novell, Inc.
19
 
 * Copyright (C) 2007 - 2011 Red Hat, Inc.
 
19
 * Copyright (C) 2007 - 2012 Red Hat, Inc.
20
20
 */
21
21
 
22
22
#include <config.h>
23
23
 
24
24
#include <netinet/ether.h>
25
 
#include <unistd.h>
26
25
#include <fcntl.h>
27
26
#include <errno.h>
28
27
#include <string.h>
 
28
#include <sys/stat.h>
29
29
#include <dbus/dbus-glib-lowlevel.h>
30
30
#include <dbus/dbus-glib.h>
31
31
#include <gio/gio.h>
43
43
#include "nm-device-wifi.h"
44
44
#include "nm-device-olpc-mesh.h"
45
45
#include "nm-device-modem.h"
 
46
#include "nm-device-infiniband.h"
46
47
#include "nm-system.h"
47
48
#include "nm-properties-changed-signal.h"
48
49
#include "nm-setting-bluetooth.h"
60
61
#include "nm-manager-auth.h"
61
62
#include "NetworkManagerUtils.h"
62
63
#include "nm-utils.h"
 
64
#include "nm-device-factory.h"
 
65
#include "wifi-utils.h"
63
66
 
64
67
#define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd"
65
68
#define NM_AUTOIP_DBUS_IFACE   "org.freedesktop.nm_avahi_autoipd"
113
116
 
114
117
#include "nm-manager-glue.h"
115
118
 
116
 
static void udev_device_added_cb (NMUdevManager *udev_mgr,
117
 
                                  GUdevDevice *device,
118
 
                                  NMDeviceCreatorFn creator_fn,
119
 
                                  gpointer user_data);
120
 
 
121
 
static void udev_device_removed_cb (NMUdevManager *udev_mgr,
122
 
                                    GUdevDevice *device,
123
 
                                    gpointer user_data);
124
 
 
125
119
static void bluez_manager_bdaddr_added_cb (NMBluezManager *bluez_mgr,
126
120
                                           const char *bdaddr,
127
121
                                           const char *name,
201
195
        NMUdevManager *udev_mgr;
202
196
        NMBluezManager *bluez_mgr;
203
197
 
 
198
        /* List of NMDeviceFactoryFunc pointers sorted in priority order */
 
199
        GSList *factories;
 
200
 
204
201
        NMSettings *settings;
205
202
        char *hostname;
206
203
 
1825
1822
        return NULL;
1826
1823
}
1827
1824
 
 
1825
#define PLUGIN_PREFIX "libnm-device-plugin-"
 
1826
 
 
1827
typedef struct {
 
1828
        NMDeviceType t;
 
1829
        guint priority;
 
1830
        NMDeviceFactoryCreateFunc create_func;
 
1831
} PluginInfo;
 
1832
 
 
1833
static gint
 
1834
plugin_sort (PluginInfo *a, PluginInfo *b)
 
1835
{
 
1836
        /* Higher priority means sort earlier in the list (ie, return -1) */
 
1837
        if (a->priority > b->priority)
 
1838
                return -1;
 
1839
        else if (a->priority < b->priority)
 
1840
                return 1;
 
1841
        return 0;
 
1842
}
 
1843
 
 
1844
static void
 
1845
load_device_factories (NMManager *self)
 
1846
{
 
1847
        NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
 
1848
        GDir *dir;
 
1849
        GError *error = NULL;
 
1850
        const char *item;
 
1851
        char *path;
 
1852
        GSList *list = NULL, *iter;
 
1853
 
 
1854
        dir = g_dir_open (NMPLUGINDIR, 0, &error);
 
1855
        if (!dir) {
 
1856
                nm_log_warn (LOGD_HW, "Failed to open plugin directory %s: %s",
 
1857
                             NMPLUGINDIR,
 
1858
                             (error && error->message) ? error->message : "(unknown)");
 
1859
                g_clear_error (&error);
 
1860
                return;
 
1861
        }
 
1862
 
 
1863
        while ((item = g_dir_read_name (dir))) {
 
1864
                GModule *plugin;
 
1865
                NMDeviceFactoryCreateFunc create_func;
 
1866
                NMDeviceFactoryPriorityFunc priority_func;
 
1867
                NMDeviceFactoryTypeFunc type_func;
 
1868
                PluginInfo *info = NULL;
 
1869
                NMDeviceType plugin_type;
 
1870
 
 
1871
                if (!g_str_has_prefix (item, PLUGIN_PREFIX))
 
1872
                        continue;
 
1873
 
 
1874
                path = g_module_build_path (NMPLUGINDIR, item);
 
1875
                g_assert (path);
 
1876
                plugin = g_module_open (path, G_MODULE_BIND_LOCAL);
 
1877
                g_free (path);
 
1878
 
 
1879
                if (!plugin) {
 
1880
                        nm_log_warn (LOGD_HW, "(%s): failed to load plugin: %s", item, g_module_error ());
 
1881
                        continue;
 
1882
                }
 
1883
 
 
1884
                if (!g_module_symbol (plugin, "nm_device_factory_get_type", (gpointer) (&type_func))) {
 
1885
                        nm_log_warn (LOGD_HW, "(%s): failed to find device factory: %s", item, g_module_error ());
 
1886
                        g_module_close (plugin);
 
1887
                        continue;
 
1888
                }
 
1889
 
 
1890
                /* Make sure we don't double-load plugins */
 
1891
                plugin_type = type_func ();
 
1892
                for (iter = list; iter; iter = g_slist_next (iter)) {
 
1893
                        PluginInfo *candidate = iter->data;
 
1894
 
 
1895
                        if (plugin_type == candidate->t) {
 
1896
                                info = candidate;
 
1897
                                break;
 
1898
                        }
 
1899
                }
 
1900
                if (info) {
 
1901
                        g_module_close (plugin);
 
1902
                        continue;
 
1903
                }
 
1904
 
 
1905
                if (!g_module_symbol (plugin, "nm_device_factory_create_device", (gpointer) (&create_func))) {
 
1906
                        nm_log_warn (LOGD_HW, "(%s): failed to find device creator: %s", item, g_module_error ());
 
1907
                        g_module_close (plugin);
 
1908
                        continue;
 
1909
                }
 
1910
 
 
1911
                info = g_malloc0 (sizeof (*info));
 
1912
                info->create_func = create_func;
 
1913
                info->t = plugin_type;
 
1914
 
 
1915
                /* Grab priority; higher number equals higher priority */
 
1916
                if (g_module_symbol (plugin, "nm_device_factory_get_priority", (gpointer) (&priority_func)))
 
1917
                        info->priority = priority_func ();
 
1918
                else {
 
1919
                        nm_log_dbg (LOGD_HW, "(%s): failed to find device factory priority func: %s",
 
1920
                                    item, g_module_error ());
 
1921
                }
 
1922
 
 
1923
                g_module_make_resident (plugin);
 
1924
                list = g_slist_insert_sorted (list, info, (GCompareFunc) plugin_sort);
 
1925
 
 
1926
                nm_log_info (LOGD_HW, "Loaded device factory: %s", g_module_name (plugin));
 
1927
        };
 
1928
        g_dir_close (dir);
 
1929
 
 
1930
        /* Ditch the priority info and copy the factory functions to our private data */
 
1931
        for (iter = list; iter; iter = g_slist_next (iter)) {
 
1932
                PluginInfo *info = iter->data;
 
1933
 
 
1934
                priv->factories = g_slist_append (priv->factories, info->create_func);
 
1935
                g_free (info);
 
1936
        }
 
1937
        g_slist_free (list);
 
1938
}
 
1939
 
 
1940
static gboolean
 
1941
is_wireless (GUdevDevice *device)
 
1942
{
 
1943
        char phy80211_path[255];
 
1944
        struct stat s;
 
1945
        const char *path;
 
1946
        const char *tmp;
 
1947
 
 
1948
        /* Check devtype, newer kernels (2.6.32+) have this */
 
1949
        tmp = g_udev_device_get_property (device, "DEVTYPE");
 
1950
        if (g_strcmp0 (tmp, "wlan") == 0)
 
1951
                return TRUE;
 
1952
 
 
1953
        /* Check for nl80211 sysfs paths */
 
1954
        path = g_udev_device_get_sysfs_path (device);
 
1955
        snprintf (phy80211_path, sizeof (phy80211_path), "%s/phy80211", path);
 
1956
        if ((stat (phy80211_path, &s) == 0 && (s.st_mode & S_IFDIR)))
 
1957
                return TRUE;
 
1958
 
 
1959
        /* Otherwise hit up WEXT directly */
 
1960
        return wifi_utils_is_wifi (g_udev_device_get_name (device));
 
1961
}
 
1962
 
 
1963
static gboolean
 
1964
is_olpc_mesh (GUdevDevice *device)
 
1965
{
 
1966
        const gchar *prop = g_udev_device_get_property (device, "ID_NM_OLPC_MESH");
 
1967
        return (prop != NULL);
 
1968
}
 
1969
 
 
1970
static gboolean
 
1971
is_infiniband (GUdevDevice *device)
 
1972
{
 
1973
        gint etype = g_udev_device_get_sysfs_attr_as_int (device, "type");
 
1974
        return etype == ARPHRD_INFINIBAND;
 
1975
}
 
1976
 
1828
1977
static void
1829
1978
udev_device_added_cb (NMUdevManager *udev_mgr,
1830
1979
                      GUdevDevice *udev_device,
1831
 
                      NMDeviceCreatorFn creator_fn,
 
1980
                      const char *iface,
 
1981
                      const char *sysfs_path,
 
1982
                      const char *driver,
 
1983
                      int ifindex,
1832
1984
                      gpointer user_data)
1833
1985
{
1834
1986
        NMManager *self = NM_MANAGER (user_data);
1835
 
        GObject *device;
1836
 
        guint32 ifindex;
 
1987
        NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
 
1988
        GObject *device = NULL;
 
1989
        GSList *iter;
 
1990
        GError *error = NULL;
1837
1991
 
1838
1992
        ifindex = g_udev_device_get_property_as_int (udev_device, "IFINDEX");
1839
1993
        if (find_device_by_ifindex (self, ifindex))
1840
1994
                return;
1841
1995
 
1842
 
        device = creator_fn (udev_mgr, udev_device, manager_sleeping (self));
 
1996
        /* Try registered device factories */
 
1997
        for (iter = priv->factories; iter; iter = g_slist_next (iter)) {
 
1998
                NMDeviceFactoryCreateFunc create_func = iter->data;
 
1999
 
 
2000
                g_clear_error (&error);
 
2001
                device = create_func (udev_device, sysfs_path, iface, driver, &error);
 
2002
                if (device) {
 
2003
                        g_assert_no_error (error);
 
2004
                        break;  /* success! */
 
2005
                }
 
2006
 
 
2007
                if (error) {
 
2008
                        nm_log_warn (LOGD_HW, "%s: factory failed to create device: (%d) %s",
 
2009
                                     sysfs_path, error->code, error->message);
 
2010
                        g_clear_error (&error);
 
2011
                        return;
 
2012
                }
 
2013
        }
 
2014
 
 
2015
        if (device == NULL) {
 
2016
                if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
 
2017
                        device = (GObject *) nm_device_olpc_mesh_new (sysfs_path, iface, driver);
 
2018
                else if (is_wireless (udev_device))
 
2019
                        device = (GObject *) nm_device_wifi_new (sysfs_path, iface, driver);
 
2020
                else if (is_infiniband (udev_device))
 
2021
                        device = (GObject *) nm_device_infiniband_new (sysfs_path, iface, driver);
 
2022
                else
 
2023
                        device = (GObject *) nm_device_ethernet_new (sysfs_path, iface, driver);
 
2024
        }
 
2025
 
1843
2026
        if (device)
1844
2027
                add_device (self, NM_DEVICE (device));
1845
2028
}
3316
3499
                g_object_unref (priv->fw_monitor);
3317
3500
        }
3318
3501
 
 
3502
        g_slist_free (priv->factories);
 
3503
 
3319
3504
        if (priv->timestamp_update_id) {
3320
3505
                g_source_remove (priv->timestamp_update_id);
3321
3506
                priv->timestamp_update_id = 0;
3662
3847
                             KERNEL_FIRMWARE_DIR);
3663
3848
        }
3664
3849
 
 
3850
        load_device_factories (manager);
 
3851
 
3665
3852
        /* Update timestamps in active connections */
3666
3853
        priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, manager);
3667
3854
}