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.

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