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.

837 lines
18 KiB

  1. /*++
  2. Copyright (c) 2001-2002 Microsoft Corporation
  3. Module Name:
  4. teredo.h
  5. Abstract:
  6. This module contains the teredo client and server (cum relay) state.
  7. Author:
  8. Mohit Talwar (mohitt) Mon Oct 22 15:17:48 2001
  9. Environment:
  10. User mode only.
  11. --*/
  12. #ifndef _TEREDO_
  13. #define _TEREDO_
  14. #pragma once
  15. //
  16. // IP6_HDR
  17. //
  18. // Define the RFC 2292 structure for an IPv6 header.
  19. //
  20. typedef struct _IP6_HDR {
  21. union {
  22. struct ip6_hdrctl {
  23. UINT32 ip6_un1_flow; // 20 bits of flow-ID
  24. UINT16 ip6_un1_plen; // payload length
  25. UINT8 ip6_un1_nxt; // next header
  26. UINT8 ip6_un1_hlim; // hop limit
  27. } ip6_un1;
  28. UINT8 ip6_un2_vfc; // 4 bits version, 4 bits priority
  29. } ip6_ctlun;
  30. IN6_ADDR ip6_src; // source address
  31. IN6_ADDR ip6_dest; // destination address
  32. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  33. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  34. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  35. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  36. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  37. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  38. } IP6_HDR, *PIP6_HDR;
  39. #define IPV6_VERSION 0x60 // This is 6 << 4
  40. #define IPV6_TEREDOMTU 1280
  41. #define IPV6_INFINITE_LIFETIME 0xffffffff
  42. #define IPPROTO_NONE 59
  43. //
  44. // HASHTABLE
  45. //
  46. // Define a simple, statically sized, locked hash table.
  47. // Each bucket is a doubly linked LRU list.
  48. //
  49. #define BUCKET_COUNT 29 // # buckets in the hash table
  50. typedef struct _HASHTABLE {
  51. CRITICAL_SECTION Lock; // Protects the table and entries.
  52. ULONG Size; // # entries in the hash table
  53. LIST_ENTRY Bucket[BUCKET_COUNT];
  54. } HASHTABLE, *PHASHTABLE;
  55. //
  56. // TEREDO_TYPE
  57. //
  58. // Define the type of the teredo service.
  59. //
  60. typedef enum {
  61. TEREDO_DEFAULT = 0,
  62. TEREDO_CLIENT,
  63. TEREDO_SERVER,
  64. TEREDO_DISABLE,
  65. TEREDO_MAXIMUM,
  66. } TEREDO_TYPE, *PTEREDO_TYPE;
  67. //
  68. // TEREDO_PACKET_TYPE
  69. //
  70. // Define the type of a teredo packet.
  71. //
  72. typedef enum {
  73. TEREDO_PACKET_READ, // Data read from TUN device.
  74. TEREDO_PACKET_WRITE, // Data written to TUN device.
  75. TEREDO_PACKET_BUBBLE, // Bubble transmitted on UDP socket.
  76. TEREDO_PACKET_BOUNCE, // Packet bounced on UDP socket.
  77. TEREDO_PACKET_RECEIVE, // Packet received on UDP socket.
  78. TEREDO_PACKET_TRANSMIT, // Packet transmitted on UDP socket.
  79. TEREDO_PACKET_MULTICAST, // Multicast bubble transmitted on UDP socket.
  80. TEREDO_PACKET_MAX,
  81. } TEREDO_PACKET_TYPE, *PTEREDO_PACKET_TYPE;
  82. //
  83. // TEREDO_PACKET
  84. //
  85. // Define a teredo packet.
  86. // The packet structure is followed in memory by the packet's data buffer.
  87. //
  88. typedef struct _TEREDO_PACKET {
  89. #if DBG
  90. ULONG Signature; // TEREDO_PACKET_SIGNATURE
  91. #endif // DBG
  92. OVERLAPPED Overlapped; // For asynchronous completion.
  93. TEREDO_PACKET_TYPE Type; // Packet type.
  94. SOCKADDR_IN SocketAddress; // Peer we are in communication with.
  95. UINT SocketAddressLength; // Length of the peer's socket address.
  96. WSABUF Buffer; // Packet buffer and length.
  97. DWORD Flags; // Flags required during sends and receives.
  98. } TEREDO_PACKET, *PTEREDO_PACKET;
  99. #define TEREDO_PACKET_BUFFER(Packet) \
  100. ((PUCHAR) (((PTEREDO_PACKET) (Packet)) + 1))
  101. typedef
  102. VOID
  103. (TEREDO_REFERENCE)(
  104. VOID
  105. );
  106. typedef TEREDO_REFERENCE *PTEREDO_REFERENCE;
  107. typedef
  108. VOID
  109. (TEREDO_DEREFERENCE)(
  110. VOID
  111. );
  112. typedef TEREDO_DEREFERENCE *PTEREDO_DEREFERENCE;
  113. typedef
  114. VOID
  115. (TEREDO_PACKET_IO_COMPLETE)(
  116. IN DWORD Error,
  117. IN ULONG Bytes,
  118. IN PTEREDO_PACKET Packet
  119. );
  120. typedef TEREDO_PACKET_IO_COMPLETE *PTEREDO_PACKET_IO_COMPLETE;
  121. //
  122. // TEREDO_STATE_TYPE
  123. //
  124. // Define the protocol state values of the teredo client service.
  125. //
  126. typedef enum {
  127. TEREDO_STATE_OFFLINE,
  128. TEREDO_STATE_PROBE,
  129. TEREDO_STATE_QUALIFIED,
  130. TEREDO_STATE_ONLINE,
  131. } TEREDO_STATE_TYPE, *PTEREDO_STATE_TYPE;
  132. //
  133. // TEREDO_IO
  134. //
  135. // Define teredo I/O state.
  136. // NOTE: All addresses and ports are stored in network byte order.
  137. //
  138. typedef struct _TEREDO_IO {
  139. #if DBG
  140. ULONG Signature; // TEREDO_PACKET_SIGNATURE
  141. #endif // DBG
  142. HANDLE PacketHeap; // Head for allocating teredo packets.
  143. ULONG PostedReceives; // Count of posted receives.
  144. HANDLE ReceiveEvent; // Event signalled upon a receive notification.
  145. HANDLE ReceiveEventWait; // Wait registered for ReceiveEvent.
  146. IN_ADDR Group; // Group joined on the native interface.
  147. SOCKADDR_IN ServerAddress; // Teredo server IPv4 address and UDP port.
  148. SOCKADDR_IN SourceAddress; // Preferred source address to teredo server.
  149. SOCKET Socket; // Socket bound to SourceAddress on a UDP port.
  150. HANDLE TunnelDevice; // Interface to the TUNNEL driver.
  151. WCHAR TunnelInterface[MAX_ADAPTER_NAME_LENGTH];
  152. //
  153. // Function handlers.
  154. //
  155. PTEREDO_REFERENCE Reference;
  156. PTEREDO_DEREFERENCE Dereference;
  157. LPOVERLAPPED_COMPLETION_ROUTINE IoCompletionCallback;
  158. } TEREDO_IO, *PTEREDO_IO;
  159. //
  160. // TEREDO_CLIENT_STATE
  161. //
  162. // Define the global state of the teredo client service.
  163. //
  164. // References:
  165. // - One for initialization.
  166. // - One for any running timer.
  167. // - One for each teredo peer.
  168. // - One for each teredo packet
  169. // - One for "the" multicast bubble. At most one outstanding bubble allowed.
  170. // (reads, writes posted on TunDevice & receives, transmits posted on Socket).
  171. //
  172. typedef struct _TEREDO_CLIENT_STATE {
  173. ULONG ReferenceCount; // Number of outstanding references.
  174. TEREDO_IO Io; // I/O state. TUN device and UDP socket.
  175. HANDLE PeerHeap; // Heap for allocating teredo peers.
  176. HANDLE Timer; // One shot timer active in Probe & Qualified.
  177. HANDLE TimerEvent; // Event signalled upon timer deletion.
  178. HANDLE TimerEventWait; // Wait registered for TimerEvent.
  179. BOOL RestartQualifiedTimer; // When NAT mapping is created or refreshed.
  180. LONG Time; // Current time (in seconds).
  181. TEREDO_STATE_TYPE State; // Teredo client service protocol state.
  182. IN6_ADDR Ipv6Prefix; // Teredo IPv6 prefix advertised by server.
  183. ULONG RefreshInterval; // Expected lifetime of client's NAT mapping.
  184. HASHTABLE PeerSet; // Locked set of recent teredo peers.
  185. ULONG BubbleTicks; // "RefreshInterval" ticks until next bubble.
  186. BOOL BubblePosted; // Whether there is any outstanding bubble.
  187. TEREDO_PACKET Packet; // Teredo multicast bubble packet.
  188. IP6_HDR Bubble; // Teredo multicast bubble packet buffer.
  189. } TEREDO_CLIENT_STATE, *PTEREDO_CLIENT_STATE;
  190. //
  191. // TEREDO_SERVER_STATE
  192. //
  193. // Define the global state of the teredo server service.
  194. //
  195. // References:
  196. // - One for initialization.
  197. // - One for each teredo packet
  198. // (reads, writes posted on TunDevice & receives, transmits posted on Socket).
  199. //
  200. typedef struct _TEREDO_SERVER_STATE {
  201. ULONG ReferenceCount; // Number of outstanding references.
  202. TEREDO_IO Io; // I/O state. TUN device and UDP socket.
  203. TEREDO_STATE_TYPE State; // Teredo server service protocol state.
  204. } TEREDO_SERVER_STATE, *PTEREDO_SERVER_STATE;
  205. //
  206. // TEREDO_PEER
  207. //
  208. // Define a teredo peer's state.
  209. //
  210. // References:
  211. // - One for initialization.
  212. // - One for "the" posted bubble. At most one outstanding bubble is allowed.
  213. //
  214. // Synchronization:
  215. // - Link: Protected by PeerSet::Lock.
  216. // - ReferenceCount: InterlockedIncrement, InterlockedDecrement.
  217. // - LastReceive, LastTransmit: Atomic reads and writes.
  218. // - BubbleCount: Single writer! Atomic reads.
  219. // - BubblePosted: InterlockedExchange.
  220. // - Remaining Fields: Read only.
  221. //
  222. typedef struct _TEREDO_PEER {
  223. #if DBG
  224. ULONG Signature; // TEREDO_PEER_SIGNATURE
  225. #endif // DBG
  226. LIST_ENTRY Link; // Linkage within the PeerSet.
  227. ULONG ReferenceCount; // Number of outstanding references.
  228. LONG LastReceive; // Time of last reception from the peer.
  229. LONG LastTransmit; // Time of last transmission to the peer.
  230. IN6_ADDR Address; // Teredo IPv6 address of the peer.
  231. ULONG BubbleCount; // Number of bubbles transmitted to the peer.
  232. BOOL BubblePosted; // Whether there is any outstanding bubble.
  233. TEREDO_PACKET Packet; // Teredo bubble packet.
  234. IP6_HDR Bubble; // Teredo bubble packet buffer.
  235. } TEREDO_PEER, *PTEREDO_PEER;
  236. //
  237. // Cast and Signature Verification
  238. //
  239. #define TEREDO_IO_SIGNATURE 'oIhS' // 'ShIo'
  240. #define TEREDO_PEER_SIGNATURE 'ePhS' // 'ShPe'
  241. #define TEREDO_PACKET_SIGNATURE 'aPhS' // 'ShPa'
  242. //
  243. // A NULL handle is considered a valid structure.
  244. //
  245. #define Cast(Pointer, TYPE) \
  246. ((TYPE *) (Pointer)); \
  247. ASSERT(!(Pointer) || \
  248. (((TYPE *) (Pointer))->Signature == TYPE##_SIGNATURE))
  249. //
  250. // Lower and upper limits on number of posted reads or receives.
  251. //
  252. #define TEREDO_LOW_WATER_MARK 5 // Receives or Reads.
  253. #define TEREDO_HIGH_WATER_MARK 256 // Receives. Reads are fixed.
  254. //
  255. // Intervals used by the protocol.
  256. //
  257. #define INFINITE_INTERVAL 0x7fffffff
  258. #define TEREDO_RESOLVE_INTERVAL 15 * MINUTES
  259. #define TEREDO_PROBE_INTERVAL 15 * SECONDS
  260. #define TEREDO_REFRESH_INTERVAL 30 * SECONDS
  261. #define TEREDO_MULTICAST_BUBBLE_TICKS 0 // In RefreshInterval units.
  262. #define TEREDO_BUBBLE_INTERVAL 10 * SECONDS
  263. #define TEREDO_SLOW_BUBBLE_INTERVAL 5 * MINUTES
  264. #define TEREDO_BUBBLE_THRESHHOLD 2 * MINUTES
  265. #define TEREDO_ROUTER_LIFETIME 5 * HOURS
  266. //
  267. // Teredo multicast bubbles are sent to group 224.0.0.252 on port 337.
  268. //
  269. #define TEREDO_MULTICAST_PREFIX \
  270. { 0x20, 0x03, 0xe0, 0x00, 0x00, 0xfc, 0x01, 0x51, }
  271. #define TEREDO_DEFAULT_TYPE TEREDO_DISABLE
  272. #define TEREDO_PORT htons(337)
  273. #define TEREDO_SERVER_NAME L"teredo.ipv6.microsoft.com"
  274. #define TEREDO_SERVICE_PREFIX { 0x20, 0x03, }
  275. #define KEY_TEREDO_REFRESH_INTERVAL L"RefreshInterval"
  276. #define KEY_TEREDO_TYPE L"Type"
  277. #define KEY_TEREDO_SERVER_NAME L"ServerName"
  278. #define KEY_TEREDO L"System\\CurrentControlSet\\Services\\Teredo"
  279. //
  280. // Configured parameters.
  281. //
  282. extern ULONG TeredoClientRefreshInterval;
  283. extern BOOL TeredoClientEnabled;
  284. extern BOOL TeredoServerEnabled;
  285. extern WCHAR TeredoServerName[NI_MAXHOST];
  286. extern WCHAR TeredoServiceName[NI_MAXSERV];
  287. extern CONST IN6_ADDR TeredoIpv6ServicePrefix;
  288. extern CONST IN6_ADDR TeredoIpv6MulticastPrefix;
  289. extern TEREDO_CLIENT_STATE TeredoClient;
  290. extern TEREDO_SERVER_STATE TeredoServer;
  291. //
  292. // Time.
  293. //
  294. __inline
  295. LONG
  296. TeredoGetTime(
  297. VOID
  298. )
  299. {
  300. //
  301. // GetTickCount retrieves time in milliseconds.
  302. //
  303. return (GetTickCount() / 1000);
  304. }
  305. #define TIME_GREATER(a, b) (((a) - (b)) > 0)
  306. //
  307. // Address validation and parsing.
  308. //
  309. __inline
  310. BOOL
  311. IN4_MULTICAST(IN_ADDR a)
  312. {
  313. return ((a.s_addr & 0x0000000f) == 0x0000000e);
  314. }
  315. _inline
  316. BOOL
  317. IN4_ADDR_EQUAL(IN_ADDR a, IN_ADDR b)
  318. {
  319. return (a.s_addr == b.s_addr);
  320. }
  321. _inline
  322. BOOL
  323. IN4_SOCKADDR_EQUAL(CONST SOCKADDR_IN *a, CONST SOCKADDR_IN *b)
  324. {
  325. ASSERT((a->sin_family == AF_INET) && (b->sin_family == AF_INET));
  326. return (IN4_ADDR_EQUAL(a->sin_addr, b->sin_addr) &&
  327. (a->sin_port == b->sin_port));
  328. }
  329. __inline
  330. BOOL
  331. TeredoIpv6GlobalAddress(
  332. IN CONST IN6_ADDR *Address
  333. )
  334. /*++
  335. Routine Description:
  336. Determine whether the supplied IPv6 address is of global unicast scope.
  337. --*/
  338. {
  339. //
  340. // This can be coded quite a bit more efficiently!
  341. //
  342. if (IN6_IS_ADDR_UNSPECIFIED(Address) ||
  343. IN6_IS_ADDR_LOOPBACK(Address) ||
  344. IN6_IS_ADDR_MULTICAST(Address) ||
  345. IN6_IS_ADDR_LINKLOCAL(Address) ||
  346. IN6_IS_ADDR_SITELOCAL(Address)) {
  347. return FALSE;
  348. }
  349. return TRUE;
  350. }
  351. __inline
  352. BOOL
  353. TeredoIpv4GlobalAddress(
  354. IN CONST UCHAR *Address
  355. )
  356. /*++
  357. Routine Description:
  358. Determine whether the supplied IPv4 address is of global unicast scope.
  359. --*/
  360. {
  361. if ((Address[0] > 223) || // ~Unicast
  362. (Address[0] == 0) || // 0/8
  363. (Address[0] == 127) || // 127/8
  364. (Address[0] == 10) || // 10/8
  365. ((Address[0] == 169) && (Address[1] == 254)) || // 169.254/16
  366. ((Address[0] == 172) && ((Address[1] & 0xf0) == 16)) || // 172.16/12
  367. ((Address[0] == 192) && (Address[1] == 168))) { // 192.168/16
  368. return FALSE;
  369. }
  370. return TRUE;
  371. }
  372. __inline
  373. BOOL
  374. TeredoServicePrefix(
  375. IN CONST IN6_ADDR *Address
  376. )
  377. {
  378. return (Address->s6_words[0] == TeredoIpv6ServicePrefix.s6_words[0]);
  379. }
  380. __inline
  381. BOOL
  382. TeredoValidAdvertisedPrefix(
  383. IN CONST IN6_ADDR *Address,
  384. IN UCHAR Length
  385. )
  386. {
  387. if (Length != 64) {
  388. return FALSE;
  389. }
  390. if (!TeredoServicePrefix(Address)) {
  391. return FALSE;
  392. }
  393. if (!TeredoIpv4GlobalAddress((PUCHAR) (Address->s6_words + 1))) {
  394. return FALSE;
  395. }
  396. return TRUE;
  397. }
  398. __inline
  399. VOID
  400. TeredoParseAddress(
  401. IN CONST IN6_ADDR *Address,
  402. OUT PIN_ADDR Ipv4Address,
  403. OUT PUSHORT Ipv4Port
  404. )
  405. {
  406. ASSERT(TeredoServicePrefix(Address));
  407. //
  408. // These are returned in network byte order.
  409. //
  410. ((PUSHORT) Ipv4Address)[0] = Address->s6_words[1];
  411. ((PUSHORT) Ipv4Address)[1] = Address->s6_words[2];
  412. *Ipv4Port = Address->s6_words[3];
  413. }
  414. __inline
  415. BOOL
  416. TeredoEqualPrefix(
  417. IN CONST IN6_ADDR *Address1,
  418. IN CONST IN6_ADDR *Address2
  419. )
  420. {
  421. //
  422. // Compare Teredo IPv6 Service Prefix, Mapped IPv4 Address and Port.
  423. //
  424. return ((Address1->s6_words[0] == Address2->s6_words[0]) &&
  425. (Address1->s6_words[1] == Address2->s6_words[1]) &&
  426. (Address1->s6_words[2] == Address2->s6_words[2]) &&
  427. (Address1->s6_words[3] == Address2->s6_words[3]));
  428. }
  429. //
  430. // Client API
  431. //
  432. DWORD
  433. TeredoInitializeClient(
  434. VOID
  435. );
  436. VOID
  437. TeredoUninitializeClient(
  438. VOID
  439. );
  440. VOID
  441. TeredoCleanupClient(
  442. VOID
  443. );
  444. __inline
  445. VOID
  446. TeredoReferenceClient(
  447. VOID
  448. )
  449. {
  450. ASSERT(TeredoClient.ReferenceCount > 0);
  451. InterlockedIncrement(&(TeredoClient.ReferenceCount));
  452. }
  453. __inline
  454. VOID
  455. TeredoDereferenceClient(
  456. VOID
  457. )
  458. {
  459. ASSERT(TeredoClient.ReferenceCount > 0);
  460. if (InterlockedDecrement(&(TeredoClient.ReferenceCount)) == 0) {
  461. TeredoCleanupClient();
  462. }
  463. }
  464. VOID
  465. TeredoStartClient(
  466. VOID
  467. );
  468. VOID
  469. TeredoStopClient(
  470. VOID
  471. );
  472. VOID
  473. TeredoProbeClient(
  474. VOID
  475. );
  476. VOID
  477. TeredoQualifyClient(
  478. VOID
  479. );
  480. VOID
  481. TeredoClientAddressDeletionNotification(
  482. IN IN_ADDR Address
  483. );
  484. VOID
  485. TeredoClientRefreshIntervalChangeNotification(
  486. VOID
  487. );
  488. //
  489. // Server API
  490. //
  491. DWORD
  492. TeredoInitializeServer(
  493. VOID
  494. );
  495. VOID
  496. TeredoUninitializeServer(
  497. VOID
  498. );
  499. VOID
  500. TeredoCleanupServer(
  501. VOID
  502. );
  503. __inline
  504. VOID
  505. TeredoReferenceServer(
  506. VOID
  507. )
  508. {
  509. ASSERT(TeredoServer.ReferenceCount > 0);
  510. InterlockedIncrement(&(TeredoServer.ReferenceCount));
  511. }
  512. __inline
  513. VOID
  514. TeredoDereferenceServer(
  515. VOID
  516. )
  517. {
  518. ASSERT(TeredoServer.ReferenceCount > 0);
  519. if (InterlockedDecrement(&(TeredoServer.ReferenceCount)) == 0) {
  520. TeredoCleanupServer();
  521. }
  522. }
  523. VOID
  524. TeredoStartServer(
  525. VOID
  526. );
  527. VOID
  528. TeredoStopServer(
  529. VOID
  530. );
  531. VOID
  532. TeredoServerAddressDeletionNotification(
  533. IN IN_ADDR Address
  534. );
  535. //
  536. // Common API
  537. //
  538. DWORD
  539. TeredoInitializeGlobals(
  540. VOID
  541. );
  542. VOID
  543. TeredoUninitializeGlobals(
  544. VOID
  545. );
  546. VOID
  547. TeredoAddressChangeNotification(
  548. IN BOOL Delete,
  549. IN IN_ADDR Address
  550. );
  551. VOID
  552. TeredoConfigurationChangeNotification(
  553. VOID
  554. );
  555. VOID
  556. WINAPI
  557. TeredoWmiEventNotification(
  558. IN PWNODE_HEADER Event,
  559. IN UINT_PTR Context
  560. );
  561. //
  562. // Peer API.
  563. //
  564. DWORD
  565. TeredoInitializePeerSet(
  566. VOID
  567. );
  568. VOID
  569. TeredoUninitializePeerSet(
  570. VOID
  571. );
  572. VOID
  573. TeredoCleanupPeerSet(
  574. VOID
  575. );
  576. PTEREDO_PEER
  577. TeredoFindOrCreatePeer(
  578. IN CONST IN6_ADDR *Address
  579. );
  580. VOID
  581. TeredoDestroyPeer(
  582. IN PTEREDO_PEER Peer
  583. );
  584. __inline
  585. VOID
  586. TeredoReferencePeer(
  587. IN PTEREDO_PEER Peer
  588. )
  589. {
  590. ASSERT(Peer->ReferenceCount > 0);
  591. InterlockedIncrement(&(Peer->ReferenceCount));
  592. }
  593. __inline
  594. VOID
  595. TeredoDereferencePeer(
  596. IN PTEREDO_PEER Peer
  597. )
  598. {
  599. ASSERT(Peer->ReferenceCount > 0);
  600. if (InterlockedDecrement(&(Peer->ReferenceCount)) == 0) {
  601. TeredoDestroyPeer(Peer);
  602. }
  603. }
  604. //
  605. // I/O API.
  606. //
  607. DWORD
  608. TeredoInitializeIo(
  609. IN PTEREDO_IO TeredoIo,
  610. IN IN_ADDR Group,
  611. IN PTEREDO_REFERENCE Reference,
  612. IN PTEREDO_DEREFERENCE Dereference,
  613. IN LPOVERLAPPED_COMPLETION_ROUTINE IoCompletionCallback
  614. );
  615. VOID
  616. TeredoCleanupIo(
  617. IN PTEREDO_IO TeredoIo
  618. );
  619. DWORD
  620. TeredoStartIo(
  621. IN PTEREDO_IO TeredoIo
  622. );
  623. DWORD
  624. TeredoRefreshSocket(
  625. IN PTEREDO_IO TeredoIo
  626. );
  627. VOID
  628. TeredoStopIo(
  629. IN PTEREDO_IO TeredoIo
  630. );
  631. __inline
  632. VOID
  633. TeredoInitializePacket(
  634. IN PTEREDO_PACKET Packet
  635. )
  636. {
  637. #if DBG
  638. Packet->Signature = TEREDO_PACKET_SIGNATURE;
  639. #endif // DBG
  640. ZeroMemory(&(Packet->SocketAddress), sizeof(SOCKADDR_IN));
  641. Packet->SocketAddress.sin_family = AF_INET;
  642. Packet->SocketAddressLength = sizeof(SOCKADDR_IN);
  643. Packet->Flags = 0;
  644. Packet->Buffer.buf = TEREDO_PACKET_BUFFER(Packet);
  645. }
  646. ULONG
  647. TeredoPostReceives(
  648. IN PTEREDO_IO TeredoIo,
  649. IN PTEREDO_PACKET Packet
  650. );
  651. PTEREDO_PACKET
  652. TeredoTransmitPacket(
  653. IN PTEREDO_IO TeredoIo,
  654. IN PTEREDO_PACKET Packet
  655. );
  656. BOOL
  657. TeredoPostRead(
  658. IN PTEREDO_IO TeredoIo,
  659. IN PTEREDO_PACKET Packet OPTIONAL
  660. );
  661. PTEREDO_PACKET
  662. TeredoWritePacket(
  663. IN PTEREDO_IO TeredoIo,
  664. IN PTEREDO_PACKET Packet
  665. );
  666. //
  667. // Utility Functions.
  668. //
  669. ICMPv6Header *
  670. TeredoParseIpv6Headers(
  671. IN PUCHAR Buffer,
  672. IN ULONG Bytes
  673. );
  674. #endif // _TEREDO_