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.

139 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. Loopback.c
  5. Abstract:
  6. This file contains the procedures for doing loopback of send
  7. packets for ndiswan. Loopback is being done in NdisWan because
  8. the NDIS wrapper could not meet all of the needs of NdisWan.
  9. Author:
  10. Tony Bell (TonyBe) January 25, 1996
  11. Environment:
  12. Kernel Mode
  13. Revision History:
  14. TonyBe 01/25/96 Created
  15. --*/
  16. #include "wan.h"
  17. #define __FILE_SIG__ LOOPBACK_FILESIG
  18. VOID
  19. NdisWanIndicateLoopbackPacket(
  20. PMINIPORTCB MiniportCB,
  21. PNDIS_PACKET NdisPacket
  22. )
  23. {
  24. ULONG BytesCopied, PacketLength;
  25. PRECV_DESC RecvDesc;
  26. PNDIS_PACKET LocalNdisPacket;
  27. PNDIS_BUFFER NdisBuffer;
  28. NDIS_STATUS Status;
  29. PCM_VCCB CmVcCB;
  30. KIRQL OldIrql;
  31. NdisWanDbgOut(DBG_TRACE, DBG_LOOPBACK, ("NdisWanIndicateLoopbackPacket: Enter"));
  32. NdisWanDbgOut(DBG_INFO, DBG_LOOPBACK, ("MiniportCB: 0x%p, NdisPacket: 0x%p",
  33. MiniportCB, NdisPacket));
  34. NdisQueryPacket(NdisPacket,
  35. NULL,
  36. NULL,
  37. NULL,
  38. &PacketLength);
  39. RecvDesc =
  40. NdisWanAllocateRecvDesc(PacketLength);
  41. if (RecvDesc == NULL) {
  42. return;
  43. }
  44. NdisWanCopyFromPacketToBuffer(NdisPacket,
  45. 0,
  46. PacketLength,
  47. RecvDesc->StartBuffer,
  48. &BytesCopied);
  49. ASSERT(BytesCopied == PacketLength);
  50. if (MiniportCB->ProtocolType == PROTOCOL_IP) {
  51. UCHAR x[ETH_LENGTH_OF_ADDRESS];
  52. //
  53. // If this is IP we are going to assume
  54. // that wanarp has set the appropriate
  55. // bit requiring ndiswan to loopback the
  56. // packet so we must switch the src/dest
  57. // contexts.
  58. ETH_COPY_NETWORK_ADDRESS(x, &RecvDesc->StartBuffer[6]);
  59. ETH_COPY_NETWORK_ADDRESS(&RecvDesc->StartBuffer[6],
  60. &RecvDesc->StartBuffer[0]);
  61. ETH_COPY_NETWORK_ADDRESS(&RecvDesc->StartBuffer[0], x);
  62. }
  63. RecvDesc->CurrentLength = PacketLength;
  64. LocalNdisPacket =
  65. RecvDesc->NdisPacket;
  66. NdisBuffer =
  67. RecvDesc->NdisBuffer;
  68. //
  69. // Attach the buffers
  70. //
  71. NdisAdjustBufferLength(NdisBuffer,
  72. RecvDesc->CurrentLength);
  73. NdisRecalculatePacketCounts(LocalNdisPacket);
  74. CmVcCB =
  75. PMINIPORT_RESERVED_FROM_NDIS(NdisPacket)->CmVcCB;
  76. KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
  77. NDIS_SET_PACKET_STATUS(LocalNdisPacket, NDIS_STATUS_RESOURCES);
  78. INSERT_DBG_RECV(PacketTypeNdis, MiniportCB, NULL, NULL, LocalNdisPacket);
  79. //
  80. // Indicate the packet
  81. //
  82. if (CmVcCB != NULL) {
  83. NdisMCoIndicateReceivePacket(CmVcCB->NdisVcHandle,
  84. &LocalNdisPacket,
  85. 1);
  86. } else {
  87. NdisMIndicateReceivePacket(MiniportCB->MiniportHandle,
  88. &LocalNdisPacket,
  89. 1);
  90. }
  91. KeLowerIrql(OldIrql);
  92. #if DBG
  93. Status = NDIS_GET_PACKET_STATUS(LocalNdisPacket);
  94. ASSERT(Status == NDIS_STATUS_RESOURCES);
  95. #endif
  96. REMOVE_DBG_RECV(PacketTypeNdis, MiniportCB, LocalNdisPacket);
  97. NdisWanFreeRecvDesc(RecvDesc);
  98. NdisWanDbgOut(DBG_TRACE, DBG_LOOPBACK, ("NdisWanIndicateLoopbackPacket: Exit"));
  99. }