mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
2008-10-30 Dan Williams <dcbw@redhat.com>
* src/nm-device-ethernet.c src/nm-device-wifi.c src/nm-device.c src/ppp-manager/nm-ppp-manager.c - Harmonize return checking of ioctl * system-settings/plugins/ifcfg-fedora/reader.c - (is_wireless_device): fall back to SIOCGIWNAME (rh #466340) git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4236 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
cbd88c9482
commit
4129798d51
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2008-10-30 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* src/nm-device-ethernet.c
|
||||||
|
src/nm-device-wifi.c
|
||||||
|
src/nm-device.c
|
||||||
|
src/ppp-manager/nm-ppp-manager.c
|
||||||
|
- Harmonize return checking of ioctl
|
||||||
|
|
||||||
|
* system-settings/plugins/ifcfg-fedora/reader.c
|
||||||
|
- (is_wireless_device): fall back to SIOCGIWNAME (rh #466340)
|
||||||
|
|
||||||
2008-10-30 Dan Williams <dcbw@redhat.com>
|
2008-10-30 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* src/ppp-manager/nm-ppp-manager.c
|
* src/ppp-manager/nm-ppp-manager.c
|
||||||
|
|
|
@ -451,7 +451,7 @@ nm_device_ethernet_get_speed (NMDeviceEthernet *self)
|
||||||
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
||||||
ifr.ifr_data = (char *) &edata;
|
ifr.ifr_data = (char *) &edata;
|
||||||
|
|
||||||
if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
|
if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
|
||||||
|
@ -474,7 +474,7 @@ real_update_hw_address (NMDevice *dev)
|
||||||
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
|
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
|
||||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
int ret, fd;
|
int fd;
|
||||||
|
|
||||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -484,8 +484,7 @@ real_update_hw_address (NMDevice *dev)
|
||||||
|
|
||||||
memset (&req, 0, sizeof (struct ifreq));
|
memset (&req, 0, sizeof (struct ifreq));
|
||||||
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
|
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
|
||||||
ret = ioctl (fd, SIOCGIFHWADDR, &req);
|
if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
|
||||||
if (ret) {
|
|
||||||
nm_warning ("%s: (%s) error getting hardware address: %d",
|
nm_warning ("%s: (%s) error getting hardware address: %d",
|
||||||
__func__, nm_device_get_iface (dev), errno);
|
__func__, nm_device_get_iface (dev), errno);
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1616,7 +1615,7 @@ supports_ethtool_carrier_detect (NMDeviceEthernet *self)
|
||||||
edata.cmd = ETHTOOL_GLINK;
|
edata.cmd = ETHTOOL_GLINK;
|
||||||
ifr.ifr_data = (char *) &edata;
|
ifr.ifr_data = (char *) &edata;
|
||||||
|
|
||||||
if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
|
if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
supports_ethtool = TRUE;
|
supports_ethtool = TRUE;
|
||||||
|
@ -1649,7 +1648,7 @@ mdio_read (NMDeviceEthernet *self, int fd, struct ifreq *ifr, int location)
|
||||||
mii = (struct mii_ioctl_data *) &ifr->ifr_ifru;
|
mii = (struct mii_ioctl_data *) &ifr->ifr_ifru;
|
||||||
mii->reg_num = location;
|
mii->reg_num = location;
|
||||||
|
|
||||||
if (ioctl (fd, SIOCGMIIREG, ifr) >= 0)
|
if (ioctl (fd, SIOCGMIIREG, ifr) == 0)
|
||||||
val = mii->val_out;
|
val = mii->val_out;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
@ -1658,7 +1657,7 @@ mdio_read (NMDeviceEthernet *self, int fd, struct ifreq *ifr, int location)
|
||||||
static gboolean
|
static gboolean
|
||||||
supports_mii_carrier_detect (NMDeviceEthernet *self)
|
supports_mii_carrier_detect (NMDeviceEthernet *self)
|
||||||
{
|
{
|
||||||
int err, fd, bmsr;
|
int fd, bmsr;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
gboolean supports_mii = FALSE;
|
gboolean supports_mii = FALSE;
|
||||||
|
|
||||||
|
@ -1673,8 +1672,7 @@ supports_mii_carrier_detect (NMDeviceEthernet *self)
|
||||||
memset (&ifr, 0, sizeof (struct ifreq));
|
memset (&ifr, 0, sizeof (struct ifreq));
|
||||||
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
||||||
|
|
||||||
err = ioctl (fd, SIOCGMIIPHY, &ifr);
|
if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0)
|
||||||
if (err < 0)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* If we can read the BMSR register, we assume that the card supports MII link detection */
|
/* If we can read the BMSR register, we assume that the card supports MII link detection */
|
||||||
|
|
|
@ -310,7 +310,7 @@ wireless_get_range (NMDeviceWifi *self,
|
||||||
struct iw_range *range,
|
struct iw_range *range,
|
||||||
guint32 *response_len)
|
guint32 *response_len)
|
||||||
{
|
{
|
||||||
int fd, err, i = 26;
|
int fd, i = 26;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
const char *iface;
|
const char *iface;
|
||||||
struct iwreq wrq;
|
struct iwreq wrq;
|
||||||
|
@ -336,8 +336,7 @@ wireless_get_range (NMDeviceWifi *self,
|
||||||
* see rh bz#362421)
|
* see rh bz#362421)
|
||||||
*/
|
*/
|
||||||
while (i-- > 0) {
|
while (i-- > 0) {
|
||||||
err = ioctl (fd, SIOCGIWRANGE, &wrq);
|
if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0) {
|
||||||
if (err == 0) {
|
|
||||||
if (response_len)
|
if (response_len)
|
||||||
*response_len = wrq.u.data.length;
|
*response_len = wrq.u.data.length;
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
@ -390,8 +389,7 @@ real_get_generic_capabilities (NMDevice *dev)
|
||||||
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
||||||
err = ioctl (fd, SIOCSIWSCAN, &wrq);
|
err = ioctl (fd, SIOCSIWSCAN, &wrq);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
if ((err < 0) && (errno == EOPNOTSUPP))
|
||||||
if ((err == -1) && (errno == EOPNOTSUPP))
|
|
||||||
caps = NM_DEVICE_CAP_NONE;
|
caps = NM_DEVICE_CAP_NONE;
|
||||||
else
|
else
|
||||||
caps |= NM_DEVICE_CAP_NM_SUPPORTED;
|
caps |= NM_DEVICE_CAP_NM_SUPPORTED;
|
||||||
|
@ -1239,14 +1237,13 @@ nm_device_wifi_set_mode (NMDeviceWifi *self, const NM80211Mode mode)
|
||||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||||
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
||||||
|
|
||||||
if (ioctl (fd, SIOCSIWMODE, &wrq) == 0)
|
if (ioctl (fd, SIOCSIWMODE, &wrq) < 0) {
|
||||||
success = TRUE;
|
|
||||||
else {
|
|
||||||
if (errno != ENODEV) {
|
if (errno != ENODEV) {
|
||||||
nm_warning ("error setting card %s to mode %d: %s",
|
nm_warning ("error setting card %s to mode %d: %s",
|
||||||
iface, mode, strerror (errno));
|
iface, mode, strerror (errno));
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
success = TRUE;
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -1263,7 +1260,7 @@ out:
|
||||||
static guint32
|
static guint32
|
||||||
nm_device_wifi_get_frequency (NMDeviceWifi *self)
|
nm_device_wifi_get_frequency (NMDeviceWifi *self)
|
||||||
{
|
{
|
||||||
int err, fd;
|
int fd;
|
||||||
guint32 freq = 0;
|
guint32 freq = 0;
|
||||||
const char *iface;
|
const char *iface;
|
||||||
struct iwreq wrq;
|
struct iwreq wrq;
|
||||||
|
@ -1278,11 +1275,10 @@ nm_device_wifi_get_frequency (NMDeviceWifi *self)
|
||||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||||
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
||||||
|
|
||||||
err = ioctl (fd, SIOCGIWFREQ, &wrq);
|
if (ioctl (fd, SIOCGIWFREQ, &wrq) < 0)
|
||||||
if (err >= 0)
|
|
||||||
freq = iw_freq_to_uint32 (&wrq.u.freq);
|
|
||||||
else if (err == -1)
|
|
||||||
nm_warning ("(%s): error getting frequency: %s", iface, strerror (errno));
|
nm_warning ("(%s): error getting frequency: %s", iface, strerror (errno));
|
||||||
|
else
|
||||||
|
freq = iw_freq_to_uint32 (&wrq.u.freq);
|
||||||
|
|
||||||
close (fd);
|
close (fd);
|
||||||
return freq;
|
return freq;
|
||||||
|
@ -1555,7 +1551,7 @@ nm_device_wifi_get_bitrate (NMDeviceWifi *self)
|
||||||
err = ioctl (fd, SIOCGIWRATE, &wrq);
|
err = ioctl (fd, SIOCGIWRATE, &wrq);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0);
|
return ((err == 0) ? wrq.u.bitrate.value / 1000 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1584,7 +1580,7 @@ nm_device_wifi_get_bssid (NMDeviceWifi *self,
|
||||||
|
|
||||||
memset (&wrq, 0, sizeof (wrq));
|
memset (&wrq, 0, sizeof (wrq));
|
||||||
strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
|
||||||
if (ioctl (fd, SIOCGIWAP, &wrq) >= 0)
|
if (ioctl (fd, SIOCGIWAP, &wrq) == 0)
|
||||||
memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
|
memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
|
||||||
|
|
||||||
close (fd);
|
close (fd);
|
||||||
|
@ -1619,7 +1615,7 @@ nm_device_wifi_disable_encryption (NMDeviceWifi *self)
|
||||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||||
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
||||||
|
|
||||||
if (ioctl (fd, SIOCSIWENCODE, &wrq) == -1) {
|
if (ioctl (fd, SIOCSIWENCODE, &wrq) < 0) {
|
||||||
if (errno != ENODEV) {
|
if (errno != ENODEV) {
|
||||||
nm_warning ("error setting key for device %s: %s",
|
nm_warning ("error setting key for device %s: %s",
|
||||||
iface, strerror (errno));
|
iface, strerror (errno));
|
||||||
|
@ -2714,7 +2710,7 @@ real_update_hw_address (NMDevice *dev)
|
||||||
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
|
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
|
||||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
int ret, fd;
|
int fd;
|
||||||
|
|
||||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -2724,8 +2720,7 @@ real_update_hw_address (NMDevice *dev)
|
||||||
|
|
||||||
memset (&req, 0, sizeof (struct ifreq));
|
memset (&req, 0, sizeof (struct ifreq));
|
||||||
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
|
strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
|
||||||
ret = ioctl (fd, SIOCGIFHWADDR, &req);
|
if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
|
||||||
if (ret) {
|
|
||||||
nm_warning ("%s: (%s) error getting hardware address: %d",
|
nm_warning ("%s: (%s) error getting hardware address: %d",
|
||||||
__func__, nm_device_get_iface (dev), errno);
|
__func__, nm_device_get_iface (dev), errno);
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -1970,7 +1970,7 @@ nm_device_update_ip4_address (NMDevice *self)
|
||||||
{
|
{
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
guint32 new_address;
|
guint32 new_address;
|
||||||
int fd, err;
|
int fd;
|
||||||
|
|
||||||
g_return_if_fail (self != NULL);
|
g_return_if_fail (self != NULL);
|
||||||
|
|
||||||
|
@ -1982,16 +1982,13 @@ nm_device_update_ip4_address (NMDevice *self)
|
||||||
|
|
||||||
memset (&req, 0, sizeof (struct ifreq));
|
memset (&req, 0, sizeof (struct ifreq));
|
||||||
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
|
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
|
||||||
err = ioctl (fd, SIOCGIFADDR, &req);
|
if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
|
||||||
close (fd);
|
|
||||||
|
|
||||||
if (err != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
|
new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
|
||||||
if (new_address != nm_device_get_ip4_address (self))
|
if (new_address != nm_device_get_ip4_address (self))
|
||||||
self->priv->ip4_address = new_address;
|
self->priv->ip4_address = new_address;
|
||||||
}
|
}
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
nm_device_is_up (NMDevice *self)
|
nm_device_is_up (NMDevice *self)
|
||||||
|
|
|
@ -306,7 +306,7 @@ monitor_cb (gpointer user_data)
|
||||||
req.stats_ptr = (caddr_t) &req.stats;
|
req.stats_ptr = (caddr_t) &req.stats;
|
||||||
|
|
||||||
strncpy (req.ifr__name, priv->ip_iface, sizeof (req.ifr__name));
|
strncpy (req.ifr__name, priv->ip_iface, sizeof (req.ifr__name));
|
||||||
if (!ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
|
if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
|
||||||
nm_warning ("Could not read ppp stats: %s", strerror (errno));
|
nm_warning ("Could not read ppp stats: %s", strerror (errno));
|
||||||
else
|
else
|
||||||
g_signal_emit (manager, signals[STATS], 0,
|
g_signal_emit (manager, signals[STATS], 0,
|
||||||
|
|
|
@ -880,17 +880,14 @@ wired_connection_from_ifcfg (const char *file,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_wireless_device (const char *iface, gboolean *is_wireless)
|
is_wireless_device (const char *iface)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct iw_range range;
|
struct iw_range range;
|
||||||
struct iwreq wrq;
|
struct iwreq wrq;
|
||||||
gboolean success = FALSE;
|
gboolean is_wireless = FALSE;
|
||||||
|
|
||||||
g_return_val_if_fail (iface != NULL, FALSE);
|
g_return_val_if_fail (iface != NULL, FALSE);
|
||||||
g_return_val_if_fail (is_wireless != NULL, FALSE);
|
|
||||||
|
|
||||||
*is_wireless = FALSE;
|
|
||||||
|
|
||||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (!fd)
|
if (!fd)
|
||||||
|
@ -902,18 +899,25 @@ is_wireless_device (const char *iface, gboolean *is_wireless)
|
||||||
wrq.u.data.pointer = (caddr_t) ⦥
|
wrq.u.data.pointer = (caddr_t) ⦥
|
||||||
wrq.u.data.length = sizeof (struct iw_range);
|
wrq.u.data.length = sizeof (struct iw_range);
|
||||||
|
|
||||||
if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) {
|
if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0)
|
||||||
|
is_wireless = TRUE;
|
||||||
|
else {
|
||||||
if (errno == EOPNOTSUPP)
|
if (errno == EOPNOTSUPP)
|
||||||
success = TRUE;
|
is_wireless = FALSE;
|
||||||
goto out;
|
else {
|
||||||
|
/* Sigh... some wired devices (kvm/qemu) return EINVAL when the
|
||||||
|
* device is down even though it's not a wireless device. So try
|
||||||
|
* IWNAME as a fallback.
|
||||||
|
*/
|
||||||
|
memset (&wrq, 0, sizeof (struct iwreq));
|
||||||
|
strncpy (wrq.ifr_name, iface, IFNAMSIZ);
|
||||||
|
if (ioctl (fd, SIOCGIWNAME, &wrq) == 0)
|
||||||
|
is_wireless = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*is_wireless = TRUE;
|
|
||||||
success = TRUE;
|
|
||||||
|
|
||||||
out:
|
|
||||||
close (fd);
|
close (fd);
|
||||||
return success;
|
return is_wireless;
|
||||||
}
|
}
|
||||||
|
|
||||||
NMConnection *
|
NMConnection *
|
||||||
|
@ -953,7 +957,6 @@ connection_from_file (const char *filename,
|
||||||
type = svGetValue (parsed, "TYPE");
|
type = svGetValue (parsed, "TYPE");
|
||||||
if (!type) {
|
if (!type) {
|
||||||
char *device;
|
char *device;
|
||||||
gboolean is_wireless = FALSE;
|
|
||||||
|
|
||||||
/* If no type, if the device has wireless extensions, it's wifi,
|
/* If no type, if the device has wireless extensions, it's wifi,
|
||||||
* otherwise it's ethernet.
|
* otherwise it's ethernet.
|
||||||
|
@ -973,15 +976,7 @@ connection_from_file (const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test wireless extensions */
|
/* Test wireless extensions */
|
||||||
if (!is_wireless_device (device, &is_wireless)) {
|
if (is_wireless_device (device))
|
||||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
|
||||||
"File '%s' specified device '%s', but the device's "
|
|
||||||
"type could not be determined.", filename, device);
|
|
||||||
g_free (device);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_wireless)
|
|
||||||
type = g_strdup (TYPE_WIRELESS);
|
type = g_strdup (TYPE_WIRELESS);
|
||||||
else
|
else
|
||||||
type = g_strdup (TYPE_ETHERNET);
|
type = g_strdup (TYPE_ETHERNET);
|
||||||
|
|
Loading…
Reference in a new issue