📄 ip_fw_nt.h.svn-base
字号:
#define betoh16(x) (x)
#define betoh32(x) (x)
#define betoh64(x) (x)
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)
#define NTOHL(x) (x)
#define NTOHS(x) (x)
#define HTONL(x) (x)
#define HTONS(x) (x)
#endif
/*
* priorities/facilities are encoded into a single 32-bit quantity, where the
* bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
* (0-big number). Both the priorities and the facilities map roughly
* one-to-one to strings in the syslogd(8) source code. This mapping is
* included in this file.
*
* priorities (these are ordered)
*/
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
/* facility codes */
#define LOG_SECURITY (13<<3) /* security subsystems (firewalling, etc.) */
// Vlad: avoid intrinsic log() from math.h
void log_win32(int, const char *, ...);
#define log log_win32
typedef u_int32_t time_t; // Vlad: using 32-bit time_t (will expire after 19:14:07, January 18, 2038, UTC)
// Vlad: extern time_t time_second;
time_t get_current_time(void);
#define time_second get_current_time()
/*
* flags to malloc.
*/
#define M_WAITOK 0x0000
#define M_NOWAIT 0x0001 /* do not block */
#define M_ZERO 0x0008 /* Vlad: not a original value */
#define M_MAGIC 877983977 /* time when first defined :-) */
struct malloc_type {
// Vlad: ripped
u_long ks_magic; /* if it's not magic, don't touch it */
const char *ks_shortdesc; /* short description */
};
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
struct malloc_type type[1] = { \
{ M_MAGIC, shortdesc } \
}
#define MALLOC_DECLARE(type) \
extern struct malloc_type type[1]
MALLOC_DECLARE(M_TEMP);
void free(void *addr, struct malloc_type *type);
void *malloc(unsigned long size, struct malloc_type *type, int flags);
// Vlad: very nice function to implement :-)
static __inline void
panic(const char *msg)
{
KdPrint(("!!!PANIC!!! %s", msg));
KdBreakPoint();
KeBugCheck(MANUALLY_INITIATED_CRASH); // is this code good enough?
}
/*
* Constants related to network buffer management.
* MCLBYTES must be no larger than the software page size, and,
* on machines that exchange pages of input or output buffers with mbuf
* clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
* of the hardware page size.
*/
#define MSIZE 2048 /* size of an mbuf Vlad: this value depends on what? */
#define MCLSHIFT 11 /* convert bytes to m_buf clusters */
#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
#define MCLOFSET (MCLBYTES - 1) /* offset within a m_buf cluster */
/*
* Mbufs are of a single size, MSIZE (machine/param.h), which
* includes overhead. An mbuf may add a single "mbuf cluster" of size
* MCLBYTES (also in machine/param.h), which has no additional overhead
* and is used instead of the internal data area; this is done when
* at least MINCLSIZE of data must be stored.
*/
#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
/*
* Macros for type conversion
* mtod(m,t) - convert mbuf pointer to data pointer of correct type
*/
#define mtod(m,t) ((t)((m)->m_data))
/* header at beginning of each mbuf: */
struct m_hdr {
struct mbuf *mh_next; /* next buffer in chain */
caddr_t mh_data; /* location of data */
u_int mh_len; /* amount of data in this mbuf */
short mh_flags; /* flags; see below */
// Vlad: ripped
};
/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
int len; /* total packet length */
// Vlad: ripped
};
struct mbuf {
struct m_hdr m_hdr;
union {
struct {
struct pkthdr MH_pkthdr; /* M_PKTHDR set */
union {
// Vlad: ripped
char MH_databuf[MHLEN];
} MH_dat;
} MH;
char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
} M_dat;
};
// Vlad: not all macros
#define m_next m_hdr.mh_next
#define m_len m_hdr.mh_len
#define m_data m_hdr.mh_data
#define m_flags m_hdr.mh_flags
#define m_pkthdr M_dat.MH.MH_pkthdr
#define m_pktdat M_dat.MH.MH_dat.MH_databuf
#define m_dat M_dat.M_databuf
/* mbuf flags */
#define M_PKTHDR 0x0002 /* start of record */
/* mbuf pkthdr flags, also in m_flags */
#define M_BCAST 0x0100 /* send/received as link-level broadcast */
#define M_MCAST 0x0200 /* send/received as link-level multicast */
/* flags to m_get/MGET */
#define M_DONTWAIT M_NOWAIT
#define M_WAIT M_WAITOK
struct mbuf *m_pullup(struct mbuf *, int);
/*
* Structure of a 10Mb/s Ethernet header.
*/
struct ether_header {
u_char ether_dhost[6];
u_char ether_shost[6];
u_short ether_type;
};
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
#define ETHERTYPE_IP 0x0800 /* IP protocol */
#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
u_long random(void);
#define KASSERT(cond, msg) \
do { \
if (!(cond)) { \
KdPrint(msg); \
KdBreakPoint(); \
} \
} while(0)
#define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x)))
#define IN_CLASSD(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \
__IPADDR(0xe0000000))
/* These ones aren't really net and host fields, but routing needn't know. */
#define IN_MULTICAST(i) IN_CLASSD(i)
/*
* Overlay for ip header used by other protocols (tcp, udp).
*/
struct ipovly {
u_char ih_x1[9]; /* (unused) */
u_char ih_pr; /* protocol */
u_short ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
};
// Vlad: void bcopy(const void *, void *, size_t); ???? or memmove() ????
#define bcopy(src, dst, size) memcpy((dst), (src), (size))
// Vlad: void bzero(void *, size_t);
#define bzero(p, size) memset((p), 0, (size))
#include <sys/errno.h>
extern KSPIN_LOCK g_spin_lock;
static __inline int
splimp(void)
{
KIRQL old_irql;
KeAcquireSpinLock(&g_spin_lock, &old_irql);
return (int)old_irql;
}
static __inline void
splx(int s)
{
KeReleaseSpinLock(&g_spin_lock, (KIRQL)s);
}
// Vlad: we don't support dummynet for now (
#define DUMMYNET_LOADED 0
typedef void ip_dn_ruledel_t(void *); /* ip_fw.c */
extern int securelevel; /* system security level (see init(8)) */
int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
int sooptcopyout(struct sockopt *sopt, void *buf, size_t len);
typedef PDRIVER_OBJECT module_t; // good?
#define MOD_LOAD 1
#define MOD_UNLOAD 2
typedef int modevent_t(module_t mod, int type, void *unused);
typedef struct moduledata {
char *name;
modevent_t *modevent;
int unknown;
} moduledata_t;
#define DECLARE_MODULE(a, b, c, d) struct moduledata *module_##a = &b;
#if DBG
# define printf DbgPrint
#else
# define printf
#endif
#define SYSCTL_NODE(parent, nbr, name, access, handler, descr)
#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
int *_fw_##name = ptr;
static int fw_enable;
/* Vlad: due to missing reverse function of RtlNtStatusToDosError() define NTSTATUS equialents directly */
#define ENOSPC STATUS_INSUFFICIENT_RESOURCES /* No space left on device (Vlad: on malloc() fail) */
#define EINVAL STATUS_INVALID_PARAMETER /* Invalid argument */
#define EPERM STATUS_ACCESS_DENIED /* Operation not permitted */
#define ENOBUFS STATUS_INSUFFICIENT_RESOURCES /* No buffer space available (Vlad: on malloc() fail inside spinlock) */
#define EEXIST STATUS_OBJECT_NAME_EXISTS /* File exists */
// Vlad: struct sockopt moved out to wipfw.h
#include "wipfw.h"
void ip_fw_nt_init(void);
#endif /* _ip_fw_nt_h_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -