#include "connman.h"
-static GStaticRWLock rtnl_lock = G_STATIC_RW_LOCK_INIT;
static GSList *rtnl_list = NULL;
static gint compare_priority(gconstpointer a, gconstpointer b)
{
DBG("rtnl %p name %s", rtnl, rtnl->name);
- g_static_rw_lock_writer_lock(&rtnl_lock);
-
rtnl_list = g_slist_insert_sorted(rtnl_list, rtnl,
compare_priority);
- g_static_rw_lock_writer_unlock(&rtnl_lock);
-
return 0;
}
{
DBG("rtnl %p name %s", rtnl, rtnl->name);
- g_static_rw_lock_writer_lock(&rtnl_lock);
-
rtnl_list = g_slist_remove(rtnl_list, rtnl);
-
- g_static_rw_lock_writer_unlock(&rtnl_lock);
}
-static void process_link_flags(int flags)
+static void process_newlink(unsigned short type, int index,
+ unsigned flags, unsigned change)
{
GSList *list;
- DBG("idex %d", index);
-
- g_static_rw_lock_reader_lock(&rtnl_lock);
+ DBG("index %d", index);
for (list = rtnl_list; list; list = list->next) {
struct connman_rtnl *rtnl = list->data;
- if (rtnl->link_flags)
- rtnl->link_flags(index, flags);
+ if (rtnl->newlink)
+ rtnl->newlink(type, index, flags, change);
}
+}
- g_static_rw_lock_reader_unlock(&rtnl_lock);
+static void process_dellink(unsigned short type, int index,
+ unsigned flags, unsigned change)
+{
+ GSList *list;
+
+ DBG("index %d", index);
+
+ for (list = rtnl_list; list; list = list->next) {
+ struct connman_rtnl *rtnl = list->data;
+
+ if (rtnl->dellink)
+ rtnl->dellink(type, index, flags, change);
+ }
}
static inline void print_inet(struct rtattr *attr, const char *name, int family)
static void rtnl_link(struct nlmsghdr *hdr)
{
+#if 0
struct ifinfomsg *msg;
struct rtattr *attr;
int bytes;
break;
}
}
+#endif
+}
+
+static void rtnl_newlink(struct nlmsghdr *hdr)
+{
+ struct ifinfomsg *msg;
+
+ msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
- process_link_flags(msg->ifi_flags);
+ DBG("ifi_index %d ifi_flags 0x%04x", msg->ifi_index, msg->ifi_flags);
+
+ process_newlink(msg->ifi_type, msg->ifi_index,
+ msg->ifi_flags, msg->ifi_change);
+
+ rtnl_link(hdr);
+}
+
+static void rtnl_dellink(struct nlmsghdr *hdr)
+{
+ struct ifinfomsg *msg;
+
+ msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+
+ DBG("ifi_index %d ifi_flags 0x%04x", msg->ifi_index, msg->ifi_flags);
+
+ process_dellink(msg->ifi_type, msg->ifi_index,
+ msg->ifi_flags, msg->ifi_change);
+
+ rtnl_link(hdr);
}
static void rtnl_addr(struct nlmsghdr *hdr)
return;
case RTM_NEWLINK:
DBG("NEWLINK");
- rtnl_link(hdr);
+ rtnl_newlink(hdr);
break;
case RTM_DELLINK:
DBG("DELLINK");
- rtnl_link(hdr);
+ rtnl_dellink(hdr);
break;
case RTM_NEWADDR:
DBG("NEWADDR");
static gboolean netlink_event(GIOChannel *chan,
GIOCondition cond, gpointer data)
{
- unsigned char buf[256];
+ unsigned char buf[4096];
gsize len;
GIOError err;
(struct sockaddr *) &addr, sizeof(addr));
}
+int connman_rtnl_send_getlink(void)
+{
+ struct {
+ struct nlmsghdr hdr;
+ struct rtgenmsg msg;
+ } req;
+
+ 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;
+
+ return __connman_rtnl_send(&req, sizeof(req));
+}
+
int __connman_rtnl_init(void)
{
struct sockaddr_nl addr;