~ubuntu-branches/ubuntu/oneiric/network-manager/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-08-08 10:17:28 UTC
  • Revision ID: james.westby@ubuntu.com-20110808101728-nbhqa7aztcwetla2
Tags: 0.8.9997+git.20110721t045648.36db194-0ubuntu2
* debian/control: bump libnl Build-Depends to libnl3-dev.
* debian/patches/libnl3-port.patch: backport changes from NM's libnl3 git
  branch to port to libnl3 APIs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include "nm-logging.h"
60
60
#include "nm-properties-changed-signal.h"
61
61
#include "nm-dhcp-manager.h"
 
62
#include "nm-netlink-utils.h"
62
63
 
63
64
#include "nm-device-ethernet-glue.h"
64
65
 
546
547
static gboolean
547
548
real_hw_is_up (NMDevice *device)
548
549
{
549
 
        return nm_system_device_is_up (device);
 
550
        return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
550
551
}
551
552
 
552
553
static gboolean
553
554
real_hw_bring_up (NMDevice *dev, gboolean *no_firmware)
554
555
{
555
 
        return nm_system_device_set_up_down (dev, TRUE, no_firmware);
 
556
        return nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware);
556
557
}
557
558
 
558
559
static void
559
560
real_hw_take_down (NMDevice *dev)
560
561
{
561
 
        nm_system_device_set_up_down (dev, FALSE, NULL);
 
562
        nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), FALSE, NULL);
562
563
}
563
564
 
564
565
NMDevice *
677
678
        /* Can't change MAC address while device is up */
678
679
        real_hw_take_down (dev);
679
680
 
680
 
        success = nm_system_device_set_mac (iface, (struct ether_addr *) addr);
 
681
        success = nm_system_iface_set_mac (nm_device_get_ip_ifindex (dev), (struct ether_addr *) addr);
681
682
        if (success) {
682
683
                /* MAC address succesfully changed; update the current MAC to match */
683
684
                _update_hw_addr (self, addr);
1796
1797
        return TRUE;
1797
1798
}
1798
1799
 
1799
 
typedef struct {
1800
 
        int ifindex;
1801
 
        NMIP4Address *addr;
1802
 
        gboolean found;
1803
 
} AddrData;
1804
 
 
1805
 
static void
1806
 
check_one_address (struct nl_object *object, void *user_data)
1807
 
