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.

880 lines
33 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-2000 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. #pragma once
  7. #ifndef IPDEF_H_INCLUDED
  8. #define IPDEF_H_INCLUDED
  9. #if !MILLEN
  10. #ifndef IF_REFERENCE_DEBUG
  11. #define IF_REFERENCE_DEBUG 1
  12. #endif
  13. #else // !MILLEN
  14. #ifndef IF_REFERENCE_DEBUG
  15. #define IF_REFERENCE_DEBUG 0
  16. #endif
  17. #endif // !MILLEN
  18. //** IPDEF.H - IP private definitions.
  19. //
  20. // This file contains all of the definitions for IP that
  21. // are private to IP, i.e. not visible to outside layers.
  22. #define CLASSA_ADDR(a) (( (*((uchar *)&(a))) & 0x80) == 0)
  23. #define CLASSB_ADDR(a) (( (*((uchar *)&(a))) & 0xc0) == 0x80)
  24. #define CLASSC_ADDR(a) (( (*((uchar *)&(a))) & 0xe0) == 0xc0)
  25. #define CLASSE_ADDR(a) ((( (*((uchar *)&(a))) & 0xf0) == 0xf0) && \
  26. ((a) != 0xffffffff))
  27. #define CLASSA_MASK 0x000000ff
  28. #define CLASSB_MASK 0x0000ffff
  29. #define CLASSC_MASK 0x00ffffff
  30. #define CLASSD_MASK 0x000000f0
  31. #define CLASSE_MASK 0xffffffff
  32. #define MCAST_DEST 0x000000e0
  33. #define IP_OPT_COPIED 0x80 // Bit indicating options is to be copied.
  34. #define IP_OPT_TYPE 0
  35. #define IP_OPT_LENGTH 1
  36. #define IP_OPT_DATA 2
  37. #define IP_OPT_PTR 2 // Pointer offset, for those options that have it.
  38. #define IP_TS_OVFLAGS 3 // Offset for overflow and flags.
  39. #define IP_TS_FLMASK 0xf // Mask for flags
  40. #define IP_TS_OVMASK 0xf0 // Mask for overflow field.
  41. #define IP_TS_MAXOV 0xf0 // Maximum value for the overflow field.
  42. #define IP_TS_INC 0x10 // Increment used on overflow field.
  43. #define MIN_RT_PTR 4
  44. #define MIN_TS_PTR 5
  45. #define TS_REC_TS 0 // Record TS option.
  46. #define TS_REC_ADDR 1 // Record TS and address.
  47. #define TS_REC_SPEC 3 // Only specified addresses record.
  48. #define OPT_SSRR 1 // We've seen a SSRR in this option buffer
  49. #define OPT_LSRR 2 // We've seen a LSRR in this option buffer
  50. #define OPT_RR 4 // We've seen a RR
  51. #define OPT_TS 8 // We've seen a TS.
  52. #define OPT_ROUTER_ALERT 0x10 // We-ve seen a Router Alert option already
  53. #define ROUTER_ALERT_SIZE 4 // size of router alert option.
  54. #define MAX_OPT_SIZE 40
  55. #define ALL_ROUTER_MCAST 0x020000E0
  56. // Flags for retrieving interface capabilities.
  57. #define IF_WOL_CAP 0
  58. #define IF_OFFLOAD_CAP 1
  59. // Received option index structure.
  60. //
  61. typedef struct OptIndex {
  62. uchar oi_srindex;
  63. uchar oi_rrindex;
  64. uchar oi_tsindex;
  65. uchar oi_srtype;
  66. uchar oi_rtrindex; // rtr alert option
  67. } OptIndex;
  68. // This is a local definition of task offload OID to indicate to DoNdisRequest
  69. // to query for offload capability
  70. #define OID_TCP_TASK_OFFLOAD_EX 0x9999
  71. #define MAX_HDR_SIZE (sizeof(IPHeader) + MAX_OPT_SIZE)
  72. #define MAX_TOTAL_LENGTH 0xffff
  73. #define MAX_DATA_LENGTH (MAX_TOTAL_LENGTH - sizeof(IPHeader))
  74. #define DEFAULT_VERLEN 0x45 // Default version and length.
  75. #define IP_VERSION 0x40
  76. #define IP_VER_FLAG 0xF0
  77. #define IP_RSVD_FLAG 0x0080 // Reserved.
  78. #define IP_DF_FLAG 0x0040 // 'Don't fragment' flag
  79. #define IP_MF_FLAG 0x0020 // 'More fragments flag'
  80. #define IP_OFFSET_MASK ~0x00E0 // Mask for extracting offset field.
  81. typedef IP_STATUS (*ULRcvProc)(void *, IPAddr, IPAddr, IPAddr, IPAddr,
  82. IPHeader UNALIGNED *, uint, IPRcvBuf *, uint,
  83. uchar, uchar, IPOptInfo *);
  84. typedef uint (*ULStatusProc)(uchar, IP_STATUS, IPAddr, IPAddr, IPAddr, ulong,
  85. void *);
  86. typedef void (*ULElistProc)();
  87. typedef NTSTATUS (*ULPnPProc)(void *, IPAddr ipAddr, NDIS_HANDLE handle,
  88. PNET_PNP_EVENT);
  89. //* Protocol information structure. These is one of there for each protocol
  90. // bound to an NTE.
  91. //
  92. typedef struct ProtInfo {
  93. void (*pi_xmitdone)(void *, PNDIS_BUFFER, IP_STATUS); // Pointer
  94. // to xmit done routine.
  95. ULRcvProc pi_rcv; // Pointer to receive routine.
  96. ULStatusProc pi_status; // Pointer to status handler.
  97. void (*pi_rcvcmplt)(void); // Pointer to recv. cmplt handler.
  98. ULPnPProc pi_pnppower; // pnp power handler
  99. ULElistProc pi_elistchange; // entity list changed notification
  100. uchar pi_protocol; // Protocol type.
  101. uchar pi_valid; // Is this entry valid?
  102. uchar pi_pad[2]; // Pad to dword
  103. } ProtInfo;
  104. #define PI_ENTRY_INVALID 0
  105. #define PI_ENTRY_VALID 1
  106. //* Per-net information. We keep a variety of information for
  107. // each net, including the IP address, subnet mask, and reassembly
  108. // information.
  109. //
  110. #define MAX_IP_PROT 7 // ICMP, IGMP, TCP, UDP, AH,
  111. // ESP & Raw
  112. typedef struct IPRtrEntry {
  113. struct IPRtrEntry *ire_next;
  114. IPAddr ire_addr;
  115. long ire_preference;
  116. ushort ire_lifetime;
  117. ushort ire_pad;
  118. } IPRtrEntry;
  119. typedef struct NetTableEntry {
  120. struct NetTableEntry *nte_next; // Next NTE of I/F.
  121. IPAddr nte_addr; // IP address for this net.
  122. IPMask nte_mask; // Subnet mask for this net.
  123. struct Interface *nte_if; // Pointer to interface for
  124. // this net.
  125. struct NetTableEntry *nte_ifnext; // Linkage on if chain.
  126. ushort nte_flags; // Flags for NTE.
  127. ushort nte_context; // Context passed to upper
  128. // layers.
  129. ulong nte_instance; // Unique instance ID for this
  130. // net
  131. void *nte_pnpcontext; // PNP context.
  132. DEFINE_LOCK_STRUCTURE(nte_lock)
  133. struct ReassemblyHeader *nte_ralist; // Reassembly list.
  134. struct EchoControl *nte_echolist; // List of pending echo control
  135. // blocks
  136. CTETimer nte_timer; // Timer for this net.
  137. CTEBlockStruc nte_timerblock; // used to sync stopping the
  138. // interface timer
  139. ushort nte_mss;
  140. ushort nte_pad; // for alignment.
  141. uint nte_icmpseq; // ICMP seq. #. 32 bit to reduce
  142. // collisions from wraparound.
  143. struct IGMPAddr **nte_igmplist; // Pointer to hash table
  144. void *nte_addrhandle; // Handle for address
  145. // registration.
  146. IPAddr nte_rtrdiscaddr; // Address used for Router
  147. // Discovery
  148. uchar nte_rtrdiscstate; // state of router solicitations
  149. uchar nte_rtrdisccount; // router solicitation count
  150. uchar nte_rtrdiscovery;
  151. uchar nte_deleting;
  152. IPRtrEntry *nte_rtrlist;
  153. uint nte_igmpcount; // total number of groups joined on this NTE
  154. } NetTableEntry;
  155. // Note - Definition here has dependency on addr type defined in iprtrmib.h
  156. #define NTE_VALID 0x0001 // NTE is valid.
  157. #define NTE_COPY 0x0002 // For NDIS copy lookahead
  158. #define NTE_PRIMARY 0x0004 // This is the 'primary' NTE
  159. // on the I/F.
  160. #define NTE_ACTIVE 0x0008 // NTE is active,
  161. // i.e. interface is valid.
  162. #define NTE_DYNAMIC 0x0010 // NTE was created dynamically
  163. #define NTE_DHCP 0x0020 // Is DHCP working on this
  164. // interface?
  165. #define NTE_DISCONNECTED 0x0040 // Is Media disconnected?
  166. #define NTE_TIMER_STARTED 0x0080 // Is timer started for this?
  167. #define NTE_IF_DELETING 0x0100 // nte->if is soon to be deleted
  168. #define NTE_TRANSIENT_ADDR 0x0200 // Transient addr type
  169. //========================================================================
  170. // DHCPNTE is used by the sendpath to figure out which NTE to send on.
  171. // nte_flags & NTE_DHCP is used to decide at the receive path if the
  172. // NTE is dhcp-mode (is trying to get an address) to push the packet up
  173. // further to dhcpcsvc.dll.
  174. // The basic logic used by dhcp is :
  175. // each interface do : (in parallel)
  176. // SetDHCPNTE on the interface and send packet out (atomic)
  177. // process packet and maybe go to above step.
  178. // Set address and call SetDHCPNTE w/ invalid interface
  179. // Step one sets the DHCPNTE variable and the nte_flags on this NTE.
  180. // Step 3 turns off the DHCPNTE variable making it NULL.
  181. // Step 2 set the nte_flags & NTE_DHCP to false.. turns off the flag.
  182. //=======================================================================
  183. #define IP_TIMEOUT 500
  184. #define NTE_RTRDISC_UNINIT 0
  185. #define NTE_RTRDISC_DELAYING 1
  186. #define NTE_RTRDISC_SOLICITING 2
  187. #define MAX_SOLICITATION_DELAY 2 // ticks to delay
  188. #define SOLICITATION_INTERVAL 6 // ticks between solicitations
  189. #define MAX_SOLICITATIONS 3 // number of solicitations
  190. //* Buffer reference structure. Used by broadcast and fragmentation code to
  191. // track multiple references to a single user buffer.
  192. typedef struct BufferReference {
  193. PNDIS_BUFFER br_buffer; // Pointer to uses buffer.
  194. DEFINE_LOCK_STRUCTURE(br_lock)
  195. int br_refcount; // Count of references to user's buffer.
  196. PNDIS_BUFFER br_userbuffer; // Buffer to be restored, in header incl case.
  197. } BufferReference;
  198. // Definitions of flags in pc_flags field
  199. #define PACKET_FLAG_OPTIONS 0x01 // Set if packet has an options buffer.
  200. #define PACKET_FLAG_IPBUF 0x02 // Set if packet is composed of IP
  201. // buffers.
  202. #define PACKET_FLAG_RA 0x04 // Set if packet is being used for
  203. // reassembly.
  204. #define PACKET_FLAG_FW 0x08 // Set if packet is a forwarding packet.
  205. #define PACKET_FLAG_IPHDR 0x10 // Packet uses an IP hdr buffer.
  206. #define PACKET_FLAG_SNAP 0x20 // Packet uses a SNAP header.
  207. //* Transfer data packet context.
  208. // Used when TD'ing a packet - we store information for the callback here.
  209. //
  210. typedef struct TDContext {
  211. struct PCCommon tdc_common;
  212. void *tdc_buffer; // Pointer to buffer containing data.
  213. NetTableEntry *tdc_nte; // NTE to receive this on.
  214. struct RABufDesc *tdc_rbd; // Pointer to RBD, if any.
  215. uchar tdc_dtype; // Destination type of original address.
  216. uchar tdc_hlength; // Length in bytes of header.
  217. uchar tdc_pad[2];
  218. uchar tdc_header[MAX_HDR_SIZE + 8];
  219. } TDContext;
  220. // IP requests to NDIS miniports through ARP
  221. //
  222. typedef void (*RCCALL) (PVOID pRequestInfo);
  223. // General request block for asynchronous NDIS requests
  224. //
  225. typedef struct ReqInfoBlock {
  226. ulong RequestType;
  227. ulong RequestRefs; // Reference Count on this block
  228. RCCALL ReqCompleteCallback; // Request Complete Callback
  229. uchar RequestLength;
  230. uchar RequestInfo[0]; // Variable length - see below
  231. } ReqInfoBlock;
  232. #if FFP_SUPPORT
  233. // Default FFP startup params
  234. //
  235. #define DEFAULT_FFP_FFWDCACHE_SIZE 0 // 0 => FFP code picks default cachesize
  236. #define DEFAULT_FFP_CONTROL_FLAGS 0x00010001 // Enable Fast Forwarding with
  237. // Filtering
  238. // FFP Cache Params In the Registry
  239. //
  240. extern ulong FFPRegFastForwardingCacheSize;
  241. extern ulong FFPRegControlFlags;
  242. // Some timing parameters in secs
  243. //
  244. #define FFP_IP_FLUSH_INTERVAL 5 // Min time interval between
  245. // consequtive flush requests
  246. #endif // if FFP_SUPPORT
  247. //* Firewall queue entry definition
  248. //
  249. typedef struct FIREWALL_INFO {
  250. Queue hook_q; // Queue linkage for firewall hook in IF
  251. IPPacketFirewallPtr hook_Ptr; // Packet firewall callout.
  252. uint hook_priority; // Recv Priority of the hook
  253. } FIREWALL_HOOK, *PFIREWALL_HOOK;
  254. typedef struct LinkEntry {
  255. struct LinkEntry *link_next; // next link in chain
  256. IPAddr link_NextHop; // next hop address of the link
  257. struct Interface *link_if; // back ptr to the interface
  258. void *link_arpctxt; // link layers context
  259. struct RouteTableEntry *link_rte; // rte chain associated with this link
  260. uint link_Action; // needed for filter hooks;
  261. // by default FORWARD
  262. uint link_mtu; // mtu of the link
  263. long link_refcount; // refcount for the link
  264. } LinkEntry;
  265. // Some flags for multicast properties
  266. //
  267. #define IPMCAST_IF_ENABLED (uchar)0x01
  268. #define IPMCAST_IF_WRONG_IF (uchar)0x02
  269. #define IPMCAST_IF_ACCEPT_ALL (uchar)0x04
  270. //* Information about net interfaces. There can be multiple nets for each
  271. // interface, but there is exactly one interface per net.
  272. //
  273. #if IF_REFERENCE_DEBUG
  274. #define MAX_IFREFERENCE_HISTORY 4
  275. typedef struct _IF_REFERENCE_HISTORY {
  276. uchar *File;
  277. uint Line;
  278. void *Caller;
  279. uint Count;
  280. } IF_REFERENCE_HISTORY;
  281. #endif // IF_REFERENCE_DEBUG
  282. typedef struct Interface {
  283. struct Interface *if_next; // Next interface in chain.
  284. void *if_lcontext; // Link layer context.
  285. ARP_TRANSMIT if_xmit;
  286. ARP_TRANSFER if_transfer;
  287. ARP_RETURN_PKT if_returnpkt;
  288. ARP_CLOSE if_close;
  289. ARP_ADDADDR if_addaddr;
  290. ARP_DELADDR if_deladdr;
  291. ARP_INVALIDATE if_invalidate;
  292. ARP_OPEN if_open;
  293. ARP_QINFO if_qinfo;
  294. ARP_SETINFO if_setinfo;
  295. ARP_GETELIST if_getelist;
  296. ARP_DONDISREQ if_dondisreq;
  297. NDIS_STATUS (__stdcall *if_dowakeupptrn)(void *, PNET_PM_WAKEUP_PATTERN_DESC, ushort, BOOLEAN);
  298. void (__stdcall *if_pnpcomplete)(void *, NDIS_STATUS, PNET_PNP_EVENT);
  299. NDIS_STATUS (__stdcall *if_setndisrequest)(void *, NDIS_OID, uint);
  300. NDIS_STATUS (__stdcall *if_arpresolveip)(void *, IPAddr, void *);
  301. BOOLEAN (__stdcall *if_arpflushate)(void *, IPAddr);
  302. void (__stdcall *if_arpflushallate)(void *);
  303. uint if_numgws; // Number of default gateways
  304. IPAddr if_gw[MAX_DEFAULT_GWS]; //IPaddresses for gateways
  305. uint if_gwmetric[MAX_DEFAULT_GWS];
  306. uint if_metric;
  307. ushort if_rtrdiscovery; // is router discovery enabled?
  308. ushort if_dhcprtrdiscovery; // is router discovery DHCP-enabled?
  309. PNDIS_PACKET if_tdpacket; // Packet used for transferring data.
  310. uint if_index; // Index of this interface.
  311. ULONG if_mediatype;
  312. uchar if_accesstype;
  313. uchar if_conntype;
  314. uchar if_mcastttl;
  315. uchar if_mcastflags;
  316. LONGLONG if_lastupcall;
  317. uint if_ntecount; // Valid NTEs on this interface.
  318. NetTableEntry *if_nte; // Pointer to list of NTE on interface.
  319. IPAddr if_bcast; // Broadcast address for this interface.
  320. uint if_mtu; // True maximum MTU for the interface.
  321. uint if_speed; // Speed in bits/sec of this interface.
  322. uint if_flags; // Flags for this interface.
  323. uint if_addrlen; // Length of i/f addr.
  324. uchar *if_addr; // Pointer to addr.
  325. uint IgmpVersion; //igmp version active on this interface
  326. uint IgmpVer1Timeout; //Version 1 router present timeout
  327. uint IgmpVer2Timeout;// Version 2 router present timeout
  328. uint IgmpGeneralTimer; //General query response timer
  329. uint if_refcount; // Reference count for this i/f.
  330. CTEBlockStruc *if_block; // Block structure for PnP.
  331. void *if_pnpcontext; // Context to pass to upper layers.
  332. HANDLE if_tdibindhandle;
  333. uint if_llipflags; // Lower layer flags
  334. NDIS_STRING if_configname; // Name of the i/f config section
  335. NDIS_STRING if_name; // The current name of the interface
  336. NDIS_STRING if_devname; // The name of the device
  337. PVOID if_ipsecsniffercontext; // context for IPSEC sniffer
  338. DEFINE_LOCK_STRUCTURE(if_lock)
  339. #if FFP_SUPPORT
  340. ulong if_ffpversion; // Version of FFP code (or zero)
  341. ULONG_PTR if_ffpdriver; // Driver that does FFP (or zero)
  342. #endif // if FFP_SUPPORT
  343. uint if_OffloadFlags; // Checksum capability holder.
  344. uint if_MaxOffLoadSize;
  345. uint if_MaxSegments;
  346. NDIS_TASK_TCP_LARGE_SEND if_TcpLargeSend;
  347. uint if_TcpWindowSize;
  348. uint if_TcpInitialRTT;
  349. uchar if_TcpDelAckTicks;
  350. uchar if_TcpAckFrequency; // holds ack frequency for this Interface
  351. uchar if_absorbfwdpkts;
  352. uchar if_InitInProgress;
  353. uchar if_resetInProgress;
  354. uchar if_promiscuousmode;
  355. uchar if_auto_metric; // whether it is in auto mode or not
  356. uchar if_iftype; // type of interface: allow unicast/mcast/both
  357. LinkEntry *if_link; // chain of links for this interface
  358. void (__stdcall *if_closelink)(void *, void *);
  359. uint if_mediastatus;
  360. uint if_pnpcap; // remeber pnpcapability of the adapter
  361. struct Interface *if_dampnext;
  362. ushort if_damptimer;
  363. ushort if_wlantimer;
  364. ULONGLONG if_InMcastPkts; // Multicast counters for packets rcvd
  365. ULONGLONG if_InMcastOctets; // and bytes rcvd
  366. ULONGLONG if_OutMcastPkts; // Multicast packets sent and
  367. ULONGLONG if_OutMcastOctets; // bytes sent
  368. ARP_CANCEL if_cancelpackets;
  369. uint if_order; // holds this interface's position
  370. // in the admin-specified ordering
  371. // of adapters.
  372. #if IF_REFERENCE_DEBUG
  373. uint if_refhistory_index;
  374. IF_REFERENCE_HISTORY if_refhistory[MAX_IFREFERENCE_HISTORY]; // Added for tracking purpose
  375. #endif // IF_REFERENCE_DEBUG
  376. } Interface;
  377. #if IF_REFERENCE_DEBUG
  378. uint
  379. DbgLockedReferenceIF (
  380. Interface *RefIF,
  381. uchar *File,
  382. uint Line
  383. );
  384. uint
  385. DbgDereferenceIF (
  386. Interface *DerefIF,
  387. uchar *File,
  388. uint Line
  389. );
  390. uint
  391. DbgLockedDereferenceIF (
  392. Interface *DerefIF,
  393. uchar *File,
  394. uint Line
  395. );
  396. #define LOCKED_REFERENCE_IF(_a) DbgLockedReferenceIF((_a), __FILE__, __LINE__)
  397. #define LOCKED_DEREFERENCE_IF(_a) DbgLockedDereferenceIF((_a), __FILE__, __LINE__)
  398. #define DEREFERENCE_IF(_a) DbgDereferenceIF((_a), __FILE__, __LINE__)
  399. #else // IF_REFERENCE_DEBUG
  400. #define LOCKED_REFERENCE_IF(_a) ++(_a)->if_refcount
  401. #define LOCKED_DEREFERENCE_IF(_a) --(_a)->if_refcount
  402. #define DEREFERENCE_IF(_a) \
  403. CTEInterlockedAddUlong(&(_a)->if_refcount, (ULONG) -1, &RouteTableLock.Lock);
  404. #endif // IF_REFERENCE_DEBUG
  405. // Bit values for if_iftype
  406. //
  407. #define DONT_ALLOW_UCAST 0x01
  408. #define DONT_ALLOW_MCAST 0x02
  409. // value for invalid interface context
  410. //
  411. #define INVALID_INTERFACE_CONTEXT 0xffff
  412. // specs for speed order
  413. //
  414. #define FIRST_ORDER_METRIC 10 //metric for speed > 200M
  415. #define FIRST_ORDER_SPEED 200000000
  416. #define SECOND_ORDER_METRIC 20 //metric for 20M < speed <=200M
  417. #define SECOND_ORDER_SPEED 20000000
  418. #define THIRD_ORDER_METRIC 30 //metric for 4M < speed <=20M
  419. #define THIRD_ORDER_SPEED 4000000
  420. #define FOURTH_ORDER_METRIC 40 //metric for 500K < speed <=4M
  421. #define FOURTH_ORDER_SPEED 500000
  422. #define FIFTH_ORDER_METRIC 50 //metric for speed <= 500K
  423. /*NOINC*/
  424. extern void DerefIF(Interface *IF);
  425. extern void LockedDerefIF(Interface *IF);
  426. /*INC*/
  427. extern void DerefLink(LinkEntry *Link);
  428. extern CTEBlockStruc TcpipUnloadBlock;
  429. extern BOOLEAN fRouteTimerStopping;
  430. typedef struct NdisResEntry {
  431. struct NdisResEntry *nre_next;
  432. NDIS_HANDLE nre_handle;
  433. uchar *nre_buffer;
  434. } NdisResEntry;
  435. // macro to check that interface is not shutting down.
  436. #define IS_IF_INVALID( _interface ) \
  437. (_interface)->if_flags & \
  438. (IF_FLAGS_REMOVING_POWER|IF_FLAGS_POWER_DOWN|IF_FLAGS_REMOVING_DEVICE)
  439. #if !MILLEN
  440. // No bind or export prefixes on Millennium.
  441. //
  442. #define TCP_EXPORT_STRING_PREFIX L"\\DEVICE\\TCPIP_"
  443. #define TCP_BIND_STRING_PREFIX L"\\DEVICE\\"
  444. #endif // !MILLEN
  445. // Structure of a reassembly buffer descriptor. Each RBD describes a
  446. // fragment of the total datagram.
  447. //
  448. typedef struct RABufDesc {
  449. IPRcvBuf rbd_buf; // IP receive buffer for this fragment.
  450. ushort rbd_start; // Offset of first byte of this fragment.
  451. ushort rbd_end; // Offset of last byte of this fragment.
  452. int rbd_AllocSize;
  453. } RABufDesc;
  454. // Reassembly header. The includes the information needed for the lookup,
  455. // as well as space for the received header and a chain of reassembly
  456. // buffer descriptors.
  457. //
  458. typedef struct ReassemblyHeader {
  459. struct ReassemblyHeader *rh_next; // Next header in chain.
  460. IPAddr rh_dest; // Destination address of fragment.
  461. IPAddr rh_src; // Source address of fragment.
  462. ushort rh_id; // ID of datagram.
  463. uchar rh_protocol; // Protocol of datagram.
  464. uchar rh_ttl; // Remaining time of datagram.
  465. RABufDesc *rh_rbd; // Chain of RBDs for this datagram.
  466. ushort rh_datasize; // Total size of data.
  467. ushort rh_datarcvd; // Amount of data received so far.
  468. ushort rh_headersize; // Size in bytes of header.
  469. ushort rh_numoverlaps; // for fragment attack detection.
  470. uchar rh_header[MAX_HDR_SIZE+8]; // Saved IP header of
  471. // first fragment.
  472. } ReassemblyHeader;
  473. // ICMP type and code definitions
  474. #define IP_DEST_UNREACH_BASE IP_DEST_NET_UNREACHABLE
  475. #define ICMP_REDIRECT 5 // Redirect
  476. #define ADDR_MASK_REQUEST 17 // Address mask request
  477. #define ADDR_MASK_REPLY 18
  478. #define ICMP_DEST_UNREACH 3 // Destination unreachable
  479. #define ICMP_TIME_EXCEED 11 // Time exceeded during reassembly
  480. #define ICMP_PARAM_PROBLEM 12 // Parameter problem
  481. #define ICMP_SOURCE_QUENCH 4 // Source quench
  482. #define ICMP_ROUTER_ADVERTISEMENT 9 // Router Advertisement
  483. #define ICMP_ROUTER_SOLICITATION 10 // Router Solicitation
  484. #define NET_UNREACH 0
  485. #define HOST_UNREACH 1
  486. #define PROT_UNREACH 2
  487. #define PORT_UNREACH 3
  488. #define FRAG_NEEDED 4
  489. #define SR_FAILED 5
  490. #define DEST_NET_UNKNOWN 6
  491. #define DEST_HOST_UNKNOWN 7
  492. #define SRC_ISOLATED 8
  493. #define DEST_NET_ADMIN 9
  494. #define DEST_HOST_ADMIN 10
  495. #define NET_UNREACH_TOS 11
  496. #define HOST_UNREACH_TOS 12
  497. #define TTL_IN_TRANSIT 0 // TTL expired in transit
  498. #define TTL_IN_REASSEM 1 // Time exceeded in reassembly
  499. #define PTR_VALID 0
  500. #define REQ_OPTION_MISSING 1
  501. #define REDIRECT_NET 0
  502. #define REDIRECT_HOST 1
  503. #define REDIRECT_NET_TOS 2
  504. #define REDIRECT_HOST_TOS 3
  505. // Flags for set and delete route
  506. //
  507. #define RT_REFCOUNT 0x01
  508. #define RT_NO_NOTIFY 0x02
  509. #define RT_EXCLUDE_LOCAL 0x04
  510. extern uint DHCPActivityCount;
  511. extern IP_STATUS SetIFContext(uint Index, INTERFACE_CONTEXT *Context, IPAddr NextHop);
  512. extern IP_STATUS SetFirewallHook(PIP_SET_FIREWALL_HOOK_INFO pFirewallHookInfo);
  513. extern IP_STATUS SetFilterPtr(IPPacketFilterPtr FilterPtr);
  514. extern IP_STATUS SetMapRoutePtr(IPMapRouteToInterfacePtr MapRoutePtr);
  515. #if FFP_SUPPORT
  516. extern void IPFlushFFPCaches(void);
  517. extern void IPSetInFFPCaches(struct IPHeader UNALIGNED *PacketHeader,
  518. uchar *Packet, uint PacketLength,
  519. ulong CacheEntryType);
  520. extern void IPStatsFromFFPCaches(FFPDriverStats *pCumulStats);
  521. #endif // if FFP_SUPPORT
  522. //
  523. // All IP externs in one place
  524. //
  525. extern void __stdcall IPRcv(void *, void *, uint, uint, NDIS_HANDLE, uint, uint, void *);
  526. extern void __stdcall IPRcvPacket(void *, void *, uint, uint, NDIS_HANDLE,
  527. uint, uint,uint,PNDIS_BUFFER, uint *, void *);
  528. extern void __stdcall IPTDComplete(void *, PNDIS_PACKET, NDIS_STATUS, uint);
  529. extern void __stdcall IPSendComplete(void *, PNDIS_PACKET, NDIS_STATUS);
  530. extern void __stdcall IPStatus(void *, uint, void *, uint, void *);
  531. extern void __stdcall IPRcvComplete(void);
  532. extern void __stdcall IPAddAddrComplete( IPAddr, void *, IP_STATUS );
  533. extern void __stdcall IPBindAdapter(PNDIS_STATUS RetStatus,
  534. NDIS_HANDLE BindContext,
  535. PNDIS_STRING AdapterName,
  536. PVOID SS1, PVOID SS2);
  537. extern NTSTATUS GetLLInterfaceValue(NDIS_HANDLE Handle,
  538. PNDIS_STRING valueString);
  539. extern void __stdcall ARPBindAdapter(PNDIS_STATUS RetStatus,
  540. NDIS_HANDLE BindContext,
  541. PNDIS_STRING AdapterName,
  542. PVOID SS1, PVOID SS2);
  543. EXTERNAL_LOCK(ArpModuleLock)
  544. //
  545. // List to keep all the registered Arp modules.
  546. //
  547. LIST_ENTRY ArpModuleList;
  548. //
  549. // The actual structure which links into the above list
  550. //
  551. typedef struct _ARP_MODULE {
  552. LIST_ENTRY Linkage;
  553. ARP_BIND BindHandler; // pointer to ARP bind handler
  554. NDIS_STRING Name; // the unicode string buffer is
  555. // located at the end of this structure
  556. } ARP_MODULE, *PARP_MODULE;
  557. #ifdef POOL_TAGGING
  558. #ifdef ExAllocatePool
  559. #undef ExAllocatePool
  560. #endif
  561. #define ExAllocatePool(type, size) ExAllocatePoolWithTag(type, size, 'iPCT')
  562. #ifndef CTEAllocMem
  563. #error "CTEAllocMem is not already defined - will override tagging"
  564. #else
  565. #undef CTEAllocMem
  566. #endif
  567. #if MILLEN
  568. #define CTEAllocMem(size) \
  569. ExAllocatePoolWithTag(NonPagedPool, size, 'tPCT')
  570. #define CTEAllocMemN(size,tag) \
  571. ExAllocatePoolWithTag(NonPagedPool, size, tag)
  572. #else // MILLEN
  573. #define CTEAllocMem(size) \
  574. ExAllocatePoolWithTagPriority(NonPagedPool, size, 'tPCT', \
  575. NormalPoolPriority)
  576. #define CTEAllocMemN(size,tag) \
  577. ExAllocatePoolWithTagPriority(NonPagedPool, size, tag, NormalPoolPriority)
  578. #endif // !MILLEN
  579. #define CTEAllocMemBoot(size) \
  580. ExAllocatePoolWithTag(NonPagedPool, size, 'iPCT')
  581. #define CTEAllocMemNBoot(size,tag) \
  582. ExAllocatePoolWithTag(NonPagedPool, size, tag)
  583. #endif // POOL_TAGGING
  584. //* Change notification structure.
  585. //
  586. extern void AddChangeNotifyCancel(PDEVICE_OBJECT pDevice, PIRP pIrp);
  587. #if MILLEN
  588. extern void AddChangeNotify(IPAddr Addr, IPMask Mask, void *Context,
  589. ushort IPContext, PNDIS_STRING ConfigName,
  590. PNDIS_STRING IFName, uint Added,
  591. uint UniAddr);
  592. #else // MILLEN
  593. extern void AddChangeNotify(ulong Add);
  594. #endif // !MILLEN
  595. EXTERNAL_LOCK(AddChangeLock)
  596. extern void ChangeNotify(IPNotifyOutput *, PLIST_ENTRY, PVOID);
  597. extern void CancelNotify(PIRP, PLIST_ENTRY, PVOID);
  598. extern LIST_ENTRY AddChangeNotifyQueue;
  599. #if MILLEN
  600. EXTERNAL_LOCK(IfChangeLock)
  601. extern LIST_ENTRY IfChangeNotifyQueue;
  602. #endif // MILLEN
  603. #define NO_SR 0
  604. //* Routine for TCP checksum. This is defined as call through a function
  605. // pointer which is set to point at the optimal routine for this processor
  606. //
  607. typedef ULONG (*TCPXSUM_ROUTINE) (ULONG Checksum, PUCHAR Source, ULONG Length);
  608. extern TCPXSUM_ROUTINE tcpxsum_routine;
  609. #define xsum(Buffer, Length) \
  610. ((ushort) tcpxsum_routine(0, (PUCHAR) (Buffer), (Length)))
  611. //
  612. // VOID
  613. // MARK_REQUEST_PENDING(
  614. // IN PREQUEST Request
  615. // );
  616. //
  617. // Marks that a request will pend.
  618. //
  619. #define MARK_REQUEST_PENDING(_Request) \
  620. IoMarkIrpPending(_Request)
  621. //
  622. // VOID
  623. // UNMARK_REQUEST_PENDING(
  624. // IN PREQUEST Request
  625. // );
  626. //
  627. // Marks that a request will not pend.
  628. //
  629. #define UNMARK_REQUEST_PENDING(_Request) \
  630. (((IoGetCurrentIrpStackLocation(_Request))->Control) &= ~SL_PENDING_RETURNED)
  631. typedef struct _MediaSenseNotifyEvent {
  632. CTEEvent Event;
  633. uint Status;
  634. NDIS_STRING devname;
  635. } MediaSenseNotifyEvent;
  636. typedef struct _AddStaticAddrEvent {
  637. CTEEvent Event;
  638. Interface *IF;
  639. NDIS_STRING ConfigName;
  640. } AddStaticAddrEvent;
  641. typedef struct _IPResetEvent {
  642. CTEEvent Event;
  643. Interface *IF;
  644. } IPResetEvent;
  645. //
  646. // Debugging macros
  647. //
  648. #if DBG
  649. extern ULONG IPDebug;
  650. #define IP_DEBUG_GPC 0x00000001
  651. #define IP_DEBUG_ADDRESS 0x00000002
  652. #define IF_IPDBG(flag) if (IPDebug & flag)
  653. #define TCPTRACE(many_args) DbgPrint many_args
  654. #else // DBG
  655. #define IF_IPDBG(flag) if (0)
  656. #define TCPTRACE(many_args)
  657. #endif // DBG
  658. extern PNDIS_BUFFER FreeIPPacket(PNDIS_PACKET Packet, BOOLEAN FixHdrs, IP_STATUS Status);
  659. extern void *IPRegisterProtocol(uchar Protocol, void *RcvHandler,
  660. void *XmitHandler, void *StatusHandler,
  661. void *RcvCmpltHandler, void *PnPHandler,
  662. void *ElistHandler);
  663. //
  664. // IPSec dummy functions to prevent IPSec unload complications
  665. //
  666. IPSEC_ACTION
  667. IPSecHandlePacketDummy(
  668. IN PUCHAR pIPHeader,
  669. IN PVOID pData,
  670. IN PVOID IPContext,
  671. IN PNDIS_PACKET Packet,
  672. IN OUT PULONG pExtraBytes,
  673. IN OUT PULONG pMTU,
  674. OUT PVOID *pNewData,
  675. IN OUT PULONG IpsecFlags,
  676. IN UCHAR DestinationType
  677. );
  678. BOOLEAN
  679. IPSecQueryStatusDummy(
  680. IN CLASSIFICATION_HANDLE GpcHandle
  681. );
  682. VOID
  683. IPSecSendCompleteDummy(
  684. IN PNDIS_PACKET Packet,
  685. IN PVOID pData,
  686. IN PIPSEC_SEND_COMPLETE_CONTEXT pContext,
  687. IN IP_STATUS Status,
  688. OUT PVOID *ppNewData
  689. );
  690. NTSTATUS
  691. IPSecNdisStatusDummy(
  692. IN PVOID IPContext,
  693. IN UINT Status
  694. );
  695. IPSEC_ACTION
  696. IPSecRcvFWPacketDummy(
  697. IN PCHAR pIPHeader,
  698. IN PVOID pData,
  699. IN UINT DataLength,
  700. IN UCHAR DestType
  701. );
  702. #define NET_TABLE_HASH(x) ( ( (((uchar *)&(x))[0]) + (((uchar *)&(x))[1]) + \
  703. (((uchar *)&(x))[2]) + (((uchar *)&(x))[3]) ) \
  704. & (NET_TABLE_SIZE-1))
  705. uchar IPGetAddrType(IPAddr Address);
  706. // Global IP ID.
  707. typedef struct CACHE_ALIGN _IPID_CACHE_LINE {
  708. ulong Value;
  709. } IPID_CACHE_LINE;
  710. #if !MILLEN
  711. #define SET_CANCEL_CONTEXT(irp, DestIF) \
  712. if (irp) { \
  713. ((PIRP)irp)->Tail.Overlay.DriverContext[0] = DestIF; \
  714. }
  715. #define SET_CANCELID(irp, Packet) \
  716. if (irp) { \
  717. NdisSetPacketCancelId(Packet, ((PIRP)irp)->Tail.Overlay.DriverContext[1]); \
  718. }
  719. #else // !MILLEN
  720. #define SET_CANCEL_CONTEXT(irp, DestIF) ((VOID)0)
  721. #define SET_CANCELID(irp, Packet) ((VOID)0)
  722. #endif // !MILLEN
  723. #define PACKET_GROW_COUNT 46
  724. #define SMALL_POOL PACKET_GROW_COUNT*500
  725. #define MEDIUM_POOL PACKET_GROW_COUNT*750
  726. #define LARGE_POOL PACKET_GROW_COUNT*1280 // Note that packet pool can have max 64K packets
  727. #endif