1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-08 00:34:57 +03:00

Change line endings to LF

This commit is contained in:
Piroro-hs
2021-02-26 16:06:15 +09:00
parent f52730c724
commit 9997785812
944 changed files with 450585 additions and 450587 deletions

View File

@ -1,63 +1,63 @@
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __DEBUG_INCLUDE
#define __DEBUG_INCLUDE
#if DBG
#define IF_PACKETDEBUG(f) if (PacketDebugFlag & (f))
extern ULONG PacketDebugFlag;
#define PACKET_DEBUG_LOUD 0x00000001 // debugging info
#define PACKET_DEBUG_VERY_LOUD 0x00000002 // excessive debugging info
#define PACKET_DEBUG_INIT 0x00000100 // init debugging info
//
// Macro for deciding whether to dump lots of debugging information.
//
#define IF_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_LOUD ) { A }
#define IF_VERY_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_VERY_LOUD ) { A }
#define IF_INIT_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_INIT ) { A }
#else
#define IF_LOUD(A)
#define IF_VERY_LOUD(A)
#define IF_INIT_LOUD(A)
#endif
#endif /*#define __DEBUG_INCLUDE*/
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __DEBUG_INCLUDE
#define __DEBUG_INCLUDE
#if DBG
#define IF_PACKETDEBUG(f) if (PacketDebugFlag & (f))
extern ULONG PacketDebugFlag;
#define PACKET_DEBUG_LOUD 0x00000001 // debugging info
#define PACKET_DEBUG_VERY_LOUD 0x00000002 // excessive debugging info
#define PACKET_DEBUG_INIT 0x00000100 // init debugging info
//
// Macro for deciding whether to dump lots of debugging information.
//
#define IF_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_LOUD ) { A }
#define IF_VERY_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_VERY_LOUD ) { A }
#define IF_INIT_LOUD(A) IF_PACKETDEBUG( PACKET_DEBUG_INIT ) { A }
#else
#define IF_LOUD(A)
#define IF_VERY_LOUD(A)
#define IF_INIT_LOUD(A)
#endif
#endif /*#define __DEBUG_INCLUDE*/

View File

