This email list is read-only. Emails sent to this list will be discarded
----------------------------------
configure.ac | 4 +-
include/rtnl.h | 24 ++++++++
plugins/ethernet.c | 156 +++++----------------------------------------------
plugins/rtnllink.c | 120 ++++++++++++++++++++++++++++++++++++++++
src/rtnl.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 305 insertions(+), 145 deletions(-)
New commits:
commit 61d0b6297c0f8e96a5ce79d03009a2d436e742f4
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 15:12:01 2008 +0200
Add really simple RTNL device detection support
commit 86629ba675d53064d536f0516b32b09efdef8305
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:59:04 2008 +0200
Increase message buffer size
commit ad74ad47566ed5565744d91e0f090b3c4d662c90
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:53:50 2008 +0200
Fix spelling mistake of debug message
commit 1eea67f44015142e6634e2b89593b0d587df864e
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:41:46 2008 +0200
Add option to enable/disable HAL plugin
commit 4c171836e1a1001d4ba7f1364c50f3f44622d9c9
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:34:00 2008 +0200
Disable link attribute parsing for now
commit 29132f772f4ee73ebb6ae2610a36c83db2824c6b
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:32:35 2008 +0200
Add debug message to RTNL callback
commit 804fc546f7da86a88979373802df9653dc6959d6
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:29:17 2008 +0200
Fix return value of getlink function
commit 629ec10165691a7c5f9a7dfe3859644c280654c9
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:26:30 2008 +0200
Remove link_flags callback
commit a69968d931fee36826442a5af7e8286f3287133c
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:20:40 2008 +0200
Add skeleton for RTNL framework callbacks
commit 773ce270c27a7b9b14c93e19b7f261c12e6126ef
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:18:13 2008 +0200
Use RTNL newlink callback for link changes
commit 6d8e8898bd6b68dc07305b0e2b1d3e007fa37dfd
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 14:15:21 2008 +0200
Add support for newlink and dellink callbacks
commit b6997d2f97406ca50ad536be16e09bb68dbd1ed4
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 13:59:51 2008 +0200
Make use of the RTNL framework
commit b389f8d373c2d8f5c636d40ec020e5e2adf0f01c
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 13:57:41 2008 +0200
Add function for requesting link status
commit 9427977bb5efee031b5001bd943c0efd8aa39276
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 13:56:31 2008 +0200
The interface flags are from type short
commit d953423c66367ee7d9b2429914257286b48c3b79
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 13:48:57 2008 +0200
Fix forgotten index parameter
commit 31d8cfc6648686d832b2df63e3bb68bf23f45762
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date: Tue Oct 14 13:44:13 2008 +0200
Add generic RTNL framework
Diff in this email is a maximum of 400 lines.
diff --git a/configure.ac b/configure.ac
index 5857197..1d438b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,9 @@ AC_SUBST([GDBUS_LIBS], ['$(top_builddir)/gdbus/libgdbus.la
$(DBUS_LIBS)'])
PKG_CHECK_MODULES(HAL, hal >= 0.5.8, hal_found=yes, hal_found=no)
AC_SUBST(HAL_CFLAGS)
AC_SUBST(HAL_LIBS)
-AM_CONDITIONAL(HAL, test "${hal_found}" = "yes")
+AC_ARG_ENABLE(hal, AC_HELP_STRING([--enable-hal],
+ [enable HAL plugin]), [enable_hal=${enableval}])
+AM_CONDITIONAL(HAL, test "${enable_hal}" = "yes" && test "${hal_found}" =
"yes")
PKG_CHECK_MODULES(POLKIT, polkit-dbus >= 0.7, polkit_found=yes,
polkit_found=no)
AC_SUBST(POLKIT_CFLAGS)
diff --git a/include/rtnl.h b/include/rtnl.h
index f167a16..395d20b 100644
--- a/include/rtnl.h
+++ b/include/rtnl.h
@@ -26,6 +26,30 @@
extern "C" {
#endif
+/**
+ * SECTION:rtnl
+ * @title: RTNL premitives
+ * @short_description: Functions for registering RTNL modules
+ */
+
+#define CONNMAN_RTNL_PRIORITY_LOW -100
+#define CONNMAN_RTNL_PRIORITY_DEFAULT 0
+#define CONNMAN_RTNL_PRIORITY_HIGH 100
+
+struct connman_rtnl {
+ const char *name;
+ int priority;
+ void (*newlink) (unsigned short type, int index,
+ unsigned flags, unsigned change);
+ void (*dellink) (unsigned short type, int index,
+ unsigned flags, unsigned change);
+};
+
+extern int connman_rtnl_register(struct connman_rtnl *rtnl);
+extern void connman_rtnl_unregister(struct connman_rtnl *rtnl);
+
+int connman_rtnl_send_getlink(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index b05c78b..fb8afb4 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -33,27 +33,23 @@
#include <connman/plugin.h>
#include <connman/driver.h>
+#include <connman/rtnl.h>
#include <connman/log.h>
struct ethernet_data {
int index;
- short flags;
+ unsigned flags;
};
static GStaticMutex ethernet_mutex = G_STATIC_MUTEX_INIT;
static GSList *ethernet_list = NULL;
-static void rtnl_link(struct nlmsghdr *hdr, const char *type)
+static void ethernet_newlink(unsigned short type, int index,
+ unsigned flags, unsigned change)
{
GSList *list;
- struct ifinfomsg *msg;
- int bytes;
- msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
- bytes = IFLA_PAYLOAD(hdr);
-
- DBG("%s ifi_index %d ifi_flags 0x%04x",
- type, msg->ifi_index, msg->ifi_flags);
+ DBG("index %d flags %ld change %ld", index, flags, change);
g_static_mutex_lock(ðernet_mutex);
@@ -66,14 +62,13 @@ static void rtnl_link(struct nlmsghdr *hdr, const char
*type)
if (ethernet == NULL)
continue;
- if (ethernet->index != msg->ifi_index)
+ if (ethernet->index != index)
continue;
- if ((ethernet->flags & IFF_RUNNING) ==
- (msg->ifi_flags & IFF_RUNNING))
+ if ((ethernet->flags & IFF_RUNNING) == (flags & IFF_RUNNING))
continue;
- ethernet->flags = msg->ifi_flags;
+ ethernet->flags = flags;
if (ethernet->flags & IFF_RUNNING) {
DBG("carrier on");
@@ -96,91 +91,10 @@ static void rtnl_link(struct nlmsghdr *hdr, const char
*type)
g_static_mutex_unlock(ðernet_mutex);
}
-static gboolean rtnl_event(GIOChannel *chan, GIOCondition cond, gpointer data)
-{
- unsigned char buf[1024];
- void *ptr = buf;
- gsize len;
- GIOError err;
-
- if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
- return FALSE;
-
- memset(buf, 0, sizeof(buf));
-
- err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
- if (err) {
- if (err == G_IO_ERROR_AGAIN)
- return TRUE;
- return FALSE;
- }
-
- DBG("buf %p len %zd", buf, len);
-
- while (len > 0) {
- struct nlmsghdr *hdr = ptr;
- struct nlmsgerr *err;
-
- if (!NLMSG_OK(hdr, len))
- break;
-
- DBG("len %d type %d flags 0x%04x seq %d",
- hdr->nlmsg_len, hdr->nlmsg_type,
- hdr->nlmsg_flags, hdr->nlmsg_seq);
-
- switch (hdr->nlmsg_type) {
- case NLMSG_ERROR:
- err = NLMSG_DATA(hdr);
- DBG("ERROR %d (%s)", -err->error,
- strerror(-err->error));
- break;
-
- case RTM_NEWLINK:
- rtnl_link(hdr, "NEWLINK");
- break;
-
- case RTM_DELLINK:
- rtnl_link(hdr, "DELLINK");
- break;
- }
-
- len -= hdr->nlmsg_len;
- ptr += hdr->nlmsg_len;
- }
-
- return TRUE;
-}
-
-static GIOChannel *channel;
-
-static int rtnl_request(void)
-{
- struct {
- struct nlmsghdr hdr;
- struct rtgenmsg msg;
- } req;
-
- struct sockaddr_nl addr;
- int sk;
-
- DBG("");
-
- memset(&req, 0, sizeof(req));
- req.hdr.nlmsg_len = sizeof(req.hdr) + sizeof(req.msg);
- req.hdr.nlmsg_type = RTM_GETLINK;
- req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
- req.hdr.nlmsg_pid = 0;
- req.hdr.nlmsg_seq = 42;
- req.msg.rtgen_family = AF_INET;
-
- sk = g_io_channel_unix_get_fd(channel);
-
- memset(&addr, 0, sizeof(addr));
- addr.nl_family = AF_NETLINK;
-
- return sendto(sk, &req, sizeof(req), 0,
- (struct sockaddr *) &addr, sizeof(addr));
-}
+static struct connman_rtnl ethernet_rtnl = {
+ .name = "ethernet",
+ .newlink = ethernet_newlink,
+};
static int iface_up(struct ethernet_data *ethernet)
{
@@ -288,7 +202,7 @@ static int ethernet_probe(struct connman_element *element)
iface_up(ethernet);
- rtnl_request();
+ connman_rtnl_send_getlink();
return 0;
}
@@ -318,55 +232,17 @@ static struct connman_driver ethernet_driver = {
.remove = ethernet_remove,
};
-static int rtnl_init(void)
-{
- struct sockaddr_nl addr;
- int sk, err;
-
- DBG("");
-
- sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
- if (sk < 0)
- return -errno;
-
- memset(&addr, 0, sizeof(addr));
- addr.nl_family = AF_NETLINK;
- addr.nl_groups = RTMGRP_LINK;
-
- if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- err = -errno;
- close(sk);
- return err;
- }
-
- channel = g_io_channel_unix_new(sk);
- g_io_channel_set_close_on_unref(channel, TRUE);
-
- g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
- rtnl_event, NULL);
-
- return 0;
-}
-
-static void rtnl_cleanup(void)
-{
- DBG("");
-
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
-}
-
static int ethernet_init(void)
{
int err;
- err = rtnl_init();
+ err = connman_rtnl_register(ðernet_rtnl);
if (err < 0)
return err;
err = connman_driver_register(ðernet_driver);
if (err < 0) {
- rtnl_cleanup();
+ connman_rtnl_unregister(ðernet_rtnl);
return err;
}
@@ -377,7 +253,7 @@ static void ethernet_exit(void)
{
connman_driver_unregister(ðernet_driver);
- rtnl_cleanup();
+ connman_rtnl_unregister(ðernet_rtnl);
}
CONNMAN_PLUGIN_DEFINE("ethernet", "Ethernet interface plugin", VERSION,
diff --git a/plugins/rtnllink.c b/plugins/rtnllink.c
index 07f969e..abe6811 100644
--- a/plugins/rtnllink.c
+++ b/plugins/rtnllink.c
@@ -25,15 +25,135 @@
#include <connman/plugin.h>
#include <connman/element.h>
+#include <connman/rtnl.h>
#include <connman/log.h>
+#include "inet.h"
+
+static GStaticMutex device_mutex = G_STATIC_MUTEX_INIT;
+static GSList *device_list = NULL;
+
+static void rtnllink_newlink(unsigned short type, int index,
+ unsigned flags, unsigned change)
+{
+ struct connman_element *device;
+ enum connman_element_subtype subtype;
+ GSList *list;
+ gboolean exists = FALSE;
+ gchar *name;
+
+ DBG("index %d", index);
+
+ g_static_mutex_lock(&device_mutex);
+
+ for (list = device_list; list; list = list->next) {
+ struct connman_element *device = list->data;
+
+ if (device->index == index) {
+ exists = TRUE;
+ break;
+ }
+ }
+
+ g_static_mutex_unlock(&device_mutex);
+
+ if (exists == TRUE)
+ return;
+
+ name = inet_index2name(index);
+
+ if (g_str_has_prefix(name, "eth") == TRUE)
+ subtype = CONNMAN_ELEMENT_SUBTYPE_ETHERNET;
+ else if (g_str_has_prefix(name, "wlan") == TRUE)
+ subtype = CONNMAN_ELEMENT_SUBTYPE_WIFI;
+ else if (g_str_has_prefix(name, "wmx") == TRUE)
+ subtype = CONNMAN_ELEMENT_SUBTYPE_WIMAX;
+ else if (g_str_has_prefix(name, "bnep") == TRUE)
+ subtype = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH;
+ else
+ subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN;
+
+ if (subtype == CONNMAN_ELEMENT_SUBTYPE_UNKNOWN) {
+ g_free(name);
+ return;
+ }
+
+ device = connman_element_create(NULL);
+ device->type = CONNMAN_ELEMENT_TYPE_DEVICE;
+ device->subtype = subtype;
+
+ device->index = index;
+ device->name = name;
+
+ g_static_mutex_lock(&device_mutex);
+
+ connman_element_register(device, NULL);
+ device_list = g_slist_append(device_list, device);
+
+ g_static_mutex_unlock(&device_mutex);
+}
+
+static void rtnllink_dellink(unsigned short type, int index,
+ unsigned flags, unsigned change)
+{
+ GSList *list;
+
+ DBG("index %d", index);
+
+ g_static_mutex_lock(&device_mutex);
+
+ for (list = device_list; list; list = list->next) {
+ struct connman_element *device = list->data;
+
+ if (device->index == index) {
+ device_list = g_slist_remove(device_list, device);
+ connman_element_unregister(device);
+ connman_element_unref(device);
+ break;
+ }
+ }
+
+ g_static_mutex_unlock(&device_mutex);
+}
+
+static struct connman_rtnl rtnllink_rtnl = {
+ .name = "rtnllink",
+ .newlink = rtnllink_newlink,
+ .dellink = rtnllink_dellink,
+};
+
static int rtnllink_init(void)
{
+ int err;
+
+ err = connman_rtnl_register(&rtnllink_rtnl);
+ if (err < 0)
+ return err;
+
+ connman_rtnl_send_getlink();
+
return 0;
}
static void rtnllink_exit(void)
{
+ GSList *list;
+
+ connman_rtnl_unregister(&rtnllink_rtnl);
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits