From 6d8e8898bd6b68dc07305b0e2b1d3e007fa37dfd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 14 Oct 2008 14:15:21 +0200 Subject: [PATCH] Add support for newlink and dellink callbacks --- include/rtnl.h | 4 ++++ src/rtnl.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/include/rtnl.h b/include/rtnl.h index 42bd79a..3af6321 100644 --- a/include/rtnl.h +++ b/include/rtnl.h @@ -39,6 +39,10 @@ extern "C" { 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); void (*link_flags) (int index, short flags); }; diff --git a/src/rtnl.c b/src/rtnl.c index 1cc59b6..35fa54b 100644 --- a/src/rtnl.c +++ b/src/rtnl.c @@ -86,6 +86,44 @@ void connman_rtnl_unregister(struct connman_rtnl *rtnl) g_static_rw_lock_writer_unlock(&rtnl_lock); } +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); + + for (list = rtnl_list; list; list = list->next) { + struct connman_rtnl *rtnl = list->data; + + 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("idex %d", index); + + g_static_rw_lock_reader_lock(&rtnl_lock); + + for (list = rtnl_list; list; list = list->next) { + struct connman_rtnl *rtnl = list->data; + + if (rtnl->dellink) + rtnl->dellink(type, index, flags, change); + } + + g_static_rw_lock_reader_unlock(&rtnl_lock); +} + static void process_link_flags(int index, short flags) { GSList *list; @@ -210,6 +248,34 @@ static void rtnl_link(struct nlmsghdr *hdr) process_link_flags(msg->ifi_index, msg->ifi_flags); } +static void rtnl_newlink(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_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) { struct ifaddrmsg *msg; @@ -332,11 +398,11 @@ static void rtnl_message(void *buf, size_t len) 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"); -- 2.7.4