@ -1,90 +1,90 @@
/*++ BUILD Version: 0004 // Increment this if a change has global effects
Copyright (c) 1992-1993 Microsoft Corporation
Module Name:
devioctl.h
Revision History:
-- */
// begin_winioctl
#ifndef _DEVIOCTL_
#define _DEVIOCTL_
// begin_ntddk begin_nthal begin_ntifs
//
// Define the various device type values. Note that values used by Microsoft
// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
// by customers.
//
#define DEVICE_TYPE ULONG
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_INPORT_PORT 0x0000000a
#define FILE_DEVICE_KEYBOARD 0x0000000b
#define FILE_DEVICE_MAILSLOT 0x0000000c
#define FILE_DEVICE_MIDI_IN 0x0000000d
#define FILE_DEVICE_MIDI_OUT 0x0000000e
#define FILE_DEVICE_MOUSE 0x0000000f
#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SCANNER 0x00000019
#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_SCREEN 0x0000001c
#define FILE_DEVICE_SOUND 0x0000001d
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_TRANSPORT 0x00000021
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_VIDEO 0x00000023
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_WAVE_IN 0x00000025
#define FILE_DEVICE_WAVE_OUT 0x00000026
#define FILE_DEVICE_8042_PORT 0x00000027
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
#define FILE_DEVICE_BATTERY 0x00000029
#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
#define FILE_DEVICE_MODEM 0x0000002b
#define FILE_DEVICE_VDM 0x0000002c
#define FILE_DEVICE_MASS_STORAGE 0x0000002d
//
// Macro definition for defining IOCTL and FSCTL function control codes. Note
// that function codes 0-2047 are reserved for Microsoft Corporation, and
// 2048-4095 are reserved for customers.
//
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
//
// Define the method codes for how buffers are passed for I/O and FS controls
//
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3
//
// Define the access check value for any access
//
//
// The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
// ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
// constants *MUST* always be in sync.
//
#define FILE_ANY_ACCESS 0
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
// end_ntddk end_nthal end_ntifs
#endif // _DEVIOCTL_
// end_winioctl
/*++ BUILD Version: 0004 // Increment this if a change has global effects
Copyright (c) 1992-1993 Microsoft Corporation
Module Name:
devioctl.h
Revision History:
-- */
// begin_winioctl
#ifndef _DEVIOCTL_
#define _DEVIOCTL_
// begin_ntddk begin_nthal begin_ntifs
//
// Define the various device type values. Note that values used by Microsoft
// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
// by customers.
//
#define DEVICE_TYPE ULONG
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_INPORT_PORT 0x0000000a
#define FILE_DEVICE_KEYBOARD 0x0000000b
#define FILE_DEVICE_MAILSLOT 0x0000000c
#define FILE_DEVICE_MIDI_IN 0x0000000d
#define FILE_DEVICE_MIDI_OUT 0x0000000e
#define FILE_DEVICE_MOUSE 0x0000000f
#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SCANNER 0x00000019
#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_SCREEN 0x0000001c
#define FILE_DEVICE_SOUND 0x0000001d
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_TRANSPORT 0x00000021
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_VIDEO 0x00000023
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_WAVE_IN 0x00000025
#define FILE_DEVICE_WAVE_OUT 0x00000026
#define FILE_DEVICE_8042_PORT 0x00000027
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
#define FILE_DEVICE_BATTERY 0x00000029
#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
#define FILE_DEVICE_MODEM 0x0000002b
#define FILE_DEVICE_VDM 0x0000002c
#define FILE_DEVICE_MASS_STORAGE 0x0000002d
//
// Macro definition for defining IOCTL and FSCTL function control codes. Note
// that function codes 0-2047 are reserved for Microsoft Corporation, and
// 2048-4095 are reserved for customers.
//
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
//
// Define the method codes for how buffers are passed for I/O and FS controls
//
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3
//
// Define the access check value for any access
//
//
// The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
// ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
// constants *MUST* always be in sync.
//
#define FILE_ANY_ACCESS 0
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
// end_ntddk end_nthal end_ntifs
#endif // _DEVIOCTL_
// end_winioctl

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,26 @@
#ifndef __NTDDPACKET
#define __NTDDPACKET 1
#include "devioctl.h"
/*#include <packon.h> */
struct _PACKET_OID_DATA {
ULONG Oid;
ULONG Length;
UCHAR Data[1];
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
/*#include <packoff.h> */
#define FILE_DEVICE_PROTOCOL 0x8000
#define IOCTL_PROTOCOL_QUERY_OID CTL_CODE(FILE_DEVICE_PROTOCOL, 0 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_SET_OID CTL_CODE(FILE_DEVICE_PROTOCOL, 1 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif
#ifndef __NTDDPACKET
#define __NTDDPACKET 1
#include "devioctl.h"
/*#include <packon.h> */
struct _PACKET_OID_DATA {
ULONG Oid;
ULONG Length;
UCHAR Data[1];
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
/*#include <packoff.h> */
#define FILE_DEVICE_PROTOCOL 0x8000
#define IOCTL_PROTOCOL_QUERY_OID CTL_CODE(FILE_DEVICE_PROTOCOL, 0 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_SET_OID CTL_CODE(FILE_DEVICE_PROTOCOL, 1 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,423 +1,423 @@
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @ingroup packetapi
* @{
*/
/** @defgroup packet32h Packet.dll definitions and data structures
* Packet32.h contains the data structures and the definitions used by packet.dll.
* The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
* by the applications that use the functions of this library
* @{
*/
#ifndef __PACKET32
#define __PACKET32
#include <winsock2.h>
#include "devioctl.h"
#ifdef HAVE_DAG_API
#include <dagc.h>
#endif /* HAVE_DAG_API */
// Working modes
#define PACKET_MODE_CAPT 0x0 ///< Capture mode
#define PACKET_MODE_STAT 0x1 ///< Statistical mode
#define PACKET_MODE_MON 0x2 ///< Monitoring mode
#define PACKET_MODE_DUMP 0x10 ///< Dump mode
#define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode
// ioctls
#define FILE_DEVICE_PROTOCOL 0x8000
#define IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define pBIOCSETBUFFERSIZE 9592 ///< IOCTL code: set kernel buffer size.
#define pBIOCSETF 9030 ///< IOCTL code: set packet filtering program.
#define pBIOCGSTATS 9031 ///< IOCTL code: get the capture stats.
#define pBIOCSRTIMEOUT 7416 ///< IOCTL code: set the read timeout.
#define pBIOCSMODE 7412 ///< IOCTL code: set working mode.
#define pBIOCSWRITEREP 7413 ///< IOCTL code: set number of physical repetions of every packet written by the app.
#define pBIOCSMINTOCOPY 7414 ///< IOCTL code: set minimum amount of data in the kernel buffer that unlocks a read call.
#define pBIOCSETOID 2147483648 ///< IOCTL code: set an OID value.
#define pBIOCQUERYOID 2147483652 ///< IOCTL code: get an OID value.
#define pATTACHPROCESS 7117 ///< IOCTL code: attach a process to the driver. Used in Win9x only.
#define pDETACHPROCESS 7118 ///< IOCTL code: detach a process from the driver. Used in Win9x only.
#define pBIOCSETDUMPFILENAME 9029 ///< IOCTL code: set the name of a the file used by kernel dump mode.
#define pBIOCEVNAME 7415 ///< IOCTL code: get the name of the event that the driver signals when some data is present in the buffer.
#define pBIOCSENDPACKETSNOSYNC 9032 ///< IOCTL code: Send a buffer containing multiple packets to the network, ignoring the timestamps associated with the packets.
#define pBIOCSENDPACKETSSYNC 9033 ///< IOCTL code: Send a buffer containing multiple packets to the network, respecting the timestamps associated with the packets.
#define pBIOCSETDUMPLIMITS 9034 ///< IOCTL code: Set the dump file limits. See the PacketSetDumpLimits() function.
#define pBIOCISDUMPENDED 7411 ///< IOCTL code: Get the status of the kernel dump process. See the PacketIsDumpEnded() function.
#define pBIOCSTIMEZONE 7471 ///< IOCTL code: set time zone. Used in Win9x only.
/// Alignment macro. Defines the alignment size.
#define Packet_ALIGNMENT sizeof(int)
/// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
#define NdisMediumNull -1 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumCHDLC -2 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumPPPSerial -3 // Custom linktype: NDIS doesn't provide an equivalent
/*!
\brief Network type structure.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
*/
typedef struct NetType
{
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
}NetType;
//some definitions stolen from libpcap
#ifndef BPF_MAJOR_VERSION
/*!
\brief A BPF pseudo-assembly program.
The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
*/
struct bpf_program
{
UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
struct bpf_insn *bf_insns; ///< A pointer to the first instruction of the program.
};
/*!
\brief A single BPF pseudo-instruction.
bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
*/
struct bpf_insn
{
USHORT code; ///< Instruction type and addressing mode.
UCHAR jt; ///< Jump if true
UCHAR jf; ///< Jump if false
int k; ///< Generic field used for various purposes.
};
/*!
\brief Structure that contains a couple of statistics values on the current capture.
It is used by packet.dll to return statistics about a capture session.
*/
struct bpf_stat
{
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*!
\brief Packet header.
This structure defines the header associated with every packet delivered to the application.
*/
struct bpf_hdr
{
struct timeval bh_tstamp; ///< The timestamp associated with the captured packet.
///< It is stored in a TimeVal structure.
UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b>
///< from the original packet, because it is possible (with a proper filter)
///< to instruct the driver to capture only a portion of the packets.
UINT bh_datalen; ///< Original length of packet
USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases,
///< a padding could be added between the end of this structure and the packet
///< data for performance reasons. This filed can be used to retrieve the actual data
///< of the packet.
};
/*!
\brief Dump packet header.
This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
*/
struct dump_bpf_hdr{
struct timeval ts; ///< Time stamp of the packet
UINT caplen; ///< Length of captured portion. The captured portion can smaller than the
///< the original packet, because it is possible (with a proper filter) to
///< instruct the driver to capture only a portion of the packets.
UINT len; ///< Length of the original packet (off wire).
};
#endif
#define DOSNAMEPREFIX TEXT("Packet_") ///< Prefix added to the adapters device names to create the WinPcap devices
#define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
#define NMAX_PACKET 65535
/*!
\brief Addresses of a network adapter.
This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
an adapter.
*/
typedef struct npf_if_addr {
struct sockaddr_storage IPAddress; ///< IP address.
struct sockaddr_storage SubnetMask; ///< Netmask for that address.
struct sockaddr_storage Broadcast; ///< Broadcast address.
}npf_if_addr;
#define ADAPTER_NAME_LENGTH 256 + 12 ///< Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
#define ADAPTER_DESC_LENGTH 128 ///< Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
#define MAX_MAC_ADDR_LENGTH 8 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define MAX_NETWORK_ADDRESSES 16 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
#define INFO_FLAG_NDIS_ADAPTER 0 ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter
#define INFO_FLAG_NDISWAN_ADAPTER 1 ///< Flag for ADAPTER_INFO: this is a NdisWan adapter
#define INFO_FLAG_DAG_CARD 2 ///< Flag for ADAPTER_INFO: this is a DAG card
#define INFO_FLAG_DAG_FILE 6 ///< Flag for ADAPTER_INFO: this is a DAG file
#define INFO_FLAG_DONT_EXPORT 8 ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
/*!
\brief Contains comprehensive information about a network adapter.
This structure is filled with all the accessory information that the user can need about an adapter installed
on his system.
*/
typedef struct _ADAPTER_INFO
{
struct _ADAPTER_INFO *Next; ///< Pointer to the next adapter in the list.
CHAR Name[ADAPTER_NAME_LENGTH + 1]; ///< Name of the device representing the adapter.
CHAR Description[ADAPTER_DESC_LENGTH + 1]; ///< Human understandable description of the adapter
UINT MacAddressLen; ///< Length of the link layer address.
UCHAR MacAddress[MAX_MAC_ADDR_LENGTH]; ///< Link layer address.
NetType LinkLayer; ///< Physical characteristics of this adapter. This NetType structure contains the link type and the speed of the adapter.
INT NNetworkAddresses; ///< Number of network layer addresses of this adapter.
npf_if_addr *NetworkAddresses; ///< Pointer to an array of npf_if_addr, each of which specifies a network address of this adapter.
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
}
ADAPTER_INFO, *PADAPTER_INFO;
/*!
\brief Describes an opened network adapter.
This structure is the most important for the functioning of packet.dll, but the great part of its fields
should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
*/
typedef struct _ADAPTER {
HANDLE hFile; ///< \internal Handle to an open instance of the NPF driver.
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.
int NumWrites; ///< \internal Number of times a packets written on this adapter will be repeated
///< on the wire.
HANDLE ReadEvent; ///< A notification event associated with the read calls on the adapter.
///< It can be passed to standard Win32 functions (like WaitForSingleObject
///< or WaitForMultipleObjects) to wait until the driver's buffer contains some
///< data. It is particularly useful in GUI applications that need to wait
///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
///< function can be used to define the minimum amount of data in the kernel buffer
///< that will cause the event to be signalled.
UINT ReadTimeOut; ///< \internal The amount of time after which a read on the driver will be released and
///< ReadEvent will be signaled, also if no packets were captured
CHAR Name[ADAPTER_NAME_LENGTH];
PWAN_ADAPTER pWanAdapter;
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
#ifdef HAVE_DAG_API
dagc_t *pDagCard; ///< Pointer to the dagc API adapter descriptor for this adapter
PCHAR DagBuffer; ///< Pointer to the buffer with the packets that is received from the DAG card
struct timeval DagReadTimeout; ///< Read timeout. The dagc API requires a timeval structure
unsigned DagFcsLen; ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry
DWORD DagFastProcess; ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
#endif // HAVE_DAG_API
} ADAPTER, *LPADAPTER;
/*!
\brief Structure that contains a group of packets coming from the driver.
This structure defines the header associated with every packet delivered to the application.
*/
typedef struct _PACKET {
HANDLE hEvent; ///< \deprecated Still present for compatibility with old applications.
OVERLAPPED OverLapped; ///< \deprecated Still present for compatibility with old applications.
PVOID Buffer; ///< Buffer with containing the packets. See the PacketReceivePacket() for
///< details about the organization of the data in this buffer
UINT Length; ///< Length of the buffer
DWORD ulBytesReceived; ///< Number of valid bytes present in the buffer, i.e. amount of data
///< received by the last call to PacketReceivePacket()
BOOLEAN bIoComplete; ///< \deprecated Still present for compatibility with old applications.
} PACKET, *LPPACKET;
/*!
\brief Structure containing an OID request.
It is used by the PacketRequest() function to send an OID to the interface card driver.
It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
the list of the multicast groups defined on it, and so on.
*/
struct _PACKET_OID_DATA {
ULONG Oid; ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
///< for a complete list of valid codes.
ULONG Length; ///< Length of the data field
UCHAR Data[1]; ///< variable-length field that contains the information passed to or received
///< from the adapter.
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
#if _DBG
#define ODS(_x) OutputDebugString(TEXT(_x))
#define ODSEx(_x, _y)
#else
#ifdef _DEBUG_TO_FILE
/*!
\brief Macro to print a debug string. The behavior differs depending on the debug level
*/
#define ODS(_x) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, "%s", _x); \
fclose(f); \
}
/*!
\brief Macro to print debug data with the printf convention. The behavior differs depending on
the debug level
*/
#define ODSEx(_x, _y) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, _x, _y); \
fclose(f); \
}
LONG PacketDumpRegistryKey(PCHAR KeyName, PCHAR FileName);
#else
#define ODS(_x)
#define ODSEx(_x, _y)
#endif
#endif
/* We load dynamically the dag library in order link it only when it's present on the system */
#ifdef HAVE_DAG_API
typedef dagc_t* (*dagc_open_handler)(const char *source, unsigned flags, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef void (*dagc_close_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinktype_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinkspeed_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_setsnaplen_handler)(dagc_t *dagcfd, unsigned snaplen); ///< prototype used to dynamically load the dag dll
typedef unsigned (*dagc_getfcslen_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_receive_handler)(dagc_t *dagcfd, u_char **buffer, u_int *bufsize); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_stats_handler)(dagc_t *dagcfd, dagc_stats_t *ps); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_wait_handler)(dagc_t *dagcfd, struct timeval *timeout); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_finddevs_handler)(dagc_if_t **alldevsp, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_freedevs_handler)(dagc_if_t *alldevsp); ///< prototype used to dynamically load the dag dll
#endif // HAVE_DAG_API
#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/
// The following is used to check the adapter name in PacketOpenAdapterNPF and prevent
// opening of firewire adapters
#define FIREWIRE_SUBSTR L"1394"
void PacketPopulateAdaptersInfoList();
PWCHAR SChar2WChar(PCHAR string);
PCHAR WChar2SChar(PWCHAR string);
BOOL PacketGetFileVersion(LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen);
PADAPTER_INFO PacketFindAdInfo(PCHAR AdapterName);
BOOLEAN PacketUpdateAdInfo(PCHAR AdapterName);
BOOLEAN IsFireWire(TCHAR *AdapterDesc);
//---------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//---------------------------------------------------------------------------
PCHAR PacketGetVersion();
PCHAR PacketGetDriverVersion();
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
LPPACKET PacketAllocatePacket(void);
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
VOID PacketFreePacket(LPPACKET lpPacket);
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
BOOL PacketStopDriver();
VOID PacketCloseAdapter(LPADAPTER lpAdapter);
#ifdef __cplusplus
}
#endif
#endif //__PACKET32
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @ingroup packetapi
* @{
*/
/** @defgroup packet32h Packet.dll definitions and data structures
* Packet32.h contains the data structures and the definitions used by packet.dll.
* The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
* by the applications that use the functions of this library
* @{
*/
#ifndef __PACKET32
#define __PACKET32
#include <winsock2.h>
#include "devioctl.h"
#ifdef HAVE_DAG_API
#include <dagc.h>
#endif /* HAVE_DAG_API */
// Working modes
#define PACKET_MODE_CAPT 0x0 ///< Capture mode
#define PACKET_MODE_STAT 0x1 ///< Statistical mode
#define PACKET_MODE_MON 0x2 ///< Monitoring mode
#define PACKET_MODE_DUMP 0x10 ///< Dump mode
#define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode
// ioctls
#define FILE_DEVICE_PROTOCOL 0x8000
#define IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define pBIOCSETBUFFERSIZE 9592 ///< IOCTL code: set kernel buffer size.
#define pBIOCSETF 9030 ///< IOCTL code: set packet filtering program.
#define pBIOCGSTATS 9031 ///< IOCTL code: get the capture stats.
#define pBIOCSRTIMEOUT 7416 ///< IOCTL code: set the read timeout.
#define pBIOCSMODE 7412 ///< IOCTL code: set working mode.
#define pBIOCSWRITEREP 7413 ///< IOCTL code: set number of physical repetions of every packet written by the app.
#define pBIOCSMINTOCOPY 7414 ///< IOCTL code: set minimum amount of data in the kernel buffer that unlocks a read call.
#define pBIOCSETOID 2147483648 ///< IOCTL code: set an OID value.
#define pBIOCQUERYOID 2147483652 ///< IOCTL code: get an OID value.
#define pATTACHPROCESS 7117 ///< IOCTL code: attach a process to the driver. Used in Win9x only.
#define pDETACHPROCESS 7118 ///< IOCTL code: detach a process from the driver. Used in Win9x only.
#define pBIOCSETDUMPFILENAME 9029 ///< IOCTL code: set the name of a the file used by kernel dump mode.
#define pBIOCEVNAME 7415 ///< IOCTL code: get the name of the event that the driver signals when some data is present in the buffer.
#define pBIOCSENDPACKETSNOSYNC 9032 ///< IOCTL code: Send a buffer containing multiple packets to the network, ignoring the timestamps associated with the packets.
#define pBIOCSENDPACKETSSYNC 9033 ///< IOCTL code: Send a buffer containing multiple packets to the network, respecting the timestamps associated with the packets.
#define pBIOCSETDUMPLIMITS 9034 ///< IOCTL code: Set the dump file limits. See the PacketSetDumpLimits() function.
#define pBIOCISDUMPENDED 7411 ///< IOCTL code: Get the status of the kernel dump process. See the PacketIsDumpEnded() function.
#define pBIOCSTIMEZONE 7471 ///< IOCTL code: set time zone. Used in Win9x only.
/// Alignment macro. Defines the alignment size.
#define Packet_ALIGNMENT sizeof(int)
/// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
#define NdisMediumNull -1 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumCHDLC -2 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumPPPSerial -3 // Custom linktype: NDIS doesn't provide an equivalent
/*!
\brief Network type structure.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
*/
typedef struct NetType
{
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
}NetType;
//some definitions stolen from libpcap
#ifndef BPF_MAJOR_VERSION
/*!
\brief A BPF pseudo-assembly program.
The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
*/
struct bpf_program
{
UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
struct bpf_insn *bf_insns; ///< A pointer to the first instruction of the program.
};
/*!
\brief A single BPF pseudo-instruction.
bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
*/
struct bpf_insn
{
USHORT code; ///< Instruction type and addressing mode.
UCHAR jt; ///< Jump if true
UCHAR jf; ///< Jump if false
int k; ///< Generic field used for various purposes.
};
/*!
\brief Structure that contains a couple of statistics values on the current capture.
It is used by packet.dll to return statistics about a capture session.
*/
struct bpf_stat
{
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*!
\brief Packet header.
This structure defines the header associated with every packet delivered to the application.
*/
struct bpf_hdr
{
struct timeval bh_tstamp; ///< The timestamp associated with the captured packet.
///< It is stored in a TimeVal structure.
UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b>
///< from the original packet, because it is possible (with a proper filter)
///< to instruct the driver to capture only a portion of the packets.
UINT bh_datalen; ///< Original length of packet
USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases,
///< a padding could be added between the end of this structure and the packet
///< data for performance reasons. This filed can be used to retrieve the actual data
///< of the packet.
};
/*!
\brief Dump packet header.
This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
*/
struct dump_bpf_hdr{
struct timeval ts; ///< Time stamp of the packet
UINT caplen; ///< Length of captured portion. The captured portion can smaller than the
///< the original packet, because it is possible (with a proper filter) to
///< instruct the driver to capture only a portion of the packets.
UINT len; ///< Length of the original packet (off wire).
};
#endif
#define DOSNAMEPREFIX TEXT("Packet_") ///< Prefix added to the adapters device names to create the WinPcap devices
#define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
#define NMAX_PACKET 65535
/*!
\brief Addresses of a network adapter.
This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
an adapter.
*/
typedef struct npf_if_addr {
struct sockaddr_storage IPAddress; ///< IP address.
struct sockaddr_storage SubnetMask; ///< Netmask for that address.
struct sockaddr_storage Broadcast; ///< Broadcast address.
}npf_if_addr;
#define ADAPTER_NAME_LENGTH 256 + 12 ///< Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
#define ADAPTER_DESC_LENGTH 128 ///< Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
#define MAX_MAC_ADDR_LENGTH 8 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define MAX_NETWORK_ADDRESSES 16 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
#define INFO_FLAG_NDIS_ADAPTER 0 ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter
#define INFO_FLAG_NDISWAN_ADAPTER 1 ///< Flag for ADAPTER_INFO: this is a NdisWan adapter
#define INFO_FLAG_DAG_CARD 2 ///< Flag for ADAPTER_INFO: this is a DAG card
#define INFO_FLAG_DAG_FILE 6 ///< Flag for ADAPTER_INFO: this is a DAG file
#define INFO_FLAG_DONT_EXPORT 8 ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
/*!
\brief Contains comprehensive information about a network adapter.
This structure is filled with all the accessory information that the user can need about an adapter installed
on his system.
*/
typedef struct _ADAPTER_INFO
{
struct _ADAPTER_INFO *Next; ///< Pointer to the next adapter in the list.
CHAR Name[ADAPTER_NAME_LENGTH + 1]; ///< Name of the device representing the adapter.
CHAR Description[ADAPTER_DESC_LENGTH + 1]; ///< Human understandable description of the adapter
UINT MacAddressLen; ///< Length of the link layer address.
UCHAR MacAddress[MAX_MAC_ADDR_LENGTH]; ///< Link layer address.
NetType LinkLayer; ///< Physical characteristics of this adapter. This NetType structure contains the link type and the speed of the adapter.
INT NNetworkAddresses; ///< Number of network layer addresses of this adapter.
npf_if_addr *NetworkAddresses; ///< Pointer to an array of npf_if_addr, each of which specifies a network address of this adapter.
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
}
ADAPTER_INFO, *PADAPTER_INFO;
/*!
\brief Describes an opened network adapter.
This structure is the most important for the functioning of packet.dll, but the great part of its fields
should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
*/
typedef struct _ADAPTER {
HANDLE hFile; ///< \internal Handle to an open instance of the NPF driver.
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.
int NumWrites; ///< \internal Number of times a packets written on this adapter will be repeated
///< on the wire.
HANDLE ReadEvent; ///< A notification event associated with the read calls on the adapter.
///< It can be passed to standard Win32 functions (like WaitForSingleObject
///< or WaitForMultipleObjects) to wait until the driver's buffer contains some
///< data. It is particularly useful in GUI applications that need to wait
///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
///< function can be used to define the minimum amount of data in the kernel buffer
///< that will cause the event to be signalled.
UINT ReadTimeOut; ///< \internal The amount of time after which a read on the driver will be released and
///< ReadEvent will be signaled, also if no packets were captured
CHAR Name[ADAPTER_NAME_LENGTH];
PWAN_ADAPTER pWanAdapter;
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
#ifdef HAVE_DAG_API
dagc_t *pDagCard; ///< Pointer to the dagc API adapter descriptor for this adapter
PCHAR DagBuffer; ///< Pointer to the buffer with the packets that is received from the DAG card
struct timeval DagReadTimeout; ///< Read timeout. The dagc API requires a timeval structure
unsigned DagFcsLen; ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry
DWORD DagFastProcess; ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
#endif // HAVE_DAG_API
} ADAPTER, *LPADAPTER;
/*!
\brief Structure that contains a group of packets coming from the driver.
This structure defines the header associated with every packet delivered to the application.
*/
typedef struct _PACKET {
HANDLE hEvent; ///< \deprecated Still present for compatibility with old applications.
OVERLAPPED OverLapped; ///< \deprecated Still present for compatibility with old applications.
PVOID Buffer; ///< Buffer with containing the packets. See the PacketReceivePacket() for
///< details about the organization of the data in this buffer
UINT Length; ///< Length of the buffer
DWORD ulBytesReceived; ///< Number of valid bytes present in the buffer, i.e. amount of data
///< received by the last call to PacketReceivePacket()
BOOLEAN bIoComplete; ///< \deprecated Still present for compatibility with old applications.
} PACKET, *LPPACKET;
/*!
\brief Structure containing an OID request.
It is used by the PacketRequest() function to send an OID to the interface card driver.
It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
the list of the multicast groups defined on it, and so on.
*/
struct _PACKET_OID_DATA {
ULONG Oid; ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
///< for a complete list of valid codes.
ULONG Length; ///< Length of the data field
UCHAR Data[1]; ///< variable-length field that contains the information passed to or received
///< from the adapter.
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
#if _DBG
#define ODS(_x) OutputDebugString(TEXT(_x))
#define ODSEx(_x, _y)
#else
#ifdef _DEBUG_TO_FILE
/*!
\brief Macro to print a debug string. The behavior differs depending on the debug level
*/
#define ODS(_x) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, "%s", _x); \
fclose(f); \
}
/*!
\brief Macro to print debug data with the printf convention. The behavior differs depending on
the debug level
*/
#define ODSEx(_x, _y) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, _x, _y); \
fclose(f); \
}
LONG PacketDumpRegistryKey(PCHAR KeyName, PCHAR FileName);
#else
#define ODS(_x)
#define ODSEx(_x, _y)
#endif
#endif
/* We load dynamically the dag library in order link it only when it's present on the system */
#ifdef HAVE_DAG_API
typedef dagc_t* (*dagc_open_handler)(const char *source, unsigned flags, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef void (*dagc_close_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinktype_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinkspeed_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_setsnaplen_handler)(dagc_t *dagcfd, unsigned snaplen); ///< prototype used to dynamically load the dag dll
typedef unsigned (*dagc_getfcslen_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_receive_handler)(dagc_t *dagcfd, u_char **buffer, u_int *bufsize); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_stats_handler)(dagc_t *dagcfd, dagc_stats_t *ps); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_wait_handler)(dagc_t *dagcfd, struct timeval *timeout); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_finddevs_handler)(dagc_if_t **alldevsp, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_freedevs_handler)(dagc_if_t *alldevsp); ///< prototype used to dynamically load the dag dll
#endif // HAVE_DAG_API
#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/
// The following is used to check the adapter name in PacketOpenAdapterNPF and prevent
// opening of firewire adapters
#define FIREWIRE_SUBSTR L"1394"
void PacketPopulateAdaptersInfoList();
PWCHAR SChar2WChar(PCHAR string);
PCHAR WChar2SChar(PWCHAR string);
BOOL PacketGetFileVersion(LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen);
PADAPTER_INFO PacketFindAdInfo(PCHAR AdapterName);
BOOLEAN PacketUpdateAdInfo(PCHAR AdapterName);
BOOLEAN IsFireWire(TCHAR *AdapterDesc);
//---------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//---------------------------------------------------------------------------
PCHAR PacketGetVersion();
PCHAR PacketGetDriverVersion();
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
LPPACKET PacketAllocatePacket(void);
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
VOID PacketFreePacket(LPPACKET lpPacket);
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
BOOL PacketStopDriver();
VOID PacketCloseAdapter(LPADAPTER lpAdapter);
#ifdef __cplusplus
}
#endif
#endif //__PACKET32

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +1,63 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource1.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Japanese resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN)
#ifdef _WIN32
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(932)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource1.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Japanese resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
// Microsoft Visual C++ generated resource script.
//
#include "resource1.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Japanese resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN)
#ifdef _WIN32
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(932)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource1.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Japanese resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -1,462 +1,462 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="See"
ProjectGUID="{D817977C-481C-4575-B229-DD2896EDF6C9}"
RootNamespace="See"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)BuiltDriverPackages\See\x86"
IntermediateDirectory="$(PlatformName)_$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="0"
EnableIntrinsicFunctions="false"
FavorSizeOrSpeed="0"
AdditionalIncludeDirectories="$(SolutionDir)Mayaqua\win32_inc;C:\WinDDK\7600.16385.1\inc\ddk;C:\WinDDK\7600.16385.1\inc\api;C:\WinDDK\7600.16385.1\inc\crt;$(SolutionDir)"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NEO_EXPORTS;VPN_SPEED;WIN_NT_DRIVER;_X86_=1;NDIS50;NTKERNEL"
StringPooling="false"
ExceptionHandling="0"
RuntimeLibrary="0"
StructMemberAlignment="4"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CallingConvention="2"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:GenerateVersionResource &quot;$(TargetPath)&quot; /OUT:&quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot; /PRODUCT:&quot;SoftEther VPN&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/driver /subsystem:native,5.00 /FULLBUILD /align:0x80 /osversion:5.00 /MERGE:_PAGE=PAGE /MERGE:_TEXT=.text /NODEFAULTLIB /ALIGN:4096"
AdditionalDependencies="ntoskrnl.lib hal.lib wmilib.lib ndis.lib &quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot;"
OutputFile="$(OutDir)\See_x86.sys"
LinkIncremental="1"
AdditionalLibraryDirectories="C:\WinDDK\7600.16385.1\lib\wnet\i386"
GenerateManifest="false"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(SolutionDir)DebugFiles\pdb\$(PlatformName)_$(ConfigurationName)\$(ProjectName).pdb"
GenerateMapFile="true"
MapFileName="$(SolutionDir)DebugFiles\map\$(PlatformName)_$(ConfigurationName)\$(ProjectName).map"
SubSystem="0"
StackReserveSize="262144"
StackCommitSize="4096"
OptimizeReferences="1"
EnableCOMDATFolding="1"
EntryPointSymbol="DriverEntry"
BaseAddress="0x10000"
RandomizedBaseAddress="0"
DataExecutionPrevention="0"
ImportLibrary="$(SolutionDir)tmp\lib\$(PlatformName)_$(ConfigurationName)\$(ProjectName).lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode &quot;$(TargetPath)&quot; /COMMENT:&quot;VPN Software&quot; /KERNEL:yes"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)BuiltDriverPackages\See\x64"
IntermediateDirectory="$(PlatformName)_$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="0"
EnableIntrinsicFunctions="false"
FavorSizeOrSpeed="0"
AdditionalIncludeDirectories="$(SolutionDir)Mayaqua\win32_inc;C:\WinDDK\7600.16385.1\inc\ddk;C:\WinDDK\7600.16385.1\inc\api;C:\WinDDK\7600.16385.1\inc\crt;$(SolutionDir)"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NEO_EXPORTS;VPN_SPEED;WIN_NT_DRIVER;NDIS50;WIN32_EXT;__NPF_AMD64__;_AMD64_;AMD64;_WIN64;NTKERNEL;CPU_64"
StringPooling="false"
ExceptionHandling="0"
RuntimeLibrary="0"
StructMemberAlignment="4"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CallingConvention="2"
CompileAs="1"
DisableSpecificWarnings="4996;4334"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:GenerateVersionResource &quot;$(TargetPath)&quot; /OUT:&quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot; /PRODUCT:&quot;SoftEther VPN&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/driver /subsystem:native /FULLBUILD /align:0x80 /osversion:5.00 /MERGE:_PAGE=PAGE /MERGE:_TEXT=.text /NODEFAULTLIB /ALIGN:4096"
AdditionalDependencies="ntoskrnl.lib hal.lib wmilib.lib ndis.lib &quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot;"
OutputFile="$(OutDir)\See_x64.sys"
LinkIncremental="1"
AdditionalLibraryDirectories="C:\WinDDK\7600.16385.1\lib\wnet\amd64"
GenerateManifest="false"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(SolutionDir)DebugFiles\pdb\$(PlatformName)_$(ConfigurationName)\$(ProjectName).pdb"
GenerateMapFile="true"
MapFileName="$(SolutionDir)DebugFiles\map\$(PlatformName)_$(ConfigurationName)\$(ProjectName).map"
SubSystem="0"
StackReserveSize="262144"
StackCommitSize="4096"
OptimizeReferences="1"
EnableCOMDATFolding="1"
EntryPointSymbol="DriverEntry"
BaseAddress="0x10000"
RandomizedBaseAddress="0"
DataExecutionPrevention="0"
ImportLibrary="$(SolutionDir)tmp\lib\$(PlatformName)_$(ConfigurationName)\$(ProjectName).lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode &quot;$(TargetPath)&quot; /COMMENT:&quot;VPN Software&quot; /KERNEL:yes"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\bucket_lookup.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\count_packets.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\dump.c"
>
</File>
<File
RelativePath=".\functions.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\jitter.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\normal_lookup.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Openclos.c"
>
</File>
<File
RelativePath=".\Packet.c"
>
</File>
<File
RelativePath=".\Read.c"
>
</File>
<File
RelativePath=".\tcp_session.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\tme.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\win_bpf_filter.c"
>
</File>
<File
RelativePath=".\win_bpf_filter_init.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Write.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bucket_lookup.h"
>
</File>
<File
RelativePath=".\count_packets.h"
>
</File>
<File
RelativePath=".\dagc.h"
>
</File>
<File
RelativePath=".\DEBUG.H"
>
</File>
<File
RelativePath=".\Devioctl.h"
>
</File>
<File
RelativePath=".\functions.h"
>
</File>
<File
RelativePath=".\jitter.h"
>
</File>
<File
RelativePath=".\memory_t.h"
>
</File>
<File
RelativePath=".\normal_lookup.h"
>
</File>
<File
RelativePath=".\Ntddndis.h"
>
</File>
<File
RelativePath=".\Ntddpack.h"
>
</File>
<File
RelativePath=".\Packet.h"
>
</File>
<File
RelativePath=".\Packet32.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\resource1.h"
>
</File>
<File
RelativePath=".\tcp_session.h"
>
</File>
<File
RelativePath=".\time_calls.h"
>
</File>
<File
RelativePath=".\tme.h"
>
</File>
<File
RelativePath=".\valid_insns.h"
>
</File>
<File
RelativePath=".\win_bpf.h"
>
</File>
<File
RelativePath=".\win_bpf_filter_init.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\See.rc"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="See"
ProjectGUID="{D817977C-481C-4575-B229-DD2896EDF6C9}"
RootNamespace="See"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)BuiltDriverPackages\See\x86"
IntermediateDirectory="$(PlatformName)_$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="0"
EnableIntrinsicFunctions="false"
FavorSizeOrSpeed="0"
AdditionalIncludeDirectories="$(SolutionDir)Mayaqua\win32_inc;C:\WinDDK\7600.16385.1\inc\ddk;C:\WinDDK\7600.16385.1\inc\api;C:\WinDDK\7600.16385.1\inc\crt;$(SolutionDir)"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NEO_EXPORTS;VPN_SPEED;WIN_NT_DRIVER;_X86_=1;NDIS50;NTKERNEL"
StringPooling="false"
ExceptionHandling="0"
RuntimeLibrary="0"
StructMemberAlignment="4"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CallingConvention="2"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:GenerateVersionResource &quot;$(TargetPath)&quot; /OUT:&quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot; /PRODUCT:&quot;SoftEther VPN&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/driver /subsystem:native,5.00 /FULLBUILD /align:0x80 /osversion:5.00 /MERGE:_PAGE=PAGE /MERGE:_TEXT=.text /NODEFAULTLIB /ALIGN:4096"
AdditionalDependencies="ntoskrnl.lib hal.lib wmilib.lib ndis.lib &quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot;"
OutputFile="$(OutDir)\See_x86.sys"
LinkIncremental="1"
AdditionalLibraryDirectories="C:\WinDDK\7600.16385.1\lib\wnet\i386"
GenerateManifest="false"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(SolutionDir)DebugFiles\pdb\$(PlatformName)_$(ConfigurationName)\$(ProjectName).pdb"
GenerateMapFile="true"
MapFileName="$(SolutionDir)DebugFiles\map\$(PlatformName)_$(ConfigurationName)\$(ProjectName).map"
SubSystem="0"
StackReserveSize="262144"
StackCommitSize="4096"
OptimizeReferences="1"
EnableCOMDATFolding="1"
EntryPointSymbol="DriverEntry"
BaseAddress="0x10000"
RandomizedBaseAddress="0"
DataExecutionPrevention="0"
ImportLibrary="$(SolutionDir)tmp\lib\$(PlatformName)_$(ConfigurationName)\$(ProjectName).lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode &quot;$(TargetPath)&quot; /COMMENT:&quot;VPN Software&quot; /KERNEL:yes"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)BuiltDriverPackages\See\x64"
IntermediateDirectory="$(PlatformName)_$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="0"
EnableIntrinsicFunctions="false"
FavorSizeOrSpeed="0"
AdditionalIncludeDirectories="$(SolutionDir)Mayaqua\win32_inc;C:\WinDDK\7600.16385.1\inc\ddk;C:\WinDDK\7600.16385.1\inc\api;C:\WinDDK\7600.16385.1\inc\crt;$(SolutionDir)"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NEO_EXPORTS;VPN_SPEED;WIN_NT_DRIVER;NDIS50;WIN32_EXT;__NPF_AMD64__;_AMD64_;AMD64;_WIN64;NTKERNEL;CPU_64"
StringPooling="false"
ExceptionHandling="0"
RuntimeLibrary="0"
StructMemberAlignment="4"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CallingConvention="2"
CompileAs="1"
DisableSpecificWarnings="4996;4334"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:GenerateVersionResource &quot;$(TargetPath)&quot; /OUT:&quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot; /PRODUCT:&quot;SoftEther VPN&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/driver /subsystem:native /FULLBUILD /align:0x80 /osversion:5.00 /MERGE:_PAGE=PAGE /MERGE:_TEXT=.text /NODEFAULTLIB /ALIGN:4096"
AdditionalDependencies="ntoskrnl.lib hal.lib wmilib.lib ndis.lib &quot;$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(PlatformName).res&quot;"
OutputFile="$(OutDir)\See_x64.sys"
LinkIncremental="1"
AdditionalLibraryDirectories="C:\WinDDK\7600.16385.1\lib\wnet\amd64"
GenerateManifest="false"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(SolutionDir)DebugFiles\pdb\$(PlatformName)_$(ConfigurationName)\$(ProjectName).pdb"
GenerateMapFile="true"
MapFileName="$(SolutionDir)DebugFiles\map\$(PlatformName)_$(ConfigurationName)\$(ProjectName).map"
SubSystem="0"
StackReserveSize="262144"
StackCommitSize="4096"
OptimizeReferences="1"
EnableCOMDATFolding="1"
EntryPointSymbol="DriverEntry"
BaseAddress="0x10000"
RandomizedBaseAddress="0"
DataExecutionPrevention="0"
ImportLibrary="$(SolutionDir)tmp\lib\$(PlatformName)_$(ConfigurationName)\$(ProjectName).lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode &quot;$(TargetPath)&quot; /COMMENT:&quot;VPN Software&quot; /KERNEL:yes"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\bucket_lookup.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\count_packets.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\dump.c"
>
</File>
<File
RelativePath=".\functions.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\jitter.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\normal_lookup.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Openclos.c"
>
</File>
<File
RelativePath=".\Packet.c"
>
</File>
<File
RelativePath=".\Read.c"
>
</File>
<File
RelativePath=".\tcp_session.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\tme.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\win_bpf_filter.c"
>
</File>
<File
RelativePath=".\win_bpf_filter_init.c"
>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Write.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\bucket_lookup.h"
>
</File>
<File
RelativePath=".\count_packets.h"
>
</File>
<File
RelativePath=".\dagc.h"
>
</File>
<File
RelativePath=".\DEBUG.H"
>
</File>
<File
RelativePath=".\Devioctl.h"
>
</File>
<File
RelativePath=".\functions.h"
>
</File>
<File
RelativePath=".\jitter.h"
>
</File>
<File
RelativePath=".\memory_t.h"
>
</File>
<File
RelativePath=".\normal_lookup.h"
>
</File>
<File
RelativePath=".\Ntddndis.h"
>
</File>
<File
RelativePath=".\Ntddpack.h"
>
</File>
<File
RelativePath=".\Packet.h"
>
</File>
<File
RelativePath=".\Packet32.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\resource1.h"
>
</File>
<File
RelativePath=".\tcp_session.h"
>
</File>
<File
RelativePath=".\time_calls.h"
>
</File>
<File
RelativePath=".\tme.h"
>
</File>
<File
RelativePath=".\valid_insns.h"
>
</File>
<File
RelativePath=".\win_bpf.h"
>
</File>
<File
RelativePath=".\win_bpf_filter_init.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\See.rc"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,426 +1,426 @@
/*
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#include "stdarg.h"
#include "ntddk.h"
#include "ntiologc.h"
#include "ndis.h"
#include "debug.h"
#include "packet.h"
void *test_addr = NULL;
//-------------------------------------------------------------------
NTSTATUS
NPF_Write(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
POPEN_INSTANCE Open;
PIO_STACK_LOCATION IrpSp;
PNDIS_PACKET pPacket;
UINT i;
NDIS_STATUS Status;
IF_LOUD(DbgPrint("NPF_Write\n");)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
if( Open->Bound == FALSE )
{
// The Network adapter was removed.
EXIT_FAILURE(0);
}
NdisAcquireSpinLock(&Open->WriteLock);
if(Open->WriteInProgress)
{
// Another write operation is currently in progress
NdisReleaseSpinLock(&Open->WriteLock);
EXIT_FAILURE(0);
}
else
{
Open->WriteInProgress = TRUE;
}
NdisReleaseSpinLock(&Open->WriteLock);
IF_LOUD(DbgPrint("Max frame size = %d, packet size = %d\n", Open->MaxFrameSize, IrpSp->Parameters.Write.Length);)
if(IrpSp->Parameters.Write.Length == 0 || // Check that the buffer provided by the user is not empty
Open->MaxFrameSize == 0/* || // Check that the MaxFrameSize is correctly initialized
IrpSp->Parameters.Write.Length > Open->MaxFrameSize*/) // Check that the fame size is smaller that the MTU
{
IF_LOUD(DbgPrint("frame size out of range, send aborted\n");)
EXIT_FAILURE(0);
}
IoMarkIrpPending(Irp);
Open->Multiple_Write_Counter=Open->Nwrites;
NdisResetEvent(&Open->WriteEvent);
for(i=0;i<Open->Nwrites;i++){
// Try to get a packet from our list of free ones
NdisAllocatePacket(
&Status,
&pPacket,
Open->PacketPool
);
if (Status != NDIS_STATUS_SUCCESS) {
// No free packets
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_INSUFFICIENT_RESOURCES;
}
if(Open->SkipSentPackets)
{
NdisSetPacketFlags(
pPacket,
g_SendPacketFlags);
}
// The packet hasn't a buffer that needs not to be freed after every single write
RESERVED(pPacket)->FreeBufAfterWrite = FALSE;
// Save the IRP associated with the packet
RESERVED(pPacket)->Irp=Irp;
// Attach the writes buffer to the packet
NdisChainBufferAtFront(pPacket,Irp->MdlAddress);
test_addr = MmGetMdlVirtualAddress(Irp->MdlAddress);
// Call the MAC
NdisSend(
&Status,
Open->AdapterHandle,
pPacket);
if (Status != NDIS_STATUS_PENDING) {
// The send didn't pend so call the completion handler now
NPF_SendComplete(
Open,
pPacket,
Status
);
}
if(i%100==99){
NdisWaitEvent(&Open->WriteEvent,1000);
NdisResetEvent(&Open->WriteEvent);
}
}
return(STATUS_PENDING);
}
//-------------------------------------------------------------------
INT
NPF_BufferedWrite(
IN PIRP Irp,
IN PCHAR UserBuff,
IN ULONG UserBuffSize,
BOOLEAN Sync)
{
POPEN_INSTANCE Open;
PIO_STACK_LOCATION IrpSp;
PNDIS_PACKET pPacket;
NDIS_STATUS Status;
struct sf_pkthdr *winpcap_hdr;
PMDL TmpMdl;
PCHAR EndOfUserBuff = UserBuff + UserBuffSize;
IF_LOUD(DbgPrint("NPF: BufferedWrite, UserBuff=%x, Size=%u\n", UserBuff, UserBuffSize);)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
if( Open->Bound == FALSE ){
// The Network adapter was removed.
return 0;
}
// Sanity check on the user buffer
if(UserBuff == NULL)
{
return 0;
}
// Check that the MaxFrameSize is correctly initialized
if(Open->MaxFrameSize == 0)
{
IF_LOUD(DbgPrint("BufferedWrite: Open->MaxFrameSize not initialized, probably because of a problem in the OID query\n");)
return 0;
}
// Reset the event used to synchronize packet allocation
NdisResetEvent(&Open->WriteEvent);
// Reset the pending packets counter
Open->Multiple_Write_Counter = 0;
// Start from the first packet
winpcap_hdr = (struct sf_pkthdr*)UserBuff;
// Check the consistency of the user buffer
if( (PCHAR)winpcap_hdr + winpcap_hdr->caplen + sizeof(struct sf_pkthdr) > EndOfUserBuff )
{
IF_LOUD(DbgPrint("Buffered Write: bogus packet buffer\n");)
return -1;
}
//
// Main loop: send the buffer to the wire
//
while(TRUE)
{
if(winpcap_hdr->caplen ==0/* || winpcap_hdr->caplen > Open->MaxFrameSize*/)
{
// Malformed header
IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed or bogus user buffer, aborting write.\n");)
return -1;
}
// Allocate an MDL to map the packet data
TmpMdl = IoAllocateMdl((PCHAR)winpcap_hdr + sizeof(struct sf_pkthdr),
winpcap_hdr->caplen,
FALSE,
FALSE,
NULL);
if (TmpMdl == NULL)
{
// Unable to map the memory: packet lost
IF_LOUD(DbgPrint("NPF_BufferedWrite: unable to allocate the MDL.\n");)
return -1;
}
MmBuildMdlForNonPagedPool(TmpMdl); // XXX can this line be removed?
// Allocate a packet from our free list
NdisAllocatePacket( &Status, &pPacket, Open->PacketPool);
if (Status != NDIS_STATUS_SUCCESS) {
// No more free packets
IF_LOUD(DbgPrint("NPF_BufferedWrite: no more free packets, returning.\n");)
NdisResetEvent(&Open->WriteEvent);
NdisWaitEvent(&Open->WriteEvent, 1000);
// Try again to allocate a packet
NdisAllocatePacket( &Status, &pPacket, Open->PacketPool);
if (Status != NDIS_STATUS_SUCCESS) {
// Second failure, report an error
IoFreeMdl(TmpMdl);
return -1;
}
// IoFreeMdl(TmpMdl);
// return (PCHAR)winpcap_hdr - UserBuff;
}
if(Open->SkipSentPackets)
{
NdisSetPacketFlags(
pPacket,
g_SendPacketFlags);
}
// The packet has a buffer that needs to be freed after every single write
RESERVED(pPacket)->FreeBufAfterWrite = TRUE;
TmpMdl->Next = NULL;
// Attach the MDL to the packet
NdisChainBufferAtFront(pPacket, TmpMdl);
// Increment the number of pending sends
InterlockedIncrement(&Open->Multiple_Write_Counter);
// Call the MAC
NdisSend( &Status, Open->AdapterHandle, pPacket);
if (Status != NDIS_STATUS_PENDING) {
// The send didn't pend so call the completion handler now
NPF_SendComplete(
Open,
pPacket,
Status
);
}
// Step to the next packet in the buffer
(PCHAR)winpcap_hdr += winpcap_hdr->caplen + sizeof(struct sf_pkthdr);
// Check if the end of the user buffer has been reached
if( (PCHAR)winpcap_hdr >= EndOfUserBuff )
{
IF_LOUD(DbgPrint("NPF_BufferedWrite: End of buffer.\n");)
// Wait the completion of pending sends
NPF_WaitEndOfBufferedWrite(Open);
return (INT)((PCHAR)winpcap_hdr - UserBuff);
}
}
return (INT)((PCHAR)winpcap_hdr - UserBuff);
}
//-------------------------------------------------------------------
VOID NPF_WaitEndOfBufferedWrite(POPEN_INSTANCE Open)
{
UINT i;
NdisResetEvent(&Open->WriteEvent);
for(i=0; Open->Multiple_Write_Counter > 0 && i < TRANSMIT_PACKETS; i++)
{
NdisWaitEvent(&Open->WriteEvent, 100);
NdisResetEvent(&Open->WriteEvent);
}
return;
}
//-------------------------------------------------------------------
VOID
NPF_SendComplete(
IN NDIS_HANDLE ProtocolBindingContext,
IN PNDIS_PACKET pPacket,
IN NDIS_STATUS Status
)
{
PIRP Irp;
PIO_STACK_LOCATION irpSp;
POPEN_INSTANCE Open;
PMDL TmpMdl;
IF_LOUD(DbgPrint("NPF: SendComplete, BindingContext=%d\n",ProtocolBindingContext);)
Open= (POPEN_INSTANCE)ProtocolBindingContext;
if( RESERVED(pPacket)->FreeBufAfterWrite )
{
//
// Packet sent by NPF_BufferedWrite()
//
// Free the MDL associated with the packet
NdisUnchainBufferAtFront(pPacket, &TmpMdl);
IoFreeMdl(TmpMdl);
// recyle the packet
// NdisReinitializePacket(pPacket);
NdisFreePacket(pPacket);
// Increment the number of pending sends
InterlockedDecrement(&Open->Multiple_Write_Counter);
NdisSetEvent(&Open->WriteEvent);
return;
}
else
{
//
// Packet sent by NPF_Write()
//
if((Open->Nwrites - Open->Multiple_Write_Counter) %100 == 99)
NdisSetEvent(&Open->WriteEvent);
Open->Multiple_Write_Counter--;
if(Open->Multiple_Write_Counter == 0){
// Release the buffer and awake the application
NdisUnchainBufferAtFront(pPacket, &TmpMdl);
// Complete the request
Irp=RESERVED(pPacket)->Irp;
irpSp = IoGetCurrentIrpStackLocation(Irp);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
NdisAcquireSpinLock(&Open->WriteLock);
Open->WriteInProgress = FALSE;
NdisReleaseSpinLock(&Open->WriteLock);
}
// Put the packet back on the free list
NdisFreePacket(pPacket);
return;
}
}
/*
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#include "stdarg.h"
#include "ntddk.h"
#include "ntiologc.h"
#include "ndis.h"
#include "debug.h"
#include "packet.h"
void *test_addr = NULL;
//-------------------------------------------------------------------
NTSTATUS
NPF_Write(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
POPEN_INSTANCE Open;
PIO_STACK_LOCATION IrpSp;
PNDIS_PACKET pPacket;
UINT i;
NDIS_STATUS Status;
IF_LOUD(DbgPrint("NPF_Write\n");)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
if( Open->Bound == FALSE )
{
// The Network adapter was removed.
EXIT_FAILURE(0);
}
NdisAcquireSpinLock(&Open->WriteLock);
if(Open->WriteInProgress)
{
// Another write operation is currently in progress
NdisReleaseSpinLock(&Open->WriteLock);
EXIT_FAILURE(0);
}
else
{
Open->WriteInProgress = TRUE;
}
NdisReleaseSpinLock(&Open->WriteLock);
IF_LOUD(DbgPrint("Max frame size = %d, packet size = %d\n", Open->MaxFrameSize, IrpSp->Parameters.Write.Length);)
if(IrpSp->Parameters.Write.Length == 0 || // Check that the buffer provided by the user is not empty
Open->MaxFrameSize == 0/* || // Check that the MaxFrameSize is correctly initialized
IrpSp->Parameters.Write.Length > Open->MaxFrameSize*/) // Check that the fame size is smaller that the MTU
{
IF_LOUD(DbgPrint("frame size out of range, send aborted\n");)
EXIT_FAILURE(0);
}
IoMarkIrpPending(Irp);
Open->Multiple_Write_Counter=Open->Nwrites;
NdisResetEvent(&Open->WriteEvent);
for(i=0;i<Open->Nwrites;i++){
// Try to get a packet from our list of free ones
NdisAllocatePacket(
&Status,
&pPacket,
Open->PacketPool
);
if (Status != NDIS_STATUS_SUCCESS) {
// No free packets
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_INSUFFICIENT_RESOURCES;
}
if(Open->SkipSentPackets)
{
NdisSetPacketFlags(
pPacket,
g_SendPacketFlags);
}
// The packet hasn't a buffer that needs not to be freed after every single write
RESERVED(pPacket)->FreeBufAfterWrite = FALSE;
// Save the IRP associated with the packet
RESERVED(pPacket)->Irp=Irp;
// Attach the writes buffer to the packet
NdisChainBufferAtFront(pPacket,Irp->MdlAddress);
test_addr = MmGetMdlVirtualAddress(Irp->MdlAddress);
// Call the MAC
NdisSend(
&Status,
Open->AdapterHandle,
pPacket);
if (Status != NDIS_STATUS_PENDING) {
// The send didn't pend so call the completion handler now
NPF_SendComplete(
Open,
pPacket,
Status
);
}
if(i%100==99){
NdisWaitEvent(&Open->WriteEvent,1000);
NdisResetEvent(&Open->WriteEvent);
}
}
return(STATUS_PENDING);
}
//-------------------------------------------------------------------
INT
NPF_BufferedWrite(
IN PIRP Irp,
IN PCHAR UserBuff,
IN ULONG UserBuffSize,
BOOLEAN Sync)
{
POPEN_INSTANCE Open;
PIO_STACK_LOCATION IrpSp;
PNDIS_PACKET pPacket;
NDIS_STATUS Status;
struct sf_pkthdr *winpcap_hdr;
PMDL TmpMdl;
PCHAR EndOfUserBuff = UserBuff + UserBuffSize;
IF_LOUD(DbgPrint("NPF: BufferedWrite, UserBuff=%x, Size=%u\n", UserBuff, UserBuffSize);)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
if( Open->Bound == FALSE ){
// The Network adapter was removed.
return 0;
}
// Sanity check on the user buffer
if(UserBuff == NULL)
{
return 0;
}
// Check that the MaxFrameSize is correctly initialized
if(Open->MaxFrameSize == 0)
{
IF_LOUD(DbgPrint("BufferedWrite: Open->MaxFrameSize not initialized, probably because of a problem in the OID query\n");)
return 0;
}
// Reset the event used to synchronize packet allocation
NdisResetEvent(&Open->WriteEvent);
// Reset the pending packets counter
Open->Multiple_Write_Counter = 0;
// Start from the first packet
winpcap_hdr = (struct sf_pkthdr*)UserBuff;
// Check the consistency of the user buffer
if( (PCHAR)winpcap_hdr + winpcap_hdr->caplen + sizeof(struct sf_pkthdr) > EndOfUserBuff )
{
IF_LOUD(DbgPrint("Buffered Write: bogus packet buffer\n");)
return -1;
}
//
// Main loop: send the buffer to the wire
//
while(TRUE)
{
if(winpcap_hdr->caplen ==0/* || winpcap_hdr->caplen > Open->MaxFrameSize*/)
{
// Malformed header
IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed or bogus user buffer, aborting write.\n");)
return -1;
}
// Allocate an MDL to map the packet data
TmpMdl = IoAllocateMdl((PCHAR)winpcap_hdr + sizeof(struct sf_pkthdr),
winpcap_hdr->caplen,
FALSE,
FALSE,
NULL);
if (TmpMdl == NULL)
{
// Unable to map the memory: packet lost
IF_LOUD(DbgPrint("NPF_BufferedWrite: unable to allocate the MDL.\n");)
return -1;
}
MmBuildMdlForNonPagedPool(TmpMdl); // XXX can this line be removed?
// Allocate a packet from our free list
NdisAllocatePacket( &Status, &pPacket, Open->PacketPool);
if (Status != NDIS_STATUS_SUCCESS) {
// No more free packets
IF_LOUD(DbgPrint("NPF_BufferedWrite: no more free packets, returning.\n");)
NdisResetEvent(&Open->WriteEvent);
NdisWaitEvent(&Open->WriteEvent, 1000);
// Try again to allocate a packet
NdisAllocatePacket( &Status, &pPacket, Open->PacketPool);
if (Status != NDIS_STATUS_SUCCESS) {
// Second failure, report an error
IoFreeMdl(TmpMdl);
return -1;
}
// IoFreeMdl(TmpMdl);
// return (PCHAR)winpcap_hdr - UserBuff;
}
if(Open->SkipSentPackets)
{
NdisSetPacketFlags(
pPacket,
g_SendPacketFlags);
}
// The packet has a buffer that needs to be freed after every single write
RESERVED(pPacket)->FreeBufAfterWrite = TRUE;
TmpMdl->Next = NULL;
// Attach the MDL to the packet
NdisChainBufferAtFront(pPacket, TmpMdl);
// Increment the number of pending sends
InterlockedIncrement(&Open->Multiple_Write_Counter);
// Call the MAC
NdisSend( &Status, Open->AdapterHandle, pPacket);
if (Status != NDIS_STATUS_PENDING) {
// The send didn't pend so call the completion handler now
NPF_SendComplete(
Open,
pPacket,
Status
);
}
// Step to the next packet in the buffer
(PCHAR)winpcap_hdr += winpcap_hdr->caplen + sizeof(struct sf_pkthdr);
// Check if the end of the user buffer has been reached
if( (PCHAR)winpcap_hdr >= EndOfUserBuff )
{
IF_LOUD(DbgPrint("NPF_BufferedWrite: End of buffer.\n");)
// Wait the completion of pending sends
NPF_WaitEndOfBufferedWrite(Open);
return (INT)((PCHAR)winpcap_hdr - UserBuff);
}
}
return (INT)((PCHAR)winpcap_hdr - UserBuff);
}
//-------------------------------------------------------------------
VOID NPF_WaitEndOfBufferedWrite(POPEN_INSTANCE Open)
{
UINT i;
NdisResetEvent(&Open->WriteEvent);
for(i=0; Open->Multiple_Write_Counter > 0 && i < TRANSMIT_PACKETS; i++)
{
NdisWaitEvent(&Open->WriteEvent, 100);
NdisResetEvent(&Open->WriteEvent);
}
return;
}
//-------------------------------------------------------------------
VOID
NPF_SendComplete(
IN NDIS_HANDLE ProtocolBindingContext,
IN PNDIS_PACKET pPacket,
IN NDIS_STATUS Status
)
{
PIRP Irp;
PIO_STACK_LOCATION irpSp;
POPEN_INSTANCE Open;
PMDL TmpMdl;
IF_LOUD(DbgPrint("NPF: SendComplete, BindingContext=%d\n",ProtocolBindingContext);)
Open= (POPEN_INSTANCE)ProtocolBindingContext;
if( RESERVED(pPacket)->FreeBufAfterWrite )
{
//
// Packet sent by NPF_BufferedWrite()
//
// Free the MDL associated with the packet
NdisUnchainBufferAtFront(pPacket, &TmpMdl);
IoFreeMdl(TmpMdl);
// recyle the packet
// NdisReinitializePacket(pPacket);
NdisFreePacket(pPacket);
// Increment the number of pending sends
InterlockedDecrement(&Open->Multiple_Write_Counter);
NdisSetEvent(&Open->WriteEvent);
return;
}
else
{
//
// Packet sent by NPF_Write()
//
if((Open->Nwrites - Open->Multiple_Write_Counter) %100 == 99)
NdisSetEvent(&Open->WriteEvent);
Open->Multiple_Write_Counter--;
if(Open->Multiple_Write_Counter == 0){
// Release the buffer and awake the application
NdisUnchainBufferAtFront(pPacket, &TmpMdl);
// Complete the request
Irp=RESERVED(pPacket)->Irp;
irpSp = IoGetCurrentIrpStackLocation(Irp);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
NdisAcquireSpinLock(&Open->WriteLock);
Open->WriteInProgress = FALSE;
NdisReleaseSpinLock(&Open->WriteLock);
}
// Put the packet back on the free list
NdisFreePacket(pPacket);
return;
}
}

