00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __arp_h__
00038 #define __arp_h__
00039
00040 #include "scheduler.h"
00041 #include "delay.h"
00042 #include "lib/bsd-list.h"
00043
00044 #ifndef EADDRNOTAVAIL
00045 #define EADDRNOTAVAIL 125
00046 #endif
00047
00048 class LinkDelay;
00049 class ARPEntry;
00050 class ARPTable;
00051 class LL;
00052 class Mac;
00053
00054 LIST_HEAD(ARPTable_List, ARPTable);
00055 LIST_HEAD(ARPEntry_List, ARPEntry);
00056
00057
00058
00059
00060
00061 #define ARPHRD_ETHER 1
00062
00063 #define ARPOP_REQUEST 1
00064 #define ARPOP_REPLY 2
00065 #define ARPOP_REVREQUEST 3
00066 #define ARPOP_REVREPLY 4
00067 #define ARPOP_INVREQUEST 8
00068 #define ARPOP_INVREPLY 9
00069
00070 #define ARP_HDR_LEN 28
00071
00072 struct hdr_arp {
00073 u_int16_t arp_hrd;
00074 u_int16_t arp_pro;
00075 u_int8_t arp_hln;
00076 u_int8_t arp_pln;
00077 u_int16_t arp_op;
00078 int arp_sha;
00079 u_int16_t pad1;
00080 nsaddr_t arp_spa;
00081 int arp_tha;
00082 u_int16_t pad2;
00083 nsaddr_t arp_tpa;
00084
00085
00086 static int offset_;
00087 inline static int& offset() { return offset_; }
00088 inline static hdr_arp* access(const Packet* p) {
00089 return (hdr_arp*) p->access(offset_);
00090 }
00091 };
00092
00093 class ARPEntry {
00094 friend class ARPTable;
00095 public:
00096 ARPEntry(ARPEntry_List* head, nsaddr_t dst) {
00097 up_ = macaddr_ = count_ = 0;
00098 ipaddr_ = dst;
00099 hold_ = 0;
00100 LIST_INSERT_HEAD(head, this, arp_link_);
00101 }
00102 inline ARPEntry* nextarp() { return arp_link_.le_next; }
00103
00104 private:
00105 LIST_ENTRY(ARPEntry) arp_link_;
00106
00107 int up_;
00108 nsaddr_t ipaddr_;
00109 int macaddr_;
00110 Packet *hold_;
00111 int count_;
00112 #define ARP_MAX_REQUEST_COUNT 3
00113 };
00114
00115
00116 class ARPTable : public LinkDelay {
00117 public:
00118 ARPTable(const char *tclnode, const char *tclmac);
00119
00120 int command(int argc, const char*const* argv);
00121 int arpresolve(nsaddr_t dst, Packet *p, LL *ll);
00122 void arpinput(Packet *p, LL *ll);
00123 ARPEntry* arplookup(nsaddr_t dst);
00124 void arprequest(nsaddr_t src, nsaddr_t dst, LL *ll);
00125
00126 void Terminate(void);
00127
00128 private:
00129 inline int initialized() { return node_ && mac_; }
00130
00131 ARPEntry_List arphead_;
00132 MobileNode *node_;
00133 Mac *mac_;
00134
00135
00136
00137
00138
00139 public:
00140 LIST_ENTRY(ARPTable) link_;
00141 static ARPTable_List athead_;
00142 };
00143
00144 #endif
00145
00146
00147
00148
00149
00150
00151