Leaked source code of windows server 2003
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.

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