View File

@ -1,264 +1,264 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "bucket_lookup.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/bucket_lookup.h>
#else
#include <tme/tme.h>
#include <tme/bucket_lookup.h>
#endif
#endif
/* the key is represented by the initial and final value */
/* of the bucket. At the moment bucket_lookup is able to */
/* manage values of 16, 32 bits. */
uint32 bucket_lookup(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 value;
uint32 i,j;
int found=-1;
uint32 blocks;
uint32 block_size;
uint8 *temp;
if ((data->key_len!=1)&& /*16 bit value*/
(data->key_len!=2)) /*32 bit value*/
return TME_ERROR;
/*32 bit values*/
blocks=data->filled_blocks-1;
block_size=data->block_size;
i=blocks/2; /*relative shift*/
j=i;
temp=data->shared_memory_base_address+block_size;
if (data->key_len==2)
{
value=SW_ULONG_AT(key,0);
if((value<SW_ULONG_AT(temp,0))||(value>SW_ULONG_AT(temp+block_size*(blocks-1),4)))
{
uint32 *key32=(uint32*) key;
key32[0]=key32[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+8),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
while(found==-1) /* search routine */
{
i=(i==1)? 1:i>>1;
if (SW_ULONG_AT(temp+block_size*j,0)>value)
if (SW_ULONG_AT(temp+block_size*(j-1),4)<value)
found=-2;
else
j-=i;
else
if (SW_ULONG_AT(temp+block_size*j,4)<value)
if (SW_ULONG_AT(temp+block_size*j,0)>value)
found=-2;
else
j+=i;
else found=j;
}
if (found<0)
{
uint32 *key32=(uint32*) key;
key32[0]=key32[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+8),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
data->last_found=data->lut_base_address+found*sizeof(RECORD);
COPY_MEMORY(key,temp+block_size*found,8);
GET_TIME((struct timeval *)(temp+block_size*found+8),time_ref);
return TME_TRUE;
}
else
{
value=SW_USHORT_AT(key,0);
if((value<SW_USHORT_AT(temp,0))||(value>SW_USHORT_AT(temp+block_size*(blocks-1),2)))
{
uint16 *key16=(uint16*) key;
key16[0]=key16[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+4),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
while(found==-1) /* search routine */
{
i=(i==1)? 1:i>>1;
if (SW_USHORT_AT(temp+block_size*j,0)>value)
if (SW_USHORT_AT(temp+block_size*(j-1),2)<value)
found=-2;
else
j-=i;
else
if (SW_USHORT_AT(temp+block_size*j,2)<value)
if (SW_USHORT_AT(temp+block_size*j,0)>value)
found=-2;
else
j+=i;
else found=j;
}
if (found<0)
{
uint16 *key16=(uint16*) key;
key16[0]=key16[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+4),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
data->last_found=data->lut_base_address+found*sizeof(RECORD);
GET_TIME((struct timeval *)(temp+block_size*found+4),time_ref);
COPY_MEMORY(key,temp+block_size*found,4);
return TME_TRUE;
}
}
uint32 bucket_lookup_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
RECORD *records=(RECORD*)data->lut_base_address;
if ((data->key_len!=1)&& /*16 bit value*/
(data->key_len!=2)) /*32 bit value*/
return TME_ERROR;
if(data->key_len==2)
{
uint32 start,stop;
uint8 *tmp;
start=SW_ULONG_AT(key,0);
stop=SW_ULONG_AT(key,4);
if (start>stop)
return TME_ERROR;
if (data->filled_entries>0)
{
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries-1].block,0);
/*check if it is coherent with the previous block*/
if (SW_ULONG_AT(tmp,4)>=start)
return TME_ERROR;
}
if (data->filled_blocks==data->shared_memory_blocks)
return TME_ERROR;
if (data->filled_entries==data->lut_entries)
return TME_ERROR;
tmp=data->shared_memory_base_address+data->block_size*data->filled_blocks;
COPY_MEMORY(tmp,key,8);
SW_ULONG_ASSIGN(&records[data->filled_entries].block,tmp-mem_ex->buffer);
SW_ULONG_ASSIGN(&records[data->filled_entries].exec_fcn,data->default_exec);
GET_TIME((struct timeval *)(tmp+8),time_ref);
data->filled_blocks++;
data->filled_entries++;
return TME_TRUE;
}
else
{
uint16 start,stop;
uint8 *tmp;
start=SW_USHORT_AT(key,0);
stop=SW_USHORT_AT(key,2);
if (start>stop)
return TME_ERROR;
if (data->filled_entries>0)
{
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries-1].block,0);
/*check if it is coherent with the previous block*/
if (SW_USHORT_AT(tmp,2)>=start)
return TME_ERROR;
}
if (data->filled_blocks==data->shared_memory_blocks)
return TME_ERROR;
if (data->filled_entries==data->lut_entries)
return TME_ERROR;
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries].block,0);
COPY_MEMORY(tmp,key,4);
SW_ULONG_ASSIGN(&records[data->filled_entries].block,tmp-mem_ex->buffer);
SW_ULONG_ASSIGN(&records[data->filled_entries].exec_fcn,data->default_exec);
GET_TIME((struct timeval *)(tmp+4),time_ref);
data->filled_blocks++;
data->filled_entries++;
return TME_TRUE;
}
}
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "bucket_lookup.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/bucket_lookup.h>
#else
#include <tme/tme.h>
#include <tme/bucket_lookup.h>
#endif
#endif
/* the key is represented by the initial and final value */
/* of the bucket. At the moment bucket_lookup is able to */
/* manage values of 16, 32 bits. */
uint32 bucket_lookup(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 value;
uint32 i,j;
int found=-1;
uint32 blocks;
uint32 block_size;
uint8 *temp;
if ((data->key_len!=1)&& /*16 bit value*/
(data->key_len!=2)) /*32 bit value*/
return TME_ERROR;
/*32 bit values*/
blocks=data->filled_blocks-1;
block_size=data->block_size;
i=blocks/2; /*relative shift*/
j=i;
temp=data->shared_memory_base_address+block_size;
if (data->key_len==2)
{
value=SW_ULONG_AT(key,0);
if((value<SW_ULONG_AT(temp,0))||(value>SW_ULONG_AT(temp+block_size*(blocks-1),4)))
{
uint32 *key32=(uint32*) key;
key32[0]=key32[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+8),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
while(found==-1) /* search routine */
{
i=(i==1)? 1:i>>1;
if (SW_ULONG_AT(temp+block_size*j,0)>value)
if (SW_ULONG_AT(temp+block_size*(j-1),4)<value)
found=-2;
else
j-=i;
else
if (SW_ULONG_AT(temp+block_size*j,4)<value)
if (SW_ULONG_AT(temp+block_size*j,0)>value)
found=-2;
else
j+=i;
else found=j;
}
if (found<0)
{
uint32 *key32=(uint32*) key;
key32[0]=key32[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+8),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
data->last_found=data->lut_base_address+found*sizeof(RECORD);
COPY_MEMORY(key,temp+block_size*found,8);
GET_TIME((struct timeval *)(temp+block_size*found+8),time_ref);
return TME_TRUE;
}
else
{
value=SW_USHORT_AT(key,0);
if((value<SW_USHORT_AT(temp,0))||(value>SW_USHORT_AT(temp+block_size*(blocks-1),2)))
{
uint16 *key16=(uint16*) key;
key16[0]=key16[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+4),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
while(found==-1) /* search routine */
{
i=(i==1)? 1:i>>1;
if (SW_USHORT_AT(temp+block_size*j,0)>value)
if (SW_USHORT_AT(temp+block_size*(j-1),2)<value)
found=-2;
else
j-=i;
else
if (SW_USHORT_AT(temp+block_size*j,2)<value)
if (SW_USHORT_AT(temp+block_size*j,0)>value)
found=-2;
else
j+=i;
else found=j;
}
if (found<0)
{
uint16 *key16=(uint16*) key;
key16[0]=key16[1]=0;
GET_TIME((struct timeval *)(data->shared_memory_base_address+4),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
data->last_found=data->lut_base_address+found*sizeof(RECORD);
GET_TIME((struct timeval *)(temp+block_size*found+4),time_ref);
COPY_MEMORY(key,temp+block_size*found,4);
return TME_TRUE;
}
}
uint32 bucket_lookup_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
RECORD *records=(RECORD*)data->lut_base_address;
if ((data->key_len!=1)&& /*16 bit value*/
(data->key_len!=2)) /*32 bit value*/
return TME_ERROR;
if(data->key_len==2)
{
uint32 start,stop;
uint8 *tmp;
start=SW_ULONG_AT(key,0);
stop=SW_ULONG_AT(key,4);
if (start>stop)
return TME_ERROR;
if (data->filled_entries>0)
{
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries-1].block,0);
/*check if it is coherent with the previous block*/
if (SW_ULONG_AT(tmp,4)>=start)
return TME_ERROR;
}
if (data->filled_blocks==data->shared_memory_blocks)
return TME_ERROR;
if (data->filled_entries==data->lut_entries)
return TME_ERROR;
tmp=data->shared_memory_base_address+data->block_size*data->filled_blocks;
COPY_MEMORY(tmp,key,8);
SW_ULONG_ASSIGN(&records[data->filled_entries].block,tmp-mem_ex->buffer);
SW_ULONG_ASSIGN(&records[data->filled_entries].exec_fcn,data->default_exec);
GET_TIME((struct timeval *)(tmp+8),time_ref);
data->filled_blocks++;
data->filled_entries++;
return TME_TRUE;
}
else
{
uint16 start,stop;
uint8 *tmp;
start=SW_USHORT_AT(key,0);
stop=SW_USHORT_AT(key,2);
if (start>stop)
return TME_ERROR;
if (data->filled_entries>0)
{
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries-1].block,0);
/*check if it is coherent with the previous block*/
if (SW_USHORT_AT(tmp,2)>=start)
return TME_ERROR;
}
if (data->filled_blocks==data->shared_memory_blocks)
return TME_ERROR;
if (data->filled_entries==data->lut_entries)
return TME_ERROR;
tmp=mem_ex->buffer+SW_ULONG_AT(&records[data->filled_entries].block,0);
COPY_MEMORY(tmp,key,4);
SW_ULONG_ASSIGN(&records[data->filled_entries].block,tmp-mem_ex->buffer);
SW_ULONG_ASSIGN(&records[data->filled_entries].exec_fcn,data->default_exec);
GET_TIME((struct timeval *)(tmp+4),time_ref);
data->filled_blocks++;
data->filled_entries++;
return TME_TRUE;
}
}

View File

