IBR-DTNSuite
0.8
|
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 00024 namespace ibrcommon 00025 { 00026 class NetLinkManagerEvent : public LinkManagerEvent 00027 { 00028 public: 00029 NetLinkManagerEvent(int fd); 00030 virtual ~NetLinkManagerEvent(); 00031 00032 virtual const ibrcommon::vinterface& getInterface() const; 00033 virtual const ibrcommon::vaddress& getAddress() const; 00034 virtual unsigned int getState() const; 00035 virtual EventType getType() const; 00036 00037 virtual bool isWirelessExtension() const; 00038 00039 void debug() const; 00040 const std::string toString() const; 00041 00042 private: 00043 EventType _type; 00044 unsigned int _state; 00045 bool _wireless; 00046 ibrcommon::vinterface _interface; 00047 ibrcommon::vaddress _address; 00048 std::map<int, std::string> _attributes; 00049 }; 00050 00051 class NetLinkManager : public ibrcommon::LinkManager, public ibrcommon::JoinableThread 00052 { 00053 friend class LinkManager; 00054 00055 public: 00056 virtual ~NetLinkManager(); 00057 00058 const std::string getInterface(int index) const; 00059 const std::list<vaddress> getAddressList(const vinterface &iface, const vaddress::Family f); 00060 00061 class parse_exception : public Exception 00062 { 00063 public: 00064 parse_exception(string error) : Exception(error) 00065 {}; 00066 }; 00067 00068 protected: 00069 void run(); 00070 void __cancellation(); 00071 00072 private: 00073 NetLinkManager(); 00074 00075 std::map<int, std::string> read_nlmsg(int fd); 00076 00077 ibrcommon::Mutex _call_mutex; 00078 00079 struct nl_handle *_handle; 00080 struct nl_cache *_link_cache; 00081 struct nl_cache *_addr_cache; 00082 00083 bool _initialized; 00084 ibrcommon::vsocket *_sock; 00085 00086 bool _refresh_cache; 00087 }; 00088 } 00089 00090 #endif /* NETLINKMANAGER_H_ */