基于ndis的防火墙源码供大家赏析firewall.c

基于ndis的防火墙源码供大家赏析firewall c 阅读详情

 #include "precomp.h"
#pragma hdrstop

#pragma NDIS_INIT_FUNCTION(DriverEntry)

NDIS_PHYSICAL_ADDRESS         HighestAcceptableMax = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);

NDIS_MEDIUM                           MediumArray[3] =
                                         {
                                        NdisMedium802_3,      // Ethernet
                                            NdisMedium802_5,      // Token-ring
                                        NdisMediumFddi            // Fddi
                                         };

//
// g_GlobalLock - Protects resources
//
NDIS_SPIN_LOCK         g_GlobalLock;

//
// g_ProtocolHandle - handle returned by NDIS when registering the protocol portion of the IM
//
NDIS_HANDLE                           g_ProtocolHandle = NULL;

//
// g_MiniportHandle - handle returned by NDIS when MP portion registers as LM
//
NDIS_HANDLE                           g_MiniportHandle   = NULL;

//
// g_AdapterList - List of adapters to which the NetWall is bound
//
PADAPT               g_AdapterList     = NULL;

//
// g_DriverObject - pointer to NT driver and device objects
//
PDRIVER_OBJECT         g_DriverObject     = NULL;


/**
* Routine Description:
*
*   This is the primary initialization routine for the NetWall IM driver.
*   It is simply responsible for the intializing the wrapper and registering
*   the Miniport and Protocol driver.
*
* Arguments:
*
*       IN DriverObject - Pointer to driver object created by the system.
*   IN RegistryPath - Registry path string for driver service key
*
* Return Value:
*
*   The status of the operation.
*/
NTSTATUS
DriverEntry(
     IN      PDRIVER_OBJECT            DriverObject,
     IN      PUNICODE_STRING            RegistryPath
     )
{
     NDIS_STATUS                                    Status;
     NDIS_PROTOCOL_CHARACTERISTICS      PChars;
     NDIS_MINIPORT_CHARACTERISTICS      MChars;
     NDIS_STRING               protoName;      
  UNICODE_STRING             ntDeviceName;
  UNICODE_STRING             win32DeviceName;
     NDIS_HANDLE                                    WrapperHandle;
  UINT                   FuncIndex   = 0;

  DBGPRINT("===> NetWall - DriverEntry/n");
 
  DbgPrint("=== RegistryPath is : %ws ===/n", RegistryPath->Buffer);

  g_DriverObject = DriverObject;

  //
  // Initialize Global Lock
  //
  NdisAllocateSpinLock(&g_GlobalLock);  

  do
  {
        //
    // 1. Register the miniport with NDIS. Note that it is the miniport
        //   which was started as a driver and not the protocol. Also the miniport
        //   must be registered prior to the protocol since the protocol's BindAdapter
        //   handler can be initiated anytime and when it is, it must be ready to
        //   start driver instances.
        //
        NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);

    //
    // 2. Perform IM Driver's Miniport Initialization
    //
        NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS));

        MChars.MajorNdisVersion       = 4;
        MChars.MinorNdisVersion       = 0;

        MChars.InitializeHandler     = MPInitialize;
        MChars.QueryInformationHandler = MPQueryInformation;
        MChars.SetInformationHandler   = MPSetInformation;
        MChars.ResetHandler         = MPReset;
        MChars.TransferDataHandler     = MPTransferData;
        MChars.HaltHandler         = MPHalt;

        //
        // We will disable the check for hang timeout so we do not
        // need a check for hang handler!
        //
        MChars.CheckForHangHandler     = NULL;
        MChars.SendHandler         = MPSend;
        MChars.ReturnPacketHandler     = MPReturnPacket;

        //
        // Either the Send or the SendPackets handler should be specified.
        // If SendPackets handler is specified, SendHandler is ignored
        //
        MChars.SendPacketsHandler     = NULL;//MPSendPackets;

        Status = NdisIMRegisterLayeredMiniport(WrapperHandle,
                                                                &MChars,
                                                                sizeof(MChars),
                                                                &g_MiniportHandle);
        if (! NT_SUCCESS(Status))
    {
        DbgPrint("MPRegisterAsMiniport Failed! Status: 0x%x/n", Status);

        NdisWriteErrorLogEntry(
                    DriverObject,
                    (ULONG)IM_ERROR_IM_REGISTER_FAILED,
                    0,
                    1,
                    (ULONG )Status);
        break;
    }

    //
    // 3. Perform initialization supported by WDM
    //
    // Create a control device object for this driver.
    // Application can send an IOCTL to this device to get
    // bound adapter information.
    //
    //

    DBGPRINT("===> NetWall - NdisWDMInitialize/n");

        NdisAcquireSpinLock(&g_GlobalLock); // sync

        ++g_MiniportCount;
       
        if (1 == g_MiniportCount)
    {
              ASSERT(g_DeviceState != PS_DEVICE_STATE_CREATING); //
   
              while (g_DeviceState != PS_DEVICE_STATE_READY)
              {
                    NdisReleaseSpinLock(&g_GlobalLock);
                    NdisMSleep(1); // Waiting
                    NdisAcquireSpinLock(&g_GlobalLock);
              }
              g_DeviceState = PS_DEVICE_STATE_CREATING;

              // Now Can Create Device, Call NdisMRegisterDevice
              NdisReleaseSpinLock(&g_GlobalLock);
             
        //
        // Initialize The Driver's Default Device Function Handlers
        // --------------------------------------------------------
        // Actually, we are re-initializing the MajorFunction table that
        // has already been initialized by the NDIS wrapper.
        //
              DriverObject->FastIoDispatch = NULL;
        for (FuncIndex = 0; FuncIndex <= IRP_MJ_MAXIMUM_FUNCTION; FuncIndex++)
              {
          //
          // Save The Original MajorFunction Table
          // -------------------------------------
          // At this point the NDIS wrapper has ALREADY initialized the
          // g_DriverObject MajorFunction table and created a DeviceObject for
          // the miniport. Save the NDIS MajorFunction table entries.
          //
                    NdisFunctionTable[FuncIndex]               = DriverObject->MajorFunction[FuncIndex];
       
          //
          // Setup Our MajorFunction Table
          //
          g_DriverObject->MajorFunction[FuncIndex]       = NetWall_DefaultFunctionDispatch;
              }

        //
        // Specify Functions To Dispatch Directly
        //
          g_DriverObject->MajorFunction[IRP_MJ_CREATE]       = NetWall_DeviceCreate;
          g_DriverObject->MajorFunction[IRP_MJ_CLOSE]       = NetWall_DeviceClose;
          g_DriverObject->MajorFunction[IRP_MJ_CLEANUP]     = NetWall_DeviceCleanup;
          g_DriverObject->MajorFunction[IRP_MJ_WRITE]       = NetWall_DeviceWrite;
          g_DriverObject->MajorFunction[IRP_MJ_READ]       = NetWall_DeviceRead;
          g_DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NetWall_DeviceIoControl;
              g_DriverObject->DriverUnload                 = NetWall_DeviceUnload;

        RtlInitUnicodeString(&ntDeviceName,   NETWALL_WDM_DEVICE_NAME_W);
        RtlInitUnicodeString(&win32DeviceName, NETWALL_WDM_SYMBOLIC_LINK_W);
        //
        // Create The "WDM Interface"
        // --------------------------
        // Creating the driver device object and sumbolic link and implementing
        // an I/O function dispatcher provides the mechanism for a Win32
        // application to communicate with the driver. This is sometines
        // described as a "WDM interface".
        //
          Status = NdisMRegisterDevice(WrapperHandle,
                          &ntDeviceName,       // /Device/DeviceName
                          &win32DeviceName,     // /DosDevices/SymbolicName
                          g_DriverObject->MajorFunction,
                          &g_DeviceObject,
                          &g_DeviceHandle
                          );

        if (NT_SUCCESS(Status))
        {
          g_DeviceObject->Flags |= DO_BUFFERED_IO;
        }
        if (!NT_SUCCESS(Status))
        {
          DbgPrint("NdisMRegisterDevice Failed - %08x/n", Status);
          g_DeviceObject = NULL;
          break;
        }

              NdisAcquireSpinLock(&g_GlobalLock); // Acquire spin Lock
              g_DeviceState = PS_DEVICE_STATE_READY;        
        }
       
        NdisReleaseSpinLock(&g_GlobalLock);

        DBGPRINT("<=== NetWall - NdisWDMInitialize /n");


        NdisMRegisterUnloadHandler(WrapperHandle, PtUnload);

    //
    // 4. Perform IM Driver's Protocol Initialization
    //
     
        NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
       
    PChars.MajorNdisVersion         = 4;
        PChars.MinorNdisVersion         = 0;

        //
        // Make sure the protocol-name matches the service-name under which this protocol is installed.
        // This is needed to ensure that NDIS can correctly determine the binding and call us to bind
        // to miniports below.
        //        
    NdisInitUnicodeString(&protoName, L"NetWall");
        PChars.Name                 = protoName;
        PChars.OpenAdapterCompleteHandler   = PtOpenAdapterComplete;
        PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete;
        PChars.SendCompleteHandler       = PtSendComplete;
        PChars.TransferDataCompleteHandler = PtTransferDataComplete;
       
        PChars.ResetCompleteHandler       = PtResetComplete;
        PChars.RequestCompleteHandler     = PtRequestComplete;
        PChars.ReceiveHandler           = PtReceive;
        PChars.ReceiveCompleteHandler     = PtReceiveComplete;
        PChars.StatusHandler           = PtStatus;
        PChars.StatusCompleteHandler     = PtStatusComplete;
        PChars.BindAdapterHandler       = PtBindAdapter;
        PChars.UnbindAdapterHandler       = PtUnbindAdapter;
        PChars.UnloadHandler           = NULL;
        PChars.ReceivePacketHandler       = PtReceivePacket;
        PChars.PnPEventHandler         = PtPNPHandler;

        NdisRegisterProtocol(&Status,
                                      &g_ProtocolHandle,
                                      &PChars,
                                      sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        if (! NT_SUCCESS(Status))
    {
        DbgPrint("PtRegisterAsProtocol Failed! Status: 0x%x/n", Status);

        NdisWriteErrorLogEntry(
                    DriverObject,
                    EVENT_TRANSPORT_REGISTER_FAILED,
                    IM_ERROR_PROTOCOL_INIT,
                    1,
                    L"NETWALL",
                    sizeof(Status),
                    &Status);
        break;
    }

    //
    // 5. Associate Miniport & Protocol, informs NDIS that the specified lower and upper interfaces for miniport and protocol respectively belong to the same intermediate driver.
    //
        NdisIMAssociateMiniport(g_MiniportHandle, g_ProtocolHandle);

    DBGPRINT("<=== NetWall - DriverEntry Success. ===/n");
    return Status;

  } while (FALSE);

  //
  // Cleanup after a error that causes DriverEntry to fail.
  //

  if (g_DeviceObject)
  {
    NdisMDeregisterDevice(g_DeviceHandle);
  }

  //
  // Deregister the protocol; we should have no references that would cause
  // this to pend
  //
  if (g_ProtocolHandle)
  {
    NdisDeregisterProtocol(&Status, g_ProtocolHandle);

    if (Status == NDIS_STATUS_PENDING)
    {
        DbgPrint("Client DeregProto failed - %08X/n", Status);
    }
  }

  //
  // Terminate the wrapper
  //
  if (WrapperHandle)
  {
    NdisTerminateWrapper(WrapperHandle, NULL);
  }

  //
  // Free our global locks
  //
  NdisFreeSpinLock(&g_GlobalLock);
 
  DBGPRINT("<=== NetWall - DriverEntry Failed. ===/n");

     return (STATUS_UNSUCCESSFUL);
}