@ -1,54 +1,54 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __bucket_lookup
#define __bucket_lookup
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define BUCKET_LOOKUP_INSERT 0x00000011
uint32 bucket_lookup_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define BUCKET_LOOKUP 0x00000010
uint32 bucket_lookup(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __bucket_lookup
#define __bucket_lookup
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define BUCKET_LOOKUP_INSERT 0x00000011
uint32 bucket_lookup_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define BUCKET_LOOKUP 0x00000010
uint32 bucket_lookup(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#endif

View File

@ -1,64 +1,64 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "count_packets.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/count_packets.h>
#else
#include <tme/tme.h>
#include <tme/count_packets.h>
#endif
#endif
uint32 count_packets(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data)
{
c_p_data *counters=(c_p_data*)(block+data->key_len*4);
counters->bytes+=pkt_size;
counters->packets++;
return TME_SUCCESS;
}
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "count_packets.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/count_packets.h>
#else
#include <tme/tme.h>
#include <tme/count_packets.h>
#endif
#endif
uint32 count_packets(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data)
{
c_p_data *counters=(c_p_data*)(block+data->key_len*4);
counters->bytes+=pkt_size;
counters->packets++;
return TME_SUCCESS;
}

View File

@ -1,62 +1,62 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __count_packets
#define __count_packets
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
typedef struct __c_p_data
{
struct timeval timestamp;
uint64 packets;
uint64 bytes;
}
c_p_data;
#define COUNT_PACKETS 0x00000000
uint32 count_packets(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __count_packets
#define __count_packets
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
typedef struct __c_p_data
{
struct timeval timestamp;
uint64 packets;
uint64 bytes;
}
c_p_data;
#define COUNT_PACKETS 0x00000000
uint32 count_packets(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
#endif

View File

@ -1,225 +1,225 @@
/*
* Copyright (c) 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define DAGC_ERRBUF_SIZE 512
#define FILEBUFSIZE 65536
#define MAXDAGCARDS 32
#ifndef _WIN32
typedef long long long_long;
typedef long long ull_t;
#define TRUE 1
#define devicestring "/dev/dag%d"
#define dagc_sleepms(_MS) usleep(_MS * 1000)
#else /* _WIN32 */
typedef LONGLONG long_long;
typedef ULONGLONG ull_t;
#define dagc_sleepms(_MS) Sleep(_MS)
#define devicestring "\\\\.\\dag%d"
#endif /* _WIN32 */
#define MIN_DAG_SNAPLEN 12
#define MAX_DAG_SNAPLEN 2040
#define erffilestring "erffile://"
#define ATM_SNAPLEN 48
/* Size of ATM payload */
#define ATM_WLEN(h) ATM_SNAPLEN
#define ATM_SLEN(h) ATM_SNAPLEN
/* Size Ethernet payload */
#define ETHERNET_WLEN(h, b) ((u_int)ntohs((h)->wlen) - ((b) >> 3))
#define ETHERNET_SLEN(h, b) min(ETHERNET_WLEN(h, b), \
(u_int)ntohs((h)->rlen) - dag_record_size - 2)
/* Size of HDLC payload */
#define HDLC_WLEN(h, b) ((u_int)ntohs((h)->wlen) - ((b) >> 3))
#define HDLC_SLEN(h, b) min(HDLC_WLEN(h, b), \
(u_int)ntohs((h)->rlen) - dag_record_size)
/* Flags for dagc_open */
#define DAGC_OPEN_SHARED 1
#define DAGC_OPEN_EXCLUSIVE 2
#define TYPE_LEGACY 0
#define TYPE_HDLC_POS 1
#define TYPE_ETH 2
#define TYPE_ATM 3
#define TYPE_AAL5 4
/*
* Card statistics.
*/
typedef struct dagc_stats_t
{
ull_t received; /* (NOT IMPLEMENTED) total number of frames received by the DAG */
ull_t dropped; /* number of frames dropped for buffer full */
ull_t captured; /* (NOT IMPLEMENTED) number of frames that actually reach the
application, i.e that are not filtered or dropped */
} dagc_stats_t;
/*
* Descriptor of an open session.
* Note: the dagc_t descriptor is completely opaque to the application. It can be compared
* to a file descriptor.
*/
typedef struct dagc dagc_t;
/*
* Card description.
*/
typedef struct dagc_if_t
{
struct dagc_if_t *next;
char *name; /* pointer to a string to pass to dagc_open*/
char *description; /* human-understandable description (e.g. Endace 3.5e Fast
Ethernet Card) */
} dagc_if_t;
/*
* returns a string with last dagc lib error
*/
#define dagc_getlasterror(dagcfd) dagcfd->errbuf
/*
* returns a linked list with the cards available on the systems. For every card, it scans the
* card type and converts it to a human-understandable string, in order to provide a description
* useful for example when a system has more than one card
*/
int dagc_finddevs (dagc_if_t **alldevsp, char *ebuf);
/*
* frees the card list.
*/
void dagc_freedevs (dagc_if_t *alldevsp);
/*
* Opens a card (or a file) for capture. Snaplen is the portion of packet delivered to the
* application, flags can contain specific settings (for example promisc mode??), minbufsize
* is the smallest buffer that the API can provide to the application (to limit CPU waste
* with several small buffers under moderated network throughputs)
*/
dagc_t* dagc_open(const char *source, unsigned flags, char *ebuf);
/*
* Sets the snaplen of a card
* Returns -1 on failure. On success, the actual snaplen is returned (snap len has to be a multiple of 4
* with DAG cards).
*/
int dagc_setsnaplen(dagc_t *dagcfd, unsigned snaplen);
/*
* closes a capture instance
*/
void dagc_close(dagc_t *dagcfd);
/*
* returns the linktype of a card
*/
int dagc_getlinktype(dagc_t *dagcfd);
/*
* returns the link speed of the adapter, in MB/s.
* If the link speed of the card is unknown, -1 is returned.
* XXX NOTE: Currently, there is no consistent way to get linkspeed querying the card.
* As a consequence, we determine this value statically from the card model. For cards that can run at
* different speeds, we report only the *maximum* speed.
*/
int dagc_getlinkspeed(dagc_t *dagcfd);
/*
* Returns the length of the CRC checksum that the card associates with any packet in the hole. This
* information will be used to understand the actual length of the packet on the wire.
* Note: this information is not provided consistently by DAG cards, so we gather it from an environment
* variable in Unix and from a registry key in Windows.
*/
unsigned dagc_getfcslen(dagc_t *dagcfd);
/*
* provides a buffer with the new packets (from the board or from the file) and its size.
* On success, the return value is 0. If an error has occurred, the return value is -1.
* If EOF has reached, the return value is -2. Note that this function always returns
* immediately, eventually with an empty buffer, so it is possible to have a success (0)
* return value and bufsize = 0.
*/
int dagc_receive(dagc_t *dagcfd, u_char **buffer, u_int *bufsize);
/*
* returns nonzero if any data is available from dagcfd, -1 if an error occurred. Waits until almost the time
* specified by timeout has past or any data is available. If timeout=0, returns immediately.
* If timeout=NULL, blocks until a packet arrives.
*/
int dagc_wait(dagc_t *dagcfd, struct timeval *timeout);
/*
* returns statistics about current capture session
*/
int dagc_stats(dagc_t *dagcfd, dagc_stats_t *ps);
/*
* Opens a dump file to store the data of this capture.
* Returns 0 on success.
* NOTE: currently, dagc_dumpfile_open, dagc_dumpfile_close and dagc_dump are simply wrappers
* for open, close and write. However, if the programmer uses these functions, he is more protected
* against file format changes (for example if the file format will have an header in the future).
* Moreover, assuming that the user knows the file format is a bad practice: providing
* simple simple save functionality is more intuitive and user-friendly.
*/
int dagc_dumpfile_open(dagc_t *dagcfd, char* name);
/*
* Closes a dump file
*/
int dagc_dumpfile_close(dagc_t *dagcfd);
/*
* Writes a buffer of packets to a dump file
* Returns 0 on success.
*/
int dagc_dump(dagc_t *dagcfd, u_char *buffer, u_int bufsize);
/*
* Copyright (c) 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define DAGC_ERRBUF_SIZE 512
#define FILEBUFSIZE 65536
#define MAXDAGCARDS 32
#ifndef _WIN32
typedef long long long_long;
typedef long long ull_t;
#define TRUE 1
#define devicestring "/dev/dag%d"
#define dagc_sleepms(_MS) usleep(_MS * 1000)
#else /* _WIN32 */
typedef LONGLONG long_long;
typedef ULONGLONG ull_t;
#define dagc_sleepms(_MS) Sleep(_MS)
#define devicestring "\\\\.\\dag%d"
#endif /* _WIN32 */
#define MIN_DAG_SNAPLEN 12
#define MAX_DAG_SNAPLEN 2040
#define erffilestring "erffile://"
#define ATM_SNAPLEN 48
/* Size of ATM payload */
#define ATM_WLEN(h) ATM_SNAPLEN
#define ATM_SLEN(h) ATM_SNAPLEN
/* Size Ethernet payload */
#define ETHERNET_WLEN(h, b) ((u_int)ntohs((h)->wlen) - ((b) >> 3))
#define ETHERNET_SLEN(h, b) min(ETHERNET_WLEN(h, b), \
(u_int)ntohs((h)->rlen) - dag_record_size - 2)
/* Size of HDLC payload */
#define HDLC_WLEN(h, b) ((u_int)ntohs((h)->wlen) - ((b) >> 3))
#define HDLC_SLEN(h, b) min(HDLC_WLEN(h, b), \
(u_int)ntohs((h)->rlen) - dag_record_size)
/* Flags for dagc_open */
#define DAGC_OPEN_SHARED 1
#define DAGC_OPEN_EXCLUSIVE 2
#define TYPE_LEGACY 0
#define TYPE_HDLC_POS 1
#define TYPE_ETH 2
#define TYPE_ATM 3
#define TYPE_AAL5 4
/*
* Card statistics.
*/
typedef struct dagc_stats_t
{
ull_t received; /* (NOT IMPLEMENTED) total number of frames received by the DAG */
ull_t dropped; /* number of frames dropped for buffer full */
ull_t captured; /* (NOT IMPLEMENTED) number of frames that actually reach the
application, i.e that are not filtered or dropped */
} dagc_stats_t;
/*
* Descriptor of an open session.
* Note: the dagc_t descriptor is completely opaque to the application. It can be compared
* to a file descriptor.
*/
typedef struct dagc dagc_t;
/*
* Card description.
*/
typedef struct dagc_if_t
{
struct dagc_if_t *next;
char *name; /* pointer to a string to pass to dagc_open*/
char *description; /* human-understandable description (e.g. Endace 3.5e Fast
Ethernet Card) */
} dagc_if_t;
/*
* returns a string with last dagc lib error
*/
#define dagc_getlasterror(dagcfd) dagcfd->errbuf
/*
* returns a linked list with the cards available on the systems. For every card, it scans the
* card type and converts it to a human-understandable string, in order to provide a description
* useful for example when a system has more than one card
*/
int dagc_finddevs (dagc_if_t **alldevsp, char *ebuf);
/*
* frees the card list.
*/
void dagc_freedevs (dagc_if_t *alldevsp);
/*
* Opens a card (or a file) for capture. Snaplen is the portion of packet delivered to the
* application, flags can contain specific settings (for example promisc mode??), minbufsize
* is the smallest buffer that the API can provide to the application (to limit CPU waste
* with several small buffers under moderated network throughputs)
*/
dagc_t* dagc_open(const char *source, unsigned flags, char *ebuf);
/*
* Sets the snaplen of a card
* Returns -1 on failure. On success, the actual snaplen is returned (snap len has to be a multiple of 4
* with DAG cards).
*/
int dagc_setsnaplen(dagc_t *dagcfd, unsigned snaplen);
/*
* closes a capture instance
*/
void dagc_close(dagc_t *dagcfd);
/*
* returns the linktype of a card
*/
int dagc_getlinktype(dagc_t *dagcfd);
/*
* returns the link speed of the adapter, in MB/s.
* If the link speed of the card is unknown, -1 is returned.
* XXX NOTE: Currently, there is no consistent way to get linkspeed querying the card.
* As a consequence, we determine this value statically from the card model. For cards that can run at
* different speeds, we report only the *maximum* speed.
*/
int dagc_getlinkspeed(dagc_t *dagcfd);
/*
* Returns the length of the CRC checksum that the card associates with any packet in the hole. This
* information will be used to understand the actual length of the packet on the wire.
* Note: this information is not provided consistently by DAG cards, so we gather it from an environment
* variable in Unix and from a registry key in Windows.
*/
unsigned dagc_getfcslen(dagc_t *dagcfd);
/*
* provides a buffer with the new packets (from the board or from the file) and its size.
* On success, the return value is 0. If an error has occurred, the return value is -1.
* If EOF has reached, the return value is -2. Note that this function always returns
* immediately, eventually with an empty buffer, so it is possible to have a success (0)
* return value and bufsize = 0.
*/
int dagc_receive(dagc_t *dagcfd, u_char **buffer, u_int *bufsize);
/*
* returns nonzero if any data is available from dagcfd, -1 if an error occurred. Waits until almost the time
* specified by timeout has past or any data is available. If timeout=0, returns immediately.
* If timeout=NULL, blocks until a packet arrives.
*/
int dagc_wait(dagc_t *dagcfd, struct timeval *timeout);
/*
* returns statistics about current capture session
*/
int dagc_stats(dagc_t *dagcfd, dagc_stats_t *ps);
/*
* Opens a dump file to store the data of this capture.
* Returns 0 on success.
* NOTE: currently, dagc_dumpfile_open, dagc_dumpfile_close and dagc_dump are simply wrappers
* for open, close and write. However, if the programmer uses these functions, he is more protected
* against file format changes (for example if the file format will have an header in the future).
* Moreover, assuming that the user knows the file format is a bad practice: providing
* simple simple save functionality is more intuitive and user-friendly.
*/
int dagc_dumpfile_open(dagc_t *dagcfd, char* name);
/*
* Closes a dump file
*/
int dagc_dumpfile_close(dagc_t *dagcfd);
/*
* Writes a buffer of packets to a dump file
* Returns 0 on success.
*/
int dagc_dump(dagc_t *dagcfd, u_char *buffer, u_int bufsize);

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +1,95 @@
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "functions.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/bpf.h>
#include <net/tme/functions.h>
#else
#include <tme/tme.h>
#include <bpf.h>
#include <tme/functions.h>
#endif
#endif
lut_fcn lut_fcn_mapper(uint32 index)
{
switch (index)
{
case NORMAL_LUT_W_INSERT:
return (lut_fcn) normal_lut_w_insert;
case NORMAL_LUT_WO_INSERT:
return (lut_fcn) normal_lut_wo_insert;
case BUCKET_LOOKUP:
return (lut_fcn) bucket_lookup;
case BUCKET_LOOKUP_INSERT:
return (lut_fcn) bucket_lookup_insert;
default:
return NULL;
}
return NULL;
}
exec_fcn exec_fcn_mapper(uint32 index)
{
switch (index)
{
case COUNT_PACKETS:
return (exec_fcn) count_packets;
case TCP_SESSION:
return (exec_fcn) tcp_session;
default:
return NULL;
}
return NULL;
}
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "functions.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/bpf.h>
#include <net/tme/functions.h>
#else
#include <tme/tme.h>
#include <bpf.h>
#include <tme/functions.h>
#endif
#endif
lut_fcn lut_fcn_mapper(uint32 index)
{
switch (index)
{
case NORMAL_LUT_W_INSERT:
return (lut_fcn) normal_lut_w_insert;
case NORMAL_LUT_WO_INSERT:
return (lut_fcn) normal_lut_wo_insert;
case BUCKET_LOOKUP:
return (lut_fcn) bucket_lookup;
case BUCKET_LOOKUP_INSERT:
return (lut_fcn) bucket_lookup_insert;
default:
return NULL;
}
return NULL;
}
exec_fcn exec_fcn_mapper(uint32 index)
{
switch (index)
{
case COUNT_PACKETS:
return (exec_fcn) count_packets;
case TCP_SESSION:
return (exec_fcn) tcp_session;
default:
return NULL;
}
return NULL;
}

View File

