mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-23 19:24:38 +00:00
2008-03-13 Dan Williams <dcbw@redhat.com>
* NetworkManagerUtils.c NetworkManagerUtils.h - Remove NMSock stuff - Remove the completion stuff * nm-device.c nm-device.h NetworkManager.c NetworkManagerSystem.c autoip.c nm-device-802-11-wireless.c nm-device-802-3-ethernet.c - Remove NMSock and completion stuff - Remove nm_ioctl_info() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3448 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
de4d3703ce
commit
6cfaab9c0c
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2008-03-13 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* NetworkManagerUtils.c
|
||||
NetworkManagerUtils.h
|
||||
- Remove NMSock stuff
|
||||
- Remove the completion stuff
|
||||
|
||||
* nm-device.c
|
||||
nm-device.h
|
||||
NetworkManager.c
|
||||
NetworkManagerSystem.c
|
||||
autoip.c
|
||||
nm-device-802-11-wireless.c
|
||||
nm-device-802-3-ethernet.c
|
||||
- Remove NMSock and completion stuff
|
||||
- Remove nm_ioctl_info()
|
||||
|
||||
2008-03-12 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/nm-device.c
|
||||
|
|
|
@ -353,8 +353,6 @@ main (int argc, char *argv[])
|
|||
g_main_loop_run (main_loop);
|
||||
|
||||
done:
|
||||
nm_print_open_socks ();
|
||||
|
||||
if (vpn_manager)
|
||||
g_object_unref (vpn_manager);
|
||||
|
||||
|
|
|
@ -68,11 +68,10 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
int ip4_netmask,
|
||||
int mss)
|
||||
{
|
||||
NMSock * sk;
|
||||
int fd, err;
|
||||
gboolean success = FALSE;
|
||||
struct rtentry rtent;
|
||||
struct sockaddr_in *p;
|
||||
int err;
|
||||
struct rtentry rtent2;
|
||||
|
||||
/*
|
||||
|
@ -92,8 +91,11 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
return TRUE;
|
||||
|
||||
|
||||
if ((sk = nm_dev_sock_open (iface, NETWORK_CONTROL, __func__, NULL)) == NULL)
|
||||
fd = socket (AF_PACKET, SOCK_PACKET, htons (ETH_P_ALL));
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset (&rtent, 0, sizeof (struct rtentry));
|
||||
p = (struct sockaddr_in *) &rtent.rt_dst;
|
||||
|
@ -115,9 +117,7 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
rtent.rt_mtu = mss;
|
||||
}
|
||||
|
||||
nm_ioctl_info ("%s: About to CADDRT\n", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent);
|
||||
nm_ioctl_info ("%s: About to CADDRT\n", iface);
|
||||
err = ioctl (fd, SIOCADDRT, &rtent);
|
||||
if (err == 0) {
|
||||
/* Everything good */
|
||||
success = TRUE;
|
||||
|
@ -151,9 +151,7 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
}
|
||||
|
||||
/* Add route to gateway over bridge */
|
||||
nm_ioctl_info ("%s: About to CADDRT (2)\n", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent2);
|
||||
nm_ioctl_info ("%s: About to CADDRT (2)\n", iface);
|
||||
err = ioctl (fd, SIOCADDRT, &rtent2);
|
||||
if (err) {
|
||||
nm_warning ("Failed to add IPv4 default route on '%s': %s",
|
||||
iface,
|
||||
|
@ -162,9 +160,7 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
}
|
||||
|
||||
/* Try adding the route again */
|
||||
nm_ioctl_info ("%s: About to CADDRT (3)\n", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent);
|
||||
nm_ioctl_info ("%s: About to CADDRT (3)\n", iface);
|
||||
err = ioctl (fd, SIOCADDRT, &rtent);
|
||||
if (!err) {
|
||||
success = TRUE;
|
||||
} else {
|
||||
|
@ -174,7 +170,7 @@ nm_system_device_set_ip4_route (const char *iface,
|
|||
}
|
||||
|
||||
out:
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,140 +43,6 @@
|
|||
#include <netlink/addr.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
|
||||
struct NMSock
|
||||
{
|
||||
int fd;
|
||||
char *func;
|
||||
char *desc;
|
||||
char *iface;
|
||||
};
|
||||
|
||||
static GSList * sock_list = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* nm_dev_sock_open
|
||||
*
|
||||
* Open a socket to a network device and store some debug info about it.
|
||||
*
|
||||
*/
|
||||
NMSock *
|
||||
nm_dev_sock_open (const char *iface, SockType type, const char *func_name, const char *desc)
|
||||
{
|
||||
NMSock *sock = NULL;
|
||||
|
||||
sock = g_slice_new (NMSock);
|
||||
sock->fd = -1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DEV_WIRELESS:
|
||||
sock->fd = iw_sockets_open ();
|
||||
break;
|
||||
|
||||
case DEV_GENERAL:
|
||||
if ((sock->fd = socket (PF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
if ((sock->fd = socket (PF_PACKET, SOCK_DGRAM, 0)) < 0)
|
||||
sock->fd = socket (PF_INET6, SOCK_DGRAM, 0);
|
||||
break;
|
||||
|
||||
case NETWORK_CONTROL:
|
||||
sock->fd = socket (AF_PACKET, SOCK_PACKET, htons (ETH_P_ALL));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (sock->fd < 0)
|
||||
{
|
||||
g_slice_free (NMSock, sock);
|
||||
nm_warning ("Could not open control socket for device '%s'.", iface ? iface : "none");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->func = func_name ? g_strdup (func_name) : NULL;
|
||||
sock->desc = desc ? g_strdup (desc) : NULL;
|
||||
sock->iface = iface ? g_strdup (iface) : NULL;
|
||||
|
||||
/* Add the sock to our global sock list for tracking */
|
||||
sock_list = g_slist_prepend (sock_list, sock);
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dev_sock_close
|
||||
*
|
||||
* Close a socket and free its debug data.
|
||||
*
|
||||
*/
|
||||
void nm_dev_sock_close (NMSock *sock)
|
||||
{
|
||||
GSList *elt;
|
||||
|
||||
g_return_if_fail (sock != NULL);
|
||||
|
||||
close (sock->fd);
|
||||
g_free (sock->func);
|
||||
g_free (sock->desc);
|
||||
g_free (sock->iface);
|
||||
|
||||
memset (sock, 0, sizeof (NMSock));
|
||||
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt)) {
|
||||
NMSock *temp_sock = (NMSock *)(elt->data);
|
||||
if (temp_sock == sock) {
|
||||
sock_list = g_slist_remove_link (sock_list, elt);
|
||||
g_slist_free (elt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_slice_free (NMSock, sock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dev_sock_get_fd
|
||||
*
|
||||
* Return the fd associated with an NMSock
|
||||
*
|
||||
*/
|
||||
int nm_dev_sock_get_fd (NMSock *sock)
|
||||
{
|
||||
g_return_val_if_fail (sock != NULL, -1);
|
||||
|
||||
return sock->fd;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_print_open_socks
|
||||
*
|
||||
* Print a list of currently open and registered NMSocks.
|
||||
*
|
||||
*/
|
||||
void nm_print_open_socks (void)
|
||||
{
|
||||
GSList *elt = NULL;
|
||||
int i = 0;
|
||||
|
||||
nm_debug ("Open Sockets List:");
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt)) {
|
||||
NMSock *sock = (NMSock *)(elt->data);
|
||||
if (sock) {
|
||||
i++;
|
||||
nm_debug (" %d: %s fd:%d F:'%s' D:'%s'", i, sock->iface ? sock->iface : "",
|
||||
sock->fd, sock->func, sock->desc);
|
||||
}
|
||||
}
|
||||
nm_debug ("Open Sockets List Done.");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_null_safe_strcmp
|
||||
*
|
||||
|
@ -387,162 +253,6 @@ static inline void nm_timeval_add(struct timeval *a,
|
|||
}
|
||||
}
|
||||
|
||||
static void nm_v_wait_for_completion_or_timeout(
|
||||
const int max_tries,
|
||||
const struct timeval *max_time,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args)
|
||||
{
|
||||
int try;
|
||||
gboolean finished = FALSE;
|
||||
struct timeval finish_time;
|
||||
|
||||
g_return_if_fail (test_func || action_func);
|
||||
|
||||
if (max_time) {
|
||||
gettimeofday(&finish_time, NULL);
|
||||
nm_timeval_add(&finish_time, max_time);
|
||||
}
|
||||
|
||||
try = -1;
|
||||
while (!finished &&
|
||||
(max_tries == NM_COMPLETION_TRIES_INFINITY || try < max_tries))
|
||||
{
|
||||
if (max_time && nm_timeval_has_passed(&finish_time))
|
||||
break;
|
||||
try++;
|
||||
if (test_func)
|
||||
{
|
||||
finished = (*test_func)(try, args);
|
||||
if (finished)
|
||||
break;
|
||||
}
|
||||
|
||||
/* #define NM_SLEEP_DEBUG */
|
||||
#ifdef NM_SLEEP_DEBUG
|
||||
syslog (LOG_INFO, "sleeping for %d usecs", interval_usecs);
|
||||
#endif
|
||||
g_usleep(interval_usecs);
|
||||
if (action_func)
|
||||
finished = (*action_func)(try, args);
|
||||
}
|
||||
}
|
||||
|
||||
/* these should probably be moved to NetworkManagerUtils.h as macros
|
||||
* since they don't do varargs stuff any more */
|
||||
void nm_wait_for_completion_or_timeout(
|
||||
const int max_tries,
|
||||
const struct timeval *max_time,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args)
|
||||
{
|
||||
nm_v_wait_for_completion_or_timeout(max_tries, max_time,
|
||||
interval_usecs, test_func,
|
||||
action_func, args);
|
||||
}
|
||||
|
||||
void nm_wait_for_completion(
|
||||
const int max_tries,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args)
|
||||
{
|
||||
nm_v_wait_for_completion_or_timeout(max_tries, NULL,
|
||||
interval_usecs, test_func,
|
||||
action_func, args);
|
||||
}
|
||||
|
||||
void nm_wait_for_timeout(
|
||||
const struct timeval *max_time,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args)
|
||||
{
|
||||
nm_v_wait_for_completion_or_timeout(NM_COMPLETION_TRIES_INFINITY, max_time,
|
||||
interval_usecs, test_func, action_func, args);
|
||||
}
|
||||
|
||||
/* you can use these, but they're really just examples */
|
||||
gboolean nm_completion_boolean_test(int tries, nm_completion_args args)
|
||||
{
|
||||
gboolean *condition = (gboolean *)args[0];
|
||||
char *message = (char *)args[1];
|
||||
int log_level = GPOINTER_TO_INT (args[2]);
|
||||
int log_interval = GPOINTER_TO_INT (args[3]);
|
||||
|
||||
g_return_val_if_fail (condition != NULL, TRUE);
|
||||
|
||||
if (message)
|
||||
if ((log_interval == 0 && tries == 0) || (log_interval != 0 && tries % log_interval == 0))
|
||||
{
|
||||
if (log_level == LOG_WARNING)
|
||||
nm_warning_str (message);
|
||||
else if (log_level == LOG_ERR)
|
||||
nm_error_str (message);
|
||||
else if (log_level == LOG_DEBUG)
|
||||
nm_debug_str (message);
|
||||
else
|
||||
nm_info_str (message);
|
||||
}
|
||||
|
||||
if (*condition)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean nm_completion_boolean_function1_test(int tries,
|
||||
nm_completion_args args)
|
||||
{
|
||||
nm_completion_boolean_function_1 condition = args[0];
|
||||
char *message = args[1];
|
||||
int log_level = GPOINTER_TO_INT (args[2]);
|
||||
int log_interval = GPOINTER_TO_INT (args[3]);
|
||||
u_int64_t arg0;
|
||||
|
||||
memcpy(&arg0, &args[4], sizeof (arg0));
|
||||
|
||||
g_return_val_if_fail (condition, TRUE);
|
||||
|
||||
if (message)
|
||||
if ((log_interval == 0 && tries == 0)
|
||||
|| (log_interval != 0 && tries % log_interval == 0))
|
||||
syslog(log_level, "%s", message);
|
||||
|
||||
if (!(*condition)(arg0))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean nm_completion_boolean_function2_test(int tries,
|
||||
nm_completion_args args)
|
||||
{
|
||||
nm_completion_boolean_function_2 condition = args[0];
|
||||
char *message = args[1];
|
||||
int log_level = GPOINTER_TO_INT (args[2]);
|
||||
int log_interval = GPOINTER_TO_INT (args[3]);
|
||||
u_int64_t arg0, arg1;
|
||||
|
||||
memcpy(&arg0, &args[4], sizeof (arg0));
|
||||
memcpy(&arg1, &args[4]+sizeof (arg0), sizeof (arg1));
|
||||
|
||||
g_return_val_if_fail (condition, TRUE);
|
||||
|
||||
if (message)
|
||||
if ((log_interval == 0 && tries == 0)
|
||||
|| (log_interval != 0 && tries % log_interval == 0))
|
||||
syslog(log_level, "%s", message);
|
||||
|
||||
if (!(*condition)(arg0, arg1))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
gchar *nm_utils_inet_ip4_address_as_string (guint32 ip)
|
||||
{
|
||||
|
|
|
@ -33,25 +33,6 @@
|
|||
#include "NetworkManager.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
typedef enum SockType
|
||||
{
|
||||
DEV_WIRELESS,
|
||||
DEV_GENERAL,
|
||||
NETWORK_CONTROL
|
||||
} SockType;
|
||||
|
||||
typedef struct NMSock NMSock;
|
||||
|
||||
|
||||
NMSock * nm_dev_sock_open (const char *iface,
|
||||
SockType type,
|
||||
const char *func_name,
|
||||
const char *desc);
|
||||
|
||||
void nm_dev_sock_close (NMSock *sock);
|
||||
int nm_dev_sock_get_fd (NMSock *sock);
|
||||
void nm_print_open_socks (void);
|
||||
|
||||
int nm_null_safe_strcmp (const char *s1, const char *s2);
|
||||
|
||||
gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr);
|
||||
|
@ -61,44 +42,6 @@ int nm_spawn_process (const char *args);
|
|||
|
||||
void nm_print_device_capabilities (NMDevice *dev);
|
||||
|
||||
#define NM_COMPLETION_TRIES_INFINITY -1
|
||||
|
||||
typedef void * nm_completion_args[8];
|
||||
|
||||
typedef gboolean (*nm_completion_func)(int tries, nm_completion_args args);
|
||||
typedef gboolean (*nm_completion_boolean_function_1)(u_int64_t arg);
|
||||
typedef gboolean (*nm_completion_boolean_function_2)(
|
||||
u_int64_t arg0, u_int64_t arg1);
|
||||
|
||||
void nm_wait_for_completion(
|
||||
const int max_tries,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args);
|
||||
|
||||
void nm_wait_for_completion_or_timeout(
|
||||
const int max_tries,
|
||||
const struct timeval *max_time,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args);
|
||||
|
||||
void nm_wait_for_timeout(
|
||||
const struct timeval *max_time,
|
||||
const guint interval_usecs,
|
||||
nm_completion_func test_func,
|
||||
nm_completion_func action_func,
|
||||
nm_completion_args args);
|
||||
|
||||
gboolean nm_completion_boolean_test(int tries, nm_completion_args args);
|
||||
gboolean nm_completion_boolean_function1_test(int tries,
|
||||
nm_completion_args args);
|
||||
gboolean nm_completion_boolean_function2_test(int tries,
|
||||
nm_completion_args args);
|
||||
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
|
||||
|
||||
gchar* nm_utils_inet_ip4_address_as_string (guint32 ip);
|
||||
|
||||
struct nl_addr * nm_utils_ip4_addr_to_nl_addr (guint32 ip4_addr);
|
||||
|
|
25
src/autoip.c
25
src/autoip.c
|
@ -209,7 +209,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
ARPMessage p;
|
||||
struct ether_addr addr;
|
||||
struct in_addr ip = {0};
|
||||
NMSock * sk = NULL;
|
||||
int fd = -1;
|
||||
int nprobes = 0;
|
||||
int nannounce = 0;
|
||||
gboolean success = FALSE;
|
||||
|
@ -233,15 +233,14 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
goto out;
|
||||
|
||||
/* open an ARP socket */
|
||||
if ((sk = nm_dev_sock_open (iface, NETWORK_CONTROL, __FUNCTION__, NULL)) == NULL)
|
||||
{
|
||||
fd = socket (AF_PACKET, SOCK_PACKET, htons (ETH_P_ALL));
|
||||
if (fd < 0) {
|
||||
nm_warning ("%s: Couldn't open network control socket.", iface);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* bind to the ARP socket */
|
||||
if (bind (nm_dev_sock_get_fd (sk), &saddr, sizeof (saddr)) < 0)
|
||||
{
|
||||
if (bind (fd, &saddr, sizeof (saddr)) < 0) {
|
||||
nm_warning ("%s: Couldn't bind to the device.", iface);
|
||||
goto out;
|
||||
}
|
||||
|
@ -264,7 +263,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
if (nprobes < PROBE_NUM)
|
||||
{
|
||||
nm_info ("autoip: Sending probe #%d for IP address %s.", nprobes, inet_ntoa (ip));
|
||||
arp (nm_dev_sock_get_fd (sk), &saddr, ARPOP_REQUEST, &addr, null_ip, &null_addr, ip);
|
||||
arp (fd, &saddr, ARPOP_REQUEST, &addr, null_ip, &null_addr, ip);
|
||||
nprobes++;
|
||||
gettimeofday (&timeout, NULL);
|
||||
if (nprobes == PROBE_NUM)
|
||||
|
@ -286,7 +285,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
else if (nannounce < ANNOUNCE_NUM)
|
||||
{
|
||||
nm_info ("autoip: Sending announce #%d for IP address %s.", nannounce, inet_ntoa (ip));
|
||||
arp (nm_dev_sock_get_fd (sk), &saddr, ARPOP_REQUEST, &addr, ip, &addr, ip);
|
||||
arp (fd, &saddr, ARPOP_REQUEST, &addr, ip, &addr, ip);
|
||||
nannounce++;
|
||||
gettimeofday (&timeout, NULL);
|
||||
timeout.tv_sec += ANNOUNCE_INTERVAL;
|
||||
|
@ -301,18 +300,16 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
}
|
||||
|
||||
nm_info ("autoip: Waiting for reply...");
|
||||
err = peekfd (dev, nm_dev_sock_get_fd (sk), &timeout);
|
||||
err = peekfd (dev, fd, &timeout);
|
||||
if ((err == RET_ERROR) || (err == RET_CEASED))
|
||||
goto out;
|
||||
|
||||
/* There's some data waiting for us */
|
||||
if (err == RET_SUCCESS)
|
||||
{
|
||||
if (err == RET_SUCCESS) {
|
||||
nm_info ("autoip: Got some data to check for reply packet.");
|
||||
|
||||
/* read ARP packet */
|
||||
if (recv (nm_dev_sock_get_fd (sk), &p, sizeof (p), 0) < 0)
|
||||
{
|
||||
if (recv (fd, &p, sizeof (p), 0) < 0) {
|
||||
nm_warning ("autoip: packet receive failure, ignoring it.");
|
||||
continue;
|
||||
}
|
||||
|
@ -348,7 +345,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||
}
|
||||
|
||||
out:
|
||||
if (sk)
|
||||
nm_dev_sock_close (sk);
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -210,34 +210,29 @@ static void
|
|||
nm_device_802_11_wireless_update_signal_strength (NMDevice80211Wireless *self,
|
||||
NMAccessPoint *ap)
|
||||
{
|
||||
gboolean has_range = FALSE;
|
||||
NMSock * sk;
|
||||
iwrange range;
|
||||
iwstats stats;
|
||||
int percent = -1;
|
||||
int fd, percent = -1;
|
||||
const char *iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL)))
|
||||
{
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd >= 0) {
|
||||
gboolean has_range = FALSE;
|
||||
iwrange range;
|
||||
iwstats stats;
|
||||
|
||||
memset (&range, 0, sizeof (iwrange));
|
||||
has_range = (iw_get_range_info (fd, iface, &range) >= 0);
|
||||
|
||||
memset (&stats, 0, sizeof (iwstats));
|
||||
|
||||
nm_ioctl_info ("%s: About to GET 'iwrange'.", iface);
|
||||
has_range = (iw_get_range_info (nm_dev_sock_get_fd (sk), iface, &range) >= 0);
|
||||
nm_ioctl_info ("%s: About to GET 'iwstats'.", iface);
|
||||
|
||||
if (iw_get_stats (nm_dev_sock_get_fd (sk), iface, &stats, &range, has_range) == 0)
|
||||
{
|
||||
if (iw_get_stats (fd, iface, &stats, &range, has_range) == 0) {
|
||||
percent = wireless_qual_to_percent (&stats.qual, (const iwqual *)(&self->priv->max_qual),
|
||||
(const iwqual *)(&self->priv->avg_qual));
|
||||
}
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
/* Try to smooth out the strength. Atmel cards, for example, will give no strength
|
||||
* one second and normal strength the next.
|
||||
*/
|
||||
|
||||
if (percent >= 0 || ++self->priv->invalid_strength_counter > 3) {
|
||||
nm_ap_set_strength (ap, (gint8) percent);
|
||||
self->priv->invalid_strength_counter = 0;
|
||||
|
@ -248,20 +243,24 @@ nm_device_802_11_wireless_update_signal_strength (NMDevice80211Wireless *self,
|
|||
static guint32
|
||||
real_get_generic_capabilities (NMDevice *dev)
|
||||
{
|
||||
NMSock * sk;
|
||||
int err;
|
||||
guint32 caps = NM_DEVICE_CAP_NONE;
|
||||
iwrange range;
|
||||
struct iwreq wrq;
|
||||
int fd, err;
|
||||
guint32 caps = NM_DEVICE_CAP_NONE;
|
||||
iwrange range;
|
||||
struct iwreq wrq;
|
||||
const char *iface = nm_device_get_iface (dev);
|
||||
|
||||
/* Check for Wireless Extensions support >= 16 for wireless devices */
|
||||
|
||||
if (!(sk = nm_dev_sock_open (iface, DEV_WIRELESS, __func__, NULL)))
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (iw_get_range_info (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), &range) < 0)
|
||||
if (iw_get_range_info (fd, iface, &range) < 0) {
|
||||
nm_warning ("couldn't get driver range information.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (range.we_version_compiled < 16) {
|
||||
nm_warning ("%s: driver's Wireless Extensions version (%d) is too old.",
|
||||
|
@ -273,13 +272,13 @@ real_get_generic_capabilities (NMDevice *dev)
|
|||
|
||||
/* Card's that don't scan aren't supported */
|
||||
memset (&wrq, 0, sizeof (struct iwreq));
|
||||
err = iw_set_ext (nm_dev_sock_get_fd (sk), nm_device_get_iface (dev), SIOCSIWSCAN, &wrq);
|
||||
err = iw_set_ext (fd, iface, SIOCSIWSCAN, &wrq);
|
||||
if ((err == -1) && (errno == EOPNOTSUPP))
|
||||
caps = NM_DEVICE_CAP_NONE;
|
||||
|
||||
out:
|
||||
if (sk)
|
||||
nm_dev_sock_close (sk);
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
@ -404,7 +403,7 @@ constructor (GType type,
|
|||
NMDevice80211Wireless *self;
|
||||
NMDevice80211WirelessPrivate *priv;
|
||||
const char *iface;
|
||||
NMSock *sk = NULL;
|
||||
int fd;
|
||||
struct iw_range range;
|
||||
struct iw_range_with_scan_capa *scan_capa_range;
|
||||
struct iwreq wrq;
|
||||
|
@ -419,8 +418,8 @@ constructor (GType type,
|
|||
priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (self);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
|
||||
memset (&wrq, 0, sizeof (struct iwreq));
|
||||
|
@ -429,7 +428,7 @@ constructor (GType type,
|
|||
wrq.u.data.pointer = (caddr_t) ⦥
|
||||
wrq.u.data.length = sizeof (struct iw_range);
|
||||
|
||||
if (ioctl (nm_dev_sock_get_fd (sk), SIOCGIWRANGE, &wrq) < 0)
|
||||
if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0)
|
||||
goto error;
|
||||
|
||||
priv->max_qual.qual = range.max_qual.qual;
|
||||
|
@ -467,12 +466,12 @@ constructor (GType type,
|
|||
/* 802.11 wireless-specific capabilities */
|
||||
priv->capabilities = get_wireless_capabilities (self, &range, wrq.u.data.length);
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return object;
|
||||
|
||||
error:
|
||||
if (sk)
|
||||
nm_dev_sock_close (sk);
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -963,7 +962,7 @@ nm_device_802_11_wireless_can_activate (NMDevice80211Wireless * self)
|
|||
int
|
||||
nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *self)
|
||||
{
|
||||
NMSock *sk;
|
||||
int fd;
|
||||
int mode = IW_MODE_AUTO;
|
||||
const char *iface;
|
||||
struct iwreq wrq;
|
||||
|
@ -971,21 +970,20 @@ nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *self)
|
|||
g_return_val_if_fail (self != NULL, -1);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
goto out;
|
||||
|
||||
memset (&wrq, 0, sizeof (struct iwreq));
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IWMODE.", iface);
|
||||
if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWMODE, &wrq) == 0) {
|
||||
if (iw_get_ext (fd, iface, SIOCGIWMODE, &wrq) == 0) {
|
||||
if ((wrq.u.mode == IW_MODE_ADHOC) || (wrq.u.mode == IW_MODE_INFRA))
|
||||
mode = wrq.u.mode;
|
||||
} else {
|
||||
if (errno != ENODEV)
|
||||
nm_warning ("error getting card mode on %s: %s", iface, strerror (errno));
|
||||
}
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
|
||||
out:
|
||||
return mode;
|
||||
|
@ -1002,7 +1000,7 @@ gboolean
|
|||
nm_device_802_11_wireless_set_mode (NMDevice80211Wireless *self,
|
||||
const int mode)
|
||||
{
|
||||
NMSock *sk;
|
||||
int fd;
|
||||
const char *iface;
|
||||
gboolean success = FALSE;
|
||||
struct iwreq wrq;
|
||||
|
@ -1015,16 +1013,13 @@ nm_device_802_11_wireless_set_mode (NMDevice80211Wireless *self,
|
|||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
goto out;
|
||||
|
||||
nm_ioctl_info ("%s: About to SET IWMODE.", iface);
|
||||
|
||||
memset (&wrq, 0, sizeof (struct iwreq));
|
||||
wrq.u.mode = mode;
|
||||
|
||||
if (iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWMODE, &wrq) == 0)
|
||||
if (iw_set_ext (fd, iface, SIOCSIWMODE, &wrq) == 0)
|
||||
success = TRUE;
|
||||
else {
|
||||
if (errno != ENODEV) {
|
||||
|
@ -1032,7 +1027,7 @@ nm_device_802_11_wireless_set_mode (NMDevice80211Wireless *self,
|
|||
iface, mode, strerror (errno));
|
||||
}
|
||||
}
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
|
||||
out:
|
||||
return success;
|
||||
|
@ -1048,8 +1043,7 @@ out:
|
|||
static guint32
|
||||
nm_device_802_11_wireless_get_frequency (NMDevice80211Wireless *self)
|
||||
{
|
||||
NMSock *sk;
|
||||
int err;
|
||||
int err, fd;
|
||||
guint32 freq = 0;
|
||||
const char *iface;
|
||||
struct iwreq wrq;
|
||||
|
@ -1057,20 +1051,19 @@ nm_device_802_11_wireless_get_frequency (NMDevice80211Wireless *self)
|
|||
g_return_val_if_fail (self != NULL, 0);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
memset (&wrq, 0, sizeof (struct iwreq));
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IWFREQ.", iface);
|
||||
err = iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWFREQ, &wrq);
|
||||
err = iw_get_ext (fd, iface, SIOCGIWFREQ, &wrq);
|
||||
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_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return freq;
|
||||
}
|
||||
|
||||
|
@ -1325,22 +1318,20 @@ nm_device_802_11_wireless_set_ssid (NMDevice80211Wireless *self,
|
|||
static guint32
|
||||
nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self)
|
||||
{
|
||||
NMSock *sk;
|
||||
int err = -1;
|
||||
int err = -1, fd;
|
||||
struct iwreq wrq;
|
||||
const char *iface;
|
||||
|
||||
g_return_val_if_fail (self != NULL, 0);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __func__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IWRATE.", iface);
|
||||
memset (&wrq, 0, sizeof (wrq));
|
||||
err = iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWRATE, &wrq);
|
||||
nm_dev_sock_close (sk);
|
||||
err = iw_get_ext (fd, iface, SIOCGIWRATE, &wrq);
|
||||
close (fd);
|
||||
|
||||
return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0);
|
||||
}
|
||||
|
@ -1355,9 +1346,9 @@ void
|
|||
nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self,
|
||||
struct ether_addr *bssid)
|
||||
{
|
||||
NMSock * sk;
|
||||
struct iwreq wrq;
|
||||
const char * iface;
|
||||
int fd;
|
||||
struct iwreq wrq;
|
||||
const char *iface;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (bssid != NULL);
|
||||
|
@ -1365,18 +1356,17 @@ nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self,
|
|||
memset (bssid, 0, sizeof (struct ether_addr));
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __func__, NULL);
|
||||
if (!sk) {
|
||||
g_warning ("%s: failed to open device socket.", __func__);
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
g_warning ("failed to open control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IWAP.", iface);
|
||||
memset (&wrq, 0, sizeof (wrq));
|
||||
if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWAP, &wrq) >= 0)
|
||||
if (iw_get_ext (fd, iface, SIOCGIWAP, &wrq) >= 0)
|
||||
memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1389,31 +1379,31 @@ nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self,
|
|||
static void
|
||||
nm_device_802_11_wireless_disable_encryption (NMDevice80211Wireless *self)
|
||||
{
|
||||
const char * iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
NMSock * sk;
|
||||
int fd;
|
||||
const char *iface;
|
||||
struct iwreq wreq = {
|
||||
.u.data.pointer = (caddr_t) NULL,
|
||||
.u.data.length = 0,
|
||||
.u.data.flags = IW_ENCODE_DISABLED
|
||||
};
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL)))
|
||||
{
|
||||
struct iwreq wreq = {
|
||||
.u.data.pointer = (caddr_t) NULL,
|
||||
.u.data.length = 0,
|
||||
.u.data.flags = IW_ENCODE_DISABLED
|
||||
};
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("could not open control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
nm_ioctl_info ("%s: About to SET IWENCODE.", iface);
|
||||
if (iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWENCODE, &wreq) == -1)
|
||||
{
|
||||
if (errno != ENODEV)
|
||||
{
|
||||
nm_warning ("error setting key for device %s: %s",
|
||||
iface, strerror (errno));
|
||||
}
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
if (iw_set_ext (fd, iface, SIOCSIWENCODE, &wreq) == -1) {
|
||||
if (errno != ENODEV) {
|
||||
nm_warning ("error setting key for device %s: %s",
|
||||
iface, strerror (errno));
|
||||
}
|
||||
}
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
} else nm_warning ("could not get wireless control socket for device %s", iface);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -2481,18 +2471,23 @@ static void
|
|||
real_set_hw_address (NMDevice *dev)
|
||||
{
|
||||
NMDevice80211Wireless *self = NM_DEVICE_802_11_WIRELESS (dev);
|
||||
const char *iface;
|
||||
struct ifreq req;
|
||||
NMSock *sk;
|
||||
int ret;
|
||||
size_t len;
|
||||
int ret, fd;
|
||||
|
||||
sk = nm_dev_sock_open (nm_device_get_iface (dev), DEV_GENERAL, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
g_warning ("could not open control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
iface = nm_device_get_iface (dev);
|
||||
len = MIN (sizeof (req.ifr_name) - 1, (size_t) strlen (iface));
|
||||
|
||||
memset (&req, 0, sizeof (struct ifreq));
|
||||
strncpy (req.ifr_name, nm_device_get_iface (dev), sizeof (req.ifr_name) - 1);
|
||||
|
||||
ret = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFHWADDR, &req);
|
||||
strncpy (req.ifr_name, iface, len);
|
||||
ret = ioctl (fd, SIOCGIFHWADDR, &req);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
|
@ -2503,7 +2498,7 @@ real_set_hw_address (NMDevice *dev)
|
|||
g_object_notify (G_OBJECT (dev), NM_DEVICE_802_11_WIRELESS_HW_ADDRESS);
|
||||
|
||||
out:
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -342,32 +342,35 @@ set_carrier (NMDevice8023Ethernet *self, const gboolean carrier)
|
|||
static guint32
|
||||
nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *self)
|
||||
{
|
||||
NMSock * sk;
|
||||
struct ifreq ifr;
|
||||
struct ethtool_cmd edata;
|
||||
const char * iface;
|
||||
guint32 speed = 0;
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
struct ethtool_cmd edata;
|
||||
const char *iface;
|
||||
guint32 speed = 0;
|
||||
size_t len;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (self != NULL, 0);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_GENERAL, __func__, NULL)) == NULL)
|
||||
{
|
||||
nm_warning ("cannot open socket on interface %s for ethtool: %s",
|
||||
iface, strerror (errno));
|
||||
return FALSE;
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1);
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
|
||||
memset (&ifr, 0, sizeof (struct ifreq));
|
||||
strncpy (ifr.ifr_name, iface, len);
|
||||
|
||||
edata.cmd = ETHTOOL_GSET;
|
||||
ifr.ifr_data = (char *) &edata;
|
||||
if (ioctl (nm_dev_sock_get_fd (sk), SIOCETHTOOL, &ifr) == -1)
|
||||
if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
|
||||
goto out;
|
||||
|
||||
speed = edata.speed != G_MAXUINT16 ? edata.speed : 0;
|
||||
|
||||
out:
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return speed;
|
||||
}
|
||||
|
||||
|
@ -376,23 +379,30 @@ real_set_hw_address (NMDevice *dev)
|
|||
{
|
||||
NMDevice8023Ethernet *self = NM_DEVICE_802_3_ETHERNET (dev);
|
||||
struct ifreq req;
|
||||
NMSock *sk;
|
||||
int ret;
|
||||
int ret, fd;
|
||||
const char *iface;
|
||||
size_t len;
|
||||
|
||||
sk = nm_dev_sock_open (nm_device_get_iface (dev), DEV_GENERAL, __FUNCTION__, NULL);
|
||||
if (!sk)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
iface = nm_device_get_iface (dev);
|
||||
len = MIN (sizeof (req.ifr_name) - 1, strlen (iface));
|
||||
memset (&req, 0, sizeof (struct ifreq));
|
||||
strncpy (req.ifr_name, nm_device_get_iface (dev), sizeof (req.ifr_name) - 1);
|
||||
strncpy (req.ifr_name, iface, len);
|
||||
|
||||
ret = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFHWADDR, &req);
|
||||
if (ret == 0)
|
||||
ret = ioctl (fd, SIOCGIFHWADDR, &req);
|
||||
if (ret == 0) {
|
||||
memcpy (&(NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (self)->hw_addr),
|
||||
&(req.ifr_hwaddr.sa_data), sizeof (struct ether_addr));
|
||||
}
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
static guint32
|
||||
real_get_generic_capabilities (NMDevice *dev)
|
||||
{
|
||||
|
@ -815,35 +825,36 @@ supplicant_iface_state_cb (NMSupplicantInterface * iface,
|
|||
static gboolean
|
||||
supports_ethtool_carrier_detect (NMDevice8023Ethernet *self)
|
||||
{
|
||||
NMSock * sk;
|
||||
struct ifreq ifr;
|
||||
gboolean supports_ethtool = FALSE;
|
||||
struct ethtool_cmd edata;
|
||||
const char * iface;
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
gboolean supports_ethtool = FALSE;
|
||||
struct ethtool_cmd edata;
|
||||
const char *iface;
|
||||
size_t len;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_GENERAL, __func__, NULL)) == NULL)
|
||||
{
|
||||
nm_warning ("cannot open socket on interface %s for ethtool detect: %s",
|
||||
iface, strerror (errno));
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
strncpy (ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1);
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
|
||||
memset (&ifr, 0, sizeof (struct ifreq));
|
||||
strncpy (ifr.ifr_name, iface, len);
|
||||
|
||||
edata.cmd = ETHTOOL_GLINK;
|
||||
ifr.ifr_data = (char *) &edata;
|
||||
|
||||
nm_ioctl_info ("%s: About to ETHTOOL\n", iface);
|
||||
if (ioctl (nm_dev_sock_get_fd (sk), SIOCETHTOOL, &ifr) == -1)
|
||||
if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
|
||||
goto out;
|
||||
|
||||
supports_ethtool = TRUE;
|
||||
|
||||
out:
|
||||
nm_ioctl_info ("%s: Done with ETHTOOL\n", iface);
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return supports_ethtool;
|
||||
}
|
||||
|
||||
|
@ -856,13 +867,13 @@ out:
|
|||
#undef _LINUX_IF_H
|
||||
|
||||
static int
|
||||
mdio_read (NMDevice8023Ethernet *self, NMSock *sk, struct ifreq *ifr, int location)
|
||||
mdio_read (NMDevice8023Ethernet *self, int fd, struct ifreq *ifr, int location)
|
||||
{
|
||||
struct mii_ioctl_data *mii;
|
||||
int val = -1;
|
||||
const char * iface;
|
||||
|
||||
g_return_val_if_fail (sk != NULL, -1);
|
||||
g_return_val_if_fail (fd >= 0, -1);
|
||||
g_return_val_if_fail (ifr != NULL, -1);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
|
@ -870,10 +881,8 @@ mdio_read (NMDevice8023Ethernet *self, NMSock *sk, struct ifreq *ifr, int locati
|
|||
mii = (struct mii_ioctl_data *) &ifr->ifr_ifru;
|
||||
mii->reg_num = location;
|
||||
|
||||
nm_ioctl_info ("%s: About to GET MIIREG\n", iface);
|
||||
if (ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIREG, ifr) >= 0)
|
||||
if (ioctl (fd, SIOCGMIIREG, ifr) >= 0)
|
||||
val = mii->val_out;
|
||||
nm_ioctl_info ("%s: Done with GET MIIREG\n", iface);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -881,36 +890,34 @@ mdio_read (NMDevice8023Ethernet *self, NMSock *sk, struct ifreq *ifr, int locati
|
|||
static gboolean
|
||||
supports_mii_carrier_detect (NMDevice8023Ethernet *self)
|
||||
{
|
||||
NMSock * sk;
|
||||
struct ifreq ifr;
|
||||
int bmsr;
|
||||
gboolean supports_mii = FALSE;
|
||||
int err;
|
||||
const char * iface;
|
||||
int err, fd, bmsr;
|
||||
struct ifreq ifr;
|
||||
gboolean supports_mii = FALSE;
|
||||
const char *iface;
|
||||
size_t len;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_GENERAL, __FUNCTION__, NULL)) == NULL)
|
||||
{
|
||||
nm_warning ("cannot open socket on interface %s for MII detect; errno=%d",
|
||||
iface, errno);
|
||||
return FALSE;
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1);
|
||||
nm_ioctl_info ("%s: About to GET MIIPHY\n", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIPHY, &ifr);
|
||||
nm_ioctl_info ("%s: Done with GET MIIPHY\n", iface);
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
|
||||
memset (&ifr, 0, sizeof (struct ifreq));
|
||||
strncpy (ifr.ifr_name, iface, len);
|
||||
|
||||
err = ioctl (fd, SIOCGMIIPHY, &ifr);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
|
||||
/* If we can read the BMSR register, we assume that the card supports MII link detection */
|
||||
bmsr = mdio_read (self, sk, &ifr, MII_BMSR);
|
||||
bmsr = mdio_read (self, fd, &ifr, MII_BMSR);
|
||||
supports_mii = (bmsr != -1) ? TRUE : FALSE;
|
||||
|
||||
out:
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
return supports_mii;
|
||||
}
|
||||
|
|
|
@ -191,23 +191,25 @@ error:
|
|||
static gboolean
|
||||
real_is_up (NMDevice *self)
|
||||
{
|
||||
NMSock * sk;
|
||||
struct ifreq ifr;
|
||||
int err;
|
||||
struct ifreq ifr;
|
||||
const char *iface;
|
||||
int err, fd;
|
||||
size_t len;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_GENERAL, __FUNCTION__, NULL)) == NULL)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Get device's flags */
|
||||
strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1);
|
||||
iface = nm_device_get_iface (self);
|
||||
len = MIN (sizeof (ifr.ifr_name) - 1, strlen (iface));
|
||||
strncpy (ifr.ifr_name, iface, len);
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IFFLAGS.", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFFLAGS, &ifr);
|
||||
nm_ioctl_info ("%s: Done with GET IFFLAGS.", iface);
|
||||
err = ioctl (fd, SIOCGIFFLAGS, &ifr);
|
||||
close (fd);
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
if (!err)
|
||||
return (!((ifr.ifr_flags^IFF_UP) & IFF_UP));
|
||||
|
||||
|
@ -1469,28 +1471,29 @@ nm_device_get_ip4_address (NMDevice *self)
|
|||
void
|
||||
nm_device_update_ip4_address (NMDevice *self)
|
||||
{
|
||||
guint32 new_address;
|
||||
struct ifreq req;
|
||||
NMSock * sk;
|
||||
int err;
|
||||
const char * iface;
|
||||
struct ifreq req;
|
||||
const char *iface;
|
||||
guint32 new_address;
|
||||
int fd, err;
|
||||
size_t len;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
g_return_if_fail (iface != NULL);
|
||||
|
||||
if ((sk = nm_dev_sock_open (iface, DEV_GENERAL, __func__, NULL)) == NULL)
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
nm_warning ("couldn't open control socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
len = MIN (sizeof (req.ifr_name) - 1, strlen (iface));
|
||||
|
||||
memset (&req, 0, sizeof (struct ifreq));
|
||||
strncpy (req.ifr_name, iface, sizeof (req.ifr_name) - 1);
|
||||
strncpy (req.ifr_name, iface, len);
|
||||
|
||||
nm_ioctl_info ("%s: About to GET IFADDR.", iface);
|
||||
err = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFADDR, &req);
|
||||
nm_ioctl_info ("%s: Done with GET IFADDR.", iface);
|
||||
err = ioctl (fd, SIOCGIFADDR, &req);
|
||||
|
||||
nm_dev_sock_close (sk);
|
||||
close (fd);
|
||||
if (err != 0)
|
||||
return;
|
||||
|
||||
|
@ -1511,24 +1514,11 @@ nm_device_is_up (NMDevice *self)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* I really wish nm_v_wait_for_completion_or_timeout could translate these
|
||||
* to first class args instead of a all this void * arg stuff, so these
|
||||
* helpers could be nice and _tiny_. */
|
||||
static gboolean
|
||||
nm_completion_device_is_up_test (int tries,
|
||||
nm_completion_args args)
|
||||
{
|
||||
NMDevice *self = NM_DEVICE (args[0]);
|
||||
|
||||
if (nm_device_is_up (self))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_bring_up (NMDevice *self, gboolean wait)
|
||||
{
|
||||
gboolean success;
|
||||
guint32 tries = 0;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
|
||||
|
||||
|
@ -1547,12 +1537,9 @@ nm_device_bring_up (NMDevice *self, gboolean wait)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (wait) {
|
||||
nm_completion_args args;
|
||||
|
||||
args[0] = self;
|
||||
nm_wait_for_completion (400, G_USEC_PER_SEC / 200, NULL, nm_completion_device_is_up_test, args);
|
||||
}
|
||||
/* Wait for the device to come up if requested */
|
||||
while (wait && !nm_device_is_up (self) && (tries++ < 50))
|
||||
g_usleep (200);
|
||||
|
||||
nm_device_state_changed (self, NM_DEVICE_STATE_DISCONNECTED);
|
||||
|
||||
|
@ -1563,6 +1550,7 @@ void
|
|||
nm_device_bring_down (NMDevice *self, gboolean wait)
|
||||
{
|
||||
NMDeviceState state;
|
||||
guint32 tries = 0;
|
||||
|
||||
g_return_if_fail (NM_IS_DEVICE (self));
|
||||
|
||||
|
@ -1580,12 +1568,9 @@ nm_device_bring_down (NMDevice *self, gboolean wait)
|
|||
|
||||
nm_system_device_set_up_down (self, FALSE);
|
||||
|
||||
if (wait) {
|
||||
nm_completion_args args;
|
||||
|
||||
args[0] = self;
|
||||
nm_wait_for_completion (400, G_USEC_PER_SEC / 200, NULL, nm_completion_device_is_up_test, args);
|
||||
}
|
||||
/* Wait for the device to come up if requested */
|
||||
while (wait && nm_device_is_up (self) && (tries++ < 50))
|
||||
g_usleep (200);
|
||||
|
||||
nm_device_state_changed (self, NM_DEVICE_STATE_DOWN);
|
||||
}
|
||||
|
|
|
@ -31,19 +31,6 @@
|
|||
#include "nm-ip4-config.h"
|
||||
#include "nm-connection.h"
|
||||
|
||||
#if 0
|
||||
# define IOCTL_DEBUG 1
|
||||
#endif
|
||||
|
||||
#ifdef IOCTL_DEBUG
|
||||
# define nm_ioctl_info(fmt, args...) \
|
||||
G_STMT_START { \
|
||||
g_message ("<information>\t" fmt "\n", ##args); \
|
||||
} G_STMT_END
|
||||
#else
|
||||
# define nm_ioctl_info(fmt, args...) do { } while(0)
|
||||
#endif
|
||||
|
||||
typedef enum NMActStageReturn
|
||||
{
|
||||
NM_ACT_STAGE_RETURN_FAILURE = 0,
|
||||
|
|
Loading…
Reference in a new issue