00001 #ifndef _TAPIFACE_H__
00002 #define _TAPIFACE_H__
00003
00004
00005 #include <fcntl.h>
00006 #include <sys/ioctl.h>
00007 #include <sys/socket.h>
00008 #include <sys/types.h>
00009 #include <string.h>
00010 #include <linux/if.h>
00011 #include <linux/if_tun.h>
00012 #include <unistd.h>
00013 #include <net/if_arp.h>
00014
00015 #include <gea/posix/UnixFdHandle.h>
00016 #include <gea/ObjRepository.h>
00017 #include <gea/API.h>
00018
00019 #include <awds/NodeId.h>
00020 #include <awds/routing.h>
00021 #include <awds/UnicastPacket.h>
00022 #include <awds/Flood.h>
00023
00024
00025 #define ADDR_TRNSLTR 0x04
00026 #define PROTO_NR 0x62
00027
00028 namespace awds {
00029
00030 class TapInterface {
00031
00032 public:
00033 int fd;
00034 char devname[IFNAMSIZ+1];
00035
00036 protected:
00037 gea::UnixFdHandle *tapHandle;
00038 Routing * const routing;
00039
00040 struct MacEntry {
00041 NodeId id;
00042 gea::AbsTime validity;
00043 };
00044
00045 typedef std::map<NodeId, struct MacEntry> MacTable;
00046 MacTable macTable;
00047 public:
00048
00049 TapInterface(Routing *routing);
00050
00051 bool init(const char*dev);
00052
00053 bool setIfaceMTU(int mtu);
00054 bool createDevice(const char *dev);
00055
00056 static void tap_recv(gea::Handle *h, gea::AbsTime t, void *data);
00057 static void recv_unicast ( BasePacket *p, void *data);
00058 static void recv_broadcast( BasePacket *p, void *data);
00059
00060 static void tap_sendcb(BasePacket &p, void *data, ssize_t len);
00061
00068 bool getNodeForMacAddress(const char* mac, NodeId& id, gea::AbsTime t);
00069
00073 void storeSrcAndMac(const NodeId &id, const char *bufO, gea::AbsTime t);
00074
00075 };
00076 }
00077
00078
00079 #endif //TAPIFACE_H__
00080
00081
00082
00083
00084
00085