@ -1,78 +1,78 @@
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __FUNCTIONS
#define __FUNCTIONS
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
/*function mappers */
lut_fcn lut_fcn_mapper(uint32 index);
exec_fcn exec_fcn_mapper(uint32 index);
/* lookup functions */
#ifdef WIN32
#include "bucket_lookup.h"
#include "normal_lookup.h"
#endif
#ifdef __FreeBSD__
#include <net/tme/bucket_lookup.h>
#include <net/tme/normal_lookup.h>
#endif
/* execution functions */
#ifdef WIN32
#include "count_packets.h"
#include "tcp_session.h"
#endif
#ifdef __FreeBSD__
#include <net/tme/count_packets.h>
#include <ne/tme/tcp_session.h>
#endif
#endif
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __FUNCTIONS
#define __FUNCTIONS
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
/*function mappers */
lut_fcn lut_fcn_mapper(uint32 index);
exec_fcn exec_fcn_mapper(uint32 index);
/* lookup functions */
#ifdef WIN32
#include "bucket_lookup.h"
#include "normal_lookup.h"
#endif
#ifdef __FreeBSD__
#include <net/tme/bucket_lookup.h>
#include <net/tme/normal_lookup.h>
#endif
/* execution functions */
#ifdef WIN32
#include "count_packets.h"
#include "tcp_session.h"
#endif
#ifdef __FreeBSD__
#include <net/tme/count_packets.h>
#include <ne/tme/tcp_session.h>
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,404 +1,404 @@
/*
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @ingroup NPF
* @{
*/
/** @defgroup NPF_include NPF structures and definitions
* @{
*/
//
// Registers
//
#define EAX 0
#define ECX 1
#define EDX 2
#define EBX 3
#define ESP 4
#define EBP 5
#define ESI 6
#define EDI 7
#define AX 0
#define CX 1
#define DX 2
#define BX 3
#define SP 4
#define BP 5
#define SI 6
#define DI 7
#define AL 0
#define CL 1
#define DL 2
#define BL 3
/*! \brief A stream of X86 binary code.*/
typedef struct binary_stream{
INT cur_ip; ///< Current X86 instruction pointer.
INT bpf_pc; ///< Current BPF instruction pointer, i.e. position in the BPF program reached by the jitter.
PCHAR ibuf; ///< Instruction buffer, contains the X86 generated code.
PUINT refs; ///< Jumps reference table.
}binary_stream;
/*! \brief Prototype of a filtering function created by the jitter.
The syntax and the meaning of the parameters is analogous to the one of bpf_filter(). Notice that the filter
is not among the parameters, because it is hardwired in the function.
*/
typedef UINT (__cdecl *BPF_filter_function)( PVOID *, ULONG, UINT);
/*! \brief Prototype of the emit functions.
Different emit functions are used to create the reference table and to generate the actual filtering code.
This allows to have simpler instruction macros.
The first parameter is the stream that will receive the data. The secon one is a variable containing
the data, the third one is the length, that can be 1,2 or 4 since it is possible to emit a byte, a short
or a work at a time.
*/
typedef void (*emit_func)(binary_stream *stream, ULONG value, UINT n);
/*! \brief Structure describing a x86 filtering program created by the jitter.*/
typedef struct JIT_BPF_Filter{
BPF_filter_function Function; ///< The x86 filtering binary, in the form of a BPF_filter_function.
PINT mem;
}
JIT_BPF_Filter;
/**************************/
/* X86 INSTRUCTION MACROS */
/**************************/
/// mov r32,i32
#define MOVid(r32, i32) \
emitm(&stream, 11 << 4 | 1 << 3 | r32 & 0x7, 1); emitm(&stream, i32, 4);
/// mov dr32,sr32
#define MOVrd(dr32, sr32) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// mov dr32,sr32[off]
#define MOVodd(dr32, sr32, off) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, 1 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);\
emitm(&stream, off, 1);
/// mov dr32,sr32[or32]
#define MOVobd(dr32, sr32, or32) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, (dr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov dr16,sr32[or32]
#define MOVobw(dr32, sr32, or32) \
emitm(&stream, 0x66, 1); \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, (dr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov dr8,sr32[or32]
#define MOVobb(dr8, sr32, or32) \
emitm(&stream, 0x8a, 1); \
emitm(&stream, (dr8 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov [dr32][or32],sr32
#define MOVomd(dr32, or32, sr32) \
emitm(&stream, 0x89, 1); \
emitm(&stream, (sr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (dr32 & 0x7) , 1);
/// bswap dr32
#define BSWAP(dr32) \
emitm(&stream, 0xf, 1); \
emitm(&stream, 0x19 << 3 | dr32 , 1);
/// xchg al,ah
#define SWAP_AX() \
emitm(&stream, 0x86, 1); \
emitm(&stream, 0xc4 , 1);
/// push r32
#define PUSH(r32) \
emitm(&stream, 5 << 4 | 0 << 3 | r32 & 0x7, 1);
/// pop r32
#define POP(r32) \
emitm(&stream, 5 << 4 | 1 << 3 | r32 & 0x7, 1);
/// ret
#define RET() \
emitm(&stream, 12 << 4 | 0 << 3 | 3, 1);
/// add dr32,sr32
#define ADDrd(dr32, sr32) \
emitm(&stream, 0x03, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | (sr32 & 0x7), 1);
/// add eax,i32
#define ADD_EAXi(i32) \
emitm(&stream, 0x05, 1);\
emitm(&stream, i32, 4);
/// add r32,i32
#define ADDid(r32, i32) \
emitm(&stream, 0x81, 1);\
emitm(&stream, 24 << 3 | r32, 1);\
emitm(&stream, i32, 4);
/// add r32,i8
#define ADDib(r32, i8) \
emitm(&stream, 0x83, 1);\
emitm(&stream, 24 << 3 | r32, 1);\
emitm(&stream, i8, 1);
/// sub dr32,sr32
#define SUBrd(dr32, sr32) \
emitm(&stream, 0x2b, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | (sr32 & 0x7), 1);
/// sub eax,i32
#define SUB_EAXi(i32) \
emitm(&stream, 0x2d, 1);\
emitm(&stream, i32, 4);
/// mul r32
#define MULrd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 7 << 5 | (r32 & 0x7), 1);
/// div r32
#define DIVrd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 15 << 4 | (r32 & 0x7), 1);
/// and r8,i8
#define ANDib(r8, i8) \
emitm(&stream, 0x80, 1);\
emitm(&stream, 7 << 5 | r8, 1);\
emitm(&stream, i8, 1);
/// and r32,i32
#define ANDid(r32, i32) \
if (r32 == EAX){ \
emitm(&stream, 0x25, 1);\
emitm(&stream, i32, 4);}\
else{ \
emitm(&stream, 0x81, 1);\
emitm(&stream, 7 << 5 | r32, 1);\
emitm(&stream, i32, 4);}
/// and dr32,sr32
#define ANDrd(dr32, sr32) \
emitm(&stream, 0x23, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// or dr32,sr32
#define ORrd(dr32, sr32) \
emitm(&stream, 0x0b, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// or r32,i32
#define ORid(r32, i32) \
if (r32 == EAX){ \
emitm(&stream, 0x0d, 1);\
emitm(&stream, i32, 4);}\
else{ \
emitm(&stream, 0x81, 1);\
emitm(&stream, 25 << 3 | r32, 1);\
emitm(&stream, i32, 4);}
/// shl r32,i8
#define SHLib(r32, i8) \
emitm(&stream, 0xc1, 1);\
emitm(&stream, 7 << 5 | r32 & 0x7, 1);\
emitm(&stream, i8, 1);
/// shl dr32,cl
#define SHL_CLrb(dr32) \
emitm(&stream, 0xd3, 1);\
emitm(&stream, 7 << 5 | dr32 & 0x7, 1);
/// shr r32,i8
#define SHRib(r32, i8) \
emitm(&stream, 0xc1, 1);\
emitm(&stream, 29 << 3 | r32 & 0x7, 1);\
emitm(&stream, i8, 1);
/// shr dr32,cl
#define SHR_CLrb(dr32) \
emitm(&stream, 0xd3, 1);\
emitm(&stream, 29 << 3 | dr32 & 0x7, 1);
/// neg r32
#define NEGd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 27 << 3 | r32 & 0x7, 1);
/// cmp dr32,sr32[off]
#define CMPodd(dr32, sr32, off) \
emitm(&stream, 3 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, 1 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);\
emitm(&stream, off, 1);
/// cmp dr32,sr32
#define CMPrd(dr32, sr32) \
emitm(&stream, 0x3b, 1); \
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// cmp dr32,i32
#define CMPid(dr32, i32) \
if (dr32 == EAX){ \
emitm(&stream, 0x3d, 1); \
emitm(&stream, i32, 4);} \
else{ \
emitm(&stream, 0x81, 1); \
emitm(&stream, 0x1f << 3 | (dr32 & 0x7), 1);\
emitm(&stream, i32, 4);}
/// jne off32
#define JNEb(off8) \
emitm(&stream, 0x75, 1);\
emitm(&stream, off8, 1);
/// je off32
#define JE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x84, 1);\
emitm(&stream, off32, 4);
/// jle off32
#define JLE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8e, 1);\
emitm(&stream, off32, 4);
/// jle off8
#define JLEb(off8) \
emitm(&stream, 0x7e, 1);\
emitm(&stream, off8, 1);
/// ja off32
#define JA(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x87, 1);\
emitm(&stream, off32, 4);
/// jae off32
#define JAE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x83, 1);\
emitm(&stream, off32, 4);
/// jg off32
#define JG(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8f, 1);\
emitm(&stream, off32, 4);
/// jge off32
#define JGE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8d, 1);\
emitm(&stream, off32, 4);
/// jmp off32
#define JMP(off32) \
emitm(&stream, 0xe9, 1);\
emitm(&stream, off32, 4);
/**
* @}
*/
/**
* @}
*/
/**************************/
/* Prototypes */
/**************************/
/** @ingroup NPF
* @{
*/
/** @defgroup NPF_code NPF functions
* @{
*/
/*!
\brief BPF jitter, builds an x86 function from a BPF program.
\param fp The BPF pseudo-assembly filter that will be translated into x86 code.
\param nins Number of instructions of the input filter.
\return The JIT_BPF_Filter structure containing the x86 filtering binary.
BPF_jitter allocates the buffers for the new native filter and then translates the program pointed by fp
calling BPFtoX86().
*/
JIT_BPF_Filter* BPF_jitter(struct bpf_insn *fp, INT nins);
/*!
\brief Translates a set of BPF instructions in a set of x86 ones.
\param ins Pointer to the BPF instructions that will be translated into x86 code.
\param nins Number of instructions to translate.
\param mem Memory used by the x86 function to emulate the RAM of the BPF pseudo processor.
\return The x86 filtering function.
This function does the hard work for the JIT compilation. It takes a group of BPF pseudo instructions and
through the instruction macros defined in jitter.h it is able to create an function directly executable
by NPF.
*/
BPF_filter_function BPFtoX86(struct bpf_insn *ins, UINT nins, INT *mem);
/*!
\brief Deletes a filtering function that was previously created by BPF_jitter().
\param Filter The filter to destroy.
This function frees the variuos buffers (code, memory, etc.) associated with a filtering function.
*/
void BPF_Destroy_JIT_Filter(JIT_BPF_Filter *Filter);
/**
* @}
*/
/**
* @}
*/
/*
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @ingroup NPF
* @{
*/
/** @defgroup NPF_include NPF structures and definitions
* @{
*/
//
// Registers
//
#define EAX 0
#define ECX 1
#define EDX 2
#define EBX 3
#define ESP 4
#define EBP 5
#define ESI 6
#define EDI 7
#define AX 0
#define CX 1
#define DX 2
#define BX 3
#define SP 4
#define BP 5
#define SI 6
#define DI 7
#define AL 0
#define CL 1
#define DL 2
#define BL 3
/*! \brief A stream of X86 binary code.*/
typedef struct binary_stream{
INT cur_ip; ///< Current X86 instruction pointer.
INT bpf_pc; ///< Current BPF instruction pointer, i.e. position in the BPF program reached by the jitter.
PCHAR ibuf; ///< Instruction buffer, contains the X86 generated code.
PUINT refs; ///< Jumps reference table.
}binary_stream;
/*! \brief Prototype of a filtering function created by the jitter.
The syntax and the meaning of the parameters is analogous to the one of bpf_filter(). Notice that the filter
is not among the parameters, because it is hardwired in the function.
*/
typedef UINT (__cdecl *BPF_filter_function)( PVOID *, ULONG, UINT);
/*! \brief Prototype of the emit functions.
Different emit functions are used to create the reference table and to generate the actual filtering code.
This allows to have simpler instruction macros.
The first parameter is the stream that will receive the data. The secon one is a variable containing
the data, the third one is the length, that can be 1,2 or 4 since it is possible to emit a byte, a short
or a work at a time.
*/
typedef void (*emit_func)(binary_stream *stream, ULONG value, UINT n);
/*! \brief Structure describing a x86 filtering program created by the jitter.*/
typedef struct JIT_BPF_Filter{
BPF_filter_function Function; ///< The x86 filtering binary, in the form of a BPF_filter_function.
PINT mem;
}
JIT_BPF_Filter;
/**************************/
/* X86 INSTRUCTION MACROS */
/**************************/
/// mov r32,i32
#define MOVid(r32, i32) \
emitm(&stream, 11 << 4 | 1 << 3 | r32 & 0x7, 1); emitm(&stream, i32, 4);
/// mov dr32,sr32
#define MOVrd(dr32, sr32) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// mov dr32,sr32[off]
#define MOVodd(dr32, sr32, off) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, 1 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);\
emitm(&stream, off, 1);
/// mov dr32,sr32[or32]
#define MOVobd(dr32, sr32, or32) \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, (dr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov dr16,sr32[or32]
#define MOVobw(dr32, sr32, or32) \
emitm(&stream, 0x66, 1); \
emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, (dr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov dr8,sr32[or32]
#define MOVobb(dr8, sr32, or32) \
emitm(&stream, 0x8a, 1); \
emitm(&stream, (dr8 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (sr32 & 0x7) , 1);
/// mov [dr32][or32],sr32
#define MOVomd(dr32, or32, sr32) \
emitm(&stream, 0x89, 1); \
emitm(&stream, (sr32 & 0x7) << 3 | 4 , 1);\
emitm(&stream, (or32 & 0x7) << 3 | (dr32 & 0x7) , 1);
/// bswap dr32
#define BSWAP(dr32) \
emitm(&stream, 0xf, 1); \
emitm(&stream, 0x19 << 3 | dr32 , 1);
/// xchg al,ah
#define SWAP_AX() \
emitm(&stream, 0x86, 1); \
emitm(&stream, 0xc4 , 1);
/// push r32
#define PUSH(r32) \
emitm(&stream, 5 << 4 | 0 << 3 | r32 & 0x7, 1);
/// pop r32
#define POP(r32) \
emitm(&stream, 5 << 4 | 1 << 3 | r32 & 0x7, 1);
/// ret
#define RET() \
emitm(&stream, 12 << 4 | 0 << 3 | 3, 1);
/// add dr32,sr32
#define ADDrd(dr32, sr32) \
emitm(&stream, 0x03, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | (sr32 & 0x7), 1);
/// add eax,i32
#define ADD_EAXi(i32) \
emitm(&stream, 0x05, 1);\
emitm(&stream, i32, 4);
/// add r32,i32
#define ADDid(r32, i32) \
emitm(&stream, 0x81, 1);\
emitm(&stream, 24 << 3 | r32, 1);\
emitm(&stream, i32, 4);
/// add r32,i8
#define ADDib(r32, i8) \
emitm(&stream, 0x83, 1);\
emitm(&stream, 24 << 3 | r32, 1);\
emitm(&stream, i8, 1);
/// sub dr32,sr32
#define SUBrd(dr32, sr32) \
emitm(&stream, 0x2b, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | (sr32 & 0x7), 1);
/// sub eax,i32
#define SUB_EAXi(i32) \
emitm(&stream, 0x2d, 1);\
emitm(&stream, i32, 4);
/// mul r32
#define MULrd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 7 << 5 | (r32 & 0x7), 1);
/// div r32
#define DIVrd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 15 << 4 | (r32 & 0x7), 1);
/// and r8,i8
#define ANDib(r8, i8) \
emitm(&stream, 0x80, 1);\
emitm(&stream, 7 << 5 | r8, 1);\
emitm(&stream, i8, 1);
/// and r32,i32
#define ANDid(r32, i32) \
if (r32 == EAX){ \
emitm(&stream, 0x25, 1);\
emitm(&stream, i32, 4);}\
else{ \
emitm(&stream, 0x81, 1);\
emitm(&stream, 7 << 5 | r32, 1);\
emitm(&stream, i32, 4);}
/// and dr32,sr32
#define ANDrd(dr32, sr32) \
emitm(&stream, 0x23, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// or dr32,sr32
#define ORrd(dr32, sr32) \
emitm(&stream, 0x0b, 1);\
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// or r32,i32
#define ORid(r32, i32) \
if (r32 == EAX){ \
emitm(&stream, 0x0d, 1);\
emitm(&stream, i32, 4);}\
else{ \
emitm(&stream, 0x81, 1);\
emitm(&stream, 25 << 3 | r32, 1);\
emitm(&stream, i32, 4);}
/// shl r32,i8
#define SHLib(r32, i8) \
emitm(&stream, 0xc1, 1);\
emitm(&stream, 7 << 5 | r32 & 0x7, 1);\
emitm(&stream, i8, 1);
/// shl dr32,cl
#define SHL_CLrb(dr32) \
emitm(&stream, 0xd3, 1);\
emitm(&stream, 7 << 5 | dr32 & 0x7, 1);
/// shr r32,i8
#define SHRib(r32, i8) \
emitm(&stream, 0xc1, 1);\
emitm(&stream, 29 << 3 | r32 & 0x7, 1);\
emitm(&stream, i8, 1);
/// shr dr32,cl
#define SHR_CLrb(dr32) \
emitm(&stream, 0xd3, 1);\
emitm(&stream, 29 << 3 | dr32 & 0x7, 1);
/// neg r32
#define NEGd(r32) \
emitm(&stream, 0xf7, 1);\
emitm(&stream, 27 << 3 | r32 & 0x7, 1);
/// cmp dr32,sr32[off]
#define CMPodd(dr32, sr32, off) \
emitm(&stream, 3 << 4 | 3 | 1 << 3, 1); \
emitm(&stream, 1 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);\
emitm(&stream, off, 1);
/// cmp dr32,sr32
#define CMPrd(dr32, sr32) \
emitm(&stream, 0x3b, 1); \
emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
/// cmp dr32,i32
#define CMPid(dr32, i32) \
if (dr32 == EAX){ \
emitm(&stream, 0x3d, 1); \
emitm(&stream, i32, 4);} \
else{ \
emitm(&stream, 0x81, 1); \
emitm(&stream, 0x1f << 3 | (dr32 & 0x7), 1);\
emitm(&stream, i32, 4);}
/// jne off32
#define JNEb(off8) \
emitm(&stream, 0x75, 1);\
emitm(&stream, off8, 1);
/// je off32
#define JE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x84, 1);\
emitm(&stream, off32, 4);
/// jle off32
#define JLE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8e, 1);\
emitm(&stream, off32, 4);
/// jle off8
#define JLEb(off8) \
emitm(&stream, 0x7e, 1);\
emitm(&stream, off8, 1);
/// ja off32
#define JA(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x87, 1);\
emitm(&stream, off32, 4);
/// jae off32
#define JAE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x83, 1);\
emitm(&stream, off32, 4);
/// jg off32
#define JG(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8f, 1);\
emitm(&stream, off32, 4);
/// jge off32
#define JGE(off32) \
emitm(&stream, 0x0f, 1);\
emitm(&stream, 0x8d, 1);\
emitm(&stream, off32, 4);
/// jmp off32
#define JMP(off32) \
emitm(&stream, 0xe9, 1);\
emitm(&stream, off32, 4);
/**
* @}
*/
/**
* @}
*/
/**************************/
/* Prototypes */
/**************************/
/** @ingroup NPF
* @{
*/
/** @defgroup NPF_code NPF functions
* @{
*/
/*!
\brief BPF jitter, builds an x86 function from a BPF program.
\param fp The BPF pseudo-assembly filter that will be translated into x86 code.
\param nins Number of instructions of the input filter.
\return The JIT_BPF_Filter structure containing the x86 filtering binary.
BPF_jitter allocates the buffers for the new native filter and then translates the program pointed by fp
calling BPFtoX86().
*/
JIT_BPF_Filter* BPF_jitter(struct bpf_insn *fp, INT nins);
/*!
\brief Translates a set of BPF instructions in a set of x86 ones.
\param ins Pointer to the BPF instructions that will be translated into x86 code.
\param nins Number of instructions to translate.
\param mem Memory used by the x86 function to emulate the RAM of the BPF pseudo processor.
\return The x86 filtering function.
This function does the hard work for the JIT compilation. It takes a group of BPF pseudo instructions and
through the instruction macros defined in jitter.h it is able to create an function directly executable
by NPF.
*/
BPF_filter_function BPFtoX86(struct bpf_insn *ins, UINT nins, INT *mem);
/*!
\brief Deletes a filtering function that was previously created by BPF_jitter().
\param Filter The filter to destroy.
This function frees the variuos buffers (code, memory, etc.) associated with a filtering function.
*/
void BPF_Destroy_JIT_Filter(JIT_BPF_Filter *Filter);
/**
* @}
*/
/**
* @}
*/

View File

@ -1,132 +1,132 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __memory_t
#define __memory_t
#define uint8 UCHAR
#define int8 CHAR
#define uint16 USHORT
#define int16 SHORT
#define uint32 ULONG
#define int32 LONG
#define uint64 ULONGLONG
#define int64 LONGLONG
/*memory type*/
typedef struct __MEM_TYPE
{
uint8 *buffer;
uint32 size;
} MEM_TYPE, *PMEM_TYPE;
#define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
#define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
#define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
#define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
__inline int32 SW_LONG_AT(void *b, uint32 c)
{
return ((int32)*((uint8 *)b+c)<<24|
(int32)*((uint8 *)b+c+1)<<16|
(int32)*((uint8 *)b+c+2)<<8|
(int32)*((uint8 *)b+c+3)<<0);
}
__inline uint32 SW_ULONG_AT(void *b, uint32 c)
{
return ((uint32)*((uint8 *)b+c)<<24|
(uint32)*((uint8 *)b+c+1)<<16|
(uint32)*((uint8 *)b+c+2)<<8|
(uint32)*((uint8 *)b+c+3)<<0);
}
__inline int16 SW_SHORT_AT(void *b, uint32 os)
{
return ((int16)
((int16)*((uint8 *)b+os+0)<<8|
(int16)*((uint8 *)b+os+1)<<0));
}
__inline uint16 SW_USHORT_AT(void *b, uint32 os)
{
return ((uint16)
((uint16)*((uint8 *)b+os+0)<<8|
(uint16)*((uint8 *)b+os+1)<<0));
}
__inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
{
*((uint8*)dst+0)=*((uint8*)&src+3);
*((uint8*)dst+1)=*((uint8*)&src+2);
*((uint8*)dst+2)=*((uint8*)&src+1);
*((uint8*)dst+3)=*((uint8*)&src+0);
}
#ifdef WIN_NT_DRIVER
#define ALLOCATE_MEMORY(dest,type,amount) \
(dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount));
#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
{ \
(dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount)); \
if ((dest)!=NULL) \
RtlZeroMemory((dest),sizeof(type)*(amount)); \
}
#define FREE_MEMORY(dest) ExFreePool(dest);
#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
#else
#define ALLOCATE_MEMORY(dest,type,amount) \
(dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
(dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
#define FREE_MEMORY(dest) GlobalFree(dest);
#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
#endif /*WIN_NT_DRIVER*/
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __memory_t
#define __memory_t
#define uint8 UCHAR
#define int8 CHAR
#define uint16 USHORT
#define int16 SHORT
#define uint32 ULONG
#define int32 LONG
#define uint64 ULONGLONG
#define int64 LONGLONG
/*memory type*/
typedef struct __MEM_TYPE
{
uint8 *buffer;
uint32 size;
} MEM_TYPE, *PMEM_TYPE;
#define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
#define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
#define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
#define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
__inline int32 SW_LONG_AT(void *b, uint32 c)
{
return ((int32)*((uint8 *)b+c)<<24|
(int32)*((uint8 *)b+c+1)<<16|
(int32)*((uint8 *)b+c+2)<<8|
(int32)*((uint8 *)b+c+3)<<0);
}
__inline uint32 SW_ULONG_AT(void *b, uint32 c)
{
return ((uint32)*((uint8 *)b+c)<<24|
(uint32)*((uint8 *)b+c+1)<<16|
(uint32)*((uint8 *)b+c+2)<<8|
(uint32)*((uint8 *)b+c+3)<<0);
}
__inline int16 SW_SHORT_AT(void *b, uint32 os)
{
return ((int16)
((int16)*((uint8 *)b+os+0)<<8|
(int16)*((uint8 *)b+os+1)<<0));
}
__inline uint16 SW_USHORT_AT(void *b, uint32 os)
{
return ((uint16)
((uint16)*((uint8 *)b+os+0)<<8|
(uint16)*((uint8 *)b+os+1)<<0));
}
__inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
{
*((uint8*)dst+0)=*((uint8*)&src+3);
*((uint8*)dst+1)=*((uint8*)&src+2);
*((uint8*)dst+2)=*((uint8*)&src+1);
*((uint8*)dst+3)=*((uint8*)&src+0);
}
#ifdef WIN_NT_DRIVER
#define ALLOCATE_MEMORY(dest,type,amount) \
(dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount));
#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
{ \
(dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount)); \
if ((dest)!=NULL) \
RtlZeroMemory((dest),sizeof(type)*(amount)); \
}
#define FREE_MEMORY(dest) ExFreePool(dest);
#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
#else
#define ALLOCATE_MEMORY(dest,type,amount) \
(dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
(dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
#define FREE_MEMORY(dest) GlobalFree(dest);
#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
#endif /*WIN_NT_DRIVER*/
#endif

View File

@ -1,204 +1,204 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "normal_lookup.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/normal_lookup.h>
#else
#include <tme/tme.h>
#include <tme/normal_lookup.h>
#endif
#endif
/* lookup in the table, seen as an hash */
/* if not found, inserts an element */
/* returns TME_TRUE if the entry is found or created, */
/* returns TME_FALSE if no more blocks are available */
uint32 normal_lut_w_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 i;
uint32 tocs=0;
uint32 *key32=(uint32*) key;
uint32 shrinked_key=0;
uint32 index;
RECORD *records=(RECORD*)data->lut_base_address;
uint8 *offset;
uint32 key_len=data->key_len;
/*the key is shrinked into a 32-bit value */
for (i=0; i<key_len;i++)
shrinked_key^=key32[i];
/*the first index in the table is calculated*/
index=shrinked_key % data->lut_entries;
while (tocs<=data->filled_entries)
{
if (records[index].block==0)
{ /*creation of a new entry*/
if (data->filled_blocks==data->shared_memory_blocks)
{
/*no more free blocks*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/*offset=absolute pointer to the block associated*/
/*with the newly created entry*/
offset=data->shared_memory_base_address+
data->block_size*data->filled_blocks;
/*copy the key in the block*/
COPY_MEMORY(offset,key32,key_len*4);
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
/*assign the block relative offset to the entry, in NBO*/
SW_ULONG_ASSIGN(&records[index].block,offset-mem_ex->buffer);
data->filled_blocks++;
/*assign the exec function ID to the entry, in NBO*/
SW_ULONG_ASSIGN(&records[index].exec_fcn,data->default_exec);
data->filled_entries++;
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
/*offset contains the absolute pointer to the block*/
/*associated with the current entry */
offset=mem_ex->buffer+SW_ULONG_AT(&records[index].block,0);
for (i=0; (i<key_len) && (key32[i]==ULONG_AT(offset,i*4)); i++);
if (i==key_len)
{
/*key in the block matches the one provided, right entry*/
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
/* wrong entry, rehashing */
if (IS_DELETABLE(offset+key_len*4,data))
{
ZERO_MEMORY(offset,data->block_size);
COPY_MEMORY(offset,key32,key_len*4);
SW_ULONG_ASSIGN(&records[index].exec_fcn,data->default_exec);
GET_TIME((struct timeval*)(offset+key_len*4),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
index=(index+data->rehashing_value) % data->lut_entries;
tocs++;
}
}
}
/* nothing found, last found= out of lut */
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/* lookup in the table, seen as an hash */
/* if not found, returns out of count entry index */
/* returns TME_TRUE if the entry is found */
/* returns TME_FALSE if the entry is not found */
uint32 normal_lut_wo_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 i;
uint32 tocs=0;
uint32 *key32=(uint32*) key;
uint32 shrinked_key=0;
uint32 index;
RECORD *records=(RECORD*)data->lut_base_address;
uint8 *offset;
uint32 key_len=data->key_len;
/*the key is shrinked into a 32-bit value */
for (i=0; i<key_len;i++)
shrinked_key^=key32[i];
/*the first index in the table is calculated*/
index=shrinked_key % data->lut_entries;
while (tocs<=data->filled_entries)
{
if (records[index].block==0)
{ /*out of table, insertion is not allowed*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/*offset contains the absolute pointer to the block*/
/*associated with the current entry */
offset=mem_ex->buffer+SW_ULONG_AT(&records[index].block,0);
for (i=0; (i<key_len) && (key32[i]==ULONG_AT(offset,i*4)); i++);
if (i==key_len)
{
/*key in the block matches the one provided, right entry*/
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
/*wrong entry, rehashing*/
index=(index+data->rehashing_value) % data->lut_entries;
tocs++;
}
}
/*nothing found, last found= out of lut*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "normal_lookup.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/normal_lookup.h>
#else
#include <tme/tme.h>
#include <tme/normal_lookup.h>
#endif
#endif
/* lookup in the table, seen as an hash */
/* if not found, inserts an element */
/* returns TME_TRUE if the entry is found or created, */
/* returns TME_FALSE if no more blocks are available */
uint32 normal_lut_w_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 i;
uint32 tocs=0;
uint32 *key32=(uint32*) key;
uint32 shrinked_key=0;
uint32 index;
RECORD *records=(RECORD*)data->lut_base_address;
uint8 *offset;
uint32 key_len=data->key_len;
/*the key is shrinked into a 32-bit value */
for (i=0; i<key_len;i++)
shrinked_key^=key32[i];
/*the first index in the table is calculated*/
index=shrinked_key % data->lut_entries;
while (tocs<=data->filled_entries)
{
if (records[index].block==0)
{ /*creation of a new entry*/
if (data->filled_blocks==data->shared_memory_blocks)
{
/*no more free blocks*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/*offset=absolute pointer to the block associated*/
/*with the newly created entry*/
offset=data->shared_memory_base_address+
data->block_size*data->filled_blocks;
/*copy the key in the block*/
COPY_MEMORY(offset,key32,key_len*4);
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
/*assign the block relative offset to the entry, in NBO*/
SW_ULONG_ASSIGN(&records[index].block,offset-mem_ex->buffer);
data->filled_blocks++;
/*assign the exec function ID to the entry, in NBO*/
SW_ULONG_ASSIGN(&records[index].exec_fcn,data->default_exec);
data->filled_entries++;
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
/*offset contains the absolute pointer to the block*/
/*associated with the current entry */
offset=mem_ex->buffer+SW_ULONG_AT(&records[index].block,0);
for (i=0; (i<key_len) && (key32[i]==ULONG_AT(offset,i*4)); i++);
if (i==key_len)
{
/*key in the block matches the one provided, right entry*/
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
/* wrong entry, rehashing */
if (IS_DELETABLE(offset+key_len*4,data))
{
ZERO_MEMORY(offset,data->block_size);
COPY_MEMORY(offset,key32,key_len*4);
SW_ULONG_ASSIGN(&records[index].exec_fcn,data->default_exec);
GET_TIME((struct timeval*)(offset+key_len*4),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
index=(index+data->rehashing_value) % data->lut_entries;
tocs++;
}
}
}
/* nothing found, last found= out of lut */
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/* lookup in the table, seen as an hash */
/* if not found, returns out of count entry index */
/* returns TME_TRUE if the entry is found */
/* returns TME_FALSE if the entry is not found */
uint32 normal_lut_wo_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref)
{
uint32 i;
uint32 tocs=0;
uint32 *key32=(uint32*) key;
uint32 shrinked_key=0;
uint32 index;
RECORD *records=(RECORD*)data->lut_base_address;
uint8 *offset;
uint32 key_len=data->key_len;
/*the key is shrinked into a 32-bit value */
for (i=0; i<key_len;i++)
shrinked_key^=key32[i];
/*the first index in the table is calculated*/
index=shrinked_key % data->lut_entries;
while (tocs<=data->filled_entries)
{
if (records[index].block==0)
{ /*out of table, insertion is not allowed*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}
/*offset contains the absolute pointer to the block*/
/*associated with the current entry */
offset=mem_ex->buffer+SW_ULONG_AT(&records[index].block,0);
for (i=0; (i<key_len) && (key32[i]==ULONG_AT(offset,i*4)); i++);
if (i==key_len)
{
/*key in the block matches the one provided, right entry*/
GET_TIME((struct timeval *)(offset+4*key_len),time_ref);
data->last_found=(uint8*)&records[index];
return TME_TRUE;
}
else
{
/*wrong entry, rehashing*/
index=(index+data->rehashing_value) % data->lut_entries;
tocs++;
}
}
/*nothing found, last found= out of lut*/
GET_TIME((struct timeval *)(data->shared_memory_base_address+4*key_len),time_ref);
data->last_found=NULL;
return TME_FALSE;
}

View File

@ -1,56 +1,56 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __normal_lookup
#define __normal_lookup
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define NORMAL_LUT_W_INSERT 0x00000000
uint32 normal_lut_w_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define NORMAL_LUT_WO_INSERT 0x00000001
uint32 normal_lut_wo_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define DUMMY_INSERT 1234
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __normal_lookup
#define __normal_lookup
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define NORMAL_LUT_W_INSERT 0x00000000
uint32 normal_lut_w_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define NORMAL_LUT_WO_INSERT 0x00000001
uint32 normal_lut_wo_insert(uint8 *key, TME_DATA *data, MEM_TYPE *mem_ex, struct time_conv *time_ref);
#define DUMMY_INSERT 1234
#endif

View File

@ -1,16 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by NPF.RC
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by NPF.RC
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -1,15 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by See.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by See.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -1,296 +1,296 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "tcp_session.h"
#endif
#ifdef __FreeBSD
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/tcp_session.h>
#else
#include <tme/tme.h>
#include <tme/tcp_session.h>
#endif
#endif
uint32 tcp_session(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data)
{
uint32 next_status;
uint32 direction=ULONG_AT(mem_data,12);
uint8 flags=mem_ex->buffer[25];
tcp_data *session=(tcp_data*)(block+data->key_len*4);
session->last_timestamp=session->timestamp_block;
session->timestamp_block.tv_sec=0x7fffffff;
if (direction==session->direction)
{
session->pkts_cln_to_srv++;
session->bytes_cln_to_srv+=pkt_size;
}
else
{
session->pkts_srv_to_cln++;
session->bytes_srv_to_cln+=pkt_size;
}
/* we use only thes four flags, we don't need PSH or URG */
flags&=(ACK|FIN|SYN|RST);
switch (session->status)
{
case ERROR_TCP:
next_status=ERROR_TCP;
break;
case UNKNOWN:
if (flags==SYN)
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=0)
{
next_status=ERROR_TCP;
break;
}
next_status=SYN_RCV;
session->syn_timestamp=session->last_timestamp;
session->direction=direction;
session->seq_n_0_cln=SW_ULONG_AT(mem_ex->buffer,16);
}
else
next_status=UNKNOWN;
break;
case SYN_RCV:
if ((flags&RST)&&(direction!=session->direction))
{
next_status=CLOSED_RST;
break;
}
if ((flags==SYN)&&(direction==session->direction))
{ /* two syns... */
next_status=SYN_RCV;
session->seq_n_0_cln=SW_ULONG_AT(mem_ex->buffer,16);
break;
}
if ((flags==(SYN|ACK))&&(direction!=session->direction))
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=session->seq_n_0_cln+1)
{
next_status=ERROR_TCP;
break;
}
next_status=SYN_ACK_RCV;
session->syn_ack_timestamp=session->last_timestamp;
session->seq_n_0_srv=SW_ULONG_AT(mem_ex->buffer,16);
session->ack_cln=session->seq_n_0_cln+1;
}
else
{
next_status=ERROR_TCP;
}
break;
case SYN_ACK_RCV:
if ((flags&ACK)&&(flags&RST)&&(direction==session->direction))
{
next_status=CLOSED_RST;
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,20);
break;
}
if ((flags==ACK)&&(!(flags&(SYN|FIN|RST)))&&(direction==session->direction))
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=session->seq_n_0_srv+1)
{
next_status=ERROR_TCP;
break;
}
next_status=ESTABLISHED;
session->ack_srv=session->seq_n_0_srv+1;
break;
}
if ((flags&ACK)&&(flags&SYN)&&(direction!=session->direction))
{
next_status=SYN_ACK_RCV;
break;
}
next_status=ERROR_TCP;
break;
case ESTABLISHED:
if (flags&SYN)
{
if ((flags&ACK)&&
(direction!=session->direction)&&
((session->ack_cln-SW_ULONG_AT(mem_ex->buffer,20))<MAX_WINDOW)
)
{ /* SYN_ACK duplicato */
next_status=ESTABLISHED;
break;
}
if ((!(flags&ACK))&&
(direction==session->direction)&&
(SW_ULONG_AT(mem_ex->buffer,16)==session->seq_n_0_cln)&&
(ULONG_AT(mem_ex->buffer,20)==0)
)
{ /* syn duplicato */
next_status=ESTABLISHED;
break;
}
next_status=ERROR_TCP;
break;
}
if (flags&ACK)
if (direction==session->direction)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (new_ack-session->ack_srv<MAX_WINDOW)
session->ack_srv=new_ack;
}
else
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (new_ack-session->ack_cln<MAX_WINDOW)
session->ack_cln=new_ack;
}
if (flags&RST)
{
next_status=CLOSED_RST;
break;
}
if (flags&FIN)
if (direction==session->direction)
{ /* an hack to make all things work */
session->ack_cln=SW_ULONG_AT(mem_ex->buffer,16);
next_status=FIN_CLN_RCV;
break;
}
else
{
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,16);
next_status=FIN_SRV_RCV;
break;
}
next_status=ESTABLISHED;
break;
case CLOSED_RST:
next_status=CLOSED_RST;
break;
case FIN_SRV_RCV:
if (flags&SYN)
{
next_status=ERROR_TCP;
break;
}
next_status=FIN_SRV_RCV;
if (flags&ACK)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (direction!=session->direction)
if ((new_ack-session->ack_cln)<MAX_WINDOW)
session->ack_cln=new_ack;
}
if (flags&RST)
next_status=CLOSED_RST;
else
if ((flags&FIN)&&(direction==session->direction))
{
session->ack_cln=SW_ULONG_AT(mem_ex->buffer,16);
next_status=CLOSED_FIN;
}
break;
case FIN_CLN_RCV:
if (flags&SYN)
{
next_status=ERROR_TCP;
break;
}
next_status=FIN_CLN_RCV;
if (flags&ACK)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (direction==session->direction)
if (new_ack-session->ack_srv<MAX_WINDOW)
session->ack_srv=new_ack;
}
if (flags&RST)
next_status=CLOSED_RST;
else
if ((flags&FIN)&&(direction!=session->direction))
{
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,16);
next_status=CLOSED_FIN;
}
break;
case CLOSED_FIN:
next_status=CLOSED_FIN;
break;
default:
next_status=ERROR_TCP;
}
session->status=next_status;
if ((next_status==CLOSED_FIN)||(next_status==UNKNOWN)||(next_status==CLOSED_RST)||(next_status==ERROR_TCP))
session->timestamp_block=session->last_timestamp;
return TME_SUCCESS;
}
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#ifdef WIN32
#include "tme.h"
#include "tcp_session.h"
#endif
#ifdef __FreeBSD
#ifdef _KERNEL
#include <net/tme/tme.h>
#include <net/tme/tcp_session.h>
#else
#include <tme/tme.h>
#include <tme/tcp_session.h>
#endif
#endif
uint32 tcp_session(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data)
{
uint32 next_status;
uint32 direction=ULONG_AT(mem_data,12);
uint8 flags=mem_ex->buffer[25];
tcp_data *session=(tcp_data*)(block+data->key_len*4);
session->last_timestamp=session->timestamp_block;
session->timestamp_block.tv_sec=0x7fffffff;
if (direction==session->direction)
{
session->pkts_cln_to_srv++;
session->bytes_cln_to_srv+=pkt_size;
}
else
{
session->pkts_srv_to_cln++;
session->bytes_srv_to_cln+=pkt_size;
}
/* we use only thes four flags, we don't need PSH or URG */
flags&=(ACK|FIN|SYN|RST);
switch (session->status)
{
case ERROR_TCP:
next_status=ERROR_TCP;
break;
case UNKNOWN:
if (flags==SYN)
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=0)
{
next_status=ERROR_TCP;
break;
}
next_status=SYN_RCV;
session->syn_timestamp=session->last_timestamp;
session->direction=direction;
session->seq_n_0_cln=SW_ULONG_AT(mem_ex->buffer,16);
}
else
next_status=UNKNOWN;
break;
case SYN_RCV:
if ((flags&RST)&&(direction!=session->direction))
{
next_status=CLOSED_RST;
break;
}
if ((flags==SYN)&&(direction==session->direction))
{ /* two syns... */
next_status=SYN_RCV;
session->seq_n_0_cln=SW_ULONG_AT(mem_ex->buffer,16);
break;
}
if ((flags==(SYN|ACK))&&(direction!=session->direction))
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=session->seq_n_0_cln+1)
{
next_status=ERROR_TCP;
break;
}
next_status=SYN_ACK_RCV;
session->syn_ack_timestamp=session->last_timestamp;
session->seq_n_0_srv=SW_ULONG_AT(mem_ex->buffer,16);
session->ack_cln=session->seq_n_0_cln+1;
}
else
{
next_status=ERROR_TCP;
}
break;
case SYN_ACK_RCV:
if ((flags&ACK)&&(flags&RST)&&(direction==session->direction))
{
next_status=CLOSED_RST;
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,20);
break;
}
if ((flags==ACK)&&(!(flags&(SYN|FIN|RST)))&&(direction==session->direction))
{
if (SW_ULONG_AT(mem_ex->buffer,20)!=session->seq_n_0_srv+1)
{
next_status=ERROR_TCP;
break;
}
next_status=ESTABLISHED;
session->ack_srv=session->seq_n_0_srv+1;
break;
}
if ((flags&ACK)&&(flags&SYN)&&(direction!=session->direction))
{
next_status=SYN_ACK_RCV;
break;
}
next_status=ERROR_TCP;
break;
case ESTABLISHED:
if (flags&SYN)
{
if ((flags&ACK)&&
(direction!=session->direction)&&
((session->ack_cln-SW_ULONG_AT(mem_ex->buffer,20))<MAX_WINDOW)
)
{ /* SYN_ACK duplicato */
next_status=ESTABLISHED;
break;
}
if ((!(flags&ACK))&&
(direction==session->direction)&&
(SW_ULONG_AT(mem_ex->buffer,16)==session->seq_n_0_cln)&&
(ULONG_AT(mem_ex->buffer,20)==0)
)
{ /* syn duplicato */
next_status=ESTABLISHED;
break;
}
next_status=ERROR_TCP;
break;
}
if (flags&ACK)
if (direction==session->direction)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (new_ack-session->ack_srv<MAX_WINDOW)
session->ack_srv=new_ack;
}
else
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (new_ack-session->ack_cln<MAX_WINDOW)
session->ack_cln=new_ack;
}
if (flags&RST)
{
next_status=CLOSED_RST;
break;
}
if (flags&FIN)
if (direction==session->direction)
{ /* an hack to make all things work */
session->ack_cln=SW_ULONG_AT(mem_ex->buffer,16);
next_status=FIN_CLN_RCV;
break;
}
else
{
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,16);
next_status=FIN_SRV_RCV;
break;
}
next_status=ESTABLISHED;
break;
case CLOSED_RST:
next_status=CLOSED_RST;
break;
case FIN_SRV_RCV:
if (flags&SYN)
{
next_status=ERROR_TCP;
break;
}
next_status=FIN_SRV_RCV;
if (flags&ACK)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (direction!=session->direction)
if ((new_ack-session->ack_cln)<MAX_WINDOW)
session->ack_cln=new_ack;
}
if (flags&RST)
next_status=CLOSED_RST;
else
if ((flags&FIN)&&(direction==session->direction))
{
session->ack_cln=SW_ULONG_AT(mem_ex->buffer,16);
next_status=CLOSED_FIN;
}
break;
case FIN_CLN_RCV:
if (flags&SYN)
{
next_status=ERROR_TCP;
break;
}
next_status=FIN_CLN_RCV;
if (flags&ACK)
{
uint32 new_ack=SW_ULONG_AT(mem_ex->buffer,20);
if (direction==session->direction)
if (new_ack-session->ack_srv<MAX_WINDOW)
session->ack_srv=new_ack;
}
if (flags&RST)
next_status=CLOSED_RST;
else
if ((flags&FIN)&&(direction!=session->direction))
{
session->ack_srv=SW_ULONG_AT(mem_ex->buffer,16);
next_status=CLOSED_FIN;
}
break;
case CLOSED_FIN:
next_status=CLOSED_FIN;
break;
default:
next_status=ERROR_TCP;
}
session->status=next_status;
if ((next_status==CLOSED_FIN)||(next_status==UNKNOWN)||(next_status==CLOSED_RST)||(next_status==ERROR_TCP))
session->timestamp_block=session->last_timestamp;
return TME_SUCCESS;
}

View File

