Cleanup of API dependencies
authorHenning Rogge <hrogge@googlemail.com>
Sat, 4 May 2013 12:56:33 +0000 (14:56 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Sat, 4 May 2013 12:56:33 +0000 (14:56 +0200)
15 files changed:
src-api/core/olsr_clock.c
src-api/core/olsr_interface.c
src-api/core/olsr_interface.h
src-api/core/olsr_packet_socket.c
src-api/core/olsr_packet_socket.h
src-api/core/olsr_timer.c
src-api/core/os_linux/os_net_linux.h
src-api/core/os_linux/os_system_linux.c
src-api/core/os_linux/os_system_linux.h
src-api/core/os_net.h
src-api/core/os_system.h
src-api/tools/olsr_http.c
src-api/tools/olsr_logging_cfg.c
src-api/tools/olsr_rfc5444.c
src-api/tools/olsr_telnet.c

index f327e71..c8f2fcc 100644 (file)
 #include "config/cfg_schema.h"
 #include "config/cfg.h"
 
-#include "core/os_clock.h"
-#include "core/olsr_logging.h"
 #include "core/olsr_clock.h"
+#include "core/olsr_logging.h"
 #include "core/olsr_subsystem.h"
+#include "core/os_clock.h"
 
 /* prototypes */
 static int _init(void);
index 240a63b..07eaf14 100644 (file)
@@ -83,6 +83,10 @@ static struct olsr_timer_info _change_timer_info = {
   .callback = _cb_change_handler,
 };
 
+static struct os_system_if_listener _iflistener = {
+  .if_changed = olsr_interface_trigger_change,
+};
+
 /**
  * Initialize interface subsystem
  * @return always returns 0
@@ -93,6 +97,8 @@ _init(void) {
 
   avl_init(&olsr_interface_tree, avl_comp_strcasecmp, false);
   list_init_head(&_interface_listener);
+
+  os_system_iflistener_add(&_iflistener);
   return 0;
 }
 
@@ -107,6 +113,7 @@ _cleanup(void) {
     olsr_interface_remove_listener(listener);
   }
 
+  os_system_iflistener_remove(&_iflistener);
   olsr_timer_remove(&_change_timer_info);
 }
 
index 866d819..dea4a68 100644 (file)
 #include "common/netaddr.h"
 
 #include "core/olsr_timer.h"
-
-struct olsr_interface_data {
-  /* Interface addresses with mesh-wide scope (at least) */
-  struct netaddr *if_v4, *if_v6;
-
-  /* IPv6 Interface address with global scope */
-  struct netaddr *linklocal_v6_ptr;
-
-  /* mac address of interface */
-  struct netaddr mac;
-
-  /* list of all addresses of the interface */
-  struct netaddr *addresses;
-  size_t addrcount;
-
-  /* interface name */
-  char name[IF_NAMESIZE];
-
-  /* interface index */
-  unsigned index;
-
-  /* true if the interface exists and is up */
-  bool up;
-};
+#include "core/os_net.h"
 
 struct olsr_interface {
   /* data of interface */
index cf0b435..237c5ca 100644 (file)
@@ -49,6 +49,8 @@
 #include "core/os_net.h"
 #include "core/olsr_logging.h"
 #include "core/olsr_packet_socket.h"
+#include "core/olsr_interface.h"
+#include "core/olsr_socket.h"
 #include "core/olsr_subsystem.h"
 
 /* prototypes */
index ef5d770..5ef4528 100644 (file)
@@ -46,8 +46,8 @@
 #include "common/list.h"
 #include "common/autobuf.h"
 #include "common/netaddr.h"
-#include "core/olsr_interface.h"
 #include "common/netaddr_acl.h"
+#include "core/olsr_interface.h"
 #include "core/olsr_socket.h"
 
 #ifndef _WIN32
index fcdde83..9df5f7b 100644 (file)
@@ -48,7 +48,6 @@
 #include "common/common_types.h"
 #include "core/olsr_clock.h"
 #include "core/olsr_logging.h"
-#include "core/olsr_class.h"
 #include "core/olsr_timer.h"
 #include "core/olsr_subsystem.h"
 
index a2985b9..7f2418a 100644 (file)
@@ -46,7 +46,7 @@
 #include <unistd.h>
 #include <ifaddrs.h>
 
-#include "core/olsr_interface.h"
+#include "core/os_net.h"
 
 /* name of the loopback interface */
 #define IF_LOOPBACK_NAME "lo"
index 7e78ccb..3ee82dd 100644 (file)
@@ -57,7 +57,6 @@
 
 #include "common/common_types.h"
 #include "common/string.h"
-#include "core/olsr_interface.h"
 #include "core/olsr_socket.h"
 #include "core/olsr_subsystem.h"
 #include "core/os_system.h"
@@ -133,6 +132,9 @@ const uint32_t _rtnetlink_mcast[] = {
   RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR
 };
 
+/* list of interface change listeners */
+struct list_entity _ifchange_listener;
+
 /* subsystem definition */
 struct oonf_subsystem oonf_os_system_subsystem = {
   .init = _init,
@@ -162,8 +164,9 @@ _init(void) {
     close(_ioctl_fd);
     return -1;
   }
-  olsr_timer_add(&_netlink_timer);
 
+  olsr_timer_add(&_netlink_timer);
+  list_init_head(&_ifchange_listener);
   return 0;
 }
 
@@ -220,6 +223,16 @@ os_system_set_interface_state(const char *dev, bool up) {
   return 0;
 }
 
+void
+os_system_iflistener_add(struct os_system_if_listener *listener) {
+  list_add_tail(&_ifchange_listener, &listener->_node);
+}
+
+void
+os_system_iflistener_remove(struct os_system_if_listener *listener) {
+  list_remove(&listener->_node);
+}
+
 /**
  * Open a new bidirectional netlink socket
  * @param nl pointer to initialized netlink socket handler
@@ -565,6 +578,7 @@ _handle_rtnetlink(struct nlmsghdr *hdr) {
   struct ifinfomsg *ifi;
   struct ifaddrmsg *ifa;
 
+  struct os_system_if_listener *listener;
   char if_name[IF_NAMESIZE];
 
   if (hdr->nlmsg_type == RTM_NEWLINK || hdr->nlmsg_type == RTM_DELLINK) {
@@ -577,7 +591,9 @@ _handle_rtnetlink(struct nlmsghdr *hdr) {
     }
 
     OLSR_DEBUG(LOG_OS_SYSTEM, "Linkstatus of interface '%s' changed", if_name);
-    olsr_interface_trigger_change(if_name, (ifi->ifi_flags & IFF_UP) == 0);
+    list_for_each_element(&_ifchange_listener, listener, _node) {
+      listener->if_changed(if_name, (ifi->ifi_flags & IFF_UP) == 0);
+    }
   }
 
   else if (hdr->nlmsg_type == RTM_NEWADDR || hdr->nlmsg_type == RTM_DELADDR) {
@@ -590,7 +606,9 @@ _handle_rtnetlink(struct nlmsghdr *hdr) {
     }
 
     OLSR_DEBUG(LOG_OS_SYSTEM, "Address of interface '%s' changed", if_name);
-    olsr_interface_trigger_change(if_name, false);
+    list_for_each_element(&_ifchange_listener, listener, _node) {
+      listener->if_changed(if_name, false);
+    }
   }
 }
 
index 9c59084..dcca783 100644 (file)
@@ -46,6 +46,7 @@
 
 #include "common/netaddr.h"
 #include "core/olsr_socket.h"
+#include "core/olsr_timer.h"
 
 struct os_system_netlink {
   struct olsr_socket_entry socket;
index ecb71f4..57b466a 100644 (file)
 #include "common/common_types.h"
 #include "common/netaddr.h"
 #include "core/olsr_logging.h"
-#include "core/olsr_interface.h"
+
+struct olsr_interface_data {
+  /* Interface addresses with mesh-wide scope (at least) */
+  struct netaddr *if_v4, *if_v6;
+
+  /* IPv6 Interface address with global scope */
+  struct netaddr *linklocal_v6_ptr;
+
+  /* mac address of interface */
+  struct netaddr mac;
+
+  /* list of all addresses of the interface */
+  struct netaddr *addresses;
+  size_t addrcount;
+
+  /* interface name */
+  char name[IF_NAMESIZE];
+
+  /* interface index */
+  unsigned index;
+
+  /* true if the interface exists and is up */
+  bool up;
+};
 
 /* pre-declare inlines */
 static INLINE int os_net_bindto_interface(int, struct olsr_interface_data *data);
