From 57bb91f7f0f527732615f94208a25e3a29dba6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 10 May 2012 15:40:48 +0200 Subject: [PATCH] ifnet: handle 'biosdevname' interface names better (bgo #674765) (lp:962587) Finding out interface type from interface name string is fragile. It is easily broken, e.g. by biosdevname changing interface names to em or p*p. Sadly, Gentoo network configuration scripts are rather stupid, using format: variable_${interface|mac|essid|apmac}. http://www.gentoo.org/doc/en/handbook/2007.0/handbook-x86.xml?full=1#book_part4_chap2 The entries interface|mac|essid|apmac are basically indistinguishable. It's not possible to say whether 'p1p1' is an interface or SSID, for example. Fix the current behaviour a bit by checking whether the string is an interface. If so, and it is not a Wi-Fi one, set the connection type as wired. Else it is regarded as wireless. --- src/settings/plugins/ifnet/Makefile.am | 2 ++ src/settings/plugins/ifnet/net_parser.c | 33 ++++++++++++++++++-- src/settings/plugins/ifnet/tests/Makefile.am | 3 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index 84deda5b33..07a2fc8852 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -1,5 +1,6 @@ SUBDIRS = . tests INCLUDES = \ + -I$(top_srcdir)/src/wifi \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-glib \ @@ -52,6 +53,7 @@ lib_ifnet_io_la_CPPFLAGS = \ -DSBINDIR=\"$(sbindir)\" lib_ifnet_io_la_LIBADD = \ + $(top_builddir)/src/wifi/libwifi-utils.la \ $(top_builddir)/libnm-util/libnm-util.la \ $(GLIB_LIBS)\ $(GIO_LIBS) diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index 66caa74631..2562e61331 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -22,7 +22,14 @@ #include #include #include + +#include +#include +#include + #include "plugin.h" +#include "wifi-utils.h" + #include "net_parser.h" #include "net_utils.h" @@ -122,6 +129,24 @@ is_global_setting (char *key) return 0; } +/* Find out whether the 'iface' is an interface */ +static gboolean +name_is_interface (const char *iface) +{ + int fd; + struct ifreq ifr; + gboolean is_iface = FALSE; + + fd = socket (PF_INET, SOCK_DGRAM, 0); + if (fd >= 0) { + strncpy (ifr.ifr_name, iface, IFNAMSIZ); + if (ioctl (fd, SIOCGIFHWADDR, &ifr) == 0) + is_iface = TRUE; + close (fd); + } + return is_iface; +} + /* Parse a complete line */ /* Connection type is determined here */ static void @@ -166,8 +191,12 @@ init_block_by_line (gchar * buf) /* ignored connection */ conn = add_new_connection_config ("ignore", pos); } else - /* wireless connection */ - conn = add_new_connection_config ("wireless", pos); + if (name_is_interface (pos) && !wifi_utils_is_wifi (pos, NULL)) + /* wired connection */ + conn = add_new_connection_config ("wired", pos); + else + /* wireless connection */ + conn = add_new_connection_config ("wireless", pos); } data = g_strdup (key_value[1]); tmp = strip_string (data, '"'); diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 20a2680523..85d42388a5 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -10,7 +10,8 @@ check_ifnet_CPPFLAGS = $(CHECK_CFLAGS) $(GLIB_CFLAGS) check_ifnet_LDADD = $(top_builddir)/libnm-util/libnm-util.la \ $(builddir)/../lib-ifnet-io.la \ $(CHECK_LIBS) \ - $(GLIB_LIBS) + $(GLIB_LIBS) \ + $(LIBM) EXTRA_DIST = hostname \ net \ net.all \