@ -1,96 +1,96 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __tcp_session
#define __tcp_session
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define UNKNOWN 0
#define SYN_RCV 1
#define SYN_ACK_RCV 2
#define ESTABLISHED 3
#define CLOSED_RST 4
#define FIN_CLN_RCV 5
#define FIN_SRV_RCV 6
#define CLOSED_FIN 7
#define ERROR_TCP 8
#define FIRST_IS_CLN 0
#define FIRST_IS_SRV 0xffffffff
#define FIN_CLN 1
#define FIN_SRV 2
#define MAX_WINDOW 65536
typedef struct __tcp_data
{
struct timeval timestamp_block; /*DO NOT MOVE THIS VALUE*/
struct timeval syn_timestamp;
struct timeval last_timestamp;
struct timeval syn_ack_timestamp;
uint32 direction;
uint32 seq_n_0_srv;
uint32 seq_n_0_cln;
uint32 ack_srv; /* acknowledge of (data sent by server) */
uint32 ack_cln; /* acknowledge of (data sent by client) */
uint32 status;
uint32 pkts_cln_to_srv;
uint32 pkts_srv_to_cln;
uint32 bytes_srv_to_cln;
uint32 bytes_cln_to_srv;
uint32 close_state;
}
tcp_data;
#define FIN 1
#define SYN 2
#define RST 4
#define PSH 8
#define ACK 16
#define URG 32
#define TCP_SESSION 0x00000800
uint32 tcp_session(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __tcp_session
#define __tcp_session
#ifdef WIN32
#include "tme.h"
#endif
#ifdef __FreeBSD__
#ifdef _KERNEL
#include <net/tme/tme.h>
#else
#include <tme/tme.h>
#endif
#endif
#define UNKNOWN 0
#define SYN_RCV 1
#define SYN_ACK_RCV 2
#define ESTABLISHED 3
#define CLOSED_RST 4
#define FIN_CLN_RCV 5
#define FIN_SRV_RCV 6
#define CLOSED_FIN 7
#define ERROR_TCP 8
#define FIRST_IS_CLN 0
#define FIRST_IS_SRV 0xffffffff
#define FIN_CLN 1
#define FIN_SRV 2
#define MAX_WINDOW 65536
typedef struct __tcp_data
{
struct timeval timestamp_block; /*DO NOT MOVE THIS VALUE*/
struct timeval syn_timestamp;
struct timeval last_timestamp;
struct timeval syn_ack_timestamp;
uint32 direction;
uint32 seq_n_0_srv;
uint32 seq_n_0_cln;
uint32 ack_srv; /* acknowledge of (data sent by server) */
uint32 ack_cln; /* acknowledge of (data sent by client) */
uint32 status;
uint32 pkts_cln_to_srv;
uint32 pkts_srv_to_cln;
uint32 bytes_srv_to_cln;
uint32 bytes_cln_to_srv;
uint32 close_state;
}
tcp_data;
#define FIN 1
#define SYN 2
#define RST 4
#define PSH 8
#define ACK 16
#define URG 32
#define TCP_SESSION 0x00000800
uint32 tcp_session(uint8 *block, uint32 pkt_size, TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
#endif

View File

@ -1,486 +1,486 @@
/*
* Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _time_calls
#define _time_calls
#ifdef WIN_NT_DRIVER
#include "debug.h"
#include "ndis.h"
#define DEFAULT_TIMESTAMPMODE 0
#define TIMESTAMPMODE_SINGLE_SYNCHRONIZATION 0
#define TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP 1
#define TIMESTAMPMODE_QUERYSYSTEMTIME 2
#define TIMESTAMPMODE_RDTSC 3
#define TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP 99
#define TIMESTAMPMODE_REGKEY L"TimestampMode"
extern ULONG TimestampMode;
extern ULONG NCpu;
/*!
\brief A microsecond precise timestamp.
included in the sf_pkthdr or the bpf_hdr that NPF associates with every packet.
*/
struct timeval {
long tv_sec; ///< seconds
long tv_usec; ///< microseconds
};
#endif /*WIN_NT_DRIVER*/
struct time_conv
{
ULONGLONG reference;
struct timeval start[32];
};
#ifdef WIN_NT_DRIVER
__inline void TIME_DESYNCHRONIZE(struct time_conv *data)
{
data->reference = 0;
// data->start.tv_sec = 0;
// data->start.tv_usec = 0;
}
__inline void ReadTimeStampModeFromRegistry(PUNICODE_STRING RegistryPath)
{
ULONG NewLength;
PWSTR NullTerminatedString;
RTL_QUERY_REGISTRY_TABLE Queries[2];
ULONG DefaultTimestampMode = DEFAULT_TIMESTAMPMODE;
NewLength = RegistryPath->Length/2;
NullTerminatedString = ExAllocatePool(PagedPool, (NewLength+1) *sizeof(WCHAR));
if (NullTerminatedString != NULL)
{
RtlCopyMemory(NullTerminatedString, RegistryPath->Buffer, RegistryPath->Length);
NullTerminatedString[NewLength]=0;
RtlZeroMemory(Queries, sizeof(Queries));
Queries[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
Queries[0].Name = TIMESTAMPMODE_REGKEY;
Queries[0].EntryContext = &TimestampMode;
Queries[0].DefaultType = REG_DWORD;
Queries[0].DefaultData = &DefaultTimestampMode;
Queries[0].DefaultLength = sizeof(ULONG);
if (RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, NullTerminatedString, Queries, NULL, NULL) != STATUS_SUCCESS)
{
TimestampMode = DEFAULT_TIMESTAMPMODE;
}
RtlWriteRegistryValue( RTL_REGISTRY_ABSOLUTE, NullTerminatedString, TIMESTAMPMODE_REGKEY, REG_DWORD, &TimestampMode,sizeof(ULONG));
ExFreePool(NullTerminatedString);
}
else
TimestampMode = DEFAULT_TIMESTAMPMODE;
}
#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600
/* KeQueryPerformanceCounter TimeStamps */
__inline void SynchronizeOnCpu(struct timeval *start)
{
// struct timeval *start = (struct timeval*)Data;
LARGE_INTEGER SystemTime;
LARGE_INTEGER TimeFreq,PTime;
// get the absolute value of the system boot time.
PTime = KeQueryPerformanceCounter(&TimeFreq);
KeQuerySystemTime(&SystemTime);
start->tv_sec = (LONG)(SystemTime.QuadPart/10000000-11644473600);
start->tv_usec = (LONG)((SystemTime.QuadPart%10000000)/10);
start->tv_sec -= (ULONG)(PTime.QuadPart/TimeFreq.QuadPart);
start->tv_usec -= (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (start->tv_usec < 0)
{
start->tv_sec --;
start->tv_usec += 1000000;
}
}
//
// inline assembler is not supported with the current AMD64 compilers
// At the moment we simply disable this timestamping mode on AMD64.
// A solution would be to allocate a small memory from the non-paged
// pool, dump the instructions on that buffer, and then execute them.
// The non paged pool is needed since it's the only area of kernel
// data memory that is not subject to the NX protection.
// Or use some lower level trick, like using an assembler to assemble
// a small function for this.
//
#ifdef __NPF_x86__
/*RDTSC timestamps */
/* callers must be at IRQL=PASSIVE_LEVEL*/
__inline VOID TimeSynchronizeRDTSC(struct time_conv *data)
{
struct timeval tmp;
LARGE_INTEGER system_time;
ULONGLONG curr_ticks;
KIRQL old;
LARGE_INTEGER start_kqpc,stop_kqpc,start_freq,stop_freq;
ULONGLONG start_ticks,stop_ticks;
ULONGLONG delta,delta2;
KEVENT event;
LARGE_INTEGER i;
ULONGLONG reference;
if (data->reference!=0)
return;
KeInitializeEvent(&event,NotificationEvent,FALSE);
i.QuadPart=-3500000;
KeRaiseIrql(HIGH_LEVEL,&old);
start_kqpc=KeQueryPerformanceCounter(&start_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, start_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
KeLowerIrql(old);
KeWaitForSingleObject(&event,UserRequest,KernelMode,TRUE ,&i);
KeRaiseIrql(HIGH_LEVEL,&old);
stop_kqpc=KeQueryPerformanceCounter(&stop_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, stop_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
KeLowerIrql(old);
delta=stop_ticks-start_ticks;
delta2=stop_kqpc.QuadPart-start_kqpc.QuadPart;
if (delta>10000000000)
{
delta/=16;
delta2/=16;
}
reference=delta*(start_freq.QuadPart)/delta2;
data->reference=reference/1000;
if (reference%1000>500)
data->reference++;
data->reference*=1000;
reference=data->reference;
KeQuerySystemTime(&system_time);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, curr_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
tmp.tv_sec=-(LONG)(curr_ticks/reference);
tmp.tv_usec=-(LONG)((curr_ticks%reference)*1000000/reference);
system_time.QuadPart-=116444736000000000;
tmp.tv_sec+=(LONG)(system_time.QuadPart/10000000);
tmp.tv_usec+=(LONG)((system_time.QuadPart%10000000)/10);
if (tmp.tv_usec<0)
{
tmp.tv_sec--;
tmp.tv_usec+=1000000;
}
data->start[0] = tmp;
IF_LOUD(DbgPrint("Frequency %I64u MHz\n",data->reference);)
}
#endif //__NPF_x86__
#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
ULONG NumberOfCpus, i;
KAFFINITY AffinityMask;
if (data->reference != 0)
return;
NumberOfCpus = NCpu;
if ( TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP || TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP)
{
for (i = 0 ; i < NumberOfCpus ; i++ )
{
AffinityMask = (1 << i);
ZwSetInformationThread(NtCurrentThread(), ThreadAffinityMask, &AffinityMask, sizeof(KAFFINITY));
SynchronizeOnCpu(&(data->start[i]));
}
AffinityMask = 0xFFFFFFFF;
ZwSetInformationThread(NtCurrentThread(), ThreadAffinityMask, &AffinityMask, sizeof(KAFFINITY));
data->reference = 1;
}
else
if ( TimestampMode == TIMESTAMPMODE_QUERYSYSTEMTIME )
{
//do nothing
data->reference = 1;
}
else
//
// This timestamp mode is supported on x86 (32 bit) only
//
#ifdef __NPF_x86__
if ( TimestampMode == TIMESTAMPMODE_RDTSC )
{
TimeSynchronizeRDTSC(data);
}
else
#endif // __NPF_x86__
{ //it should be only the normal case i.e. TIMESTAMPMODE_SINGLESYNCHRONIZATION
SynchronizeOnCpu(data->start);
data->reference = 1;
}
return;
}
#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline void GetTimeKQPC(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER PTime, TimeFreq;
LONG tmp;
ULONG CurrentCpu;
static struct timeval old_ts={0,0};
PTime = KeQueryPerformanceCounter(&TimeFreq);
tmp = (LONG)(PTime.QuadPart/TimeFreq.QuadPart);
if (TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP || TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP)
{
//actually this code is ok only if we are guaranteed that no thread scheduling will take place.
CurrentCpu = KeGetCurrentProcessorNumber();
dst->tv_sec = data->start[CurrentCpu].tv_sec + tmp;
dst->tv_usec = data->start[CurrentCpu].tv_usec + (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (dst->tv_usec >= 1000000)
{
dst->tv_sec ++;
dst->tv_usec -= 1000000;
}
if (TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP)
{
if (old_ts.tv_sec > dst->tv_sec || (old_ts.tv_sec == dst->tv_sec && old_ts.tv_usec > dst->tv_usec) )
*dst = old_ts;
else
old_ts = *dst;
}
}
else
{ //it should be only the normal case i.e. TIMESTAMPMODE_SINGLESYNCHRONIZATION
dst->tv_sec = data->start[0].tv_sec + tmp;
dst->tv_usec = data->start[0].tv_usec + (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (dst->tv_usec >= 1000000)
{
dst->tv_sec ++;
dst->tv_usec -= 1000000;
}
}
}
//
// inline assembler is not supported with the current AMD64 compilers
// At the moment we simply disable this timestamping mode on AMD64.
// A solution would be to allocate a small memory from the non-paged
// pool, dump the instructions on that buffer, and then execute them.
// The non paged pool is needed since it's the only area of kernel
// data memory that is not subject to the NX protection.
// Or use some lower level trick, like using an assembler to assemble
// a small function for this.
//
#ifdef __NPF_x86__
__inline void GetTimeRDTSC(struct timeval *dst, struct time_conv *data)
{
ULONGLONG tmp;
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, tmp
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
if (data->reference==0)
{
return;
}
dst->tv_sec=(LONG)(tmp/data->reference);
dst->tv_usec=(LONG)((tmp-dst->tv_sec*data->reference)*1000000/data->reference);
dst->tv_sec+=data->start[0].tv_sec;
dst->tv_usec+=data->start[0].tv_usec;
if (dst->tv_usec>=1000000)
{
dst->tv_sec++;
dst->tv_usec-=1000000;
}
}
#endif //__NPF_x86__
__inline void GetTimeQST(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER SystemTime;
KeQuerySystemTime(&SystemTime);
dst->tv_sec = (LONG)(SystemTime.QuadPart/10000000-11644473600);
dst->tv_usec = (LONG)((SystemTime.QuadPart%10000000)/10);
}
#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
return;
#if 0
//
// This timestamp mode is supported on x86 (32 bit) only
//
#ifdef __NPF_x86__
if ( TimestampMode == TIMESTAMPMODE_RDTSC )
{
GetTimeRDTSC(dst,data);
}
else
#endif
if ( TimestampMode == TIMESTAMPMODE_QUERYSYSTEMTIME )
{
GetTimeQST(dst,data);
}
else
{
GetTimeKQPC(dst,data);
}
#endif
}
#else /*WIN_NT_DRIVER*/
__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start[0]=*src;
}
__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
return;
*dst=data->start[0];
}
#endif /*WIN_NT_DRIVER*/
#endif /*_time_calls*/
/*
* Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _time_calls
#define _time_calls
#ifdef WIN_NT_DRIVER
#include "debug.h"
#include "ndis.h"
#define DEFAULT_TIMESTAMPMODE 0
#define TIMESTAMPMODE_SINGLE_SYNCHRONIZATION 0
#define TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP 1
#define TIMESTAMPMODE_QUERYSYSTEMTIME 2
#define TIMESTAMPMODE_RDTSC 3
#define TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP 99
#define TIMESTAMPMODE_REGKEY L"TimestampMode"
extern ULONG TimestampMode;
extern ULONG NCpu;
/*!
\brief A microsecond precise timestamp.
included in the sf_pkthdr or the bpf_hdr that NPF associates with every packet.
*/
struct timeval {
long tv_sec; ///< seconds
long tv_usec; ///< microseconds
};
#endif /*WIN_NT_DRIVER*/
struct time_conv
{
ULONGLONG reference;
struct timeval start[32];
};
#ifdef WIN_NT_DRIVER
__inline void TIME_DESYNCHRONIZE(struct time_conv *data)
{
data->reference = 0;
// data->start.tv_sec = 0;
// data->start.tv_usec = 0;
}
__inline void ReadTimeStampModeFromRegistry(PUNICODE_STRING RegistryPath)
{
ULONG NewLength;
PWSTR NullTerminatedString;
RTL_QUERY_REGISTRY_TABLE Queries[2];
ULONG DefaultTimestampMode = DEFAULT_TIMESTAMPMODE;
NewLength = RegistryPath->Length/2;
NullTerminatedString = ExAllocatePool(PagedPool, (NewLength+1) *sizeof(WCHAR));
if (NullTerminatedString != NULL)
{
RtlCopyMemory(NullTerminatedString, RegistryPath->Buffer, RegistryPath->Length);
NullTerminatedString[NewLength]=0;
RtlZeroMemory(Queries, sizeof(Queries));
Queries[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
Queries[0].Name = TIMESTAMPMODE_REGKEY;
Queries[0].EntryContext = &TimestampMode;
Queries[0].DefaultType = REG_DWORD;
Queries[0].DefaultData = &DefaultTimestampMode;
Queries[0].DefaultLength = sizeof(ULONG);
if (RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, NullTerminatedString, Queries, NULL, NULL) != STATUS_SUCCESS)
{
TimestampMode = DEFAULT_TIMESTAMPMODE;
}
RtlWriteRegistryValue( RTL_REGISTRY_ABSOLUTE, NullTerminatedString, TIMESTAMPMODE_REGKEY, REG_DWORD, &TimestampMode,sizeof(ULONG));
ExFreePool(NullTerminatedString);
}
else
TimestampMode = DEFAULT_TIMESTAMPMODE;
}
#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600
/* KeQueryPerformanceCounter TimeStamps */
__inline void SynchronizeOnCpu(struct timeval *start)
{
// struct timeval *start = (struct timeval*)Data;
LARGE_INTEGER SystemTime;
LARGE_INTEGER TimeFreq,PTime;
// get the absolute value of the system boot time.
PTime = KeQueryPerformanceCounter(&TimeFreq);
KeQuerySystemTime(&SystemTime);
start->tv_sec = (LONG)(SystemTime.QuadPart/10000000-11644473600);
start->tv_usec = (LONG)((SystemTime.QuadPart%10000000)/10);
start->tv_sec -= (ULONG)(PTime.QuadPart/TimeFreq.QuadPart);
start->tv_usec -= (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (start->tv_usec < 0)
{
start->tv_sec --;
start->tv_usec += 1000000;
}
}
//
// inline assembler is not supported with the current AMD64 compilers
// At the moment we simply disable this timestamping mode on AMD64.
// A solution would be to allocate a small memory from the non-paged
// pool, dump the instructions on that buffer, and then execute them.
// The non paged pool is needed since it's the only area of kernel
// data memory that is not subject to the NX protection.
// Or use some lower level trick, like using an assembler to assemble
// a small function for this.
//
#ifdef __NPF_x86__
/*RDTSC timestamps */
/* callers must be at IRQL=PASSIVE_LEVEL*/
__inline VOID TimeSynchronizeRDTSC(struct time_conv *data)
{
struct timeval tmp;
LARGE_INTEGER system_time;
ULONGLONG curr_ticks;
KIRQL old;
LARGE_INTEGER start_kqpc,stop_kqpc,start_freq,stop_freq;
ULONGLONG start_ticks,stop_ticks;
ULONGLONG delta,delta2;
KEVENT event;
LARGE_INTEGER i;
ULONGLONG reference;
if (data->reference!=0)
return;
KeInitializeEvent(&event,NotificationEvent,FALSE);
i.QuadPart=-3500000;
KeRaiseIrql(HIGH_LEVEL,&old);
start_kqpc=KeQueryPerformanceCounter(&start_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, start_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
KeLowerIrql(old);
KeWaitForSingleObject(&event,UserRequest,KernelMode,TRUE ,&i);
KeRaiseIrql(HIGH_LEVEL,&old);
stop_kqpc=KeQueryPerformanceCounter(&stop_freq);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, stop_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
KeLowerIrql(old);
delta=stop_ticks-start_ticks;
delta2=stop_kqpc.QuadPart-start_kqpc.QuadPart;
if (delta>10000000000)
{
delta/=16;
delta2/=16;
}
reference=delta*(start_freq.QuadPart)/delta2;
data->reference=reference/1000;
if (reference%1000>500)
data->reference++;
data->reference*=1000;
reference=data->reference;
KeQuerySystemTime(&system_time);
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, curr_ticks
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
tmp.tv_sec=-(LONG)(curr_ticks/reference);
tmp.tv_usec=-(LONG)((curr_ticks%reference)*1000000/reference);
system_time.QuadPart-=116444736000000000;
tmp.tv_sec+=(LONG)(system_time.QuadPart/10000000);
tmp.tv_usec+=(LONG)((system_time.QuadPart%10000000)/10);
if (tmp.tv_usec<0)
{
tmp.tv_sec--;
tmp.tv_usec+=1000000;
}
data->start[0] = tmp;
IF_LOUD(DbgPrint("Frequency %I64u MHz\n",data->reference);)
}
#endif //__NPF_x86__
#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
ULONG NumberOfCpus, i;
KAFFINITY AffinityMask;
if (data->reference != 0)
return;
NumberOfCpus = NCpu;
if ( TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP || TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP)
{
for (i = 0 ; i < NumberOfCpus ; i++ )
{
AffinityMask = (1 << i);
ZwSetInformationThread(NtCurrentThread(), ThreadAffinityMask, &AffinityMask, sizeof(KAFFINITY));
SynchronizeOnCpu(&(data->start[i]));
}
AffinityMask = 0xFFFFFFFF;
ZwSetInformationThread(NtCurrentThread(), ThreadAffinityMask, &AffinityMask, sizeof(KAFFINITY));
data->reference = 1;
}
else
if ( TimestampMode == TIMESTAMPMODE_QUERYSYSTEMTIME )
{
//do nothing
data->reference = 1;
}
else
//
// This timestamp mode is supported on x86 (32 bit) only
//
#ifdef __NPF_x86__
if ( TimestampMode == TIMESTAMPMODE_RDTSC )
{
TimeSynchronizeRDTSC(data);
}
else
#endif // __NPF_x86__
{ //it should be only the normal case i.e. TIMESTAMPMODE_SINGLESYNCHRONIZATION
SynchronizeOnCpu(data->start);
data->reference = 1;
}
return;
}
#pragma optimize ("g",off) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline void GetTimeKQPC(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER PTime, TimeFreq;
LONG tmp;
ULONG CurrentCpu;
static struct timeval old_ts={0,0};
PTime = KeQueryPerformanceCounter(&TimeFreq);
tmp = (LONG)(PTime.QuadPart/TimeFreq.QuadPart);
if (TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP || TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_NO_FIXUP)
{
//actually this code is ok only if we are guaranteed that no thread scheduling will take place.
CurrentCpu = KeGetCurrentProcessorNumber();
dst->tv_sec = data->start[CurrentCpu].tv_sec + tmp;
dst->tv_usec = data->start[CurrentCpu].tv_usec + (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (dst->tv_usec >= 1000000)
{
dst->tv_sec ++;
dst->tv_usec -= 1000000;
}
if (TimestampMode == TIMESTAMPMODE_SYNCHRONIZATION_ON_CPU_WITH_FIXUP)
{
if (old_ts.tv_sec > dst->tv_sec || (old_ts.tv_sec == dst->tv_sec && old_ts.tv_usec > dst->tv_usec) )
*dst = old_ts;
else
old_ts = *dst;
}
}
else
{ //it should be only the normal case i.e. TIMESTAMPMODE_SINGLESYNCHRONIZATION
dst->tv_sec = data->start[0].tv_sec + tmp;
dst->tv_usec = data->start[0].tv_usec + (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
if (dst->tv_usec >= 1000000)
{
dst->tv_sec ++;
dst->tv_usec -= 1000000;
}
}
}
//
// inline assembler is not supported with the current AMD64 compilers
// At the moment we simply disable this timestamping mode on AMD64.
// A solution would be to allocate a small memory from the non-paged
// pool, dump the instructions on that buffer, and then execute them.
// The non paged pool is needed since it's the only area of kernel
// data memory that is not subject to the NX protection.
// Or use some lower level trick, like using an assembler to assemble
// a small function for this.
//
#ifdef __NPF_x86__
__inline void GetTimeRDTSC(struct timeval *dst, struct time_conv *data)
{
ULONGLONG tmp;
__asm
{
push eax
push edx
push ecx
rdtsc
lea ecx, tmp
mov [ecx+4], edx
mov [ecx], eax
pop ecx
pop edx
pop eax
}
if (data->reference==0)
{
return;
}
dst->tv_sec=(LONG)(tmp/data->reference);
dst->tv_usec=(LONG)((tmp-dst->tv_sec*data->reference)*1000000/data->reference);
dst->tv_sec+=data->start[0].tv_sec;
dst->tv_usec+=data->start[0].tv_usec;
if (dst->tv_usec>=1000000)
{
dst->tv_sec++;
dst->tv_usec-=1000000;
}
}
#endif //__NPF_x86__
__inline void GetTimeQST(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER SystemTime;
KeQuerySystemTime(&SystemTime);
dst->tv_sec = (LONG)(SystemTime.QuadPart/10000000-11644473600);
dst->tv_usec = (LONG)((SystemTime.QuadPart%10000000)/10);
}
#pragma optimize ("g",on) //Due to some weird behaviour of the optimizer of DDK build 2600
__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
return;
#if 0
//
// This timestamp mode is supported on x86 (32 bit) only
//
#ifdef __NPF_x86__
if ( TimestampMode == TIMESTAMPMODE_RDTSC )
{
GetTimeRDTSC(dst,data);
}
else
#endif
if ( TimestampMode == TIMESTAMPMODE_QUERYSYSTEMTIME )
{
GetTimeQST(dst,data);
}
else
{
GetTimeKQPC(dst,data);
}
#endif
}
#else /*WIN_NT_DRIVER*/
__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start[0]=*src;
}
__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
return;
*dst=data->start[0];
}
#endif /*WIN_NT_DRIVER*/
#endif /*_time_calls*/

View File

@ -1,385 +1,385 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#include "tme.h"
/* resizes extended memory */
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex)
{
uint8 *tmp;
if ((mem_ex==NULL)||(mem_ex->buffer==NULL)||(size==0))
return TME_ERROR; /* awfully never reached!!!! */
tmp=mem_ex->buffer;
mem_ex->buffer=NULL;
FREE_MEMORY(tmp);
ALLOCATE_MEMORY(tmp,uint8,size);
if (tmp==NULL)
return TME_ERROR; /* no memory */
mem_ex->size=size;
mem_ex->buffer=tmp;
return TME_SUCCESS;
}
/* activates a block of the TME */
uint32 set_active_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active=block;
tme->working=block;
return TME_SUCCESS;
}
/* simply inserts default values in a TME block */
/* it DOESN'T initialize the block in the core!! */
/* FIXME default values are defined at compile time, */
/* it will be useful to store them in the registry */
uint32 init_tme_block(TME_CORE *tme, uint32 block)
{
TME_DATA *data;
if (block>=MAX_TME_DATA_BLOCKS)
return TME_ERROR;
data=&(tme->block_data[block]);
tme->working=block;
ZERO_MEMORY(data,sizeof(TME_DATA));
/* entries in LUT */
data->lut_entries=TME_LUT_ENTRIES_DEFAULT;
/* blocks */
data->shared_memory_blocks=TME_SHARED_MEMORY_BLOCKS_DEFAULT;
/* block size */
data->block_size=TME_BLOCK_SIZE_DEFAULT;
/* lookup function */
data->lookup_code=lut_fcn_mapper(TME_LOOKUP_CODE_DEFAULT);
/* rehashing value */
data->rehashing_value=TME_REHASHING_VALUE_DEFAULT;
/* out lut function */
data->out_lut_exec=TME_OUT_LUT_EXEC_DEFAULT;
/* default function */
data->default_exec=TME_DEFAULT_EXEC_DEFAULT;
/* extra segment size */
data->extra_segment_size=TME_EXTRA_SEGMENT_SIZE_DEFAULT;
data->enable_deletion=FALSE;
data->last_read.tv_sec=0;
data->last_read.tv_usec=0;
return TME_SUCCESS;
}
/* it validates a TME block and */
/* (on OK) inserts the block in the core */
uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset)
{
uint32 required_memory;
uint8 *base=mem_ex_offset+mem_ex->buffer;
TME_DATA *data;
/* FIXME soluzione un po' posticcia... */
if (mem_ex_offset==0)
return TME_ERROR;
if (block>=MAX_TME_DATA_BLOCKS)
return TME_ERROR;
data=&tme->block_data[block];
if (data->lut_entries==0)
return TME_ERROR;
if (data->key_len==0)
return TME_ERROR;
if (data->shared_memory_blocks==0)
return TME_ERROR;
if (data->block_size==0)
return TME_ERROR;
/* checks if the lookup function is valid */
if (data->lookup_code==NULL)
return TME_ERROR;
/* checks if the out lut exec function is valid */
if (exec_fcn_mapper(data->out_lut_exec)==NULL)
return TME_ERROR;
/* checks if the default exec function is valid */
if (exec_fcn_mapper(data->default_exec)==NULL)
return TME_ERROR;
/* let's calculate memory needed */
required_memory=data->lut_entries*sizeof(RECORD); /*LUT*/
required_memory+=data->block_size*data->shared_memory_blocks; /*shared segment*/
required_memory+=data->extra_segment_size; /*extra segment*/
if (required_memory>(mem_ex->size-mem_ex_offset))
return TME_ERROR; /*not enough memory*/
/* the TME block can be initialized */
ZERO_MEMORY(base,required_memory);
data->lut_base_address=base;
data->shared_memory_base_address=
data->lut_base_address+
data->lut_entries*sizeof(RECORD);
data->extra_segment_base_address=
data->shared_memory_base_address+
data->block_size*data->shared_memory_blocks;
data->filled_blocks=1;
VALIDATE(tme->validated_blocks,block);
tme->active=block;
tme->working=block;
return TME_SUCCESS;
}
/* I/F between the bpf machine and the callbacks, just some checks */
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref)
{
if (tme->active==TME_NONE_ACTIVE)
return TME_FALSE;
return (tme->block_data[tme->active].lookup_code)(mem_ex_offset+mem_ex->buffer,&tme->block_data[tme->active],mem_ex, time_ref);
}
/* I/F between the bpf machine and the callbacks, just some checks */
uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size, uint32 offset)
{
exec_fcn tmp;
TME_DATA *data;
uint8 *block;
uint8 *mem_data;
if (tme->active==TME_NONE_ACTIVE)
return TME_ERROR;
data=&tme->block_data[tme->active];
if (data->last_found==NULL)
{ /*out lut exec */
tmp=exec_fcn_mapper(data->out_lut_exec);
block=data->shared_memory_base_address;
}
else
{ /*checks if last_found is valid */
if ((data->last_found<data->lut_base_address)||(data->last_found>=data->shared_memory_base_address))
return TME_ERROR;
else
{
tmp=exec_fcn_mapper(SW_ULONG_AT(&((RECORD*)data->last_found)->exec_fcn,0));
if (tmp==NULL)
return TME_ERROR;
block=SW_ULONG_AT(&((RECORD*)data->last_found)->block,0)+mem_ex->buffer;
if ((block<data->shared_memory_base_address)||(block>=data->extra_segment_base_address))
return TME_ERROR;
}
}
if (offset>=mem_ex->size)
return TME_ERROR;
mem_data=mem_ex->buffer+offset;
return tmp(block,pkt_size,data,mem_ex,mem_data);
}
/*resets all the TME core*/
uint32 reset_tme(TME_CORE *tme)
{
if (tme==NULL)
return TME_ERROR;
ZERO_MEMORY(tme, sizeof(TME_CORE));
return TME_SUCCESS;
}
/* returns a register value of the active TME block */
/* FIXME last found in maniera elegante e veloce ?!?! */
uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval)
{
switch(rgstr)
{
case TME_LUT_ENTRIES:
*rval=data->lut_entries;
return TME_SUCCESS;
case TME_MAX_FILL_STATE:
*rval=data->max_fill_state;
return TME_SUCCESS;
case TME_REHASHING_VALUE:
*rval=data->rehashing_value;
return TME_SUCCESS;
case TME_KEY_LEN:
*rval=data->key_len;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BLOCKS:
*rval=data->shared_memory_blocks;
return TME_SUCCESS;
case TME_FILLED_ENTRIES:
*rval=data->filled_entries;
return TME_SUCCESS;
case TME_BLOCK_SIZE:
*rval=data->block_size;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_SIZE:
*rval=data->extra_segment_size;
return TME_SUCCESS;
case TME_FILLED_BLOCKS:
*rval=data->filled_blocks;
return TME_SUCCESS;
case TME_DEFAULT_EXEC:
*rval=data->default_exec;
return TME_SUCCESS;
case TME_OUT_LUT_EXEC:
*rval=data->out_lut_exec;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BASE_ADDRESS:
*rval=data->shared_memory_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_LUT_BASE_ADDRESS:
*rval=data->lut_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_BASE_ADDRESS:
*rval=data->extra_segment_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_LAST_FOUND_BLOCK:
if (data->last_found==NULL)
*rval=0;
else
*rval=data->last_found-mem_ex->buffer;
return TME_SUCCESS;
default:
return TME_ERROR;
}
}
/* sets a register value in the active block */
/* FIXME last found in maniera elegante e veloce ?!?! */
uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init)
{ /* very very very dangerous!!!!!!!!!!! */
lut_fcn tmp;
switch(rgstr)
{
case TME_MAX_FILL_STATE:
data->max_fill_state=value;
return TME_SUCCESS;
case TME_REHASHING_VALUE:
data->rehashing_value=value;
return TME_SUCCESS;
case TME_FILLED_ENTRIES:
data->filled_entries=value;
return TME_SUCCESS;
case TME_FILLED_BLOCKS:
if (value<=data->shared_memory_blocks)
{
data->filled_blocks=value;
return TME_SUCCESS;
}
else
return TME_ERROR;
case TME_DEFAULT_EXEC:
data->default_exec=value;
return TME_SUCCESS;
case TME_OUT_LUT_EXEC:
data->out_lut_exec=value;
return TME_SUCCESS;
case TME_LOOKUP_CODE:
tmp=lut_fcn_mapper(value);
if (tmp==NULL)
return TME_ERROR;
else
data->lookup_code=tmp;
return TME_SUCCESS;
default:
break;
}
if (init)
switch (rgstr)
{
case TME_LUT_ENTRIES:
data->lut_entries=value;
return TME_SUCCESS;
case TME_KEY_LEN:
data->key_len=value;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BLOCKS:
data->shared_memory_blocks=value;
return TME_SUCCESS;
case TME_BLOCK_SIZE:
data->block_size=value;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_SIZE:
data->extra_segment_size=value;
return TME_SUCCESS;
default:
return TME_ERROR;
}
else
return TME_ERROR;
}
/* chooses the TME block for read */
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active_read=block;
return TME_SUCCESS;
}
/* chooses if the autodeletion must be used */
uint32 set_autodeletion(TME_DATA *data, uint32 value)
{
if (value==0) /* no autodeletion */
data->enable_deletion=FALSE;
else
data->enable_deletion=TRUE;
return TME_SUCCESS;
}
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <GlobalConst.h>
#include "tme.h"
/* resizes extended memory */
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex)
{
uint8 *tmp;
if ((mem_ex==NULL)||(mem_ex->buffer==NULL)||(size==0))
return TME_ERROR; /* awfully never reached!!!! */
tmp=mem_ex->buffer;
mem_ex->buffer=NULL;
FREE_MEMORY(tmp);
ALLOCATE_MEMORY(tmp,uint8,size);
if (tmp==NULL)
return TME_ERROR; /* no memory */
mem_ex->size=size;
mem_ex->buffer=tmp;
return TME_SUCCESS;
}
/* activates a block of the TME */
uint32 set_active_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active=block;
tme->working=block;
return TME_SUCCESS;
}
/* simply inserts default values in a TME block */
/* it DOESN'T initialize the block in the core!! */
/* FIXME default values are defined at compile time, */
/* it will be useful to store them in the registry */
uint32 init_tme_block(TME_CORE *tme, uint32 block)
{
TME_DATA *data;
if (block>=MAX_TME_DATA_BLOCKS)
return TME_ERROR;
data=&(tme->block_data[block]);
tme->working=block;
ZERO_MEMORY(data,sizeof(TME_DATA));
/* entries in LUT */
data->lut_entries=TME_LUT_ENTRIES_DEFAULT;
/* blocks */
data->shared_memory_blocks=TME_SHARED_MEMORY_BLOCKS_DEFAULT;
/* block size */
data->block_size=TME_BLOCK_SIZE_DEFAULT;
/* lookup function */
data->lookup_code=lut_fcn_mapper(TME_LOOKUP_CODE_DEFAULT);
/* rehashing value */
data->rehashing_value=TME_REHASHING_VALUE_DEFAULT;
/* out lut function */
data->out_lut_exec=TME_OUT_LUT_EXEC_DEFAULT;
/* default function */
data->default_exec=TME_DEFAULT_EXEC_DEFAULT;
/* extra segment size */
data->extra_segment_size=TME_EXTRA_SEGMENT_SIZE_DEFAULT;
data->enable_deletion=FALSE;
data->last_read.tv_sec=0;
data->last_read.tv_usec=0;
return TME_SUCCESS;
}
/* it validates a TME block and */
/* (on OK) inserts the block in the core */
uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset)
{
uint32 required_memory;
uint8 *base=mem_ex_offset+mem_ex->buffer;
TME_DATA *data;
/* FIXME soluzione un po' posticcia... */
if (mem_ex_offset==0)
return TME_ERROR;
if (block>=MAX_TME_DATA_BLOCKS)
return TME_ERROR;
data=&tme->block_data[block];
if (data->lut_entries==0)
return TME_ERROR;
if (data->key_len==0)
return TME_ERROR;
if (data->shared_memory_blocks==0)
return TME_ERROR;
if (data->block_size==0)
return TME_ERROR;
/* checks if the lookup function is valid */
if (data->lookup_code==NULL)
return TME_ERROR;
/* checks if the out lut exec function is valid */
if (exec_fcn_mapper(data->out_lut_exec)==NULL)
return TME_ERROR;
/* checks if the default exec function is valid */
if (exec_fcn_mapper(data->default_exec)==NULL)
return TME_ERROR;
/* let's calculate memory needed */
required_memory=data->lut_entries*sizeof(RECORD); /*LUT*/
required_memory+=data->block_size*data->shared_memory_blocks; /*shared segment*/
required_memory+=data->extra_segment_size; /*extra segment*/
if (required_memory>(mem_ex->size-mem_ex_offset))
return TME_ERROR; /*not enough memory*/
/* the TME block can be initialized */
ZERO_MEMORY(base,required_memory);
data->lut_base_address=base;
data->shared_memory_base_address=
data->lut_base_address+
data->lut_entries*sizeof(RECORD);
data->extra_segment_base_address=
data->shared_memory_base_address+
data->block_size*data->shared_memory_blocks;
data->filled_blocks=1;
VALIDATE(tme->validated_blocks,block);
tme->active=block;
tme->working=block;
return TME_SUCCESS;
}
/* I/F between the bpf machine and the callbacks, just some checks */
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref)
{
if (tme->active==TME_NONE_ACTIVE)
return TME_FALSE;
return (tme->block_data[tme->active].lookup_code)(mem_ex_offset+mem_ex->buffer,&tme->block_data[tme->active],mem_ex, time_ref);
}
/* I/F between the bpf machine and the callbacks, just some checks */
uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size, uint32 offset)
{
exec_fcn tmp;
TME_DATA *data;
uint8 *block;
uint8 *mem_data;
if (tme->active==TME_NONE_ACTIVE)
return TME_ERROR;
data=&tme->block_data[tme->active];
if (data->last_found==NULL)
{ /*out lut exec */
tmp=exec_fcn_mapper(data->out_lut_exec);
block=data->shared_memory_base_address;
}
else
{ /*checks if last_found is valid */
if ((data->last_found<data->lut_base_address)||(data->last_found>=data->shared_memory_base_address))
return TME_ERROR;
else
{
tmp=exec_fcn_mapper(SW_ULONG_AT(&((RECORD*)data->last_found)->exec_fcn,0));
if (tmp==NULL)
return TME_ERROR;
block=SW_ULONG_AT(&((RECORD*)data->last_found)->block,0)+mem_ex->buffer;
if ((block<data->shared_memory_base_address)||(block>=data->extra_segment_base_address))
return TME_ERROR;
}
}
if (offset>=mem_ex->size)
return TME_ERROR;
mem_data=mem_ex->buffer+offset;
return tmp(block,pkt_size,data,mem_ex,mem_data);
}
/*resets all the TME core*/
uint32 reset_tme(TME_CORE *tme)
{
if (tme==NULL)
return TME_ERROR;
ZERO_MEMORY(tme, sizeof(TME_CORE));
return TME_SUCCESS;
}
/* returns a register value of the active TME block */
/* FIXME last found in maniera elegante e veloce ?!?! */
uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval)
{
switch(rgstr)
{
case TME_LUT_ENTRIES:
*rval=data->lut_entries;
return TME_SUCCESS;
case TME_MAX_FILL_STATE:
*rval=data->max_fill_state;
return TME_SUCCESS;
case TME_REHASHING_VALUE:
*rval=data->rehashing_value;
return TME_SUCCESS;
case TME_KEY_LEN:
*rval=data->key_len;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BLOCKS:
*rval=data->shared_memory_blocks;
return TME_SUCCESS;
case TME_FILLED_ENTRIES:
*rval=data->filled_entries;
return TME_SUCCESS;
case TME_BLOCK_SIZE:
*rval=data->block_size;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_SIZE:
*rval=data->extra_segment_size;
return TME_SUCCESS;
case TME_FILLED_BLOCKS:
*rval=data->filled_blocks;
return TME_SUCCESS;
case TME_DEFAULT_EXEC:
*rval=data->default_exec;
return TME_SUCCESS;
case TME_OUT_LUT_EXEC:
*rval=data->out_lut_exec;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BASE_ADDRESS:
*rval=data->shared_memory_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_LUT_BASE_ADDRESS:
*rval=data->lut_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_BASE_ADDRESS:
*rval=data->extra_segment_base_address-mem_ex->buffer;
return TME_SUCCESS;
case TME_LAST_FOUND_BLOCK:
if (data->last_found==NULL)
*rval=0;
else
*rval=data->last_found-mem_ex->buffer;
return TME_SUCCESS;
default:
return TME_ERROR;
}
}
/* sets a register value in the active block */
/* FIXME last found in maniera elegante e veloce ?!?! */
uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init)
{ /* very very very dangerous!!!!!!!!!!! */
lut_fcn tmp;
switch(rgstr)
{
case TME_MAX_FILL_STATE:
data->max_fill_state=value;
return TME_SUCCESS;
case TME_REHASHING_VALUE:
data->rehashing_value=value;
return TME_SUCCESS;
case TME_FILLED_ENTRIES:
data->filled_entries=value;
return TME_SUCCESS;
case TME_FILLED_BLOCKS:
if (value<=data->shared_memory_blocks)
{
data->filled_blocks=value;
return TME_SUCCESS;
}
else
return TME_ERROR;
case TME_DEFAULT_EXEC:
data->default_exec=value;
return TME_SUCCESS;
case TME_OUT_LUT_EXEC:
data->out_lut_exec=value;
return TME_SUCCESS;
case TME_LOOKUP_CODE:
tmp=lut_fcn_mapper(value);
if (tmp==NULL)
return TME_ERROR;
else
data->lookup_code=tmp;
return TME_SUCCESS;
default:
break;
}
if (init)
switch (rgstr)
{
case TME_LUT_ENTRIES:
data->lut_entries=value;
return TME_SUCCESS;
case TME_KEY_LEN:
data->key_len=value;
return TME_SUCCESS;
case TME_SHARED_MEMORY_BLOCKS:
data->shared_memory_blocks=value;
return TME_SUCCESS;
case TME_BLOCK_SIZE:
data->block_size=value;
return TME_SUCCESS;
case TME_EXTRA_SEGMENT_SIZE:
data->extra_segment_size=value;
return TME_SUCCESS;
default:
return TME_ERROR;
}
else
return TME_ERROR;
}
/* chooses the TME block for read */
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active_read=block;
return TME_SUCCESS;
}
/* chooses if the autodeletion must be used */
uint32 set_autodeletion(TME_DATA *data, uint32 value)
{
if (value==0) /* no autodeletion */
data->enable_deletion=FALSE;
else
data->enable_deletion=TRUE;
return TME_SUCCESS;
}