index 2a22c2c..2bf1a59 100644 (file)
 #include <sys/time.h>
 
 #include "common/common_types.h"
+#include "common/list.h"
 #include "core/olsr_logging.h"
-#include "core/olsr_interface.h"
 
 #define MSEC_PER_SEC 1000
 #define USEC_PER_MSEC 1000
 
+struct os_system_if_listener {
+  void (*if_changed)(const char *ifname, bool up);
+
+  struct list_entity _node;
+};
+
 /* include os-specific headers */
 #if defined(__linux__)
 #include "core/os_linux/os_system_linux.h"
@@ -66,6 +72,8 @@
 EXPORT extern struct oonf_subsystem oonf_os_system_subsystem;
 
 /* prototypes for all os_system functions */
+EXPORT void os_system_iflistener_add(struct os_system_if_listener *);
+EXPORT void os_system_iflistener_remove(struct os_system_if_listener *);
 EXPORT int os_system_set_interface_state(const char *dev, bool up);
 
 #endif /* OS_SYSTEM_H_ */
index b4e4bf1..7d8619a 100644 (file)
 #include "common/common_types.h"
 #include "common/avl.h"
 #include "common/avl_comp.h"
+#include "common/netaddr.h"
+#include "common/netaddr_acl.h"
 
 #include "config/cfg_schema.h"
 
 #include "core/olsr_subsystem.h"
 #include "core/olsr_libdata.h"
 #include "core/olsr_logging.h"