------------------

#include "precomp.h"
#pragma hdrstop

/**
* Routine Description:
*
*   PtReceive determines whether a received network packet is of
*   interest to the protocol's client(s) and, if so, copies the indicated
*   data and, possibly, calls NdisTransferData to retrieve the rest of
*   the indicated packet.
*
*   If the data passed to ProtocolReceive was indicated by a call to NdisMXxxIndicateReceive,
*   the size of the lookahead buffer passed to ProtocolReceive is <= the size returned by a
*   call to NdisRequest with OID_GEN_CURRENT_LOOKAHEAD. All data in the lookahead buffer is
*   read-only to the intermediate driver. If the call to ProtocolReceive occurred because
*   the underlying NIC driver set the status of one or more packets in a packet array to
*   NDIS_STATUS_RESOURCES before calling NdisMIndicateReceivePacket, the size of the lookahead
*   buffer will always be equal to the size of the full network packet so the intermediate
*   driver need not call NdisTransferData.
*
*   If PacketSize is less than or equal to the given LookaheadBufferSize,
*   the lookahead buffer contains the entire packet. If the underlying
*   driver made the indication with NdisMIndicateReceivePacket, the
*   lookahead buffer always contains a full network packet.
*   Otherwise, Protocol must call NdisTransferData to copy any remaining data .
*
*   LBFO - need to use primary for all receives
*
* Arguments:
*
*   IN ProtocolBindingContext - Pointer to the adapter
*       IN MacReceiveContext     - Specifies a context handle that the underlying NIC driver associates with the packet received from the network.
*       IN HeaderBuffer         - Points to the base virtual address of a range containing the buffered packet header.
*       IN HeaderBufferSize     - Specifies the number of bytes in the packet header.
*       IN LookAheadBuffer       - Points to the base virtual address of a range that contains LookaheadBufferSize bytes of buffered network packet data.
*       IN LookAheadBufferSize   - Specifies the number of bytes of network packet data in the lookahead buffer.
*       IN PacketSize         - Specifies the size, in bytes, of the network packet data. The length of the packet does not include the length of the header.
*
* Return Value:
*
*   NDIS_STATUS
*
* Remarks :
*
*   The ProtocolReceive function of an NDIS intermediate driver cannot simply
*   forward receive indications to still higher-level protocols. Such an
*   attempt can cause a deadlock.
*
*   The NDIS intermediate driver must repackage the indication in a fresh
*   packet descriptor.
*
*   By default, ProtocolReceive runs at IRQL DISPATCH_LEVEL in an arbitrary
*   thread context.
*/
NDIS_STATUS
PtReceive(
     IN NDIS_HANDLE                  ProtocolBindingContext,
     IN NDIS_HANDLE                  MacReceiveContext,
     IN PVOID                        HeaderBuffer,
     IN UINT                        HeaderBufferSize,
     IN PVOID                        LookAheadBuffer,
     IN UINT                        LookAheadBufferSize,
     IN UINT                        PacketSize
)
{
     PADAPT                  pAdapt = (PADAPT)ProtocolBindingContext;
     PNDIS_PACKET      MyPacket, Packet;
     NDIS_STATUS            Status = NDIS_STATUS_SUCCESS;

  NETWALL_RCV_FILTER_ACTION   FilterAction = RCV_FILTER_ACTION_PASS_PACKET;

     DBGPRINT("===> NetWall - PtReceive/n");
           
  //-----------------------------------------------
     if (! pAdapt->MiniportHandle)
     {
           Status = NDIS_STATUS_FAILURE;
     }
     else do
     {    
    FilterAction = NetWall_FilterReceive(
                      pAdapt,
                      MacReceiveContext,
                      (PCHAR)HeaderBuffer,
                      HeaderBufferSize,
                      (PCHAR)LookAheadBuffer,
                      LookAheadBufferSize,
                      PacketSize,
                      NETWALL_DIRECTION_IN
                    );

    if (FilterAction == RCV_FILTER_ACTION_REJECT_PACKET)
    {
        DBGPRINT("<=== NetWall - PtReceive -> RCV_FILTER_ACTION_REJECT_PACKET/n");
        return NDIS_STATUS_NOT_ACCEPTED;
    }
         
    //
           // We should not be getting Receives on a Secondary, this is just specific to our LBFO driver
           //
           if (pAdapt->isSecondary)
           {
                  DBGPRINT("NETWALL GETTING RECIEVES ON SECONDARY/n");
                  ASSERT(0);
           }

    //
           // If this was indicated by the miniport below as a packet, then get that packet pointer and indicate
           // it as a packet as well(with appropriate status). This way the OOB stuff is accessible to the
           // transport above us.
           //
           Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext);

    if (Packet != NULL)
           {
        DBGPRINT("===> NetWall - PtReceive RePacket.../n");
       
        //
                 // Get a packet off the pool and indicate that up
                 //
        NdisDprAllocatePacket(&Status, &MyPacket, pAdapt->RecvPacketPoolHandle);
                       
        if (Status == NDIS_STATUS_SUCCESS)
        {
          MyPacket->Private.Head = Packet->Private.Head;
                       MyPacket->Private.Tail = Packet->Private.Tail;

          //
                       // Get the original packet(it could be the same packet as one received or a different one
                       // based on # of layered MPs) and set it on the indicated packet so the OOB stuff is visible
                       // correctly at the top.
                       //
                       NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet));
                       NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize);

          //
                       // Set Packet Flags
                       //
                       NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet);

          //
                       // Make sure the status is set to NDIS_STATUS_RESOURCES.
                       //
                       NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES);

                       NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);

                       ASSERT(NDIS_GET_PACKET_STATUS(MyPacket) == NDIS_STATUS_RESOURCES);

                       NdisDprFreePacket(MyPacket);
                   DBGPRINT("<=== NetWall - PtReceive RePacket/n");

                       break;
                  }
           }
   
    //
           // Fall through if the miniport below us has either not indicated a packet or
    // we could not allocate one
           //
           pAdapt->IndicateRcvComplete = TRUE;
           switch (pAdapt->Medium)
           {
            case NdisMedium802_3:
                  NdisMEthIndicateReceive(pAdapt->MiniportHandle,
                                                                  MacReceiveContext,
                                                                  HeaderBuffer,
                                                                  HeaderBufferSize,
                                                                  LookAheadBuffer,
                                                                  LookAheadBufferSize,
                                                                  PacketSize
                            );
                  break;

            case NdisMedium802_5:
                  NdisMTrIndicateReceive(pAdapt->MiniportHandle,
                                                                 MacReceiveContext,
                                                                 HeaderBuffer,
                                                                 HeaderBufferSize,
                                                                 LookAheadBuffer,
                                                                 LookAheadBufferSize,
                                                                 PacketSize
                            );
                  break;

            case NdisMediumFddi:
                  NdisMFddiIndicateReceive(pAdapt->MiniportHandle,
                                                                  MacReceiveContext,
                                                                  HeaderBuffer,
                                                                  HeaderBufferSize,
                                                                  LookAheadBuffer,
                                                                  LookAheadBufferSize,
                                                                  PacketSize
                              );
                  break;

            default:
                  ASSERT(0);
                  break;
           }

     } while (FALSE);

     DBGPRINT("<=== NetWall - PtReceive/n");

     return Status;
}

/**
* Routine Description:
*
*       Called by the adapter below us when it is done indicating a batch of received buffers.
*
* Arguments:
*
*       ProtocolBindingContext   - Pointer to our adapter structure.
*
* Return Value:
*
*       None
*/
VOID
PtReceiveComplete(
     IN      NDIS_HANDLE            ProtocolBindingContext
     )
{
     PADAPT            pAdapt = (PADAPT)ProtocolBindingContext;

  DBGPRINT("===> NetWall - PtReceiveComplete/n");
 
     //
     // We should not be getting Receives on a Secondary, this is just specific to our LBFO driver
     //
     if (pAdapt->isSecondary)
     {
            DBGPRINT("NetWall GETTING RECEIVES ON SECONDARY/n");
            ASSERT(0);
     }

     if ((pAdapt->MiniportHandle != NULL) && pAdapt->IndicateRcvComplete)
     {
           switch (pAdapt->Medium)
           {
            case NdisMedium802_3:
                 NdisMEthIndicateReceiveComplete(pAdapt->MiniportHandle);
                 break;

            case NdisMedium802_5:
                 NdisMTrIndicateReceiveComplete(pAdapt->MiniportHandle);
                 break;

            case NdisMediumFddi:
                 NdisMFddiIndicateReceiveComplete(pAdapt->MiniportHandle);
                 break;

            default:
                 ASSERT(0);
                 break;
           }
     }
     pAdapt->IndicateRcvComplete = FALSE;
     
     DBGPRINT("<=== NetWall - PtReceiveComplete/n");
}