View File

@ -1,174 +1,174 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __tme_include_
#define __tme_include_
#ifdef WIN_NT_DRIVER
#include "ndis.h"
#else
#include <windows.h>
#endif /*WIN_NT_DRIVER*/
#include "memory_t.h"
#include "time_calls.h"
/* error codes */
#define TME_ERROR 0
#define TME_SUCCESS 1
#define TME_TRUE 2
#define TME_FALSE 3
/* some constants */
#define DEFAULT_MEM_EX_SIZE 65536
#define MAX_TME_DATA_BLOCKS 4
#define TME_NONE_ACTIVE 0xffffffff
#define DELTA_READ 2 /* secs */
#define TME_LUT_ENTRIES 0x00000000
#define TME_MAX_FILL_STATE 0x00000001 /*potrebbe servire per un thread a passive level!?!?! */
#define TME_REHASHING_VALUE 0x00000002
#define TME_KEY_LEN 0x00000003
#define TME_SHARED_MEMORY_BLOCKS 0x00000004
#define TME_FILLED_ENTRIES 0x00000005
#define TME_BLOCK_SIZE 0x00000006
#define TME_EXTRA_SEGMENT_SIZE 0x00000007
#define TME_LOOKUP_CODE 0x00000008
#define TME_OUT_LUT_EXEC 0x00000009
#define TME_FILLED_BLOCKS 0x0000000a
#define TME_DEFAULT_EXEC 0x0000000b
#define TME_LUT_BASE_ADDRESS 0x0000000c
#define TME_SHARED_MEMORY_BASE_ADDRESS 0x0000000d
#define TME_EXTRA_SEGMENT_BASE_ADDRESS 0x0000000e
#define TME_LAST_FOUND 0x0000000f /* contains the offset of the last found entry */
#define TME_LAST_FOUND_BLOCK 0x00000010
/* TME default values */
#define TME_LUT_ENTRIES_DEFAULT 32007
#define TME_REHASHING_VALUE_DEFAULT 1
#define TME_SHARED_MEMORY_BLOCKS_DEFAULT 16000
#define TME_BLOCK_SIZE_DEFAULT 64
#define TME_EXTRA_SEGMENT_SIZE_DEFAULT 0
#define TME_LOOKUP_CODE_DEFAULT 0
#define TME_OUT_LUT_EXEC_DEFAULT 0
#define TME_DEFAULT_EXEC_DEFAULT 0
#define TME_MAX_FILL_STATE_DEFAULT 15000
#define IS_VALIDATED(src,index) (src&(1<<index))
#define VALIDATE(src,index) src|=(1<<index);
#define FORCE_NO_DELETION(timestamp) (struct timeval*)(timestamp)->tv_sec=0x7fffffff;
/* TME callback prototypes */
typedef uint32 (*lut_fcn)(uint8 *key, struct __TME_DATA *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, struct __TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
/* DO NOT MODIFY THIS STRUCTURE!!!! GV */
typedef struct __RECORD
{
uint32 block;
uint32 exec_fcn;
}
RECORD, *PRECORD;
/* TME data registers */
struct __TME_DATA
{
uint32 lut_entries;
uint32 max_fill_state;
uint32 rehashing_value;
uint32 key_len;
uint32 shared_memory_blocks;
uint32 filled_entries;
uint32 block_size;
uint32 extra_segment_size;
uint32 filled_blocks;
lut_fcn lookup_code;
uint32 default_exec;
uint32 out_lut_exec;
uint8 *lut_base_address;
uint8 *shared_memory_base_address;
uint8 *extra_segment_base_address;
struct timeval last_read;
uint32 enable_deletion;
uint8 *last_found;
};
typedef struct __TME_DATA TME_DATA,*PTME_DATA;
/* TME core */
typedef struct __TME_CORE
{
uint32 working;
uint32 active;
uint32 validated_blocks;
TME_DATA block_data[MAX_TME_DATA_BLOCKS];
uint32 active_read;
} TME_CORE, *PTME_CORE;
static __inline int32 IS_DELETABLE(void *timestamp, TME_DATA *data)
{
struct timeval *ts=(struct timeval*)timestamp;
if (data->enable_deletion==FALSE)
return FALSE;
if (data->filled_entries<data->max_fill_state)
return FALSE;
if ((ts->tv_sec+DELTA_READ)<data->last_read.tv_sec)
return TRUE;
return FALSE;
}
/* functions to manage TME */
uint32 init_tme_block(TME_CORE *tme, uint32 block);
uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset);
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref);
uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size,uint32 offset);
uint32 set_active_tme_block(TME_CORE *tme, uint32 block);
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex);
uint32 reset_tme(TME_CORE *tme);
uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval);
uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init);
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block);
uint32 set_autodeletion(TME_DATA *data, uint32 value);
/* function mappers */
lut_fcn lut_fcn_mapper(uint32 index);
exec_fcn exec_fcn_mapper(uint32 index);
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __tme_include_
#define __tme_include_
#ifdef WIN_NT_DRIVER
#include "ndis.h"
#else
#include <windows.h>
#endif /*WIN_NT_DRIVER*/
#include "memory_t.h"
#include "time_calls.h"
/* error codes */
#define TME_ERROR 0
#define TME_SUCCESS 1
#define TME_TRUE 2
#define TME_FALSE 3
/* some constants */
#define DEFAULT_MEM_EX_SIZE 65536
#define MAX_TME_DATA_BLOCKS 4
#define TME_NONE_ACTIVE 0xffffffff
#define DELTA_READ 2 /* secs */
#define TME_LUT_ENTRIES 0x00000000
#define TME_MAX_FILL_STATE 0x00000001 /*potrebbe servire per un thread a passive level!?!?! */
#define TME_REHASHING_VALUE 0x00000002
#define TME_KEY_LEN 0x00000003
#define TME_SHARED_MEMORY_BLOCKS 0x00000004
#define TME_FILLED_ENTRIES 0x00000005
#define TME_BLOCK_SIZE 0x00000006
#define TME_EXTRA_SEGMENT_SIZE 0x00000007
#define TME_LOOKUP_CODE 0x00000008
#define TME_OUT_LUT_EXEC 0x00000009
#define TME_FILLED_BLOCKS 0x0000000a
#define TME_DEFAULT_EXEC 0x0000000b
#define TME_LUT_BASE_ADDRESS 0x0000000c
#define TME_SHARED_MEMORY_BASE_ADDRESS 0x0000000d
#define TME_EXTRA_SEGMENT_BASE_ADDRESS 0x0000000e
#define TME_LAST_FOUND 0x0000000f /* contains the offset of the last found entry */
#define TME_LAST_FOUND_BLOCK 0x00000010
/* TME default values */
#define TME_LUT_ENTRIES_DEFAULT 32007
#define TME_REHASHING_VALUE_DEFAULT 1
#define TME_SHARED_MEMORY_BLOCKS_DEFAULT 16000
#define TME_BLOCK_SIZE_DEFAULT 64
#define TME_EXTRA_SEGMENT_SIZE_DEFAULT 0
#define TME_LOOKUP_CODE_DEFAULT 0
#define TME_OUT_LUT_EXEC_DEFAULT 0
#define TME_DEFAULT_EXEC_DEFAULT 0
#define TME_MAX_FILL_STATE_DEFAULT 15000
#define IS_VALIDATED(src,index) (src&(1<<index))
#define VALIDATE(src,index) src|=(1<<index);
#define FORCE_NO_DELETION(timestamp) (struct timeval*)(timestamp)->tv_sec=0x7fffffff;
/* TME callback prototypes */
typedef uint32 (*lut_fcn)(uint8 *key, struct __TME_DATA *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, struct __TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
/* DO NOT MODIFY THIS STRUCTURE!!!! GV */
typedef struct __RECORD
{
uint32 block;
uint32 exec_fcn;
}
RECORD, *PRECORD;
/* TME data registers */
struct __TME_DATA
{
uint32 lut_entries;
uint32 max_fill_state;
uint32 rehashing_value;
uint32 key_len;
uint32 shared_memory_blocks;
uint32 filled_entries;
uint32 block_size;
uint32 extra_segment_size;
uint32 filled_blocks;
lut_fcn lookup_code;
uint32 default_exec;
uint32 out_lut_exec;
uint8 *lut_base_address;
uint8 *shared_memory_base_address;
uint8 *extra_segment_base_address;
struct timeval last_read;
uint32 enable_deletion;
uint8 *last_found;
};
typedef struct __TME_DATA TME_DATA,*PTME_DATA;
/* TME core */
typedef struct __TME_CORE
{
uint32 working;
uint32 active;
uint32 validated_blocks;
TME_DATA block_data[MAX_TME_DATA_BLOCKS];
uint32 active_read;
} TME_CORE, *PTME_CORE;
static __inline int32 IS_DELETABLE(void *timestamp, TME_DATA *data)
{
struct timeval *ts=(struct timeval*)timestamp;
if (data->enable_deletion==FALSE)
return FALSE;
if (data->filled_entries<data->max_fill_state)
return FALSE;
if ((ts->tv_sec+DELTA_READ)<data->last_read.tv_sec)
return TRUE;
return FALSE;
}
/* functions to manage TME */
uint32 init_tme_block(TME_CORE *tme, uint32 block);
uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset);
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref);
uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size,uint32 offset);
uint32 set_active_tme_block(TME_CORE *tme, uint32 block);
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex);
uint32 reset_tme(TME_CORE *tme);
uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval);
uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init);
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block);
uint32 set_autodeletion(TME_DATA *data, uint32 value);
/* function mappers */
lut_fcn lut_fcn_mapper(uint32 index);
exec_fcn exec_fcn_mapper(uint32 index);
#endif

View File

