From 51818dc258152d9578c78219eb6fe32e5e94c84e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 9 Aug 2008 04:30:21 +0200 Subject: [PATCH] Add basics for a global RTNL engine --- include/Makefile.am | 4 ++-- src/Makefile.am | 2 +- src/main.c | 4 ++++ src/rtnl.c | 66 ++++------------------------------------------------- 4 files changed, 11 insertions(+), 65 deletions(-) diff --git a/include/Makefile.am b/include/Makefile.am index 70c39d2..1844d98 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,9 +1,9 @@ includedir = @includedir@/connman -include_HEADERS = log.h plugin.h driver.h element.h property.h dbus.h +include_HEADERS = log.h plugin.h driver.h element.h property.h rtnl.h dbus.h -noinst_HEADERS = iface.h rtnl.h dhcp.h resolver.h +noinst_HEADERS = iface.h dhcp.h resolver.h MAINTAINERCLEANFILES = Makefile.in diff --git a/src/Makefile.am b/src/Makefile.am index e4ad954..f959379 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ DISTCLEANFILES = $(service_DATA) sbin_PROGRAMS = connmand connmand_SOURCES = main.c connman.h log.c plugin.c profile.c element.c \ - storage.c manager.c agent.c + storage.c manager.c agent.c rtnl.c connmand_LDADD = @SQLITE_LIBS@ @GDBUS_LIBS@ @GMODULE_LIBS@ @GTHREAD_LIBS@ diff --git a/src/main.c b/src/main.c index 5f8b487..77dff01 100644 --- a/src/main.c +++ b/src/main.c @@ -146,6 +146,8 @@ int main(int argc, char *argv[]) __connman_profile_init(conn); + __connman_rtnl_init(); + __connman_plugin_init(); g_free(option_device); @@ -157,6 +159,8 @@ int main(int argc, char *argv[]) g_main_loop_run(main_loop); + __connman_rtnl_cleanup(); + __connman_agent_cleanup(); __connman_element_cleanup(); diff --git a/src/rtnl.c b/src/rtnl.c index f100c21..491f190 100644 --- a/src/rtnl.c +++ b/src/rtnl.c @@ -36,21 +36,6 @@ #include "connman.h" -struct rtnl_data { - unsigned ifi_flags; -}; - -static struct rtnl_data *get_rtnl_data(struct connman_iface *iface) -{ - if ((iface->flags & CONNMAN_IFACE_FLAG_RTNL) == 0) - return NULL; - - if (iface->rtnl_data == NULL) - iface->rtnl_data = g_try_new0(struct rtnl_data, 1); - - return iface->rtnl_data; -} - static inline void print_inet(struct rtattr *attr, const char *name, int family) { if (family == AF_INET) { @@ -85,8 +70,6 @@ static inline void print_attr(struct rtattr *attr, const char *name) static void rtnl_link(struct nlmsghdr *hdr) { - struct connman_iface *iface; - struct rtnl_data *data; struct ifinfomsg *msg; struct rtattr *attr; int bytes; @@ -96,34 +79,6 @@ static void rtnl_link(struct nlmsghdr *hdr) DBG("ifi_index %d ifi_flags 0x%04x", msg->ifi_index, msg->ifi_flags); - iface = __connman_iface_find(msg->ifi_index); - if (iface == NULL) - return; - - data = get_rtnl_data(iface); - if (data == NULL) - return; - - if ((data->ifi_flags & IFF_RUNNING) != (msg->ifi_flags & IFF_RUNNING)) { - if (!(iface->flags & CONNMAN_IFACE_FLAG_NOCARRIER)) { - if (msg->ifi_flags & IFF_RUNNING) - connman_iface_indicate_carrier_on(iface); - else - connman_iface_indicate_carrier_off(iface); - } - } - - if ((data->ifi_flags & IFF_UP) != (msg->ifi_flags & IFF_UP)) { - if (msg->ifi_flags & IFF_UP) - connman_iface_indicate_ifup(iface); - else - connman_iface_indicate_ifdown(iface); - } - - data->ifi_flags = msg->ifi_flags; - - return; - for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes); attr = RTA_NEXT(attr, bytes)) { switch (attr->rta_type) { @@ -158,9 +113,7 @@ static void rtnl_link(struct nlmsghdr *hdr) print_attr(attr, "master"); break; case IFLA_WIRELESS: - if (iface->driver->rtnl_wireless) - iface->driver->rtnl_wireless(iface, - RTA_DATA(attr), RTA_PAYLOAD(attr)); + print_attr(attr, "wireless"); break; case IFLA_PROTINFO: print_attr(attr, "protinfo"); @@ -189,8 +142,6 @@ static void rtnl_link(struct nlmsghdr *hdr) static void rtnl_addr(struct nlmsghdr *hdr) { - struct connman_iface *iface; - struct rtnl_data *data; struct ifaddrmsg *msg; struct rtattr *attr; int bytes; @@ -200,14 +151,6 @@ static void rtnl_addr(struct nlmsghdr *hdr) DBG("ifa_family %d ifa_index %d", msg->ifa_family, msg->ifa_index); - iface = __connman_iface_find(msg->ifa_index); - if (iface == NULL) - return; - - data = get_rtnl_data(iface); - if (data == NULL) - return; - for (attr = IFA_RTA(msg); RTA_OK(attr, bytes); attr = RTA_NEXT(attr, bytes)) { switch (attr->rta_type) { @@ -406,7 +349,7 @@ int __connman_rtnl_init(void) memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; - addr.nl_groups = RTMGRP_LINK; + //addr.nl_groups = RTMGRP_LINK; //addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR; //addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE; @@ -418,9 +361,8 @@ int __connman_rtnl_init(void) 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, - netlink_event, NULL); + g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR, + netlink_event, NULL); return 0; } -- 2.7.4