/**
* Routine Description:
*
*       ReceivePacket handler. Called up by the miniport below when it supports NDIS 4.0 style receives.
*       Re-package the packet and hand it back to NDIS for protocols above us. The re-package part is
*       important since NDIS uses the WrapperReserved part of the packet for its own book-keeping. Also
*       the re-packaging works differently when packets flow-up or down. In the up-path(here) the protocol
*       reserved is owned by the protocol above. We need to use the miniport reserved here.
*
* Arguments:
*
*       ProtocolBindingContext - Pointer to our adapter structure.
*       Packet             - Pointer to the packet
*
* Return Value:
*
*   == 0 -> We are done with the packet
*       != 0 -> We will keep the packet and call NdisReturnPackets() this many times when done.
*/
INT
PtReceivePacket(
     IN      NDIS_HANDLE                  ProtocolBindingContext,
     IN      PNDIS_PACKET            Packet
     )
{
     PADAPT                  pAdapt = (PADAPT)ProtocolBindingContext;
     NDIS_STATUS         Status;
     PNDIS_PACKET      MyPacket;
     PRSVD                  Resvd;

  NETWALL_RCV_FILTER_ACTION   FilterAction = RCV_FILTER_ACTION_PASS_PACKET;

  DBGPRINT("===> NetWall - PtReceivePacket/n");
 
  if (! pAdapt->MiniportHandle)
     {
        return 0;
     }

  //
  // Filter packet
  //
  FilterAction = FilterReceivePacket(pAdapt, Packet, NETWALL_DIRECTION_IN);
  if (FilterAction == RCV_FILTER_ACTION_REJECT_PACKET)
  {
        DBGPRINT("<=== NetWall - PtReceivePacket, but dropped by filter !/n");
    return 0;        
  }
 
     //
     // We should not be getting Receives on a Secondary, this is just specific to our LBFO driver
     //
     if (pAdapt->isSecondary)
     {
        DBGPRINT("NetWall GETTING RECEIVES ON SECONDARY/n");
        ASSERT(0);
     }

     //
     // Get a packet off the pool and indicate that up
     //
     NdisDprAllocatePacket(&Status,
                                    &MyPacket,
                                    pAdapt->RecvPacketPoolHandle
                );

     if (Status == NDIS_STATUS_SUCCESS)
     {
           Resvd = (PRSVD)(MyPacket->MiniportReserved);
           Resvd->OriginalPkt = Packet;

           MyPacket->Private.Head = Packet->Private.Head;
           MyPacket->Private.Tail = Packet->Private.Tail;

           //
           // Get the original packet(it could be the same packet as one received or a different one
           // based on # of layered MPs) and set it on the indicated packet so the OOB stuff is visible
           // correctly at the top.
           //
           NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet));

           //
           // Set Packet Flags
           //
           NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet);

           Status = NDIS_GET_PACKET_STATUS(Packet);

           NDIS_SET_PACKET_STATUS(MyPacket, Status);
           NDIS_SET_PACKET_HEADER_SIZE(MyPacket, NDIS_GET_PACKET_HEADER_SIZE(Packet));

           NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);

           if (Status == NDIS_STATUS_RESOURCES)
           {
              NdisDprFreePacket(MyPacket);
           }
   
    DBGPRINT("<=== NetWall - PtReceivePacket/n");
   
    //
    // If it does return a nonzero value, the intermediate driver must subsequently
    // call NdisReturnPackets with a pointer to this packet descriptor.
    //
           return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0);
     }
     else
     {
            //
            // We are out of packets. Silently drop it. Alternatively we can deal with it:
            //      - By keeping separate send and receive pools
            //      - Dynamically allocate more pools as needed and free them when not needed
            //
            return(0);
     }
     
     DBGPRINT("<=== NetWall - PtReceivePacket/n");
}

