|
IBR-DTNSuite 0.6
|
00001 /* 00002 * NetLinkManager.h 00003 * 00004 * Created on: 21.12.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef NETLINKMANAGER_H_ 00009 #define NETLINKMANAGER_H_ 00010 00011 #include "ibrcommon/net/LinkManager.h" 00012 #include "ibrcommon/net/vsocket.h" 00013 #include "ibrcommon/net/vinterface.h" 00014 #include "ibrcommon/thread/Mutex.h" 00015 #include "ibrcommon/thread/Conditional.h" 00016 #include "ibrcommon/thread/Thread.h" 00017 00018 //#include <netinet/in.h> 00019 #include <netlink/netlink.h> 00020 #include <netlink/attr.h> 00021 00022 #include <map> 00023 #include <set> 00024 00025 namespace ibrcommon 00026 { 00027 class NetLinkManagerEvent : public LinkManagerEvent 00028 { 00029 public: 00030 NetLinkManagerEvent(int fd); 00031 virtual ~NetLinkManagerEvent(); 00032 00033 virtual const ibrcommon::vinterface& getInterface() const; 00034 virtual const ibrcommon::vaddress& getAddress() const; 00035 virtual unsigned int getState() const; 00036 virtual EventType getType() const; 00037 00038 virtual bool isWirelessExtension() const; 00039 00040 void debug() const; 00041 const std::string toString() const; 00042 00043 private: 00044 EventType _type; 00045 unsigned int _state; 00046 bool _wireless; 00047 ibrcommon::vinterface _interface; 00048 ibrcommon::vaddress _address; 00049 std::map<int, std::string> _attributes; 00050 }; 00051 00052 class NetLinkManager : public ibrcommon::LinkManager, public ibrcommon::JoinableThread 00053 { 00054 friend class LinkManager; 00055 00056 public: 00057 virtual ~NetLinkManager(); 00058 00059 const std::string getInterface(int index) const; 00060 const std::list<vaddress> getAddressList(const vinterface &iface, const vaddress::Family f); 00061 00062 void registerInterfaceEvent(const vinterface &iface, LinkManager::EventCallback*); 00063 void unregisterInterfaceEvent(const vinterface &iface, LinkManager::EventCallback*); 00064 void unregisterAllEvents(LinkManager::EventCallback *cb); 00065 00066 class parse_exception : public Exception 00067 { 00068 public: 00069 parse_exception(string error) : Exception(error) 00070 {}; 00071 }; 00072 00073 protected: 00074 void run(); 00075 bool __cancellation(); 00076 00077 private: 00078 NetLinkManager(); 00079 00080 std::map<int, std::string> read_nlmsg(int fd); 00081 00082 ibrcommon::Mutex _call_mutex; 00083 00084 struct nl_handle *_handle; 00085 struct nl_cache *_link_cache; 00086 struct nl_cache *_addr_cache; 00087 00088 bool _initialized; 00089 ibrcommon::vsocket *_sock; 00090 00091 ibrcommon::Mutex _listener_mutex; 00092 std::map<vinterface, std::set<LinkManager::EventCallback* > > _listener; 00093 00094 bool _refresh_cache; 00095 }; 00096 } 00097 00098 #endif /* NETLINKMANAGER_H_ */