Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
14 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-2000 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //*** arpdef.h - ARP definitions
  7. //
  8. // This file containes all of the private ARP related definitions.
  9. #define MEDIA_DIX 0
  10. #define MEDIA_TR 1
  11. #define MEDIA_FDDI 2
  12. #define MEDIA_ARCNET 3
  13. #define MAX_MEDIA 4
  14. #define INTERFACE_UP 0 // Interface is up.
  15. #define INTERFACE_INIT 1 // Interface is initializing.
  16. #define INTERFACE_DOWN 2 // Interface is down.
  17. #define LOOKAHEAD_SIZE 128 // A reasonable lookahead size
  18. // Definitions for state of an ATE. The 'RESOLVING' indicators must occur first.
  19. #define ARP_RESOLVING_LOCAL 0 // Address is being resolved (on local ring, if TR)
  20. #define ARP_RESOLVING_GLOBAL 1 // Address is being resolved globally.
  21. #define ARP_RESOLVING ARP_RESOLVING_GLOBAL
  22. #define ARP_GOOD 2 // ATE is good.
  23. #define ARP_BAD 3 // ATE is bad.
  24. #define ARP_FLOOD_RATE 1000L // No more than once a second.
  25. #define ARP_802_ADDR_LENGTH 6 // Length of an 802 address.
  26. #define MIN_ETYPE 0x600 // Minimum valid Ethertype
  27. #define SNAP_SAP 170
  28. #define SNAP_UI 3
  29. //* Structure of an Ethernet header.
  30. typedef struct ENetHeader {
  31. uchar eh_daddr[ARP_802_ADDR_LENGTH];
  32. uchar eh_saddr[ARP_802_ADDR_LENGTH];
  33. ushort eh_type;
  34. } ENetHeader;
  35. //* Structure of a token ring header.
  36. typedef struct TRHeader {
  37. uchar tr_ac;
  38. uchar tr_fc;
  39. uchar tr_daddr[ARP_802_ADDR_LENGTH];
  40. uchar tr_saddr[ARP_802_ADDR_LENGTH];
  41. } TRHeader;
  42. #define ARP_AC 0x10
  43. #define ARP_FC 0x40
  44. #define TR_RII 0x80
  45. typedef struct RC {
  46. uchar rc_blen; // Broadcast indicator and length.
  47. uchar rc_dlf; // Direction and largest frame.
  48. } RC;
  49. #define RC_DIR 0x80
  50. #define RC_LENMASK 0x1f
  51. #define RC_SRBCST 0xc2 // Single route broadcast RC.
  52. #define RC_ARBCST 0x82 // All route broadcast RC.
  53. #define RC_LMASK 0x1F // Mask for length field for route
  54. // information
  55. #define RC_LEN 0x2 // Length to put in the length bits
  56. // when sending source routed
  57. // frames
  58. #define RC_BCST_LEN 0x70 // Length for a broadcast.
  59. #define RC_LF_MASK 0x70 // Mask for length bits.
  60. //* Structure of source routing information.
  61. typedef struct SRInfo {
  62. RC sri_rc; // Routing control info.
  63. ushort sri_rd[1]; // Routing designators.
  64. } SRInfo;
  65. #define ARP_MAX_RD 8
  66. //* Structure of an FDDI header.
  67. typedef struct FDDIHeader {
  68. uchar fh_pri;
  69. uchar fh_daddr[ARP_802_ADDR_LENGTH];
  70. uchar fh_saddr[ARP_802_ADDR_LENGTH];
  71. } FDDIHeader;
  72. #define ARP_FDDI_PRI 0x57
  73. #define ARP_FDDI_MSS 4352
  74. //* Structure of an ARCNET header.
  75. typedef struct ARCNetHeader {
  76. uchar ah_saddr;
  77. uchar ah_daddr;
  78. uchar ah_prot;
  79. } ARCNetHeader;
  80. //* Structure of a SNAP header.
  81. typedef struct SNAPHeader {
  82. uchar sh_dsap;
  83. uchar sh_ssap;
  84. uchar sh_ctl;
  85. uchar sh_protid[3];
  86. ushort sh_etype;
  87. } SNAPHeader;
  88. #define ARP_MAX_MEDIA_ENET sizeof(ENetHeader)
  89. #define ARP_MAX_MEDIA_TR (sizeof(TRHeader)+sizeof(RC)+(ARP_MAX_RD*sizeof(ushort))+sizeof(SNAPHeader))
  90. #define ARP_MAX_MEDIA_FDDI (sizeof(FDDIHeader)+sizeof(SNAPHeader))
  91. #define ARP_MAX_MEDIA_ARC sizeof(ARCNetHeader)
  92. #define ENET_BCAST_MASK 0x01
  93. #define TR_BCAST_MASK 0x80
  94. #define FDDI_BCAST_MASK 0x01
  95. #define ARC_BCAST_MASK 0xff
  96. #define ENET_BCAST_VAL 0x01
  97. #define TR_BCAST_VAL 0x80
  98. #define FDDI_BCAST_VAL 0x01
  99. #define ARC_BCAST_VAL 0x00
  100. #define ENET_BCAST_OFF 0x00
  101. #define TR_BCAST_OFF offsetof(struct TRHeader, tr_daddr)
  102. #define FDDI_BCAST_OFF offsetof(struct FDDIHeader, fh_daddr)
  103. #define ARC_BCAST_OFF offsetof(struct ARCNetHeader, ah_daddr)
  104. typedef void (*ArpRtn)(void *, IP_STATUS Status);
  105. typedef struct ARPControlBlock {
  106. struct ARPControlBlock *next;
  107. ArpRtn CompletionRtn;
  108. ulong status;
  109. ulong PhyAddrLen;
  110. ulong *PhyAddr;
  111. } ARPControlBlock;
  112. //* Structure of an ARP table entry.
  113. typedef struct ARPTableEntry {
  114. struct ARPTableEntry *ate_next; // Next ATE in hash chain
  115. ulong ate_valid; // Last time ATE was known to be valid.
  116. IPAddr ate_dest; // IP address represented.
  117. PNDIS_PACKET ate_packet; // Packet (if any) queued for resolution
  118. RouteCacheEntry *ate_rce; // List of RCEs that reference this ATE.
  119. DEFINE_LOCK_STRUCTURE(ate_lock) // Lock for this ATE.
  120. uint ate_useticks; // Number of ticks left until this
  121. // goes away.
  122. uchar ate_addrlength; // Length of the address.
  123. uchar ate_state; // State of this entry
  124. ulong ate_userarp; // added to facilitate user api ARP reauests
  125. ARPControlBlock *ate_resolveonly;// This field points ARP control block(s)
  126. uint ate_refresh; //refresh arp entries before timeingout
  127. uchar ate_addr[1]; // Address that maps to dest
  128. } ARPTableEntry;
  129. #define ALWAYS_VALID 0xffffffff
  130. //* Structure of the ARP table.
  131. #define ARP_TABLE_SIZE 64
  132. #define ARP_HASH(x) ((((uchar *)&(x))[3] + ((uchar *)&(x))[2] + ((uchar *)&(x))[1] + ((uchar *)&(x))[0]) % ARP_TABLE_SIZE)
  133. typedef ARPTableEntry *ARPTable[];
  134. //* List structure for local representation of an IPAddress.
  135. typedef struct ARPIPAddr {
  136. struct ARPIPAddr *aia_next; // Next in list.
  137. uint aia_age;
  138. IPAddr aia_addr; // The address.
  139. IPMask aia_mask;
  140. void *aia_context;
  141. } ARPIPAddr;
  142. #define ARPADDR_NOT_LOCAL 4
  143. #define ARPADDR_NEW_LOCAL 3
  144. #define ARPADDR_OLD_LOCAL 0
  145. //* List structure for Proxy-ARP addresses.
  146. typedef struct ARPPArpAddr {
  147. struct ARPPArpAddr *apa_next; // Next in list.
  148. IPAddr apa_addr; // The address.
  149. IPMask apa_mask; // And the mask.
  150. } ARPPArpAddr;
  151. //* List structure for a multicast IP address.
  152. typedef struct ARPMCastAddr {
  153. struct ARPMCastAddr *ama_next; // Next in list.
  154. IPAddr ama_addr; // The (masked) address.
  155. uint ama_refcnt; // Reference count for this address.
  156. } ARPMCastAddr;
  157. #define ARP_MCAST_MASK 0xffff7f00
  158. #define ARP_TIMER_TIME 1000L
  159. #define ARP_RESOLVE_TIMEOUT 1000L
  160. #define ARP_MIN_VALID_TIMEOUT 600000L
  161. #define ARP_REFRESH_TIME 2000L
  162. #if FFP_SUPPORT
  163. #define FFP_ARP_FLUSH_INTERVAL 300 // Time (in s) after which ARP forces an FFP
  164. // flush (inorder to keep the ARP cache and
  165. // FFP's MAC Addr mapping in limited sync)
  166. #endif
  167. typedef struct ARPNotifyStruct {
  168. CTEEvent ans_event;
  169. uint ans_shutoff;
  170. IPAddr ans_addr;
  171. uint ans_hwaddrlen;
  172. uchar ans_hwaddr[1];
  173. } ARPNotifyStruct;
  174. //* Structure of information we keep on a per-interface basis.
  175. typedef struct ARPInterface {
  176. LIST_ENTRY ai_linkage; // to link into ARP interface list
  177. void *ai_context; // Upper layer context info.
  178. #if FFP_SUPPORT
  179. NDIS_HANDLE ai_driver; // NDIS Miniport/MAC driver handle
  180. #endif
  181. NDIS_HANDLE ai_handle; // NDIS bind handle.
  182. NDIS_MEDIUM ai_media; // Media type.
  183. NDIS_HANDLE ai_ppool; // Handle for packet pool.
  184. DEFINE_LOCK_STRUCTURE(ai_lock) // Lock for this structure.
  185. DEFINE_LOCK_STRUCTURE(ai_ARPTblLock) // ARP Table lock for this structure.
  186. ARPTable *ai_ARPTbl; // Pointer to the ARP table for this interface
  187. ARPIPAddr ai_ipaddr; // Local IP address list.
  188. ARPPArpAddr *ai_parpaddr; // Proxy ARP address list.
  189. IPAddr ai_bcast; // Broadcast mask for this interface.
  190. // SNMP required counters
  191. uint ai_inoctets; // Input octets.
  192. uint ai_inpcount[3]; // Count of nonunicast, unicast & promiscuous
  193. // packets received.
  194. uint ai_outoctets; // Output octets
  195. uint ai_outpcount[2];// Count of nonunicast and unicast
  196. // packets sent.
  197. uint ai_qlen; // Output q length.
  198. uchar ai_addr[ARP_802_ADDR_LENGTH]; // Local HW address.
  199. uchar ai_state; // State of the interface. Union of
  200. // admin and operational states.
  201. uchar ai_addrlen; // Length of ai_addr.
  202. uchar ai_bcastmask; // Mask for checking unicast.
  203. uchar ai_bcastval; // Value to check against.
  204. uchar ai_bcastoff; // Offset in frame to check against.
  205. uchar ai_hdrsize; // Size of 'typical' header.
  206. uchar ai_snapsize; // Size of snap header, if any.
  207. uchar ai_pad[2]; // PAD PAD
  208. uint ai_pfilter; // Packet filter for this i/f.
  209. uint ai_count; // Number of entries in the ARPTable.
  210. uint ai_parpcount; // Number of proxy ARP entries.
  211. CTETimer ai_timer; // ARP timer for this interface.
  212. BOOLEAN ai_timerstarted;// ARP timer started for this interface?
  213. BOOLEAN ai_stoptimer; // ARP timer started for this interface?
  214. CTEBlockStruc ai_timerblock; // used to sync stopping the interface timer
  215. CTEBlockStruc ai_block; // Structure for blocking on.
  216. ushort ai_mtu; // MTU for this interface.
  217. uchar ai_adminstate; // Admin state.
  218. uchar ai_operstate; // Operational state;
  219. uint ai_speed; // Speed.
  220. uint ai_lastchange; // Last change time.
  221. uint ai_indiscards; // In discards.
  222. uint ai_inerrors; // Input errors.
  223. uint ai_uknprotos; // Unknown protocols received.
  224. uint ai_outdiscards; // Output packets discarded.
  225. uint ai_outerrors; // Output errors.
  226. uint ai_desclen; // Length of desc. string.
  227. uint ai_index; // Global I/F index ID.
  228. uint ai_atinst; // AT instance number.
  229. uint ai_ifinst; // IF instance number.
  230. char *ai_desc; // Descriptor string.
  231. ARPMCastAddr *ai_mcast; // Multicast list.
  232. uint ai_mcastcnt; // Count of elements on mcast list.
  233. uint ai_ipaddrcnt; // number of local address on this
  234. uint ai_telladdrchng;// tell link layer about addr change? (for psched)
  235. ULONG ai_mediatype;
  236. uint ai_promiscuous; // promiscuous mode or not.
  237. #if FFP_SUPPORT
  238. ulong ai_ffpversion; // The version of FFP in use (0 implies no support)
  239. uint ai_ffplastflush;// Number of timer ticks since arp's last FFP flush
  240. #endif
  241. ARPNotifyStruct *ai_conflict;
  242. uint ai_delay;
  243. uint ai_OffloadFlags;// H/W checksum capability flag
  244. NDIS_TASK_TCP_LARGE_SEND ai_TcpLargeSend;
  245. NDIS_PNP_CAPABILITIES ai_wakeupcap; // wakeup capabilities.
  246. NDIS_STRING ai_devicename; // Name of the device.
  247. } ARPInterface;
  248. //* NOTE: These two values MUST stay at 0 and 1.
  249. #define AI_UCAST_INDEX 0
  250. #define AI_NONUCAST_INDEX 1
  251. #define AI_PROMIS_INDEX 2
  252. #define ARP_DEFAULT_PACKETS 10
  253. //* Structure of information passed as context in RCE.
  254. typedef struct ARPContext {
  255. RouteCacheEntry *ac_next; // Next RCE in ARP table chain.
  256. ARPTableEntry *ac_ate; // Back pointer to ARP table entry.
  257. } ARPContext;
  258. typedef struct IPNMEContext {
  259. uint inc_index;
  260. ARPTableEntry *inc_entry;
  261. } IPNMEContext;
  262. #include <packon.h>
  263. // Structure of an ARP header.
  264. typedef struct ARPHeader {
  265. ushort ah_hw; // Hardware address space.
  266. ushort ah_pro; // Protocol address space.
  267. uchar ah_hlen; // Hardware address length.
  268. uchar ah_plen; // Protocol address length.
  269. ushort ah_opcode; // Opcode.
  270. uchar ah_shaddr[ARP_802_ADDR_LENGTH]; // Source HW address.
  271. IPAddr ah_spaddr; // Source protocol address.
  272. uchar ah_dhaddr[ARP_802_ADDR_LENGTH]; // Destination HW address.
  273. IPAddr ah_dpaddr; // Destination protocol address.
  274. } ARPHeader;
  275. #include <packoff.h>
  276. #define ARP_ETYPE_IP 0x800
  277. #define ARP_ETYPE_ARP 0x806
  278. #define ARP_REQUEST 1
  279. #define ARP_RESPONSE 2
  280. #define ARP_HW_ENET 1
  281. #define ARP_HW_802 6
  282. #define ARP_HW_ARCNET 7
  283. #define ARP_ARCPROT_ARP 0xd5
  284. #define ARP_ARCPROT_IP 0xd4
  285. // The size we need to back off the buffer length because ARCNet address
  286. // are one bytes instead of six.
  287. #define ARCNET_ARPHEADER_ADJUSTMENT 10
  288. typedef struct _AddAddrNotifyEvent {
  289. CTEEvent Event;
  290. SetAddrControl *SAC;
  291. IPAddr Address;
  292. IP_STATUS Status;
  293. } AddAddrNotifyEvent;
  294. // Compute the length of the wakeup pattern mask based on the length
  295. // of the pattern. See NET_PM_WAKEUP_PATTERN_DESC.
  296. //
  297. __inline
  298. UINT
  299. GetWakeupPatternMaskLength(
  300. IN UINT Ptrnlen)
  301. {
  302. return (Ptrnlen - 1)/8 + 1;
  303. }