/**
*
* Routine Description:
*
*   Indicate receives with NdisMIndicateReceivePacket.
*   It is called when PtReceivePacket return value > 0.
*
* Arguments:
*
*       MiniportAdapterContext - Pointer to our adapter structure.
*       Packet             - Pointer to the packet
*
* Return Value:
*
*   Node.
*
* Remarks :
*
*   Packet points to an NDIS_PACKET structure that belongs to the virtual
*   adapter, and must be re-cycled by calling NdisFreePacket function.
*
*   If Packet was being used to "passthru" a packet that NETWALLIM received
*   from a lower-level miniport driver, then the pOriginalPacket field
*   of the private packet context structure points to the original packet.
*   This packet must be returned to the lower-level miniport by calling
*   NdisReturnPackets.
*
*   Finally, Packet and any associated NDIS_BUFFERs that belong to this
*   virtual adapter must be re-cycled for reuse by calling NdisFreePacket.
*
*/
VOID
MPReturnPacket(
     IN      NDIS_HANDLE                        MiniportAdapterContext,
     IN      PNDIS_PACKET                  Packet
     )
{
     PADAPT                  pAdapt = (PADAPT)MiniportAdapterContext;
     PNDIS_PACKET      MyPacket;
     PRSVD                  Resvd;

  DBGPRINT("===> NetWall - MPReturnPacket/n");

     Resvd   = (PRSVD)(Packet->MiniportReserved);
     MyPacket = Resvd->OriginalPkt;

     NdisFreePacket(Packet);
     NdisReturnPackets(&MyPacket, 1);
     
     DBGPRINT("<=== NetWall - MPReturnPacket/n");
}