@ -1,117 +1,117 @@
/*
* Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
u_short valid_instructions[]=
{
BPF_RET|BPF_K,
BPF_RET|BPF_A,
BPF_LD|BPF_IMM,
BPF_LDX|BPF_IMM,
BPF_LD|BPF_MEM,
BPF_LDX|BPF_MEM,
#ifdef __NPF_x86__
BPF_LD|BPF_MEM_EX_IMM|BPF_B,
BPF_LD|BPF_MEM_EX_IMM|BPF_H,
BPF_LD|BPF_MEM_EX_IMM|BPF_W,
BPF_LD|BPF_MEM_EX_IND|BPF_B,
BPF_LD|BPF_MEM_EX_IND|BPF_H,
BPF_LD|BPF_MEM_EX_IND|BPF_W,
#endif
BPF_LD|BPF_W|BPF_ABS,
BPF_LD|BPF_H|BPF_ABS,
BPF_LD|BPF_B|BPF_ABS,
BPF_LDX|BPF_W|BPF_ABS,
BPF_LDX|BPF_H|BPF_ABS,
BPF_LDX|BPF_B|BPF_ABS,
BPF_LD|BPF_W|BPF_LEN,
BPF_LDX|BPF_W|BPF_LEN,
BPF_LD|BPF_W|BPF_IND,
BPF_LD|BPF_H|BPF_IND,
BPF_LD|BPF_B|BPF_IND,
BPF_LDX|BPF_MSH|BPF_B,
BPF_ST,
BPF_STX,
#ifdef __NPF_x86__
BPF_ST|BPF_MEM_EX_IMM|BPF_B,
BPF_STX|BPF_MEM_EX_IMM|BPF_B,
BPF_ST|BPF_MEM_EX_IMM|BPF_W,
BPF_STX|BPF_MEM_EX_IMM|BPF_W,
BPF_ST|BPF_MEM_EX_IMM|BPF_H,
BPF_STX|BPF_MEM_EX_IMM|BPF_H,
BPF_ST|BPF_MEM_EX_IND|BPF_B,
BPF_ST|BPF_MEM_EX_IND|BPF_W,
BPF_ST|BPF_MEM_EX_IND|BPF_H,
#endif
BPF_JMP|BPF_JA,
BPF_JMP|BPF_JGT|BPF_K,
BPF_JMP|BPF_JGE|BPF_K,
BPF_JMP|BPF_JEQ|BPF_K,
BPF_JMP|BPF_JSET|BPF_K,
BPF_JMP|BPF_JGT|BPF_X,
BPF_JMP|BPF_JGE|BPF_X,
BPF_JMP|BPF_JEQ|BPF_X,
BPF_JMP|BPF_JSET|BPF_X,
BPF_ALU|BPF_ADD|BPF_X,
BPF_ALU|BPF_SUB|BPF_X,
BPF_ALU|BPF_MUL|BPF_X,
BPF_ALU|BPF_DIV|BPF_X,
BPF_ALU|BPF_AND|BPF_X,
BPF_ALU|BPF_OR|BPF_X,
BPF_ALU|BPF_LSH|BPF_X,
BPF_ALU|BPF_RSH|BPF_X,
BPF_ALU|BPF_ADD|BPF_K,
BPF_ALU|BPF_SUB|BPF_K,
BPF_ALU|BPF_MUL|BPF_K,
BPF_ALU|BPF_DIV|BPF_K,
BPF_ALU|BPF_AND|BPF_K,
BPF_ALU|BPF_OR|BPF_K,
BPF_ALU|BPF_LSH|BPF_K,
BPF_ALU|BPF_RSH|BPF_K,
BPF_ALU|BPF_NEG,
BPF_MISC|BPF_TAX,
BPF_MISC|BPF_TXA,
#ifdef __NPF_x86__
BPF_MISC|BPF_TME|BPF_LOOKUP,
BPF_MISC|BPF_TME|BPF_EXECUTE,
BPF_MISC|BPF_TME|BPF_SET_ACTIVE,
BPF_MISC|BPF_TME|BPF_GET_REGISTER_VALUE,
BPF_MISC|BPF_TME|BPF_SET_REGISTER_VALUE
#endif
};
#define VALID_INSTRUCTIONS_LEN (sizeof(valid_instructions)/sizeof(u_short))
/*
* Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 CACE Technologies, Davis (California)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
u_short valid_instructions[]=
{
BPF_RET|BPF_K,
BPF_RET|BPF_A,
BPF_LD|BPF_IMM,
BPF_LDX|BPF_IMM,
BPF_LD|BPF_MEM,
BPF_LDX|BPF_MEM,
#ifdef __NPF_x86__
BPF_LD|BPF_MEM_EX_IMM|BPF_B,
BPF_LD|BPF_MEM_EX_IMM|BPF_H,
BPF_LD|BPF_MEM_EX_IMM|BPF_W,
BPF_LD|BPF_MEM_EX_IND|BPF_B,
BPF_LD|BPF_MEM_EX_IND|BPF_H,
BPF_LD|BPF_MEM_EX_IND|BPF_W,
#endif
BPF_LD|BPF_W|BPF_ABS,
BPF_LD|BPF_H|BPF_ABS,
BPF_LD|BPF_B|BPF_ABS,
BPF_LDX|BPF_W|BPF_ABS,
BPF_LDX|BPF_H|BPF_ABS,
BPF_LDX|BPF_B|BPF_ABS,
BPF_LD|BPF_W|BPF_LEN,
BPF_LDX|BPF_W|BPF_LEN,
BPF_LD|BPF_W|BPF_IND,
BPF_LD|BPF_H|BPF_IND,
BPF_LD|BPF_B|BPF_IND,
BPF_LDX|BPF_MSH|BPF_B,
BPF_ST,
BPF_STX,
#ifdef __NPF_x86__
BPF_ST|BPF_MEM_EX_IMM|BPF_B,
BPF_STX|BPF_MEM_EX_IMM|BPF_B,
BPF_ST|BPF_MEM_EX_IMM|BPF_W,
BPF_STX|BPF_MEM_EX_IMM|BPF_W,
BPF_ST|BPF_MEM_EX_IMM|BPF_H,
BPF_STX|BPF_MEM_EX_IMM|BPF_H,
BPF_ST|BPF_MEM_EX_IND|BPF_B,
BPF_ST|BPF_MEM_EX_IND|BPF_W,
BPF_ST|BPF_MEM_EX_IND|BPF_H,
#endif
BPF_JMP|BPF_JA,
BPF_JMP|BPF_JGT|BPF_K,
BPF_JMP|BPF_JGE|BPF_K,
BPF_JMP|BPF_JEQ|BPF_K,
BPF_JMP|BPF_JSET|BPF_K,
BPF_JMP|BPF_JGT|BPF_X,
BPF_JMP|BPF_JGE|BPF_X,
BPF_JMP|BPF_JEQ|BPF_X,
BPF_JMP|BPF_JSET|BPF_X,
BPF_ALU|BPF_ADD|BPF_X,
BPF_ALU|BPF_SUB|BPF_X,
BPF_ALU|BPF_MUL|BPF_X,
BPF_ALU|BPF_DIV|BPF_X,
BPF_ALU|BPF_AND|BPF_X,
BPF_ALU|BPF_OR|BPF_X,
BPF_ALU|BPF_LSH|BPF_X,
BPF_ALU|BPF_RSH|BPF_X,
BPF_ALU|BPF_ADD|BPF_K,
BPF_ALU|BPF_SUB|BPF_K,
BPF_ALU|BPF_MUL|BPF_K,
BPF_ALU|BPF_DIV|BPF_K,
BPF_ALU|BPF_AND|BPF_K,
BPF_ALU|BPF_OR|BPF_K,
BPF_ALU|BPF_LSH|BPF_K,
BPF_ALU|BPF_RSH|BPF_K,
BPF_ALU|BPF_NEG,
BPF_MISC|BPF_TAX,
BPF_MISC|BPF_TXA,
#ifdef __NPF_x86__
BPF_MISC|BPF_TME|BPF_LOOKUP,
BPF_MISC|BPF_TME|BPF_EXECUTE,
BPF_MISC|BPF_TME|BPF_SET_ACTIVE,
BPF_MISC|BPF_TME|BPF_GET_REGISTER_VALUE,
BPF_MISC|BPF_TME|BPF_SET_REGISTER_VALUE
#endif
};
#define VALID_INSTRUCTIONS_LEN (sizeof(valid_instructions)/sizeof(u_short))

View File

@ -1,417 +1,417 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /usr/cvsroot_private/winpcap/packetNtx/driver/win_bpf.h,v 1.2.2.1 2005/12/02 22:12:58 gianlucav Exp $ (LBL)
*/
#ifndef BPF_MAJOR_VERSION
/* BSD style release date */
#define BPF_RELEASE 199606
#ifdef WIN_NT_DRIVER
#include <ndis.h>
#endif
#include "tme.h"
#include "time_calls.h"
typedef UCHAR u_char;
typedef USHORT u_short;
#ifdef WIN_NT_DRIVER
typedef ULONG u_int;
#endif
typedef LONG bpf_int32;
typedef ULONG bpf_u_int32;
typedef ULONG u_int32;
#define BPF_MAXINSNS 512
#define BPF_MAXBUFSIZE 0x8000
#define BPF_MINBUFSIZE 32
/*
* The instruction data structure.
*/
struct bpf_insn {
u_short code;
u_char jt;
u_char jf;
bpf_u_int32 k;
};
/*
* Structure for BIOCSETF.
*/
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
/*
* Struct returned by BIOCGSTATS.
*/
struct bpf_stat {
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*
* Struct return by BIOCVERSION. This represents the version number of
* the filter language described by the instruction encodings below.
* bpf understands a program iff kernel_major == filter_major &&
* kernel_minor >= filter_minor, that is, if the value returned by the
* running kernel has the same major number and a minor number equal
* equal to or less than the filter being downloaded. Otherwise, the
* results are undefined, meaning an error may be returned or packets
* may be accepted haphazardly.
* It has nothing to do with the source code version.
*/
struct bpf_version {
u_short bv_major;
u_short bv_minor;
};
/* Current version number of filter architecture. */
#define BPF_MAJOR_VERSION 1
#define BPF_MINOR_VERSION 1
/*
* Structure prepended to each packet.
*/
struct bpf_hdr {
struct timeval bh_tstamp; /* time stamp */
bpf_u_int32 bh_caplen; /* length of captured portion */
bpf_u_int32 bh_datalen; /* original length of packet */
u_short bh_hdrlen; /* length of bpf header (this struct
plus alignment padding) */
};
/*
* Data-link level type codes.
*/
/*
* These are the types that are the same on all platforms; on other
* platforms, a <net/bpf.h> should be supplied that defines the additional
* DLT_* codes appropriately for that platform (the BSDs, for example,
* should not just pick up this version of "bpf.h"; they should also define
* the additional DLT_* codes used by their kernels, as well as the values
* defined here - and, if the values they use for particular DLT_ types
* differ from those here, they should use their values, not the ones
* here).
*/
#define DLT_NULL 0 /* no link-layer encapsulation */
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
#define DLT_AX25 3 /* Amateur Radio AX.25 */
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
#define DLT_CHAOS 5 /* Chaos */
#define DLT_IEEE802 6 /* IEEE 802 Networks */
#define DLT_ARCNET 7 /* ARCNET */
#define DLT_SLIP 8 /* Serial Line IP */
#define DLT_PPP 9 /* Point-to-point Protocol */
#define DLT_FDDI 10 /* FDDI */
/*
* These are values from the traditional libpcap "bpf.h".
* Ports of this to particular platforms should replace these definitions
* with the ones appropriate to that platform, if the values are
* different on that platform.
*/
#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
#define DLT_RAW 12 /* raw IP */
/*
* These are values from BSD/OS's "bpf.h".
* These are not the same as the values from the traditional libpcap
* "bpf.h"; however, these values shouldn't be generated by any
* OS other than BSD/OS, so the correct values to use here are the
* BSD/OS values.
*
* Platforms that have already assigned these values to other
* DLT_ codes, however, should give these codes the values
* from that platform, so that programs that use these codes will
* continue to compile - even though they won't correctly read
* files of these types.
*/
#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
/*
* This value is defined by NetBSD; other platforms should refrain from
* using it for other purposes, so that NetBSD savefiles with a link
* type of 50 can be read as this type on all platforms.
*/
#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
/*
* This value was defined by libpcap 0.5; platforms that have defined
* it with a different value should define it here with that value -
* a link type of 104 in a save file will be mapped to DLT_C_HDLC,
* whatever value that happens to be, so programs will correctly
* handle files with that link type regardless of the value of
* DLT_C_HDLC.
*
* The name DLT_C_HDLC was used by BSD/OS; we use that name for source
* compatibility with programs written for BSD/OS.
*
* libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
* for source compatibility with programs written for libpcap 0.5.
*/
#define DLT_C_HDLC 104 /* Cisco HDLC */
#define DLT_CHDLC DLT_C_HDLC
/*
* Reserved for future use.
* Do not pick other numerical value for these unless you have also
* picked up the tcpdump.org top-of-CVS-tree version of "savefile.c",
* which will arrange that capture files for these DLT_ types have
* the same "network" value on all platforms, regardless of what
* value is chosen for their DLT_ type (thus allowing captures made
* on one platform to be read on other platforms, even if the two
* platforms don't use the same numerical values for all DLT_ types).
*/
#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
/*
* Values between 106 and 107 are used in capture file headers as
* link-layer types corresponding to DLT_ types that might differ
* between platforms; don't use those values for new DLT_ new types.
*/
/*
* OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
* that the AF_ type in the link-layer header is in network byte order.
*
* OpenBSD defines it as 12, but that collides with DLT_RAW, so we
* define it as 108 here. If OpenBSD picks up this file, it should
* define DLT_LOOP as 12 in its version, as per the comment above -
* and should not use 108 for any purpose.
*/
#define DLT_LOOP 108
/*
* Values between 109 and 112 are used in capture file headers as
* link-layer types corresponding to DLT_ types that might differ
* between platforms; don't use those values for new DLT_ new types.
*/
/*
* This is for Linux cooked sockets.
*/
#define DLT_LINUX_SLL 113
/*
* The instruction encodings.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
#define BPF_LDX 0x01
#define BPF_ST 0x02
#define BPF_STX 0x03
#define BPF_ALU 0x04
#define BPF_JMP 0x05
#define BPF_RET 0x06
#define BPF_MISC 0x07
/* ld/ldx fields */
#define BPF_SIZE(code) ((code) & 0x18)
#define BPF_W 0x00
#define BPF_H 0x08
#define BPF_B 0x10
#define BPF_MODE(code) ((code) & 0xe0)
#define BPF_IMM 0x00
#define BPF_ABS 0x20
#define BPF_IND 0x40
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
/* alu/jmp fields */
#define BPF_OP(code) ((code) & 0xf0)
#define BPF_ADD 0x00
#define BPF_SUB 0x10
#define BPF_MUL 0x20
#define BPF_DIV 0x30
#define BPF_OR 0x40
#define BPF_AND 0x50
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
#define BPF_SRC(code) ((code) & 0x08)
#define BPF_K 0x00
#define BPF_X 0x08
/* ret - BPF_K and BPF_X also apply */
#define BPF_RVAL(code) ((code) & 0x18)
#define BPF_A 0x10
/* misc */
#define BPF_MISCOP(code) ((code) & 0xf8)
#define BPF_TAX 0x00
#define BPF_TXA 0x80
/* TME instructions */
#define BPF_TME 0x08
#define BPF_LOOKUP 0x90
#define BPF_EXECUTE 0xa0
#define BPF_INIT 0xb0
#define BPF_VALIDATE 0xc0
#define BPF_SET_ACTIVE 0xd0
#define BPF_RESET 0xe0
#define BPF_SET_MEMORY 0x80
#define BPF_GET_REGISTER_VALUE 0x70
#define BPF_SET_REGISTER_VALUE 0x60
#define BPF_SET_WORKING 0x50
#define BPF_SET_ACTIVE_READ 0x40
#define BPF_SET_AUTODELETION 0x30
#define BPF_SEPARATION 0xff
#define BPF_MEM_EX_IMM 0xc0
#define BPF_MEM_EX_IND 0xe0
/*used for ST */
#define BPF_MEM_EX 0xc0
/*
* Macros for insn array initializers.
*/
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
#ifdef __cplusplus
extern "C"
{
#endif
/*!
\brief Validates a filtering program arriving from the user-level app.
\param f The filter.
\param len Its length, in pseudo instructions.
\param mem_ex_size The length of the extended memory, used to validate LD/ST to that memory
\return true if f is a valid filter program..
The kernel needs to be able to verify an application's filter code. Otherwise, a bogus program could easily
crash the system.
This function returns true if f is a valid filter program. The constraints are that each jump be forward and
to a valid code. The code must terminate with either an accept or reject.
*/
int32 bpf_validate(struct bpf_insn *f,int32 len, uint32 mem_ex_size);
/*!
\brief The filtering pseudo-machine interpreter.
\param pc The filter.
\param p Pointer to a memory buffer containing the packet on which the filter will be executed.
\param wirelen Original length of the packet.
\param buflen Current length of the packet. In some cases (for example when the transfer of the packet to the RAM
has not yet finished), bpf_filter can be executed on a portion of the packet.
\param mem_ex The extended memory.
\param tme The virtualization of the TME co-processor
\param time_ref Data structure needed by the TME co-processor to timestamp data
\return The portion of the packet to keep, in bytes. 0 means that the packet must be rejected, -1 means that
the whole packet must be kept.
\note this function is not used in normal situations, because the jitter creates a native filtering function
that is faster than the interpreter.
*/
u_int bpf_filter(register struct bpf_insn *pc,
register UCHAR *p,
u_int wirelen,
register u_int buflen ,
PMEM_TYPE mem_ex,
PTME_CORE tme ,
struct time_conv *time_ref);
/*!
\brief The filtering pseudo-machine interpreter with two buffers. This function is slower than bpf_filter(),
but works correctly also if the MAC header and the data of the packet are in two different buffers.
\param pc The filter.
\param p Pointer to a memory buffer containing the MAC header of the packet.
\param pd Pointer to a memory buffer containing the data of the packet.
\param wirelen Original length of the packet.
\param buflen Current length of the packet. In some cases (for example when the transfer of the packet to the RAM
has not yet finished), bpf_filter can be executed on a portion of the packet.
\param mem_ex The extended memory.
\param tme The virtualization of the TME co-processor
\param time_ref Data structure needed by the TME co-processor to timestamp data
\return The portion of the packet to keep, in bytes. 0 means that the packet must be rejected, -1 means that
the whole packet must be kept.
This function is used when NDIS passes the packet to NPF_tap() in two buffers instead than in a single one.
*/
u_int bpf_filter_with_2_buffers(register struct bpf_insn *pc,
register u_char *p,
register u_char *pd,
register int headersize,
u_int wirelen,
register u_int buflen,
PMEM_TYPE mem_ex,
PTME_CORE tme,
struct time_conv *time_ref);
#ifdef __cplusplus
}
#endif
#endif
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /usr/cvsroot_private/winpcap/packetNtx/driver/win_bpf.h,v 1.2.2.1 2005/12/02 22:12:58 gianlucav Exp $ (LBL)
*/
#ifndef BPF_MAJOR_VERSION
/* BSD style release date */
#define BPF_RELEASE 199606
#ifdef WIN_NT_DRIVER
#include <ndis.h>
#endif
#include "tme.h"
#include "time_calls.h"
typedef UCHAR u_char;
typedef USHORT u_short;
#ifdef WIN_NT_DRIVER
typedef ULONG u_int;
#endif
typedef LONG bpf_int32;
typedef ULONG bpf_u_int32;
typedef ULONG u_int32;
#define BPF_MAXINSNS 512
#define BPF_MAXBUFSIZE 0x8000
#define BPF_MINBUFSIZE 32
/*
* The instruction data structure.
*/
struct bpf_insn {
u_short code;
u_char jt;
u_char jf;
bpf_u_int32 k;
};
/*
* Structure for BIOCSETF.
*/
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
/*
* Struct returned by BIOCGSTATS.
*/
struct bpf_stat {
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*
* Struct return by BIOCVERSION. This represents the version number of
* the filter language described by the instruction encodings below.
* bpf understands a program iff kernel_major == filter_major &&
* kernel_minor >= filter_minor, that is, if the value returned by the
* running kernel has the same major number and a minor number equal
* equal to or less than the filter being downloaded. Otherwise, the
* results are undefined, meaning an error may be returned or packets
* may be accepted haphazardly.
* It has nothing to do with the source code version.
*/
struct bpf_version {
u_short bv_major;
u_short bv_minor;
};
/* Current version number of filter architecture. */
#define BPF_MAJOR_VERSION 1
#define BPF_MINOR_VERSION 1
/*
* Structure prepended to each packet.
*/
struct bpf_hdr {
struct timeval bh_tstamp; /* time stamp */
bpf_u_int32 bh_caplen; /* length of captured portion */
bpf_u_int32 bh_datalen; /* original length of packet */
u_short bh_hdrlen; /* length of bpf header (this struct
plus alignment padding) */
};
/*
* Data-link level type codes.
*/
/*
* These are the types that are the same on all platforms; on other
* platforms, a <net/bpf.h> should be supplied that defines the additional
* DLT_* codes appropriately for that platform (the BSDs, for example,
* should not just pick up this version of "bpf.h"; they should also define
* the additional DLT_* codes used by their kernels, as well as the values
* defined here - and, if the values they use for particular DLT_ types
* differ from those here, they should use their values, not the ones
* here).
*/
#define DLT_NULL 0 /* no link-layer encapsulation */
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
#define DLT_AX25 3 /* Amateur Radio AX.25 */
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
#define DLT_CHAOS 5 /* Chaos */
#define DLT_IEEE802 6 /* IEEE 802 Networks */
#define DLT_ARCNET 7 /* ARCNET */
#define DLT_SLIP 8 /* Serial Line IP */
#define DLT_PPP 9 /* Point-to-point Protocol */
#define DLT_FDDI 10 /* FDDI */
/*
* These are values from the traditional libpcap "bpf.h".
* Ports of this to particular platforms should replace these definitions
* with the ones appropriate to that platform, if the values are
* different on that platform.
*/
#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
#define DLT_RAW 12 /* raw IP */
/*
* These are values from BSD/OS's "bpf.h".
* These are not the same as the values from the traditional libpcap
* "bpf.h"; however, these values shouldn't be generated by any
* OS other than BSD/OS, so the correct values to use here are the
* BSD/OS values.
*
* Platforms that have already assigned these values to other
* DLT_ codes, however, should give these codes the values
* from that platform, so that programs that use these codes will
* continue to compile - even though they won't correctly read
* files of these types.
*/
#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
/*
* This value is defined by NetBSD; other platforms should refrain from
* using it for other purposes, so that NetBSD savefiles with a link
* type of 50 can be read as this type on all platforms.
*/
#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
/*
* This value was defined by libpcap 0.5; platforms that have defined
* it with a different value should define it here with that value -
* a link type of 104 in a save file will be mapped to DLT_C_HDLC,
* whatever value that happens to be, so programs will correctly
* handle files with that link type regardless of the value of
* DLT_C_HDLC.
*
* The name DLT_C_HDLC was used by BSD/OS; we use that name for source
* compatibility with programs written for BSD/OS.
*
* libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
* for source compatibility with programs written for libpcap 0.5.
*/
#define DLT_C_HDLC 104 /* Cisco HDLC */
#define DLT_CHDLC DLT_C_HDLC
/*
* Reserved for future use.
* Do not pick other numerical value for these unless you have also
* picked up the tcpdump.org top-of-CVS-tree version of "savefile.c",
* which will arrange that capture files for these DLT_ types have
* the same "network" value on all platforms, regardless of what
* value is chosen for their DLT_ type (thus allowing captures made
* on one platform to be read on other platforms, even if the two
* platforms don't use the same numerical values for all DLT_ types).
*/
#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
/*
* Values between 106 and 107 are used in capture file headers as
* link-layer types corresponding to DLT_ types that might differ
* between platforms; don't use those values for new DLT_ new types.
*/
/*
* OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
* that the AF_ type in the link-layer header is in network byte order.
*
* OpenBSD defines it as 12, but that collides with DLT_RAW, so we
* define it as 108 here. If OpenBSD picks up this file, it should
* define DLT_LOOP as 12 in its version, as per the comment above -
* and should not use 108 for any purpose.
*/
#define DLT_LOOP 108
/*
* Values between 109 and 112 are used in capture file headers as
* link-layer types corresponding to DLT_ types that might differ
* between platforms; don't use those values for new DLT_ new types.
*/
/*
* This is for Linux cooked sockets.
*/
#define DLT_LINUX_SLL 113
/*
* The instruction encodings.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
#define BPF_LDX 0x01
#define BPF_ST 0x02
#define BPF_STX 0x03
#define BPF_ALU 0x04
#define BPF_JMP 0x05
#define BPF_RET 0x06
#define BPF_MISC 0x07
/* ld/ldx fields */
#define BPF_SIZE(code) ((code) & 0x18)
#define BPF_W 0x00
#define BPF_H 0x08
#define BPF_B 0x10
#define BPF_MODE(code) ((code) & 0xe0)
#define BPF_IMM 0x00
#define BPF_ABS 0x20
#define BPF_IND 0x40
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
/* alu/jmp fields */
#define BPF_OP(code) ((code) & 0xf0)
#define BPF_ADD 0x00
#define BPF_SUB 0x10
#define BPF_MUL 0x20
#define BPF_DIV 0x30
#define BPF_OR 0x40
#define BPF_AND 0x50
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
#define BPF_SRC(code) ((code) & 0x08)
#define BPF_K 0x00
#define BPF_X 0x08
/* ret - BPF_K and BPF_X also apply */
#define BPF_RVAL(code) ((code) & 0x18)
#define BPF_A 0x10
/* misc */
#define BPF_MISCOP(code) ((code) & 0xf8)
#define BPF_TAX 0x00
#define BPF_TXA 0x80
/* TME instructions */
#define BPF_TME 0x08
#define BPF_LOOKUP 0x90
#define BPF_EXECUTE 0xa0
#define BPF_INIT 0xb0
#define BPF_VALIDATE 0xc0
#define BPF_SET_ACTIVE 0xd0
#define BPF_RESET 0xe0
#define BPF_SET_MEMORY 0x80
#define BPF_GET_REGISTER_VALUE 0x70
#define BPF_SET_REGISTER_VALUE 0x60
#define BPF_SET_WORKING 0x50
#define BPF_SET_ACTIVE_READ 0x40
#define BPF_SET_AUTODELETION 0x30
#define BPF_SEPARATION 0xff
#define BPF_MEM_EX_IMM 0xc0
#define BPF_MEM_EX_IND 0xe0
/*used for ST */
#define BPF_MEM_EX 0xc0
/*
* Macros for insn array initializers.
*/
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
#ifdef __cplusplus
extern "C"
{
#endif
/*!
\brief Validates a filtering program arriving from the user-level app.
\param f The filter.
\param len Its length, in pseudo instructions.
\param mem_ex_size The length of the extended memory, used to validate LD/ST to that memory
\return true if f is a valid filter program..
The kernel needs to be able to verify an application's filter code. Otherwise, a bogus program could easily
crash the system.
This function returns true if f is a valid filter program. The constraints are that each jump be forward and
to a valid code. The code must terminate with either an accept or reject.
*/
int32 bpf_validate(struct bpf_insn *f,int32 len, uint32 mem_ex_size);
/*!
\brief The filtering pseudo-machine interpreter.
\param pc The filter.
\param p Pointer to a memory buffer containing the packet on which the filter will be executed.
\param wirelen Original length of the packet.
\param buflen Current length of the packet. In some cases (for example when the transfer of the packet to the RAM
has not yet finished), bpf_filter can be executed on a portion of the packet.
\param mem_ex The extended memory.
\param tme The virtualization of the TME co-processor
\param time_ref Data structure needed by the TME co-processor to timestamp data
\return The portion of the packet to keep, in bytes. 0 means that the packet must be rejected, -1 means that
the whole packet must be kept.
\note this function is not used in normal situations, because the jitter creates a native filtering function
that is faster than the interpreter.
*/
u_int bpf_filter(register struct bpf_insn *pc,
register UCHAR *p,
u_int wirelen,
register u_int buflen ,
PMEM_TYPE mem_ex,
PTME_CORE tme ,
struct time_conv *time_ref);
/*!
\brief The filtering pseudo-machine interpreter with two buffers. This function is slower than bpf_filter(),
but works correctly also if the MAC header and the data of the packet are in two different buffers.
\param pc The filter.
\param p Pointer to a memory buffer containing the MAC header of the packet.
\param pd Pointer to a memory buffer containing the data of the packet.
\param wirelen Original length of the packet.
\param buflen Current length of the packet. In some cases (for example when the transfer of the packet to the RAM
has not yet finished), bpf_filter can be executed on a portion of the packet.
\param mem_ex The extended memory.
\param tme The virtualization of the TME co-processor
\param time_ref Data structure needed by the TME co-processor to timestamp data
\return The portion of the packet to keep, in bytes. 0 means that the packet must be rejected, -1 means that
the whole packet must be kept.
This function is used when NDIS passes the packet to NPF_tap() in two buffers instead than in a single one.
*/
u_int bpf_filter_with_2_buffers(register struct bpf_insn *pc,
register u_char *p,
register u_char *pd,
register int headersize,
u_int wirelen,
register u_int buflen,
PMEM_TYPE mem_ex,
PTME_CORE tme,
struct time_conv *time_ref);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,50 +1,50 @@
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __FILTER_INIT
#define __FILTER_INIT
#include "tme.h"
#define INIT_OK 1
#define INIT_ERROR 0
#ifdef __cplusplus
extern "C"
{
#endif
uint32 bpf_filter_init(register struct bpf_insn *pc,MEM_TYPE *mem_ex, TME_CORE *tme, struct time_conv *time_ref);
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (c) 2001 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __FILTER_INIT
#define __FILTER_INIT
#include "tme.h"
#define INIT_OK 1
#define INIT_ERROR 0
#ifdef __cplusplus
extern "C"
{
#endif
uint32 bpf_filter_init(register struct bpf_insn *pc,MEM_TYPE *mem_ex, TME_CORE *tme, struct time_conv *time_ref);
#ifdef __cplusplus
}
#endif
#endif