-#include "common/netaddr_acl.h"
 #include "core/olsr_stream_socket.h"
 #include "core/os_clock.h"
 
index fe98ff1..9d88827 100644 (file)
@@ -50,7 +50,6 @@
 #include "config/cfg.h"
 
 #include "core/olsr_logging.h"
-#include "core/os_syslog.h"
 
 #include "tools/olsr_logging_cfg.h"
 #include "tools/olsr_cfg.h"
@@ -355,6 +354,6 @@ _apply_log_setting(struct cfg_named_section *named,
 static void
 _cb_logcfg_apply(void) {
   if (olsr_logcfg_apply(olsr_cfg_get_db())) {
-    os_syslog_log(LOG_SEVERITY_WARN, "Could not open logging file");
+    OLSR_WARN(LOG_MAIN, "Could not open logging file");
   }
 }
index baeea40..f50d471 100644 (file)
 #include "rfc5444/rfc5444_writer.h"
 #include "core/olsr_logging.h"
 #include "core/olsr_class.h"
+#include "core/olsr_packet_socket.h"
 #include "core/olsr_subsystem.h"
 #include "core/olsr_timer.h"
-#include "tools/olsr_cfg.h"
+#include "tools/olsr_duplicate_set.h"
 #include "tools/olsr_rfc5444.h"
 
 /* constants and definitions */
index 015c7c0..73d2561 100644 (file)
 #include "common/common_types.h"
 #include "common/avl.h"
 #include "common/avl_comp.h"
+#include "common/netaddr.h"
+#include "common/netaddr_acl.h"
 
 #include "config/cfg_schema.h"
 
 #include "core/olsr_logging.h"
 #include "core/olsr_class.h"
-#include "common/netaddr_acl.h"
 #include "core/olsr_plugins.h"
 #include "core/olsr_stream_socket.h"
 #include "core/olsr_timer.h"