Windows Mobile嵌入式开发实操指南:ROM刷写与ActiveSync调试 Windows Mobile虽已退出主流,但在工业终端、物流手持设备及数字遗产保护等场景中仍广泛服役。其本质是基于ARM架构(如Intel PXA270、Samsung S3C2440)的轻量级嵌入式操作系统,依赖ActiveSync协议实现PC协同,并通过ROM镜像、注册表持久化和CAB包部署保障系统稳定性。技术价值在于离线可操作、无云依赖、强硬件绑定与高确定性响应——这使其成为严苛工业环境中的‘时间锚定系统’。典型应用场景包括工控面板维护、老款Symbol/Motorola采集终端升级、PIM数据迁移及 阅读详情

相关推荐

费尔防火墙源代码阅读

费尔防火墙使用了重载系统提供的winsock.dll动态链接库的方法,实现网络数据包的检查;winsock.dll在系统启动时自动加载,ie等网络程序利用了其中提供的WSPSend、WSPRecv等函数实现数据包的收发过程;通过重载这个dll文件,费尔防火墙程序实现了自己的一个动态链接库xfilter.dll(好像是),其中导出了WSPStartup函数和XfIoControl函数,第一个函数将指

unicode1985的专栏 6066

基于Filter-Hook Driver(使用ipfirewall.h)的IP过滤驱动