{
1808
 
        AddrData *data = user_data;
1809
 
        struct rtnl_addr *addr = (struct rtnl_addr *) object;
1810
 
        struct nl_addr *local;
1811
 
        struct in_addr tmp;
1812
 
 
1813
 
        if (rtnl_addr_get_ifindex (addr) != data->ifindex)
1814
 
                return;
1815
 
        if (rtnl_addr_get_family (addr) != AF_INET)
1816
 
                return;
1817
 
 
1818
 
        if (nm_ip4_address_get_prefix (data->addr) != rtnl_addr_get_prefixlen (addr))
1819
 
                return;
1820
 
 
1821
 
        local = rtnl_addr_get_local (addr);
1822
 
        if (nl_addr_get_family (local) != AF_INET)
1823
 
                return;
1824
 
        if (nl_addr_get_len (local) != sizeof (struct in_addr))
1825
 
                return;
1826
 
        if (!nl_addr_get_binary_addr (local))
1827
 
                return;
1828
 
 
1829
 
        memcpy (&tmp, nl_addr_get_binary_addr (local), nl_addr_get_len (local));
1830
 
        if (tmp.s_addr != nm_ip4_address_get_address (data->addr))
1831
 
                return;
1832
 
 
1833
 
        /* Yay, found it */
1834
 
        data->found = TRUE;
1835
 
}
1836
 
 
1837
1800
static gboolean
1838
1801
ip4_match_config (NMDevice *self, NMConnection *connection)
1839
1802
{
1840
1803
        NMSettingIP4Config *s_ip4;
1841
 
        struct nl_handle *nlh = NULL;
1842
 
        struct nl_cache *addr_cache = NULL;
1843
1804
        int i, num;
1844
1805
        GSList *leases, *iter;
1845
1806
        NMDHCPManager *dhcp_mgr;
1846
1807
        const char *method;
1847
 
        int ifindex;
1848
 
        AddrData check_data;
1849
 
 
1850
 
        ifindex = nm_device_get_ifindex (self);
1851
 
 
1852
 
        s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
 
1808
 
 
1809
        s_ip4 = nm_connection_get_setting_ip4_config (connection);
1853
1810
        if (!s_ip4)
1854
1811
                return FALSE;
1855
1812
 
1856
 
        /* Read all the device's IP addresses */
1857
 
        nlh = nm_netlink_get_default_handle ();
1858
 
        if (!nlh)
1859
 
                return FALSE;
1860
 
 
1861
 
        addr_cache = rtnl_addr_alloc_cache (nlh);
1862
 
        if (!addr_cache)
1863
 
                return FALSE;
1864
 
        nl_cache_mngt_provide (addr_cache);
1865
 
 
1866
1813
        /* Get any saved leases that apply to this connection */
1867
1814
        dhcp_mgr = nm_dhcp_manager_get ();
1868
1815
        leases = nm_dhcp_manager_get_lease_config (dhcp_mgr,
1876
1823
 
1877
1824
                /* Find at least one lease's address on the device */
1878
1825
                for (iter = leases; iter; iter = g_slist_next (iter)) {
1879
 
                        NMIP4Config *addr = iter->data;
1880
 
 
1881
 
                        memset (&check_data, 0, sizeof (check_data));
1882
 
                        check_data.ifindex = ifindex;
1883
 
                        check_data.found = FALSE;
1884
 
                        check_data.addr = nm_ip4_config_get_address (addr, 0);
1885
 
 
1886
 
                        nl_cache_foreach (addr_cache, check_one_address, &check_data);
1887
 
                        if (check_data.found) {
 
1826
                        NMIP4Config *ip4_config = iter->data;
 
1827
                        NMIP4Address *addr = nm_ip4_config_get_address (ip4_config, 0);
 
1828
                        struct in_addr tmp = { .s_addr = nm_ip4_address_get_address (addr) };
 
1829
 
 
1830
                        if (addr && nm_netlink_find_address (nm_device_get_ip_ifindex (self),
 
1831
                                                             AF_INET,
 
1832
                                                             &tmp,
 
1833
                                                             nm_ip4_address_get_prefix (addr))) {
1888
1834
                                found = TRUE; /* Yay, device has same address as a lease */
1889
1835
                                break;
1890
1836
                        }
1908
1854
 
1909
1855
        /* Everything below for static addressing */
1910
1856
 
1911
 
        /* Find all IP4 addresses of this connection in the device's address list */
 
1857
        /* Find all IP4 addresses of this connection on the device */
1912
1858
        num = nm_setting_ip4_config_get_num_addresses (s_ip4);
1913
1859
        for (i = 0; i < num; i++) {
1914
 
                memset (&check_data, 0, sizeof (check_data));
1915
 
                check_data.ifindex = ifindex;
1916
 
                check_data.found = FALSE;
1917
 
                check_data.addr = nm_setting_ip4_config_get_address (s_ip4, i);
 
1860
                NMIP4Address *addr = nm_setting_ip4_config_get_address (s_ip4, i);
 
1861
                struct in_addr tmp = { .s_addr = nm_ip4_address_get_address (addr) };
1918
1862
 
1919
 
                nl_cache_foreach (addr_cache, check_one_address, &check_data);
1920
 
                if (!check_data.found)
 
1863
                if (!nm_netlink_find_address (nm_device_get_ip_ifindex (self),
 
1864
                                              AF_INET,
 
1865
                                              &tmp,
 
1866
                                              nm_ip4_address_get_prefix (addr)))
1921
1867
                        return FALSE;
1922
1868
        }
1923
1869