From 6dfed60dddb3518080a08a9618888af85f0770ab Mon Sep 17 00:00:00 2001 From: lijia Date: Thu, 25 Oct 2018 13:02:50 +0800 Subject: 清理源码中无用的.a, .so, 废弃的.c文件 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gnu_c.def | 1253 -------------------- gnu_cpp.def | 140 --- inner_plug/Makefile | 7 - inner_plug/afh_common.c | 23 - inner_plug/afh_inner.h | 226 ---- inner_plug/anti_flood_hijack.c | 873 -------------- inner_plug/anti_flood_hijack.h | 87 -- inner_plug/anti_flood_plug.c | 64 - packet_io/cycle_pkt_dump_pipe.c.bak | 556 --------- packet_io/cycle_pkt_dump_through_write.c.bak | 975 --------------- packet_io/cycle_pkt_dump_unix.c.bak | 677 ----------- packet_io/pkt_dispatch.c_BAK | 553 --------- packet_io/pkt_dispatch_new.BAK | 89 -- plugin/lib/plugctrl.a | Bin 88678 -> 0 bytes project/project_special_manage.c_BAK | 184 --- splint.sh | 3 - support/MESA_socket_wrap/lib/libMESA_socket_wrap.a | Bin 45920 -> 0 bytes 17 files changed, 5710 deletions(-) delete mode 100644 gnu_c.def delete mode 100644 gnu_cpp.def delete mode 100644 inner_plug/afh_common.c delete mode 100644 inner_plug/afh_inner.h delete mode 100644 inner_plug/anti_flood_hijack.c delete mode 100644 inner_plug/anti_flood_hijack.h delete mode 100644 inner_plug/anti_flood_plug.c delete mode 100644 packet_io/cycle_pkt_dump_pipe.c.bak delete mode 100644 packet_io/cycle_pkt_dump_through_write.c.bak delete mode 100644 packet_io/cycle_pkt_dump_unix.c.bak delete mode 100644 packet_io/pkt_dispatch.c_BAK delete mode 100644 packet_io/pkt_dispatch_new.BAK delete mode 100644 plugin/lib/plugctrl.a delete mode 100644 project/project_special_manage.c_BAK delete mode 100644 splint.sh delete mode 100644 support/MESA_socket_wrap/lib/libMESA_socket_wrap.a diff --git a/gnu_c.def b/gnu_c.def deleted file mode 100644 index 4226c5f..0000000 --- a/gnu_c.def +++ /dev/null @@ -1,1253 +0,0 @@ -#define TCPOLEN_TIMESTAMP 10 -#define TCP_KEEPCNT 6 -#define _IO_CURRENTLY_PUTTING 0x800 -#define IP_UNBLOCK_SOURCE 37 -#define IPV6_RTHDR_TYPE_0 0 -#define IPV6_2292HOPOPTS 3 -#define __DBL_MIN_EXP__ (-1021) -#define AF_LLC PF_LLC -#define IPV4_FRAG_MEM_HIGH_THRESH (64 * 1024 * 1024) -#define AF_MAX PF_MAX -#define TCP_CONGESTION 13 -#define IPOPT_SECUR_CONFID 0xf135 -#define UDP_MORE_STATE 2 -#define IP_FRAG_DISCARD (0x08) -#define IP_ROUTER_ALERT 5 -#define CMSG_NXTHDR(mhdr,cmsg) __cmsg_nxthdr (mhdr, cmsg) -#define TCPOPT_WINDOW 3 -#define IP_DEFAULT_MULTICAST_TTL 1 -#define TCP_CTEAT_LINK_BYDATA 0x02 -#define __FLT_MIN__ 1.17549435e-38F -#define __NFDBITS (8 * (int) sizeof (__fd_mask)) -#define _IO_UNITBUF 020000 -#define __bswap_16(x) (__extension__ ({ register unsigned short int __v, __x = (unsigned short int) (x); if (__builtin_constant_p (__x)) __v = __bswap_constant_16 (__x); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) -#define _T_WCHAR_ -#define SOL_ATM 264 -#define _G_HAVE_LONG_DOUBLE_IO 1 -#define INT_LEAST16_MIN (-32767-1) -#define TCP_CORK 3 -#define SO_KEEPALIVE 9 -#define _NETINET_IN_H 1 -#define __flexarr [] -#define PF_IRDA 23 -#define IP_DF 0x4000 -#define _IO_FLAGS2_USER_WBUF 8 -#define __S64_TYPE long int -#define IP_TOS 1 -#define __bswap_32(x) (__extension__ ({ register unsigned int __v, __x = (x); if (__builtin_constant_p (__x)) __v = __bswap_constant_32 (__x); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; })) -#define __stub_fchflags -#define __SQUAD_TYPE long int -#define _BSD_SIZE_T_DEFINED_ -#define _BITS_TIME_H 1 -#define TCP_FLOOD_DETECT_OFF 0x0 -#define __socklen_t_defined -#define MAXTTL 255 -#define CLOCK_THREAD_CPUTIME_ID 3 -#define IPTOS_PREC_CRITIC_ECP IPTOS_CLASS_CS5 -#define __TIME_T_TYPE __SLONGWORD_TYPE -#define __CHAR_BIT__ 8 -#define SO_DOMAIN 39 -#define IPV6_LEAVE_GROUP 21 -#define _G_HAVE_MREMAP 1 -#define makedev(maj,min) gnu_dev_makedev (maj, min) -#define FIOGETOWN 0x8903 -#define IP_HDRINCL 3 -#define __bswap_64(x) (__extension__ ({ register unsigned long __v, __x = (x); if (__builtin_constant_p (__x)) __v = __bswap_constant_64 (__x); else __asm__ ("bswap %q0" : "=r" (__v) : "0" (__x)); __v; })) -#define SOCK_RAW SOCK_RAW -#define INT16_C(c) c -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define __sigset_t_defined -#define __SIZEOF_PTHREAD_ATTR_T 56 -#define IPV4_LOCAL_CLASS_B(_add) (((_add&0xFFF00000)==0xAC100000)?1:0) -#define _G_OPEN64 __open64 -#define IP_TTL 2 -#define INT8_MAX (127) -#define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615)) -#define stderr stderr -#define __GLIBC_PREREQ(maj,min) ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min)) -#define IPOPT_OPTVAL 0 -#define SOCK_RDM SOCK_RDM -#define ITIMER_VIRTUAL ITIMER_VIRTUAL -#define PF_DECnet 12 -#define IPV6_CHECKSUM 7 -#define __stub_putmsg -#define IP_MAX_MEMBERSHIPS 20 -#define _G_pid_t __pid_t -#define IPV6_PMTUDISC_WANT 1 -#define __WCHAR_MAX__ 2147483647 -#define AF_APPLETALK PF_APPLETALK -#define SINGLE_ACK_RECEVED_NO 0 -#define __WAIT_INT(status) (__extension__ (((union { __typeof(status) __in; int __i; }) { .__in = (status) }).__i)) -#define INT16_MAX (32767) -#define IPV6_NEXTHOP 9 -#define __BLKCNT_T_TYPE __SLONGWORD_TYPE -#define _BITS_SOCKADDR_H 1 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 -#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 -#define IPPROTO_ROUTING IPPROTO_ROUTING -#define SO_PEERCRED 17 -#define IPOPT_SECUR_MMMM 0xbc4d -#define MCAST_LEAVE_SOURCE_GROUP 47 -#define _IO_flockfile(_fp) -#define _IOFBF 0 -#define __USE_BSD 1 -#define IPV6_IPSEC_POLICY 34 -#define __FLT_EVAL_METHOD__ 0 -#define TCPI_OPT_TIMESTAMPS 1 -#define _IO_NO_WRITES 8 -#define __ASMNAME2(prefix,cname) __STRING (prefix) cname -#define __unix__ 1 -#define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE) -#define IPV6_PMTUDISC_PROBE 3 -#define IPOPT_TIMESTAMP IPOPT_TS -#define IP_FREEBIND 15 -#define __stub_setlogin -#define _IO_peekc_unlocked(_fp) (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) && __underflow (_fp) == EOF ? EOF : *(unsigned char *) (_fp)->_IO_read_ptr) -#define w_termsig __wait_terminated.__w_termsig -#define __FLOAT_WORD_ORDER __BYTE_ORDER -#define INT8_MIN (-128) -#define __x86_64 1 -#define IN6_ARE_ADDR_EQUAL(a,b) ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3])) -#define IPOPT_OLEN 1 -#define MCAST_LEAVE_GROUP 45 -#define IPOPT_CONTROL 0x00 -#define __COMPAR_FN_T -#define __GID_T_TYPE __U32_TYPE -#define _IO_BAD_SEEN 0x4000 -#define __DBL_MIN_10_EXP__ (-307) -#define INT16_MIN (-32767-1) -#define IPOPT_SECURITY 130 -#define __FINITE_MATH_ONLY__ 0 -#define __id_t_defined -#define UINTMAX_C(c) c ## UL -#define _G_HAVE_SYS_WAIT 1 -#define __u_char_defined -#define SOL_PACKET 263 -#define IPOPT_RESERVED1 0x20 -#define IPOPT_RESERVED2 0x60 -#define __pid_t_defined -#define __GNUC_PATCHLEVEL__ 6 -#define IPV6_HOPOPTS 54 -#define _G_size_t size_t -#define SO_SECURITY_AUTHENTICATION 22 -#define SCM_SRCRT IPV6_RXSRCRT -#define _IO_pid_t _G_pid_t -#define IPTOS_ECN_MASK 0x03 -#define MSG_NOSIGNAL MSG_NOSIGNAL -#define __LDBL_REDIR1(name,proto,alias) name proto -#define MSG_MORE MSG_MORE -#define MSG_WAITALL MSG_WAITALL -#define _G_off_t __off_t -#define __size_t -#define IPTOS_ECN_CE 0x03 -#define INT_FAST8_MAX (127) -#define __DEC64_MAX_EXP__ 385 -#define _WCHAR_T_DEFINED -#define __SIZEOF_PTHREAD_CONDATTR_T 4 -#define WCHAR_MAX __WCHAR_MAX -#define _SYS_TIME_H 1 -#define MSG_PEEK MSG_PEEK -#define IP_MSFILTER_SIZE(numsrc) (sizeof (struct ip_msfilter) - sizeof (struct in_addr) + (numsrc) * sizeof (struct in_addr)) -#define _IO_FLAGS2_MMAP 1 -#define htobe16(x) __bswap_16 (x) -#define IN_CLASSB_NSHIFT 16 -#define __always_inline __inline __attribute__ ((__always_inline__)) -#define NFDBITS __NFDBITS -#define __SHRT_MAX__ 32767 -#define w_stopval __wait_stopped.__w_stopval -#define __LDBL_MAX__ 1.18973149535723176502e+4932L -#define TCPI_OPT_ECN 8 -#define IPOPT_NUMBER_MASK 0x1f -#define IP_MSS 576 -#define MAX_TCP_STATE 3 -#define SOL_IPV6 41 -#define __daddr_t_defined -#define IP_MTU 14 -#define _PARAMS(protos) __P(protos) -#define AF_ROSE PF_ROSE -#define _IOS_BIN 128 -#define SOCK_DCCP SOCK_DCCP -#define __mbstate_t_defined 1 -#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) -#define _IO_UNIFIED_JUMPTABLES 1 -#define PF_SECURITY 14 -#define IP_MF 0x2000 -#define IPV6_2292DSTOPTS 4 -#define htobe64(x) __bswap_64 (x) -#define __UINTMAX_TYPE__ long unsigned int -#define _G_ssize_t __ssize_t -#define INT_FAST8_MIN (-128) -#define CLOCK_MONOTONIC_COARSE 6 -#define __SOCKADDR_COMMON(sa_prefix) sa_family_t sa_prefix ##family -#define __linux 1 -#define __DEC32_EPSILON__ 1E-6DF -#define WCHAR_MIN __WCHAR_MIN -#define __stub_sigreturn -#define _BITS_TYPES_H 1 -#define _IO_cleanup_region_end(_Doit) -#define _IO_DONT_CLOSE 0100000 -#define PF_BLUETOOTH 31 -#define __unix 1 -#define __UID_T_TYPE __U32_TYPE -#define getc(_fp) _IO_getc (_fp) -#define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC -#define __SIZE_T -#define MSG_ERRQUEUE MSG_ERRQUEUE -#define FD_SETSIZE __FD_SETSIZE -#define __LDBL_MAX_EXP__ 16384 -#define SOL_TCP 6 -#define PF_SNA 22 -#define _ATFILE_SOURCE 1 -#define PF_WANPIPE 25 -#define _NETINET_IN_SYSTM_H 1 -#define STREAM_LINK_CLOSE 3 -#define UINT_FAST16_MAX (18446744073709551615UL) -#define _IO_ssize_t _G_ssize_t -#define MSG_FIN MSG_FIN -#define PF_IEEE802154 36 -#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 -#define __linux__ 1 -#define UINT16_C(c) c -#define IPTOS_DSCP_AF23 0x58 -#define AF_NETROM PF_NETROM -#define _IOS_OUTPUT 2 -#define IPTOS_MINCOST IPTOS_LOWCOST -#define EXIT_FAILURE 1 -#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } -#define TCP_NOUSE_STATE 2 -#define _SIZE_T_DEFINED_ -#define IPV6_MTU_DISCOVER 23 -#define TCP_SYN_STATE 0 -#define __LDBL_REDIR_NTH(name,proto) name proto __THROW -#define AF_FILE PF_FILE -#define __SCHAR_MAX__ 127 -#define __USING_NAMESPACE_STD(name) -#define SO_REUSEADDR 2 -#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT -#define __KERNEL_STRICT_NAMES -#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_)) -#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) -#define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status)) -#define __INT64_C(c) c ## L -#define __NTH(fct) __attribute__ ((__nothrow__)) fct -#define __DBL_DIG__ 15 -#define SOL_X25 262 -#define SO_DEBUG 1 -#define SO_BINDTODEVICE 25 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define AF_TIPC PF_TIPC -#define IN6_IS_ADDR_UNSPECIFIED(a) (((__const uint32_t *) (a))[0] == 0 && ((__const uint32_t *) (a))[1] == 0 && ((__const uint32_t *) (a))[2] == 0 && ((__const uint32_t *) (a))[3] == 0) -#define _G_MMAP64 __mmap64 -#define _POSIX_SOURCE 1 -#define UIO_MAXIOV 1024 -#define __SIZEOF_INT__ 4 -#define __SIZEOF_POINTER__ 8 -#define _G_uid_t __uid_t -#define SO_MARK 36 -#define __attribute_used__ __attribute__ ((__used__)) -#define _STDIO_USES_IOSTREAM -#define FIOSETOWN 0x8901 -#define _IO_IN_BACKUP 0x100 -#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff) -#define CLOCK_REALTIME 0 -#define _ARPA_INET_H 1 -#define IPPROTO_EGP IPPROTO_EGP -#define __USER_LABEL_PREFIX__ -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) -#define IPV6_AUTHHDR 10 -#define __GLIBC__ 2 -#define __END_DECLS -#define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int)) -#define __CONCAT(x,y) x ## y -#define WCONTINUED 8 -#define SINGLE_ACK_RECEVED 1 -#define UINT8_MAX (255) -#define __STDC_HOSTED__ 1 -#define __WAIT_STATUS_DEFN int * -#define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 -#define __LDBL_HAS_INFINITY__ 1 -#define __SLONG32_TYPE int -#define SOCK_SEQPACKET SOCK_SEQPACKET -#define _SYS_SELECT_H 1 -#define _IO_LINE_BUF 0x200 -#define _IOS_NOCREATE 32 -#define AF_ATMPVC PF_ATMPVC -#define AF_PHONET PF_PHONET -#define UINT64_MAX (__UINT64_C(18446744073709551615)) -#define IP_IPSEC_POLICY 16 -#define IPPROTO_PIM IPPROTO_PIM -#define __GNU_LIBRARY__ 6 -#define AF_INET6 PF_INET6 -#define _G_BUFSIZ 8192 -#define H_COMPAT__H -#define __FLT_EPSILON__ 1.19209290e-7F -#define _G_HAVE_BOOL 1 -#define _IO_EOF_SEEN 0x10 -#define AF_WANPIPE PF_WANPIPE -#define PF_LLC 26 -#define _IO_USER_LOCK 0x8000 -#define SO_LINGER 13 -#define s6_addr16 __in6_u.__u6_addr16 -#define _STDIO_H 1 -#define SO_BROADCAST 6 -#define TMP_MAX 238328 -#define __SSIZE_T_TYPE __SWORD_TYPE -#define PF_UNIX PF_LOCAL -#define __DEV_T_TYPE __UQUAD_TYPE -#define IPVERSION 4 -#define IPTOS_DSCP_AF31 0x68 -#define IPV6_DSTOPTS 59 -#define IPTOS_DSCP_AF32 0x70 -#define _IO_SCIENTIFIC 04000 -#define IPPROTO_ENCAP IPPROTO_ENCAP -#define __LDBL_MIN__ 3.36210314311209350626e-4932L -#define AF_UNSPEC PF_UNSPEC -#define s6_addr32 __in6_u.__u6_addr32 -#define _SS_SIZE 128 -#define __BITS_SOCKET_H -#define le32toh(x) (x) -#define __DEC32_MAX__ 9.999999E96DF -#define _IO_SHOWPOS 02000 -#define PF_ASH 18 -#define UINT64_C(c) c ## UL -#define __WCOREDUMP(status) ((status) & __WCOREFLAG) -#define _WCHAR_T_ -#define IPPROTO_ESP IPPROTO_ESP -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) -#define SO_ACCEPTCONN 30 -#define __SIZEOF_PTHREAD_COND_T 48 -#define AF_BRIDGE PF_BRIDGE -#define IP_FRAG_IGNORE (0x04) -#define __SIZEOF_LONG__ 8 -#define _IO_getc_unlocked(_fp) (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++) -#define __STDC_IEC_559__ 1 -#define SO_TYPE 3 -#define __STDC_ISO_10646__ 200009L -#define PF_NETLINK 16 -#define SCM_RIGHTS SCM_RIGHTS -#define IP_MULTICAST_LOOP 34 -#define __SIZEOF_PTHREAD_BARRIER_T 32 -#define _IO_PENDING_OUTPUT_COUNT(_fp) ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) -#define __DECIMAL_DIG__ 21 -#define __USE_FORTIFY_LEVEL 0 -#define AF_CAN PF_CAN -#define SOCK_PACKET SOCK_PACKET -#define TCPOPT_MAXSEG 2 -#define __gnu_linux__ 1 -#define _ENDIAN_H 1 -#define INT_FAST16_MAX (9223372036854775807L) -#define SOL_IP 0 -#define IPPROTO_PUP IPPROTO_PUP -#define __attribute_warn_unused_result__ __attribute__ ((__warn_unused_result__)) -#define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status)) -#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) -#define PTRDIFF_MAX (9223372036854775807L) -#define _IO_LEFT 02 -#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } -#define IP_ORIGDSTADDR 20 -#define __LDBL_HAS_QUIET_NAN__ 1 -#define INT64_C(c) c ## L -#define IPOPT_DEBMEAS 0x40 -#define SOL_ICMPV6 58 -#define IPPROTO_IDP IPPROTO_IDP -#define IPOPT_TS_TSONLY 0 -#define __THROW __attribute__ ((__nothrow__)) -#define __SOCKADDR_ARG struct sockaddr *__restrict -#define IPTOS_ECN_NOT_ECT 0x00 -#define htobe32(x) __bswap_32 (x) -#define AF_BLUETOOTH PF_BLUETOOTH -#define IPPROTO_IPIP IPPROTO_IPIP -#define __GLIBC_HAVE_LONG_LONG 1 -#define L_tmpnam 20 -#define ___int_wchar_t_h -#define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status)) -#define __GNUC__ 4 -#define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) -#define __MMX__ 1 -#define IPPROTO_TCP IPPROTO_TCP -#define IPV6_2292PKTOPTIONS 6 -#define DROP 0x00 -#define IN6_IS_ADDR_LINKLOCAL(a) ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000)) -#define __timespec_defined 1 -#define L_ctermid 9 -#define __OFF64_T_TYPE __SQUAD_TYPE -#define PF_ISDN 34 -#define FD_SET(fd,fdsetp) __FD_SET (fd, fdsetp) -#define __FLT_HAS_DENORM__ 1 -#define __SIZEOF_LONG_DOUBLE__ 16 -#define IN_CLASSA_NSHIFT 24 -#define __USE_SVID 1 -#define INT_FAST16_MIN (-9223372036854775807L-1) -#define MSG_CTRUNC MSG_CTRUNC -#define _IO_va_list __gnuc_va_list -#define MSG_PROXY MSG_PROXY -#define __LDBL_REDIR1_NTH(name,proto,alias) name proto __THROW -#define __BIGGEST_ALIGNMENT__ 16 -#define MCAST_MSFILTER 48 -#define __FDELT(d) ((d) / __NFDBITS) -#define _SYS_SOCKET_H 1 -#define PTRDIFF_MIN (-9223372036854775807L-1) -#define AF_ROUTE PF_ROUTE -#define IPV6_RECVHOPOPTS 53 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define __USE_ISOC95 1 -#define _TIME_H 1 -#define __USE_ISOC99 1 -#define _G_wint_t wint_t -#define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) -#define MSG_DONTROUTE MSG_DONTROUTE -#define IPTOS_CLASS_CS0 0x00 -#define IPTOS_CLASS_CS1 0x20 -#define IPTOS_CLASS_CS2 0x40 -#define IPTOS_CLASS_CS3 0x60 -#define IPTOS_CLASS_CS4 0x80 -#define IPTOS_CLASS_CS5 0xa0 -#define IPTOS_CLASS_CS6 0xc0 -#define IPTOS_CLASS_CS7 0xe0 -#define IPOPT_SECUR_EFTO 0x789a -#define _IO_uid_t _G_uid_t -#define AF_SECURITY PF_SECURITY -#define EXIT_SUCCESS 0 -#define __DBL_MAX__ 1.7976931348623157e+308 -#define TCP_QUICKACK 12 -#define __DBL_HAS_INFINITY__ 1 -#define __SIZEOF_PTHREAD_MUTEX_T 40 -#define IP_MTU_DISCOVER 10 -#define ITIMER_PROF ITIMER_PROF -#define IP_MINTTL 21 -#define IPOPT_MINOFF 4 -#define __intN_t(N,MODE) typedef int int ##N ##_t __attribute__ ((__mode__ (MODE))) -#define __SIZEOF_PTHREAD_RWLOCK_T 56 -#define stdin stdin -#define __USE_XOPEN2K 1 -#define w_stopsig __wait_stopped.__w_stopsig -#define STREAM_LINK_LRU_OUT 6 -#define __DEC32_MIN_EXP__ (-94) -#define __DADDR_T_TYPE __S32_TYPE -#define __END_NAMESPACE_C99 -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define AF_NETLINK PF_NETLINK -#define TCP_MSS 512 -#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) -#define IN6_IS_ADDR_MC_SITELOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5)) -#define IPPROTO_IPV6 IPPROTO_IPV6 -#define __FD_SETSIZE 1024 -#define IPTOS_PREC_IMMEDIATE IPTOS_CLASS_CS2 -#define be32toh(x) __bswap_32 (x) -#define __attribute_format_strfmon__(a,b) __attribute__ ((__format__ (__strfmon__, a, b))) -#define _IO_MAGIC 0xFBAD0000 -#define IPPROTO_SCTP IPPROTO_SCTP -#define INET_ADDRSTRLEN 16 -#define _SIZE_T_DEFINED -#define SO_SECURITY_ENCRYPTION_NETWORK 24 -#define _WCHAR_T_DEFINED_ -#define _G_LSEEK64 __lseek64 -#define UINT_LEAST8_MAX (255) -#define __USE_POSIX199506 1 -#define _FEATURES_H 1 -#define _G_FSTAT64(fd,buf) __fxstat64 (_STAT_VER, fd, buf) -#define __LDBL_HAS_DENORM__ 1 -#define __stub_getmsg -#define _IO_FIXED 010000 -#define __stub_fattach -#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL -#define _STRUCT_TIMEVAL 1 -#define _IO_UNBUFFERED 2 -#define _IO_pos_t _G_fpos_t -#define _IO_INTERNAL 010 -#define __DEC32_MIN__ 1E-95DF -#define __dev_t_defined -#define __S32_TYPE int -#define IP_PKTOPTIONS 9 -#define SO_DONTROUTE 5 -#define __DBL_MAX_EXP__ 1024 -#define SOL_SOCKET 1 -#define __WORDSIZE_COMPAT32 1 -#define SO_PEERNAME 28 -#define _BITS_WCHAR_H 1 -#define IP_RECVERR 11 -#define __DEC128_EPSILON__ 1E-33DL -#define _G_VTABLE_LABEL_PREFIX_ID __vt_ -#define __SSE2_MATH__ 1 -#define __FSFILCNT_T_TYPE __ULONGWORD_TYPE -#define PDP_ENDIAN __PDP_ENDIAN -#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) -#define STREAM_LINK_REUSE_BYSYN 0 -#define __amd64 1 -#define _IO_LINKED 0x80 -#define _G_HAVE_IO_GETLINE_INFO 1 -#define MCAST_INCLUDE 1 -#define IPPROTO_RSVP IPPROTO_RSVP -#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE -#define IPV6_UNICAST_HOPS 16 -#define __bounded -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define PF_PHONET 35 -#define __USECONDS_T_TYPE __U32_TYPE -#define TCP_DEFER_ACCEPT 9 -#define IPOPT_NOP 1 -#define __BEGIN_NAMESPACE_STD -#define __OFF_T_TYPE __SLONGWORD_TYPE -#define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) -#define IP_PMTUDISC_PROBE 3 -#define __WIFSIGNALED(status) (((signed char) (((status) & 0x7f) + 1) >> 1) > 0) -#define MAX_IPOPTLEN 40 -#define SO_ATTACH_FILTER 26 -#define SO_PASSCRED 16 -#define MCAST_EXCLUDE 0 -#define TCP_KEEPIDLE 4 -#define _T_WCHAR -#define AF_AX25 PF_AX25 -#define __LONG_LONG_MAX__ 9223372036854775807LL -#define AF_RDS PF_RDS -#define IPPROTO_AH IPPROTO_AH -#define __SIZEOF_SIZE_T__ 8 -#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) -#define _WCHAR_T -#define IPOPT_MEASUREMENT IPOPT_DEBMEAS -#define _IO_BOOLALPHA 0200000 -#define __FD_ZERO(fdsp) do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " __FD_ZERO_STOS : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&__FDS_BITS (fdsp)[0]) : "memory"); } while (0) -#define SOL_DECNET 261 -#define SIZE_MAX (18446744073709551615UL) -#define __SIZEOF_WINT_T__ 4 -#define __stub_bdflush -#define IPV6_ROUTER_ALERT 22 -#define _G_VTABLE_LABEL_PREFIX "__vt_" -#define MSG_WAITFORONE MSG_WAITFORONE -#define PF_UNSPEC 0 -#define __u_intN_t(N,MODE) typedef unsigned int u_int ##N ##_t __attribute__ ((__mode__ (MODE))) -#define INT32_MIN (-2147483647-1) -#define _IONBF 2 -#define IP_FRAG_FIRST_IN (0x02) -#define IN6_IS_ADDR_MC_ORGLOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8)) -#define __U16_TYPE unsigned short int -#define TCPOPT_SACK 5 -#define _GCC_WCHAR_T -#define WINT_MAX (4294967295u) -#define SIOCATMARK 0x8905 -#define _IO_HEX 0100 -#define IP_FRAG_LAST_IN (0x01) -#define UINTPTR_MAX (18446744073709551615UL) -#define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) -#define SO_PASSSEC 34 -#define PF_X25 9 -#define __GCC_HAVE_DWARF2_CFI_ASM 1 -#define __ptrvalue -#define _G_HAVE_IO_FILE_OPEN 1 -#define __GXX_ABI_VERSION 1002 -#define __isleap(year) ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) -#define __FLT_MIN_EXP__ (-125) -#define PF_BRIDGE 7 -#define IP_PMTUDISC_DONT 0 -#define __FD_CLR(d,set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d)) -#define WEXITED 4 -#define IPV6_V6ONLY 26 -#define ITIMER_REAL ITIMER_REAL -#define AF_PPPOX PF_PPPOX -#define UINT32_MAX (4294967295U) -#define IPV6_RECVRTHDR 56 -#define alloca(size) __builtin_alloca (size) -#define IP_MULTICAST_ALL 49 -#define PF_IPX 4 -#define __extern_always_inline extern __always_inline __attribute__ ((__artificial__)) -#define IPV6_RECVHOPLIMIT 51 -#define _G_off64_t __off64_t -#define IPV6_RECVTCLASS 66 -#define __DBL_MIN__ 2.2250738585072014e-308 -#define WINT_MIN (0u) -#define __key_t_defined -#define _IO_MAGIC_MASK 0xFFFF0000 -#define IPV6_MTU 24 -#define SO_RCVLOWAT 18 -#define IPV6_RECVDSTOPTS 58 -#define __LITTLE_ENDIAN 1234 -#define IPPROTO_MTP IPPROTO_MTP -#define CLOCK_REALTIME_COARSE 5 -#define __WCOREFLAG 0x80 -#define TCP_MD5SIG_MAXKEYLEN 80 -#define IPOPT_SATID 136 -#define __REDIRECT(name,proto,alias) name proto __asm__ (__ASMNAME (#alias)) -#define __LP64__ 1 -#define IPTOS_PREC_MASK IPTOS_CLASS_MASK -#define __ASM_GENERIC_SOCKET_H -#define _IO_off64_t _G_off64_t -#define IPV6_MULTICAST_IF 17 -#define __WTERMSIG(status) ((status) & 0x7f) -#define SO_SNDTIMEO 21 -#define __MODE_T_TYPE __U32_TYPE -#define __nonnull(params) __attribute__ ((__nonnull__ params)) -#define __DECIMAL_BID_FORMAT__ 1 -#define SHUT_RDWR SHUT_RDWR -#define IPV6_RECVERR 25 -#define __RLIM64_T_TYPE __UQUAD_TYPE -#define PF_MAX 37 -#define IPTOS_PREC_PRIORITY IPTOS_CLASS_CS1 -#define _IOS_ATEND 4 -#define INT_LEAST8_MAX (127) -#define IP_RECVTOS 13 -#define SO_PEERSEC 31 -#define TCPOPT_EOL 0 -#define IP_RF 0x8000 -#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) -#define IPPROTO_TP IPPROTO_TP -#define __FDS_BITS(set) ((set)->__fds_bits) -#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) -#define IP_OFFMASK 0x1fff -#define PROJECT_REQ_MAX_PLUG_NUM (16) -#define SO_PROTOCOL 38 -#define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS)) -#define IPV6_RXDSTOPTS IPV6_DSTOPTS -#define __DEC128_MIN__ 1E-6143DL -#define __REGISTER_PREFIX__ -#define _IOS_NOREPLACE 64 -#define __DBL_HAS_DENORM__ 1 -#define INT_LEAST32_MAX (2147483647) -#define AF_KEY PF_KEY -#define PF_ROSE 11 -#define _IO_TIED_PUT_GET 0x400 -#define __attribute_pure__ __attribute__ ((__pure__)) -#define IPTOS_RELIABILITY 0x04 -#define PF_INET6 10 -#define __USE_POSIX2 1 -#define IP_TRANSPARENT 19 -#define __SLONGWORD_TYPE long int -#define IP_RECVTTL 12 -#define __REDIRECT_LDBL(name,proto,alias) __REDIRECT (name, proto, alias) -#define __NO_INLINE__ 1 -#define MSG_RST MSG_RST -#define __warndecl(name,msg) extern void name (void) __attribute__((__warning__ (msg))) -#define _SYS_UIO_H 1 -#define IPV6_2292PKTINFO 2 -#define __FLT_MANT_DIG__ 24 -#define AF_IUCV PF_IUCV -#define INT_LEAST8_MIN (-128) -#define __VERSION__ "4.4.6 20120305 (Red Hat 4.4.6-4)" -#define TCPOLEN_WINDOW 3 -#define FD_ZERO(fdsetp) __FD_ZERO (fdsetp) -#define UINT_LEAST16_MAX (65535) -#define IP_PKTINFO 8 -#define __UINT64_C(c) c ## UL -#define _SYS_CDEFS_H 1 -#define IPTOS_DSCP_EF 0xb8 -#define TCP_MAX_WINSHIFT 14 -#define INT_LEAST32_MIN (-2147483647-1) -#define __PTHREAD_MUTEX_HAVE_PREV 1 -#define __INT_WCHAR_T_H -#define _IO_file_flags _flags -#define _G_USING_THUNKS 1 -#define __USE_XOPEN2K8 1 -#define _ALLOCA_H 1 -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) -#define SOCK_DGRAM SOCK_DGRAM -#define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status)) -#define __W_EXITCODE(ret,sig) ((ret) << 8 | (sig)) -#define _BSD_SOURCE 1 -#define __STRING(x) #x -#define SO_OOBINLINE 10 -#define MSG_CONFIRM MSG_CONFIRM -#define AF_ECONET PF_ECONET -#define PF_FILE PF_LOCAL -#define timercmp(a,b,CMP) (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP (b)->tv_usec) : ((a)->tv_sec CMP (b)->tv_sec)) -#define __unbounded -#define INADDR_ANY ((in_addr_t) 0x00000000) -#define __INO_T_TYPE __ULONGWORD_TYPE -#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) -#define IPOPT_SECUR_TOPSECRET 0x6bc5 -#define __ssize_t_defined -#define __GNUC_PREREQ(maj,min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#define IN6_IS_ADDR_V4COMPAT(a) ((((__const uint32_t *) (a))[0] == 0) && (((__const uint32_t *) (a))[1] == 0) && (((__const uint32_t *) (a))[2] == 0) && (ntohl (((__const uint32_t *) (a))[3]) > 1)) -#define IPV6_MULTICAST_HOPS 18 -#define _SYS_SIZE_T_H -#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE -#define IP_PMTUDISC_DO 2 -#define SIOCGPGRP 0x8904 -#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE -#define PF_TIPC 30 -#define __SIZE_T__ -#define __stub_gtty -#define SEEK_CUR 1 -#define __NLINK_T_TYPE __UWORD_TYPE -#define SIG_ATOMIC_MAX (2147483647) -#define __uint32_t_defined -#define __need_clockid_t -#define IP_FRAG_INVALID_PACKET (0x10) -#define IP_PASSSEC 18 -#define __nlink_t_defined -#define PROJECT_CONF_NAME "conf/project_list.conf" -#define _IO_SHOWPOINT 0400 -#define SIOCGSTAMP 0x8906 -#define INT32_MAX (2147483647) -#define _G_config_h 1 -#define __stub_sstk -#define __wur -#define __STDC_IEC_559_COMPLEX__ 1 -#define _G_HAVE_MMAP 1 -#define _G_stat64 stat64 -#define _IO_OCT 040 -#define SO_TIMESTAMPING 37 -#define IPV4_LOCAL_CLASS_A(_add) (((_add&0xFF000000)==0x0A000000)?1:0) -#define SIOCGSTAMPNS 0x8907 -#define IPV4_LOCAL_CLASS_C(_add) (((_add&0xFFFFFF00)==0xC0A80000)?1:0) -#define IN_CLASSB_MAX 65536 -#define __DEC64_EPSILON__ 1E-15DD -#define __DEC128_MIN_EXP__ (-6142) -#define __PDP_ENDIAN 3412 -#define IPTOS_DSCP_AF11 0x28 -#define IPTOS_DSCP_AF12 0x30 -#define IPTOS_DSCP_AF13 0x38 -#define _NETINET_TCP_H 1 -#define IP_ADD_MEMBERSHIP 35 -#define UNORDER_MAX_NUM (tcp_max_unorder) -#define TCPOPT_TIMESTAMP 8 -#define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data) -#define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) -#define IPTOS_DSCP_AF21 0x48 -#define IPTOS_DSCP_AF22 0x50 -#define BYTE_ORDER __BYTE_ORDER -#define s6_addr __in6_u.__u6_addr8 -#define PF_ROUTE PF_NETLINK -#define _BITS_TYPESIZES_H 1 -#define IPV6_HOPLIMIT 52 -#define IPTOS_DSCP_AF33 0x78 -#define SIG_ATOMIC_MIN (-2147483647-1) -#define __WIFEXITED(status) (__WTERMSIG(status) == 0) -#define IPPROTO_UDP IPPROTO_UDP -#define IPTOS_DSCP_AF41 0x88 -#define IPTOS_DSCP_AF42 0x90 -#define IPTOS_DSCP_AF43 0x98 -#define __SWBLK_T_TYPE __SLONGWORD_TYPE -#define RAND_MAX 2147483647 -#define unix 1 -#define IPTOS_PREC_ROUTINE IPTOS_CLASS_CS0 -#define __FD_ZERO_STOS "stosq" -#define _BSD_SIZE_T_ -#define __SIZE_TYPE__ long unsigned int -#define __va_arg_pack_len() __builtin_va_arg_pack_len () -#define __ULONGWORD_TYPE unsigned long int -#define _SIZE_T_DECLARED -#define IPTOS_PREC(tos) IPTOS_CLASS(tos) -#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) -#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) -#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) -#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) -#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) -#define AF_INET PF_INET -#define _IO_SHOWBASE 0200 -#define STREAM_LINK_DATA 2 -#define IPOPT_SECUR_UNCLASS 0x0000 -#define TCPI_OPT_SACK 2 -#define IPTOS_ECN_ECT0 0x02 -#define IPV4_FRAG_MEM_FREE_ONCE (512 * 1024) -#define IPOPT_NOOP IPOPT_NOP -#define IPTOS_LOWDELAY 0x10 -#define __ELF__ 1 -#define IPOPT_TS_TSANDADDR 1 -#define IPV6_PMTUDISC_DO 2 -#define IPDEFTTL 64 -#define IPV6_PKTINFO 50 -#define _SIGSET_H_types 1 -#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) -#define _BITS_BYTESWAP_H 1 -#define __ID_T_TYPE __U32_TYPE -#define IPV4_FRAG_TIMEOUT (30) -#define STREAM_LINK_RESET 4 -#define __warnattr(msg) __attribute__((__warning__ (msg))) -#define _IO_funlockfile(_fp) -#define SOL_RAW 255 -#define IPTOS_LOWCOST 0x02 -#define __FLT_RADIX__ 2 -#define SOL_IRDA 266 -#define __LDBL_EPSILON__ 1.08420217248550443401e-19L -#define INTPTR_MAX (9223372036854775807L) -#define IPTOS_PREC_INTERNETCONTROL IPTOS_CLASS_CS6 -#define __GNUC_RH_RELEASE__ 4 -#define minor(dev) gnu_dev_minor (dev) -#define _POSIX_C_SOURCE 200809L -#define TCP_SYNCNT 7 -#define IP_MULTICAST_IF 32 -#define IP_DROP_MEMBERSHIP 36 -#define IPOPT_TS_PRESPEC 3 -#define _G_IO_IO_FILE_VERSION 0x20001 -#define IN6_IS_ADDR_V4MAPPED(a) ((((__const uint32_t *) (a))[0] == 0) && (((__const uint32_t *) (a))[1] == 0) && (((__const uint32_t *) (a))[2] == htonl (0xffff))) -#define __SSE_MATH__ 1 -#define __long_double_t long double -#define AF_ATMSVC PF_ATMSVC -#define __uid_t_defined -#define __k8 1 -#define SO_SNDBUFFORCE 32 -#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 -#define __LDBL_REDIR(name,proto) name proto -#define CLOCK_MONOTONIC_RAW 4 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define MSG_TRUNC MSG_TRUNC -#define IPTOS_DSCP_MASK 0xfc -#define IPTOS_CLASS_MASK 0xe0 -#define MAX_THREAD_NUM 64 -#define __blksize_t_defined -#define INT_LEAST64_MAX (__INT64_C(9223372036854775807)) -#define _IO_IS_FILEBUF 0x2000 -#define __bswap_constant_16(x) ((unsigned short int) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))) -#define PF_NETBEUI 13 -#define IPPROTO_IP IPPROTO_IP -#define AF_PACKET PF_PACKET -#define __WCHAR_MAX (2147483647) -#define _G_ARGS(ARGLIST) ARGLIST -#define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) -#define __SIZEOF_PTRDIFF_T__ 8 -#define SEEK_SET 0 -#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) -#define IP_PMTUDISC_WANT 1 -#define IP_XFRM_POLICY 17 -#define AF_IEEE802154 PF_IEEE802154 -#define __NETINET_IP_H 1 -#define __bswap_constant_32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) -#define _IO_FLAGS2_NOTCANCEL 2 -#define IN_CLASSA_MAX 128 -#define SO_TIMESTAMP 29 -#define __errordecl(name,msg) extern void name (void) __attribute__((__error__ (msg))) -#define IPOPT_SECUR_SECRET 0xd788 -#define SO_DETACH_FILTER 27 -#define __restrict_arr __restrict -#define INTPTR_MIN (-9223372036854775807L-1) -#define INT8_C(c) c -#define _G_wchar_t wchar_t -#define IP_MSFILTER 41 -#define __USE_MISC 1 -#define __UWORD_TYPE unsigned long int -#define IP_BLOCK_SOURCE 38 -#define WNOHANG 1 -#define IN6_IS_ADDR_LOOPBACK(a) (((__const uint32_t *) (a))[0] == 0 && ((__const uint32_t *) (a))[1] == 0 && ((__const uint32_t *) (a))[2] == 0 && ((__const uint32_t *) (a))[3] == htonl (1)) -#define __x86_64__ 1 -#define _SIZE_T_ -#define __bswap_constant_64(x) ((((x) & 0xff00000000000000ull) >> 56) | (((x) & 0x00ff000000000000ull) >> 40) | (((x) & 0x0000ff0000000000ull) >> 24) | (((x) & 0x000000ff00000000ull) >> 8) | (((x) & 0x00000000ff000000ull) << 8) | (((x) & 0x0000000000ff0000ull) << 24) | (((x) & 0x000000000000ff00ull) << 40) | (((x) & 0x00000000000000ffull) << 56)) -#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF -#define _IO_iconv_t _G_iconv_t -#define _IO_USER_BUF 1 -#define UINT_FAST32_MAX (18446744073709551615UL) -#define _WCHAR_T_H -#define IP_RETOPTS 7 -#define __stub_revoke -#define __timer_t_defined 1 -#define MSG_OOB MSG_OOB -#define __WCLONE 0x80000000 -#define IP_FRAG_OK (0x00) -#define IPFRAGTTL 60 -#define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1) -#define major(dev) gnu_dev_major (dev) -#define IPTOS_PREC_FLASH IPTOS_CLASS_CS3 -#define _IO_off_t _G_off_t -#define __WCHAR_MIN (-2147483647 - 1) -#define SIOCSPGRP 0x8902 -#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) -#define SO_BSDCOMPAT 14 -#define __U64_TYPE unsigned long int -#define IPV6_RTHDRDSTOPTS 55 -#define __FLT_HAS_QUIET_NAN__ 1 -#define IP_RECVOPTS 6 -#define UINTMAX_MAX (__UINT64_C(18446744073709551615)) -#define INT32_C(c) c -#define __FLT_MAX_10_EXP__ 38 -#define __LONG_MAX__ 9223372036854775807L -#define __WCHAR_T__ -#define IP_MULTICAST_TTL 33 -#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL -#define IPOPT_COPY 0x80 -#define __FLT_HAS_INFINITY__ 1 -#define SO_SNDBUF 7 -#define __WSTOPSIG(status) __WEXITSTATUS(status) -#define IPV6_JOIN_ANYCAST 27 -#define MCAST_UNBLOCK_SOURCE 44 -#define IPV6_TCLASS 67 -#define MCAST_JOIN_SOURCE_GROUP 46 -#define __LONG_LONG_PAIR(HI,LO) LO, HI -#define __bos0(ptr) __builtin_object_size (ptr, 0) -#define __DEC64_MAX__ 9.999999999999999E384DD -#define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status)) -#define NULL ((void *)0) -#define AF_IRDA PF_IRDA -#define __CHAR16_TYPE__ short unsigned int -#define __ss_aligntype unsigned long int -#define __USING_NAMESPACE_C99(name) -#define BIG_ENDIAN __BIG_ENDIAN -#define IPTOS_TOS_MASK 0x1E -#define PF_PPPOX 24 -#define STREAM_LINK_TIMEOUT 5 -#define _VA_LIST_DEFINED -#define __BLKSIZE_T_TYPE __SLONGWORD_TYPE -#define PF_ECONET 19 -#define _IO_size_t _G_size_t -#define __stub_lchmod -#define __DEC64_MANT_DIG__ 16 -#define AF_RXRPC PF_RXRPC -#define IPV6_XFRM_POLICY 35 -#define IPOPT_SECUR_RESTR 0xaf13 -#define IN6_IS_ADDR_MC_NODELOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1)) -#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS -#define MAX_UDP_STATE 3 -#define SOCK_NONBLOCK SOCK_NONBLOCK -#define INT64_MAX (__INT64_C(9223372036854775807)) -#define htole16(x) (x) -#define __DEC32_MAX_EXP__ 97 -#define _SIZET_ -#define TIMER_ABSTIME 1 -#define htole32(x) (x) -#define __PMT(args) args -#define TCP_MAXSEG 2 -#define _SYS_TYPES_H 1 -#define AF_NETBEUI PF_NETBEUI -#define IPV6_2292RTHDR 5 -#define SO_TIMESTAMPNS 35 -#define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status)) -#define _OLD_STDIO_MAGIC 0xFABC0000 -#define AF_SNA PF_SNA -#define linux 1 -#define _IOS_APPEND 8 -#define IPOPT_SSRR 137 -#define CLOCK_MONOTONIC 1 -#define IPV6_RTHDR_LOOSE 0 -#define __int8_t_defined -#define IPOPT_CLASS_MASK 0x60 -#define ____FILE_defined 1 -#define _IOLBF 1 -#define htole64(x) (x) -#define IPOPT_SEC IPOPT_SECURITY -#define IPV6_ADDRFORM 1 -#define IPV4_MULTICAST_ADDR(_add) (((_add&0xF0000000)==0xE0000000)?1:0) -#define _IO_UPPERCASE 01000 -#define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status)) -#define MCAST_JOIN_GROUP 42 -#define _XLOCALE_H 1 -#define INET6_ADDRSTRLEN 46 -#define __SSE2__ 1 -#define __KEY_T_TYPE __S32_TYPE -#define TCP_DATAFLOOD_DETECT_ON 0x02 -#define PF_CAN 29 -#define __WORDSIZE 64 -#define INT64_MIN (-__INT64_C(9223372036854775807)-1) -#define __BEGIN_DECLS -#define __LDBL_MANT_DIG__ 64 -#define _G_NEED_STDARG_H 1 -#define __USE_ANSI 1 -#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 -#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) -#define __DBL_HAS_QUIET_NAN__ 1 -#define IPOPT_SID IPOPT_SATID -#define IPV6_JOIN_GROUP 20 -#define _STRING_H 1 -#define __GNUC_VA_LIST -#define TCP_CTEAT_LINK_BYSYN 0x01 -#define WSTOPPED 2 -#define TCPOLEN_SACK_PERMITTED 2 -#define __RLIM_T_TYPE __ULONGWORD_TYPE -#define le64toh(x) (x) -#define PF_AX25 3 -#define FILENAME_MAX 4096 -#define IPPROTO_RAW IPPROTO_RAW -#define __ino_t_defined -#define AF_LOCAL PF_LOCAL -#define __k8__ 1 -#define __WCHAR_TYPE__ int -#define __CLOCKID_T_TYPE __S32_TYPE -#define IPV4_FRAG_NUM_PER_IPQ (100) -#define __SIZEOF_FLOAT__ 4 -#define _IOS_TRUNC 16 -#define IPTTLDEC 1 -#define __HAVE_COLUMN -#define IPPROTO_ICMP IPPROTO_ICMP -#define __stub_fdetach -#define __DEC64_MIN_EXP__ (-382) -#define __stub_chflags -#define putc(_ch,_fp) _IO_putc (_ch, _fp) -#define __UQUAD_TYPE unsigned long int -#define __BYTE_ORDER __LITTLE_ENDIAN -#define __USE_POSIX 1 -#define IPTOS_ECN_ECT1 0x01 -#define TCPOLEN_MAXSEG 4 -#define SCM_TIMESTAMPING SO_TIMESTAMPING -#define BUFSIZ _IO_BUFSIZ -#define __FLT_DIG__ 6 -#define __FSID_T_TYPE struct { int __val[2]; } -#define _DEAL_IPV4_H_ -#define __malloc_and_calloc_defined -#define INT_FAST32_MAX (9223372036854775807L) -#define _WCHAR_T_DECLARED -#define _IO_putc_unlocked(_ch,_fp) (_IO_BE ((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end, 0) ? __overflow (_fp, (unsigned char) (_ch)) : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) -#define WNOWAIT 0x01000000 -#define TCP_DATA_STATE 1 -#define __LDBL_REDIR_DECL(name) -#define UINT_FAST8_MAX (255) -#define __INT_MAX__ 2147483647 -#define w_retcode __wait_terminated.__w_retcode -#define __amd64__ 1 -#define w_coredump __wait_terminated.__w_coredump -#define __S16_TYPE short int -#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT -#define IPV6_RTHDR 57 -#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) -#define SOCK_CLOEXEC SOCK_CLOEXEC -#define _G_HAVE_ATEXIT 1 -#define _T_SIZE_ -#define IPv4_FRAG_CE 0x8000 -#define IN6_IS_ADDR_MC_LINKLOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2)) -#define PF_ATMSVC 20 -#define IN_CLASSC_NET 0xffffff00 -#define IP_MAXPACKET 65535 -#define __FD_SET(d,set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d)) -#define __WNOTHREAD 0x20000000 -#define _G_va_list __gnuc_va_list -#define _IOS_INPUT 1 -#define __FLT_MAX_EXP__ 128 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define __gid_t_defined -#define IN_LOOPBACKNET 127 -#define UINT32_C(c) c ## U -#define __ptr_t void * -#define __DBL_MANT_DIG__ 53 -#define ___int_size_t_h -#define __TIMER_T_TYPE void * -#define IPv4_FRAG_OFFSET 0x1FFF -#define PF_PACKET 17 -#define MSG_SYN MSG_SYN -#define __WIFCONTINUED(status) ((status) == __W_CONTINUED) -#define UINT_FAST64_MAX (__UINT64_C(18446744073709551615)) -#define __clock_t_defined 1 -#define INT_FAST32_MIN (-9223372036854775807L-1) -#define __GLIBC_MINOR__ 12 -#define __DEC64_MIN__ 1E-383DD -#define __WINT_TYPE__ unsigned int -#define __SIZEOF_SHORT__ 2 -#define __SSE__ 1 -#define AF_ASH PF_ASH -#define IPPROTO_GRE IPPROTO_GRE -#define __intptr_t_defined -#define __LDBL_MIN_EXP__ (-16381) -#define IPTOS_CLASS(class) ((tos) & IPTOS_CLASS_MASK) -#define UDP_TWO_STATE 1 -#define __BIT_TYPES_DEFINED__ 1 -#define IPV6_RECVPKTINFO 49 -#define stdout stdout -#define IP_OPTIONS 4 -#define IN6_IS_ADDR_MC_GLOBAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe)) -#define EOF (-1) -#define __extern_inline extern __inline -#define __USE_POSIX199309 1 -#define SO_RCVBUF 8 -#define IPTOS_THROUGHPUT 0x08 -#define TCP_WINDOW_CLAMP 10 -#define SO_RCVBUFFORCE 33 -#define __BLKCNT64_T_TYPE __SQUAD_TYPE -#define TCP_MAXWIN 65535 -#define __LDBL_MAX_10_EXP__ 4932 -#define IP_PMTUDISC 10 -#define __FSBLKCNT_T_TYPE __ULONGWORD_TYPE -#define __DBL_EPSILON__ 2.2204460492503131e-16 -#define IPv4_FRAG_MF 0x2000 -#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS -#define le16toh(x) (x) -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define _SVID_SOURCE 1 -#define _LP64 1 -#define __REDIRECT_NTH_LDBL(name,proto,alias) __REDIRECT_NTH (name, proto, alias) -#define TCP_KEEPINTVL 5 -#define __CONST_SOCKADDR_ARG __const struct sockaddr * -#define INADDR_NONE ((in_addr_t) 0xffffffff) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define IPPROTO_NONE IPPROTO_NONE -#define _G_HAVE_SYS_CDEFS 1 -#define __stub_stty -#define __ASM_GENERIC_SOCKIOS_H -#define __wchar_t__ -#define UDP_ONE_STATE 0 -#define SO_RXQ_OVFL 40 -#define SEEK_END 2 -#define __SIZEOF_WCHAR_T__ 4 -#define __USE_POSIX_IMPLICITLY 1 -#define __REDIRECT_NTH(name,proto,alias) name proto __asm__ (__ASMNAME (#alias)) __THROW -#define MSG_DONTWAIT MSG_DONTWAIT -#define _IO_RIGHT 04 -#define __END_NAMESPACE_STD -#define TCPOPT_TSTAMP_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) -#define MB_CUR_MAX (__ctype_get_mb_cur_max ()) -#define be64toh(x) __bswap_64 (x) -#define IPPROTO_IGMP IPPROTO_IGMP -#define TCP_INFO 11 -#define PF_IUCV 32 -#define PF_RDS 21 -#define __PID_T_TYPE __S32_TYPE -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IN_CLASSB_NET 0xffff0000 -#define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype))) -#define P_tmpdir "/tmp" -#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_)) -#define INTMAX_MAX (__INT64_C(9223372036854775807)) -#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) -#define _IO_cleanup_region_start(_fct,_fp) -#define _IO_NO_READS 4 -#define _IO_DEC 020 -#define IPOPT_RA 148 -#define IPOPT_RR 7 -#define CLOCKS_PER_SEC 1000000l -#define __DEC_EVAL_METHOD__ 2 -#define _SIZE_T -#define _IO_ERR_SEEN 0x20 -#define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f) -#define __ULONG32_TYPE unsigned int -#define IN6_IS_ADDR_SITELOCAL(a) ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfec00000)) -#define SOCK_STREAM SOCK_STREAM -#define FOPEN_MAX 16 -#define __BIG_ENDIAN 4321 -#define __suseconds_t_defined -#define IPOPT_TS 68 -#define __W_STOPCODE(sig) ((sig) << 8 | 0x7f) -#define IPPROTO_ICMPV6 IPPROTO_ICMPV6 -#define UINT16_MAX (65535) -#define _IO_STDIO 040000 -#define __off_t_defined -#define _IO_IS_APPENDING 0x1000 -#define TCP_LINGER2 8 -#define __mode_t_defined -#define _GCC_SIZE_T -#define __INO64_T_TYPE __UQUAD_TYPE -#define __W_CONTINUED 0xffff -#define __INTMAX_MAX__ 9223372036854775807L -#define SO_NO_CHECK 11 -#define __size_t__ -#define _IO_BUFSIZ _G_BUFSIZ -#define __FLT_DENORM_MIN__ 1.40129846e-45F -#define _IO_DELETE_DONT_CLOSE 0x40 -#define TCP_MD5SIG 14 -#define INTMAX_MIN (-__INT64_C(9223372036854775807)-1) -#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) -#define __BEGIN_NAMESPACE_C99 -#define AF_UNIX PF_UNIX -#define IP_RECVRETOPTS IP_RETOPTS -#define TCPOPT_SACK_PERMITTED 4 -#define IPPROTO_COMP IPPROTO_COMP -#define AF_DECnet PF_DECnet -#define FD_ISSET(fd,fdsetp) __FD_ISSET (fd, fdsetp) -#define _IO_fpos_t _G_fpos_t -#define __CHAR32_TYPE__ unsigned int -#define _IO_STDIO_H -#define __FLT_MAX__ 3.40282347e+38F -#define __fsfilcnt_t_defined -#define __blkcnt_t_defined -#define INT_FAST64_MAX (__INT64_C(9223372036854775807)) -#define UINT_LEAST32_MAX (4294967295U) -#define SO_SNDLOWAT 19 -#define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))) -#define __lldiv_t_defined 1 -#define _IO_SKIPWS 01 -#define SO_ERROR 4 -#define MSG_EOR MSG_EOR -#define IPOPT_END IPOPT_EOL -#define WUNTRACED 2 -#define __SIZEOF_DOUBLE__ 8 -#define __FLT_MIN_10_EXP__ (-37) -#define __time_t_defined 1 -#define _SYS_SYSMACROS_H 1 -#define _IO_BE(expr,res) __builtin_expect ((expr), res) -#define IN_MULTICAST(a) IN_CLASSD(a) -#define PF_APPLETALK 5 -#define IPOPT_EOL 0 -#define __SWORD_TYPE long int -#define __INTMAX_TYPE__ long int -#define IPPROTO_DCCP IPPROTO_DCCP -#define be16toh(x) __bswap_16 (x) -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define _G_HAVE_PRINTF_FP 1 -#define MCAST_BLOCK_SOURCE 43 -#define __DEC128_MAX_EXP__ 6145 -#define IN_CLASSA_NET 0xff000000 -#define _T_SIZE -#define UINT8_C(c) c -#define __va_arg_pack() __builtin_va_arg_pack () -#define GROUP_FILTER_SIZE(numsrc) (sizeof (struct group_filter) - sizeof (struct sockaddr_storage) + ((numsrc) * sizeof (struct sockaddr_storage))) -#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_)) -#define __GNUC_MINOR__ 4 -#define PF_KEY 15 -#define __DEC32_MANT_DIG__ 7 -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define TCPI_OPT_WSCALE 4 -#define INTMAX_C(c) c ## L -#define PF_NETROM 6 -#define PF_INET 2 -#define TCPOPT_NOP 1 -#define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1) -#define _STDINT_H 1 -#define TCP_SYNFLOOD_DETECT_ON 0x01 -#define __DBL_MAX_10_EXP__ 308 -#define __FILE_defined 1 -#define IN_CLASSC_NSHIFT 8 -#define _BITS_PTHREADTYPES_H 1 -#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L -#define PASS 0x01 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define PF_RXRPC 33 -#define SOL_AAL 265 -#define timeradd(a,b,result) do { (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; if ((result)->tv_usec >= 1000000) { ++(result)->tv_sec; (result)->tv_usec -= 1000000; } } while (0) -#define FD_CLR(fd,fdsetp) __FD_CLR (fd, fdsetp) -#define timersub(a,b,result) do { (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; if ((result)->tv_usec < 0) { --(result)->tv_sec; (result)->tv_usec += 1000000; } } while (0) -#define __STDC__ 1 -#define __attribute_malloc__ __attribute__ ((__malloc__)) -#define __PTRDIFF_TYPE__ long int -#define IPV4_DEBUG (0) -#define IPv4_HDR_MAX_LEN (60) -#define SOMAXCONN 128 -#define AF_ISDN PF_ISDN -#define __clockid_t_defined 1 -#define __attribute_noinline__ __attribute__ ((__noinline__)) -#define PF_ATMPVC 8 -#define IPV6_MULTICAST_LOOP 19 -#define IPTOS_PREC_NETCONTROL IPTOS_CLASS_CS7 -#define IPV6_2292HOPLIMIT 8 -#define __CLOCK_T_TYPE __SLONGWORD_TYPE -#define AF_X25 PF_X25 -#define _IO_fpos64_t _G_fpos64_t -#define IPV6_LEAVE_ANYCAST 28 -#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD -#define __FSFILCNT64_T_TYPE __UQUAD_TYPE -#define SHUT_RD SHUT_RD -#define __DEC128_MANT_DIG__ 34 -#define IPV6_PMTUDISC_DONT 0 -#define __LDBL_MIN_10_EXP__ (-4931) -#define __attribute_deprecated__ __attribute__ ((__deprecated__)) -#define IPV6_RTHDR_STRICT 1 -#define _IO_wint_t _G_wint_t -#define __SIZEOF_LONG_LONG__ 8 -#define AF_IPX PF_IPX -#define __USE_ATFILE 1 -#define _STREAM_MANAGE_H_ -#define IPOPT_OFFSET 2 -#define _IP_REASSEMBLY_H_ -#define SCM_TIMESTAMPNS SO_TIMESTAMPNS -#define __LDBL_DIG__ 18 -#define STREAM_LINK_JUST_EST 1 -#define IPOPT_LSRR 131 -#define __GNUC_GNU_INLINE__ 1 -#define __WALL 0x40000000 -#define __ldiv_t_defined 1 -#define _G_NAMES_HAVE_UNDERSCORE 0 -#define IPOPT_COPIED(o) ((o) & IPOPT_COPY) -#define SHUT_WR SHUT_WR -#define INT_LEAST16_MAX (32767) -#define IPTOS_PREC_FLASHOVERRIDE IPTOS_CLASS_CS4 -#define _IO_ftrylockfile(_fp) -#define __FD_ISSET(d,set) ((__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d)) != 0) -#define SO_PRIORITY 12 -#define SO_RCVTIMEO 20 -#define __P(args) args -#define PF_LOCAL 1 -#define __WCHAR_T -#define __U32_TYPE unsigned int -#define TCP_NODELAY 1 -#define __fsblkcnt_t_defined -#define IPv4_FRAG_DF 0x4000 -#define _BITS_UIO_H 1 -#define _STDLIB_H 1 -#define _IO_peekc(_fp) _IO_peekc_unlocked (_fp) -#define IPPROTO_UDPLITE IPPROTO_UDPLITE -#define _G_VTABLE_LABEL_HAS_LENGTH 1 diff --git a/gnu_cpp.def b/gnu_cpp.def deleted file mode 100644 index 047e94c..0000000 --- a/gnu_cpp.def +++ /dev/null @@ -1,140 +0,0 @@ -#define __DBL_MIN_EXP__ (-1021) -#define __FLT_MIN__ 1.17549435e-38F -#define __CHAR_BIT__ 8 -#define __WCHAR_MAX__ 2147483647 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 -#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 -#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 -#define __FLT_EVAL_METHOD__ 0 -#define __unix__ 1 -#define __x86_64 1 -#define __DBL_MIN_10_EXP__ (-307) -#define __FINITE_MATH_ONLY__ 0 -#define __LP64__ 1 -#define __GNUC_PATCHLEVEL__ 6 -#define __DEC64_MAX_EXP__ 385 -#define __SHRT_MAX__ 32767 -#define __LDBL_MAX__ 1.18973149535723176502e+4932L -#define __UINTMAX_TYPE__ long unsigned int -#define __linux 1 -#define __DEC32_EPSILON__ 1E-6DF -#define __unix 1 -#define __LDBL_MAX_EXP__ 16384 -#define __linux__ 1 -#define __SCHAR_MAX__ 127 -#define __DBL_DIG__ 15 -#define __SIZEOF_INT__ 4 -#define __SIZEOF_POINTER__ 8 -#define __USER_LABEL_PREFIX__ -#define __STDC_HOSTED__ 1 -#define __LDBL_HAS_INFINITY__ 1 -#define __FLT_EPSILON__ 1.19209290e-7F -#define __GXX_WEAK__ 1 -#define __LDBL_MIN__ 3.36210314311209350626e-4932L -#define __DEC32_MAX__ 9.999999E96DF -#define __SIZEOF_LONG__ 8 -#define __DECIMAL_DIG__ 21 -#define __gnu_linux__ 1 -#define __LDBL_HAS_QUIET_NAN__ 1 -#define __GNUC__ 4 -#define __GXX_RTTI 1 -#define __MMX__ 1 -#define __FLT_HAS_DENORM__ 1 -#define __SIZEOF_LONG_DOUBLE__ 16 -#define __BIGGEST_ALIGNMENT__ 16 -#define __DBL_MAX__ 1.7976931348623157e+308 -#define __DBL_HAS_INFINITY__ 1 -#define __DEC32_MIN_EXP__ (-94) -#define __LDBL_HAS_DENORM__ 1 -#define __cplusplus 1 -#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL -#define __DEC32_MIN__ 1E-95DF -#define __DEPRECATED 1 -#define __DBL_MAX_EXP__ 1024 -#define __DEC128_EPSILON__ 1E-33DL -#define __SSE2_MATH__ 1 -#define __amd64 1 -#define __GNUG__ 4 -#define __LONG_LONG_MAX__ 9223372036854775807LL -#define __SIZEOF_SIZE_T__ 8 -#define __SIZEOF_WINT_T__ 4 -#define __GCC_HAVE_DWARF2_CFI_ASM 1 -#define __GXX_ABI_VERSION 1002 -#define __FLT_MIN_EXP__ (-125) -#define __DBL_MIN__ 2.2250738585072014e-308 -#define __FLT_MIN_10_EXP__ (-37) -#define __DECIMAL_BID_FORMAT__ 1 -#define __DEC128_MIN__ 1E-6143DL -#define __REGISTER_PREFIX__ -#define __DBL_HAS_DENORM__ 1 -#define __NO_INLINE__ 1 -#define __FLT_MANT_DIG__ 24 -#define __VERSION__ "4.4.6 20120305 (Red Hat 4.4.6-4)" -#define __DEC64_EPSILON__ 1E-15DD -#define __DEC128_MIN_EXP__ (-6142) -#define unix 1 -#define __SIZE_TYPE__ long unsigned int -#define __ELF__ 1 -#define __FLT_RADIX__ 2 -#define __LDBL_EPSILON__ 1.08420217248550443401e-19L -#define __GNUC_RH_RELEASE__ 4 -#define __k8 1 -#define __SIZEOF_PTRDIFF_T__ 8 -#define __x86_64__ 1 -#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF -#define __FLT_HAS_QUIET_NAN__ 1 -#define __FLT_MAX_10_EXP__ 38 -#define __LONG_MAX__ 9223372036854775807L -#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL -#define __FLT_HAS_INFINITY__ 1 -#define __DEC64_MAX__ 9.999999999999999E384DD -#define __CHAR16_TYPE__ short unsigned int -#define __DEC64_MANT_DIG__ 16 -#define __DEC32_MAX_EXP__ 97 -#define linux 1 -#define __SSE2__ 1 -#define __EXCEPTIONS 1 -#define __LDBL_MANT_DIG__ 64 -#define __DBL_HAS_QUIET_NAN__ 1 -#define __k8__ 1 -#define __WCHAR_TYPE__ int -#define __SIZEOF_FLOAT__ 4 -#define __DEC64_MIN_EXP__ (-382) -#define __FLT_DIG__ 6 -#define __INT_MAX__ 2147483647 -#define __amd64__ 1 -#define __FLT_MAX_EXP__ 128 -#define __DBL_MANT_DIG__ 53 -#define __DEC64_MIN__ 1E-383DD -#define __WINT_TYPE__ unsigned int -#define __SIZEOF_SHORT__ 2 -#define __SSE__ 1 -#define __LDBL_MIN_EXP__ (-16381) -#define __LDBL_MAX_10_EXP__ 4932 -#define __DBL_EPSILON__ 2.2204460492503131e-16 -#define _LP64 1 -#define __SIZEOF_WCHAR_T__ 4 -#define __DEC_EVAL_METHOD__ 2 -#define __INTMAX_MAX__ 9223372036854775807L -#define __FLT_DENORM_MIN__ 1.40129846e-45F -#define __CHAR32_TYPE__ unsigned int -#define __FLT_MAX__ 3.40282347e+38F -#define __SIZEOF_DOUBLE__ 8 -#define __INTMAX_TYPE__ long int -#define __DEC128_MAX_EXP__ 6145 -#define __GNUC_MINOR__ 4 -#define __DEC32_MANT_DIG__ 7 -#define __DBL_MAX_10_EXP__ 308 -#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L -#define __STDC__ 1 -#define __PTRDIFF_TYPE__ long int -#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD -#define __DEC128_MANT_DIG__ 34 -#define __LDBL_MIN_10_EXP__ (-4931) -#define __SSE_MATH__ 1 -#define __SIZEOF_LONG_LONG__ 8 -#define __LDBL_DIG__ 18 -#define __GNUC_GNU_INLINE__ 1 -#define _GNU_SOURCE 1 diff --git a/inner_plug/Makefile b/inner_plug/Makefile index eacde31..b16dbcc 100644 --- a/inner_plug/Makefile +++ b/inner_plug/Makefile @@ -29,7 +29,6 @@ TARGET = isakmp_protocol_plug.so ipsec_biz_sample.so l2tp_protocol_plug.so l2tp_ TARGET += pptp_protocol_plug.so pptp_biz_sample.so TARGET += g_device_plug.so TARGET += libsapp_assistant.so -TARGET += libanti_flood_hijack.so all: $(TARGET) @@ -83,12 +82,6 @@ libsapp_assistant.so: sapp_assistant.c mkdir -p $(RELEASE_PLT_PATH)/sapp_assistant/; cp $@ $(RELEASE_PLT_PATH)/sapp_assistant/sapp_assistant.so -libanti_flood_hijack.so:anti_flood_plug.o anti_flood_hijack.o - $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES); - mkdir -p $(RELEASE_BIZ_PATH)/anti_flood; - cp $@ $(RELEASE_BIZ_PATH)/anti_flood/; - cp $@ /opt/MESA/lib/libanti_flood_hijack.so; - clean: rm -f *.o *.so *.a $(TARGET) diff --git a/inner_plug/afh_common.c b/inner_plug/afh_common.c deleted file mode 100644 index 0ea4a65..0000000 --- a/inner_plug/afh_common.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dictator.h" -#include "afh_inner.h" - -#ifdef __cplusplus -extern "C" { -#endif - - - -#ifdef __cplusplus -} -#endif diff --git a/inner_plug/afh_inner.h b/inner_plug/afh_inner.h deleted file mode 100644 index ca03e62..0000000 --- a/inner_plug/afh_inner.h +++ /dev/null @@ -1,226 +0,0 @@ -#ifndef _AFH_INNER_H_ -#define _AFH_INNER_H_ 1 - -#include -#include -#include -#include -#include "avltree.h" - -#define AFH_DEBUG (1) - -#define SYM_HIDDEN __attribute__((visibility("hidden"))) - -#define AFH_MAX_THREAD_NUM (64) - -/* ȫIPΧΪ42, Ŀ޴, ޷ȫּ. ֻʹضBITλ, - BITλλλ, ǵһ豸ֻͨضεIPͨ, - Ǿ, IPһC, ʹ. - ʵʿܻ, ʹ24bitʱ, 1.2.3.410.2.3.4ΪһIP. -*/ -#define AFH_IP_WHITE_LIST_MASK (0x00FFFFFFU) -#define AFH_IP_WHITE_LIST_MASK_HOST_BIT (24) - -#define AFH_FLOOD_THRESHOLD_UNUSUAL_MULTIPE (2) /* ƽֵ2, ʼJC, ͳ */ - -#define AFH_FLOOD_THRESHOLD_SERIOUS_MULTIPLE (5) /* ƽֵ, ʼ */ - -#define AFH_DNS_DEFAULT_PORT (53) -#define AFH_NTP_DEFAULT_PORT (123) - -#define AFH_REALTIME_SORT_TOPN (7) /* ʵʱTOPN */ - -#ifndef afh_likely -#define afh_likely(x) __builtin_expect(!!(x), 1) -#endif - -#ifndef afh_unlikely -#define afh_unlikely(x) __builtin_expect(!!(x), 0) -#endif - - -enum afh_state_t{ - AFH_STATE_NORMAL = 0, /* */ - AFH_STATE_UNUSUAL = 1, /* 쳣, Գֵ */ - AFH_STATE_SERIOUS = 2, /* , ̬ */ -}; - - -/* - * TCP packet header prototype. - */ -#ifndef TH_FIN -#define TH_FIN 0x01 -#endif -#ifndef TH_SYN -#define TH_SYN 0x02 -#endif -#ifndef TH_RST -#define TH_RST 0x04 -#endif -#ifndef TH_PUSH -#define TH_PUSH 0x08 -#endif -#ifndef TH_ACK -#define TH_ACK 0x10 -#endif -#ifndef TH_URG -#define TH_URG 0x20 -#endif -struct afh_tcphdr -{ - u_int16_t th_sport; /* source port */ - u_int16_t th_dport; /* destination port */ - u_int32_t th_seq; /* sequence number */ - u_int32_t th_ack; /* acknowledgement number */ -#if __BYTE_ORDER == __LITTLE_ENDIAN - u_int8_t th_x2:4, /* (unused) */ - th_off:4; /* data offset */ -#elif __BYTE_ORDER == __BIG_ENDIAN - u_int8_t th_off:4, /* data offset */ - th_x2:4; /* (unused) */ -#else -#error "Please check " -#endif - u_int8_t th_flags; /* control flags */ - u_int16_t th_win; /* window */ - u_int16_t th_sum; /* checksum */ - u_int16_t th_urp; /* urgent pointer */ -}; - -/* - * UDP packet header prototype. - */ -struct afh_udp_hdr -{ - u_int16_t uh_sport; /* soure port */ - u_int16_t uh_dport; /* destination port */ - u_int16_t uh_ulen; /* length */ - u_int16_t uh_sum; /* checksum */ -}; - -struct afh_ip4_hdr -{ -#if __BYTE_ORDER == __LITTLE_ENDIAN - u_int8_t ip_hl:4, /* header length */ - ip_v:4; /* version */ -#elif __BYTE_ORDER == __BIG_ENDIAN - u_int8_t ip_v:4, /* version */ - ip_hl:4; /* header length */ -#else -#error "Please check " -#endif - u_int8_t ip_tos; /* type of service */ - u_int16_t ip_len; /* total length */ - u_int16_t ip_id; /* identification */ -#define AFH_IP_MF 0x2000 /* more fragments flag */ -#define AFH_IP_OFFMASK 0x1fff /* mask for fragmenting bits */ - u_int16_t ip_off; - u_int8_t ip_ttl; /* time to live */ - u_int8_t ip_p; /* protocol */ - u_int16_t ip_sum; /* checksum */ - struct in_addr ip_src, ip_dst; /* source and dest address */ -}; - - -typedef struct{ - struct avl_node avl_node_topN; /* AVLṹ */ - unsigned int dip_net_order; /* ĿIP, IP̫, ʹĿIP */ - unsigned char thread_seq; /* for dictator */ - char __pad; - unsigned short detectd_flood_silent_time; - long long history_cpu_cycle; /* ÿdipʱ, ȫʱ */ - unsigned long long realtime_tot_pkt_num; /* ǰʵʱͳƵİ */ - unsigned long long history_pkt_num; /* һͳڵļ, ںrealtime_tot_pkt_numʵʱPPS */ - unsigned long long anti_flood_drop_pkt; - unsigned long long realtime_pps; /* HTABLEʵʱÿͳ, AVL, ÿ1һ */ -}anti_flood_item_t; - -/* afhȫֱ, ÿ̶߳, ̲߳ʹ, Ҫ֤64ֽCache */ -typedef struct{ - unsigned long long ip_pkt_num; - unsigned long long tcp_pkt_num; - unsigned long long udp_pkt_num; - unsigned long long ip_frag_pkt_num; - unsigned long long tcp_syn_pkt_num; - unsigned long long udp_dns_pkt_num; - unsigned long long udp_ntp_pkt_num; - struct avl_tree avl_tree_topN; - unsigned long long realtime_pps_min_syn_pkt; /* topNСֵ */ - unsigned long long realtime_pps_min_dns_pkt; /* topNСֵ */ - unsigned long long realtime_pps_min_ntp_pkt; /* topNСֵ */ - char __pad[32]; -}afh_thread_variable_t; - - -/* afhȫֱ, ̹ */ -typedef struct{ - /* - ͳƷ: ȫͳ or ߳ͳ, ĿǰȫͳƷʽ. - (1)ÿ̶߳ͳơ - ΪȫSYNֵ, һij߳Ҳֵ, - ֻض߳̿򶪰, Ӱ߳. - DDOS˵, ij߳ҲжDIPĹ, ڷԭ, - ̫, Ǹ̵߳SYNֵ, - ôijЩSYNҲͲᱻ, - ɷЧ̫, ȫSYNֻ70%, 30%û. - - (2)ȫͳ - һȫSYNֵ, а߳̿SYN_floodģʽ, - ֻҪǷDIPsyn, Ҳڰ, , - , ijֻ߳мDIPҲڰSYN, Ҳܱ⵽. - - */ - volatile unsigned char syn_flood_state; - volatile unsigned char dns_flood_state; - volatile unsigned char ntp_flood_state; - volatile unsigned char udp_pkt_state; /* רΪsappƽ̨, ߷ֹUDP, DNS, NTP, ̶߳߳༸, Ҫ */ - - /* - drop_silent_time: - Ĭڼ, PPS, Ҫһʱ - Ҫж>1, ھĬڼ1, ¼PPSǷ񻹳ֵ, - й, ¾Ĭʱ, Լ, - ˶ʮرն, ½Flood1, ּ⵽, ٴζʮĶѭ. - */ - - unsigned char syn_flood_drop_silent_time; - unsigned char dns_flood_drop_silent_time; - unsigned char ntp_flood_drop_silent_time; - unsigned char udp_flood_drop_silent_time; - - double syn_in_tcp_ratio; - double dns_in_udp_ratio; - double ntp_in_udp_ratio; - double udp_in_ip_ratio; - - unsigned char global_default_drop_silent_time; -}afh_global_variable_t; - - -void *afh_malloc(int t_seq,size_t size); -void afh_free(int t_seq,void*p); - -inline long long afh_get_cpu_cycle(void) -{ -#ifdef __x86_64 -#define X86_64_ENV 1 -#endif -#ifdef __x86_64__ -#define X86_64_ENV 1 -#endif - -#ifdef X86_64_ENV - long long l; - long long h; - - __asm__ volatile("rdtsc" : "=a"(l), "=d"(h)); - return (long long )l | ((long long )h<<32); -#else - return 0; -#endif -} - -#endif - - diff --git a/inner_plug/anti_flood_hijack.c b/inner_plug/anti_flood_hijack.c deleted file mode 100644 index 7e93cec..0000000 --- a/inner_plug/anti_flood_hijack.c +++ /dev/null @@ -1,873 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dictator.h" -#include "MESA_handle_logger.h" -#include "MESA_prof_load.h" -#include "MESA_htable.h" -#include "anti_flood_hijack.h" -#include "afh_inner.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define RUN_AS_SAPP_PLUG (1) /* ΪSAPPƽ̨ */ - - -static const struct afh_pkt_check_res g_afh_check_res_normal = {1,0,0,0,0}; /* ޹ĬϷֵ, ȫֱ, ÿֳṹ */ -static const struct afh_pkt_check_res g_afh_check_res_syn_drop = {0,1,2,0,0}; /* SYN FloodĬϷֵ, ȫֱ, ÿֳṹ */ -static const struct afh_pkt_check_res g_afh_check_res_dns_drop = {0,1,3,0,0}; /* DNS FloodĬϷֵ, ȫֱ, ÿֳṹ */ - -static int g_afh_tot_thread_num = 1; -static afh_thread_variable_t *g_afh_thread_status[AFH_MAX_THREAD_NUM]; - -static afh_global_variable_t *g_afh_global_status; - -static unsigned short *g_afh_ip_white_list; /* ΪIPͳ, IP洢ʱҪת */ -static unsigned short g_current_trusted_val = 1; /* ÿg_white_ip_list_intervalһλ */ -static int g_white_ip_list_interval = 10; /* λ: */ - -static time_t g_afh_current_time; -//static int g_afh_global_normal_state = 1; /* ǰϵͳд״̬, FLood */ - -const double g_syn_in_tcp_ratio = 4.0; /* SYNռTCPռ, һΪ4% */ -const double g_dns_in_udp_ratio = 4.0; /* DNSռUDPռ, һΪ4% */ -const double g_ntp_in_udp_ratio = 2.0; /* NTPռUDPռ, һΪ2% */ - -/************************* get from cfg file *************************/ -static int anti_flood_drop_udp_dns_pps_threshold = 1000; /* ijDIP, UDP-DNSPPSֵ */ -static int anti_flood_drop_udp_ntp_pps_threshold = 1000; /* ijDIP, UDP-NTPPPSֵ */ -static int anti_flood_drop_syn_pps_threshold = 10000; /* ijDIP, SYNPPSֵ */ -static int cpu_frequency_in_MHZ = 2200; /* cpuƵ, λ:MHz */ -static long long cpu_cycle_in_1second; /* 1ӵCPUδ */ -static int anti_flood_detectd_flood_silent_time = 30; /* ֹ, Ĭʱ, ʱ, ¼, λ:. */ -//static int avltree_sort_top_N = 32; /* AVL, ౣٸԪ, top-N */ - - -#define ANTI_FLOOD_CFG_FILE "conf/anti_flood.conf" - -//extern int g_packet_io_thread_num; -//static char anti_flood_white_list_bpf_string[1024]; -//static struct bpf_program anti_flood_white_list_bpf_bin[MAX_THREAD_NUM]; -//static pcap_t *static_phony_pcap_handle[MAX_THREAD_NUM]; /* BPFʱʹ */ - -//static volatile int anti_flood_drop_thread_flag[MAX_THREAD_NUM]; - -static void *g_afh_log_handle; - -//static unsigned long long anti_flood_drop_pkt[MAX_THREAD_NUM][COUNTER_NUM]; /* ⵽, */ - -static MESA_htable_handle anti_flood_syn_htable[AFH_MAX_THREAD_NUM]; -static MESA_htable_handle anti_flood_udp_dns_htable[AFH_MAX_THREAD_NUM]; - -/* htableֵ, µĽڵ޷, AVLɾСĽڵ, ٲ! TODO */ -//static struct avl_tree anti_flood_syn_flood_avltree[MAX_THREAD_NUM]; -//static struct avl_tree anti_flood_udp_flood_avltree[MAX_THREAD_NUM]; - - -typedef struct{ - anti_flood_item_t common_st; /* ͨýṹ */ - unsigned char dns_s2c_ttl; /* S2CIP-TTLֵ, һ㲻, ڼǷDNSƭ */ -}anti_flood_udp_dns_item_t; - - -static int anti_flood_key_cmp(const uchar * key1, uint size1, const uchar * key2, uint size2) -{ - const unsigned int *ip1 = (const unsigned int *)key1; - const unsigned int *ip2 = (const unsigned int *)key2; - - return (int)(*ip1 - *ip2); -} - -static void anti_flood_data_free_cb(void *data) -{ - anti_flood_item_t *af_node = (anti_flood_item_t *)data; - afh_thread_variable_t *afh_thread_status = g_afh_thread_status[af_node->thread_seq]; - - if((NULL == af_node->avl_node_topN.parent) || (NULL == af_node->avl_node_topN.left) || (NULL == af_node->avl_node_topN.right)){ - avl_remove(&afh_thread_status->avl_tree_topN, &af_node->avl_node_topN); - } - - memset(af_node, 0, sizeof(anti_flood_item_t)); - - __dictator_free(af_node->thread_seq, data); -} - -static MESA_htable_handle afh_htable_create(void) -{ - MESA_htable_handle htable; - int opt; - - htable = MESA_htable_born(); - - opt = 0; - MESA_htable_set_opt(htable, MHO_THREAD_SAFE, &opt, sizeof(int)); - - opt = 1024 * 1024; - MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, &opt, sizeof(int)); - - opt = 100000; - MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, &opt, sizeof(int)); - - opt = 120; - MESA_htable_set_opt(htable, MHO_EXPIRE_TIME, &opt, sizeof(int)); - - opt = HASH_ELIMINATE_ALGO_LRU; - MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, &opt, sizeof(int)); - - MESA_htable_set_opt(htable, MHO_CBFUN_KEY_COMPARE, (void *)&anti_flood_key_cmp, sizeof(void *)); - - MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE, (void *)&anti_flood_data_free_cb, sizeof(void *)); - - opt = 30; - MESA_htable_set_opt(htable, MHO_HASH_LIST_COLLIDE_THRESHOLD, &opt, sizeof(int)); - - MESA_htable_set_opt(htable, MHO_HASH_LOG_FILE, (void *)"./log/anti_flood_htable.log", strlen("./log/anti_flood_htable.log")); - - opt = 0; - MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, &opt, sizeof(int)); - - MESA_htable_mature(htable); - - return htable; -} - -static int afh_htable_init(void) -{ - int i; - for(i = 0; i < g_afh_tot_thread_num; i++){ - anti_flood_syn_htable[i] = afh_htable_create(); - anti_flood_udp_dns_htable[i] = afh_htable_create(); - } - - return 0; -} - -#if 0 -static int anti_flood_avltree_init(void) -{ - int i; - for(i = 0; i < g_packet_io_thread_num; i++){ - avl_init(&anti_flood_syn_flood_avltree[i], NULL); - avl_init(&anti_flood_udp_flood_avltree[i], NULL); - } - - return 0; -} -#endif - -static void afh_ip_white_ip_list_add(unsigned int sip_net_order) -{ - unsigned int sip_segment_host_order; /* ΪIPͳ, Ҫת */ - -#if 0 - /* 쳣̬° */ - if(afh_unlikely(g_afh_global_normal_state != 1)){ - - return; - } -#endif - - sip_segment_host_order = (ntohl(sip_net_order) & AFH_IP_WHITE_LIST_MASK); - - if(afh_likely((g_afh_ip_white_list[sip_segment_host_order] & g_current_trusted_val) != 0)){ /* ǰʱѼ¼, ٸ, ˴Ӱ, ٶ߳д */ - return; - } - - g_afh_ip_white_list[sip_segment_host_order] |= g_current_trusted_val; - -#if AFH_DEBUG - char ip_str[16]; - inet_ntop(AF_INET, &sip_net_order, ip_str, 16); - MESA_handle_runtime_log(g_afh_log_handle, 10, "AFH", "add ip white list: %s\n", ip_str); -#endif - - return; -} - -static inline void anti_flood_htable_node_init(anti_flood_item_t *af_node, int thread_seq, unsigned int dip, long long cur_cpu_cycle) -{ - memset(af_node, 0, sizeof(anti_flood_item_t)); - af_node->thread_seq = thread_seq; - af_node->history_cpu_cycle = cur_cpu_cycle; - af_node->dip_net_order = dip; - - return; -} - -static inline int anti_flood_item_update_time(anti_flood_item_t *af_node, long long cur_cpu_cycle) -{ - long long pass_time_in_cpu_cycle; - - pass_time_in_cpu_cycle = cur_cpu_cycle - af_node->history_cpu_cycle; - - if(pass_time_in_cpu_cycle >= cpu_cycle_in_1second){ - af_node->history_cpu_cycle = cur_cpu_cycle; - - /* һPPS */ - af_node->realtime_pps = (unsigned int)((double)(af_node->realtime_tot_pkt_num - af_node->history_pkt_num)/(double)(pass_time_in_cpu_cycle/cpu_cycle_in_1second)); - af_node->history_pkt_num = af_node->realtime_tot_pkt_num; - - if(af_node->detectd_flood_silent_time > 0){ - /* ⵽FLOOD, ÿ1ֵݼ1 */ - af_node->detectd_flood_silent_time--; - } - - return 1; - } - - return 0; -} - - -/* TOPNеݹDIP */ -static int avl_check_dip_in_tree_recur(unsigned int dip_net_order, const struct avl_node *avlnode) -{ - const struct avl_node *left, *right; - anti_flood_item_t *cur_node, *af_left_node, *af_right_node; - - if(NULL == avlnode){ - return 0; - } - - cur_node = _get_entry(avlnode, anti_flood_item_t, avl_node_topN); - if(dip_net_order == cur_node->dip_net_order){ - return 1; - } - - left = avlnode->left; - if(left){ - af_left_node = _get_entry(left, anti_flood_item_t, avl_node_topN); - if(dip_net_order == af_left_node->dip_net_order){ - return 1; - }else{ - return avl_check_dip_in_tree_recur(dip_net_order, left); - } - } - - right = avlnode->right; - if(right){ - af_right_node = _get_entry(right, anti_flood_item_t, avl_node_topN); - if(dip_net_order == af_right_node->dip_net_order){ - return 1; - }else{ - return avl_check_dip_in_tree_recur(dip_net_order, right); - } - } - - return 0; -} - -static int afh_check_dip_is_syn_topN(unsigned int dip_net_order, int thread_seq) -{ - afh_thread_variable_t *afh_thread_status = g_afh_thread_status[thread_seq]; - const struct avl_node *avlnode; - - avlnode = afh_thread_status->avl_tree_topN.root; - - if(avlnode && (avl_check_dip_in_tree_recur(dip_net_order, avlnode) != 0)){ - return 1; - } - - return 0; -} - -static int afh_check_sip_is_white_list(unsigned int sip_net_order) -{ - unsigned int sip_val = (ntohl(sip_net_order) & AFH_IP_WHITE_LIST_MASK); - - if(g_afh_ip_white_list[sip_val] > 0){ - return 1; - } - -#if AFH_DEBUG - char ip_str[16]; - inet_ntop(AF_INET, &sip_net_order, ip_str, 16); - MESA_handle_runtime_log(g_afh_log_handle, 10, "AFH", "ip:%s is not in white list.\n", ip_str); -#endif - - return 0; -} - - -static int afh_remove_smaller_from_avl_topN(struct avl_tree *root) -{ - struct avl_node* smaller_node; - - smaller_node = avl_first(root); - - if(smaller_node != NULL){ - avl_remove(root, smaller_node); - -#if AFH_DEBUG - char ip_str[16]; - anti_flood_item_t *debug_smaller_node = _get_entry(smaller_node, anti_flood_item_t, avl_node_topN); ; - inet_ntop(AF_INET, &debug_smaller_node->dip_net_order, ip_str, 16); - MESA_handle_runtime_log(g_afh_log_handle, 20, "AFH", "dip:%s remove from top-N tree.\n", ip_str); -#endif - - } - - return 0; -} - -static int avl_topN_cmp_func(struct avl_node *cur, struct avl_node *new_node, void *aux) -{ - anti_flood_item_t *af_cur_node, *af_new_node; - - af_cur_node = _get_entry(cur, anti_flood_item_t, avl_node_topN); - af_new_node = _get_entry(new_node, anti_flood_item_t, avl_node_topN); - - if(af_cur_node->realtime_pps < af_new_node->realtime_pps){ - return -1; - }else if(af_cur_node->realtime_pps == af_new_node->realtime_pps){ - return 0; - } - - return 1; -} - -static int afh_insert_to_avl_topN(struct avl_tree *root, anti_flood_item_t *af_node) -{ - avl_insert(root, &af_node->avl_node_topN, avl_topN_cmp_func); - -#if AFH_DEBUG - char ip_str[16]; - inet_ntop(AF_INET, &af_node->dip_net_order, ip_str, 16); - MESA_handle_runtime_log(g_afh_log_handle, 20, "AFH", "dip:%s add to top-N tree.\n", ip_str); -#endif - - return 0; -} - -/* - ÿһʱ, - ޳TOPNС, - ٽǰڵtopN-AVLӦλ. -*/ -static int afh_topN_syn_sift(anti_flood_item_t *af_node) -{ - afh_thread_variable_t *afh_thread_status = g_afh_thread_status[af_node->thread_seq]; - - if((long)afh_thread_status->avl_tree_topN.aux >= AFH_REALTIME_SORT_TOPN){ /* top-N */ - if(af_node->realtime_pps > afh_thread_status->realtime_pps_min_syn_pkt){ - afh_remove_smaller_from_avl_topN(&afh_thread_status->avl_tree_topN); - afh_insert_to_avl_topN(&afh_thread_status->avl_tree_topN, af_node); - afh_thread_status->realtime_pps_min_syn_pkt = af_node->realtime_pps; - }else{ - ; /* ǰĿIPPPSTOPN-AVLСֵС, ò */ - } - }else{ - /* ǰڵ㲻TOPN */ - if(af_node->avl_node_topN.parent || af_node->avl_node_topN.left || af_node->avl_node_topN.right){ - afh_insert_to_avl_topN(&afh_thread_status->avl_tree_topN, af_node); - }else{ - /* ѾTOPNеĻ, Ϊppsʱڱ仯, Ҫ, 򵥵İ취: ȡٲ */ - avl_remove(&afh_thread_status->avl_tree_topN, &af_node->avl_node_topN); - afh_insert_to_avl_topN(&afh_thread_status->avl_tree_topN, af_node); - } - } - - return 1; - - return 0; -} - - -/* - TCPֻTCP/SYN FLOOD. - - 1.SYNֵ; - 2.DIPֵ80%; - 3.ڰڵIP, ݵԴIP; -*/ -static struct afh_pkt_check_res -anti_flood_tcp_syn_entry(int thread_seq, unsigned int sip_net_order, unsigned int dip_net_order) -{ - anti_flood_item_t *af_node; - long long cur_cpu_cycle; - char ip_str[32]; - int time_updated = 0; - int ret; - - if(afh_unlikely(AFH_STATE_SERIOUS == g_afh_global_status->syn_flood_state)){ - if(afh_check_dip_is_syn_topN(dip_net_order, thread_seq) - ///&& (0 == afh_check_sip_is_white_list(sip_net_order)) - ){ -#if AFH_DEBUG - inet_ntop(AF_INET, &dip_net_order, ip_str, 32); - MESA_handle_runtime_log(g_afh_log_handle, 10, "AFH", "detect TCP_FYN_FLOOD, dip:%s in topN!\n", ip_str); -#endif - return g_afh_check_res_syn_drop; - } - - /* TODO, diptopN, sipڰ, ppsܸ, ô? */ - } - - cur_cpu_cycle = afh_get_cpu_cycle(); - - af_node = (anti_flood_item_t *)MESA_htable_search(anti_flood_syn_htable[thread_seq], (unsigned char *)&dip_net_order, sizeof(int)); - if(NULL == af_node){ - af_node = (anti_flood_item_t *)__dictator_malloc(thread_seq, sizeof(anti_flood_item_t)); - anti_flood_htable_node_init(af_node, thread_seq, dip_net_order, cur_cpu_cycle); - - ret = MESA_htable_add(anti_flood_syn_htable[thread_seq], (unsigned char *)&dip_net_order, sizeof(int), af_node); - if(ret < 0){ - __dictator_free(thread_seq, af_node); - return g_afh_check_res_normal; - } - } - - af_node->realtime_tot_pkt_num++; - - time_updated = anti_flood_item_update_time(af_node, cur_cpu_cycle); - - if(g_afh_global_status->syn_flood_state != AFH_STATE_NORMAL){ - if(time_updated){ - afh_topN_syn_sift(af_node); - } - } - - if(af_node->detectd_flood_silent_time > 1){ - /* - Ĭڼ, PPS, Ҫһʱ - ˴Ҫж>1, ھĬڼ1, ¼PPSǷ񻹳ֵ, - й, ¾Ĭʱ, Լ, - ˶ʮرն, ½Flood1, ּ⵽, ٴζʮĶѭ. - */ - af_node->anti_flood_drop_pkt++; - }else{ - /* Ĭʱѹ, ¼PPSǷֵ */ - if(af_node->realtime_pps > (unsigned int)anti_flood_drop_syn_pps_threshold){ - af_node->detectd_flood_silent_time = anti_flood_detectd_flood_silent_time; - af_node->anti_flood_drop_pkt++; - } - } - - if(time_updated > 0){ - /* ÿ¼һζ־, ֹˢӲ */ - inet_ntop(AF_INET, &dip_net_order, ip_str, 32); - MESA_handle_runtime_log(g_afh_log_handle, 30, "anti_flood", "thread:%d, drop SYN_Flood packet dip:%s, last_second_pps:%u, slient_time:%ds, summary: %llu\n", - thread_seq, ip_str, af_node->realtime_pps, af_node->detectd_flood_silent_time, af_node->anti_flood_drop_pkt); - } - - return g_afh_check_res_normal; -} - -static struct afh_pkt_check_res -anti_flood_udp_dns_entry(int thread_seq, unsigned int dip_net, unsigned char ip_ttl, unsigned char dir) -{ - int ret; - anti_flood_udp_dns_item_t *dns_item; - anti_flood_item_t *af_node; - long long cur_cpu_cycle; - char ip_str[32]; - int time_updated = 0; - - cur_cpu_cycle = afh_get_cpu_cycle(); - - dns_item = (anti_flood_udp_dns_item_t *)MESA_htable_search(anti_flood_udp_dns_htable[thread_seq], (unsigned char *)&dip_net, sizeof(int)); - if(NULL == dns_item){ - dns_item = (anti_flood_udp_dns_item_t *)__dictator_malloc(thread_seq, sizeof(anti_flood_udp_dns_item_t)); - anti_flood_htable_node_init(&dns_item->common_st, thread_seq, dip_net, cur_cpu_cycle); - - ret = MESA_htable_add(anti_flood_udp_dns_htable[thread_seq], (unsigned char *)&dip_net, sizeof(int), dns_item); - if(ret < 0){ - __dictator_free(thread_seq, dns_item); - return g_afh_check_res_dns_drop; - } - } - af_node = &dns_item->common_st; - - af_node->realtime_tot_pkt_num++; - - time_updated = anti_flood_item_update_time(af_node, cur_cpu_cycle); - - if(af_node->detectd_flood_silent_time > 1){ - /* - Ĭڼ, PPS, Ҫһʱ - ˴Ҫж>1, ھĬڼ1, ¼PPSǷ񻹳ֵ, - й, ¾Ĭʱ, Լ, - ˶ʮ, ½1, ּ⵽, ٴζʮѭ. - */ - af_node->anti_flood_drop_pkt++; - }else{ - /* Ĭʱѹ, ¼PPSǷֵ */ - if(af_node->realtime_pps > (unsigned int)anti_flood_drop_udp_dns_pps_threshold){ - af_node->detectd_flood_silent_time = anti_flood_detectd_flood_silent_time; - af_node->anti_flood_drop_pkt++; - } - } - - if(time_updated > 0){ - /* ÿ¼һζ־, ֹˢӲ */ - inet_ntop(AF_INET, &dip_net, ip_str, 32); - MESA_handle_runtime_log(g_afh_log_handle, 30, "anti_flood", "thread:%d, drop DNS_Flood packet dip:%s, last_second_pps:%u, slient_time:%ds, summary: %llu\n", - thread_seq, ip_str, af_node->realtime_pps, af_node->detectd_flood_silent_time, af_node->anti_flood_drop_pkt); - } - - return g_afh_check_res_normal; -} - -static struct afh_pkt_check_res -anti_flood_udp_entry(int thread_seq, const struct afh_ip4_hdr *ip4hdr) -{ - struct afh_pkt_check_res ret; - const struct afh_udp_hdr *udphdr = (const struct afh_udp_hdr *)((char *)ip4hdr + ip4hdr->ip_hl * 4); - unsigned short sport, dport; - - sport = ntohs(udphdr->uh_sport); - dport = ntohs(udphdr->uh_dport); - - if(AFH_DNS_DEFAULT_PORT == sport){ - ret = anti_flood_udp_dns_entry(thread_seq, ip4hdr->ip_src.s_addr, ip4hdr->ip_ttl, 2); - }else if(AFH_NTP_DEFAULT_PORT == sport){ - ; - }else if(AFH_DNS_DEFAULT_PORT == dport){ - ret = anti_flood_udp_dns_entry(thread_seq, ip4hdr->ip_dst.s_addr, ip4hdr->ip_ttl, 1); - }else if(AFH_NTP_DEFAULT_PORT == dport){ - ; - }else{ - //other protocol, do nothing; - } - -#if 0 - if(anti_flood_drop_thread_flag[thread_seq] != 0){ - stream_pr = (struct streaminfo_private *)f_stream; - raw_pkt = stream_pr->raw_pkt; - - if(0 == bpf_filter(anti_flood_white_list_bpf_bin[thread_seq].bf_insns, - (const unsigned char *)raw_pkt->raw_pkt_data, - raw_pkt->raw_pkt_len, raw_pkt->raw_pkt_len)){ - anti_flood_drop_pkt[thread_seq][PKT_UDP]++; - return APP_STATE_GIVEME | APP_STATE_DROPPKT; - } - } -#endif - - return ret; -} - - -/* - ģݰȡӿڡ - : - pkt: յԭʼݰMACͷʼ - pkt_len: յԭʼݰȣ - thread_id: ߳ID, 0ʼ - transfer_dir: ݰ䷽ - ֵ: - ǰݰ, struct afh_pkt_check_res -*/ -struct afh_pkt_check_res -anti_flood_hijack_pkt_check(const void *pkt, int pkt_len, int thread_seq, int transfer_dir) -{ - - const struct ethhdr *ehdr = (struct ethhdr *)pkt; - const struct afh_ip4_hdr *ip4hdr; - const struct afh_tcphdr *tcphdr; - unsigned char tcp_flags; - unsigned short ip_offset, ip_flags; - afh_thread_variable_t *local_thread_stat = g_afh_thread_status[thread_seq]; - - if(afh_unlikely(ntohs(ehdr->h_proto) != ETH_P_IP)){ - return g_afh_check_res_normal; - } - - ip4hdr = (const struct afh_ip4_hdr *)((char *)pkt + sizeof(struct ethhdr)); - /*See, is this a fragment ? */ - ip_offset = ntohs(ip4hdr->ip_off); - ip_flags = ip_offset & ~AFH_IP_OFFMASK; - ip_offset &= AFH_IP_OFFMASK; - - if(afh_unlikely(((ip_flags & AFH_IP_MF) != 0) || (ip_offset != 0))){ - local_thread_stat->ip_frag_pkt_num++; - }else{ - local_thread_stat->ip_pkt_num++; - } - - if(IPPROTO_TCP == ip4hdr->ip_p){ - local_thread_stat->tcp_pkt_num++; - tcphdr = (const struct afh_tcphdr *)((char *)ip4hdr + ip4hdr->ip_hl*4); - tcp_flags = tcphdr->th_flags; - /* TCPĿǰSYN_FLOOD */ - if(afh_unlikely(TH_SYN == tcp_flags)){ - local_thread_stat->tcp_syn_pkt_num++; - return anti_flood_tcp_syn_entry(thread_seq, ip4hdr->ip_src.s_addr, ip4hdr->ip_dst.s_addr); - }else if(afh_unlikely(TH_FIN & tcp_flags)){ - /* note: ν綨һԴIPͨ? յSYN/ACKҲFlood, FIN, һ㶼ЭջΪ. TCPͨRST */ - afh_ip_white_ip_list_add(ip4hdr->ip_src.s_addr); - }else if((tcp_flags & TH_ACK) && (pkt_len > 100)){ - afh_ip_white_ip_list_add(ip4hdr->ip_src.s_addr); - }else{ - return g_afh_check_res_normal; - } - }else if(IPPROTO_UDP == ip4hdr->ip_p){ - local_thread_stat->udp_pkt_num++; - return anti_flood_udp_entry(thread_seq, ip4hdr); - }else{ - return g_afh_check_res_normal; - } - - return g_afh_check_res_normal; -} - - -static void afh_time_event_ip_white_list(void) -{ - static time_t _last_update_time = 0; - - /* ÿg_white_ip_list_intervalһ */ - if(_last_update_time + g_white_ip_list_interval < g_afh_current_time){ - _last_update_time = g_afh_current_time; - - g_current_trusted_val = g_current_trusted_val << 1; - if(0 == g_current_trusted_val){ - g_current_trusted_val = 1; /* ѭ, λ, Ϊ1 */ - } - } -} - -static void afh_time_event_traffic_calc(void) -{ - int tid; - static afh_thread_variable_t _last_stats; - afh_thread_variable_t current_stats; - const afh_thread_variable_t *realtime_stats; - static time_t _last_traffic_update_time = 0; - double tmp_ratio; - - if(_last_traffic_update_time < g_afh_current_time){ - _last_traffic_update_time = g_afh_current_time; - memset(¤t_stats, 0, sizeof(current_stats)); - - for(tid = 0; tid < g_afh_tot_thread_num; tid++){ - realtime_stats = g_afh_thread_status[tid]; - current_stats.ip_pkt_num += realtime_stats->ip_pkt_num; - current_stats.tcp_pkt_num += realtime_stats->tcp_pkt_num; - current_stats.udp_pkt_num += realtime_stats->udp_pkt_num; - current_stats.ip_frag_pkt_num += realtime_stats->ip_frag_pkt_num; - current_stats.tcp_syn_pkt_num += realtime_stats->tcp_syn_pkt_num; - current_stats.udp_dns_pkt_num += realtime_stats->udp_dns_pkt_num; - current_stats.udp_ntp_pkt_num += realtime_stats->udp_ntp_pkt_num; - } - - /* check and calc SYN pkt ratio */ - if(g_afh_global_status->syn_flood_drop_silent_time > 1){ - g_afh_global_status->syn_flood_drop_silent_time--; /* ڶĬ, */ - }else{ - tmp_ratio = (double)current_stats.tcp_syn_pkt_num/(double)current_stats.tcp_pkt_num * 100.0; - if(tmp_ratio >= AFH_FLOOD_THRESHOLD_UNUSUAL_MULTIPE * g_afh_global_status->syn_in_tcp_ratio){ - g_afh_global_status->syn_flood_state = AFH_STATE_UNUSUAL; - g_afh_global_status->syn_flood_drop_silent_time = 0; /* ԤģʽΪ0 */ - - if(tmp_ratio >= AFH_FLOOD_THRESHOLD_SERIOUS_MULTIPLE * g_afh_global_status->syn_in_tcp_ratio){ - g_afh_global_status->syn_flood_state = AFH_STATE_SERIOUS; - g_afh_global_status->syn_flood_drop_silent_time = g_afh_global_status->global_default_drop_silent_time; - } - }else{ - g_afh_global_status->syn_flood_state = AFH_STATE_NORMAL; - g_afh_global_status->syn_flood_drop_silent_time = 0; - } - } - - /* check and calc DNS pkt ratio */ - if(g_afh_global_status->dns_flood_drop_silent_time > 1){ - g_afh_global_status->dns_flood_drop_silent_time--; /* ڶĬ, */ - }else{ - tmp_ratio = (double)current_stats.udp_dns_pkt_num/(double)current_stats.udp_pkt_num * 100.0; - if(tmp_ratio >= AFH_FLOOD_THRESHOLD_UNUSUAL_MULTIPE * g_syn_in_tcp_ratio){ - g_afh_global_status->dns_flood_state = AFH_STATE_UNUSUAL; - g_afh_global_status->dns_flood_drop_silent_time = 0; /* ԤģʽΪ0 */ - - if(tmp_ratio >= AFH_FLOOD_THRESHOLD_SERIOUS_MULTIPLE * g_syn_in_tcp_ratio){ - g_afh_global_status->dns_flood_state= AFH_STATE_SERIOUS; - g_afh_global_status->dns_flood_drop_silent_time = g_afh_global_status->global_default_drop_silent_time; - } - }else{ - g_afh_global_status->dns_flood_state = AFH_STATE_NORMAL; - g_afh_global_status->dns_flood_drop_silent_time = 0; - } - } - - /* TODO, NTP and UDP check */ - - memcpy(&_last_stats, ¤t_stats, sizeof(afh_thread_variable_t)); - } - - return ; -} - -/* ʱ¼ص, ÿ1һغ, ڲٻNִһ */ -static void afh_time_event_for_1sec(void) -{ - afh_time_event_ip_white_list(); - afh_time_event_traffic_calc(); -} - -static void *afh_background_thread(void *arg) -{ - time_t last_time = time(NULL); - - while(1){ - g_afh_current_time = time(NULL); - - if(g_afh_current_time > last_time){ - last_time = g_afh_current_time; - afh_time_event_for_1sec(); - } - - usleep(1000); - } - - return NULL; -} - -static int afh_structure_init(int thread_count) -{ - int i, int_tmp; - MESA_load_profile_int_def(ANTI_FLOOD_CFG_FILE, "log", "log_level", &int_tmp, 10); - - g_afh_log_handle = MESA_create_runtime_log_handle("log/anti_flood.log", int_tmp); - - if(thread_count > AFH_MAX_THREAD_NUM){ - MESA_handle_runtime_log(g_afh_log_handle, 30, "AFH", "threqd_count is more than max thread: %d!\n", thread_count); - return -1; - } - - for(i = 0; i < thread_count; i++){ - g_afh_thread_status[i] = (afh_thread_variable_t *)malloc(sizeof(afh_thread_variable_t)); - memset(g_afh_thread_status[i], 0, sizeof(afh_thread_variable_t)); - g_afh_thread_status[i]->realtime_pps_min_syn_pkt = ~0; /* ڼ¼ǰTOPNеСֵ, ʼʱֵ */ - g_afh_thread_status[i]->realtime_pps_min_dns_pkt = ~0; - g_afh_thread_status[i]->realtime_pps_min_ntp_pkt = ~0; - avl_init(&g_afh_thread_status[i]->avl_tree_topN, (void *)0); - } - - g_afh_global_status = (afh_global_variable_t *)malloc(sizeof(afh_global_variable_t)); - - g_afh_ip_white_list = (unsigned short *)malloc(sizeof(short) * (1 << AFH_IP_WHITE_LIST_MASK_HOST_BIT)); - - afh_htable_init(); - - //anti_flood_avltree_init(); - - return 0; -} - -static int afh_variable_init(int thread_count) -{ - static int anti_flood_plug_init_flag = 0; - - if(anti_flood_plug_init_flag != 0){ - MESA_handle_runtime_log(g_afh_log_handle, 30, "AFH", "anti_flood_hijack_module_init is already initialized!\n"); - return -1; - } - - g_afh_current_time = time(NULL); - g_afh_tot_thread_num = thread_count; - - /* TODO: ԶȡCPUƵ */ - cpu_cycle_in_1second = (long long)cpu_frequency_in_MHZ * 1000000L; - - g_afh_global_status->syn_in_tcp_ratio = 4.0; - g_afh_global_status->dns_flood_state = 4.0; - g_afh_global_status->ntp_in_udp_ratio = 2.0; - g_afh_global_status->udp_in_ip_ratio = 35.0; - - g_afh_global_status->global_default_drop_silent_time = 30; /* TODO, ļȡ */ - - anti_flood_plug_init_flag = 1; - return 0; -} - - -static int afh_get_cfg(void) -{ - MESA_load_profile_int_def(ANTI_FLOOD_CFG_FILE, "main", "forced_drop_syn_pps_threshold", &anti_flood_drop_syn_pps_threshold, 10000); - MESA_load_profile_int_def(ANTI_FLOOD_CFG_FILE, "main", "anti_flood_udp_dns_pps_threshold", &anti_flood_drop_udp_dns_pps_threshold, 1000); - MESA_load_profile_int_def(ANTI_FLOOD_CFG_FILE, "main", "anti_flood_udp_ntp_pps_threshold", &anti_flood_drop_udp_ntp_pps_threshold, 1000); - -#if 0 - //MESA_load_profile_string_def(ANTI_FLOOD_CFG_FILE, "main", "anti_flood_white_list_bpf", anti_flood_white_list_bpf_string, 1024, "udp port 53 or udp port 5060"); - - for(i = 0; i < g_packet_io_thread_num; i++){ - static_phony_pcap_handle[i] = pcap_open_dead(DLT_EN10MB, 65535); - if(NULL == static_phony_pcap_handle[i]){ - printf("forced_drop: create pcap_handle error!\n"); - return -1; - } - - if(pcap_compile(static_phony_pcap_handle[i], &anti_flood_white_list_bpf_bin[i], anti_flood_white_list_bpf_string, 1, 0) < 0){ - printf("forced_drop: compile pcap filter '%s' error:%s\n", anti_flood_white_list_bpf_string, pcap_geterr(static_phony_pcap_handle[i])); - return -1; - } - } -#endif - - return 0; -} - - -static int afh_validity_check(void) -{ - int i; - unsigned int sum = 0; - - assert(sizeof(afh_thread_variable_t) % 64 == 0); - - assert(AFH_FLOOD_THRESHOLD_UNUSUAL_MULTIPE < AFH_FLOOD_THRESHOLD_SERIOUS_MULTIPLE); - - - for(i = 0; i < AFH_IP_WHITE_LIST_MASK_HOST_BIT; i++){ - sum |= (1<< i); - } - assert(sum == AFH_IP_WHITE_LIST_MASK); - - return 0; -} - - -int anti_flood_hijack_module_init(int thread_count) -{ - - pthread_t pid; - -#ifdef MESA_SAPP_PLATFORM - -#if (0 == RUN_AS_SAPP_PLUG) -#error "in sapp mode, but RUN_AS_SAPP_PLUG is 0!" - - assert(0); -#endif - -#endif - - afh_get_cfg(); - - afh_structure_init(thread_count); - - afh_variable_init(thread_count); - - afh_validity_check(); - - pthread_create(&pid, NULL, afh_background_thread, NULL); - - return 0; -} - - -#ifdef __cplusplus -} -#endif - diff --git a/inner_plug/anti_flood_hijack.h b/inner_plug/anti_flood_hijack.h deleted file mode 100644 index 6f56191..0000000 --- a/inner_plug/anti_flood_hijack.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef ANTI_FLOOD_HIJACK_H -#define ANTI_FLOOD_HIJACK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* for 863һ廯, ģ */ - -/* - ģʼӿڣģʱá - - : - thread_count: ȫصIJ߳ - ֵ: - 0 : SUCC; - -1: ERROR; -*/ -int anti_flood_hijack_module_init(int thread_count); - -/* - ģĽӿڣϵͳ˳ʱãͷԴ -*/ -int anti_flood_hijack_module_destroy(void); - - -enum afh_attack_type{ - AFH_ATTACK_TYPE_DDOS = 1, - AFH_ATTACK_TYPE_HIJACK = 2, -}; - -enum afh_ddos_attack_type{ - AFH_ATTACK_DDOS_IPFRAG = 1, - AFH_ATTACK_DDOS_SYN = 2, - AFH_ATTACK_DDOS_DNS = 3, - AFH_ATTACK_DDOS_NTP = 4, -}; - -enum afh_hijack_attack_type{ - AFH_ATTACK_HIJACK_HTTP = 1, - AFH_ATTACK_HIJACK_DNS = 2, -}; - -enum afh_hijack_action_type{ - AFH_CHECK_RES_PASS = 1, - AFH_CHECK_RES_DROP = 0, -}; - -/* ṹ嶨 */ -struct afh_pkt_check_res{ - unsigned int action:1; /* 1:pass; 0:drop */ - unsigned int attack_type:7; /* 1:ddos; 2:hijack */ - unsigned int ddos_type:8; /* 1:ip-frag-flood; 2:syn-flood; 3:dns-flood; 4:ntp-flood */ - unsigned int hijack_type:8; /* 1:http; 2:dns */ - unsigned int reserved:8; -}; - -/* - ģݰȡӿڡ - : - pkt: յԭʼݰMACͷʼ - pkt_len: յԭʼݰȣ - thread_id: ߳ID, 0ʼ - transfer_dir: ݰ䷽ - ֵ: - ǰݰ, struct afh_pkt_check_res -*/ -struct afh_pkt_check_res -anti_flood_hijack_pkt_check(const void *pkt, int pkt_len, int thread_id, int transfer_dir); - - -/* - ȫݽӿڡ - : - pkt: ͵ԭʼݰMACͷʼ - pkt_len: ͵ԭʼݰȣ - thread_id: ǰ߳ID, 0ʼ - transfer_dir: ݰ䷽ -*/ -int gateway_pkt_send(const void *pkt, int pkt_len, int thread_id, int transfer_dir); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/inner_plug/anti_flood_plug.c b/inner_plug/anti_flood_plug.c deleted file mode 100644 index d11ec9d..0000000 --- a/inner_plug/anti_flood_plug.c +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -#include "stream.h" -#include "stream_internal.h" -#include "anti_flood_hijack.h" - -/* 863һ廯Ŀ, ģеddos_flood⹦ */ - - -char ANTI_FLOOD_IPFRAG_ENTRY( struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip * a_packet) -{ - struct afh_pkt_check_res af_res; - const struct streaminfo_private *stream_pr = (const struct streaminfo_private *)f_stream; - - /* ֻIPv4ݰ */ - if((NULL == f_stream->pfather) || (f_stream->pfather->addr.addrtype != ADDR_TYPE_MAC)){ - return APP_STATE_GIVEME; - } - - af_res = anti_flood_hijack_pkt_check(stream_pr->raw_pkt->raw_pkt_data, stream_pr->raw_pkt->raw_pkt_len, thread_seq, routedir); - - if(AFH_CHECK_RES_DROP == af_res.action){ - return APP_STATE_GIVEME | APP_STATE_DROPPKT; - } - - return APP_STATE_GIVEME; -} - -char ANTI_FLOOD_IP_ENTRY( struct streaminfo *f_stream,unsigned char routedir,int thread_seq,struct ip * a_packet) -{ - struct afh_pkt_check_res af_res; - const struct streaminfo_private *stream_pr = (const struct streaminfo_private *)f_stream; - - /* ֻIPv4ݰ */ - if((NULL == f_stream->pfather) || (f_stream->pfather->addr.addrtype != ADDR_TYPE_MAC)){ - return APP_STATE_GIVEME; - } - - af_res = anti_flood_hijack_pkt_check(stream_pr->raw_pkt->raw_pkt_data, stream_pr->raw_pkt->raw_pkt_len, thread_seq, routedir); - - if(AFH_CHECK_RES_DROP == af_res.action){ - return APP_STATE_GIVEME | APP_STATE_DROPPKT; - } - - return APP_STATE_GIVEME; -} - -int ANTI_FLOOD_INIT(void) -{ - if(anti_flood_hijack_module_init(get_thread_count()) < 0){ - printf("anti_flood_hijack_module_init error!\n"); - return -1; - } - - return 0; -} - - -#ifdef __cplusplus -} -#endif - diff --git a/packet_io/cycle_pkt_dump_pipe.c.bak b/packet_io/cycle_pkt_dump_pipe.c.bak deleted file mode 100644 index 1db88b8..0000000 --- a/packet_io/cycle_pkt_dump_pipe.c.bak +++ /dev/null @@ -1,556 +0,0 @@ -#include "packet_io.h" -#include "stream_internal.h" -#include "stream_manage.h" -#include "mesa_net.h" -#include "sendpacket.h" -#include "MESA_prof_load.h" -#include "MESA_sleep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - 2015-04-15 , LiJia. - cycle_pkt_dump, - ʵʱѭ洢ݰĿǽ߻ҵֻһcore, BUG޷. - sappcoredump 'pkt_dump_file_root_dir'Ŀ¼洢һʱյİ, - öģʽ֣пܷBUGԴ - ֣pkt_dump_file_max_sizeʵһЩ. - - ----- ----- - | S | | D | - | A | ---̹ܵ--> | U | - | P | | M | - | P | | P | - ----- ----- - - Ϊʲôsapp, յ? ̼ͨͨŸһٴ洢? - : - sappյ֮, fwrite()洢, ΪfwriteлƵ, ֤дӲ. - ǵfflush()fclose(), ÿǿˢһ, Ӱ, - pipe()ݰһ, write()غ, - sappBUG, core dump, ݰҲѾcopyһ, - pkt_dumpǿ϶԰һBUGİ, ȫı浽Ӳ̵. - - main.conf1µsection5: - [pkt_dump] - pkt_dump_switch=0 //ܿ - pkt_dump_total_size=1000 //root_dirܼ.pcapļĴС, λ:MB, ֹƶдӲ - pkt_dump_file_max_size=200 //pcapļÿֵ߳̿, λ:MB. - pkt_dump_file_root_dir=/dev/shm //pcap洢·, Ƽ/dev/shm, Ӳٶȿܶ - pkt_dump_thread_seq=0,2,4,6,8 //ÿ̵߳ĿأΪܾ޴޷ȫ洢Ǿֻò̵߳dump , all=ȫ - -*/ - -#ifdef __cplusplus -extern "C" { -#endif -#if CYCLE_PKT_DUMP - -extern int g_use_MESA_sleep_sw; -extern int MESA_mkdir_p(const char *pathname, mode_t mode); -//extern time_t g_CurrentTime; -extern int g_packet_io_thread_num; -extern int g_iThreadNum; /* for dual_stack, start */ -static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* ָΪ/dev/shm, ٶȿ */ -static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ100MB, ߳ */ -static int G_PKT_DUMP_SW = 0; /* ĬϹر */ -static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM]; -static int pkt_dump_thread_num = 1; -static char phony_mac_hdr[14] = -{ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x12, 0x23, 0x34, 0x56, 0x67, 0x78, - 0x08, 0x00 -}; -typedef struct { - unsigned int magic; - unsigned short version_major; - unsigned short version_minor; - unsigned int thiszone; /* gmt to local correction */ - unsigned int sigfigs; /* accuracy of timestamps */ - unsigned int snaplen; /* max length saved portion of each pkt */ - unsigned int linktype; /* data link type (LINKTYPE_*) */ -}pkt_dump_file_hdr_t; - -struct pkt_dump_timeval { - unsigned int tv_sec; /* seconds */ - unsigned int tv_usec; /* microseconds */ -}; - -typedef struct { - struct pkt_dump_timeval ts; /* time stamp */ - unsigned int caplen; /* length of portion present */ - unsigned int len; /* length this packet (off wire) */ -}pkt_dump_pkt_hdr_t; - -typedef struct{ - enum addr_type_t low_layer_type; /* ԭʼײЭ, MAC(pcap), ҲIPv4(pag) */ - int raw_pkt_len; /* ԭʼܳ */ - //char pkt_data[]; -}pkt_dump_pipe_t; - -static int G_PKT_DUMP_PIPE[MAX_THREAD_NUM][2]; -static const pkt_dump_file_hdr_t pfile_hdr = -{ - 0xA1B2C3D4, - 0x0002, - 0x0004, - 0, - 0, - 0xFFFF, - 1 -}; - -/* reliable read */ -static inline ssize_t Rread(int fd, void *buf, size_t expect_count) -{ - ssize_t ret; - void *save_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = read(fd, save_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EAGAIN: - if(0 == g_use_MESA_sleep_sw){ - usleep(1); - }else{ - MESA_sleep(); - } - /* no break here!!! no break here!!! no break here!!!*/ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, read error:%s, ptr=%p, expect_count=%lu, left_count=%lu\n", - strerror(errno), save_ptr, expect_count, left_count); - break; - } - }else if(0 == ret){ - return 0; /* peer close */ - }else{ - save_ptr = (char *)save_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -/* reliable write */ -static inline ssize_t Rwrite(int fd, const void *buf, size_t expect_count) -{ - ssize_t ret; - const void *real_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = write(fd, real_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, write error:%s\n", strerror(errno)); - /* дռ䲻, , Ӱ */ - break; - } - }else{ - real_ptr = (const char *)real_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -static void *cycle_pkt_dump_thread(void *arg) -{ - int thread_seq = *((int *)arg); - FILE *fp; - int file_name_post_prefix = 0, ret, pfile_hdr_flag = 0; - long tot_pcap_file_len = 0; - char pkt_buf[65536]; - char dump_file_name[PATH_MAX]; - pkt_dump_pkt_hdr_t *ppkt_hdr; - unsigned int pkt_len; - int skip_pkt_hdr_len; /* Ԥͷռ䳤, ݲģʽͬ, ܻEth */ - - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getppid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - ppkt_hdr = (pkt_dump_pkt_hdr_t *)pkt_buf; - ppkt_hdr->ts.tv_usec = 0; -#ifdef CAPTURE_MODE_PAG - memcpy(pkt_buf+sizeof(pkt_dump_pkt_hdr_t), phony_mac_hdr, 14); - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t) + 14; -#else - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t); -#endif - while(1){ - /* Ȼȡ */ - ret = Rread(G_PKT_DUMP_PIPE[thread_seq][0], &pkt_len, sizeof(int)); - if(0 == ret){ - goto done; - }else if(ret < 0){ - continue; - } - if(ret != sizeof(int)) - { - printf("read hdr, but ret=%d\n", ret); - assert(0); - } - - if((unsigned int )pkt_len > 65536){ - printf("pkt length is too long, len = %u\n", pkt_len); - assert(0); - } - - /* pcapͷռԤ, ֻһfwrite, ͽͷһд */ - ret = Rread(G_PKT_DUMP_PIPE[thread_seq][0], (char *)pkt_buf+skip_pkt_hdr_len, pkt_len); - if(0 == ret){ - goto done; - }else if(ret < 0){ - /* ͷ, û, ô? */ - assert(0); - } - - if((unsigned int )ret != pkt_len) - { - printf("read pkt data, expect=%u, but ret=%d\n", pkt_len, ret); - assert(0); - } - - /* pcap file header, first time */ - if(0 == pfile_hdr_flag){ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, fp); - tot_pcap_file_len += sizeof(pkt_dump_file_hdr_t); - pfile_hdr_flag = 1; - } - /* °, ʱ */ - ppkt_hdr->ts.tv_sec = (unsigned int )g_CurrentTime; -#ifdef CAPTURE_MODE_PAG - ppkt_hdr->caplen = pkt_len+14; - ppkt_hdr->len = pkt_len+14; -#else - ppkt_hdr->caplen = pkt_len; - ppkt_hdr->len = pkt_len; -#endif - - - fwrite(pkt_buf, pkt_len+skip_pkt_hdr_len, 1, fp); - tot_pcap_file_len += pkt_len+skip_pkt_hdr_len; - - /* , ѭдļ */ - if(tot_pcap_file_len >= G_PKT_DUMP_FILE_SIZE){ - fclose(fp); - file_name_post_prefix = file_name_post_prefix ^ 1; - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getppid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); /* cycle write two files */ - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - tot_pcap_file_len = 0; - pfile_hdr_flag = 0; - } - } - -done: - - return NULL; -} - - -void cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) -{ - int ret; - - if((0 == G_PKT_DUMP_SW) || (0 == G_PKT_DUMP_PER_THREAD_SW[thread_seq])){ - return; - } - - ret = Rwrite(G_PKT_DUMP_PIPE[thread_seq][1], &p_raw_pkt->raw_pkt_len, sizeof(int)); /* hdr, Ϊͷ */ - if(ret < 0){ - printf("cycle_pkt_dump() write pkt hdr error: %s!\n", strerror(errno)); - return; - } - if(ret != sizeof(int)){ - printf("cycle_pkt_dump write pkt hdr, actual:%lu, ret:%d\n", sizeof(int), ret); - } - - ret = Rwrite(G_PKT_DUMP_PIPE[thread_seq][1], p_raw_pkt->raw_pkt_data, p_raw_pkt->raw_pkt_len); /* raw data */ - if(ret < 0){ - printf("cycle_pkt_dump() write pkt hdr data: %s!\n", strerror(errno)); - return; - } - - if(ret != p_raw_pkt->raw_pkt_len){ - printf("cycle_pkt_dump write pkt data, actual:%d, ret:%d\n", p_raw_pkt->raw_pkt_len, ret); - } -} - -void cycle_pkt_dump_old(int thread_seq, const void *ippkt, int ippktlen) -{ - raw_pkt_t raw_pkt; - - raw_pkt.raw_pkt_data = ippkt; - raw_pkt.raw_pkt_len = ippktlen; - - cycle_pkt_dump(thread_seq, &raw_pkt); -} - -static void cycle_pkt_dump_exec(int argc, char *argv[]) -{ - int i; - pid_t pid; - pthread_t thread_id[MAX_THREAD_NUM]; - static int thread_seq[MAX_THREAD_NUM]; - - pid = fork(); - if(0 == pid){ /* */ - for(i = 0; i < pkt_dump_thread_num; i++){ - close(G_PKT_DUMP_PIPE[i][1]); /* close write end */ - } - prctl(PR_SET_NAME, "cycle_pkt_dump", 0, 0, 0); - }else if(pid > 0){ - for(i = 0; i < pkt_dump_thread_num; i++){ - close(G_PKT_DUMP_PIPE[i][0]); /* close read end */ - } - usleep(10000); - return; /* , sapp */ - }else{ - printf("cycle_pkt_dump fork error!\n"); - } - - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - thread_seq[i] = i; - pthread_create(&thread_id[i], NULL, cycle_pkt_dump_thread, &thread_seq[i]); - usleep(10); - } - } - - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - pthread_join(thread_id[i], NULL); - } - } - - exit(0); -} - -static void cycle_pkt_dump_set_thread_num(int thread_num) -{ - pkt_dump_thread_num = thread_num; -} - -static int cycle_pkt_dump_get_core_num(void) -{ - FILE *fp; - char line_buf[PATH_MAX] = {0}; - int core_num = 0; - - fp = popen("ls -l core.* | wc -l", "r"); - if(NULL == fp){ - return -1; - } - - fgets(line_buf, PATH_MAX, fp); - - core_num = atoi(line_buf); - - pclose(fp); - return core_num; -} - -/* config is like: "0,1,2,3,4,5" */ -static int cycle_pkt_dump_parse_per_thread_switch(char *config_str) -{ - char *parse_config = config_str; - char *save_ptr; - char *token; - int i, thread_seq; - - if(strncasecmp("all", config_str, 3) == 0){ /* all thread is enable */ - for(i = 0; i < pkt_dump_thread_num; i++){ - G_PKT_DUMP_PER_THREAD_SW[i] = 1; - } - return 0; - } - - while((token = strtok_r(parse_config, ", \t", &save_ptr)) != NULL){ - thread_seq = atoi(token); - if(thread_seq < 0 || thread_seq >= pkt_dump_thread_num){ - printf("'pkt_dump_thread_seq' config invalid, threadnum=%d!\n", pkt_dump_thread_num); - return -1; - } - G_PKT_DUMP_PER_THREAD_SW[thread_seq] = 1; - parse_config = NULL; - } - - return 0; -} - - -static int cycle_pkt_dump_get_cur_files_size(void) -{ - FILE *fp; - int cur_files_size; - char cmd_str[PATH_MAX], tmp_str[1024]; - - snprintf(cmd_str, PATH_MAX, "du -scb %s/*.pcap | grep total | awk {'print $1'}", G_PKT_DUMP_ROOT_DIR); - - fp = popen(cmd_str, "r"); - if(NULL == fp){ - return -1; - } - - if(NULL == fgets(tmp_str, 1024, fp)){ - return -1; - } - cur_files_size = atoi(tmp_str); - - pclose(fp); - - return cur_files_size; -} - -static int cycle_pkt_dump_get_cur_enable_thread(void) -{ - int i, sum = 0; - - for(i = 0; i < MAX_THREAD_NUM; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] > 0){ - sum++; - } - } - - return sum; -} -/* - total_files_size: Ŀ¼ܵ.pcapС, λ:Byte; - file_size_per_thread_by_conf: ߳ļС, λ:Byte; - - յʵfile_size_per_threadֵ, ȡڵǰе.pcapļСtotal_files_sizeĹϵ; - ǰе.pcapļѳtotal_files_size, дµļ. -*/ -static int cycle_pkt_dump_set_file_size(int total_files_size, int file_size_per_thread_by_conf) -{ - int cur_files_size, cur_enable_thread_num = 0; - int file_size_per_thread_by_calc; /* ʵʼóÿ߳ļС */ - - cur_files_size = cycle_pkt_dump_get_cur_files_size(); - if(cur_files_size < 0 || cur_files_size >= total_files_size){ - printf("Warning: pkt_dump is enable, but current files size is more than 'pkt_dump_total_size'!\n"); - G_PKT_DUMP_SW = 0; - return -1; - } - - cur_enable_thread_num = cycle_pkt_dump_get_cur_enable_thread(); - if(0 == cur_enable_thread_num){ - return -1; - } - - file_size_per_thread_by_calc = (total_files_size-cur_files_size)/cur_enable_thread_num/2; - - /* ȡС */ - G_PKT_DUMP_FILE_SIZE = (file_size_per_thread_by_calc < file_size_per_thread_by_conf?file_size_per_thread_by_calc:file_size_per_thread_by_conf); - if(G_PKT_DUMP_FILE_SIZE < 2048){ - printf("Warning: pkt_dump is enable, but current files size is more than 'pkt_dump_total_size'!\n"); - return -1; - } - - return 0; -} - -int cycle_pkt_dump_init(int argc, char *argv[]) -{ - int i, ret, int_tmp, total_files_size, core_num; - char per_thread_sw[PATH_MAX]; - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_switch", &G_PKT_DUMP_SW, 0); - - if(0 == G_PKT_DUMP_SW){ - return 0; - } - - cycle_pkt_dump_set_thread_num(g_packet_io_thread_num); - - core_num = cycle_pkt_dump_get_core_num(); - if(core_num < 0 || core_num > 10){ - printf("Warning! core.* number is more than 10, pkt dump is auto disabled!\n"); - G_PKT_DUMP_SW = 0; - return 0; - } - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_file_root_dir", G_PKT_DUMP_ROOT_DIR, PATH_MAX, (char *)"./pkt_dump"); - MESA_mkdir_p(G_PKT_DUMP_ROOT_DIR, 0755); - - MESA_load_profile_string_nodef((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_thread_seq", per_thread_sw, PATH_MAX); - if(cycle_pkt_dump_parse_per_thread_switch(per_thread_sw) < 0){ - return 0; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_total_size", &total_files_size, 1000); - if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*100 /* 100GB */){ - printf("pkt_dump_total_size invalid!\n"); - return -1; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_file_max_size", &int_tmp, 100); - if(int_tmp < 2 || (unsigned int)int_tmp >= 1024*100 /* 100GB */){ - printf("pkt_dump_file_max_size invalid!\n"); - return -1; - } - /* ÿ߳Ҫѭд2ļ, Ҫpkt_dump_file_max_sizeʵֵٳ2 */ - if(cycle_pkt_dump_set_file_size(total_files_size*1024*1024, int_tmp*1024*512) < 0){ - return 0; - } - - for(i = 0; i < pkt_dump_thread_num; i++){ - //ret = pipe2(G_PKT_DUMP_PIPE[i], O_NONBLOCK); /* ʹ÷ģʽ, ̫, ʹģʽ */ - ret = pipe(G_PKT_DUMP_PIPE[i]); - if(ret < 0){ - return -1; - } - } - - signal(SIGPIPE, SIG_IGN); - - cycle_pkt_dump_exec(argc, argv); - - printf("\033[41mWarning! pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); - printf("\033[41mWarning! pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); - - return 0; -} - - -#endif - -#ifdef __cplusplus -} -#endif - diff --git a/packet_io/cycle_pkt_dump_through_write.c.bak b/packet_io/cycle_pkt_dump_through_write.c.bak deleted file mode 100644 index 476834c..0000000 --- a/packet_io/cycle_pkt_dump_through_write.c.bak +++ /dev/null @@ -1,975 +0,0 @@ -#include "packet_io.h" -#include "stream_internal.h" -#include "stream_manage.h" -#include "mesa_net.h" -#include "sendpacket.h" -#include "MESA_prof_load.h" -#include "MESA_sleep.h" -#include "MESA_socket_wrap.h" -#include "iknow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - 2015-04-15 , LiJia. - cycle_pkt_dump, - ʵʱѭ洢ݰĿǽ߻ҵֻһcore, BUG޷. - sappcoredump 'pkt_dump_file_root_dir'Ŀ¼洢һʱյİ, - öģʽ֣пܷBUGԴ - ֣pkt_dump_file_max_sizeʵһЩ. - - main.conf1µsection5: - [pkt_dump] - pkt_dump_switch=0 //ܿ - pkt_dump_total_size=1000 //root_dirܼ.pcapļĴС, λ:MB, ֹƶдӲ - pkt_dump_file_max_size=200 //pcapļÿֵ߳̿, λ:MB. - pkt_dump_file_root_dir=/dev/shm //pcap洢·, Ƽ/dev/shm, Ӳٶȿܶ - pkt_dump_thread_seq=0,2,4,6,8 //ÿ̵߳ĿأΪܾ޴޷ȫ洢Ǿֻò̵߳dump , all=ȫ - -*/ - -#ifdef __cplusplus -extern "C" { -#endif - - -#define UNIX_DOMAIN_SOCKET_NAME "/tmp/.pktdump" -#define PKT_DUMP_PROCESS_NAME "sapp_pkt_dump" - -extern iknow_handle PLATFORM_IHANDLE; - -enum dump_mode{ - PKT_DUMP_LOCAL_FILE = 1, /* дļ */ - PKT_DUMP_UDP_SOCKET = 2, /* дUDP ij˿ */ -}; - -#if DEBUG -#include "iknow.h" - -typedef struct{ - unsigned long long total_pkt_num; - unsigned long long total_pkt_bytes; - unsigned long long discard_pkt_num; - unsigned long long discard_pkt_bytes; - char __pad__[32]; /* 64ֽcache */ -}pkt_dump_status_t; -static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM]; - -#endif - -extern int g_packet_io_cap_level; -extern int g_use_MESA_sleep_sw; -extern int MESA_mkdir_p(const char *pathname, mode_t mode); -//extern time_t g_CurrentTime; -extern int g_packet_io_thread_num; -extern int g_iThreadNum; /* for dual_stack, start */ -static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* ָΪ/dev/shm, ٶȿ */ -static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ100MB, ߳ */ -int G_PKT_DUMP_SW = 0; /* ĬϹر */ -int G_PKT_DUMP_MODE = PKT_DUMP_LOCAL_FILE; /* Ĭдļ */ -static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM]; - -static int pkt_dump_thread_num = 1; - -static FILE *G_PKT_DUMP_FP[MAX_THREAD_NUM]; -static int G_FILENAME_INDEX[MAX_THREAD_NUM]; -static long G_PCAP_SIZE[MAX_THREAD_NUM]; -static char G_PKT_DUMP_FILTER_STR[PATH_MAX]; -static struct bpf_program G_PKT_DUMP_BPF_FILTER[MAX_THREAD_NUM]; -static pcap_t *phony_pcap_handle[MAX_THREAD_NUM]; /* BPFʱʹ */ - -static unsigned short pkt_dump_tcp_bind_port = 12345; /* ĬTCP˿, ڽⲿtcpdump */ -static int pkt_dump_tcp_cmd_sd = -1;/* TCP fd, ڽⲿtcpdump */ -static volatile int pkt_dump_udp_socket_peer_alive = 0; /* ⲿtcpdumpǷ */ -static int pkt_dump_udp_pkt_sd[MAX_THREAD_NUM]; /* UDPݰfd */ -static struct sockaddr_in udp_recv_addr; - -static unsigned char phony_mac_hdr[14] = -{ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x12, 0x23, 0x34, 0x56, 0x67, 0x78, - 0x08, 0x00 -}; -typedef struct { - unsigned int magic; - unsigned short version_major; - unsigned short version_minor; - unsigned int thiszone; /* gmt to local correction */ - unsigned int sigfigs; /* accuracy of timestamps */ - unsigned int snaplen; /* max length saved portion of each pkt */ - unsigned int linktype; /* data link type (LINKTYPE_*) */ -}pkt_dump_file_hdr_t; - -struct pkt_dump_timeval { - unsigned int tv_sec; /* seconds */ - unsigned int tv_usec; /* microseconds */ -}; - -typedef struct { - struct pkt_dump_timeval ts; /* time stamp */ - unsigned int caplen; /* length of portion present */ - unsigned int len; /* length this packet (off wire) */ -}pkt_dump_pkt_hdr_t; - -typedef struct{ - enum addr_type_t low_layer_type; /* ԭʼײЭ, MAC(pcap), ҲIPv4(pag) */ - int raw_pkt_len; /* ԭʼܳ */ - //char pkt_data[]; -}pkt_dump_pipe_t; - - -static const pkt_dump_file_hdr_t pfile_hdr = -{ - 0xA1B2C3D4, - 0x0002, - 0x0004, - 0, - 0, - 0xFFFF, - 1 -}; - -/* reliable read */ -static inline ssize_t Rread(int fd, void *buf, size_t expect_count) -{ - ssize_t ret; - void *save_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = read(fd, save_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EAGAIN: - if(0 == g_use_MESA_sleep_sw){ - usleep(1); - }else{ - MESA_sleep(); - } - /* no break here!!! no break here!!! no break here!!!*/ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, read error:%s, ptr=%p, expect_count=%lu, left_count=%lu\n", - strerror(errno), save_ptr, expect_count, left_count); - break; - } - }else if(0 == ret){ - return 0; /* peer close */ - }else{ - save_ptr = (char *)save_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -/* reliable write */ -static inline ssize_t Rwrite(int fd, const void *buf, size_t expect_count) -{ - ssize_t ret; - const void *real_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = write(fd, real_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, write error:%s\n", strerror(errno)); - /* дռ䲻, , Ӱ */ - break; - } - }else{ - real_ptr = (const char *)real_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -#if 0 -static void *cycle_pkt_dump_check_father(void *arg) -{ - while(1){ - if(1 == getppid()){ /* ̱Ϊinit, ˵Ѿ˳ */ - exit(1); - }else{ - usleep(100000); - } - } - - return NULL; -} - - -static void *cycle_pkt_dump_thread(void *arg) -{ - int thread_seq = *((int *)arg); - FILE *fp; - int file_name_post_prefix = 0, ret, pfile_hdr_flag = 0; - long tot_pcap_file_len = 0; - char pkt_buf[65536]; - char dump_file_name[PATH_MAX]; - pkt_dump_pkt_hdr_t *ppkt_hdr; - int pkt_len; - int skip_pkt_hdr_len; /* Ԥͷռ䳤, ݲģʽͬ, ܻEth */ - - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - ppkt_hdr = (pkt_dump_pkt_hdr_t *)pkt_buf; - ppkt_hdr->ts.tv_usec = 0; -#ifdef CAPTURE_MODE_PAG - memcpy(pkt_buf+sizeof(pkt_dump_pkt_hdr_t), phony_mac_hdr, 14); - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t) + 14; -#else - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t); -#endif - while(1){ - /* pcapͷռԤ, ֻһfwrite, ͽͷһд */ - pkt_len = read(G_UNIX_DOMAIN_SD[thread_seq], (char *)pkt_buf+skip_pkt_hdr_len, 2048); - if(0 == pkt_len){ - goto done; - }else if(pkt_len < 0){ - continue; - } - - /* pcap file header, first time */ - if(0 == pfile_hdr_flag){ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, fp); - tot_pcap_file_len += sizeof(pkt_dump_file_hdr_t); - pfile_hdr_flag = 1; - } - /* °, ʱ */ - ppkt_hdr->ts.tv_sec = (unsigned int )g_CurrentTime; -#ifdef CAPTURE_MODE_PAG - ppkt_hdr->caplen = pkt_len+14; - ppkt_hdr->len = pkt_len+14; -#else - ppkt_hdr->caplen = pkt_len; - ppkt_hdr->len = pkt_len; -#endif - - fwrite(pkt_buf, pkt_len+skip_pkt_hdr_len, 1, fp); - tot_pcap_file_len += pkt_len+skip_pkt_hdr_len; - - /* , ѭдļ */ - if(tot_pcap_file_len >= G_PKT_DUMP_FILE_SIZE){ - fclose(fp); - file_name_post_prefix = file_name_post_prefix ^ 1; - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); /* cycle write two files */ - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - tot_pcap_file_len = 0; - pfile_hdr_flag = 0; - } - } - -done: - - return NULL; -} -#endif - -static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_raw_pkt) -{ - if(1 == pkt_dump_udp_socket_peer_alive){ - if(g_packet_io_cap_level != CAP_LEVEL_MAC){ - if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, - (const unsigned char *)p_raw_pkt->raw_pkt_data-14, - p_raw_pkt->raw_pkt_len+14, p_raw_pkt->raw_pkt_len+14)){ - return; - } - }else{ - if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, - (const unsigned char *)p_raw_pkt->raw_pkt_data, - p_raw_pkt->raw_pkt_len, p_raw_pkt->raw_pkt_len)){ - return; - } - } - - /* bingo, match filter, sendto */ - sendto(pkt_dump_udp_pkt_sd[thread_seq], p_raw_pkt->raw_pkt_data, p_raw_pkt->raw_pkt_len, - MSG_DONTWAIT, - (const struct sockaddr *)&udp_recv_addr, - sizeof(udp_recv_addr)); - } -} - -static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) -{ - int ret; - /* Ϊpcap_hdr[2],һССtrick, [0]ʾpcapͷϢ, - [1]ʾPAGģʽ, 洢etherhdr, pkt_dump_pkt_hdr_tΪ16ֽ, ÿԷһether hdr. - */ - pkt_dump_pkt_hdr_t pcap_hdr[2]; - int write_hdr_len; - char dump_file_name[PATH_MAX]; - - if(PKT_DUMP_LOCAL_FILE == G_PKT_DUMP_MODE){ - if(0 == G_PKT_DUMP_PER_THREAD_SW[thread_seq]){ - return; - } - }else{ - __do_cycle_pkt_dump_udp_socket(thread_seq, p_raw_pkt); - return; - } - - if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ - if(g_packet_io_cap_level != CAP_LEVEL_MAC){ - if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, - (const unsigned char *)p_raw_pkt->raw_pkt_data-14, - p_raw_pkt->raw_pkt_len+14, p_raw_pkt->raw_pkt_len+14)){ - return; - } - }else{ - if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, - (const unsigned char *)p_raw_pkt->raw_pkt_data, - p_raw_pkt->raw_pkt_len, p_raw_pkt->raw_pkt_len)){ - return; - } - } - } - - if(unlikely(NULL == G_PKT_DUMP_FP[thread_seq])){ - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, G_FILENAME_INDEX[thread_seq]); - G_PKT_DUMP_FP[thread_seq] = fopen(dump_file_name, "wb+"); - if(NULL == G_PKT_DUMP_FP[thread_seq]){ - printf("fopen %s error!\n", dump_file_name); - return; - } - /* pcap file header, first time */ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, G_PKT_DUMP_FP[thread_seq]); - } - - /* °, ʱ */ - pcap_hdr[0].ts.tv_sec = (unsigned int )g_CurrentTime; - - if(g_packet_io_cap_level != CAP_LEVEL_MAC){ - pcap_hdr[0].caplen = p_raw_pkt->raw_pkt_len+14; - pcap_hdr[0].len = p_raw_pkt->raw_pkt_len+14; - memcpy(&pcap_hdr[1], phony_mac_hdr, 14); - write_hdr_len = sizeof(pkt_dump_pkt_hdr_t) + 14; - }else{ - pcap_hdr[0].caplen = p_raw_pkt->raw_pkt_len; - pcap_hdr[0].len = p_raw_pkt->raw_pkt_len; - write_hdr_len = sizeof(pkt_dump_pkt_hdr_t); - } - - ret = fwrite(&pcap_hdr[0], write_hdr_len, 1, G_PKT_DUMP_FP[thread_seq]); - if(unlikely(ret < 1)){ - return; - } - ret = fwrite(p_raw_pkt->raw_pkt_data, p_raw_pkt->raw_pkt_len, 1, G_PKT_DUMP_FP[thread_seq]); - if(unlikely(ret < 1)){ - /* ֻдͷ, дݳִ, ع */ - fseek(G_PKT_DUMP_FP[thread_seq], (int)0-(int)sizeof(pkt_dump_pkt_hdr_t), SEEK_CUR); - return; - } - - /* , ѭдļ */ - G_PCAP_SIZE[thread_seq] += write_hdr_len + p_raw_pkt->raw_pkt_len; - if(unlikely(G_PCAP_SIZE[thread_seq] >= G_PKT_DUMP_FILE_SIZE)){ - fclose(G_PKT_DUMP_FP[thread_seq]); - G_FILENAME_INDEX[thread_seq] ^= 1; - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, G_FILENAME_INDEX[thread_seq]); - G_PKT_DUMP_FP[thread_seq] = fopen(dump_file_name, "wb+"); - if(NULL == G_PKT_DUMP_FP[thread_seq]){ - printf("fopen %s error!\n", dump_file_name); - return; - } - /* pcap file header, first time */ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, G_PKT_DUMP_FP[thread_seq]); - G_PCAP_SIZE[thread_seq] = 0; - } - - return; -} - -void cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) -{ - if(likely(0 == G_PKT_DUMP_SW)){ - return; - } - - __do_cycle_pkt_dump(thread_seq, p_raw_pkt); -} - -void cycle_pkt_dump_old(int thread_seq, const void *ippkt, int ippktlen) -{ - raw_pkt_t raw_pkt; - - raw_pkt.raw_pkt_data = ippkt; - raw_pkt.raw_pkt_len = ippktlen; - - cycle_pkt_dump(thread_seq, &raw_pkt); -} - -#if 0 -static int cycle_pkt_dump_child_init(void) -{ - int i, ret; - struct sockaddr_un father_pro_addr; - int addr_len; - char test_buf[1024]; - int buf_len = 0; - socklen_t opt_len; - - for(i = 0; i < g_packet_io_thread_num; i++){ - G_UNIX_DOMAIN_SD[i] = socket(AF_UNIX,SOCK_DGRAM,0); - if(G_UNIX_DOMAIN_SD[i] < 0){ - printf("socket error: %s\n", strerror(errno)); - return -1; - } - - addr_len = sizeof(father_pro_addr); - father_pro_addr.sun_family=AF_UNIX; - snprintf(father_pro_addr.sun_path, sizeof(father_pro_addr.sun_path), "%s%d", UNIX_DOMAIN_SOCKET_NAME, i); - - unlink(father_pro_addr.sun_path); - if(bind(G_UNIX_DOMAIN_SD[i], (struct sockaddr *)&father_pro_addr, addr_len) < 0){ - printf("bind %s error: %s\n", father_pro_addr.sun_path, strerror(errno)); - return -1; - } - - listen(G_UNIX_DOMAIN_SD[i], 10); - } - - usleep(10000); - - for(i = 0; i < g_packet_io_thread_num; i++){ - ret = read(G_UNIX_DOMAIN_SD[i], test_buf, 1024); /* ȴ̵, ȷ˵ */ - if(ret <= 0){ - printf("socket read error:%s\n", strerror(errno)); - return -1; - } - } - - return 0; -} -#endif - - -#if DEBUG -static long ifuncb_show_pktdump_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args) -{ - int i; - unsigned long long discard_pkt_sum = 0, discard_byte_sum = 0; - unsigned long long tot_pkt_sum = 0, tot_byte_sum = 0; - - for(i = 0; i < g_packet_io_thread_num; i++){ - tot_pkt_sum += PKT_DISCARD_STAT[i].total_pkt_num; - tot_byte_sum += PKT_DISCARD_STAT[i].total_pkt_bytes; - discard_pkt_sum += PKT_DISCARD_STAT[i].discard_pkt_num; - discard_byte_sum += PKT_DISCARD_STAT[i].discard_pkt_bytes; - } - //iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n"); - iprintf(ihandle, iconn, "%8s %8s %13s\n", "", "packet", "byte"); - iprintf(ihandle, iconn, "%8s %8llu %13llu\n", "total", tot_pkt_sum, tot_byte_sum); - iprintf(ihandle, iconn, "%8s %8llu %13llu\n", "DROP", discard_pkt_sum, discard_byte_sum); - - return 0; -} - -#endif - -#if 0 -static int cycle_pkt_dump_father_init(void) -{ - int i; - struct sockaddr_un child_pro_addr; - int addr_len; - char test_buf[1024] = "I am father"; - int buf_len = 0; - socklen_t opt_len; - - for(i = 0; i < g_packet_io_thread_num; i++){ - G_UNIX_DOMAIN_SD[i] = socket(AF_UNIX,SOCK_DGRAM,0); - if(G_UNIX_DOMAIN_SD[i] < 0){ - printf("socket error: %s\n", strerror(errno)); - return -1; - } - - addr_len = sizeof(child_pro_addr); - child_pro_addr.sun_family=AF_UNIX; - snprintf(child_pro_addr.sun_path, sizeof(child_pro_addr.sun_path), "%s%d", UNIX_DOMAIN_SOCKET_NAME, i); - - if(connect(G_UNIX_DOMAIN_SD[i], (struct sockaddr*)&child_pro_addr, addr_len) < 0){ - printf("connect %s error: %s\n", child_pro_addr.sun_path, strerror(errno)); - return -1; - } - } - - for(i = 0; i < g_packet_io_thread_num; i++){ - write(G_UNIX_DOMAIN_SD[i], test_buf, 1024); - } - - unlink(child_pro_addr.sun_path); -#if DEBUG - iknow_register_cmd(PLATFORM_IHANDLE, "show pktdump summary", "display packet dump status", - ifuncb_show_pktdump_summary, NULL, 0, NULL); -#endif - - return 0; -} -#endif - -#if 0 -static void cycle_pkt_dump_clear_last_status(void) -{ - char cmd_buf[128]; - - snprintf(cmd_buf, 128, "killall %s", PKT_DUMP_PROCESS_NAME); - - system(cmd_buf); -} - - -static void cycle_pkt_dump_exec(int argc, char *argv[]) -{ - int i; - pid_t pid; - pthread_t check_ppid, thread_id[MAX_THREAD_NUM]; - static int thread_seq[MAX_THREAD_NUM]; - - cycle_pkt_dump_clear_last_status(); - - pid = fork(); - if(0 == pid){ /* ӽ, */ - if(cycle_pkt_dump_child_init() < 0){ - printf("cycle pkt dump init error!\n"); - exit(1); - } - prctl(PR_SET_NAME, PKT_DUMP_PROCESS_NAME, 0, 0, 0); - }else if(pid > 0){ - usleep(50000); - if(cycle_pkt_dump_father_init() < 0){ - printf("cycle pkt dump init error!\n"); - exit(1); - } - return; /* ̷, sapp */ - }else{ - printf("cycle_pkt_dump fork error!\n"); - exit(0); - } - - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - thread_seq[i] = i; - pthread_create(&thread_id[i], NULL, cycle_pkt_dump_thread, &thread_seq[i]); - usleep(100); - } - } - - pthread_create(&check_ppid, NULL, cycle_pkt_dump_check_father, NULL); - - /* ӽ̵߳ȴ */ - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - pthread_join(thread_id[i], NULL); - } - } - - exit(0); -} -#endif - -static void cycle_pkt_dump_set_thread_num(int thread_num) -{ - pkt_dump_thread_num = thread_num; -} - -static int cycle_pkt_dump_get_core_num(void) -{ - FILE *fp; - char line_buf[PATH_MAX] = {0}; - int core_num = 0; - - fp = popen("ls -l core.* | wc -l", "r"); - if(NULL == fp){ - return -1; - } - - fgets(line_buf, PATH_MAX, fp); - - core_num = atoi(line_buf); - - pclose(fp); - return core_num; -} - -/* config is like: "0,1,2,3,4,5" */ -static int cycle_pkt_dump_parse_per_thread_switch(char *config_str) -{ - char *parse_config = config_str; - char *save_ptr; - char *token; - int i, thread_seq; - - if(strncasecmp("all", config_str, 3) == 0){ /* all thread is enable */ - for(i = 0; i < pkt_dump_thread_num; i++){ - G_PKT_DUMP_PER_THREAD_SW[i] = 1; - } - return 0; - } - - while((token = strtok_r(parse_config, ", \t", &save_ptr)) != NULL){ - thread_seq = atoi(token); - if(thread_seq < 0 || thread_seq >= pkt_dump_thread_num){ - printf("'pkt_dump_thread_seq' config invalid, threadnum=%d!\n", pkt_dump_thread_num); - return -1; - } - G_PKT_DUMP_PER_THREAD_SW[thread_seq] = 1; - parse_config = NULL; - } - - return 0; -} - - -static long cycle_pkt_dump_get_cur_files_size(void) -{ - FILE *fp; - long cur_files_size; - char cmd_str[PATH_MAX], tmp_str[1024]; - - snprintf(cmd_str, PATH_MAX, "du -scb %s | grep %s | awk {'print $1'}", G_PKT_DUMP_ROOT_DIR, G_PKT_DUMP_ROOT_DIR); - - fp = popen(cmd_str, "r"); - if(NULL == fp){ - return -1; - } - - if(NULL == fgets(tmp_str, 1024, fp)){ - return -1; - } - cur_files_size = (long)strtol(tmp_str, NULL, 10); - - pclose(fp); - - return cur_files_size; -} - -static int cycle_pkt_dump_get_cur_enable_thread(void) -{ - int i, sum = 0; - - for(i = 0; i < MAX_THREAD_NUM; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] > 0){ - sum++; - } - } - - return sum; -} -/* - total_files_size: Ŀ¼ܵ.pcapС, λ:Byte; - file_size_per_thread_by_conf: ߳ļС, λ:Byte; - - յʵfile_size_per_threadֵ, ȡڵǰе.pcapļСtotal_files_sizeĹϵ; - ǰе.pcapļѳtotal_files_size, дµļ. -*/ -static int cycle_pkt_dump_set_file_size(long total_files_size, long file_size_per_thread_by_conf) -{ - long cur_files_size; - int cur_enable_thread_num = 0; - long file_size_per_thread_by_calc; /* ʵʼóÿ߳ļС */ - - cur_files_size = cycle_pkt_dump_get_cur_files_size(); - if(cur_files_size < 0 || cur_files_size >= total_files_size){ - printf("\033[33m[Warning]pkt_dump is enable, but current files size is more than 'pkt_dump_total_size', disable pktdump!\033[0m\n"); - usleep(100000); - G_PKT_DUMP_SW = 0; - return -1; - } - - cur_enable_thread_num = cycle_pkt_dump_get_cur_enable_thread(); - if(0 == cur_enable_thread_num){ - printf("\033[33m[Warning]pkt_dump is enable, but enable thread number is 0, disable pktdump!\033[0m\n"); - usleep(100000); - return -1; - } - - file_size_per_thread_by_calc = (total_files_size-cur_files_size)/cur_enable_thread_num/2; - - /* ȡС */ - G_PKT_DUMP_FILE_SIZE = (file_size_per_thread_by_calc < file_size_per_thread_by_conf?file_size_per_thread_by_calc:file_size_per_thread_by_conf); - if(G_PKT_DUMP_FILE_SIZE < 2048){ - printf("\033[33m[Warning]pkt_dump is enable, but current files size is more than 'pkt_dump_total_size'!\033[0m\n"); - return -1; - } - - return 0; -} - -static void pkt_dump_sig_ignore(int sig) -{ - return; -} - -static void pkt_dump_sig_handle(int sig) -{ - signal(SIGSEGV, pkt_dump_sig_ignore); /* SIGSEGV, һٵжϴƭϵͳ */ - sync(); /* δд̵ǿд */ - abort(); /* ֹ, coreļ */ -} - -static void cycle_pkt_dump_command_parse(int connfd) -{ - char cmd_buf[1024]; - int i, ret; - int *bpf_filter_len; /* with EOF */ - unsigned short *udp_rcv_port; - - /* ȷ2ֽtcpdump UDPն˿ */ - ret = MESA_sock_greedy_read(connfd, cmd_buf, 2, -1); - if(0 == ret){ - goto err_exit; - }else if(ret < 0){ - printf("sock read error, %s\n", strerror(errno)); - goto err_exit; - } - udp_rcv_port = (unsigned short *)&cmd_buf[0]; - - udp_recv_addr.sin_family = AF_INET; - udp_recv_addr.sin_addr.s_addr = htonl(0x7f000001); - udp_recv_addr.sin_port = htons(*udp_rcv_port); - - /* ٷ4ֽڳϢ, ʾBPF-filterַ, filterEOF */ - ret = MESA_sock_greedy_read(connfd, cmd_buf, 4, -1); - if(0 == ret){ - goto err_exit; - }else if(ret < 0){ - printf("sock read error, %s\n", strerror(errno)); - goto err_exit; - } - bpf_filter_len = (int *)&cmd_buf[0]; - - if(bpf_filter_len > 0){ /* ûfilter */ - ret = MESA_sock_greedy_read(connfd, cmd_buf, (size_t )(*bpf_filter_len), -1); - if(0 == ret){ - goto err_exit; - } - } - for(i = 0; i < g_packet_io_thread_num; i++){ - phony_pcap_handle[i] = pcap_open_dead(DLT_EN10MB, 65535); - if(NULL == phony_pcap_handle[i]){ - goto err_exit; - } - - if(bpf_filter_len > 0){ /* ûfilter */ - if(pcap_compile(phony_pcap_handle[i], &G_PKT_DUMP_BPF_FILTER[i], cmd_buf, 100, 0) < 0){ - printf("Compile pcap filter '%s' error:%s\n", cmd_buf, pcap_geterr(phony_pcap_handle[i])); - goto err_exit; - } - } - } - - pkt_dump_udp_socket_peer_alive = 1; - - while(MESA_sock_greedy_read(connfd, cmd_buf, 1, -1) != 0); - -err_exit: - pkt_dump_udp_socket_peer_alive = 0; - usleep(1000 * 500); /* ʱͷ, ߳ʹBPF */ - for(i = 0; i < g_packet_io_thread_num; i++){ - pcap_freecode(&G_PKT_DUMP_BPF_FILTER[i]); - } - close(connfd); - return; -} - -static void * cycle_pkt_dump_udp_socket_daemon_thread(void *arg) -{ - socklen_t cliaddr_len; - struct sockaddr_in cliaddr; - int connfd; -#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* 汾ж, ܶϵͳ޷ */ -#ifdef _GNU_SOURCE - pthread_setname_np(pthread_self(), "sapp_pkt_dump"); -#endif -#endif - - while(1){ - cliaddr_len = sizeof(cliaddr); - connfd = accept(pkt_dump_tcp_cmd_sd, (struct sockaddr *) &cliaddr, &cliaddr_len); - if(connfd > 0){ - cycle_pkt_dump_command_parse(connfd); - } - } - - return NULL; -} - -static int cycle_pkt_dump_socket_init(void) -{ - pthread_t pid; - int i, opt; - struct sockaddr_in sockadd; - - pkt_dump_tcp_cmd_sd = socket(AF_INET, SOCK_STREAM, 0); - - opt = 1; - setsockopt(pkt_dump_tcp_cmd_sd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); - - bzero(&sockadd, sizeof(sockadd)); - sockadd.sin_family = AF_INET; - sockadd.sin_addr.s_addr = htonl(INADDR_ANY); - sockadd.sin_port = htons(pkt_dump_tcp_bind_port); - - if(bind(pkt_dump_tcp_cmd_sd, (struct sockaddr *) &sockadd, sizeof(sockadd)) < 0){ - printf("pkt dump bind cmd port %u error, %s!\n", pkt_dump_tcp_bind_port, strerror(errno)); - return -1; - } - listen(pkt_dump_tcp_cmd_sd, 1); - - for(i = 0; i < g_packet_io_thread_num; i++){ - pkt_dump_udp_pkt_sd[i] = socket(AF_INET, SOCK_DGRAM, 0); - } - - pthread_create(&pid, NULL, cycle_pkt_dump_udp_socket_daemon_thread, NULL); - - return 0; -} - -int cycle_pkt_dump_init(int argc, char *argv[]) -{ - int i, ret = 0; - int int_tmp, total_files_size, core_num; - char per_thread_sw[PATH_MAX]; - char pcap_errbuf[PCAP_ERRBUF_SIZE]; - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_switch", &G_PKT_DUMP_SW, 0); - - if(0 == G_PKT_DUMP_SW){ - return 0; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_mode", &G_PKT_DUMP_MODE, 1); - if((G_PKT_DUMP_MODE != PKT_DUMP_LOCAL_FILE) && (G_PKT_DUMP_MODE != PKT_DUMP_UDP_SOCKET)){ - printf("\n\033[41mError! pkt_dump_mode only support 1 or 2!\033[0m\n"); - return -1; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_cmd_port", &int_tmp, 12345); - if((int_tmp <=0) || (int_tmp > 65535)){ - printf("\n\033[41mError! pkt_dump_cmd_port invalid, %d!\033[0m\n", int_tmp); - return -1; - } - pkt_dump_tcp_bind_port = (unsigned short)int_tmp; - -#if 0 == CYCLE_PKT_DUMP - printf("\n\033[33m[Warning]pkt_dump is enable, but sapp is not compile correct, please use debug=2.\033[0m\n"); - sleep(1); -#endif - - if(PKT_DUMP_LOCAL_FILE == G_PKT_DUMP_MODE){ - cycle_pkt_dump_set_thread_num(g_packet_io_thread_num); - - core_num = cycle_pkt_dump_get_core_num(); - if(core_num < 0 || core_num > 10){ - printf("\033[33m[Warning]core.* number is more than 10, pkt dump is auto disabled!\n"); - G_PKT_DUMP_SW = 0; - return 0; - } - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_bpf_filter", G_PKT_DUMP_FILTER_STR, PATH_MAX, (char *)""); - if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ - for(i = 0; i < g_packet_io_thread_num; i++){ - phony_pcap_handle[i] = pcap_open_dead(DLT_EN10MB, 65535); - if(NULL == phony_pcap_handle[i]){ - printf("pcap_open %s error, %s\n", "lo", pcap_errbuf); - printf("\n\033[41mpkt_dump_bpf_filter is not enable!\033[0m\n"); - goto skip_bpf_filter; - } - if(pcap_compile(phony_pcap_handle[i], &G_PKT_DUMP_BPF_FILTER[i], G_PKT_DUMP_FILTER_STR, 100, 0) < 0){ - printf("Compile pcap filter '%s' error:%s\n", G_PKT_DUMP_FILTER_STR, pcap_geterr(phony_pcap_handle[i])); - return -1; - } - } - } - - skip_bpf_filter: - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_file_root_dir", G_PKT_DUMP_ROOT_DIR, PATH_MAX, (char *)"/tmp/pkt_dump"); - MESA_mkdir_p(G_PKT_DUMP_ROOT_DIR, 0755); - - MESA_load_profile_string_nodef((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_thread_seq", per_thread_sw, PATH_MAX); - if(cycle_pkt_dump_parse_per_thread_switch(per_thread_sw) < 0){ - return 0; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_total_size", &total_files_size, 1000); - if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*100 /* 100GB */){ - printf("pkt_dump_total_size invalid!\n"); - return -1; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_file_max_size", &int_tmp, 100); - if(int_tmp < 2 || (unsigned int)int_tmp >= 1024*100 /* 100GB */){ - printf("pkt_dump_file_max_size invalid!\n"); - return -1; - } - /* ÿ߳Ҫѭд2ļ, Ҫpkt_dump_file_max_sizeʵֵٳ2 */ - if(cycle_pkt_dump_set_file_size((long)total_files_size*1024*1024, (long)int_tmp*1024*512) < 0){ - return 0; - } - - signal(SIGPIPE, SIG_IGN); - /* SIGSEGVź, ֤쳣ֹʱ, һBUGpcapдӲ */ - if((SIG_ERR == signal(SIGSEGV, pkt_dump_sig_handle))){ - printf("Catch SIGSEGV error!\n"); - } - -#if DEBUG - iknow_register_cmd(PLATFORM_IHANDLE, "show pkt dump summary", "display pkt dump summary", - ifuncb_show_pktdump_summary, NULL, 0, NULL); -#endif - printf("\n\033[33m[Warning]pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); - }else{ - ret = cycle_pkt_dump_socket_init(); - } - - return ret; -} - - -#ifdef __cplusplus -} -#endif - - - diff --git a/packet_io/cycle_pkt_dump_unix.c.bak b/packet_io/cycle_pkt_dump_unix.c.bak deleted file mode 100644 index fc6da5b..0000000 --- a/packet_io/cycle_pkt_dump_unix.c.bak +++ /dev/null @@ -1,677 +0,0 @@ -#include "packet_io.h" -#include "stream_internal.h" -#include "stream_manage.h" -#include "mesa_net.h" -#include "sendpacket.h" -#include "MESA_prof_load.h" -#include "MESA_sleep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - 2015-04-15 , LiJia. - cycle_pkt_dump, - ʵʱѭ洢ݰĿǽ߻ҵֻһcore, BUG޷. - sappcoredump 'pkt_dump_file_root_dir'Ŀ¼洢һʱյİ, - öģʽ֣пܷBUGԴ - ֣pkt_dump_file_max_sizeʵһЩ. - - ----- ----- - | S | | D | - | A | ---UNIX Socket--> | U | - | P | | M | - | P | | P | - ----- ----- - - Ϊʲôsapp, յ? ̼ͨͨŸһٴ洢? - : - sappյ֮, fwrite()洢, ΪfwriteлƵ, ֤дӲ. - ǵfflush()fclose(), ÿǿˢһ, Ӱ, - unix_domain_socket()ݰһ, write()غ, - sappBUG, core dump, ݰҲѾcopyһ, - pkt_dumpǿ϶԰һBUGİ, ȫı浽Ӳ̵. - - main.conf1µsection5: - [pkt_dump] - pkt_dump_switch=0 //ܿ - pkt_dump_total_size=1000 //root_dirܼ.pcapļĴС, λ:MB, ֹƶдӲ - pkt_dump_file_max_size=200 //pcapļÿֵ߳̿, λ:MB. - pkt_dump_file_root_dir=/dev/shm //pcap洢·, Ƽ/dev/shm, Ӳٶȿܶ - pkt_dump_thread_seq=0,2,4,6,8 //ÿ̵߳ĿأΪܾ޴޷ȫ洢Ǿֻò̵߳dump , all=ȫ - -*/ - -#ifdef __cplusplus -extern "C" { -#endif -#if CYCLE_PKT_DUMP - -#define UNIX_DOMAIN_SOCKET_NAME "/tmp/.pktdump" -#define PKT_DUMP_PROCESS_NAME "sapp_pkt_dump" - -#if DEBUG -#include "iknow.h" -extern iknow_handle PLATFORM_IHANDLE; - -typedef struct{ - unsigned long long total_pkt_num; - unsigned long long total_pkt_bytes; - unsigned long long discard_pkt_num; - unsigned long long discard_pkt_bytes; - char __pad__[32]; /* 64ֽcache */ -}pkt_dump_status_t; -static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM]; - -#endif - -extern int MESA_mkdir_p(const char *pathname, mode_t mode); -//extern time_t g_CurrentTime; -extern int g_packet_io_thread_num; -extern int g_iThreadNum; /* for dual_stack, start */ -static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* ָΪ/dev/shm, ٶȿ */ -static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ100MB, ߳ */ -static int G_PKT_DUMP_SW = 0; /* ĬϹر */ -static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM]; -static int G_UNIX_DOMAIN_SD[MAX_THREAD_NUM]; -static int pkt_dump_thread_num = 1; -static char phony_mac_hdr[14] = -{ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x12, 0x23, 0x34, 0x56, 0x67, 0x78, - 0x08, 0x00 -}; -typedef struct { - unsigned int magic; - unsigned short version_major; - unsigned short version_minor; - unsigned int thiszone; /* gmt to local correction */ - unsigned int sigfigs; /* accuracy of timestamps */ - unsigned int snaplen; /* max length saved portion of each pkt */ - unsigned int linktype; /* data link type (LINKTYPE_*) */ -}pkt_dump_file_hdr_t; - -struct pkt_dump_timeval { - unsigned int tv_sec; /* seconds */ - unsigned int tv_usec; /* microseconds */ -}; - -typedef struct { - struct pkt_dump_timeval ts; /* time stamp */ - unsigned int caplen; /* length of portion present */ - unsigned int len; /* length this packet (off wire) */ -}pkt_dump_pkt_hdr_t; - -typedef struct{ - enum addr_type_t low_layer_type; /* ԭʼײЭ, MAC(pcap), ҲIPv4(pag) */ - int raw_pkt_len; /* ԭʼܳ */ - //char pkt_data[]; -}pkt_dump_pipe_t; - - -static const pkt_dump_file_hdr_t pfile_hdr = -{ - 0xA1B2C3D4, - 0x0002, - 0x0004, - 0, - 0, - 0xFFFF, - 1 -}; - -/* reliable read */ -static inline ssize_t Rread(int fd, void *buf, size_t expect_count) -{ - ssize_t ret; - void *save_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = read(fd, save_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EAGAIN: - //usleep(1); - MESA_sleep(); - /* no break here!!! no break here!!! no break here!!!*/ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, read error:%s, ptr=%p, expect_count=%lu, left_count=%lu\n", - strerror(errno), save_ptr, expect_count, left_count); - break; - } - }else if(0 == ret){ - return 0; /* peer close */ - }else{ - save_ptr = (char *)save_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -/* reliable write */ -static inline ssize_t Rwrite(int fd, const void *buf, size_t expect_count) -{ - ssize_t ret; - const void *real_ptr = buf; - size_t left_count = expect_count; - - while(left_count > 0){ -retry: - ret = write(fd, real_ptr, left_count); - if(ret < 0){ - switch(errno){ - case EINTR: - goto retry; - break; - - default: - printf("pkt dump, write error:%s\n", strerror(errno)); - /* дռ䲻, , Ӱ */ - break; - } - }else{ - real_ptr = (const char *)real_ptr + ret; - left_count -= ret; - } - } - - return expect_count - left_count; -} - -static void *cycle_pkt_dump_check_father(void *arg) -{ - while(1){ - if(1 == getppid()){ /* ̱Ϊinit, ˵Ѿ˳ */ - exit(1); - }else{ - usleep(100000); - } - } - - return NULL; -} - -static void *cycle_pkt_dump_thread(void *arg) -{ - int thread_seq = *((int *)arg); - FILE *fp; - int file_name_post_prefix = 0, ret, pfile_hdr_flag = 0; - long tot_pcap_file_len = 0; - char pkt_buf[65536]; - char dump_file_name[PATH_MAX]; - pkt_dump_pkt_hdr_t *ppkt_hdr; - int pkt_len; - int skip_pkt_hdr_len; /* Ԥͷռ䳤, ݲģʽͬ, ܻEth */ - - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getppid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - ppkt_hdr = (pkt_dump_pkt_hdr_t *)pkt_buf; - ppkt_hdr->ts.tv_usec = 0; -#ifdef CAPTURE_MODE_PAG - memcpy(pkt_buf+sizeof(pkt_dump_pkt_hdr_t), phony_mac_hdr, 14); - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t) + 14; -#else - skip_pkt_hdr_len = sizeof(pkt_dump_pkt_hdr_t); -#endif - while(1){ - /* pcapͷռԤ, ֻһfwrite, ͽͷһд */ - pkt_len = read(G_UNIX_DOMAIN_SD[thread_seq], (char *)pkt_buf+skip_pkt_hdr_len, 2048); - if(0 == pkt_len){ - goto done; - }else if(pkt_len < 0){ - continue; - } - - /* pcap file header, first time */ - if(0 == pfile_hdr_flag){ - fwrite(&pfile_hdr, sizeof(pkt_dump_file_hdr_t), 1, fp); - tot_pcap_file_len += sizeof(pkt_dump_file_hdr_t); - pfile_hdr_flag = 1; - } - /* °, ʱ */ - ppkt_hdr->ts.tv_sec = (unsigned int )g_CurrentTime; -#ifdef CAPTURE_MODE_PAG - ppkt_hdr->caplen = pkt_len+14; - ppkt_hdr->len = pkt_len+14; -#else - ppkt_hdr->caplen = pkt_len; - ppkt_hdr->len = pkt_len; -#endif - - fwrite(pkt_buf, pkt_len+skip_pkt_hdr_len, 1, fp); - tot_pcap_file_len += pkt_len+skip_pkt_hdr_len; - - /* , ѭдļ */ - if(tot_pcap_file_len >= G_PKT_DUMP_FILE_SIZE){ - fclose(fp); - file_name_post_prefix = file_name_post_prefix ^ 1; - snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getppid(), thread_seq, file_name_post_prefix); - fp = fopen(dump_file_name, "w+"); /* cycle write two files */ - if(NULL == fp){ - printf("fopen %s error!\n", dump_file_name); - goto done; - } - tot_pcap_file_len = 0; - pfile_hdr_flag = 0; - } - } - -done: - - return NULL; -} - - -void cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) -{ - int ret; - - if((0 == G_PKT_DUMP_SW) || (0 == G_PKT_DUMP_PER_THREAD_SW[thread_seq])){ - return; - } - - ret = send(G_UNIX_DOMAIN_SD[thread_seq], p_raw_pkt->raw_pkt_data, p_raw_pkt->raw_pkt_len, MSG_DONTWAIT); /* raw data */ - if(ret < 0){ - //printf("cycle_pkt_dump() error: %s!\n", strerror(errno)); -#if DEBUG - PKT_DISCARD_STAT[thread_seq].discard_pkt_num++; - PKT_DISCARD_STAT[thread_seq].discard_pkt_bytes+= p_raw_pkt->raw_pkt_len; -#endif - return; - } - -#if DEBUG - PKT_DISCARD_STAT[thread_seq].total_pkt_num++; - PKT_DISCARD_STAT[thread_seq].total_pkt_bytes += p_raw_pkt->raw_pkt_len; -#endif - - if(ret != p_raw_pkt->raw_pkt_len){ - //printf("cycle_pkt_dump write pkt data, actual:%d, ret:%d\n", p_raw_pkt->raw_pkt_len, ret); - } -} - -void cycle_pkt_dump_old(int thread_seq, const void *ippkt, int ippktlen) -{ - raw_pkt_t raw_pkt; - - raw_pkt.raw_pkt_data = ippkt; - raw_pkt.raw_pkt_len = ippktlen; - - cycle_pkt_dump(thread_seq, &raw_pkt); -} - -static int cycle_pkt_dump_child_init(void) -{ - int i, ret; - struct sockaddr_un father_pro_addr; - int addr_len; - char test_buf[1024]; - int buf_len = 0; - socklen_t opt_len; - - for(i = 0; i < g_packet_io_thread_num; i++){ - G_UNIX_DOMAIN_SD[i] = socket(AF_UNIX,SOCK_DGRAM,0); - if(G_UNIX_DOMAIN_SD[i] < 0){ - printf("socket error: %s\n", strerror(errno)); - return -1; - } - - addr_len = sizeof(father_pro_addr); - father_pro_addr.sun_family=AF_UNIX; - snprintf(father_pro_addr.sun_path, sizeof(father_pro_addr.sun_path), "%s%d", UNIX_DOMAIN_SOCKET_NAME, i); - - unlink(father_pro_addr.sun_path); - if(bind(G_UNIX_DOMAIN_SD[i], (struct sockaddr *)&father_pro_addr, addr_len) < 0){ - printf("bind %s error: %s\n", father_pro_addr.sun_path, strerror(errno)); - return -1; - } - - listen(G_UNIX_DOMAIN_SD[i], 10); - } - - usleep(10000); - - for(i = 0; i < g_packet_io_thread_num; i++){ - ret = read(G_UNIX_DOMAIN_SD[i], test_buf, 1024); /* ȴ̵, ȷ˵ */ - if(ret <= 0){ - printf("socket read error:%s\n", strerror(errno)); - return -1; - } - } - - return 0; -} - - -#if DEBUG -static long ifuncb_show_pktdump_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args) -{ - int i; - unsigned long long discard_pkt_sum = 0, discard_byte_sum = 0; - unsigned long long tot_pkt_sum = 0, tot_byte_sum = 0; - - for(i = 0; i < g_packet_io_thread_num; i++){ - tot_pkt_sum += PKT_DISCARD_STAT[i].total_pkt_num; - tot_byte_sum += PKT_DISCARD_STAT[i].total_pkt_bytes; - discard_pkt_sum += PKT_DISCARD_STAT[i].discard_pkt_num; - discard_byte_sum += PKT_DISCARD_STAT[i].discard_pkt_bytes; - } - //iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n"); - iprintf(ihandle, iconn, "%8s %8s %13s\n", "", "packet", "byte"); - iprintf(ihandle, iconn, "%8s %8llu %13llu\n", "total", tot_pkt_sum, tot_byte_sum); - iprintf(ihandle, iconn, "%8s %8llu %13llu\n", "DROP", discard_pkt_sum, discard_byte_sum); - - return 0; -} - -#endif - -static int cycle_pkt_dump_father_init(void) -{ - int i; - struct sockaddr_un child_pro_addr; - int addr_len; - char test_buf[1024] = "I am father"; - int buf_len = 0; - socklen_t opt_len; - - for(i = 0; i < g_packet_io_thread_num; i++){ - G_UNIX_DOMAIN_SD[i] = socket(AF_UNIX,SOCK_DGRAM,0); - if(G_UNIX_DOMAIN_SD[i] < 0){ - printf("socket error: %s\n", strerror(errno)); - return -1; - } - - addr_len = sizeof(child_pro_addr); - child_pro_addr.sun_family=AF_UNIX; - snprintf(child_pro_addr.sun_path, sizeof(child_pro_addr.sun_path), "%s%d", UNIX_DOMAIN_SOCKET_NAME, i); - - if(connect(G_UNIX_DOMAIN_SD[i], (struct sockaddr*)&child_pro_addr, addr_len) < 0){ - printf("connect %s error: %s\n", child_pro_addr.sun_path, strerror(errno)); - return -1; - } - } - - for(i = 0; i < g_packet_io_thread_num; i++){ - write(G_UNIX_DOMAIN_SD[i], test_buf, 1024); - } - - unlink(child_pro_addr.sun_path); -#if DEBUG - iknow_register_cmd(PLATFORM_IHANDLE, "show pktdump summary", "display packet dump status", - ifuncb_show_pktdump_summary, NULL, 0, NULL); -#endif - - return 0; -} - -static void cycle_pkt_dump_clear_last_status(void) -{ - char cmd_buf[128]; - - snprintf(cmd_buf, 128, "killall %s", PKT_DUMP_PROCESS_NAME); - - system(cmd_buf); -} - -static void cycle_pkt_dump_exec(int argc, char *argv[]) -{ - int i; - pid_t pid; - pthread_t check_ppid, thread_id[MAX_THREAD_NUM]; - static int thread_seq[MAX_THREAD_NUM]; - - cycle_pkt_dump_clear_last_status(); - - pid = fork(); - if(0 == pid){ /* ӽ, */ - if(cycle_pkt_dump_child_init() < 0){ - printf("cycle pkt dump init error!\n"); - exit(1); - } - prctl(PR_SET_NAME, PKT_DUMP_PROCESS_NAME, 0, 0, 0); - }else if(pid > 0){ - usleep(50000); - if(cycle_pkt_dump_father_init() < 0){ - printf("cycle pkt dump init error!\n"); - exit(1); - } - return; /* ̷, sapp */ - }else{ - printf("cycle_pkt_dump fork error!\n"); - exit(0); - } - - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - thread_seq[i] = i; - pthread_create(&thread_id[i], NULL, cycle_pkt_dump_thread, &thread_seq[i]); - usleep(100); - } - } - - pthread_create(&check_ppid, NULL, cycle_pkt_dump_check_father, NULL); - - /* ӽ̵߳ȴ */ - for(i = 0; i < pkt_dump_thread_num; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] != 0){ - pthread_join(thread_id[i], NULL); - } - } - - exit(0); -} - -static void cycle_pkt_dump_set_thread_num(int thread_num) -{ - pkt_dump_thread_num = thread_num; -} - -static int cycle_pkt_dump_get_core_num(void) -{ - FILE *fp; - char line_buf[PATH_MAX] = {0}; - int core_num = 0; - - fp = popen("ls -l core.* | wc -l", "r"); - if(NULL == fp){ - return -1; - } - - fgets(line_buf, PATH_MAX, fp); - - core_num = atoi(line_buf); - - pclose(fp); - return core_num; -} - -/* config is like: "0,1,2,3,4,5" */ -static int cycle_pkt_dump_parse_per_thread_switch(char *config_str) -{ - char *parse_config = config_str; - char *save_ptr; - char *token; - int i, thread_seq; - - if(strncasecmp("all", config_str, 3) == 0){ /* all thread is enable */ - for(i = 0; i < pkt_dump_thread_num; i++){ - G_PKT_DUMP_PER_THREAD_SW[i] = 1; - } - return 0; - } - - while((token = strtok_r(parse_config, ", \t", &save_ptr)) != NULL){ - thread_seq = atoi(token); - if(thread_seq < 0 || thread_seq >= pkt_dump_thread_num){ - printf("'pkt_dump_thread_seq' config invalid, threadnum=%d!\n", pkt_dump_thread_num); - return -1; - } - G_PKT_DUMP_PER_THREAD_SW[thread_seq] = 1; - parse_config = NULL; - } - - return 0; -} - - -static long cycle_pkt_dump_get_cur_files_size(void) -{ - FILE *fp; - long cur_files_size; - char cmd_str[PATH_MAX], tmp_str[1024]; - - snprintf(cmd_str, PATH_MAX, "du -scb %s/*.pcap | grep total | awk {'print $1'}", G_PKT_DUMP_ROOT_DIR); - - fp = popen(cmd_str, "r"); - if(NULL == fp){ - return -1; - } - - if(NULL == fgets(tmp_str, 1024, fp)){ - return -1; - } - cur_files_size = (long)strtol(tmp_str, NULL, 10); - - pclose(fp); - - return cur_files_size; -} - -static int cycle_pkt_dump_get_cur_enable_thread(void) -{ - int i, sum = 0; - - for(i = 0; i < MAX_THREAD_NUM; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] > 0){ - sum++; - } - } - - return sum; -} -/* - total_files_size: Ŀ¼ܵ.pcapС, λ:Byte; - file_size_per_thread_by_conf: ߳ļС, λ:Byte; - - յʵfile_size_per_threadֵ, ȡڵǰе.pcapļСtotal_files_sizeĹϵ; - ǰе.pcapļѳtotal_files_size, дµļ. -*/ -static int cycle_pkt_dump_set_file_size(long total_files_size, long file_size_per_thread_by_conf) -{ - long cur_files_size; - int cur_enable_thread_num = 0; - long file_size_per_thread_by_calc; /* ʵʼóÿ߳ļС */ - - cur_files_size = cycle_pkt_dump_get_cur_files_size(); - if(cur_files_size < 0 || cur_files_size >= total_files_size){ - printf("Warning: pkt_dump is enable, but current files size is more than 'pkt_dump_total_size'!\n"); - G_PKT_DUMP_SW = 0; - return -1; - } - - cur_enable_thread_num = cycle_pkt_dump_get_cur_enable_thread(); - if(0 == cur_enable_thread_num){ - return -1; - } - - file_size_per_thread_by_calc = (total_files_size-cur_files_size)/cur_enable_thread_num/2; - - /* ȡС */ - G_PKT_DUMP_FILE_SIZE = (file_size_per_thread_by_calc < file_size_per_thread_by_conf?file_size_per_thread_by_calc:file_size_per_thread_by_conf); - if(G_PKT_DUMP_FILE_SIZE < 2048){ - printf("Warning: pkt_dump is enable, but current files size is more than 'pkt_dump_total_size'!\n"); - return -1; - } - - return 0; -} - - - -int cycle_pkt_dump_init(int argc, char *argv[]) -{ - int int_tmp, total_files_size, core_num; - char per_thread_sw[PATH_MAX]; - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_switch", &G_PKT_DUMP_SW, 0); - - if(0 == G_PKT_DUMP_SW){ - return 0; - } - - cycle_pkt_dump_set_thread_num(g_packet_io_thread_num); - - core_num = cycle_pkt_dump_get_core_num(); - if(core_num < 0 || core_num > 10){ - printf("Warning! core.* number is more than 10, pkt dump is auto disabled!\n"); - G_PKT_DUMP_SW = 0; - return 0; - } - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_file_root_dir", G_PKT_DUMP_ROOT_DIR, PATH_MAX, (char *)"./pkt_dump"); - MESA_mkdir_p(G_PKT_DUMP_ROOT_DIR, 0755); - - MESA_load_profile_string_nodef((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_thread_seq", per_thread_sw, PATH_MAX); - if(cycle_pkt_dump_parse_per_thread_switch(per_thread_sw) < 0){ - return 0; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_total_size", &total_files_size, 1000); - if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*100 /* 100GB */){ - printf("pkt_dump_total_size invalid!\n"); - return -1; - } - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_file_max_size", &int_tmp, 100); - if(int_tmp < 2 || (unsigned int)int_tmp >= 1024*100 /* 100GB */){ - printf("pkt_dump_file_max_size invalid!\n"); - return -1; - } - /* ÿ߳Ҫѭд2ļ, Ҫpkt_dump_file_max_sizeʵֵٳ2 */ - if(cycle_pkt_dump_set_file_size((long)total_files_size*1024*1024, (long)int_tmp*1024*512) < 0){ - return 0; - } - - signal(SIGPIPE, SIG_IGN); - - cycle_pkt_dump_exec(argc, argv); - - printf("\n\033[41mWarning! pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); - printf("\033[41mWarning! pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); - - return 0; -} - - -#endif - -#ifdef __cplusplus -} -#endif - - diff --git a/packet_io/pkt_dispatch.c_BAK b/packet_io/pkt_dispatch.c_BAK deleted file mode 100644 index aada825..0000000 --- a/packet_io/pkt_dispatch.c_BAK +++ /dev/null @@ -1,553 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif -#include -#include -#include -#include -#include -#include -#include "stream_manage.h" -#include "capture_internal.h" -#include "sysinfo.h" -#include "logger.h" -#include "sendpacket.h" -#include "deal_ipv6.h" -#include "packet_io_internal.h" -#include "packet_io.h" - -#define QUEUE_FULL_LOG_FILE "queue_full.log" - -int g_packetio_threadnum=4; -struct thread_node_new *threads_pool_new; -struct thread_node_new **thread_table_new; - -extern struct sendpacket_mac_table *G_PKT_MAC_TABLE; -extern const unsigned char G_BROADCAST_ADDR[6]; -static int seed = 0; -unsigned long G_RCV_PKT_NUM = 0;/* 2012-08-14 LiJia add, ܼյİÿյһ1, ȫΨһ */ - - -/* 2012-08-09 LiJia add, Ϊ˷ֹij߳ѭ޷ȷתݰ̣߳ - Ĭϲ߳κݰֻеij̶߳ʱẒ̇ᷢ߳ - Ҵֻ߳ظ豸keepaliveתӦòЭ鴦. -*/ -struct thread_node_new *G_RESERVED_THREAD; - -int ipv4_entry(struct streaminfo_private*pfstream, - void *a_packet, int thread_num, unsigned char routedir); -int ipv6_entry(struct streaminfo_private *pfstream, - void *a_packet, int thread_num, unsigned char routedir); -int gdev_keepalive(u_char *data, int len, int thread_id, int pro_type); - -volatile int queue_full_flag[MAX_THREAD_NUM]; - -/* 2012-08-09 LiJia add, - ڼ⻺Ƿ¼־. -*/ -void queue_full_detect(FILE *queue_log_fp) -{ - int i; - char time_now_str[32]; - - if(NULL == queue_log_fp) - { - return; - } - - timet_to_str(g_CurrentTime, time_now_str, 32); - - for(i = 0; i < g_packetio_threadnum; i++) - { - if(queue_full_flag[i] > 0) - { - fprintf(queue_log_fp, "%s: Thread-%d queue full!\n", time_now_str, i); - queue_full_flag[i] = 0; - } - } - - return; -} - -struct data_node *add_new_data_pcap (struct thread_node_new *a_thread, char *data,int datalen,unsigned char dir) -{ - struct data_node *a_data; -#ifdef TEST_DEAL_TIME - struct timeval tv; -#endif - - /* 2012-08-09 LiJia add, 󻺴 - ij̶߳Ѷ־Ϊ1ڼ¼־ - ͬʱݰ̴߳. - */ - if(a_thread->data_num > g_queue_max_num) - { -#if 0 /* 2013-02-04 lijia modify for debug */ - queue_full_flag[a_thread->thread_num] = 1; - - /* ģʽ£Ǵֱӷ */ - if(G_NET_CONNECTION_MODE & __NET_CONN_PARALLEL) - { - return NULL; - } - - if(G_RESERVED_THREAD->data_num > 50000) - { - return NULL; - } - - a_thread = G_RESERVED_THREAD; -#else - usleep(1000 * 10); -#endif - } - a_data = (struct data_node*)malloc(sizeof(struct data_node)); - if(!a_data){ - printf("%s:%d:no mem!\n", __FILE__, __LINE__); - exit(1); - return a_data; - } - memset (a_data, 0, sizeof(struct data_node)); - a_data->data = (unsigned char *)data; - a_data->dir = dir; - a_data->datalen=datalen; - a_data->packet_num = G_RCV_PKT_NUM++; - -#ifdef TEST_DEAL_TIME - gettimeofday(&tv, 0); - a_data->begintime = tv.tv_sec* 1000*1000 + tv.tv_usec; -#endif -#ifdef MULTITHREAD - - pthread_mutex_lock (&a_thread->mutex); - { -#endif - if (a_thread->data_queue == NULL) - { - a_thread->data_queue = a_data; - a_thread->oldest_data = a_thread->data_queue;; - } - else - { - a_data->next = a_thread->data_queue; - a_thread->data_queue->prev = a_data; - //a_data->prev_time = a_thread->data_queue; - //a_thread->data_queue->next_time = a_data; - a_thread->data_queue = a_data; - } - - a_thread->data_num++; - a_thread->new_data = 1; - pthread_cond_signal (&(a_thread->cond)); -#ifdef MULTITHREAD - pthread_mutex_unlock (&a_thread->mutex); - } -#endif - - return a_data; -} - -void free_data_pcap (struct thread_node_new *a_thread) -{ - struct data_node *oldest_data = NULL; - - oldest_data = a_thread->oldest_data; - - if (oldest_data) - { - if (a_thread->data_queue == oldest_data) - { - a_thread->data_queue = NULL; - a_thread->oldest_data = NULL; - } - else - { - if(oldest_data->prev != NULL) - { - a_thread->oldest_data = oldest_data->prev; - } - else - { - // add by yzh for debug, 20031204 - //FILE *pFile = fopen("err.txt","a"); - //time_t t; - //char buf[256]; - //time(&t); - //CTIME(&t, buf, 256); - //fprintf(pFile,"ERROR %s: oldest_data->next_time == NULL\n",buf); - //fclose(pFile); - - printf("free_data_pcap ERROR : oldest_data->next_time == NULL\n"); - exit(-1); - } - } - free(oldest_data->data); // add by yzh, 20030218 - free (oldest_data); - a_thread->data_num--; - if(a_thread->data_num == 0) - a_thread->new_data = 0; - } - -} - - - -/*Thread hander. If the data queue is finished, as well as no new data comes, it will -* sleep*/ -void thread_handler_pcap(struct thread_node_new *a_thread) -{ - unsigned char *data; - struct data_node* oldest_data; - int need_free; - unsigned int sendlen=0; - int ret=DROP; -#ifdef TEST_DEAL_TIME - struct timeval tv; - unsigned long delaytime,dealtime,endtime,begintime; -#endif - unsigned char dir; - struct sendpacket_ethernet_hdr *eth_hdr; - unsigned short ether_type; - -#ifdef MULTITHREAD - while (1) - { - pthread_mutex_lock (&a_thread->mutex); - - while (!a_thread->new_data && a_thread->data_num == 0) - { - // usleep(10); - pthread_cond_wait (&(a_thread->cond), &a_thread->mutex); - } - - pthread_mutex_unlock (&a_thread->mutex); -#endif - need_free = 0; - oldest_data = a_thread->oldest_data; - if(oldest_data!=NULL) - { - data = oldest_data->data;/*out the queue*/ - a_thread->packet_num = oldest_data->packet_num; - sendlen=oldest_data->datalen; - dir = (unsigned char)oldest_data->dir; -#ifdef TEST_DEAL_TIME - gettimeofday(&tv, 0); - begintime=oldest_data->begintime; - delaytime = tv.tv_sec* 1000*1000 + tv.tv_usec; -#endif - } - - if(G_NET_CONNECTION_MODE & __NET_CONN_LINK_LAYER) - { - memcpy(G_PKT_MAC_TABLE[a_thread->thread_num].src_mac, data+6, 6); - if(NET_CONN_SERIAL_2CARD == G_NET_CONNECTION_MODE) /* ˫ģʽҪ¼ĿMAC, ģʽĿMACMAC */ - { - memcpy(G_PKT_MAC_TABLE[a_thread->thread_num].dst_mac, data, 6); - } - G_PKT_MAC_TABLE[a_thread->thread_num].rcv_dir = dir; /* ¼հķ */ - } - - eth_hdr = (struct sendpacket_ethernet_hdr *)data; - ether_type = ntohs(eth_hdr->ether_type); - - /* 2012-08-13 LiJia add, 豸ģʽ£ARPЭĹ㲥ֱӶ! */ - if((G_NET_CONNECTION_MODE & __NET_CONN_GDEV) - && (memcmp(G_BROADCAST_ADDR, eth_hdr->ether_dhost, 6) == 0) - && (ether_type != ETHERTYPE_ARP)) - { - goto free_pkt; - } - - switch(ether_type) - { - case ETHERTYPE_IP: - ret = ipv4_entry(NULL, (struct ip *)(data+linkoffset), a_thread->thread_num, dir); - break; - - case ETHERTYPE_IPv6: - ret = ipv6_entry(NULL, (struct simple_ip6_hdr * )(data+linkoffset), a_thread->thread_num, dir); - break; - - case ETHERTYPE_ARP: - if((G_NET_CONNECTION_MODE & __NET_CONN_GDEV) - && (gdev_keepalive(data, sendlen, a_thread->thread_num, 2) > 0)) /* 豸 */ - { - goto free_pkt; - } - else - { - if(NET_CONN_SERIAL_2CARD == G_NET_CONNECTION_MODE) - { - ret = PASS; - break; - } - goto free_pkt; - } - break; - - default: - /* ģʽ£δ֪İҪת(ע) */ - if(G_NET_CONNECTION_MODE & __NET_CONN_SERIAL) - { - forwarding_packet_low_level(dir, a_thread->thread_num, data, sendlen); - } - - /* ģʽ£δ֪İֱӶ */ - goto free_pkt; - break; - } - - if(PASS == ret) - { - forwarding_packet_low_level(dir, a_thread->thread_num, data, sendlen); - } - - -free_pkt: - g_SysInputInfo[a_thread->thread_num][PKT_ETHERNET]++; - - -#ifdef MULTITHREAD - pthread_mutex_lock (&a_thread->mutex); - free_data_pcap(a_thread); - pthread_mutex_unlock(&a_thread->mutex); - continue; -#else - free_data_pcap(a_thread); - return; -#endif - - -#ifdef MULTITHREAD - } - printf("\nThread %lu exit\n", a_thread->thread_id); -#endif -} - - -int mk_thread_hash_index (u_int saddr, u_int daddr) -{ -/**modify thread dispatch strategy - by zzb 2005/12/27 -*/ - unsigned int addr; - unsigned int add; - unsigned int ixor; - unsigned char index = 0; - - if(saddr>daddr) - { - ixor = saddr % 911; - add = daddr % 439; - } - else - { - ixor = daddr % 911; - add = saddr % 439; - } - //add by lqy 20071025 - //̸߳4ʱӦηַ? - if(1==g_packetio_threadnum) - return 0; - if(4!=g_packetio_threadnum) - { - index=(ixor +add)%g_packetio_threadnum; - return index; - } - //end add - if(1!=g_packetio_threadnum) - { - addr = add; - while(addr) - { - index += (addr & 0x3); - addr = addr >> 2; - } - - addr = ixor; - while(addr) - { - index += (addr & 0x3); - addr = addr >> 3; - } - add = index + (ixor ^ seed); - index = 0; - while(add) - { - index ^= (add & 0x3); - add = add >> 5; - } - return index; - } - else - return 0; - - -// return (((u_int) (saddr )) % g_packetio_threadnum); -} - - -inline struct thread_node_new *find_thread (u_int saddr, u_int daddr) -{ - int hash_index; - hash_index = mk_thread_hash_index(saddr, daddr); - thread_table_new[hash_index]->hash_index=hash_index; - return thread_table_new[hash_index]; -} - - -void pcap_hand(u_char * par, struct pcap_pkthdr *hdr, u_char *data) -{ - struct thread_node_new *a_thread; - struct ip *ipv4_hdr; - struct ip6_hdr *ipv6_hdr; - unsigned int dispatch_arg1, dispatch_arg2; - unsigned char *new_data; - unsigned char dir; - struct sendpacket_ethernet_hdr *eth_hdr; - unsigned short ether_type; - - eth_hdr = (struct sendpacket_ethernet_hdr *)data; - ether_type = ntohs(eth_hdr->ether_type); - - - if(NET_CONN_SERIAL_GDEV == G_NET_CONNECTION_MODE) - { - if(memcmp(data, sendto_gdev_card_mac, 6) != 0) - { - if(memcmp(data, G_BROADCAST_ADDR, 6) != 0) - { - return; /* յķǹ㲥MAC */ - } - else - { - if(ETHERTYPE_ARP != ether_type) - { - return; /* ǹ㲥ARP */ - } - - /* arp */ - } - } - /* ǷMAC */ - } - - /* ݸЭַHASHÿ߳ */ - switch(ether_type) - { - case ETHERTYPE_IP: - ipv4_hdr = (struct ip *)(data+linkoffset); - dispatch_arg1 = ipv4_hdr->ip_src.s_addr; - dispatch_arg2 = ipv4_hdr->ip_dst.s_addr; - break; - - case ETHERTYPE_IPv6: - ipv6_hdr = (struct ip6_hdr *)(data+linkoffset); - dispatch_arg1 = ipv6_hdr->ip6_src.s6_addr32[3]; - dispatch_arg2 = ipv6_hdr->ip6_dst.s6_addr32[3]; - break; - - default: /* ЭʹMACַHASH */ - dispatch_arg1 = *((unsigned int *)data); - dispatch_arg2 = *((unsigned int *)(data + 6)); - break; - } - - new_data=(u_char*)malloc(hdr->len); - if(!new_data) - { - printf("no mem!\n"); - exit(0); - } - memcpy(new_data, data, hdr->len); - - a_thread = find_thread (dispatch_arg1, dispatch_arg2); - if(!a_thread) - { - goto err; - } - - if(NET_CONN_SERIAL_2CARD == G_NET_CONNECTION_MODE) - { - dir = *par; - } - else - { - if(data[11] & 0x01) /* ԴMACһλʾ */ - { - dir = 0x80; /* ϵͳڲʹλʾ */ - } - else - { - dir = 0x00; - } - } - - if(!add_new_data_pcap(a_thread, (char *)new_data, hdr->len, dir)) - { - goto err; - } - - return; - -err: - free(new_data); - return; -} - - -int thread_init_new(void) -{ - int i; - pthread_attr_t thread_attr; - struct sched_param param; - int thread_num = g_packetio_threadnum; - - if(G_NET_CONNECTION_MODE & __NET_CONN_SERIAL) - { - thread_num++; /* һռ߳ */ - } - - pthread_attr_init(&thread_attr); - pthread_attr_getschedparam(&thread_attr, ¶m); - param.sched_priority = 15; - pthread_attr_setschedpolicy(&thread_attr, SCHED_RR); - //mallopt(M_MMAP_MAX, 0); - thread_table_new = (struct thread_node_new **)malloc (thread_num * sizeof (char *)); - memset (thread_table_new, 0, thread_num * sizeof (char *)); - - threads_pool_new = (struct thread_node_new *)malloc ((thread_num) * sizeof (struct thread_node_new)); - memset(threads_pool_new, 0, thread_num * sizeof(struct thread_node_new)); - - if(G_NET_CONNECTION_MODE & __NET_CONN_SERIAL) - { - G_RESERVED_THREAD = (struct thread_node_new *)malloc(sizeof(struct thread_node_new)); - memset(G_RESERVED_THREAD, 0, sizeof(struct thread_node_new)); - } - - for (i = 0; i < thread_num; i++) - { -#ifdef MULTITHREAD - pthread_cond_init (&threads_pool_new[i].cond, NULL); - pthread_mutex_init (&threads_pool_new[i].mutex, NULL); - pthread_mutex_init (&threads_pool_new[i].free_mutex, NULL); -#endif - - threads_pool_new[i].thread_num = i; //zzb 2006/04/25 - seed = rand(); - //init_block(&threads_pool[i]); - //id2pt[threads_pool[i].thread_id % g_packetio_threadnum] = &threads_pool[i]; - thread_table_new[i] = &threads_pool_new[i]; - } - - if(G_NET_CONNECTION_MODE & __NET_CONN_SERIAL) - { - G_RESERVED_THREAD = &threads_pool_new[thread_num-1]; - } - - return 1; -} - -#ifdef __cplusplus -} -#endif diff --git a/packet_io/pkt_dispatch_new.BAK b/packet_io/pkt_dispatch_new.BAK deleted file mode 100644 index 10dea71..0000000 --- a/packet_io/pkt_dispatch_new.BAK +++ /dev/null @@ -1,89 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include -#include -#include "stream_manage.h" -#include "sendpacket.h" -#include "deal_ipv6.h" -#include "packet_io.h" - -static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr) -{ - memcpy(addr->src_mac, p_eth_hdr->ether_shost, ETHER_ADDR_LEN); - memcpy(addr->dst_mac, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN); -} - - -int eth_entry(struct streaminfo *fstream, void *raw_data, - int thread_num, unsigned char dir) -{ - int ret = PASS; - const struct mesa_ethernet_hdr *p_eth_hdr = (struct mesa_ethernet_hdr *)raw_data; - unsigned short eth_type = ntohs(p_eth_hdr->ether_type); - unsigned char *next_layer_data =(unsigned char *)raw_data + sizeof(struct mesa_ethernet_hdr); - //int next_layer_len = datalen - sizeof(struct ethhdr); - - struct streamindex tmp_index; - struct streamindex *ptmp = &tmp_index; - struct layer_addr_mac addr; - - memset(ptmp,0,sizeof(struct streamindex)); - set_mac_addr(&addr, p_eth_hdr); - ptmp->stream.addr.paddr = &addr; - ptmp->stream.addr.addrtype = ADDR_TYPE_MAC; - - ptmp->stream.pfather = fstream; - ptmp->stream.type = STREAM_TYPE_ETHERNET; - ptmp->stream.routedir = dir; - ptmp->stream.threadnum = thread_num; - - switch(eth_type){ - case ETH_P_ARP: - arp_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_8021Q: - vlan_8021q_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_IP: - ipv4_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_IPV6: - ipv6_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - default: - /* unknown protocol */ - ret = PASS; - break; - } - - return ret; -} - -int packet_ipv4_handle(const unsigned char *data, int datalen, int dir, int thread_num) -{ - -} - -int packet_ipv6_handle(const unsigned char *data, int datalen, int dir, int thread_num) -{ - -} - - - - -#ifdef __cplusplus -} -#endif - - diff --git a/plugin/lib/plugctrl.a b/plugin/lib/plugctrl.a deleted file mode 100644 index 4ad0edc..0000000 Binary files a/plugin/lib/plugctrl.a and /dev/null differ diff --git a/project/project_special_manage.c_BAK b/project/project_special_manage.c_BAK deleted file mode 100644 index 0d8ec65..0000000 --- a/project/project_special_manage.c_BAK +++ /dev/null @@ -1,184 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -/* 2014-04-01 LiJia add, - Ŀص󵥶, ͨؿǷ, - Դﵽ±ƽ̨, ɷɾijЩ. -*/ - -#include -#include "project.h" - -extern void *dictator_malloc(int thread_seq,int size); -extern void dictator_free(int thread_seq,void *pbuf); - - -extern int set_terminal_tag_switch(int op_switch); -extern void *terminal_tag_create_struct(int thread_num); -extern void terminal_tag_destroy(int thread_num, void *info); - -extern int raw_ip_frag_list_v4_init(int thread_count); -extern int set_raw_ip_frag_list_v4_switch(int op_switch); - - -extern int raw_ip_frag_list_v6_init(int thread_count); -extern int set_raw_ip_frag_list_v6_switch(int op_switch); - -extern int stream_id_init(int thread_cnt); -extern int set_stream_id_switch(int op_switch); -extern void *stream_id_create_struct(int thread_num); -extern void stream_id_destroy(int thread_num, void *info); - -extern int set_gdev_switch(int op_switch); - -static int g_project_global_switch = 0; - -struct project_special_fun_list{ - int type; - int (*set_fun)(int op_switch); - int (*global_init)(int thread_count); /* call when program start, only one time */ - void *(*create_fun)(int thread_num); /* call when a stream start */ - void (*destroy)(int thread_num, void *info);/* call when a stream close */ -}; - -static struct project_special_fun_list g_project_fun_list[PROGECT_REQUIREMENT_MAX+1] = -{ - { - __PROGECT_REQUIREMENT_PHONY_, - NULL, - NULL, - NULL, - NULL - }, - - { - PROGECT_REQUIREMENT_TERMINAL_TAG, - set_terminal_tag_switch, - NULL, - terminal_tag_create_struct, - terminal_tag_destroy - }, - - { - PROGECT_REQUIREMENT_IPV4_FRAG_LIST, - set_raw_ip_frag_list_v4_switch, - raw_ip_frag_list_v4_init, - NULL, - NULL, - }, - - { - PROGECT_REQUIREMENT_IPV6_FRAG_LIST, - set_raw_ip_frag_list_v6_switch, - raw_ip_frag_list_v6_init, - NULL, - NULL, - }, - - { - PROGECT_REQUIREMENT_STREAM_ID, - set_stream_id_switch, - stream_id_init, - stream_id_create_struct, - stream_id_destroy, - }, - - { - PROGECT_REQUIREMENT_MAX, - NULL, - NULL, - NULL, - NULL, - }, -}; - -struct project_special_info{ - void *project_info[PROGECT_REQUIREMENT_MAX]; -}; - -int set_project_requirement(int type, int op_switch) -{ - if(PROJECT_MODULE_ENABLE == op_switch){ - g_project_global_switch++; - } - - (*g_project_fun_list[type].set_fun)(op_switch); - - return 0; -} - -void **project_get_private_info(void *pproject, int type) -{ - struct project_special_info *union_info; - - if(NULL == pproject){ - return NULL; - } - - union_info = (struct project_special_info *)pproject; - - return &((union_info->project_info)[type]); -} - -int project_global_init(int thread_count) -{ - int i, ret = 0; - - for(i = 0; i < PROGECT_REQUIREMENT_MAX; i++){ - if(g_project_fun_list[i].global_init != NULL){ - ret = (*(g_project_fun_list[i].global_init))(thread_count); - if(ret < 0){ - break; - } - } - } - - return ret; -} - -void *project_special_create(int thread_num) -{ - int i; - struct project_special_info *pinfo; - - if(0 == g_project_global_switch){ - return NULL; - } - - pinfo = (struct project_special_info *)dictator_malloc(thread_num, sizeof(struct project_special_info)); - - for(i = 0; i < PROGECT_REQUIREMENT_MAX; i++){ - if(g_project_fun_list[i].create_fun != NULL){ - pinfo->project_info[i] = (*(g_project_fun_list[i].create_fun))(thread_num); - } - } - - return pinfo; -} - -void project_special_destroy(int thread_num, void *info) -{ - int i; - struct project_special_info *pinfo; - - if((0 == g_project_global_switch) || (NULL == info)){ - return; - } - - pinfo = (struct project_special_info *)info; - - for(i = 0; i < PROGECT_REQUIREMENT_MAX; i++){ - if(g_project_fun_list[i].destroy != NULL){ - (*(g_project_fun_list[i].destroy))(thread_num, pinfo->project_info[i]); - } - } - - dictator_free(thread_num, info); -} - - -#ifdef __cplusplus -} -#endif - diff --git a/splint.sh b/splint.sh deleted file mode 100644 index 6277efb..0000000 --- a/splint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -echo "splint check $1" -splint -f .splint.rc $1 diff --git a/support/MESA_socket_wrap/lib/libMESA_socket_wrap.a b/support/MESA_socket_wrap/lib/libMESA_socket_wrap.a deleted file mode 100644 index e6be73f..0000000 Binary files a/support/MESA_socket_wrap/lib/libMESA_socket_wrap.a and /dev/null differ -- cgit v1.2.3