Author:  fleshwoundEmail:   fleshwound@126.comHomepage:http://www.smatrix.org IP过滤驱动可以广泛的应用于网络安全产品的研发,NDIS和TDI的驱动资料很多,有比较成熟的代码可以参考,但是使用IPFIREWALL.h开发的IP过滤驱动的资料非常少,这次自己做一个软件的时候参考VCKBASE上的一篇文章《开发Windows

求索 2889

网络安全_(开源防火墙)

[pfSense GitHub仓库](https://github.com/pfsense/pfsense)- [OPNsense GitHub仓库](https://github.com/opnsense/core)- [iptables Git仓库](http://git.netfilter.org/iptables/)- [nftables Git仓库](http://git.netfilter.org/nftables/)- 下载方式:可通过Git命令克隆仓库,

weixin_43603708的博客 1301

Proxmox VE 上 Windows 内核调试实战:KDNET 配置与全链路优化

Windows 内核调试是一种高精度、低容错的系统级开发活动,其本质依赖稳定的调试信道、可控的硬件抽象层和可复位的执行环境。KDNET(内核网络调试)作为现代 Windows 支持的轻量级 UDP 调试协议,相比传统串口具备高带宽、低延迟、易集成等优势,但对虚拟化平台的网络仿真精度、设备直通能力和启动参数控制提出严苛要求。Proxmox VE 基于 KVM/QEMU 的裸金属架构,支持 e1000 网卡精准仿真、Q35 芯片组细粒度配置及 ZFS 快照快速回滚,成为构建可重复、可观测、可验证的内核调试环境的

weixin_33922670的博客 210

基于Netfilter从零开始写一个Linux防火墙,为我们的迷你防火墙编写代码(教程含完整源码)

在本文中,我们逐步实现了迷你防火墙,并研究了许多详细的技术。不仅是代码;但我们也通过运行真实的演示来验证迷你防火墙的行为。

code2day的博客 1713

VB多层防火墙技术的研究-状态检测(源代码+系统+开题报告+中期报告)

黑客技术的提升和黑客工具的泛滥,造成大量的企业、机构和个人的电脑系统遭受程度不同的入侵和攻击,或面临随时被攻击的危险。迫使大家不得不加强对自身电脑网络系统的安全防护,根据系统管理者设定的安全规则把守企业网络,提供强大的、应用选通、信息过滤、流量控制、网络侦听等功能。其他的诸如访问控制虚拟专网、身份认证、虚拟网桥、网络地址转换、提供完善的安全性设置,通过高性能的网络核心进行访问控制的功能我决定进一步来实现。系统采用了VB管理界面,通过直观、易用的界面管理强大、复杂的系统功能。

2301_76992670的博客 132

SamWaf 开源轻量级网站防火墙源码(源码下载)

SamWaf网站防火墙是一款适用于小公司、工作室和个人网站的开源轻量级网站防火墙,完全私有化部署,数据加密且仅保存本地,一键启动,支持Linux,Windows 64位,Arm64。 主要功能: 代码完全开源 支持私有化部署 轻量化不依赖三方服务 完全独立引擎,防护功能不依赖IIS,Nginx 自定义防护规则,支持脚本和界面编辑 支持白名单访问 支持IP黑名单 支持URL白名单 支持限制URL访问 支持指定界面数据隐私输出 支持CC频率访问 支持全局一键配置 支持分网站单独防护策略 日志加密保存 通讯日志加密 信息脱敏保存 支持OWASP CRS规则集 自动SSL证书申请以及续签 SSL证书批量检测到期情况 支持IPV6 支持自定义拦截界面

防火墙源代码(C++)

非常完整的防火墙源代码,使用C++编写,希望对您有用。

防火墙源码.rar_firewall_windows防火墙_包过滤_源码_防火墙源代码

一个防火墙的源码,比较适合学习包过滤

网络防火墙源码.rar

基于NDIS层,具备日志,IP规则设置等防火墙常用功能,运行于windows 2000系统以上,并安装在网关机器上,可以拦截SYGATES等网络共享软件的数据,另赠送98下的防火墙源码作为参考。

防火墙源码(用C++编写)

用C++写的防火墙源码,功能齐全,仅用于于学习交流用

Unix下的防火墙源码.rar_UNIX firewall_防火墙_防火墙源码

tcp_wrappers_7.6 Unix下的防火墙源码

防火墙源代码.zip

防火墙源代码.zip

c++防火墙代码

这个防火墙类有一个构造函数,它需要一个允许的IP地址向量,并将其存储。它还有一个is_allowed()`方法,它接受一个IP地址,并将该地址与允许的地址进行比较。如果提供的IP是一个允许的IP,则返回true,否则返回false。在主函数中,我们实例化了一个防火墙对象并指定允许的IP地址。然后,我们要求用户提供一个IP地址,并使用`is_allowed()方法检查该地址是否允许访问。最后,我们输出一个访问授权或拒绝的消息。

SYC20110120的博客 1501

某防火墙软件的源代码firewall

防火墙源代码

ndis驱动程序例子源代码,写防火墙的朋友可以参考

ndis网络驱动程序源代码,写防火墙的朋友可以参考

信息安全实践2.5(防火墙设计实现)

这个实验其实就是之前网络编程一个实验,不过因为代码是拿老师的代码进行修改的,所以就没有写对应的博客。实验要求基于操作系统内核驱动,设计实现一个简单防火墙系统实验思路可以基于netfilter框架,编写内核防火墙模块(驱动)和用户态防火墙控制程序,实现服务协议、IP地址、端口等的控制和过滤。实验环境使用的虚拟机:VMware16中的Ubuntu2020使用的操作系统:Linux操作系统使用的语言:C语言[gcc (Ubuntu 11.1.0-1uUbuntu1-20.04) 11.1.0]

沉在海里的鱼的博客 4236

温度实时检测预警系统(STC89C51RC+DS18B20)

温度实时检测预警系统

1 兴趣 2 实践 1496
上一篇: 最新溢出Windows Explorer URL File format overflow
下一篇: 关闭SFC[文件保护]的源代码
iiprogram
博客等级 码龄25年 1068粉丝 1515原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值